From c806a3dd8b8526ca19215705ed84c96115df99bb Mon Sep 17 00:00:00 2001 From: Cirrus Gai Date: Tue, 13 Aug 2024 19:29:45 +0800 Subject: [PATCH] feat(ADR-024): Introduce epoch number in public randomness commit (#12) --- app/keepers/keepers.go | 2 +- proto/babylon/finality/v1/finality.proto | 2 + proto/babylon/finality/v1/query.proto | 2 + test/e2e/btc_staking_e2e_test.go | 61 ++++-- test/e2e/configurer/chain/queries.go | 17 +- testutil/keeper/btcstaking.go | 2 - testutil/keeper/finality.go | 3 +- x/btcstaking/genesis_test.go | 5 +- x/btcstaking/keeper/bench_test.go | 6 +- x/btcstaking/keeper/btc_height_index_test.go | 7 +- x/btcstaking/keeper/grpc_query_test.go | 19 +- x/btcstaking/keeper/incentive_test.go | 3 +- x/btcstaking/keeper/keeper.go | 7 - x/btcstaking/keeper/keeper_test.go | 6 +- x/btcstaking/keeper/msg_server_test.go | 30 +-- x/btcstaking/keeper/params_test.go | 9 +- x/btcstaking/keeper/power_dist_change_test.go | 16 +- x/btcstaking/keeper/query_params_test.go | 7 +- .../keeper/voting_power_table_test.go | 14 +- x/btcstaking/types/errors.go | 1 - x/btcstaking/types/expected_keepers.go | 6 - x/btcstaking/types/mocked_keepers.go | 52 ----- x/finality/genesis_test.go | 5 +- x/finality/keeper/genesis_test.go | 2 +- x/finality/keeper/grpc_query_test.go | 17 +- x/finality/keeper/keeper.go | 24 +- x/finality/keeper/liveness_test.go | 3 +- x/finality/keeper/msg_server.go | 19 +- x/finality/keeper/msg_server_test.go | 48 +++- x/finality/keeper/params_test.go | 5 +- x/finality/keeper/query_params_test.go | 5 +- x/finality/keeper/tallying_bench_test.go | 8 +- x/finality/keeper/tallying_test.go | 16 +- x/finality/keeper/votes_bench_test.go | 8 +- x/finality/types/errors.go | 23 +- x/finality/types/expected_keepers.go | 7 +- x/finality/types/finality.pb.go | 108 ++++++--- x/finality/types/mocked_keepers.go | 66 ++++-- x/finality/types/query.pb.go | 205 +++++++++++------- 39 files changed, 493 insertions(+), 353 deletions(-) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 74174a608..0db6166ee 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -524,7 +524,6 @@ func (ak *AppKeepers) InitKeepers( runtime.NewKVStoreService(keys[btcstakingtypes.StoreKey]), &btclightclientKeeper, &btcCheckpointKeeper, - &checkpointingKeeper, btcNetParams, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) @@ -535,6 +534,7 @@ func (ak *AppKeepers) InitKeepers( runtime.NewKVStoreService(keys[finalitytypes.StoreKey]), ak.BTCStakingKeeper, ak.IncentiveKeeper, + ak.CheckpointingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) ak.BTCStakingKeeper = *ak.BTCStakingKeeper.SetHooks(btcstakingtypes.NewMultiBtcStakingHooks(ak.FinalityKeeper.Hooks())) diff --git a/proto/babylon/finality/v1/finality.proto b/proto/babylon/finality/v1/finality.proto index f6f56f6d9..1167e774a 100644 --- a/proto/babylon/finality/v1/finality.proto +++ b/proto/babylon/finality/v1/finality.proto @@ -27,6 +27,8 @@ message PubRandCommit { // commitment is the value of the commitment // currently, it is the root of the merkle tree constructed by the public randomness bytes commitment = 3; + // epoch_num defines the epoch number that the commit falls into + uint64 epoch_num = 4; } // Evidence is the evidence that a finality provider has signed finality diff --git a/proto/babylon/finality/v1/query.proto b/proto/babylon/finality/v1/query.proto index 7b6c9fb0b..159995a69 100644 --- a/proto/babylon/finality/v1/query.proto +++ b/proto/babylon/finality/v1/query.proto @@ -102,6 +102,8 @@ message PubRandCommitResponse { uint64 num_pub_rand = 1; // commitment is the value of the commitment bytes commitment = 2; + // epoch_num defines the epoch number that the commit falls into + uint64 epoch_num = 3; } // QueryListPubRandCommitRequest is the request type for the diff --git a/test/e2e/btc_staking_e2e_test.go b/test/e2e/btc_staking_e2e_test.go index f4f67a203..4b6676ac5 100644 --- a/test/e2e/btc_staking_e2e_test.go +++ b/test/e2e/btc_staking_e2e_test.go @@ -26,6 +26,7 @@ import ( bbn "github.com/babylonlabs-io/babylon/types" btcctypes "github.com/babylonlabs-io/babylon/x/btccheckpoint/types" bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" + ckpttypes "github.com/babylonlabs-io/babylon/x/checkpointing/types" ftypes "github.com/babylonlabs-io/babylon/x/finality/types" itypes "github.com/babylonlabs-io/babylon/x/incentive/types" ) @@ -272,6 +273,8 @@ func (s *BTCStakingTestSuite) Test3CommitPublicRandomnessAndSubmitFinalitySignat // get activated height activatedHeight := nonValidatorNode.QueryActivatedHeight() s.Positive(activatedHeight) + _, err = nonValidatorNode.QueryCurrentHeight() + s.NoError(err) /* commit a number of public randomness since activatedHeight @@ -288,8 +291,39 @@ func (s *BTCStakingTestSuite) Test3CommitPublicRandomnessAndSubmitFinalitySignat msgCommitPubRandList.Sig, ) + // no reward gauge for finality provider and delegation yet + fpBabylonAddr, err := sdk.AccAddressFromBech32(cacheFP.Addr) + s.NoError(err) + + _, err = nonValidatorNode.QueryRewardGauge(fpBabylonAddr) + s.ErrorContains(err, itypes.ErrRewardGaugeNotFound.Error()) + delBabylonAddr := fpBabylonAddr + + // finalize epochs from 1 to the current epoch + currentEpoch, err := nonValidatorNode.QueryCurrentEpoch() + s.NoError(err) + + // wait until the end epoch is sealed + s.Eventually(func() bool { + resp, err := nonValidatorNode.QueryRawCheckpoint(currentEpoch) + if err != nil { + return false + } + return resp.Status == ckpttypes.Sealed + }, time.Minute, time.Second*5) + nonValidatorNode.FinalizeSealedEpochs(1, currentEpoch) + lastFinalizedEpoch := uint64(0) + + // ensure the committed epoch is finalized + s.Eventually(func() bool { + lastFinalizedEpoch, err = nonValidatorNode.QueryLastFinalizedEpoch() + if err != nil { + return false + } + return lastFinalizedEpoch >= currentEpoch + }, time.Minute, time.Second) + // ensure public randomness list is eventually committed - nonValidatorNode.WaitForNextBlock() var prCommitMap map[uint64]*ftypes.PubRandCommitResponse s.Eventually(func() bool { prCommitMap = nonValidatorNode.QueryListPubRandCommit(cacheFP.BtcPk) @@ -297,14 +331,7 @@ func (s *BTCStakingTestSuite) Test3CommitPublicRandomnessAndSubmitFinalitySignat }, time.Minute, time.Second*5) s.Equal(prCommitMap[activatedHeight].NumPubRand, msgCommitPubRandList.NumPubRand) s.Equal(prCommitMap[activatedHeight].Commitment, msgCommitPubRandList.Commitment) - - // no reward gauge for finality provider and delegation yet - fpBabylonAddr, err := sdk.AccAddressFromBech32(cacheFP.Addr) - s.NoError(err) - - _, err = nonValidatorNode.QueryRewardGauge(fpBabylonAddr) - s.ErrorContains(err, itypes.ErrRewardGaugeNotFound.Error()) - delBabylonAddr := fpBabylonAddr + s.LessOrEqual(prCommitMap[activatedHeight].EpochNum, lastFinalizedEpoch) /* submit finality signature @@ -324,20 +351,12 @@ func (s *BTCStakingTestSuite) Test3CommitPublicRandomnessAndSubmitFinalitySignat nonValidatorNode.AddFinalitySig(cacheFP.BtcPk, activatedHeight, &randListInfo.PRList[idx], *randListInfo.ProofList[idx].ToProto(), appHash, eotsSig) // ensure vote is eventually cast - nonValidatorNode.WaitForNextBlock() - var votes []bbn.BIP340PubKey + var finalizedBlocks []*ftypes.IndexedBlock s.Eventually(func() bool { - votes = nonValidatorNode.QueryVotesAtHeight(activatedHeight) - return len(votes) > 0 + finalizedBlocks = nonValidatorNode.QueryListBlocks(ftypes.QueriedBlockStatus_FINALIZED) + return len(finalizedBlocks) > 0 }, time.Minute, time.Second*5) - s.Equal(1, len(votes)) - s.Equal(votes[0].MarshalHex(), cacheFP.BtcPk.MarshalHex()) - // once the vote is cast, ensure block is finalised - finalizedBlock := nonValidatorNode.QueryIndexedBlock(activatedHeight) - s.NotEmpty(finalizedBlock) - s.Equal(appHash.Bytes(), finalizedBlock.AppHash) - finalizedBlocks := nonValidatorNode.QueryListBlocks(ftypes.QueriedBlockStatus_FINALIZED) - s.NotEmpty(finalizedBlocks) + s.Equal(activatedHeight, finalizedBlocks[0].Height) s.Equal(appHash.Bytes(), finalizedBlocks[0].AppHash) // ensure finality provider has received rewards after the block is finalised diff --git a/test/e2e/configurer/chain/queries.go b/test/e2e/configurer/chain/queries.go index 178349bbf..75e6ec2bc 100644 --- a/test/e2e/configurer/chain/queries.go +++ b/test/e2e/configurer/chain/queries.go @@ -180,7 +180,9 @@ func (n *NodeConfig) QueryListSnapshots() ([]*cmtabcitypes.Snapshot, error) { func (n *NodeConfig) QueryRawCheckpoint(epoch uint64) (*ct.RawCheckpointWithMetaResponse, error) { path := fmt.Sprintf("babylon/checkpointing/v1/raw_checkpoint/%d", epoch) bz, err := n.QueryGRPCGateway(path, url.Values{}) - require.NoError(n.t, err) + if err != nil { + return nil, err + } var checkpointingResponse ct.QueryRawCheckpointResponse if err := util.Cdc.UnmarshalJSON(bz, &checkpointingResponse); err != nil { @@ -208,6 +210,19 @@ func (n *NodeConfig) QueryRawCheckpoints(pagination *query.PageRequest) (*ct.Que return &checkpointingResponse, nil } +func (n *NodeConfig) QueryLastFinalizedEpoch() (uint64, error) { + queryParams := url.Values{} + queryParams.Add("status", fmt.Sprintf("%d", ct.Finalized)) + + bz, err := n.QueryGRPCGateway(fmt.Sprintf("/babylon/checkpointing/v1/last_raw_checkpoint/%d", ct.Finalized), queryParams) + require.NoError(n.t, err) + var res ct.QueryLastCheckpointWithStatusResponse + if err := util.Cdc.UnmarshalJSON(bz, &res); err != nil { + return 0, err + } + return res.RawCheckpoint.EpochNum, nil +} + func (n *NodeConfig) QueryBtcBaseHeader() (*blc.BTCHeaderInfoResponse, error) { bz, err := n.QueryGRPCGateway("babylon/btclightclient/v1/baseheader", url.Values{}) require.NoError(n.t, err) diff --git a/testutil/keeper/btcstaking.go b/testutil/keeper/btcstaking.go index fd00fbf7f..d12d32820 100644 --- a/testutil/keeper/btcstaking.go +++ b/testutil/keeper/btcstaking.go @@ -27,7 +27,6 @@ func BTCStakingKeeper( t testing.TB, btclcKeeper types.BTCLightClientKeeper, btccKeeper types.BtcCheckpointKeeper, - ckptKeeper types.CheckpointingKeeper, ) (*keeper.Keeper, sdk.Context) { storeKey := storetypes.NewKVStoreKey(types.StoreKey) @@ -44,7 +43,6 @@ func BTCStakingKeeper( runtime.NewKVStoreService(storeKey), btclcKeeper, btccKeeper, - ckptKeeper, &chaincfg.SimNetParams, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) diff --git a/testutil/keeper/finality.go b/testutil/keeper/finality.go index fc15a866e..1b8a2adee 100644 --- a/testutil/keeper/finality.go +++ b/testutil/keeper/finality.go @@ -22,7 +22,7 @@ import ( "github.com/babylonlabs-io/babylon/x/finality/types" ) -func FinalityKeeper(t testing.TB, bsKeeper types.BTCStakingKeeper, iKeeper types.IncentiveKeeper) (*keeper.Keeper, sdk.Context) { +func FinalityKeeper(t testing.TB, bsKeeper types.BTCStakingKeeper, iKeeper types.IncentiveKeeper, cKeeper types.CheckpointingKeeper) (*keeper.Keeper, sdk.Context) { storeKey := storetypes.NewKVStoreKey(types.StoreKey) db := dbm.NewMemDB() @@ -38,6 +38,7 @@ func FinalityKeeper(t testing.TB, bsKeeper types.BTCStakingKeeper, iKeeper types runtime.NewKVStoreService(storeKey), bsKeeper, iKeeper, + cKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) diff --git a/x/btcstaking/genesis_test.go b/x/btcstaking/genesis_test.go index dc034bdf3..805650c8a 100644 --- a/x/btcstaking/genesis_test.go +++ b/x/btcstaking/genesis_test.go @@ -3,11 +3,12 @@ package btcstaking_test import ( "testing" + "github.com/stretchr/testify/require" + keepertest "github.com/babylonlabs-io/babylon/testutil/keeper" "github.com/babylonlabs-io/babylon/testutil/nullify" "github.com/babylonlabs-io/babylon/x/btcstaking" "github.com/babylonlabs-io/babylon/x/btcstaking/types" - "github.com/stretchr/testify/require" ) func TestGenesis(t *testing.T) { @@ -16,7 +17,7 @@ func TestGenesis(t *testing.T) { Params: []*types.Params{&p}, } - k, ctx := keepertest.BTCStakingKeeper(t, nil, nil, nil) + k, ctx := keepertest.BTCStakingKeeper(t, nil, nil) btcstaking.InitGenesis(ctx, *k, genesisState) got := btcstaking.ExportGenesis(ctx, *k) require.NotNil(t, got) diff --git a/x/btcstaking/keeper/bench_test.go b/x/btcstaking/keeper/bench_test.go index 27fe36b65..e32acbefd 100644 --- a/x/btcstaking/keeper/bench_test.go +++ b/x/btcstaking/keeper/bench_test.go @@ -8,11 +8,12 @@ import ( "testing" "time" + "github.com/golang/mock/gomock" + "github.com/babylonlabs-io/babylon/testutil/datagen" btclctypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" bsmodule "github.com/babylonlabs-io/babylon/x/btcstaking" "github.com/babylonlabs-io/babylon/x/btcstaking/types" - "github.com/golang/mock/gomock" ) func benchBeginBlock(b *testing.B, numFPs int, numDelsUnderFP int) { @@ -23,8 +24,7 @@ func benchBeginBlock(b *testing.B, numFPs int, numDelsUnderFP int) { defer ctrl.Finish() btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(b, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(b, btclcKeeper, btccKeeper) // set all parameters covenantSKs, _ := h.GenAndApplyParams(r) changeAddress, err := datagen.GenRandomBTCAddress(r, h.Net) diff --git a/x/btcstaking/keeper/btc_height_index_test.go b/x/btcstaking/keeper/btc_height_index_test.go index a40b5d4d3..326fdf39a 100644 --- a/x/btcstaking/keeper/btc_height_index_test.go +++ b/x/btcstaking/keeper/btc_height_index_test.go @@ -4,12 +4,13 @@ import ( "math/rand" "testing" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + "github.com/babylonlabs-io/babylon/testutil/datagen" keepertest "github.com/babylonlabs-io/babylon/testutil/keeper" btclctypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" "github.com/babylonlabs-io/babylon/x/btcstaking/types" - "github.com/golang/mock/gomock" - "github.com/stretchr/testify/require" ) func FuzzBTCHeightIndex(f *testing.F) { @@ -22,7 +23,7 @@ func FuzzBTCHeightIndex(f *testing.F) { // mock BTC light client btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) - keeper, ctx := keepertest.BTCStakingKeeper(t, btclcKeeper, nil, nil) + keeper, ctx := keepertest.BTCStakingKeeper(t, btclcKeeper, nil) // randomise Babylon height and BTC height babylonHeight := datagen.RandomInt(r, 100) diff --git a/x/btcstaking/keeper/grpc_query_test.go b/x/btcstaking/keeper/grpc_query_test.go index af2b03d47..312e2dcef 100644 --- a/x/btcstaking/keeper/grpc_query_test.go +++ b/x/btcstaking/keeper/grpc_query_test.go @@ -26,7 +26,7 @@ func FuzzActivatedHeight(f *testing.F) { r := rand.New(rand.NewSource(seed)) // Setup keeper and context - keeper, ctx := testkeeper.BTCStakingKeeper(t, nil, nil, nil) + keeper, ctx := testkeeper.BTCStakingKeeper(t, nil, nil) ctx = sdk.UnwrapSDKContext(ctx) // not activated yet @@ -51,7 +51,7 @@ func FuzzFinalityProviders(f *testing.F) { r := rand.New(rand.NewSource(seed)) // Setup keeper and context - keeper, ctx := testkeeper.BTCStakingKeeper(t, nil, nil, nil) + keeper, ctx := testkeeper.BTCStakingKeeper(t, nil, nil) ctx = sdk.UnwrapSDKContext(ctx) // Generate random finality providers and add them to kv store @@ -116,7 +116,7 @@ func FuzzFinalityProvider(f *testing.F) { f.Fuzz(func(t *testing.T, seed int64) { r := rand.New(rand.NewSource(seed)) // Setup keeper and context - keeper, ctx := testkeeper.BTCStakingKeeper(t, nil, nil, nil) + keeper, ctx := testkeeper.BTCStakingKeeper(t, nil, nil) ctx = sdk.UnwrapSDKContext(ctx) // Generate random finality providers and add them to kv store @@ -172,8 +172,7 @@ func FuzzPendingBTCDelegations(f *testing.F) { btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) btccKeeper.EXPECT().GetParams(gomock.Any()).Return(btcctypes.DefaultParams()).AnyTimes() - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - keeper, ctx := testkeeper.BTCStakingKeeper(t, btclcKeeper, btccKeeper, ckptKeeper) + keeper, ctx := testkeeper.BTCStakingKeeper(t, btclcKeeper, btccKeeper) // covenant and slashing addr covenantSKs, covenantPKs, covenantQuorum := datagen.GenCovenantCommittee(r) @@ -275,7 +274,7 @@ func FuzzFinalityProviderPowerAtHeight(f *testing.F) { r := rand.New(rand.NewSource(seed)) // Setup keeper and context - keeper, ctx := testkeeper.BTCStakingKeeper(t, nil, nil, nil) + keeper, ctx := testkeeper.BTCStakingKeeper(t, nil, nil) // random finality provider fp, err := datagen.GenRandomFinalityProvider(r) @@ -324,7 +323,7 @@ func FuzzFinalityProviderCurrentVotingPower(f *testing.F) { r := rand.New(rand.NewSource(seed)) // Setup keeper and context - keeper, ctx := testkeeper.BTCStakingKeeper(t, nil, nil, nil) + keeper, ctx := testkeeper.BTCStakingKeeper(t, nil, nil) // random finality provider fp, err := datagen.GenRandomFinalityProvider(r) @@ -376,8 +375,7 @@ func FuzzActiveFinalityProvidersAtHeight(f *testing.F) { btclcKeeper.EXPECT().GetTipInfo(gomock.Any()).Return(&btclctypes.BTCHeaderInfo{Height: 10}).AnyTimes() btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) btccKeeper.EXPECT().GetParams(gomock.Any()).Return(btcctypes.DefaultParams()).AnyTimes() - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - keeper, ctx := testkeeper.BTCStakingKeeper(t, btclcKeeper, btccKeeper, ckptKeeper) + keeper, ctx := testkeeper.BTCStakingKeeper(t, btclcKeeper, btccKeeper) // covenant and slashing addr covenantSKs, covenantPKs, covenantQuorum := datagen.GenCovenantCommittee(r) @@ -496,8 +494,7 @@ func FuzzFinalityProviderDelegations(f *testing.F) { btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) btccKeeper.EXPECT().GetParams(gomock.Any()).Return(btcctypes.DefaultParams()).AnyTimes() - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - keeper, ctx := testkeeper.BTCStakingKeeper(t, btclcKeeper, btccKeeper, ckptKeeper) + keeper, ctx := testkeeper.BTCStakingKeeper(t, btclcKeeper, btccKeeper) // covenant and slashing addr covenantSKs, covenantPKs, covenantQuorum := datagen.GenCovenantCommittee(r) diff --git a/x/btcstaking/keeper/incentive_test.go b/x/btcstaking/keeper/incentive_test.go index ea7d699d5..9b49da27f 100644 --- a/x/btcstaking/keeper/incentive_test.go +++ b/x/btcstaking/keeper/incentive_test.go @@ -23,8 +23,7 @@ func FuzzRecordVotingPowerDistCache(f *testing.F) { // mock BTC light client and BTC checkpoint modules btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(t, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(t, btclcKeeper, btccKeeper) // set all parameters covenantSKs, _ := h.GenAndApplyParams(r) diff --git a/x/btcstaking/keeper/keeper.go b/x/btcstaking/keeper/keeper.go index 5a992423a..51515ae6a 100644 --- a/x/btcstaking/keeper/keeper.go +++ b/x/btcstaking/keeper/keeper.go @@ -21,7 +21,6 @@ type ( btclcKeeper types.BTCLightClientKeeper btccKeeper types.BtcCheckpointKeeper - ckptKeeper types.CheckpointingKeeper hooks types.BtcStakingHooks @@ -38,7 +37,6 @@ func NewKeeper( btclcKeeper types.BTCLightClientKeeper, btccKeeper types.BtcCheckpointKeeper, - ckptKeeper types.CheckpointingKeeper, btcNet *chaincfg.Params, authority string, @@ -49,7 +47,6 @@ func NewKeeper( btclcKeeper: btclcKeeper, btccKeeper: btccKeeper, - ckptKeeper: ckptKeeper, hooks: nil, @@ -86,7 +83,3 @@ func (k Keeper) BeginBlocker(ctx context.Context) error { return nil } - -func (k Keeper) GetLastFinalizedEpoch(ctx context.Context) uint64 { - return k.ckptKeeper.GetLastFinalizedEpoch(ctx) -} diff --git a/x/btcstaking/keeper/keeper_test.go b/x/btcstaking/keeper/keeper_test.go index 1ce64721e..157f6cc7b 100644 --- a/x/btcstaking/keeper/keeper_test.go +++ b/x/btcstaking/keeper/keeper_test.go @@ -33,14 +33,13 @@ type Helper struct { BTCStakingKeeper *keeper.Keeper BTCLightClientKeeper *types.MockBTCLightClientKeeper BTCCheckpointKeeper *types.MockBtcCheckpointKeeper - CheckpointingKeeper *types.MockCheckpointingKeeper BTCStakingHooks *types.MockBtcStakingHooks MsgServer types.MsgServer Net *chaincfg.Params } -func NewHelper(t testing.TB, btclcKeeper *types.MockBTCLightClientKeeper, btccKeeper *types.MockBtcCheckpointKeeper, ckptKeeper *types.MockCheckpointingKeeper) *Helper { - k, ctx := keepertest.BTCStakingKeeper(t, btclcKeeper, btccKeeper, ckptKeeper) +func NewHelper(t testing.TB, btclcKeeper *types.MockBTCLightClientKeeper, btccKeeper *types.MockBtcCheckpointKeeper) *Helper { + k, ctx := keepertest.BTCStakingKeeper(t, btclcKeeper, btccKeeper) ctx = ctx.WithHeaderInfo(header.Info{Height: 1}) msgSrvr := keeper.NewMsgServerImpl(*k) @@ -55,7 +54,6 @@ func NewHelper(t testing.TB, btclcKeeper *types.MockBTCLightClientKeeper, btccKe BTCStakingKeeper: k, BTCLightClientKeeper: btclcKeeper, BTCCheckpointKeeper: btccKeeper, - CheckpointingKeeper: ckptKeeper, MsgServer: msgSrvr, Net: &chaincfg.SimNetParams, } diff --git a/x/btcstaking/keeper/msg_server_test.go b/x/btcstaking/keeper/msg_server_test.go index 24d2b2cec..0fd5853b4 100644 --- a/x/btcstaking/keeper/msg_server_test.go +++ b/x/btcstaking/keeper/msg_server_test.go @@ -37,8 +37,7 @@ func FuzzMsgCreateFinalityProvider(f *testing.F) { // mock BTC light client and BTC checkpoint modules btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(t, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(t, btclcKeeper, btccKeeper) // set all parameters h.GenAndApplyParams(r) @@ -144,8 +143,7 @@ func FuzzCreateBTCDelegation(f *testing.F) { // mock BTC light client and BTC checkpoint modules btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(t, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(t, btclcKeeper, btccKeeper) // set all parameters h.GenAndApplyParams(r) @@ -189,8 +187,7 @@ func TestProperVersionInDelegation(t *testing.T) { // mock BTC light client and BTC checkpoint modules btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(t, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(t, btclcKeeper, btccKeeper) // set all parameters h.GenAndApplyParams(r) @@ -257,8 +254,7 @@ func FuzzAddCovenantSigs(f *testing.F) { // mock BTC light client and BTC checkpoint modules btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(t, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(t, btclcKeeper, btccKeeper) // set all parameters covenantSKs, _ := h.GenAndApplyParams(r) @@ -322,8 +318,7 @@ func FuzzBTCUndelegate(f *testing.F) { // mock BTC light client and BTC checkpoint modules btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(t, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(t, btclcKeeper, btccKeeper) // set all parameters covenantSKs, _ := h.GenAndApplyParams(r) @@ -395,8 +390,7 @@ func FuzzSelectiveSlashing(f *testing.F) { // mock BTC light client and BTC checkpoint modules btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(t, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(t, btclcKeeper, btccKeeper) // set all parameters covenantSKs, _ := h.GenAndApplyParams(r) @@ -462,8 +456,7 @@ func FuzzSelectiveSlashing_StakingTx(f *testing.F) { // mock BTC light client and BTC checkpoint modules btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(t, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(t, btclcKeeper, btccKeeper) // set all parameters covenantSKs, _ := h.GenAndApplyParams(r) @@ -539,8 +532,7 @@ func TestDoNotAllowDelegationWithoutFinalityProvider(t *testing.T) { btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) btccKeeper.EXPECT().GetParams(gomock.Any()).Return(btcctypes.DefaultParams()).AnyTimes() - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(t, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(t, btclcKeeper, btccKeeper) // set covenant PK to params _, covenantPKs := h.GenAndApplyParams(r) @@ -707,8 +699,7 @@ func TestCorrectUnbondingTimeInDelegation(t *testing.T) { // mock BTC light client and BTC checkpoint modules btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(t, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(t, btclcKeeper, btccKeeper) // set all parameters _, _ = h.GenAndApplyCustomParams(r, tt.finalizationTimeout, tt.minUnbondingTime) @@ -780,8 +771,7 @@ func TestMinimalUnbondingRate(t *testing.T) { // mock BTC light client and BTC checkpoint modules btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(t, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(t, btclcKeeper, btccKeeper) // set all parameters, by default minimal unbonding value is 80% of staking value _, _ = h.GenAndApplyParams(r) diff --git a/x/btcstaking/keeper/params_test.go b/x/btcstaking/keeper/params_test.go index 58f8500f4..fc484dd3a 100644 --- a/x/btcstaking/keeper/params_test.go +++ b/x/btcstaking/keeper/params_test.go @@ -5,14 +5,15 @@ import ( "math/rand" "testing" + "github.com/stretchr/testify/require" + "github.com/babylonlabs-io/babylon/testutil/datagen" testkeeper "github.com/babylonlabs-io/babylon/testutil/keeper" "github.com/babylonlabs-io/babylon/x/btcstaking/types" - "github.com/stretchr/testify/require" ) func TestGetParams(t *testing.T) { - k, ctx := testkeeper.BTCStakingKeeper(t, nil, nil, nil) + k, ctx := testkeeper.BTCStakingKeeper(t, nil, nil) params := types.DefaultParams() err := k.SetParams(ctx, params) @@ -22,7 +23,7 @@ func TestGetParams(t *testing.T) { } func TestGetParamsVersions(t *testing.T) { - k, ctx := testkeeper.BTCStakingKeeper(t, nil, nil, nil) + k, ctx := testkeeper.BTCStakingKeeper(t, nil, nil) params := types.DefaultParams() pv := k.GetParamsWithVersion(ctx) @@ -55,7 +56,7 @@ func FuzzParamsVersioning(f *testing.F) { datagen.AddRandomSeedsToFuzzer(f, 10) f.Fuzz(func(t *testing.T, seed int64) { r := rand.New(rand.NewSource(seed)) - k, ctx := testkeeper.BTCStakingKeeper(t, nil, nil, nil) + k, ctx := testkeeper.BTCStakingKeeper(t, nil, nil) numVersionsToGenerate := r.Intn(100) + 1 params0 := k.GetParams(ctx) var generatedParams []*types.Params diff --git a/x/btcstaking/keeper/power_dist_change_test.go b/x/btcstaking/keeper/power_dist_change_test.go index 65320c5df..373063aaa 100644 --- a/x/btcstaking/keeper/power_dist_change_test.go +++ b/x/btcstaking/keeper/power_dist_change_test.go @@ -4,12 +4,13 @@ import ( "math/rand" "testing" - "github.com/babylonlabs-io/babylon/testutil/datagen" - btclctypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" - "github.com/babylonlabs-io/babylon/x/btcstaking/types" "github.com/btcsuite/btcd/btcec/v2" "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + + "github.com/babylonlabs-io/babylon/testutil/datagen" + btclctypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" + "github.com/babylonlabs-io/babylon/x/btcstaking/types" ) func FuzzProcessAllPowerDistUpdateEvents_Determinism(f *testing.F) { @@ -23,8 +24,7 @@ func FuzzProcessAllPowerDistUpdateEvents_Determinism(f *testing.F) { // mock BTC light client and BTC checkpoint modules btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(t, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(t, btclcKeeper, btccKeeper) // set all parameters h.GenAndApplyParams(r) @@ -75,8 +75,7 @@ func FuzzFinalityProviderEvents(f *testing.F) { // mock BTC light client and BTC checkpoint modules btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(t, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(t, btclcKeeper, btccKeeper) // set all parameters covenantSKs, _ := h.GenAndApplyParams(r) @@ -153,8 +152,7 @@ func FuzzBTCDelegationEvents(f *testing.F) { // mock BTC light client and BTC checkpoint modules btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(t, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(t, btclcKeeper, btccKeeper) // set all parameters covenantSKs, _ := h.GenAndApplyParams(r) diff --git a/x/btcstaking/keeper/query_params_test.go b/x/btcstaking/keeper/query_params_test.go index 6d0239d0b..a4a4282a8 100644 --- a/x/btcstaking/keeper/query_params_test.go +++ b/x/btcstaking/keeper/query_params_test.go @@ -3,13 +3,14 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + testkeeper "github.com/babylonlabs-io/babylon/testutil/keeper" "github.com/babylonlabs-io/babylon/x/btcstaking/types" - "github.com/stretchr/testify/require" ) func TestParamsQuery(t *testing.T) { - keeper, ctx := testkeeper.BTCStakingKeeper(t, nil, nil, nil) + keeper, ctx := testkeeper.BTCStakingKeeper(t, nil, nil) params := types.DefaultParams() err := keeper.SetParams(ctx, params) @@ -21,7 +22,7 @@ func TestParamsQuery(t *testing.T) { } func TestParamsByVersionQuery(t *testing.T) { - keeper, ctx := testkeeper.BTCStakingKeeper(t, nil, nil, nil) + keeper, ctx := testkeeper.BTCStakingKeeper(t, nil, nil) // starting with `1` as BTCStakingKeeper creates params with version 0 params1 := types.DefaultParams() diff --git a/x/btcstaking/keeper/voting_power_table_test.go b/x/btcstaking/keeper/voting_power_table_test.go index a8c743afe..48a68ff1b 100644 --- a/x/btcstaking/keeper/voting_power_table_test.go +++ b/x/btcstaking/keeper/voting_power_table_test.go @@ -5,11 +5,12 @@ import ( "sort" "testing" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + "github.com/babylonlabs-io/babylon/testutil/datagen" btclctypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" "github.com/babylonlabs-io/babylon/x/btcstaking/types" - "github.com/golang/mock/gomock" - "github.com/stretchr/testify/require" ) func FuzzVotingPowerTable(f *testing.F) { @@ -23,8 +24,7 @@ func FuzzVotingPowerTable(f *testing.F) { // mock BTC light client and BTC checkpoint modules btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(t, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(t, btclcKeeper, btccKeeper) // set all parameters covenantSKs, _ := h.GenAndApplyParams(r) @@ -162,8 +162,7 @@ func FuzzVotingPowerTable_ActiveFinalityProviders(f *testing.F) { // mock BTC light client and BTC checkpoint modules btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(t, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(t, btclcKeeper, btccKeeper) // set all parameters covenantSKs, _ := h.GenAndApplyParams(r) @@ -247,8 +246,7 @@ func FuzzVotingPowerTable_ActiveFinalityProviderRotation(f *testing.F) { // mock BTC light client and BTC checkpoint modules btclcKeeper := types.NewMockBTCLightClientKeeper(ctrl) btccKeeper := types.NewMockBtcCheckpointKeeper(ctrl) - ckptKeeper := types.NewMockCheckpointingKeeper(ctrl) - h := NewHelper(t, btclcKeeper, btccKeeper, ckptKeeper) + h := NewHelper(t, btclcKeeper, btccKeeper) // set all parameters covenantSKs, _ := h.GenAndApplyParams(r) diff --git a/x/btcstaking/types/errors.go b/x/btcstaking/types/errors.go index 5de1421d5..ffca7d9ab 100644 --- a/x/btcstaking/types/errors.go +++ b/x/btcstaking/types/errors.go @@ -11,7 +11,6 @@ var ( ErrBTCDelegationNotFound = errorsmod.Register(ModuleName, 1102, "the BTC delegation is not found") ErrFpRegistered = errorsmod.Register(ModuleName, 1103, "the finality provider has already been registered") ErrFpAlreadySlashed = errorsmod.Register(ModuleName, 1104, "the finality provider has already been slashed") - ErrFpNotBTCTimestamped = errorsmod.Register(ModuleName, 1105, "the finality provider is not BTC timestamped yet") ErrBTCStakingNotActivated = errorsmod.Register(ModuleName, 1106, "the BTC staking protocol is not activated yet") ErrBTCHeightNotFound = errorsmod.Register(ModuleName, 1107, "the BTC height is not found") ErrReusedStakingTx = errorsmod.Register(ModuleName, 1108, "the BTC staking tx is already used") diff --git a/x/btcstaking/types/expected_keepers.go b/x/btcstaking/types/expected_keepers.go index 237879011..04e85989d 100644 --- a/x/btcstaking/types/expected_keepers.go +++ b/x/btcstaking/types/expected_keepers.go @@ -7,7 +7,6 @@ import ( bbn "github.com/babylonlabs-io/babylon/types" btcctypes "github.com/babylonlabs-io/babylon/x/btccheckpoint/types" btclctypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" - etypes "github.com/babylonlabs-io/babylon/x/epoching/types" ) type BTCLightClientKeeper interface { @@ -21,11 +20,6 @@ type BtcCheckpointKeeper interface { GetParams(ctx context.Context) (p btcctypes.Params) } -type CheckpointingKeeper interface { - GetEpoch(ctx context.Context) *etypes.Epoch - GetLastFinalizedEpoch(ctx context.Context) uint64 -} - type BtcStakingHooks interface { AfterFinalityProviderActivated(ctx context.Context, fpPk *bbn.BIP340PubKey) error } diff --git a/x/btcstaking/types/mocked_keepers.go b/x/btcstaking/types/mocked_keepers.go index d68d89080..a8b740fd0 100644 --- a/x/btcstaking/types/mocked_keepers.go +++ b/x/btcstaking/types/mocked_keepers.go @@ -12,7 +12,6 @@ import ( types "github.com/babylonlabs-io/babylon/types" types0 "github.com/babylonlabs-io/babylon/x/btccheckpoint/types" types1 "github.com/babylonlabs-io/babylon/x/btclightclient/types" - types2 "github.com/babylonlabs-io/babylon/x/epoching/types" gomock "github.com/golang/mock/gomock" ) @@ -132,57 +131,6 @@ func (mr *MockBtcCheckpointKeeperMockRecorder) GetPowLimit() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPowLimit", reflect.TypeOf((*MockBtcCheckpointKeeper)(nil).GetPowLimit)) } -// MockCheckpointingKeeper is a mock of CheckpointingKeeper interface. -type MockCheckpointingKeeper struct { - ctrl *gomock.Controller - recorder *MockCheckpointingKeeperMockRecorder -} - -// MockCheckpointingKeeperMockRecorder is the mock recorder for MockCheckpointingKeeper. -type MockCheckpointingKeeperMockRecorder struct { - mock *MockCheckpointingKeeper -} - -// NewMockCheckpointingKeeper creates a new mock instance. -func NewMockCheckpointingKeeper(ctrl *gomock.Controller) *MockCheckpointingKeeper { - mock := &MockCheckpointingKeeper{ctrl: ctrl} - mock.recorder = &MockCheckpointingKeeperMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockCheckpointingKeeper) EXPECT() *MockCheckpointingKeeperMockRecorder { - return m.recorder -} - -// GetEpoch mocks base method. -func (m *MockCheckpointingKeeper) GetEpoch(ctx context.Context) *types2.Epoch { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetEpoch", ctx) - ret0, _ := ret[0].(*types2.Epoch) - return ret0 -} - -// GetEpoch indicates an expected call of GetEpoch. -func (mr *MockCheckpointingKeeperMockRecorder) GetEpoch(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEpoch", reflect.TypeOf((*MockCheckpointingKeeper)(nil).GetEpoch), ctx) -} - -// GetLastFinalizedEpoch mocks base method. -func (m *MockCheckpointingKeeper) GetLastFinalizedEpoch(ctx context.Context) uint64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetLastFinalizedEpoch", ctx) - ret0, _ := ret[0].(uint64) - return ret0 -} - -// GetLastFinalizedEpoch indicates an expected call of GetLastFinalizedEpoch. -func (mr *MockCheckpointingKeeperMockRecorder) GetLastFinalizedEpoch(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLastFinalizedEpoch", reflect.TypeOf((*MockCheckpointingKeeper)(nil).GetLastFinalizedEpoch), ctx) -} - // MockBtcStakingHooks is a mock of BtcStakingHooks interface. type MockBtcStakingHooks struct { ctrl *gomock.Controller diff --git a/x/finality/genesis_test.go b/x/finality/genesis_test.go index f66eb3555..3e7b821f7 100644 --- a/x/finality/genesis_test.go +++ b/x/finality/genesis_test.go @@ -3,11 +3,12 @@ package finality_test import ( "testing" + "github.com/stretchr/testify/require" + keepertest "github.com/babylonlabs-io/babylon/testutil/keeper" "github.com/babylonlabs-io/babylon/testutil/nullify" "github.com/babylonlabs-io/babylon/x/finality" "github.com/babylonlabs-io/babylon/x/finality/types" - "github.com/stretchr/testify/require" ) func TestGenesis(t *testing.T) { @@ -15,7 +16,7 @@ func TestGenesis(t *testing.T) { Params: types.DefaultParams(), } - k, ctx := keepertest.FinalityKeeper(t, nil, nil) + k, ctx := keepertest.FinalityKeeper(t, nil, nil, nil) finality.InitGenesis(ctx, *k, genesisState) got := finality.ExportGenesis(ctx, *k) require.NotNil(t, got) diff --git a/x/finality/keeper/genesis_test.go b/x/finality/keeper/genesis_test.go index cdad29119..695b504d5 100644 --- a/x/finality/keeper/genesis_test.go +++ b/x/finality/keeper/genesis_test.go @@ -16,7 +16,7 @@ func FuzzTestExportGenesis(f *testing.F) { datagen.AddRandomSeedsToFuzzer(f, 10) f.Fuzz(func(t *testing.T, seed int64) { r := rand.New(rand.NewSource(seed)) - k, ctx := keepertest.FinalityKeeper(t, nil, nil) + k, ctx := keepertest.FinalityKeeper(t, nil, nil, nil) btcSK, btcPK, err := datagen.GenRandomBTCKeyPair(r) require.NoError(t, err) diff --git a/x/finality/keeper/grpc_query_test.go b/x/finality/keeper/grpc_query_test.go index d8d878696..8f15e20a0 100644 --- a/x/finality/keeper/grpc_query_test.go +++ b/x/finality/keeper/grpc_query_test.go @@ -14,6 +14,7 @@ import ( "github.com/babylonlabs-io/babylon/testutil/datagen" testkeeper "github.com/babylonlabs-io/babylon/testutil/keeper" bbn "github.com/babylonlabs-io/babylon/types" + epochingtypes "github.com/babylonlabs-io/babylon/x/epoching/types" "github.com/babylonlabs-io/babylon/x/finality/keeper" "github.com/babylonlabs-io/babylon/x/finality/types" ) @@ -24,7 +25,7 @@ func FuzzBlock(f *testing.F) { r := rand.New(rand.NewSource(seed)) // Setup keeper and context - keeper, ctx := testkeeper.FinalityKeeper(t, nil, nil) + keeper, ctx := testkeeper.FinalityKeeper(t, nil, nil, nil) ctx = sdk.UnwrapSDKContext(ctx) height := datagen.RandomInt(r, 100) @@ -55,7 +56,7 @@ func FuzzListBlocks(f *testing.F) { r := rand.New(rand.NewSource(seed)) // Setup keeper and context - keeper, ctx := testkeeper.FinalityKeeper(t, nil, nil) + keeper, ctx := testkeeper.FinalityKeeper(t, nil, nil, nil) ctx = sdk.UnwrapSDKContext(ctx) // index a random list of finalised blocks @@ -146,7 +147,7 @@ func FuzzVotesAtHeight(f *testing.F) { r := rand.New(rand.NewSource(seed)) // Setup keeper and context - keeper, ctx := testkeeper.FinalityKeeper(t, nil, nil) + keeper, ctx := testkeeper.FinalityKeeper(t, nil, nil, nil) ctx = sdk.UnwrapSDKContext(ctx) // Add random number of voted finality providers to the store @@ -191,7 +192,8 @@ func FuzzListPubRandCommit(f *testing.F) { // Setup keeper and context bsKeeper := types.NewMockBTCStakingKeeper(ctrl) - fKeeper, ctx := testkeeper.FinalityKeeper(t, bsKeeper, nil) + cKeeper := types.NewMockCheckpointingKeeper(ctrl) + fKeeper, ctx := testkeeper.FinalityKeeper(t, bsKeeper, nil, cKeeper) ctx = sdk.UnwrapSDKContext(ctx) ms := keeper.NewMsgServerImpl(*fKeeper) @@ -205,6 +207,7 @@ func FuzzListPubRandCommit(f *testing.F) { require.NoError(t, err) bsKeeper.EXPECT().GetFinalityProvider(gomock.Any(), gomock.Eq(bip340PK.MustMarshal())).Return(fp, nil).AnyTimes() bsKeeper.EXPECT().HasFinalityProvider(gomock.Any(), gomock.Eq(bip340PK.MustMarshal())).Return(true).AnyTimes() + cKeeper.EXPECT().GetEpoch(gomock.Any()).Return(&epochingtypes.Epoch{EpochNumber: 1}).AnyTimes() numPrCommitList := datagen.RandomInt(r, 10) + 1 prCommitList := []*types.PubRandCommit{} @@ -260,7 +263,7 @@ func FuzzQueryEvidence(f *testing.F) { r := rand.New(rand.NewSource(seed)) // Setup keeper and context - keeper, ctx := testkeeper.FinalityKeeper(t, nil, nil) + keeper, ctx := testkeeper.FinalityKeeper(t, nil, nil, nil) ctx = sdk.UnwrapSDKContext(ctx) // set random BTC SK PK @@ -307,7 +310,7 @@ func FuzzListEvidences(f *testing.F) { r := rand.New(rand.NewSource(seed)) // Setup keeper and context - keeper, ctx := testkeeper.FinalityKeeper(t, nil, nil) + keeper, ctx := testkeeper.FinalityKeeper(t, nil, nil, nil) ctx = sdk.UnwrapSDKContext(ctx) // generate a random list of evidences since startHeight @@ -371,7 +374,7 @@ func FuzzSigningInfo(f *testing.F) { r := rand.New(rand.NewSource(seed)) // Setup keeper and context - fKeeper, ctx := testkeeper.FinalityKeeper(t, nil, nil) + fKeeper, ctx := testkeeper.FinalityKeeper(t, nil, nil, nil) ctx = sdk.UnwrapSDKContext(ctx) // generate a random list of signing info diff --git a/x/finality/keeper/keeper.go b/x/finality/keeper/keeper.go index fe185a569..d569896f9 100644 --- a/x/finality/keeper/keeper.go +++ b/x/finality/keeper/keeper.go @@ -18,8 +18,9 @@ type ( cdc codec.BinaryCodec storeService corestoretypes.KVStoreService - BTCStakingKeeper types.BTCStakingKeeper - IncentiveKeeper types.IncentiveKeeper + BTCStakingKeeper types.BTCStakingKeeper + IncentiveKeeper types.IncentiveKeeper + CheckpointingKeeper types.CheckpointingKeeper // the address capable of executing a MsgUpdateParams message. Typically, this // should be the x/gov module account. authority string @@ -38,6 +39,7 @@ func NewKeeper( storeService corestoretypes.KVStoreService, btcstakingKeeper types.BTCStakingKeeper, incentiveKeeper types.IncentiveKeeper, + checkpointingKeeper types.CheckpointingKeeper, authority string, ) Keeper { sb := collections.NewSchemaBuilder(storeService) @@ -45,9 +47,10 @@ func NewKeeper( cdc: cdc, storeService: storeService, - BTCStakingKeeper: btcstakingKeeper, - IncentiveKeeper: incentiveKeeper, - authority: authority, + BTCStakingKeeper: btcstakingKeeper, + IncentiveKeeper: incentiveKeeper, + CheckpointingKeeper: checkpointingKeeper, + authority: authority, FinalityProviderSigningTracker: collections.NewMap( sb, types.FinalityProviderSigningInfoKeyPrefix, @@ -81,5 +84,14 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { } func (k Keeper) GetLastFinalizedEpoch(ctx context.Context) uint64 { - return k.BTCStakingKeeper.GetLastFinalizedEpoch(ctx) + return k.CheckpointingKeeper.GetLastFinalizedEpoch(ctx) +} + +func (k Keeper) GetCurrentEpoch(ctx context.Context) uint64 { + currentEpoch := k.CheckpointingKeeper.GetEpoch(ctx) + if currentEpoch == nil { + panic("cannot get the current epoch") + } + + return currentEpoch.EpochNumber } diff --git a/x/finality/keeper/liveness_test.go b/x/finality/keeper/liveness_test.go index da92702e5..74f25f2d6 100644 --- a/x/finality/keeper/liveness_test.go +++ b/x/finality/keeper/liveness_test.go @@ -24,7 +24,8 @@ func FuzzHandleLiveness(f *testing.F) { bsKeeper := types.NewMockBTCStakingKeeper(ctrl) bsKeeper.EXPECT().GetParams(gomock.Any()).Return(bstypes.Params{MaxActiveFinalityProviders: 100}).AnyTimes() iKeeper := types.NewMockIncentiveKeeper(ctrl) - fKeeper, ctx := keepertest.FinalityKeeper(t, bsKeeper, iKeeper) + cKeeper := types.NewMockCheckpointingKeeper(ctrl) + fKeeper, ctx := keepertest.FinalityKeeper(t, bsKeeper, iKeeper, cKeeper) mockedHooks := types.NewMockFinalityHooks(ctrl) mockedHooks.EXPECT().AfterSluggishFinalityProviderDetected(gomock.Any(), gomock.Any()).Return(nil).AnyTimes() diff --git a/x/finality/keeper/msg_server.go b/x/finality/keeper/msg_server.go index 3576f7cd1..8282074fc 100644 --- a/x/finality/keeper/msg_server.go +++ b/x/finality/keeper/msg_server.go @@ -7,12 +7,13 @@ import ( "time" errorsmod "cosmossdk.io/errors" - bbn "github.com/babylonlabs-io/babylon/types" - bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" - "github.com/babylonlabs-io/babylon/x/finality/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + bbn "github.com/babylonlabs-io/babylon/types" + bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" + "github.com/babylonlabs-io/babylon/x/finality/types" ) type msgServer struct { @@ -82,7 +83,7 @@ func (ms msgServer) AddFinalitySig(goCtx context.Context, req *types.MsgAddFinal } fpPK := req.FpBtcPk if ms.BTCStakingKeeper.GetVotingPower(ctx, fpPK.MustMarshal(), req.BlockHeight) == 0 { - return nil, types.ErrInvalidFinalitySig.Wrapf("the finality provider %v does not have voting power at height %d", fpPK.MustMarshal(), req.BlockHeight) + return nil, types.ErrInvalidFinalitySig.Wrapf("the finality provider %s does not have voting power at height %d", fpPK.MarshalHex(), req.BlockHeight) } // ensure the finality provider has not cast the same vote yet @@ -101,6 +102,13 @@ func (ms msgServer) AddFinalitySig(goCtx context.Context, req *types.MsgAddFinal if err != nil { return nil, err } + // ensure the finality provider's last randomness commit is already finalised by BTC timestamping + finalizedEpoch := ms.GetLastFinalizedEpoch(ctx) + if finalizedEpoch < prCommit.EpochNum { + return nil, types.ErrPubRandCommitNotBTCTimestamped. + Wrapf("the finality provider %s last committed epoch number: %d, last finalized epoch number: %d", + fp.BtcPk.MarshalHex(), prCommit.EpochNum, finalizedEpoch) + } // verify the finality signature message w.r.t. the public randomness commitment // including the public randomness inclusion proof and the finality signature @@ -132,7 +140,7 @@ func (ms msgServer) AddFinalitySig(goCtx context.Context, req *types.MsgAddFinal // if this finality provider has also signed canonical block, slash it canonicalSig, err := ms.GetSig(ctx, req.BlockHeight, fpPK) if err == nil { - //set canonial sig + // set canonial sig evidence.CanonicalFinalitySig = canonicalSig // slash this finality provider, including setting its voting power to // zero, extracting its BTC SK, and emit an event @@ -206,6 +214,7 @@ func (ms msgServer) CommitPubRandList(goCtx context.Context, req *types.MsgCommi StartHeight: req.StartHeight, NumPubRand: req.NumPubRand, Commitment: req.Commitment, + EpochNum: ms.GetCurrentEpoch(ctx), } // get last public randomness commitment diff --git a/x/finality/keeper/msg_server_test.go b/x/finality/keeper/msg_server_test.go index 231ef895e..7bb39d9c9 100644 --- a/x/finality/keeper/msg_server_test.go +++ b/x/finality/keeper/msg_server_test.go @@ -7,18 +7,20 @@ import ( "time" "cosmossdk.io/core/header" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + "github.com/babylonlabs-io/babylon/testutil/datagen" keepertest "github.com/babylonlabs-io/babylon/testutil/keeper" bbn "github.com/babylonlabs-io/babylon/types" bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" + epochingtypes "github.com/babylonlabs-io/babylon/x/epoching/types" "github.com/babylonlabs-io/babylon/x/finality/keeper" "github.com/babylonlabs-io/babylon/x/finality/types" - "github.com/golang/mock/gomock" - "github.com/stretchr/testify/require" ) func setupMsgServer(t testing.TB) (*keeper.Keeper, types.MsgServer, context.Context) { - fKeeper, ctx := keepertest.FinalityKeeper(t, nil, nil) + fKeeper, ctx := keepertest.FinalityKeeper(t, nil, nil, nil) return fKeeper, keeper.NewMsgServerImpl(*fKeeper), ctx } @@ -29,7 +31,7 @@ func TestMsgServer(t *testing.T) { } func FuzzCommitPubRandList(f *testing.F) { - datagen.AddRandomSeedsToFuzzer(f, 10) + datagen.AddRandomSeedsToFuzzer(f, 100) f.Fuzz(func(t *testing.T, seed int64) { r := rand.New(rand.NewSource(seed)) @@ -37,8 +39,11 @@ func FuzzCommitPubRandList(f *testing.F) { defer ctrl.Finish() bsKeeper := types.NewMockBTCStakingKeeper(ctrl) - fKeeper, ctx := keepertest.FinalityKeeper(t, bsKeeper, nil) + cKeeper := types.NewMockCheckpointingKeeper(ctrl) + fKeeper, ctx := keepertest.FinalityKeeper(t, bsKeeper, nil, cKeeper) ms := keeper.NewMsgServerImpl(*fKeeper) + committedEpochNum := datagen.GenRandomEpochNum(r) + cKeeper.EXPECT().GetEpoch(gomock.Any()).Return(&epochingtypes.Epoch{EpochNumber: committedEpochNum}).AnyTimes() // create a random finality provider btcSK, btcPK, err := datagen.GenRandomBTCKeyPair(r) @@ -75,6 +80,11 @@ func FuzzCommitPubRandList(f *testing.F) { // query last public randomness and assert lastPrCommit := fKeeper.GetLastPubRandCommit(ctx, fpBTCPK) require.NotNil(t, lastPrCommit) + require.Equal(t, committedEpochNum, lastPrCommit.EpochNum) + committedHeight := datagen.RandomInt(r, int(numPubRand)) + startHeight + commitByHeight, err := fKeeper.GetPubRandCommitForHeight(ctx, fpBTCPK, committedHeight) + require.NoError(t, err) + require.Equal(t, committedEpochNum, commitByHeight.EpochNum) // Case 4: commit a pubrand list with overlap of the existing pubrand in KVStore and it should fail overlappedStartHeight := startHeight + numPubRand - 1 - datagen.RandomInt(r, 5) @@ -93,7 +103,7 @@ func FuzzCommitPubRandList(f *testing.F) { } func FuzzAddFinalitySig(f *testing.F) { - datagen.AddRandomSeedsToFuzzer(f, 10) + datagen.AddRandomSeedsToFuzzer(f, 100) f.Fuzz(func(t *testing.T, seed int64) { r := rand.New(rand.NewSource(seed)) @@ -101,7 +111,8 @@ func FuzzAddFinalitySig(f *testing.F) { defer ctrl.Finish() bsKeeper := types.NewMockBTCStakingKeeper(ctrl) - fKeeper, ctx := keepertest.FinalityKeeper(t, bsKeeper, nil) + cKeeper := types.NewMockCheckpointingKeeper(ctrl) + fKeeper, ctx := keepertest.FinalityKeeper(t, bsKeeper, nil, cKeeper) ms := keeper.NewMsgServerImpl(*fKeeper) // create and register a random finality provider @@ -113,6 +124,11 @@ func FuzzAddFinalitySig(f *testing.F) { fpBTCPKBytes := fpBTCPK.MustMarshal() require.NoError(t, err) bsKeeper.EXPECT().HasFinalityProvider(gomock.Any(), gomock.Eq(fpBTCPKBytes)).Return(true).AnyTimes() + + // set committed epoch num + committedEpochNum := datagen.GenRandomEpochNum(r) + 1 + cKeeper.EXPECT().GetEpoch(gomock.Any()).Return(&epochingtypes.Epoch{EpochNumber: committedEpochNum}).AnyTimes() + // commit some public randomness startHeight := uint64(0) numPubRand := uint64(200) @@ -128,6 +144,18 @@ func FuzzAddFinalitySig(f *testing.F) { msg, err := datagen.NewMsgAddFinalitySig(signer, btcSK, startHeight, blockHeight, randListInfo, blockAppHash) require.NoError(t, err) + // Case 0: fail if the committed epoch is not finalized + lastFinalizedEpoch := datagen.RandomInt(r, int(committedEpochNum)) + o1 := cKeeper.EXPECT().GetLastFinalizedEpoch(gomock.Any()).Return(lastFinalizedEpoch).Times(1) + bsKeeper.EXPECT().GetVotingPower(gomock.Any(), gomock.Eq(fpBTCPKBytes), gomock.Eq(blockHeight)).Return(uint64(1)).Times(1) + bsKeeper.EXPECT().GetFinalityProvider(gomock.Any(), gomock.Eq(fpBTCPKBytes)).Return(fp, nil).Times(1) + _, err = ms.AddFinalitySig(ctx, msg) + require.ErrorIs(t, err, types.ErrPubRandCommitNotBTCTimestamped) + + // set the committed epoch finalized for the rest of the cases + lastFinalizedEpoch = datagen.GenRandomEpochNum(r) + committedEpochNum + cKeeper.EXPECT().GetLastFinalizedEpoch(gomock.Any()).Return(lastFinalizedEpoch).After(o1).AnyTimes() + // Case 1: fail if the finality provider does not have voting power bsKeeper.EXPECT().GetVotingPower(gomock.Any(), gomock.Eq(fpBTCPKBytes), gomock.Eq(blockHeight)).Return(uint64(0)).Times(1) bsKeeper.EXPECT().GetFinalityProvider(gomock.Any(), gomock.Eq(fpBTCPKBytes)).Return(fp, nil).Times(1) @@ -208,7 +236,8 @@ func TestVoteForConflictingHashShouldRetrieveEvidenceAndSlash(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() bsKeeper := types.NewMockBTCStakingKeeper(ctrl) - fKeeper, ctx := keepertest.FinalityKeeper(t, bsKeeper, nil) + cKeeper := types.NewMockCheckpointingKeeper(ctrl) + fKeeper, ctx := keepertest.FinalityKeeper(t, bsKeeper, nil, cKeeper) ms := keeper.NewMsgServerImpl(*fKeeper) // create and register a random finality provider btcSK, btcPK, err := datagen.GenRandomBTCKeyPair(r) @@ -220,6 +249,8 @@ func TestVoteForConflictingHashShouldRetrieveEvidenceAndSlash(t *testing.T) { require.NoError(t, err) bsKeeper.EXPECT().HasFinalityProvider(gomock.Any(), gomock.Eq(fpBTCPKBytes)).Return(true).AnyTimes() + cKeeper.EXPECT().GetEpoch(gomock.Any()).Return(&epochingtypes.Epoch{EpochNumber: 1}).AnyTimes() + cKeeper.EXPECT().GetLastFinalizedEpoch(gomock.Any()).Return(uint64(1)).AnyTimes() // commit some public randomness startHeight := uint64(0) numPubRand := uint64(200) @@ -245,7 +276,6 @@ func TestVoteForConflictingHashShouldRetrieveEvidenceAndSlash(t *testing.T) { // some "evidence" ctx = ctx.WithHeaderInfo(header.Info{Height: int64(blockHeight), AppHash: forkHash}) msg1, err := datagen.NewMsgAddFinalitySig(signer, btcSK, startHeight, blockHeight, randListInfo, forkHash) - require.NoError(t, err) bsKeeper.EXPECT().GetVotingPower(gomock.Any(), gomock.Eq(fpBTCPKBytes), diff --git a/x/finality/keeper/params_test.go b/x/finality/keeper/params_test.go index 649fd3eda..b4621546d 100644 --- a/x/finality/keeper/params_test.go +++ b/x/finality/keeper/params_test.go @@ -3,13 +3,14 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + testkeeper "github.com/babylonlabs-io/babylon/testutil/keeper" "github.com/babylonlabs-io/babylon/x/finality/types" - "github.com/stretchr/testify/require" ) func TestGetParams(t *testing.T) { - k, ctx := testkeeper.FinalityKeeper(t, nil, nil) + k, ctx := testkeeper.FinalityKeeper(t, nil, nil, nil) params := types.DefaultParams() err := k.SetParams(ctx, params) diff --git a/x/finality/keeper/query_params_test.go b/x/finality/keeper/query_params_test.go index 2bdbfcc07..bc670b3e0 100644 --- a/x/finality/keeper/query_params_test.go +++ b/x/finality/keeper/query_params_test.go @@ -3,13 +3,14 @@ package keeper_test import ( "testing" + "github.com/stretchr/testify/require" + testkeeper "github.com/babylonlabs-io/babylon/testutil/keeper" "github.com/babylonlabs-io/babylon/x/finality/types" - "github.com/stretchr/testify/require" ) func TestParamsQuery(t *testing.T) { - keeper, ctx := testkeeper.FinalityKeeper(t, nil, nil) + keeper, ctx := testkeeper.FinalityKeeper(t, nil, nil, nil) params := types.DefaultParams() err := keeper.SetParams(ctx, params) require.NoError(t, err) diff --git a/x/finality/keeper/tallying_bench_test.go b/x/finality/keeper/tallying_bench_test.go index abe4c38ca..52b1532d7 100644 --- a/x/finality/keeper/tallying_bench_test.go +++ b/x/finality/keeper/tallying_bench_test.go @@ -8,13 +8,14 @@ import ( "testing" "time" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + "github.com/babylonlabs-io/babylon/testutil/datagen" keepertest "github.com/babylonlabs-io/babylon/testutil/keeper" bbn "github.com/babylonlabs-io/babylon/types" bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" "github.com/babylonlabs-io/babylon/x/finality/types" - "github.com/golang/mock/gomock" - "github.com/stretchr/testify/require" ) func benchmarkTallyBlocks(b *testing.B, numFPs int) { @@ -24,7 +25,8 @@ func benchmarkTallyBlocks(b *testing.B, numFPs int) { bsKeeper := types.NewMockBTCStakingKeeper(ctrl) iKeeper := types.NewMockIncentiveKeeper(ctrl) - fKeeper, ctx := keepertest.FinalityKeeper(b, bsKeeper, iKeeper) + cKeeper := types.NewMockCheckpointingKeeper(ctrl) + fKeeper, ctx := keepertest.FinalityKeeper(b, bsKeeper, iKeeper, cKeeper) // activate BTC staking protocol at a random height activatedHeight := uint64(1) diff --git a/x/finality/keeper/tallying_test.go b/x/finality/keeper/tallying_test.go index 881985136..9a69988d2 100644 --- a/x/finality/keeper/tallying_test.go +++ b/x/finality/keeper/tallying_test.go @@ -5,15 +5,16 @@ import ( "math/rand" "testing" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + "github.com/babylonlabs-io/babylon/testutil/datagen" keepertest "github.com/babylonlabs-io/babylon/testutil/keeper" bbn "github.com/babylonlabs-io/babylon/types" bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" "github.com/babylonlabs-io/babylon/x/finality/keeper" "github.com/babylonlabs-io/babylon/x/finality/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/golang/mock/gomock" - "github.com/stretchr/testify/require" ) func FuzzTallying_PanicCases(f *testing.F) { @@ -26,7 +27,8 @@ func FuzzTallying_PanicCases(f *testing.F) { bsKeeper := types.NewMockBTCStakingKeeper(ctrl) iKeeper := types.NewMockIncentiveKeeper(ctrl) - fKeeper, ctx := keepertest.FinalityKeeper(t, bsKeeper, iKeeper) + cKeeper := types.NewMockCheckpointingKeeper(ctrl) + fKeeper, ctx := keepertest.FinalityKeeper(t, bsKeeper, iKeeper, cKeeper) // Case 1: expect to panic if tallying upon BTC staking protocol is not activated bsKeeper.EXPECT().GetBTCStakingActivatedHeight(gomock.Any()).Return(uint64(0), bstypes.ErrBTCStakingNotActivated).Times(1) @@ -56,7 +58,8 @@ func FuzzTallying_FinalizingNoBlock(f *testing.F) { bsKeeper := types.NewMockBTCStakingKeeper(ctrl) iKeeper := types.NewMockIncentiveKeeper(ctrl) - fKeeper, ctx := keepertest.FinalityKeeper(t, bsKeeper, iKeeper) + cKeeper := types.NewMockCheckpointingKeeper(ctrl) + fKeeper, ctx := keepertest.FinalityKeeper(t, bsKeeper, iKeeper, cKeeper) // activate BTC staking protocol at a random height activatedHeight := datagen.RandomInt(r, 10) + 1 @@ -99,7 +102,8 @@ func FuzzTallying_FinalizingSomeBlocks(f *testing.F) { bsKeeper := types.NewMockBTCStakingKeeper(ctrl) bsKeeper.EXPECT().GetParams(gomock.Any()).Return(bstypes.Params{MaxActiveFinalityProviders: 100}).AnyTimes() iKeeper := types.NewMockIncentiveKeeper(ctrl) - fKeeper, ctx := keepertest.FinalityKeeper(t, bsKeeper, iKeeper) + cKeeper := types.NewMockCheckpointingKeeper(ctrl) + fKeeper, ctx := keepertest.FinalityKeeper(t, bsKeeper, iKeeper, cKeeper) // activate BTC staking protocol at a random height activatedHeight := datagen.RandomInt(r, 10) + 1 diff --git a/x/finality/keeper/votes_bench_test.go b/x/finality/keeper/votes_bench_test.go index 2f78a75c4..3a0f97faa 100644 --- a/x/finality/keeper/votes_bench_test.go +++ b/x/finality/keeper/votes_bench_test.go @@ -8,13 +8,14 @@ import ( "time" "cosmossdk.io/core/header" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/require" + "github.com/babylonlabs-io/babylon/testutil/datagen" keepertest "github.com/babylonlabs-io/babylon/testutil/keeper" bbn "github.com/babylonlabs-io/babylon/types" "github.com/babylonlabs-io/babylon/x/finality/keeper" "github.com/babylonlabs-io/babylon/x/finality/types" - "github.com/golang/mock/gomock" - "github.com/stretchr/testify/require" ) func benchmarkAddFinalitySig(b *testing.B) { @@ -23,7 +24,8 @@ func benchmarkAddFinalitySig(b *testing.B) { defer ctrl.Finish() bsKeeper := types.NewMockBTCStakingKeeper(ctrl) - fKeeper, ctx := keepertest.FinalityKeeper(b, bsKeeper, nil) + cKeeper := types.NewMockCheckpointingKeeper(ctrl) + fKeeper, ctx := keepertest.FinalityKeeper(b, bsKeeper, nil, cKeeper) ms := keeper.NewMsgServerImpl(*fKeeper) // create a random finality provider diff --git a/x/finality/types/errors.go b/x/finality/types/errors.go index ee10b27fb..6e3b89eea 100644 --- a/x/finality/types/errors.go +++ b/x/finality/types/errors.go @@ -6,15 +6,16 @@ import ( // x/finality module sentinel errors var ( - ErrBlockNotFound = errorsmod.Register(ModuleName, 1100, "Block is not found") - ErrVoteNotFound = errorsmod.Register(ModuleName, 1101, "vote is not found") - ErrHeightTooHigh = errorsmod.Register(ModuleName, 1102, "the chain has not reached the given height yet") - ErrPubRandNotFound = errorsmod.Register(ModuleName, 1103, "public randomness is not found") - ErrPubRandCommitNotFound = errorsmod.Register(ModuleName, 1104, "public randomness commitment is not found") - ErrNoPubRandYet = errorsmod.Register(ModuleName, 1105, "the finality provider has not committed any public randomness yet") - ErrTooFewPubRand = errorsmod.Register(ModuleName, 1106, "the request contains too few public randomness") - ErrInvalidPubRand = errorsmod.Register(ModuleName, 1107, "the public randomness list is invalid") - ErrEvidenceNotFound = errorsmod.Register(ModuleName, 1108, "evidence is not found") - ErrInvalidFinalitySig = errorsmod.Register(ModuleName, 1109, "finality signature is not valid") - ErrNoSlashableEvidence = errorsmod.Register(ModuleName, 1110, "there is no slashable evidence") + ErrBlockNotFound = errorsmod.Register(ModuleName, 1100, "Block is not found") + ErrVoteNotFound = errorsmod.Register(ModuleName, 1101, "vote is not found") + ErrHeightTooHigh = errorsmod.Register(ModuleName, 1102, "the chain has not reached the given height yet") + ErrPubRandNotFound = errorsmod.Register(ModuleName, 1103, "public randomness is not found") + ErrPubRandCommitNotFound = errorsmod.Register(ModuleName, 1104, "public randomness commitment is not found") + ErrNoPubRandYet = errorsmod.Register(ModuleName, 1105, "the finality provider has not committed any public randomness yet") + ErrTooFewPubRand = errorsmod.Register(ModuleName, 1106, "the request contains too few public randomness") + ErrInvalidPubRand = errorsmod.Register(ModuleName, 1107, "the public randomness list is invalid") + ErrEvidenceNotFound = errorsmod.Register(ModuleName, 1108, "evidence is not found") + ErrInvalidFinalitySig = errorsmod.Register(ModuleName, 1109, "finality signature is not valid") + ErrNoSlashableEvidence = errorsmod.Register(ModuleName, 1110, "there is no slashable evidence") + ErrPubRandCommitNotBTCTimestamped = errorsmod.Register(ModuleName, 1111, "the public randomness commit is not BTC timestamped yet") ) diff --git a/x/finality/types/expected_keepers.go b/x/finality/types/expected_keepers.go index f4d6e58d9..f3e47d3ff 100644 --- a/x/finality/types/expected_keepers.go +++ b/x/finality/types/expected_keepers.go @@ -5,6 +5,7 @@ import ( bbn "github.com/babylonlabs-io/babylon/types" bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" + etypes "github.com/babylonlabs-io/babylon/x/epoching/types" ) type BTCStakingKeeper interface { @@ -17,10 +18,14 @@ type BTCStakingKeeper interface { GetBTCStakingActivatedHeight(ctx context.Context) (uint64, error) GetVotingPowerDistCache(ctx context.Context, height uint64) (*bstypes.VotingPowerDistCache, error) RemoveVotingPowerDistCache(ctx context.Context, height uint64) - GetLastFinalizedEpoch(ctx context.Context) uint64 RevertSluggishFinalityProvider(ctx context.Context, fpBTCPK []byte) error } +type CheckpointingKeeper interface { + GetEpoch(ctx context.Context) *etypes.Epoch + GetLastFinalizedEpoch(ctx context.Context) uint64 +} + // IncentiveKeeper defines the expected interface needed to distribute rewards. type IncentiveKeeper interface { RewardBTCStaking(ctx context.Context, height uint64, filteredDc *bstypes.VotingPowerDistCache) diff --git a/x/finality/types/finality.pb.go b/x/finality/types/finality.pb.go index 8d2eb5f4b..0b1804fbf 100644 --- a/x/finality/types/finality.pb.go +++ b/x/finality/types/finality.pb.go @@ -100,6 +100,8 @@ type PubRandCommit struct { // commitment is the value of the commitment // currently, it is the root of the merkle tree constructed by the public randomness Commitment []byte `protobuf:"bytes,3,opt,name=commitment,proto3" json:"commitment,omitempty"` + // epoch_num defines the epoch number that the commit falls into + EpochNum uint64 `protobuf:"varint,4,opt,name=epoch_num,json=epochNum,proto3" json:"epoch_num,omitempty"` } func (m *PubRandCommit) Reset() { *m = PubRandCommit{} } @@ -156,6 +158,13 @@ func (m *PubRandCommit) GetCommitment() []byte { return nil } +func (m *PubRandCommit) GetEpochNum() uint64 { + if m != nil { + return m.EpochNum + } + return 0 +} + // Evidence is the evidence that a finality provider has signed finality // signatures with correct public randomness on two conflicting Babylon headers type Evidence struct { @@ -304,41 +313,43 @@ func init() { } var fileDescriptor_ca5b87e52e3e6d02 = []byte{ - // 539 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x4d, 0x6f, 0xd3, 0x30, - 0x18, 0x6e, 0x68, 0x69, 0x3b, 0x37, 0x13, 0x90, 0x8d, 0xa9, 0x7c, 0x28, 0x2b, 0x39, 0xf5, 0x00, - 0x2d, 0xfb, 0x10, 0x42, 0xdc, 0xc8, 0x34, 0xb4, 0x0a, 0x24, 0xaa, 0x74, 0x5c, 0xb8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 0xef, 0x0a, 0xe0, 0x09, 0x09, 0x8d, - 0x00, 0x3c, 0x50, 0xaa, 0x36, 0xc8, 0x5a, 0xff, 0x4d, 0x76, 0x2f, 0x03, 0xbd, 0xc1, 0x63, 0xfd, - 0xd0, 0xc0, 0x93, 0xf2, 0x3c, 0x4e, 0x58, 0x16, 0x89, 0x64, 0x42, 0x42, 0x4a, 0x68, 0x38, 0xa2, - 0x01, 0xbb, 0xbd, 0x6c, 0x6c, 0x64, 0x3c, 0xcb, 0x46, 0x7d, 0x33, 0xe3, 0x87, 0xe0, 0x61, 0x4c, - 0x84, 0xc0, 0x3e, 0x54, 0x89, 0x11, 0xd0, 0x63, 0x29, 0x95, 0x38, 0x51, 0x41, 0xa9, 0x3b, 0x3b, - 0x79, 0x53, 0xfd, 0x94, 0xe2, 0x24, 0x6f, 0xd9, 0x1f, 0xbe, 0x2f, 0x4d, 0xed, 0x72, 0x69, 0x6a, - 0xbf, 0x96, 0xa6, 0xf6, 0x6d, 0x65, 0xd6, 0x2e, 0x57, 0x66, 0xed, 0xe7, 0xca, 0xac, 0x7d, 0x3e, - 0xfc, 0xb3, 0xde, 0x8b, 0xf5, 0x8b, 0xa1, 0xa4, 0xbb, 0x4d, 0xf5, 0x02, 0x1c, 0xfd, 0x0e, 0x00, - 0x00, 0xff, 0xff, 0xb1, 0x31, 0x31, 0x81, 0x52, 0x04, 0x00, 0x00, + // 561 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x4d, 0x6f, 0xd3, 0x40, + 0x10, 0x8d, 0x49, 0xc8, 0xc7, 0xc6, 0x15, 0xe0, 0x96, 0x2a, 0x50, 0xe4, 0x06, 0x9f, 0x72, 0x80, + 0x84, 0x7e, 0x08, 0x21, 0x6e, 0xb8, 0x2a, 0x6a, 0x04, 0x82, 0xc8, 0x29, 0x17, 0x2e, 0xab, 0xf5, + 0x7a, 0x6d, 0xaf, 0x12, 0xef, 0xae, 0xec, 0x75, 0xd4, 0xf0, 0x03, 0x38, 0xc3, 0xbf, 0x42, 0x9c, + 0x7a, 0x44, 0x3d, 0x54, 0x28, 0xf9, 0x23, 0xc8, 0x6b, 0xc7, 0x69, 0x4e, 0x20, 0x10, 0x37, 0xef, + 0x9b, 0xf1, 0xbc, 0x79, 0xb3, 0x6f, 0x16, 0x58, 0x2e, 0x72, 0xe7, 0x53, 0xce, 0x06, 0x3e, 0x65, + 0x68, 0x4a, 0xe5, 0x7c, 0x30, 0x3b, 0x28, 0xbf, 0xfb, 0x22, 0xe6, 0x92, 0x1b, 0xdb, 0x45, 0x4e, + 0xbf, 0xc4, 0x67, 0x07, 0x0f, 0x77, 0x02, 0x1e, 0x70, 0x15, 0x1f, 0x64, 0x5f, 0x79, 0xaa, 0x05, + 0x81, 0x3e, 0x64, 0x1e, 0xb9, 0x20, 0x9e, 0x3d, 0xe5, 0x78, 0x62, 0xec, 0x82, 0x7a, 0x48, 0x68, + 0x10, 0xca, 0x8e, 0xd6, 0xd5, 0x7a, 0x35, 0xa7, 0x38, 0x19, 0x0f, 0x40, 0x13, 0x09, 0x01, 0x43, + 0x94, 0x84, 0x9d, 0x5b, 0x5d, 0xad, 0xa7, 0x3b, 0x0d, 0x24, 0xc4, 0x19, 0x4a, 0x42, 0xe3, 0x11, + 0x68, 0xe5, 0x3c, 0x9f, 0x88, 0xd7, 0xa9, 0x76, 0xb5, 0x5e, 0xd3, 0x59, 0x03, 0xd6, 0x57, 0x0d, + 0x6c, 0x8d, 0x52, 0xd7, 0x41, 0xcc, 0x3b, 0xe1, 0x51, 0x44, 0xa5, 0xf1, 0x18, 0xe8, 0x89, 0x44, + 0xb1, 0x84, 0x1b, 0x44, 0x6d, 0x85, 0x9d, 0xe5, 0x6c, 0x5d, 0xa0, 0xb3, 0x34, 0x82, 0x22, 0x75, + 0x61, 0x8c, 0x98, 0xa7, 0x18, 0x6b, 0x0e, 0x60, 0x69, 0x54, 0x94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4, 0xff, 0xba, 0xed, 0xd3, 0xf7, 0xe7, 0xe3, 0x31, 0x0d, 0x9c, 0x9d, 0xb2, 0xf2, 0xeb, + 0xa2, 0xf0, 0x98, 0x06, 0x86, 0x0f, 0xee, 0xa9, 0xae, 0x36, 0xc8, 0x1a, 0xff, 0x4c, 0x76, 0x27, + 0x2b, 0x7a, 0x83, 0xc7, 0xfa, 0xae, 0x81, 0xbd, 0xd5, 0x79, 0x14, 0xf3, 0xcc, 0x12, 0xf1, 0x98, + 0x06, 0x8c, 0xb2, 0x60, 0xc8, 0x7c, 0xfe, 0xff, 0xbc, 0xb1, 0xb1, 0x00, 0x99, 0x37, 0xaa, 0x9b, + 0x0b, 0x70, 0x08, 0xee, 0x47, 0x34, 0x49, 0x88, 0x07, 0x95, 0x63, 0x12, 0x88, 0x79, 0xca, 0x24, + 0x89, 0x95, 0x51, 0xaa, 0xce, 0x76, 0x1e, 0x54, 0x2b, 0x9b, 0x9c, 0xe4, 0x21, 0xfb, 0xed, 0xb7, + 0x85, 0xa9, 0x5d, 0x2e, 0x4c, 0xed, 0xe7, 0xc2, 0xd4, 0xbe, 0x2c, 0xcd, 0xca, 0xe5, 0xd2, 0xac, + 0xfc, 0x58, 0x9a, 0x95, 0x8f, 0x87, 0xbf, 0xef, 0xf7, 0x62, 0xfd, 0x9e, 0xa8, 0xd6, 0xdd, 0xba, + 0x7a, 0x1f, 0x8e, 0x7e, 0x05, 0x00, 0x00, 0xff, 0xff, 0x1b, 0xa1, 0x77, 0x79, 0x70, 0x04, 0x00, + 0x00, } func (m *IndexedBlock) Marshal() (dAtA []byte, err error) { @@ -406,6 +417,11 @@ func (m *PubRandCommit) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.EpochNum != 0 { + i = encodeVarintFinality(dAtA, i, uint64(m.EpochNum)) + i-- + dAtA[i] = 0x20 + } if len(m.Commitment) > 0 { i -= len(m.Commitment) copy(dAtA[i:], m.Commitment) @@ -607,6 +623,9 @@ func (m *PubRandCommit) Size() (n int) { if l > 0 { n += 1 + l + sovFinality(uint64(l)) } + if m.EpochNum != 0 { + n += 1 + sovFinality(uint64(m.EpochNum)) + } return n } @@ -895,6 +914,25 @@ func (m *PubRandCommit) Unmarshal(dAtA []byte) error { m.Commitment = []byte{} } iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochNum", wireType) + } + m.EpochNum = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFinality + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EpochNum |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipFinality(dAtA[iNdEx:]) diff --git a/x/finality/types/mocked_keepers.go b/x/finality/types/mocked_keepers.go index c546a68da..5af122cda 100644 --- a/x/finality/types/mocked_keepers.go +++ b/x/finality/types/mocked_keepers.go @@ -10,6 +10,7 @@ import ( types "github.com/babylonlabs-io/babylon/types" types0 "github.com/babylonlabs-io/babylon/x/btcstaking/types" + types1 "github.com/babylonlabs-io/babylon/x/epoching/types" gomock "github.com/golang/mock/gomock" ) @@ -66,20 +67,6 @@ func (mr *MockBTCStakingKeeperMockRecorder) GetFinalityProvider(ctx, fpBTCPK int return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFinalityProvider", reflect.TypeOf((*MockBTCStakingKeeper)(nil).GetFinalityProvider), ctx, fpBTCPK) } -// GetLastFinalizedEpoch mocks base method. -func (m *MockBTCStakingKeeper) GetLastFinalizedEpoch(ctx context.Context) uint64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetLastFinalizedEpoch", ctx) - ret0, _ := ret[0].(uint64) - return ret0 -} - -// GetLastFinalizedEpoch indicates an expected call of GetLastFinalizedEpoch. -func (mr *MockBTCStakingKeeperMockRecorder) GetLastFinalizedEpoch(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLastFinalizedEpoch", reflect.TypeOf((*MockBTCStakingKeeper)(nil).GetLastFinalizedEpoch), ctx) -} - // GetParams mocks base method. func (m *MockBTCStakingKeeper) GetParams(ctx context.Context) types0.Params { m.ctrl.T.Helper() @@ -191,6 +178,57 @@ func (mr *MockBTCStakingKeeperMockRecorder) SlashFinalityProvider(ctx, fpBTCPK i return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SlashFinalityProvider", reflect.TypeOf((*MockBTCStakingKeeper)(nil).SlashFinalityProvider), ctx, fpBTCPK) } +// MockCheckpointingKeeper is a mock of CheckpointingKeeper interface. +type MockCheckpointingKeeper struct { + ctrl *gomock.Controller + recorder *MockCheckpointingKeeperMockRecorder +} + +// MockCheckpointingKeeperMockRecorder is the mock recorder for MockCheckpointingKeeper. +type MockCheckpointingKeeperMockRecorder struct { + mock *MockCheckpointingKeeper +} + +// NewMockCheckpointingKeeper creates a new mock instance. +func NewMockCheckpointingKeeper(ctrl *gomock.Controller) *MockCheckpointingKeeper { + mock := &MockCheckpointingKeeper{ctrl: ctrl} + mock.recorder = &MockCheckpointingKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockCheckpointingKeeper) EXPECT() *MockCheckpointingKeeperMockRecorder { + return m.recorder +} + +// GetEpoch mocks base method. +func (m *MockCheckpointingKeeper) GetEpoch(ctx context.Context) *types1.Epoch { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetEpoch", ctx) + ret0, _ := ret[0].(*types1.Epoch) + return ret0 +} + +// GetEpoch indicates an expected call of GetEpoch. +func (mr *MockCheckpointingKeeperMockRecorder) GetEpoch(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEpoch", reflect.TypeOf((*MockCheckpointingKeeper)(nil).GetEpoch), ctx) +} + +// GetLastFinalizedEpoch mocks base method. +func (m *MockCheckpointingKeeper) GetLastFinalizedEpoch(ctx context.Context) uint64 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetLastFinalizedEpoch", ctx) + ret0, _ := ret[0].(uint64) + return ret0 +} + +// GetLastFinalizedEpoch indicates an expected call of GetLastFinalizedEpoch. +func (mr *MockCheckpointingKeeperMockRecorder) GetLastFinalizedEpoch(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLastFinalizedEpoch", reflect.TypeOf((*MockCheckpointingKeeper)(nil).GetLastFinalizedEpoch), ctx) +} + // MockIncentiveKeeper is a mock of IncentiveKeeper interface. type MockIncentiveKeeper struct { ctrl *gomock.Controller diff --git a/x/finality/types/query.pb.go b/x/finality/types/query.pb.go index a0f7f3271..76aa68501 100644 --- a/x/finality/types/query.pb.go +++ b/x/finality/types/query.pb.go @@ -258,6 +258,8 @@ type PubRandCommitResponse struct { NumPubRand uint64 `protobuf:"varint,1,opt,name=num_pub_rand,json=numPubRand,proto3" json:"num_pub_rand,omitempty"` // commitment is the value of the commitment Commitment []byte `protobuf:"bytes,2,opt,name=commitment,proto3" json:"commitment,omitempty"` + // epoch_num defines the epoch number that the commit falls into + EpochNum uint64 `protobuf:"varint,3,opt,name=epoch_num,json=epochNum,proto3" json:"epoch_num,omitempty"` } func (m *PubRandCommitResponse) Reset() { *m = PubRandCommitResponse{} } @@ -307,6 +309,13 @@ func (m *PubRandCommitResponse) GetCommitment() []byte { return nil } +func (m *PubRandCommitResponse) GetEpochNum() uint64 { + if m != nil { + return m.EpochNum + } + return 0 +} + // QueryListPubRandCommitRequest is the request type for the // Query/ListPubRandCommit RPC method. type QueryListPubRandCommitRequest struct { @@ -1147,90 +1156,91 @@ func init() { func init() { proto.RegisterFile("babylon/finality/v1/query.proto", fileDescriptor_32bddab77af6fdae) } var fileDescriptor_32bddab77af6fdae = []byte{ - // 1318 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0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0xf4, - 0xfc, 0x20, 0x3e, 0xf4, 0xe7, 0x41, 0x7c, 0xe8, 0x41, 0xb2, 0xf7, 0x12, 0xbb, 0xdb, 0x0c, 0x4c, - 0xf7, 0x59, 0x2d, 0x4c, 0xff, 0x67, 0xb3, 0xf8, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1a, 0x6c, - 0x72, 0x7b, 0x91, 0x12, 0x00, 0x00, + // 1338 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x58, 0xdf, 0x6f, 0xd3, 0xd6, + 0x17, 0xef, 0x6d, 0x69, 0xa1, 0xa7, 0x09, 0x94, 0x4b, 0xe1, 0xdb, 0x6f, 0x18, 0x69, 0x30, 0xac, + 0xb0, 0x02, 0x36, 0x4d, 0x19, 0x03, 0xb6, 0x09, 0xc8, 0x46, 0x47, 0xb4, 0x92, 0x05, 0x33, 0x21, + 0x8d, 0x87, 0x79, 0x76, 0x7a, 0x93, 0x58, 0x8d, 0x7d, 0x4d, 0x6c, 0x47, 0xcd, 0x10, 0xd2, 0x34, + 0x69, 0x3c, 0x4c, 0x9b, 0x34, 0x69, 0x2f, 0xdb, 0x03, 0x0f, 0x9b, 0xa6, 0xbd, 0xec, 0xff, 0x98, + 0x78, 0x44, 0x6c, 0x0f, 0x13, 0xd2, 0xd0, 0x04, 0xfb, 0x43, 0xa6, 0xdc, 0x7b, 0x9d, 0xd8, 0x89, + 0xf3, 0x83, 0x2e, 0xda, 0x5b, 0x7c, 0x7c, 0x7e, 0x7c, 0xce, 0xe7, 0x1c, 0x9f, 0x73, 0x5a, 0x58, + 0x32, 0x74, 0xa3, 0x59, 0xa3, 0xb6, 0x52, 0x36, 0x6d, 0xbd, 0x66, 0x7a, 0x4d, 0xa5, 0xb1, 0xaa, + 0xdc, 0xf5, 0x49, 0xbd, 0x29, 0x3b, 0x75, 0xea, 0x51, 0x7c, 0x40, 0x28,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, 0xba, 0xe3, 0x01, 0xbd, 0xd4, 0xbb, 0x8d, 0x53, 0x67, 0x46, 0xd4, 0x16, 0xa0, 0x2e, 0x31, + 0x50, 0xe7, 0x70, 0x36, 0x16, 0x54, 0x64, 0x67, 0x75, 0x93, 0x89, 0xbf, 0x47, 0x90, 0x88, 0xac, + 0xa1, 0xd1, 0x62, 0xb7, 0x19, 0x94, 0x47, 0x55, 0x17, 0x58, 0x57, 0x18, 0xd6, 0xe3, 0x58, 0x1a, + 0x8e, 0x35, 0xb7, 0xf1, 0xe8, 0x79, 0x1a, 0x3d, 0x7e, 0x9e, 0x46, 0x7f, 0x3d, 0x4f, 0xa3, 0x6f, + 0x5e, 0xa4, 0x27, 0x1e, 0xbf, 0x48, 0x4f, 0xfc, 0xf1, 0x22, 0x3d, 0x71, 0x27, 0x3b, 0xfc, 0x88, + 0xdd, 0xee, 0x38, 0x66, 0xf7, 0xac, 0x31, 0xc3, 0xfe, 0xa1, 0xb3, 0xf6, 0x4f, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xb3, 0x40, 0x11, 0x10, 0xae, 0x12, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1842,6 +1852,11 @@ func (m *PubRandCommitResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.EpochNum != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.EpochNum)) + i-- + dAtA[i] = 0x18 + } if len(m.Commitment) > 0 { i -= len(m.Commitment) copy(dAtA[i:], m.Commitment) @@ -2563,6 +2578,9 @@ func (m *PubRandCommitResponse) Size() (n int) { if l > 0 { n += 1 + l + sovQuery(uint64(l)) } + if m.EpochNum != 0 { + n += 1 + sovQuery(uint64(m.EpochNum)) + } return n } @@ -3354,6 +3372,25 @@ func (m *PubRandCommitResponse) Unmarshal(dAtA []byte) error { m.Commitment = []byte{} } iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EpochNum", wireType) + } + m.EpochNum = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EpochNum |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:])