Skip to content

Commit

Permalink
atomic slasher works, wip unbonding slasher
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Oct 23, 2024
1 parent 8775b06 commit 752dc39
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion e2etest/atomicslasher_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion e2etest/slasher_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 18 additions & 11 deletions e2etest/test_manager_btcstaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 752dc39

Please sign in to comment.