From 752dc391fc70cae18088780db3335777c4161123 Mon Sep 17 00:00:00 2001 From: Lazar Date: Wed, 23 Oct 2024 13:55:53 +0200 Subject: [PATCH] atomic slasher works, wip unbonding slasher --- e2etest/atomicslasher_e2e_test.go | 2 +- e2etest/slasher_e2e_test.go | 2 +- e2etest/test_manager_btcstaking.go | 29 ++++++++++++++++++----------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/e2etest/atomicslasher_e2e_test.go b/e2etest/atomicslasher_e2e_test.go index aa85d872..8ada2f98 100644 --- a/e2etest/atomicslasher_e2e_test.go +++ b/e2etest/atomicslasher_e2e_test.go @@ -218,7 +218,7 @@ func TestAtomicSlasher_Unbonding(t *testing.T) { /* the victim BTC delegation unbonds */ - tm.Undelegate(t, stakingSlashingInfo, unbondingSlashingInfo, btcDelSK) + tm.Undelegate(t, stakingSlashingInfo, unbondingSlashingInfo, btcDelSK, func() { tm.CatchUpBTCLightClient(t) }) /* finality provider builds unbonding slashing tx witness and sends it to Bitcoin diff --git a/e2etest/slasher_e2e_test.go b/e2etest/slasher_e2e_test.go index 4f717706..c8e36bb8 100644 --- a/e2etest/slasher_e2e_test.go +++ b/e2etest/slasher_e2e_test.go @@ -187,7 +187,7 @@ func TestSlasher_SlashingUnbonding(t *testing.T) { stakingSlashingInfo1, unbondingSlashingInfo1, stakerPrivKey1 := tm.CreateBTCDelegation(t, fpSK) // undelegate - unbondingSlashingInfo, _ := tm.Undelegate(t, stakingSlashingInfo1, unbondingSlashingInfo1, stakerPrivKey1) + unbondingSlashingInfo, _ := tm.Undelegate(t, stakingSlashingInfo1, unbondingSlashingInfo1, stakerPrivKey1, func() { tm.CatchUpBTCLightClient(t) }) // commit public randomness, vote and equivocate tm.VoteAndEquivocate(t, fpSK) diff --git a/e2etest/test_manager_btcstaking.go b/e2etest/test_manager_btcstaking.go index 38f218b4..1b1d1dbe 100644 --- a/e2etest/test_manager_btcstaking.go +++ b/e2etest/test_manager_btcstaking.go @@ -472,7 +472,8 @@ func (tm *TestManager) Undelegate( t *testing.T, stakingSlashingInfo *datagen.TestStakingSlashingInfo, unbondingSlashingInfo *datagen.TestUnbondingSlashingInfo, - delSK *btcec.PrivateKey) (*datagen.TestUnbondingSlashingInfo, *schnorr.Signature) { + delSK *btcec.PrivateKey, + catchUpLightClientFunc func()) (*datagen.TestUnbondingSlashingInfo, *schnorr.Signature) { signerAddr := tm.BabylonClient.MustGetAddr() // TODO: This generates unbonding tx signature, move it to undelegate @@ -495,16 +496,6 @@ func (tm *TestManager) Undelegate( err = unbondingSlashingInfo.UnbondingTx.Serialize(&unbondingTxBuf) require.NoError(t, err) - msgUndel := &bstypes.MsgBTCUndelegate{ - Signer: signerAddr, - StakingTxHash: stakingSlashingInfo.StakingTx.TxHash().String(), - StakeSpendingTx: unbondingTxBuf.Bytes(), - StakeSpendingTxInclusionProof: nil, - } - _, err = tm.BabylonClient.ReliablySendMsg(context.Background(), msgUndel, nil, nil) - require.NoError(t, err) - t.Logf("submitted MsgBTCUndelegate") - resp, err := tm.BabylonClient.BTCDelegation(stakingSlashingInfo.StakingTx.TxHash().String()) require.NoError(t, err) covenantSigs := resp.BtcDelegation.UndelegationResponse.CovenantUnbondingSigList @@ -532,6 +523,22 @@ func (tm *TestManager) Undelegate( mBlock := tm.mineBlock(t) require.Equal(t, 2, len(mBlock.Transactions)) + catchUpLightClientFunc() + + unbondingTxInfo := getTxInfo(t, mBlock) + msgUndel := &bstypes.MsgBTCUndelegate{ + Signer: signerAddr, + StakingTxHash: stakingSlashingInfo.StakingTx.TxHash().String(), + StakeSpendingTx: unbondingTxBuf.Bytes(), + StakeSpendingTxInclusionProof: &bstypes.InclusionProof{ + Key: unbondingTxInfo.Key, + Proof: unbondingTxInfo.Proof, + }, + } + _, err = tm.BabylonClient.ReliablySendMsg(context.Background(), msgUndel, nil, nil) + require.NoError(t, err) + t.Logf("submitted MsgBTCUndelegate") + // wait until unbonding tx is on Bitcoin require.Eventually(t, func() bool { resp, err := tm.BTCClient.GetRawTransactionVerbose(unbondingTxHash)