diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ae84a50a..76942b528 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -191,3 +191,6 @@ jobs: - name: Run e2e TestSoftwareUpgradeV1TestnetTestSuite run: | sudo make test-e2e-cache-upgrade-v1 + - name: Dump docker logs on failure + if: failure() + uses: jwalton/gh-docker-logs@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index baca4a0a1..c54a424d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ in checkpointing module implementation * [#254](https://github.com/babylonlabs-io/babylon/pull/254) Avoid constant bech-32 decoding in power table +* [#265](https://github.com/babylonlabs-io/babylon/pull/265) Add allow list for staking txs ## v0.15.0 diff --git a/app/include_upgrade_mainnet.go b/app/include_upgrade_mainnet.go index 87f7d77ad..4d492254d 100644 --- a/app/include_upgrade_mainnet.go +++ b/app/include_upgrade_mainnet.go @@ -11,11 +11,12 @@ import ( // init is used to include v1 upgrade for mainnet data func init() { Upgrades = []upgrades.Upgrade{v1.CreateUpgrade(v1.UpgradeDataString{ - BtcStakingParamStr: mainnet.BtcStakingParamStr, - FinalityParamStr: mainnet.FinalityParamStr, - IncentiveParamStr: mainnet.IncentiveParamStr, - CosmWasmParamStr: mainnet.CosmWasmParamStr, - NewBtcHeadersStr: mainnet.NewBtcHeadersStr, - TokensDistributionStr: mainnet.TokensDistributionStr, + BtcStakingParamStr: mainnet.BtcStakingParamStr, + FinalityParamStr: mainnet.FinalityParamStr, + IncentiveParamStr: mainnet.IncentiveParamStr, + CosmWasmParamStr: mainnet.CosmWasmParamStr, + NewBtcHeadersStr: mainnet.NewBtcHeadersStr, + TokensDistributionStr: mainnet.TokensDistributionStr, + AllowedStakingTxHashesStr: mainnet.AllowedStakingTxHashesStr, })} } diff --git a/app/include_upgrade_testnet.go b/app/include_upgrade_testnet.go index 483d719b2..15f974952 100644 --- a/app/include_upgrade_testnet.go +++ b/app/include_upgrade_testnet.go @@ -12,11 +12,12 @@ import ( // it is also used for e2e testing func init() { Upgrades = []upgrades.Upgrade{v1.CreateUpgrade(v1.UpgradeDataString{ - BtcStakingParamStr: testnet.BtcStakingParamStr, - FinalityParamStr: testnet.FinalityParamStr, - IncentiveParamStr: testnet.IncentiveParamStr, - CosmWasmParamStr: testnet.CosmWasmParamStr, - NewBtcHeadersStr: testnet.NewBtcHeadersStr, - TokensDistributionStr: testnet.TokensDistributionStr, + BtcStakingParamStr: testnet.BtcStakingParamStr, + FinalityParamStr: testnet.FinalityParamStr, + IncentiveParamStr: testnet.IncentiveParamStr, + CosmWasmParamStr: testnet.CosmWasmParamStr, + NewBtcHeadersStr: testnet.NewBtcHeadersStr, + TokensDistributionStr: testnet.TokensDistributionStr, + AllowedStakingTxHashesStr: testnet.AllowedStakingTxHashesStr, })} } diff --git a/app/upgrades/v1/README.md b/app/upgrades/v1/README.md index 1323039be..518d3a472 100644 --- a/app/upgrades/v1/README.md +++ b/app/upgrades/v1/README.md @@ -35,8 +35,10 @@ This upgrade loads 5 JSONs from strings in different files. - BTC Headers at `./data_btc_headers.go` - Tokens distribution at `./data_token_distribution.go` - BTC Staking Parameters `./btcstaking_params.go` +- Incentive Parameters `./incentive.go` - Finality Parameters `./finality_params.go` - CosmWasm Parameters `./cosmwasm_params.go` +- Allowed Staking Tx Hashes `./allowed_staking_tx_hashes.go` ### BTC Headers diff --git a/app/upgrades/v1/data_allowed_staking_tx_hashes_test.go b/app/upgrades/v1/data_allowed_staking_tx_hashes_test.go new file mode 100644 index 000000000..0133096db --- /dev/null +++ b/app/upgrades/v1/data_allowed_staking_tx_hashes_test.go @@ -0,0 +1,23 @@ +package v1_test + +import ( + "testing" + + v1 "github.com/babylonlabs-io/babylon/app/upgrades/v1" + "github.com/btcsuite/btcd/chaincfg/chainhash" + "github.com/stretchr/testify/require" +) + +func TestLoadAllowedStakingTxHashesFromData(t *testing.T) { + for _, upgradeData := range UpgradeV1Data { + d, err := v1.LoadAllowedStakingTransactionHashesFromData(upgradeData.AllowedStakingTxHashesStr) + require.NoError(t, err) + require.NotNil(t, d) + require.Greater(t, len(d.TxHashes), 0) + + for _, txHash := range d.TxHashes { + _, err := chainhash.NewHashFromStr(txHash) + require.NoError(t, err) + } + } +} diff --git a/app/upgrades/v1/mainnet/allowed_staking_tx_hashes.go b/app/upgrades/v1/mainnet/allowed_staking_tx_hashes.go new file mode 100644 index 000000000..ce4c7ff29 --- /dev/null +++ b/app/upgrades/v1/mainnet/allowed_staking_tx_hashes.go @@ -0,0 +1,9 @@ +package mainnet + +// TODO: Specify allowed staking tx hashes for v1 upgrade for mainnet +const AllowedStakingTxHashesStr = `{ + "tx_hashes": [ + "90463a1e0b19137f07c304f2c1c79351fa6f97f1195f1f90dc0b3b57893a350d", + "1db6de324beefd6870ec62a7385cac7144a43eba8e61fca202a8b41d963680ef" + ] +}` diff --git a/app/upgrades/v1/mainnet/btcstaking_params.go b/app/upgrades/v1/mainnet/btcstaking_params.go index a9cc60135..da035c579 100644 --- a/app/upgrades/v1/mainnet/btcstaking_params.go +++ b/app/upgrades/v1/mainnet/btcstaking_params.go @@ -21,5 +21,7 @@ const BtcStakingParamStr = ` "slashing_rate": "0.100000000000000000", "min_unbonding_time_blocks": 0, "unbonding_fee_sat": "1000", - "min_commission_rate": "0.03" + "min_commission_rate": "0.03", + "delegation_creation_base_gas_fee": 1000, + "allow_list_expiration_height": 0 }` diff --git a/app/upgrades/v1/testnet/allowed_staking_tx_hashes.go b/app/upgrades/v1/testnet/allowed_staking_tx_hashes.go new file mode 100644 index 000000000..56fa315f6 --- /dev/null +++ b/app/upgrades/v1/testnet/allowed_staking_tx_hashes.go @@ -0,0 +1,9 @@ +package testnet + +// TODO: Specify allowed staking tx hashes for v1 upgrade for testnet +const AllowedStakingTxHashesStr = `{ + "tx_hashes": [ + "a3572b22571b46b7688fbfe1e8aeee82bb772d52c5ddb069cda361dc33fb4191", + "276a2b384614976c9a6a737f347e981b91f4dc269ee510a6f71e5eec9ecb903a" + ] +}` diff --git a/app/upgrades/v1/testnet/btcstaking_params.go b/app/upgrades/v1/testnet/btcstaking_params.go index 7ae78e02f..a83dabacc 100644 --- a/app/upgrades/v1/testnet/btcstaking_params.go +++ b/app/upgrades/v1/testnet/btcstaking_params.go @@ -22,5 +22,6 @@ const BtcStakingParamStr = ` "min_unbonding_time_blocks": 0, "unbonding_fee_sat": "1000", "min_commission_rate": "0.03", - "delegation_creation_base_gas_fee": 1000 + "delegation_creation_base_gas_fee": 1000, + "allow_list_expiration_height": 0 }` diff --git a/app/upgrades/v1/types.go b/app/upgrades/v1/types.go index 0c4e3f1ce..d4a46f783 100644 --- a/app/upgrades/v1/types.go +++ b/app/upgrades/v1/types.go @@ -1,12 +1,13 @@ package v1 type UpgradeDataString struct { - BtcStakingParamStr string - FinalityParamStr string - IncentiveParamStr string - CosmWasmParamStr string - NewBtcHeadersStr string - TokensDistributionStr string + BtcStakingParamStr string + FinalityParamStr string + IncentiveParamStr string + CosmWasmParamStr string + NewBtcHeadersStr string + TokensDistributionStr string + AllowedStakingTxHashesStr string } type DataTokenDistribution struct { @@ -16,3 +17,7 @@ type DataTokenDistribution struct { Amount int64 `json:"amount"` } `json:"token_distribution"` } + +type AllowedStakingTransactionHashes struct { + TxHashes []string `json:"tx_hashes"` +} diff --git a/app/upgrades/v1/upgrades.go b/app/upgrades/v1/upgrades.go index 1eb626546..69995905a 100644 --- a/app/upgrades/v1/upgrades.go +++ b/app/upgrades/v1/upgrades.go @@ -16,6 +16,7 @@ import ( wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" "github.com/btcsuite/btcd/chaincfg" + "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -63,7 +64,7 @@ func CreateUpgradeHandler(upgradeDataStr UpgradeDataString) upgrades.UpgradeHand migrations, err := mm.RunMigrations(ctx, cfg, fromVM) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to run migrations: %w", err) } // Re-initialise the mint module as we have replaced Cosmos SDK's @@ -76,7 +77,7 @@ func CreateUpgradeHandler(upgradeDataStr UpgradeDataString) upgrades.UpgradeHand keepers.StakingKeeper, ) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to upgrade mint module: %w", err) } err = upgradeParameters( @@ -92,19 +93,21 @@ func CreateUpgradeHandler(upgradeDataStr UpgradeDataString) upgrades.UpgradeHand upgradeDataStr.CosmWasmParamStr, ) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to upgrade parameters: %w", err) } err = upgradeLaunch( ctx, keepers.EncCfg, &keepers.BTCLightClientKeeper, + &keepers.BTCStakingKeeper, keepers.BankKeeper, upgradeDataStr.NewBtcHeadersStr, upgradeDataStr.TokensDistributionStr, + upgradeDataStr.AllowedStakingTxHashesStr, ) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to upgrade inserting additional data: %w", err) } return migrations, nil @@ -140,16 +143,20 @@ func upgradeParameters( ) error { // Upgrade the staking parameters as first, as other upgrades depend on it. if err := upgradeBtcStakingParameters(ctx, cdc, btcK, btcStakingParam); err != nil { - return err + return fmt.Errorf("failed to upgrade btc staking parameters: %w", err) } if err := upgradeFinalityParameters(ctx, cdc, finK, finalityParam); err != nil { - return err + return fmt.Errorf("failed to upgrade finality parameters: %w", err) } if err := upgradeIncentiveParameters(ctx, cdc, iK, incentiveParam); err != nil { return err } - return upgradeCosmWasmParameters(ctx, cdc, wasmK, wasmParam) + if err := upgradeCosmWasmParameters(ctx, cdc, wasmK, wasmParam); err != nil { + return fmt.Errorf("failed to upgrade cosmwasm parameters: %w", err) + } + + return nil } func upgradeIncentiveParameters( @@ -217,14 +224,23 @@ func upgradeLaunch( ctx sdk.Context, encCfg *appparams.EncodingConfig, btcLigthK *btclightkeeper.Keeper, + btcK *btcstkkeeper.Keeper, bankK bankkeeper.SendKeeper, - btcHeaders, tokensDistribution string, + btcHeaders, tokensDistribution, allowedStakingTxHashes string, ) error { if err := upgradeTokensDistribution(ctx, bankK, tokensDistribution); err != nil { - return err + return fmt.Errorf("failed to upgrade tokens distribution: %w", err) } - return upgradeBTCHeaders(ctx, encCfg.Codec, btcLigthK, btcHeaders) + if err := upgradeAllowedStakingTransactions(ctx, encCfg.Codec, btcK, allowedStakingTxHashes); err != nil { + return fmt.Errorf("failed to upgrade allowed staking transactions: %w", err) + } + + if err := upgradeBTCHeaders(ctx, encCfg.Codec, btcLigthK, btcHeaders); err != nil { + return fmt.Errorf("failed to upgrade btc headers: %w", err) + } + + return nil } func upgradeTokensDistribution(ctx sdk.Context, bankK bankkeeper.SendKeeper, tokensDistribution string) error { @@ -253,6 +269,23 @@ func upgradeTokensDistribution(ctx sdk.Context, bankK bankkeeper.SendKeeper, tok return nil } +func upgradeAllowedStakingTransactions(ctx sdk.Context, cdc codec.Codec, btcStakingK *btcstkkeeper.Keeper, allowedStakingTxHashes string) error { + data, err := LoadAllowedStakingTransactionHashesFromData(allowedStakingTxHashes) + if err != nil { + return fmt.Errorf("failed to load allowed staking transaction hashes from string %s: %w", allowedStakingTxHashes, err) + } + + for _, txHash := range data.TxHashes { + hash, err := chainhash.NewHashFromStr(txHash) + if err != nil { + return fmt.Errorf("failed to parse tx hash: %w", err) + } + btcStakingK.IndexAllowedStakingTransaction(ctx, hash) + } + + return nil +} + func upgradeBTCHeaders(ctx sdk.Context, cdc codec.Codec, btcLigthK *btclightkeeper.Keeper, btcHeaders string) error { newHeaders, err := LoadBTCHeadersFromData(cdc, btcHeaders) if err != nil { @@ -336,6 +369,18 @@ func LoadTokenDistributionFromData(data string) (DataTokenDistribution, error) { return d, nil } +func LoadAllowedStakingTransactionHashesFromData(data string) (*AllowedStakingTransactionHashes, error) { + buff := bytes.NewBufferString(data) + + var d AllowedStakingTransactionHashes + err := json.Unmarshal(buff.Bytes(), &d) + if err != nil { + return nil, err + } + + return &d, nil +} + func insertBtcHeaders( ctx sdk.Context, k *btclightkeeper.Keeper, diff --git a/app/upgrades/v1/upgrades_test.go b/app/upgrades/v1/upgrades_test.go index 1e15b5a0e..3960ebc5d 100644 --- a/app/upgrades/v1/upgrades_test.go +++ b/app/upgrades/v1/upgrades_test.go @@ -21,6 +21,7 @@ import ( "github.com/babylonlabs-io/babylon/test/e2e/util" "github.com/babylonlabs-io/babylon/testutil/datagen" minttypes "github.com/babylonlabs-io/babylon/x/mint/types" + "github.com/btcsuite/btcd/chaincfg/chainhash" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -45,20 +46,22 @@ var ( wasmContract []byte UpgradeV1DataTestnet = v1.UpgradeDataString{ - BtcStakingParamStr: testnetdata.BtcStakingParamStr, - FinalityParamStr: testnetdata.FinalityParamStr, - IncentiveParamStr: testnetdata.IncentiveParamStr, - CosmWasmParamStr: testnetdata.CosmWasmParamStr, - NewBtcHeadersStr: testnetdata.NewBtcHeadersStr, - TokensDistributionStr: testnetdata.TokensDistributionStr, + BtcStakingParamStr: testnetdata.BtcStakingParamStr, + FinalityParamStr: testnetdata.FinalityParamStr, + IncentiveParamStr: testnetdata.IncentiveParamStr, + CosmWasmParamStr: testnetdata.CosmWasmParamStr, + NewBtcHeadersStr: testnetdata.NewBtcHeadersStr, + TokensDistributionStr: testnetdata.TokensDistributionStr, + AllowedStakingTxHashesStr: testnetdata.AllowedStakingTxHashesStr, } UpgradeV1DataMainnet = v1.UpgradeDataString{ - BtcStakingParamStr: mainnetdata.BtcStakingParamStr, - FinalityParamStr: mainnetdata.FinalityParamStr, - IncentiveParamStr: mainnetdata.IncentiveParamStr, - CosmWasmParamStr: mainnetdata.CosmWasmParamStr, - NewBtcHeadersStr: mainnetdata.NewBtcHeadersStr, - TokensDistributionStr: mainnetdata.TokensDistributionStr, + BtcStakingParamStr: mainnetdata.BtcStakingParamStr, + FinalityParamStr: mainnetdata.FinalityParamStr, + IncentiveParamStr: mainnetdata.IncentiveParamStr, + CosmWasmParamStr: mainnetdata.CosmWasmParamStr, + NewBtcHeadersStr: mainnetdata.NewBtcHeadersStr, + TokensDistributionStr: mainnetdata.TokensDistributionStr, + AllowedStakingTxHashesStr: mainnetdata.AllowedStakingTxHashesStr, } UpgradeV1Data = []v1.UpgradeDataString{UpgradeV1DataTestnet, UpgradeV1DataMainnet} ) @@ -300,4 +303,19 @@ func (s *UpgradeTestSuite) PostUpgrade() { upgradeWasmParams, err := v1.LoadCosmWasmParamsFromData(s.app.AppCodec(), s.upgradeDataStr.CosmWasmParamStr) s.NoError(err) s.EqualValues(chainWasmParams, upgradeWasmParams) + + allowedStakingTxHashes, err := v1.LoadAllowedStakingTransactionHashesFromData(s.upgradeDataStr.AllowedStakingTxHashesStr) + s.NoError(err) + s.NotNil(allowedStakingTxHashes) + s.Greater(len(allowedStakingTxHashes.TxHashes), 0) + + for _, txHash := range allowedStakingTxHashes.TxHashes { + hash, err := chainhash.NewHashFromStr(txHash) + s.NoError(err) + + s.True(s.app.BTCStakingKeeper.IsStakingTransactionAllowed(s.ctx, hash)) + } + + nonExistentTxHash := chainhash.Hash{} + s.False(s.app.BTCStakingKeeper.IsStakingTransactionAllowed(s.ctx, &nonExistentTxHash)) } diff --git a/proto/babylon/btcstaking/v1/params.proto b/proto/babylon/btcstaking/v1/params.proto index 8ceb86c70..862a3756d 100644 --- a/proto/babylon/btcstaking/v1/params.proto +++ b/proto/babylon/btcstaking/v1/params.proto @@ -55,6 +55,10 @@ message Params { ]; // base gas fee for delegation creation uint64 delegation_creation_base_gas_fee = 13; + // allow_list_expiration_height is the height at which the allow list expires + // i.e all staking transactions are allowed to enter Babylon chain afterwards + // setting it to 0 means allow list is disabled + uint64 allow_list_expiration_height = 14; } // StoredParams attach information about the version of stored parameters diff --git a/testutil/btcstaking-helper/keeper.go b/testutil/btcstaking-helper/keeper.go index 4e1953c23..88b56ec21 100644 --- a/testutil/btcstaking-helper/keeper.go +++ b/testutil/btcstaking-helper/keeper.go @@ -85,7 +85,7 @@ func NewHelper( err = fk.SetParams(ctx, ftypes.DefaultParams()) require.NoError(t, err) - ctx = ctx.WithHeaderInfo(header.Info{Height: 1}) + ctx = ctx.WithHeaderInfo(header.Info{Height: 1}).WithBlockHeight(1) return &Helper{ t: t, @@ -124,7 +124,7 @@ func (h *Helper) BeginBlocker() { } func (h *Helper) GenAndApplyParams(r *rand.Rand) ([]*btcec.PrivateKey, []*btcec.PublicKey) { - return h.GenAndApplyCustomParams(r, 100, 0) + return h.GenAndApplyCustomParams(r, 100, 0, 0) } func (h *Helper) SetCtxHeight(height uint64) { @@ -135,6 +135,7 @@ func (h *Helper) GenAndApplyCustomParams( r *rand.Rand, finalizationTimeout uint32, minUnbondingTime uint32, + allowListExpirationHeight uint64, ) ([]*btcec.PrivateKey, []*btcec.PublicKey) { // mock base header baseHeader := btclctypes.SimnetGenesisBlock() @@ -153,18 +154,19 @@ func (h *Helper) GenAndApplyCustomParams( slashingPkScript, err := txscript.PayToAddrScript(slashingAddress) h.NoError(err) err = h.BTCStakingKeeper.SetParams(h.Ctx, types.Params{ - CovenantPks: bbn.NewBIP340PKsFromBTCPKs(covenantPKs), - CovenantQuorum: 3, - MinStakingValueSat: 1000, - MaxStakingValueSat: int64(4 * 10e8), - MinStakingTimeBlocks: 10, - MaxStakingTimeBlocks: 10000, - SlashingPkScript: slashingPkScript, - MinSlashingTxFeeSat: 10, - MinCommissionRate: sdkmath.LegacyMustNewDecFromStr("0.01"), - SlashingRate: sdkmath.LegacyNewDecWithPrec(int64(datagen.RandomInt(r, 41)+10), 2), - MinUnbondingTimeBlocks: minUnbondingTime, - UnbondingFeeSat: 1000, + CovenantPks: bbn.NewBIP340PKsFromBTCPKs(covenantPKs), + CovenantQuorum: 3, + MinStakingValueSat: 1000, + MaxStakingValueSat: int64(4 * 10e8), + MinStakingTimeBlocks: 10, + MaxStakingTimeBlocks: 10000, + SlashingPkScript: slashingPkScript, + MinSlashingTxFeeSat: 10, + MinCommissionRate: sdkmath.LegacyMustNewDecFromStr("0.01"), + SlashingRate: sdkmath.LegacyNewDecWithPrec(int64(datagen.RandomInt(r, 41)+10), 2), + MinUnbondingTimeBlocks: minUnbondingTime, + UnbondingFeeSat: 1000, + AllowListExpirationHeight: allowListExpirationHeight, }) h.NoError(err) return covenantSKs, covenantPKs @@ -213,6 +215,7 @@ func (h *Helper) CreateDelegation( unbondingValue int64, unbondingTime uint16, usePreApproval bool, + addToAllowList bool, ) (string, *types.MsgCreateBTCDelegation, *types.BTCDelegation, *btclctypes.BTCHeaderInfo, *types.InclusionProof, *UnbondingTxInfo, error) { stakingTimeBlocks := stakingTime bsParams := h.BTCStakingKeeper.GetParams(h.Ctx) @@ -344,6 +347,10 @@ func (h *Helper) CreateDelegation( msgCreateBTCDel.StakingTxInclusionProof = txInclusionProof } + if addToAllowList { + h.BTCStakingKeeper.IndexAllowedStakingTransaction(h.Ctx, &stkTxHash) + } + _, err = h.MsgServer.CreateBTCDelegation(h.Ctx, msgCreateBTCDel) if err != nil { return "", nil, nil, nil, nil, nil, err diff --git a/x/btcstaking/keeper/allowed_transaction_index.go b/x/btcstaking/keeper/allowed_transaction_index.go new file mode 100644 index 000000000..d3e482f06 --- /dev/null +++ b/x/btcstaking/keeper/allowed_transaction_index.go @@ -0,0 +1,24 @@ +package keeper + +import ( + "context" + + "github.com/btcsuite/btcd/chaincfg/chainhash" +) + +// IndexAllowedStakingTransaction indexes the given allowed staking transaction by its hash. +func (k Keeper) IndexAllowedStakingTransaction(ctx context.Context, txHash *chainhash.Hash) { + err := k.AllowedStakingTxHashesKeySet.Set(ctx, txHash[:]) + if err != nil { + panic(err) // encoding issue; this can only be a programming error + } +} + +// IsStakingTransactionAllowed checks if the given staking transaction is allowed. +func (k Keeper) IsStakingTransactionAllowed(ctx context.Context, txHash *chainhash.Hash) bool { + has, err := k.AllowedStakingTxHashesKeySet.Has(ctx, txHash[:]) + if err != nil { + panic(err) // encoding issue; this can only be a programming error + } + return has +} diff --git a/x/btcstaking/keeper/bench_test.go b/x/btcstaking/keeper/bench_test.go index 7fc14f9ab..9ef591a14 100644 --- a/x/btcstaking/keeper/bench_test.go +++ b/x/btcstaking/keeper/bench_test.go @@ -66,6 +66,7 @@ func benchBeginBlock(b *testing.B, numFPs int, numDelsUnderFP int) { 0, 0, true, + false, ) h.NoError(err) // retrieve BTC delegation in DB diff --git a/x/btcstaking/keeper/keeper.go b/x/btcstaking/keeper/keeper.go index 872d3bd1a..0720bc231 100644 --- a/x/btcstaking/keeper/keeper.go +++ b/x/btcstaking/keeper/keeper.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "cosmossdk.io/collections" corestoretypes "cosmossdk.io/core/store" "cosmossdk.io/log" @@ -23,6 +24,9 @@ type ( btccKeeper types.BtcCheckpointKeeper iKeeper types.IncentiveKeeper + Schema collections.Schema + AllowedStakingTxHashesKeySet collections.KeySet[[]byte] + btcNet *chaincfg.Params // the address capable of executing a MsgUpdateParams message. Typically, this // should be the x/gov module account. @@ -41,7 +45,9 @@ func NewKeeper( btcNet *chaincfg.Params, authority string, ) Keeper { - return Keeper{ + sb := collections.NewSchemaBuilder(storeService) + + k := Keeper{ cdc: cdc, storeService: storeService, @@ -49,9 +55,23 @@ func NewKeeper( btccKeeper: btccKeeper, iKeeper: iKeeper, + AllowedStakingTxHashesKeySet: collections.NewKeySet( + sb, + types.AllowedStakingTxHashesKey, + "allowed_staking_tx_hashes_key_set", + collections.BytesKey, + ), btcNet: btcNet, authority: authority, } + + schema, err := sb.Build() + if err != nil { + panic(err) + } + k.Schema = schema + + return k } func (k Keeper) Logger(ctx sdk.Context) log.Logger { diff --git a/x/btcstaking/keeper/msg_server.go b/x/btcstaking/keeper/msg_server.go index 73d73fea2..1159835d5 100644 --- a/x/btcstaking/keeper/msg_server.go +++ b/x/btcstaking/keeper/msg_server.go @@ -132,12 +132,21 @@ func (ms msgServer) EditFinalityProvider(goCtx context.Context, req *types.MsgEd return &types.MsgEditFinalityProviderResponse{}, nil } +// isAllowListEnabled checks if the allow list is enabled at the given height +// allow list is enabled if AllowListExpirationHeight is larger than 0, +// and current block height is less than AllowListExpirationHeight +func (ms msgServer) isAllowListEnabled(ctx sdk.Context, p *types.Params) bool { + return p.AllowListExpirationHeight > 0 && uint64(ctx.BlockHeight()) < p.AllowListExpirationHeight +} + // CreateBTCDelegation creates a BTC delegation func (ms msgServer) CreateBTCDelegation(goCtx context.Context, req *types.MsgCreateBTCDelegation) (*types.MsgCreateBTCDelegationResponse, error) { defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), types.MetricsKeyCreateBTCDelegation) ctx := sdk.UnwrapSDKContext(goCtx) + vp := ms.GetParamsWithVersion(ctx) + // 1. Parse the message into better domain format parsedMsg, err := types.ParseCreateDelegationMessage(req) @@ -172,9 +181,15 @@ func (ms msgServer) CreateBTCDelegation(goCtx context.Context, req *types.MsgCre } } - // 5. Validate parsed message against parameters - vp := ms.GetParamsWithVersion(ctx) + // 5. if allow list is enabled we need to check whether staking transactions hash + // is in the allow list + if ms.isAllowListEnabled(ctx, &vp.Params) { + if !ms.IsStakingTransactionAllowed(ctx, &stakingTxHash) { + return nil, types.ErrInvalidStakingTx.Wrapf("staking tx hash: %s, is not in the allow list", stakingTxHash.String()) + } + } + // 6. Validate parsed message against parameters btccParams := ms.btccKeeper.GetParams(ctx) paramsValidationResult, err := types.ValidateParsedMessageAgainstTheParams(parsedMsg, &vp.Params, &btccParams, ms.btcNet) @@ -183,7 +198,7 @@ func (ms msgServer) CreateBTCDelegation(goCtx context.Context, req *types.MsgCre return nil, err } - // 6. If the delegation contains the inclusion proof, we need to verify the proof + // 7. If the delegation contains the inclusion proof, we need to verify the proof // and set start height and end height var startHeight, endHeight uint32 if parsedMsg.StakingTxProofOfInclusion != nil { @@ -206,7 +221,7 @@ func (ms msgServer) CreateBTCDelegation(goCtx context.Context, req *types.MsgCre ctx.GasMeter().ConsumeGas(vp.Params.DelegationCreationBaseGasFee, "delegation creation fee") } - // 7.all good, construct BTCDelegation and insert BTC delegation + // 8.all good, construct BTCDelegation and insert BTC delegation // NOTE: the BTC delegation does not have voting power yet. It will // have voting power only when it receives a covenant signatures newBTCDel := &types.BTCDelegation{ diff --git a/x/btcstaking/keeper/msg_server_test.go b/x/btcstaking/keeper/msg_server_test.go index 3f51d03c2..eba55bffe 100644 --- a/x/btcstaking/keeper/msg_server_test.go +++ b/x/btcstaking/keeper/msg_server_test.go @@ -174,6 +174,7 @@ func FuzzCreateBTCDelegation(f *testing.F) { 0, 0, usePreApproval, + false, ) h.NoError(err) @@ -233,6 +234,7 @@ func TestProperVersionInDelegation(t *testing.T) { 0, 0, false, + false, ) h.NoError(err) @@ -263,6 +265,7 @@ func TestProperVersionInDelegation(t *testing.T) { stakingValue-1000, uint16(customMinUnbondingTime)+1, false, + false, ) h.NoError(err) actualDel1, err := h.BTCStakingKeeper.GetBTCDelegation(h.Ctx, stakingTxHash1) @@ -311,6 +314,7 @@ func FuzzAddCovenantSigs(f *testing.F) { 0, 0, usePreApproval, + false, ) h.NoError(err) @@ -393,6 +397,7 @@ func FuzzAddBTCDelegationInclusionProof(f *testing.F) { 0, 0, true, + false, ) h.NoError(err) @@ -465,6 +470,7 @@ func FuzzBTCUndelegate(f *testing.F) { 0, 0, true, + false, ) h.NoError(err) @@ -543,6 +549,7 @@ func FuzzSelectiveSlashing(f *testing.F) { 0, 0, true, + false, ) h.NoError(err) @@ -619,6 +626,7 @@ func FuzzSelectiveSlashing_StakingTx(f *testing.F) { 0, 0, true, + false, ) h.NoError(err) @@ -847,7 +855,7 @@ func TestCorrectUnbondingTimeInDelegation(t *testing.T) { h := testutil.NewHelper(t, btclcKeeper, btccKeeper) // set all parameters - _, _ = h.GenAndApplyCustomParams(r, tt.finalizationTimeout, tt.minUnbondingTime) + _, _ = h.GenAndApplyCustomParams(r, tt.finalizationTimeout, tt.minUnbondingTime, 0) changeAddress, err := datagen.GenRandomBTCAddress(r, h.Net) require.NoError(t, err) @@ -869,6 +877,7 @@ func TestCorrectUnbondingTimeInDelegation(t *testing.T) { stakingValue-1000, tt.unbondingTimeInDelegation, true, + false, ) if tt.err != nil { require.Error(t, err) @@ -884,6 +893,88 @@ func TestCorrectUnbondingTimeInDelegation(t *testing.T) { } } +func TestAllowList(t *testing.T) { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + // mock BTC light client and BTC checkpoint modules + btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) + btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) + h := testutil.NewHelper(t, btclcKeeper, btccKeeper) + + allowListExpirationHeight := uint64(10) + // set all parameters, use the allow list + h.GenAndApplyCustomParams(r, 100, 0, allowListExpirationHeight) + + changeAddress, err := datagen.GenRandomBTCAddress(r, h.Net) + require.NoError(t, err) + + // generate and insert new finality provider + _, fpPK, _ := h.CreateFinalityProvider(r) + + usePreApproval := datagen.OneInN(r, 2) + + // generate and insert new BTC delegation + stakingValue := int64(2 * 10e8) + delSK, _, err := datagen.GenRandomBTCKeyPair(r) + h.NoError(err) + _, msgCreateBTCDel, _, _, _, _, err := h.CreateDelegation( + r, + delSK, + fpPK, + changeAddress.EncodeAddress(), + stakingValue, + 1000, + 0, + 0, + usePreApproval, + // add delegation to the allow list, it should succeed + true, + ) + h.NoError(err) + require.NotNil(t, msgCreateBTCDel) + + delSK1, _, err := datagen.GenRandomBTCKeyPair(r) + h.NoError(err) + _, msgCreateBTCDel1, _, _, _, _, err := h.CreateDelegation( + r, + delSK1, + fpPK, + changeAddress.EncodeAddress(), + stakingValue, + 1000, + 0, + 0, + usePreApproval, + // do not add delegation to the allow list, it should fail + false, + ) + require.Error(t, err) + require.ErrorIs(t, err, types.ErrInvalidStakingTx) + require.Nil(t, msgCreateBTCDel1) + + // move forward in the block height, allow list should be expired + h.Ctx = h.Ctx.WithBlockHeight(int64(allowListExpirationHeight)) + delSK2, _, err := datagen.GenRandomBTCKeyPair(r) + h.NoError(err) + _, msgCreateBTCDel2, _, _, _, _, err := h.CreateDelegation( + r, + delSK2, + fpPK, + changeAddress.EncodeAddress(), + stakingValue, + 1000, + 0, + 0, + usePreApproval, + // do not add delegation to the allow list, it should succeed as allow list is expired + false, + ) + h.NoError(err) + require.NotNil(t, msgCreateBTCDel2) +} + func createNDelegationsForFinalityProvider( r *rand.Rand, t *testing.T, diff --git a/x/btcstaking/types/keys.go b/x/btcstaking/types/keys.go index 93defdfbc..a3313b97b 100644 --- a/x/btcstaking/types/keys.go +++ b/x/btcstaking/types/keys.go @@ -1,5 +1,7 @@ package types +import "cosmossdk.io/collections" + const ( // ModuleName defines the module name ModuleName = "btcstaking" @@ -22,5 +24,6 @@ var ( // 0x05 was used for something else in the past BTCHeightKey = []byte{0x06} // key prefix for the BTC heights // 0x07 was used for something else in the past - PowerDistUpdateKey = []byte{0x08} // key prefix for power distribution update events + PowerDistUpdateKey = []byte{0x08} // key prefix for power distribution update events + AllowedStakingTxHashesKey = collections.NewPrefix(9) // key prefix for allowed staking tx hashes ) diff --git a/x/btcstaking/types/params.go b/x/btcstaking/types/params.go index 33b65a77e..43528030c 100644 --- a/x/btcstaking/types/params.go +++ b/x/btcstaking/types/params.go @@ -77,6 +77,9 @@ func DefaultParams() Params { MinUnbondingTimeBlocks: 0, UnbondingFeeSat: 1000, DelegationCreationBaseGasFee: defaultDelegationCreationBaseGasFee, + // The default allow list expiration height is 0, which effectively disables the allow list. + // Allow list can only be enabled by upgrade + AllowListExpirationHeight: 0, } } diff --git a/x/btcstaking/types/params.pb.go b/x/btcstaking/types/params.pb.go index 806cd7207..1d96cd61b 100644 --- a/x/btcstaking/types/params.pb.go +++ b/x/btcstaking/types/params.pb.go @@ -67,6 +67,10 @@ type Params struct { MinCommissionRate cosmossdk_io_math.LegacyDec `protobuf:"bytes,12,opt,name=min_commission_rate,json=minCommissionRate,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"min_commission_rate"` // base gas fee for delegation creation DelegationCreationBaseGasFee uint64 `protobuf:"varint,13,opt,name=delegation_creation_base_gas_fee,json=delegationCreationBaseGasFee,proto3" json:"delegation_creation_base_gas_fee,omitempty"` + // allow_list_expiration_height is the height at which the allow list expires + // i.e all staking transactions are allowed to enter Babylon chain afterwards + // setting it to 0 means allow list is disabled + AllowListExpirationHeight uint64 `protobuf:"varint,14,opt,name=allow_list_expiration_height,json=allowListExpirationHeight,proto3" json:"allow_list_expiration_height,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -171,6 +175,13 @@ func (m *Params) GetDelegationCreationBaseGasFee() uint64 { return 0 } +func (m *Params) GetAllowListExpirationHeight() uint64 { + if m != nil { + return m.AllowListExpirationHeight + } + return 0 +} + // StoredParams attach information about the version of stored parameters type StoredParams struct { // version of the stored parameters. Each parameters update @@ -237,46 +248,49 @@ func init() { } var fileDescriptor_8d1392776a3e15b9 = []byte{ - // 620 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xcd, 0x6e, 0xd3, 0x40, - 0x14, 0x85, 0x63, 0x1a, 0x52, 0x3a, 0x4d, 0x29, 0x35, 0x2d, 0xb8, 0x05, 0x1c, 0xab, 0x2c, 0xb0, - 0x10, 0xb5, 0x09, 0x2d, 0x12, 0x3f, 0x3b, 0xb7, 0x2a, 0x42, 0x20, 0x14, 0x9c, 0xd2, 0x05, 0x2c, - 0xac, 0xb1, 0x33, 0xb8, 0x23, 0x7b, 0x3c, 0xc6, 0x33, 0x8e, 0x92, 0xb7, 0x60, 0xc9, 0x92, 0x25, - 0x0f, 0xc0, 0x43, 0x74, 0x59, 0xb1, 0x42, 0x5d, 0x54, 0xa8, 0x79, 0x11, 0xe4, 0xf1, 0x38, 0xb1, - 0xaa, 0x2e, 0xba, 0xf3, 0xcc, 0xb9, 0xe7, 0xde, 0xf3, 0x25, 0xbe, 0x06, 0x9b, 0x3e, 0xf4, 0xc7, - 0x31, 0x4d, 0x6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fa, 0x14, 0x8e, 0x09, 0xf2, 0xfc, 0x98, - 0x06, 0x11, 0xd3, 0xae, 0x8b, 0x58, 0xab, 0xb3, 0x39, 0x07, 0x98, 0x20, 0x47, 0x68, 0xc2, 0x56, - 0x9b, 0x54, 0xb7, 0xb5, 0xa4, 0x6d, 0x3a, 0xab, 0x66, 0x7b, 0x02, 0x54, 0x16, 0x43, 0x76, 0x54, - 0x78, 0xd2, 0xc8, 0x63, 0x41, 0x86, 0x53, 0xae, 0xcd, 0x1b, 0x8a, 0xd9, 0x76, 0x6f, 0x55, 0x4a, - 0x2f, 0xea, 0x8b, 0x7b, 0x75, 0x47, 0x66, 0xab, 0x1c, 0x7c, 0xe4, 0x7d, 0x45, 0x25, 0xd0, 0x0d, - 0x01, 0x74, 0xbb, 0xc8, 0x26, 0xd5, 0x83, 0xd1, 0x3e, 0x12, 0x44, 0x87, 0x60, 0x69, 0xea, 0xc8, - 0x20, 0x47, 0xda, 0x82, 0xa1, 0x98, 0x0b, 0x4e, 0xf7, 0xf8, 0xac, 0xd3, 0x38, 0x3d, 0xeb, 0xdc, - 0x2b, 0xff, 0x75, 0x36, 0x88, 0x2c, 0x4c, 0x6d, 0x02, 0xf9, 0x91, 0xf5, 0x1e, 0x85, 0x30, 0x18, - 0xef, 0xa1, 0xe0, 0xcf, 0xef, 0x2d, 0x20, 0x5f, 0x8a, 0x3d, 0x14, 0xb8, 0xed, 0xaa, 0x8f, 0x0b, - 0x39, 0x52, 0x5f, 0x82, 0xf5, 0x22, 0x4d, 0x9e, 0xf8, 0x34, 0x19, 0x5c, 0x84, 0x06, 0x02, 0xfa, - 0x0e, 0xc1, 0xc9, 0xa7, 0x4a, 0xaf, 0x61, 0x3f, 0x06, 0x2b, 0x33, 0x5b, 0x85, 0xb0, 0x28, 0x10, - 0x96, 0xa7, 0x82, 0x8c, 0xdf, 0x07, 0x05, 0x95, 0x17, 0x50, 0x42, 0x30, 0x63, 0x98, 0x26, 0x25, - 0x44, 0x5b, 0x40, 0x3c, 0xbc, 0x02, 0x84, 0xbb, 0x42, 0x70, 0xb2, 0x3b, 0xb5, 0x8b, 0xec, 0xfb, - 0xc0, 0x18, 0xa0, 0x18, 0x85, 0x90, 0x17, 0x0d, 0x83, 0x0c, 0x95, 0x0f, 0x3e, 0x64, 0xc8, 0x0b, - 0x21, 0x2b, 0x32, 0x69, 0x4b, 0x86, 0x62, 0x36, 0xdd, 0xfb, 0xb3, 0xba, 0x5d, 0x59, 0xe6, 0x40, - 0x86, 0xde, 0x40, 0xb6, 0x8f, 0xd0, 0xab, 0xe6, 0x8f, 0x9f, 0x9d, 0xc6, 0x26, 0x02, 0xed, 0x3e, - 0xa7, 0x19, 0x1a, 0xc8, 0x7d, 0xd1, 0xc0, 0xfc, 0x10, 0x65, 0xc5, 0x30, 0x4d, 0x11, 0xbf, 0x43, - 0x75, 0x54, 0x5f, 0x83, 0x56, 0xb9, 0xac, 0xe2, 0x1d, 0x5f, 0x7c, 0xf6, 0xc0, 0xba, 0x74, 0x5b, - 0xad, 0xb2, 0x91, 0xd3, 0x2c, 0xf0, 0x5c, 0x69, 0x71, 0x3e, 0x1c, 0x9f, 0xeb, 0xca, 0xc9, 0xb9, - 0xae, 0xfc, 0x3b, 0xd7, 0x95, 0xef, 0x13, 0xbd, 0x71, 0x32, 0xd1, 0x1b, 0x7f, 0x27, 0x7a, 0xe3, - 0xf3, 0x15, 0xd6, 0x70, 0x54, 0xff, 0x66, 0x88, 0x9d, 0xf4, 0x5b, 0x62, 0xd1, 0xb7, 0xff, 0x07, - 0x00, 0x00, 0xff, 0xff, 0x80, 0xd8, 0x41, 0xc8, 0x56, 0x04, 0x00, 0x00, + // 658 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xcd, 0x6e, 0xd3, 0x4c, + 0x14, 0x8d, 0xbf, 0xe6, 0x4b, 0xe9, 0x34, 0x6d, 0xa9, 0x69,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x69, 0x5a, + 0x4d, 0x91, 0x2f, 0xb2, 0x38, 0xaa, 0xcf, 0x51, 0x25, 0xdb, 0x76, 0xb9, 0x24, 0xf3, 0x8f, 0xee, + 0x18, 0x97, 0xae, 0xbb, 0x91, 0x19, 0x59, 0xe5, 0xf4, 0xfd, 0xd8, 0xb9, 0xc4, 0x7a, 0x77, 0x7c, + 0x5e, 0x53, 0x4e, 0xce, 0x6b, 0xca, 0x9f, 0xf3, 0x9a, 0xf2, 0x6d, 0x54, 0x2b, 0x9d, 0x8c, 0x6a, + 0xa5, 0xdf, 0xa3, 0x5a, 0xe9, 0xe3, 0x15, 0xf6, 0x78, 0x30, 0xfd, 0xd1, 0x91, 0x4b, 0xed, 0x56, + 0xe4, 0x97, 0x62, 0xfb, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xdc, 0xd0, 0x43, 0xb7, 0x97, 0x04, + 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -299,6 +313,11 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.AllowListExpirationHeight != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.AllowListExpirationHeight)) + i-- + dAtA[i] = 0x70 + } if m.DelegationCreationBaseGasFee != 0 { i = encodeVarintParams(dAtA, i, uint64(m.DelegationCreationBaseGasFee)) i-- @@ -484,6 +503,9 @@ func (m *Params) Size() (n int) { if m.DelegationCreationBaseGasFee != 0 { n += 1 + sovParams(uint64(m.DelegationCreationBaseGasFee)) } + if m.AllowListExpirationHeight != 0 { + n += 1 + sovParams(uint64(m.AllowListExpirationHeight)) + } return n } @@ -844,6 +866,25 @@ func (m *Params) Unmarshal(dAtA []byte) error { break } } + case 14: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AllowListExpirationHeight", wireType) + } + m.AllowListExpirationHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AllowListExpirationHeight |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/x/finality/keeper/power_dist_change_test.go b/x/finality/keeper/power_dist_change_test.go index 1d61e61fb..86bee07d0 100644 --- a/x/finality/keeper/power_dist_change_test.go +++ b/x/finality/keeper/power_dist_change_test.go @@ -62,6 +62,7 @@ func FuzzProcessAllPowerDistUpdateEvents_Determinism(f *testing.F) { 0, 0, false, + false, ) h.NoError(err) event := types.NewEventPowerDistUpdateWithBTCDel(&types.EventBTCDelegationStateUpdate{ @@ -119,6 +120,7 @@ func FuzzSlashFinalityProviderEvent(f *testing.F) { 0, 0, true, + false, ) h.NoError(err) // give it a quorum number of covenant signatures @@ -205,6 +207,7 @@ func FuzzJailFinalityProviderEvents(f *testing.F) { 0, 0, true, + false, ) h.NoError(err) // give it a quorum number of covenant signatures @@ -274,6 +277,7 @@ func FuzzJailFinalityProviderEvents(f *testing.F) { 0, 0, true, + false, ) h.NoError(err) // give it a quorum number of covenant signatures @@ -335,6 +339,7 @@ func FuzzUnjailFinalityProviderEvents(f *testing.F) { 0, 0, true, + false, ) h.NoError(err) // give it a quorum number of covenant signatures @@ -436,6 +441,7 @@ func FuzzBTCDelegationEvents_NoPreApproval(f *testing.F) { 0, 0, false, + false, ) h.NoError(err) @@ -554,6 +560,7 @@ func FuzzBTCDelegationEvents_WithPreApproval(f *testing.F) { 0, 0, true, + false, ) h.NoError(err) @@ -681,6 +688,7 @@ func TestDoNotGenerateDuplicateEventsAfterHavingCovenantQuorum(t *testing.T) { 0, 0, false, + false, ) h.NoError(err) /* diff --git a/x/finality/keeper/power_table_test.go b/x/finality/keeper/power_table_test.go index b11250aa5..1c8ec0e9c 100644 --- a/x/finality/keeper/power_table_test.go +++ b/x/finality/keeper/power_table_test.go @@ -61,6 +61,7 @@ func FuzzVotingPowerTable(f *testing.F) { 0, 0, true, + false, ) h.NoError(err) h.CreateCovenantSigs(r, covenantSKs, delMsg, del) @@ -216,6 +217,7 @@ func FuzzRecordVotingPowerDistCache(f *testing.F) { 0, 0, true, + false, ) h.NoError(err) h.CreateCovenantSigs(r, covenantSKs, delMsg, del) @@ -287,6 +289,7 @@ func FuzzVotingPowerTable_ActiveFinalityProviders(f *testing.F) { 0, 0, true, + false, ) h.NoError(err) h.CreateCovenantSigs(r, covenantSKs, delMsg, del) @@ -403,6 +406,7 @@ func FuzzVotingPowerTable_ActiveFinalityProviderRotation(f *testing.F) { 0, 0, true, + false, ) h.NoError(err) h.CreateCovenantSigs(r, covenantSKs, delMsg, del) @@ -459,6 +463,7 @@ func FuzzVotingPowerTable_ActiveFinalityProviderRotation(f *testing.F) { 0, 0, true, + false, ) h.NoError(err) h.CreateCovenantSigs(r, covenantSKs, delMsg, del) @@ -493,6 +498,7 @@ func FuzzVotingPowerTable_ActiveFinalityProviderRotation(f *testing.F) { 0, 0, true, + false, ) h.NoError(err) h.CreateCovenantSigs(r, covenantSKs, delMsg, del)