diff --git a/btcstaking-tracker/btcslasher/bootstrapping_test.go b/btcstaking-tracker/btcslasher/bootstrapping_test.go index 0ff2acf..c8a238b 100644 --- a/btcstaking-tracker/btcslasher/bootstrapping_test.go +++ b/btcstaking-tracker/btcslasher/bootstrapping_test.go @@ -75,7 +75,7 @@ func FuzzSlasher_Bootstrapping(f *testing.F) { require.NoError(t, err) // slashing address - slashingAddr, err := datagen.GenRandomBTCAddress(r, net) + slashingPkScript, err := datagen.GenRandomPubKeyHashScript(r, net) require.NoError(t, err) // mock BTC staking parameters @@ -116,7 +116,7 @@ func FuzzSlasher_Bootstrapping(f *testing.F) { covenantSks, covPks, bsParams.Params.CovenantQuorum, - slashingAddr.String(), + slashingPkScript, 100, 1100, delAmount, @@ -146,7 +146,7 @@ func FuzzSlasher_Bootstrapping(f *testing.F) { covenantSks, covPks, bsParams.Params.CovenantQuorum, - slashingAddr.String(), + slashingPkScript, 100, 1100, delAmount, diff --git a/btcstaking-tracker/btcslasher/slasher_test.go b/btcstaking-tracker/btcslasher/slasher_test.go index d5cc134..b8e23fa 100644 --- a/btcstaking-tracker/btcslasher/slasher_test.go +++ b/btcstaking-tracker/btcslasher/slasher_test.go @@ -87,7 +87,7 @@ func FuzzSlasher(f *testing.F) { require.NoError(t, err) // slashing and change address - slashingAddr, err := datagen.GenRandomBTCAddress(r, net) + slashingPkScript, err := datagen.GenRandomPubKeyHashScript(r, net) require.NoError(t, err) // generate BTC key pair for slashed finality provider @@ -111,7 +111,7 @@ func FuzzSlasher(f *testing.F) { covenantSks, covenantBtcPks, bsParams.Params.CovenantQuorum, - slashingAddr.String(), + slashingPkScript, 100, 1099, delAmount, @@ -138,7 +138,7 @@ func FuzzSlasher(f *testing.F) { covenantSks, covenantBtcPks, bsParams.Params.CovenantQuorum, - slashingAddr.String(), + slashingPkScript, 100, 1100, delAmount, @@ -165,7 +165,7 @@ func FuzzSlasher(f *testing.F) { covenantSks, covenantBtcPks, bsParams.Params.CovenantQuorum, - slashingAddr.String(), + slashingPkScript, 100, 1100, delAmount, @@ -202,7 +202,7 @@ func FuzzSlasher(f *testing.F) { outPoint, 1000, 9000, - slashingAddr.String(), + slashingPkScript, bsParams.Params.SlashingRate, unbondingTime, ) diff --git a/e2etest/atomicslasher_e2e_test.go b/e2etest/atomicslasher_e2e_test.go index 9dc1d2c..3a9e5d3 100644 --- a/e2etest/atomicslasher_e2e_test.go +++ b/e2etest/atomicslasher_e2e_test.go @@ -34,12 +34,10 @@ func TestAtomicSlasher(t *testing.T) { // Insert all existing BTC headers to babylon node tm.CatchUpBTCLightClient(t) - emptyHintCache := btcclient.EmptyHintCache{} - backend, err := btcclient.NewNodeBackend( btcclient.ToBitcoindConfig(tm.Config.BTC), &chaincfg.RegressionNetParams, - &emptyHintCache, + &btcclient.EmptyHintCache{}, ) require.NoError(t, err) @@ -49,7 +47,6 @@ func TestAtomicSlasher(t *testing.T) { commonCfg := config.DefaultCommonConfig() bstCfg := config.DefaultBTCStakingTrackerConfig() bstCfg.CheckDelegationsInterval = 1 * time.Second - metrics := metrics.NewBTCStakingTrackerMetrics() bsTracker := bst.NewBTCSTakingTracker( tm.BTCClient, @@ -58,7 +55,7 @@ func TestAtomicSlasher(t *testing.T) { &bstCfg, &commonCfg, zap.NewNop(), - metrics, + metrics.NewBTCStakingTrackerMetrics(), ) go bsTracker.Start() defer bsTracker.Stop() @@ -124,7 +121,9 @@ func TestAtomicSlasher(t *testing.T) { require.Eventually(t, func() bool { _, err := tm.BTCClient.GetRawTransaction(slashingTxHash2) - t.Logf("err of getting slashingTxHash of the BTC delegation affected by atomic slashing: %v", err) + if err != nil { + t.Logf("err of getting slashingTxHash of the BTC delegation affected by atomic slashing: %v", err) + } return err == nil }, eventuallyWaitTimeOut, eventuallyPollTime) diff --git a/e2etest/babylon_node_handler.go b/e2etest/babylon_node_handler.go index cf97358..4e8ce4e 100644 --- a/e2etest/babylon_node_handler.go +++ b/e2etest/babylon_node_handler.go @@ -123,7 +123,7 @@ type BabylonNodeHandler struct { babylonNode *babylonNode } -func NewBabylonNodeHandler(baseHeaderHex string, slashingAddress string, epochInterval uint) (*BabylonNodeHandler, error) { +func NewBabylonNodeHandler(baseHeaderHex string, slashingPkScript string, epochInterval uint) (*BabylonNodeHandler, error) { testDir, err := baseDirBabylondir() if err != nil { return nil, err @@ -141,8 +141,10 @@ func NewBabylonNodeHandler(baseHeaderHex string, slashingAddress string, epochIn "--btc-confirmation-depth=2", "--additional-sender-account", "--btc-network=regtest", + "--min-staking-time-blocks=200", + "--min-staking-amount-sat=10000", fmt.Sprintf("--epoch-interval=%d", epochInterval), - fmt.Sprintf("--slashing-address=%s", slashingAddress), + fmt.Sprintf("--slashing-pk-script=%s", slashingPkScript), fmt.Sprintf("--btc-base-header=%s", baseHeaderHex), "--covenant-quorum=1", fmt.Sprintf("--covenant-pks=%s", bbn.NewBIP340PubKeyFromBTCPK(juryPK).MarshalHex()), diff --git a/e2etest/test_manager.go b/e2etest/test_manager.go index 9aa8764..d8b4140 100644 --- a/e2etest/test_manager.go +++ b/e2etest/test_manager.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "github.com/btcsuite/btcd/txscript" "go.uber.org/zap" "testing" "time" @@ -116,8 +117,11 @@ func StartManager(t *testing.T, numMatureOutputsInWallet uint32, epochInterval u minerAddressDecoded, err := btcutil.DecodeAddress(blocksResponse.Address, regtestParams) require.NoError(t, err) + pkScript, err := txscript.PayToAddrScript(minerAddressDecoded) + require.NoError(t, err) + // start Babylon node - bh, err := NewBabylonNodeHandler(baseHeaderHex, minerAddressDecoded.EncodeAddress(), epochInterval) + bh, err := NewBabylonNodeHandler(baseHeaderHex, hex.EncodeToString(pkScript), epochInterval) require.NoError(t, err) err = bh.Start() require.NoError(t, err) diff --git a/e2etest/test_manager_btcstaking.go b/e2etest/test_manager_btcstaking.go index c8b1bcd..cb932c8 100644 --- a/e2etest/test_manager_btcstaking.go +++ b/e2etest/test_manager_btcstaking.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "fmt" - "math" "math/rand" "testing" "time" @@ -44,7 +43,7 @@ func (tm *TestManager) getBTCUnbondingTime(t *testing.T) uint64 { btccParams, err := tm.BabylonClient.BTCCheckpointParams() require.NoError(t, err) - return bstypes.MinimumUnbondingTime(bsParams.Params, btccParams.Params) + 1 + return bstypes.MinimumUnbondingTime(&bsParams.Params, &btccParams.Params) + 1 } func (tm *TestManager) CreateFinalityProvider(t *testing.T) (*bstypes.FinalityProvider, *btcec.PrivateKey) { @@ -91,7 +90,7 @@ func (tm *TestManager) CreateBTCDelegation( require.NoError(t, err) covenantBtcPks, err := bbnPksToBtcPks(bsParams.Params.CovenantPks) require.NoError(t, err) - stakingTimeBlocks := uint16(math.MaxUint16) + stakingTimeBlocks := bsParams.Params.MaxStakingTimeBlocks // get top UTXO topUnspentResult, _, err := tm.BTCClient.GetHighUTXOAndSum() require.NoError(t, err) @@ -110,9 +109,9 @@ func (tm *TestManager) CreateBTCDelegation( []*btcec.PublicKey{fpPK}, covenantBtcPks, bsParams.Params.CovenantQuorum, - stakingTimeBlocks, + uint16(stakingTimeBlocks), stakingValue, - bsParams.Params.SlashingAddress, + bsParams.Params.SlashingPkScript, bsParams.Params.SlashingRate, uint16(tm.getBTCUnbondingTime(t)), ) @@ -193,9 +192,9 @@ func (tm *TestManager) CreateBTCDelegation( covenantBtcPks, bsParams.Params.CovenantQuorum, wire.NewOutPoint(stakingMsgTxHash, stakingOutIdx), - stakingTimeBlocks, + uint16(stakingTimeBlocks), unbondingValue, - bsParams.Params.SlashingAddress, + bsParams.Params.SlashingPkScript, bsParams.Params.SlashingRate, uint16(tm.getBTCUnbondingTime(t)), ) diff --git a/go.mod b/go.mod index d5e72d6..9a57454 100644 --- a/go.mod +++ b/go.mod @@ -7,13 +7,14 @@ require ( cosmossdk.io/log v1.3.1 cosmossdk.io/math v1.3.0 github.com/avast/retry-go/v4 v4.6.0 - github.com/babylonlabs-io/babylon v0.9.1 + github.com/babylonlabs-io/babylon v0.9.3-0.20240904123958-b1e255a85e76 github.com/boljen/go-bitmap v0.0.0-20151001105940-23cd2fb0ce7d github.com/btcsuite/btcd v0.24.2 github.com/btcsuite/btcd/btcec/v2 v2.3.2 github.com/btcsuite/btcd/btcutil v1.1.5 github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 github.com/btcsuite/btcwallet v0.16.10-0.20230621165747-9c21f464ce13 + github.com/btcsuite/btcwallet/walletdb v1.4.0 github.com/cometbft/cometbft v0.38.7 github.com/cosmos/cosmos-sdk v0.50.6 github.com/cosmos/relayer/v2 v2.5.1 @@ -25,6 +26,7 @@ require ( github.com/jinzhu/copier v0.3.5 github.com/jsternberg/zap-logfmt v1.3.0 github.com/lightningnetwork/lnd v0.16.4-beta.rc1 + github.com/lightningnetwork/lnd/kvdb v1.4.1 github.com/ory/dockertest/v3 v3.9.1 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.19.0 @@ -80,7 +82,6 @@ require ( github.com/btcsuite/btcwallet/wallet/txauthor v1.3.2 // indirect github.com/btcsuite/btcwallet/wallet/txrules v1.2.0 // indirect github.com/btcsuite/btcwallet/wallet/txsizes v1.2.3 // indirect - github.com/btcsuite/btcwallet/walletdb v1.4.0 // indirect github.com/btcsuite/btcwallet/wtxmgr v1.5.0 // indirect github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 // indirect @@ -217,7 +218,6 @@ require ( github.com/lightningnetwork/lightning-onion v1.2.1-0.20221202012345-ca23184850a1 // indirect github.com/lightningnetwork/lnd/clock v1.1.0 // indirect github.com/lightningnetwork/lnd/healthcheck v1.2.2 // indirect - github.com/lightningnetwork/lnd/kvdb v1.4.1 // indirect github.com/lightningnetwork/lnd/queue v1.1.0 // indirect github.com/lightningnetwork/lnd/ticker v1.1.0 // indirect github.com/lightningnetwork/lnd/tlv v1.1.0 // indirect diff --git a/go.sum b/go.sum index 7ad26ea..8a3bd0b 100644 --- a/go.sum +++ b/go.sum @@ -283,8 +283,8 @@ github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX github.com/aws/aws-sdk-go v1.44.312 h1:llrElfzeqG/YOLFFKjg1xNpZCFJ2xraIi3PqSuP+95k= github.com/aws/aws-sdk-go v1.44.312/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= -github.com/babylonlabs-io/babylon v0.9.1 h1:V7PtWgUAQa0kxFOwOuGvh0rKXyqiY6JheTZdfyeEkBk= -github.com/babylonlabs-io/babylon v0.9.1/go.mod h1:t7B4e+ooD2oYvAxkegtNKDL9bXe+vU29a8xnCQh+UKo= +github.com/babylonlabs-io/babylon v0.9.3-0.20240904123958-b1e255a85e76 h1:JOdd2H+bOYPyKYNyCcjT2lW7H76A4Pbfstk7n/Vo2Vc= +github.com/babylonlabs-io/babylon v0.9.3-0.20240904123958-b1e255a85e76/go.mod h1:9VUUAwVaalXiDdPZT65SPoawKWpp6ple6tBr8Vw0NI8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= diff --git a/tools/go.mod b/tools/go.mod index 6f7f46d..3a8f9e7 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -2,7 +2,7 @@ module github.com/babylonlabs-io/vigilante/tools go 1.23 -require github.com/babylonlabs-io/babylon v0.9.1 +require github.com/babylonlabs-io/babylon v0.9.3-0.20240904123958-b1e255a85e76 require ( cloud.google.com/go v0.112.0 // indirect diff --git a/tools/go.sum b/tools/go.sum index b6ffb2f..f1bb017 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -270,8 +270,8 @@ github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX github.com/aws/aws-sdk-go v1.44.312 h1:llrElfzeqG/YOLFFKjg1xNpZCFJ2xraIi3PqSuP+95k= github.com/aws/aws-sdk-go v1.44.312/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= -github.com/babylonlabs-io/babylon v0.9.1 h1:V7PtWgUAQa0kxFOwOuGvh0rKXyqiY6JheTZdfyeEkBk= -github.com/babylonlabs-io/babylon v0.9.1/go.mod h1:t7B4e+ooD2oYvAxkegtNKDL9bXe+vU29a8xnCQh+UKo= +github.com/babylonlabs-io/babylon v0.9.3-0.20240904123958-b1e255a85e76 h1:JOdd2H+bOYPyKYNyCcjT2lW7H76A4Pbfstk7n/Vo2Vc= +github.com/babylonlabs-io/babylon v0.9.3-0.20240904123958-b1e255a85e76/go.mod h1:9VUUAwVaalXiDdPZT65SPoawKWpp6ple6tBr8Vw0NI8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=