From 65ac14393d77a1a3493ce8f53a034bc7c172e45f Mon Sep 17 00:00:00 2001 From: lumtis Date: Sun, 7 Apr 2024 18:12:35 +0200 Subject: [PATCH] test for vote block header --- docs/openapi/openapi.swagger.yaml | 5 + proto/observer/tx.proto | 5 +- testutil/keeper/observer.go | 7 + typescript/observer/tx_pb.d.ts | 10 + x/lightclient/keeper/block_header_test.go | 206 ++++++++ .../testdata/header_sepolia_5000000.json | 0 .../testdata/header_sepolia_5000001.json | 0 .../testdata/header_sepolia_5000002.json | 0 .../keeper/msg_server_vote_block_header.go | 12 +- .../msg_server_vote_block_header_test.go | 457 ++++++++++-------- x/observer/keeper/utils.go | 5 +- x/observer/types/message_vote_block_header.go | 10 +- x/observer/types/tx.pb.go | 234 ++++++--- 13 files changed, 673 insertions(+), 278 deletions(-) rename x/{observer => lightclient}/keeper/testdata/header_sepolia_5000000.json (100%) rename x/{observer => lightclient}/keeper/testdata/header_sepolia_5000001.json (100%) rename x/{observer => lightclient}/keeper/testdata/header_sepolia_5000002.json (100%) diff --git a/docs/openapi/openapi.swagger.yaml b/docs/openapi/openapi.swagger.yaml index cbe43ee972..d0d756cb66 100644 --- a/docs/openapi/openapi.swagger.yaml +++ b/docs/openapi/openapi.swagger.yaml @@ -54592,6 +54592,11 @@ definitions: type: object observerMsgVoteBlockHeaderResponse: type: object + properties: + ballot_created: + type: boolean + vote_finalized: + type: boolean observerMsgVoteTSSResponse: type: object properties: diff --git a/proto/observer/tx.proto b/proto/observer/tx.proto index 93608a25ef..227f68cd6b 100644 --- a/proto/observer/tx.proto +++ b/proto/observer/tx.proto @@ -43,7 +43,10 @@ message MsgVoteBlockHeader { proofs.HeaderData header = 5 [(gogoproto.nullable) = false]; } -message MsgVoteBlockHeaderResponse {} +message MsgVoteBlockHeaderResponse { + bool ballot_created = 1; + bool vote_finalized = 2; +} message MsgUpdateChainParams { string creator = 1; diff --git a/testutil/keeper/observer.go b/testutil/keeper/observer.go index 1be05b7511..423341a883 100644 --- a/testutil/keeper/observer.go +++ b/testutil/keeper/observer.go @@ -134,6 +134,13 @@ func ObserverKeeper(t testing.TB) (*keeper.Keeper, sdk.Context, SDKKeepers, Zeta return ObserverKeeperWithMocks(t, ObserverNoMocks) } +// GetObserverLightclientMock returns a new observer lightclient keeper mock +func GetObserverLightclientMock(t testing.TB, keeper *keeper.Keeper) *observermocks.ObserverLightclientKeeper { + cok, ok := keeper.GetLightclientKeeper().(*observermocks.ObserverLightclientKeeper) + require.True(t, ok) + return cok +} + // GetObserverAuthorityMock returns a new observer authority keeper mock func GetObserverAuthorityMock(t testing.TB, keeper *keeper.Keeper) *observermocks.ObserverAuthorityKeeper { cok, ok := keeper.GetAuthorityKeeper().(*observermocks.ObserverAuthorityKeeper) diff --git a/typescript/observer/tx_pb.d.ts b/typescript/observer/tx_pb.d.ts index c8c394f3d9..a32abd14db 100644 --- a/typescript/observer/tx_pb.d.ts +++ b/typescript/observer/tx_pb.d.ts @@ -118,6 +118,16 @@ export declare class MsgVoteBlockHeader extends Message { * @generated from message zetachain.zetacore.observer.MsgVoteBlockHeaderResponse */ export declare class MsgVoteBlockHeaderResponse extends Message { + /** + * @generated from field: bool ballot_created = 1; + */ + ballotCreated: boolean; + + /** + * @generated from field: bool vote_finalized = 2; + */ + voteFinalized: boolean; + constructor(data?: PartialMessage); static readonly runtime: typeof proto3; diff --git a/x/lightclient/keeper/block_header_test.go b/x/lightclient/keeper/block_header_test.go index 35c58e29b5..77f4fe48a3 100644 --- a/x/lightclient/keeper/block_header_test.go +++ b/x/lightclient/keeper/block_header_test.go @@ -1,8 +1,12 @@ package keeper_test import ( + "encoding/json" + "os" "testing" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -40,3 +44,205 @@ func TestKeeper_GetAllBlockHeaders(t *testing.T) { require.EqualValues(t, b2, list[1]) require.EqualValues(t, b3, list[2]) } + +func ethHeaders() (*ethtypes.Header, *ethtypes.Header, *ethtypes.Header, error) { + header1, err := readHeader("./testdata/header_sepolia_5000000.json") + if err != nil { + return nil, nil, nil, err + } + header2, err := readHeader("./testdata/header_sepolia_5000001.json") + if err != nil { + return nil, nil, nil, err + } + header3, err := readHeader("./testdata/header_sepolia_5000002.json") + if err != nil { + return nil, nil, nil, err + } + return header1, header2, header3, nil +} + +// readReceipt reads a receipt from a file. +// TODO: centralize test data +// https://github.com/zeta-chain/node/issues/1874 +func readHeader(filename string) (*ethtypes.Header, error) { + file, err := os.Open(filename) + if err != nil { + return nil, err + } + defer file.Close() + + decoder := json.NewDecoder(file) + var NewHeader ethtypes.Header + err = decoder.Decode(&NewHeader) + return &NewHeader, err +} + +/* +func TestMsgServer_VoteBlockHeader(t *testing.T) { + header, header2, header3, err := ethHeaders() + require.NoError(t, err) + header1RLP, err := rlp.EncodeToBytes(header) + require.NoError(t, err) + header2RLP, err := rlp.EncodeToBytes(header2) + require.NoError(t, err) + header3RLP, err := rlp.EncodeToBytes(header3) + require.NoError(t, err) + + r := rand.New(rand.NewSource(9)) + validator := sample.Validator(t, r) + observerAddress, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) + require.NoError(t, err) + // Add tests for btc headers : https://github.com/zeta-chain/node/issues/1336 + tt := []struct { + name string + msg *types.MsgVoteBlockHeader + IsEthTypeChainEnabled bool + IsBtcTypeChainEnabled bool + validator stakingtypes.Validator + wantErr require.ErrorAssertionFunc + }{ + { + name: "success submit eth header", + msg: &types.MsgVoteBlockHeader{ + Creator: observerAddress.String(), + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: header.Hash().Bytes(), + Height: 1, + Header: proofs.NewEthereumHeader(header1RLP), + }, + IsEthTypeChainEnabled: true, + IsBtcTypeChainEnabled: true, + validator: validator, + wantErr: require.NoError, + }, + { + name: "failure submit eth header eth disabled", + msg: &types.MsgVoteBlockHeader{ + Creator: observerAddress.String(), + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: header.Hash().Bytes(), + Height: 1, + Header: proofs.NewEthereumHeader(header1RLP), + }, + IsEthTypeChainEnabled: false, + IsBtcTypeChainEnabled: true, + validator: validator, + wantErr: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) + }, + }, + { + name: "failure submit eth header eth disabled", + msg: &types.MsgVoteBlockHeader{ + Creator: sample.AccAddress(), + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: header.Hash().Bytes(), + Height: 1, + Header: proofs.NewEthereumHeader(header1RLP), + }, + IsEthTypeChainEnabled: false, + IsBtcTypeChainEnabled: true, + validator: validator, + wantErr: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, types.ErrNotObserver) + }, + }, + { + name: "should succeed if block header parent does exist", + msg: &types.MsgVoteBlockHeader{ + Creator: observerAddress.String(), + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: header2.Hash().Bytes(), + Height: 2, + Header: proofs.NewEthereumHeader(header2RLP), + }, + IsEthTypeChainEnabled: true, + IsBtcTypeChainEnabled: true, + validator: validator, + wantErr: require.NoError, + }, + // These tests don't work when using the static headers, the previous sample were also not correct (header3 used to be nil) + // The second test mention it should success but assert an error + // TODO: fix these tests + // https://github.com/zeta-chain/node/issues/1875 + //{ + // name: "should fail if block header parent does not exist", + // msg: &types.MsgVoteBlockHeader{ + // Creator: observerAddress.String(), + // ChainId: chains.GoerliLocalnetChain().ChainId, + // BlockHash: header3.Hash().Bytes(), + // Height: 3, + // Header: chains.NewEthereumHeader(header3RLP), + // }, + // IsEthTypeChainEnabled: true, + // IsBtcTypeChainEnabled: true, + // validator: validator, + // wantErr: func(t require.TestingT, err error, i ...interface{}) { + // require.Error(t, err) + // }, + //}, + //{ + // name: "should succeed to post 3rd header if 2nd header is posted", + // msg: &types.MsgVoteBlockHeader{ + // Creator: observerAddress.String(), + // ChainId: chains.GoerliLocalnetChain().ChainId, + // BlockHash: header3.Hash().Bytes(), + // Height: 3, + // Header: chains.NewEthereumHeader(header3RLP), + // }, + // IsEthTypeChainEnabled: true, + // IsBtcTypeChainEnabled: true, + // validator: validator, + // wantErr: func(t require.TestingT, err error, i ...interface{}) { + // require.Error(t, err) + // }, + //}, + { + name: "should fail if chain is not supported", + msg: &types.MsgVoteBlockHeader{ + Creator: observerAddress.String(), + ChainId: 9999, + BlockHash: header3.Hash().Bytes(), + Height: 3, + Header: proofs.NewEthereumHeader(header3RLP), + }, + IsEthTypeChainEnabled: true, + IsBtcTypeChainEnabled: true, + validator: validator, + wantErr: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, types.ErrSupportedChains) + }, + }, + } + for _, tc := range tt { + t.Run(tc.name, func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeper(t) + srv := keeper.NewMsgServerImpl(*k) + k.SetObserverSet(ctx, types.ObserverSet{ + ObserverList: []string{observerAddress.String()}, + }) + k.GetStakingKeeper().SetValidator(ctx, tc.validator) + k.SetCrosschainFlags(ctx, types.CrosschainFlags{ + IsInboundEnabled: true, + IsOutboundEnabled: true, + GasPriceIncreaseFlags: nil, + BlockHeaderVerificationFlags: &types.BlockHeaderVerificationFlags{ + IsEthTypeChainEnabled: tc.IsEthTypeChainEnabled, + IsBtcTypeChainEnabled: tc.IsBtcTypeChainEnabled, + }, + }) + + setSupportedChain(ctx, *k, chains.GoerliLocalnetChain().ChainId) + + _, err := srv.VoteBlockHeader(ctx, tc.msg) + tc.wantErr(t, err) + if err == nil { + bhs, found := k.GetBlockHeaderState(ctx, tc.msg.ChainId) + require.True(t, found) + require.Equal(t, tc.msg.Height, bhs.LatestHeight) + } + }) + } +} + +*/ diff --git a/x/observer/keeper/testdata/header_sepolia_5000000.json b/x/lightclient/keeper/testdata/header_sepolia_5000000.json similarity index 100% rename from x/observer/keeper/testdata/header_sepolia_5000000.json rename to x/lightclient/keeper/testdata/header_sepolia_5000000.json diff --git a/x/observer/keeper/testdata/header_sepolia_5000001.json b/x/lightclient/keeper/testdata/header_sepolia_5000001.json similarity index 100% rename from x/observer/keeper/testdata/header_sepolia_5000001.json rename to x/lightclient/keeper/testdata/header_sepolia_5000001.json diff --git a/x/observer/keeper/testdata/header_sepolia_5000002.json b/x/lightclient/keeper/testdata/header_sepolia_5000002.json similarity index 100% rename from x/observer/keeper/testdata/header_sepolia_5000002.json rename to x/lightclient/keeper/testdata/header_sepolia_5000002.json diff --git a/x/observer/keeper/msg_server_vote_block_header.go b/x/observer/keeper/msg_server_vote_block_header.go index c16c8de6d5..c14c56a06b 100644 --- a/x/observer/keeper/msg_server_vote_block_header.go +++ b/x/observer/keeper/msg_server_vote_block_header.go @@ -30,7 +30,7 @@ func (k msgServer) VoteBlockHeader(goCtx context.Context, msg *types.MsgVoteBloc } // add vote to ballot - ballot, _, err := k.FindBallot(ctx, msg.Digest(), chain, types.ObservationType_InBoundTx) + ballot, isNew, err := k.FindBallot(ctx, msg.Digest(), chain, types.ObservationType_InBoundTx) if err != nil { return nil, cosmoserrors.Wrap(err, "failed to find ballot") } @@ -40,11 +40,17 @@ func (k msgServer) VoteBlockHeader(goCtx context.Context, msg *types.MsgVoteBloc } _, isFinalized := k.CheckIfFinalizingVote(ctx, ballot) if !isFinalized { - return &types.MsgVoteBlockHeaderResponse{}, nil + return &types.MsgVoteBlockHeaderResponse{ + BallotCreated: isNew, + VoteFinalized: false, + }, nil } // add the new block header to the store k.lightclientKeeper.AddBlockHeader(ctx, msg.ChainId, msg.Height, msg.BlockHash, msg.Header, parentHash) - return &types.MsgVoteBlockHeaderResponse{}, nil + return &types.MsgVoteBlockHeaderResponse{ + BallotCreated: isNew, + VoteFinalized: true, + }, nil } diff --git a/x/observer/keeper/msg_server_vote_block_header_test.go b/x/observer/keeper/msg_server_vote_block_header_test.go index d25ea1d141..ae89bd984b 100644 --- a/x/observer/keeper/msg_server_vote_block_header_test.go +++ b/x/observer/keeper/msg_server_vote_block_header_test.go @@ -1,218 +1,293 @@ package keeper_test import ( - "encoding/json" - "math/rand" - "os" + "errors" "testing" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/rlp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/proofs" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" + mocks "github.com/zeta-chain/zetacore/testutil/keeper/mocks/observer" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/keeper" "github.com/zeta-chain/zetacore/x/observer/types" ) +func mockCheckNewBlockHeader(m *mocks.ObserverLightclientKeeper, err error) { + m.On( + "CheckNewBlockHeader", + mock.Anything, + mock.Anything, + mock.Anything, + mock.Anything, + mock.Anything, + ).Return(sample.Hash().Bytes(), err) +} + +func mockAddBlockHeader(m *mocks.ObserverLightclientKeeper) { + m.On( + "AddBlockHeader", + mock.Anything, + mock.Anything, + mock.Anything, + mock.Anything, + mock.Anything, + mock.Anything, + ) +} + func TestMsgServer_VoteBlockHeader(t *testing.T) { - header, header2, header3, err := ethHeaders() - require.NoError(t, err) - header1RLP, err := rlp.EncodeToBytes(header) - require.NoError(t, err) - header2RLP, err := rlp.EncodeToBytes(header2) - require.NoError(t, err) - header3RLP, err := rlp.EncodeToBytes(header3) + one, err := sdk.NewDecFromStr("1.0") require.NoError(t, err) - r := rand.New(rand.NewSource(9)) - validator := sample.Validator(t, r) - observerAddress, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) - require.NoError(t, err) - // Add tests for btc headers : https://github.com/zeta-chain/node/issues/1336 - tt := []struct { - name string - msg *types.MsgVoteBlockHeader - IsEthTypeChainEnabled bool - IsBtcTypeChainEnabled bool - validator stakingtypes.Validator - wantErr require.ErrorAssertionFunc - }{ - { - name: "success submit eth header", - msg: &types.MsgVoteBlockHeader{ - Creator: observerAddress.String(), - ChainId: chains.GoerliLocalnetChain().ChainId, - BlockHash: header.Hash().Bytes(), - Height: 1, - Header: proofs.NewEthereumHeader(header1RLP), - }, - IsEthTypeChainEnabled: true, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: require.NoError, - }, - { - name: "failure submit eth header eth disabled", - msg: &types.MsgVoteBlockHeader{ - Creator: observerAddress.String(), - ChainId: chains.GoerliLocalnetChain().ChainId, - BlockHash: header.Hash().Bytes(), - Height: 1, - Header: proofs.NewEthereumHeader(header1RLP), - }, - IsEthTypeChainEnabled: false, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: func(t require.TestingT, err error, i ...interface{}) { - require.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) - }, - }, - { - name: "failure submit eth header eth disabled", - msg: &types.MsgVoteBlockHeader{ - Creator: sample.AccAddress(), - ChainId: chains.GoerliLocalnetChain().ChainId, - BlockHash: header.Hash().Bytes(), - Height: 1, - Header: proofs.NewEthereumHeader(header1RLP), - }, - IsEthTypeChainEnabled: false, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: func(t require.TestingT, err error, i ...interface{}) { - require.ErrorIs(t, err, types.ErrNotObserver) - }, - }, - { - name: "should succeed if block header parent does exist", - msg: &types.MsgVoteBlockHeader{ - Creator: observerAddress.String(), - ChainId: chains.GoerliLocalnetChain().ChainId, - BlockHash: header2.Hash().Bytes(), - Height: 2, - Header: proofs.NewEthereumHeader(header2RLP), + t.Run("fails if the chain is not supported", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeper(t) + srv := keeper.NewMsgServerImpl(*k) + + _, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: sample.AccAddress(), + ChainId: 9999, + BlockHash: sample.Hash().Bytes(), + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.ErrorIs(t, err, types.ErrSupportedChains) + }) + + t.Run("fails if the observer is not in the observer set", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeper(t) + srv := keeper.NewMsgServerImpl(*k) + + k.SetChainParamsList(ctx, types.ChainParamsList{ + ChainParams: []*types.ChainParams{ + { + ChainId: chains.GoerliLocalnetChain().ChainId, + IsSupported: true, + BallotThreshold: one, + }, }, - IsEthTypeChainEnabled: true, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: require.NoError, - }, - // These tests don't work when using the static headers, the previous sample were also not correct (header3 used to be nil) - // The second test mention it should success but assert an error - // TODO: fix these tests - // https://github.com/zeta-chain/node/issues/1875 - //{ - // name: "should fail if block header parent does not exist", - // msg: &types.MsgVoteBlockHeader{ - // Creator: observerAddress.String(), - // ChainId: chains.GoerliLocalnetChain().ChainId, - // BlockHash: header3.Hash().Bytes(), - // Height: 3, - // Header: chains.NewEthereumHeader(header3RLP), - // }, - // IsEthTypeChainEnabled: true, - // IsBtcTypeChainEnabled: true, - // validator: validator, - // wantErr: func(t require.TestingT, err error, i ...interface{}) { - // require.Error(t, err) - // }, - //}, - //{ - // name: "should succeed to post 3rd header if 2nd header is posted", - // msg: &types.MsgVoteBlockHeader{ - // Creator: observerAddress.String(), - // ChainId: chains.GoerliLocalnetChain().ChainId, - // BlockHash: header3.Hash().Bytes(), - // Height: 3, - // Header: chains.NewEthereumHeader(header3RLP), - // }, - // IsEthTypeChainEnabled: true, - // IsBtcTypeChainEnabled: true, - // validator: validator, - // wantErr: func(t require.TestingT, err error, i ...interface{}) { - // require.Error(t, err) - // }, - //}, - { - name: "should fail if chain is not supported", - msg: &types.MsgVoteBlockHeader{ - Creator: observerAddress.String(), - ChainId: 9999, - BlockHash: header3.Hash().Bytes(), - Height: 3, - Header: proofs.NewEthereumHeader(header3RLP), + }) + + _, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: sample.AccAddress(), + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: sample.Hash().Bytes(), + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.ErrorIs(t, err, types.ErrNotObserver) + }) + + t.Run("fails if the new block header is invalid", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMocksAll) + srv := keeper.NewMsgServerImpl(*k) + observer := sample.AccAddress() + + stakingMock := keepertest.GetObserverStakingMock(t, k) + slashingMock := keepertest.GetObserverSlashingMock(t, k) + lightclientMock := keepertest.GetObserverLightclientMock(t, k) + + k.SetChainParamsList(ctx, types.ChainParamsList{ + ChainParams: []*types.ChainParams{ + { + ChainId: chains.GoerliLocalnetChain().ChainId, + IsSupported: true, + BallotThreshold: one, + }, }, - IsEthTypeChainEnabled: true, - IsBtcTypeChainEnabled: true, - validator: validator, - wantErr: func(t require.TestingT, err error, i ...interface{}) { - require.ErrorIs(t, err, types.ErrSupportedChains) + }) + + k.SetObserverSet(ctx, types.ObserverSet{ + ObserverList: []string{observer}, + }) + + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, errors.New("foo")) + + _, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: sample.Hash().Bytes(), + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.ErrorIs(t, err, types.ErrInvalidBlockHeader) + }) + + t.Run("can create a new ballot, vote and finalize", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMocksAll) + srv := keeper.NewMsgServerImpl(*k) + observer := sample.AccAddress() + + stakingMock := keepertest.GetObserverStakingMock(t, k) + slashingMock := keepertest.GetObserverSlashingMock(t, k) + lightclientMock := keepertest.GetObserverLightclientMock(t, k) + + k.SetChainParamsList(ctx, types.ChainParamsList{ + ChainParams: []*types.ChainParams{ + { + ChainId: chains.GoerliLocalnetChain().ChainId, + IsSupported: true, + BallotThreshold: one, + }, }, - }, - } - for _, tc := range tt { - t.Run(tc.name, func(t *testing.T) { - k, ctx, _, _ := keepertest.ObserverKeeper(t) - srv := keeper.NewMsgServerImpl(*k) - k.SetObserverSet(ctx, types.ObserverSet{ - ObserverList: []string{observerAddress.String()}, - }) - k.GetStakingKeeper().SetValidator(ctx, tc.validator) - k.SetCrosschainFlags(ctx, types.CrosschainFlags{ - IsInboundEnabled: true, - IsOutboundEnabled: true, - GasPriceIncreaseFlags: nil, - BlockHeaderVerificationFlags: &types.BlockHeaderVerificationFlags{ - IsEthTypeChainEnabled: tc.IsEthTypeChainEnabled, - IsBtcTypeChainEnabled: tc.IsBtcTypeChainEnabled, + }) + + k.SetObserverSet(ctx, types.ObserverSet{ + ObserverList: []string{observer}, + }) + + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + mockAddBlockHeader(lightclientMock) + + // there is a single node account, so the ballot will be created and finalized in a single vote + res, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: sample.Hash().Bytes(), + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.NoError(t, err) + require.True(t, res.VoteFinalized) + require.True(t, res.BallotCreated) + }) + + t.Run("can create a new ballot, vote without finalizing, then add vote and finalizing", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMocksAll) + srv := keeper.NewMsgServerImpl(*k) + observer1 := sample.AccAddress() + observer2 := sample.AccAddress() + observer3 := sample.AccAddress() + blockHash := sample.Hash().Bytes() + + stakingMock := keepertest.GetObserverStakingMock(t, k) + slashingMock := keepertest.GetObserverSlashingMock(t, k) + lightclientMock := keepertest.GetObserverLightclientMock(t, k) + + k.SetChainParamsList(ctx, types.ChainParamsList{ + ChainParams: []*types.ChainParams{ + { + ChainId: chains.GoerliLocalnetChain().ChainId, + IsSupported: true, + BallotThreshold: one, }, - }) + }, + }) - setSupportedChain(ctx, *k, chains.GoerliLocalnetChain().ChainId) + k.SetObserverSet(ctx, types.ObserverSet{ + ObserverList: []string{observer1, observer2, observer3}, + }) - _, err := srv.VoteBlockHeader(ctx, tc.msg) - tc.wantErr(t, err) - if err == nil { - bhs, found := k.GetBlockHeaderState(ctx, tc.msg.ChainId) - require.True(t, found) - require.Equal(t, tc.msg.Height, bhs.LatestHeight) - } + // first observer, created, not finalized + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + res, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer1, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: blockHash, + Height: 42, + Header: proofs.HeaderData{}, }) - } -} -func ethHeaders() (*ethtypes.Header, *ethtypes.Header, *ethtypes.Header, error) { - header1, err := readHeader("./testdata/header_sepolia_5000000.json") - if err != nil { - return nil, nil, nil, err - } - header2, err := readHeader("./testdata/header_sepolia_5000001.json") - if err != nil { - return nil, nil, nil, err - } - header3, err := readHeader("./testdata/header_sepolia_5000002.json") - if err != nil { - return nil, nil, nil, err - } - return header1, header2, header3, nil -} + require.NoError(t, err) + require.False(t, res.VoteFinalized) + require.True(t, res.BallotCreated) -// readReceipt reads a receipt from a file. -// TODO: centralize test data -// https://github.com/zeta-chain/node/issues/1874 -func readHeader(filename string) (*ethtypes.Header, error) { - file, err := os.Open(filename) - if err != nil { - return nil, err - } - defer file.Close() - - decoder := json.NewDecoder(file) - var NewHeader ethtypes.Header - err = decoder.Decode(&NewHeader) - return &NewHeader, err + // second observer, found, not finalized + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + res, err = srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer2, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: blockHash, + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.NoError(t, err) + require.False(t, res.VoteFinalized) + require.False(t, res.BallotCreated) + + // third observer, found, finalized, add block header called + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + mockAddBlockHeader(lightclientMock) + res, err = srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer3, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: blockHash, + Height: 42, + Header: proofs.HeaderData{}, + }) + + require.NoError(t, err) + require.True(t, res.VoteFinalized) + require.False(t, res.BallotCreated) + }) + + t.Run("fail if voting fails", func(t *testing.T) { + k, ctx, _, _ := keepertest.ObserverKeeperWithMocks(t, keepertest.ObserverMocksAll) + srv := keeper.NewMsgServerImpl(*k) + observer := sample.AccAddress() + blockHash := sample.Hash().Bytes() + + stakingMock := keepertest.GetObserverStakingMock(t, k) + slashingMock := keepertest.GetObserverSlashingMock(t, k) + lightclientMock := keepertest.GetObserverLightclientMock(t, k) + + k.SetChainParamsList(ctx, types.ChainParamsList{ + ChainParams: []*types.ChainParams{ + { + ChainId: chains.GoerliLocalnetChain().ChainId, + IsSupported: true, + BallotThreshold: one, + }, + }, + }) + + // add multiple observers to not finalize the vote + k.SetObserverSet(ctx, types.ObserverSet{ + ObserverList: []string{observer, sample.AccAddress()}, + }) + + // vote once + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + _, err := srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: blockHash, + Height: 42, + Header: proofs.HeaderData{}, + }) + require.NoError(t, err) + + // vote a second time should make voting fail + stakingMock.MockGetValidator(sample.Validator(t, sample.Rand())) + slashingMock.MockIsTombstoned(false) + mockCheckNewBlockHeader(lightclientMock, nil) + _, err = srv.VoteBlockHeader(ctx, &types.MsgVoteBlockHeader{ + Creator: observer, + ChainId: chains.GoerliLocalnetChain().ChainId, + BlockHash: blockHash, + Height: 42, + Header: proofs.HeaderData{}, + }) + require.ErrorIs(t, err, types.ErrUnableToAddVote) + }) } diff --git a/x/observer/keeper/utils.go b/x/observer/keeper/utils.go index 566b559630..ca3fc00f55 100644 --- a/x/observer/keeper/utils.go +++ b/x/observer/keeper/utils.go @@ -45,6 +45,8 @@ func (k Keeper) IsNonTombstonedObserver(ctx sdk.Context, address string) bool { return true } +// FindBallot finds the ballot for the given index +// If the ballot is not found, it creates a new ballot and returns it func (k Keeper) FindBallot( ctx sdk.Context, index string, @@ -58,8 +60,7 @@ func (k Keeper) FindBallot( cp, found := k.GetChainParamsByChainID(ctx, chain.ChainId) if !found || cp == nil || !cp.IsSupported { - err = types.ErrSupportedChains - return + return types.Ballot{}, false, types.ErrSupportedChains } ballot = types.Ballot{ diff --git a/x/observer/types/message_vote_block_header.go b/x/observer/types/message_vote_block_header.go index 445c5988be..974db7d34d 100644 --- a/x/observer/types/message_vote_block_header.go +++ b/x/observer/types/message_vote_block_header.go @@ -53,14 +53,14 @@ func (msg *MsgVoteBlockHeader) ValidateBasic() error { return cosmoserrors.Wrapf(sdkerrors.ErrInvalidAddress, err.Error()) } - if chains.IsHeaderSupportedEvmChain(msg.ChainId) || chains.IsBitcoinChain(msg.ChainId) { - if len(msg.BlockHash) != 32 { - return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid block hash length (%d)", len(msg.BlockHash)) - } - } else { + if !chains.IsHeaderSupportedEvmChain(msg.ChainId) && !chains.IsBitcoinChain(msg.ChainId) { return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid chain id (%d)", msg.ChainId) } + if len(msg.BlockHash) != 32 { + return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid block hash length (%d)", len(msg.BlockHash)) + } + if err := msg.Header.Validate(msg.BlockHash, msg.ChainId, msg.Height); err != nil { return cosmoserrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid block header (%s)", err) } diff --git a/x/observer/types/tx.pb.go b/x/observer/types/tx.pb.go index e6869da51e..87585e885d 100644 --- a/x/observer/types/tx.pb.go +++ b/x/observer/types/tx.pb.go @@ -212,6 +212,8 @@ func (m *MsgVoteBlockHeader) GetHeader() proofs.HeaderData { } type MsgVoteBlockHeaderResponse struct { + BallotCreated bool `protobuf:"varint,1,opt,name=ballot_created,json=ballotCreated,proto3" json:"ballot_created,omitempty"` + VoteFinalized bool `protobuf:"varint,2,opt,name=vote_finalized,json=voteFinalized,proto3" json:"vote_finalized,omitempty"` } func (m *MsgVoteBlockHeaderResponse) Reset() { *m = MsgVoteBlockHeaderResponse{} } @@ -247,6 +249,20 @@ func (m *MsgVoteBlockHeaderResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgVoteBlockHeaderResponse proto.InternalMessageInfo +func (m *MsgVoteBlockHeaderResponse) GetBallotCreated() bool { + if m != nil { + return m.BallotCreated + } + return false +} + +func (m *MsgVoteBlockHeaderResponse) GetVoteFinalized() bool { + if m != nil { + return m.VoteFinalized + } + return false +} + type MsgUpdateChainParams struct { Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` ChainParams *ChainParams `protobuf:"bytes,2,opt,name=chainParams,proto3" json:"chainParams,omitempty"` @@ -1081,82 +1097,82 @@ func init() { func init() { proto.RegisterFile("observer/tx.proto", fileDescriptor_1bcd40fa296a2b1d) } var fileDescriptor_1bcd40fa296a2b1d = []byte{ - // 1193 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x57, 0x4b, 0x53, 0x1b, 0x47, - 0x10, 0x66, 0x8d, 0x0d, 0xa2, 0x79, 0x6f, 0xc0, 0x08, 0x01, 0x32, 0xb5, 0x55, 0x49, 0x48, 0x82, - 0x25, 0x90, 0xf3, 0x72, 0xaa, 0x72, 0x00, 0x27, 0x06, 0xe2, 0x60, 0xa8, 0x15, 0xe1, 0xe0, 0xcb, - 0xd6, 0x68, 0x77, 0xb4, 0xda, 0x62, 0x99, 0x51, 0xed, 0x8c, 0x78, 0x38, 0x8f, 0xaa, 0x1c, 0x73, - 0x48, 0x25, 0x3f, 0x20, 0xa7, 0xfc, 0x84, 0xfc, 0x86, 0x1c, 0x7c, 0x74, 0xe5, 0x94, 0x53, 0x2a, - 0x05, 0xa7, 0xfc, 0x82, 0x5c, 0x5d, 0x3b, 0x33, 0x3b, 0x7a, 0xa2, 0x07, 0x27, 0x69, 0xba, 0xbf, - 0xee, 0xfe, 0xba, 0xa7, 0xa7, 0x5b, 0x82, 0x59, 0x5a, 0x62, 0x38, 0x3a, 0xc3, 0x51, 0x9e, 0x5f, - 0xe4, 0xaa, 0x11, 0xe5, 0xd4, 0x5c, 0x7a, 0x89, 0x39, 0x72, 0x2b, 0x28, 0x20, 0x39, 0xf1, 0x8d, - 0x46, 0x38, 0x97, 0xa0, 0x32, 0x73, 0x3e, 0xf5, 0xa9, 0xc0, 0xe5, 0xe3, 0x6f, 0xd2, 0x24, 0x33, - 0xa7, 0xbd, 0x94, 0x42, 0x74, 0x8a, 0x95, 0xf4, 0x81, 0x96, 0xba, 0x11, 0x65, 0x4c, 0xb8, 0x74, - 0xca, 0x21, 0xf2, 0x99, 0x02, 0x2c, 0x68, 0x40, 0xf2, 0x45, 0x29, 0xe6, 0xb5, 0xa2, 0x8a, 0x22, - 0x74, 0x9a, 0xe0, 0x57, 0xea, 0x62, 0x4c, 0xbc, 0x80, 0xf8, 0x0e, 0xa1, 0xc4, 0xc5, 0x89, 0xda, - 0xac, 0xe7, 0xc2, 0x74, 0x88, 0xea, 0x89, 0x9f, 0x17, 0x91, 0x99, 0xfa, 0x68, 0x54, 0x54, 0x23, - 0x4a, 0xcb, 0x4c, 0x7d, 0x48, 0x85, 0xf5, 0x9f, 0x01, 0xb3, 0xfb, 0xcc, 0xff, 0xa6, 0xea, 0x21, - 0x8e, 0x0f, 0x94, 0x47, 0x33, 0x0d, 0xa3, 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, 0x95, 0xd8, 0x8c, 0x4e, 0x48, 0xcf, 0x45, 0x43, 0x0c, - 0xdb, 0x93, 0xae, 0x76, 0xfd, 0x35, 0x3d, 0x37, 0xd7, 0x60, 0xa6, 0x11, 0x57, 0x09, 0xfc, 0x8a, - 0x9a, 0xbd, 0x53, 0x75, 0xe0, 0x6e, 0xe0, 0x57, 0xac, 0x15, 0x58, 0xea, 0xc0, 0x4e, 0xb3, 0xff, - 0xdd, 0x00, 0x50, 0x13, 0xf7, 0xa8, 0x58, 0xec, 0x42, 0x7a, 0x05, 0x80, 0x33, 0x96, 0x4c, 0x02, - 0x39, 0x3d, 0xc6, 0x38, 0x63, 0xea, 0xed, 0xaf, 0x83, 0x79, 0x22, 0xea, 0xe2, 0xc4, 0xd7, 0xeb, - 0xa8, 0x75, 0x20, 0xb9, 0xcf, 0x48, 0xcd, 0x0b, 0xcc, 0xd1, 0xae, 0x5c, 0x0c, 0x0f, 0x61, 0x84, - 0x71, 0xc4, 0x6b, 0x4c, 0x6d, 0xc2, 0xf9, 0x9c, 0x5a, 0xee, 0x36, 0x76, 0x71, 0x70, 0x86, 0x8b, - 0x42, 0x69, 0x2b, 0x90, 0xf5, 0x53, 0x7d, 0x95, 0x1d, 0x15, 0x8b, 0x09, 0x77, 0xf3, 0x6d, 0x98, - 0x2a, 0xa1, 0x30, 0xa4, 0xdc, 0x11, 0x24, 0xb1, 0x27, 0x38, 0xa7, 0xec, 0x49, 0x29, 0x7d, 0x22, - 0x85, 0x31, 0xec, 0x8c, 0x72, 0xec, 0x94, 0x03, 0x82, 0xc2, 0xe0, 0x25, 0x96, 0x45, 0x4f, 0xd9, - 0x93, 0xb1, 0xf4, 0x69, 0x22, 0x8c, 0x61, 0x2a, 0x03, 0x56, 0x73, 0xdd, 0x64, 0xa1, 0xa7, 0xec, - 0x49, 0x29, 0x2d, 0x4a, 0x61, 0xe1, 0xaf, 0x31, 0x18, 0xde, 0x67, 0xbe, 0x49, 0x61, 0xbc, 0x71, - 0x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xce, 0x0e, 0xfd, 0x7d, 0x9d, 0x1d, 0x7a, 0x91, 0xf7, 0x03, 0x5e, 0xa9, - 0x95, 0x72, 0x2e, 0x3d, 0xcd, 0xc7, 0xae, 0x1e, 0x0a, 0xaf, 0xf9, 0xc4, 0x6b, 0xfe, 0x22, 0x5f, - 0xff, 0xd7, 0x76, 0x59, 0xc5, 0xac, 0x34, 0x22, 0xfe, 0x86, 0x3d, 0x7a, 0x13, 0x00, 0x00, 0xff, - 0xff, 0x17, 0xc3, 0xde, 0x63, 0x9a, 0x0e, 0x00, 0x00, + // 1200 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0x4b, 0x6f, 0xdb, 0x46, + 0x10, 0x36, 0xe3, 0xc4, 0x96, 0xc7, 0x6f, 0xd6, 0x8e, 0x65, 0x39, 0x56, 0x0c, 0x02, 0x6d, 0xdd, + 0xd6, 0x91, 0x6c, 0xa5, 0xaf, 0x14, 0xe8, 0xc1, 0x4e, 0x1b, 0xdb, 0x4d, 0x1d, 0x1b, 0x94, 0xeb, + 0x43, 0x2e, 0xc4, 0x8a, 0x5c, 0x91, 0xac, 0xe9, 0x5d, 0x81, 0xbb, 0xf2, 0x23, 0x7d, 0x00, 0x3d, + 0xf6, 0x50, 0xb4, 0x3f, 0xa0, 0xa7, 0xfe, 0x84, 0xfe, 0x86, 0x1e, 0x72, 0x0c, 0x7a, 0xea, 0xa9, + 0x28, 0xec, 0x53, 0x7f, 0x41, 0xaf, 0x05, 0x77, 0x97, 0xd4, 0xd3, 0x94, 0x64, 0x20, 0x27, 0x91, + 0x33, 0xdf, 0x7c, 0x33, 0xb3, 0x33, 0x3b, 0x43, 0xc1, 0x2c, 0xad, 0x30, 0x1c, 0x9e, 0xe2, 0xb0, + 0xc8, 0xcf, 0x0b, 0xb5, 0x90, 0x72, 0xaa, 0x2f, 0xbd, 0xc0, 0x1c, 0xd9, 0x1e, 0xf2, 0x49, 0x41, + 0x3c, 0xd1, 0x10, 0x17, 0x62, 0x54, 0x6e, 0xce, 0xa5, 0x2e, 0x15, 0xb8, 0x62, 0xf4, 0x24, 0x4d, + 0x72, 0x73, 0x09, 0x4b, 0x25, 0x40, 0x27, 0x58, 0x49, 0xef, 0x27, 0x52, 0x3b, 0xa4, 0x8c, 0x09, + 0x4a, 0xab, 0x1a, 0x20, 0x97, 0x29, 0xc0, 0x42, 0x02, 0x88, 0x1f, 0x94, 0x62, 0x3e, 0x51, 0xd4, + 0x50, 0x88, 0x4e, 0x62, 0xfc, 0x72, 0x43, 0x8c, 0x89, 0xe3, 0x13, 0xd7, 0x22, 0x94, 0xd8, 0x38, + 0x56, 0xeb, 0x8d, 0x5c, 0x58, 0xe2, 0xa2, 0x76, 0xec, 0x16, 0x85, 0x67, 0xa6, 0x7e, 0x9a, 0x15, + 0xb5, 0x90, 0xd2, 0x2a, 0x53, 0x3f, 0x52, 0x61, 0xfc, 0xab, 0xc1, 0xec, 0x1e, 0x73, 0xbf, 0xaa, + 0x39, 0x88, 0xe3, 0x7d, 0xc5, 0xa8, 0x67, 0x61, 0xd4, 0x0e, 0x31, 0xe2, 0x34, 0xcc, 0x6a, 0x2b, + 0xda, 0xea, 0x98, 0x19, 0xbf, 0xea, 0xeb, 0x30, 0x47, 0x03, 0xc7, 0x8a, 0x7d, 0x5b, 0xc8, 0x71, + 0x42, 0xcc, 0x58, 0xf6, 0x96, 0x80, 0xe9, 0x34, 0x70, 0x62, 0x92, 0x4d, 0xa9, 0x89, 0x2c, 0x08, + 0x3e, 0xeb, 0xb4, 0x18, 0x96, 0x16, 0x04, 0x9f, 0xb5, 0x5b, 0x1c, 0xc1, 0x64, 0x5d, 0xc4, 0x63, + 0x85, 0x18, 0x31, 0x4a, 0xb2, 0xb7, 0x57, 0xb4, 0xd5, 0xa9, 0xd2, 0x46, 0x21, 0xa5, 0x54, 0x85, + 0x98, 0x44, 0x66, 0x62, 0x0a, 0x43, 0x73, 0xa2, 0xde, 0xf4, 0x66, 0x2c, 0xc1, 0x62, 0x47, 0xaa, + 0x26, 0x66, 0x35, 0x4a, 0x18, 0x36, 0x7e, 0xd7, 0x40, 0xdf, 0x63, 0xee, 0x11, 0xe5, 0x78, 0x2b, + 0xa0, 0xf6, 0xf1, 0x0e, 0x46, 0x4e, 0xea, 0x49, 0x2c, 0x42, 0x46, 0xd6, 0xd8, 0x77, 0x44, 0xf6, + 0xc3, 0xe6, 0xa8, 0x78, 0xdf, 0x75, 0xf4, 0x65, 0x80, 0x4a, 0xc4, 0x61, 0x79, 0x88, 0x79, 0x22, + 0xd1, 0x09, 0x73, 0x4c, 0x48, 0x76, 0x10, 0xf3, 0xf4, 0xbb, 0x30, 0xe2, 0x61, 0xdf, 0xf5, 0xb8, + 0x48, 0x6c, 0xd8, 0x54, 0x6f, 0xfa, 0x7a, 0x24, 0x8f, 0xbc, 0x66, 0xef, 0xac, 0x68, 0xab, 0xe3, + 0x25, 0xbd, 0xa0, 0x4a, 0x25, 0x63, 0xf9, 0x0c, 0x71, 0xb4, 0x75, 0xfb, 0xe5, 0xdf, 0xf7, 0x87, + 0x4c, 0x85, 0x33, 0xbe, 0x86, 0x5c, 0x67, 0xcc, 0x71, 0x4a, 0xfa, 0x9b, 0x30, 0x55, 0x41, 0x41, + 0x40, 0xb9, 0x25, 0x62, 0xc6, 0x8e, 0x48, 0x21, 0x63, 0x4e, 0x4a, 0xe9, 0x63, 0x29, 0x8c, 0x60, + 0xa7, 0x94, 0x63, 0xab, 0xea, 0x13, 0x14, 0xf8, 0x2f, 0xb0, 0x4c, 0x27, 0x63, 0x4e, 0x46, 0xd2, + 0x27, 0xb1, 0xd0, 0xf8, 0x16, 0xe6, 0x92, 0xd3, 0x7b, 0x1c, 0x25, 0x7a, 0x20, 0x9a, 0x35, 0xe5, + 0x84, 0xbe, 0x80, 0x71, 0xbb, 0x01, 0x14, 0xac, 0xe3, 0xa5, 0xd5, 0xd4, 0x2a, 0x36, 0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 0xe2, 0xf3, 0x27, 0x0d, 0xe6, 0xbb, 0xaf, 0x95, 0x0f, 0xfa, 0x3c, 0xcc, 0x56, 0xb3, + 0xdc, 0xa7, 0x37, 0x32, 0x6b, 0x3e, 0x83, 0x96, 0x41, 0xba, 0xd6, 0x1f, 0x9d, 0x44, 0xf7, 0x3e, + 0x83, 0x6e, 0x13, 0x56, 0xff, 0x06, 0xa6, 0xdb, 0xbf, 0x89, 0x8b, 0xbd, 0x88, 0xda, 0x0c, 0x72, + 0x1f, 0x0d, 0x68, 0x90, 0x38, 0xff, 0x1e, 0x66, 0x3a, 0x46, 0xfb, 0x7a, 0xef, 0x1e, 0x6a, 0xb5, + 0xc8, 0x7d, 0x3c, 0xa8, 0x45, 0xe2, 0xdf, 0x86, 0xd1, 0x78, 0x38, 0xbf, 0xdd, 0x4f, 0x0e, 0x87, + 0xe5, 0x72, 0xae, 0xd8, 0x27, 0x30, 0x76, 0xb2, 0xb5, 0xfb, 0xf2, 0x32, 0xaf, 0xbd, 0xba, 0xcc, + 0x6b, 0xff, 0x5c, 0xe6, 0xb5, 0x5f, 0xae, 0xf2, 0x43, 0xaf, 0xae, 0xf2, 0x43, 0x7f, 0x5d, 0xe5, + 0x87, 0x9e, 0x17, 0x5d, 0x9f, 0x7b, 0xf5, 0x4a, 0xc1, 0xa6, 0x27, 0xc5, 0x88, 0xea, 0x81, 0x60, + 0x2d, 0xc6, 0xac, 0xc5, 0xf3, 0x62, 0xe3, 0x3f, 0xe0, 0x45, 0x0d, 0xb3, 0xca, 0x88, 0xf8, 0x53, + 0xf7, 0xf0, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe4, 0xd6, 0x5e, 0xab, 0xe8, 0x0e, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1712,6 +1728,26 @@ func (m *MsgVoteBlockHeaderResponse) MarshalToSizedBuffer(dAtA []byte) (int, err _ = i var l int _ = l + if m.VoteFinalized { + i-- + if m.VoteFinalized { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + if m.BallotCreated { + i-- + if m.BallotCreated { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x8 + } return len(dAtA) - i, nil } @@ -2381,6 +2417,12 @@ func (m *MsgVoteBlockHeaderResponse) Size() (n int) { } var l int _ = l + if m.BallotCreated { + n += 2 + } + if m.VoteFinalized { + n += 2 + } return n } @@ -3065,6 +3107,46 @@ func (m *MsgVoteBlockHeaderResponse) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: MsgVoteBlockHeaderResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BallotCreated", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.BallotCreated = bool(v != 0) + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field VoteFinalized", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.VoteFinalized = bool(v != 0) default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:])