From 3d43eb1c1df31e99d05a3dfa0cc04601503379d0 Mon Sep 17 00:00:00 2001 From: Connor O'Hara Date: Tue, 28 Nov 2023 14:03:28 -0500 Subject: [PATCH 01/13] delete Validators field --- types/signed_header.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/types/signed_header.go b/types/signed_header.go index 56e6a2071d..63338c6fbc 100644 --- a/types/signed_header.go +++ b/types/signed_header.go @@ -7,7 +7,6 @@ import ( "github.com/celestiaorg/go-header" "github.com/cometbft/cometbft/crypto/ed25519" - cmtypes "github.com/cometbft/cometbft/types" ) // SignedHeader combines Header and its Commit. @@ -15,8 +14,7 @@ import ( // Used mostly for gossiping. type SignedHeader struct { Header - Commit Commit - Validators *cmtypes.ValidatorSet + Commit Commit } // New creates a new SignedHeader. @@ -103,22 +101,13 @@ func (sh *SignedHeader) ValidateBasic() error { return err } - // Handle Based Rollup case - if sh.Validators == nil || len(sh.Validators.Validators) == 0 { - return nil - } - - if err := sh.Validators.ValidateBasic(); err != nil { - return err - } - // Make sure there is exactly one signature if len(sh.Commit.Signatures) != 1 { return errors.New("expected exactly one signature") } signature := sh.Commit.Signatures[0] - proposer := sh.Validators.GetProposer() + proposer := sh.Header.ProposerAddress var pubKey ed25519.PubKey = proposer.PubKey.Bytes() msg, err := sh.Header.MarshalBinary() if err != nil { From cba8d44c97721ff67e27090586c906a55df7c1e8 Mon Sep 17 00:00:00 2001 From: Connor O'Hara Date: Tue, 28 Nov 2023 16:14:50 -0500 Subject: [PATCH 02/13] removed validators, changed ProposerAddress to ProposerPubkey --- block/manager.go | 5 ++++- node/full_client_test.go | 4 ++-- state/executor.go | 30 +++++++++++++++--------------- state/executor_test.go | 11 +---------- store/store_test.go | 1 - types/abci/block.go | 10 +++++++--- types/abci/block_test.go | 10 +++++++--- types/hashing.go | 11 ++++++++--- types/header.go | 12 ++++++------ types/signed_header.go | 10 +++++----- types/signed_header_test.go | 4 ++-- types/utils.go | 17 +++++++---------- 12 files changed, 64 insertions(+), 61 deletions(-) diff --git a/block/manager.go b/block/manager.go index 34ab0741ec..30271253c8 100644 --- a/block/manager.go +++ b/block/manager.go @@ -9,6 +9,8 @@ import ( "sync/atomic" "time" + "github.com/cometbft/cometbft/crypto/ed25519" + goheaderstore "github.com/celestiaorg/go-header/store" abci "github.com/cometbft/cometbft/abci/types" cmcrypto "github.com/cometbft/cometbft/crypto" @@ -704,7 +706,8 @@ func (m *Manager) publishBlock(ctx context.Context) error { // Publish block to channel so that block exchange service can broadcast m.BlockCh <- block - m.logger.Debug("successfully proposed block", "proposer", hex.EncodeToString(block.SignedHeader.ProposerAddress), "height", blockHeight) + var pubkey ed25519.PubKey = block.SignedHeader.ProposerPubkey + m.logger.Debug("successfully proposed block", "proposer", hex.EncodeToString(pubkey.Address().Bytes()), "height", blockHeight) return nil } diff --git a/node/full_client_test.go b/node/full_client_test.go index 7685c01cf2..71b6b461ce 100644 --- a/node/full_client_test.go +++ b/node/full_client_test.go @@ -50,9 +50,9 @@ const ( var mockTxProcessingTime = 10 * time.Millisecond -func getRandomBlockWithProposer(height uint64, nTxs int, proposerAddr []byte) *types.Block { +func getRandomBlockWithProposer(height uint64, nTxs int, proposerPubkey []byte) *types.Block { block := types.GetRandomBlock(height, nTxs) - block.SignedHeader.ProposerAddress = proposerAddr + block.SignedHeader.ProposerPubkey = proposerPubkey return block } diff --git a/state/executor.go b/state/executor.go index ee91fda7b8..145c5c84d7 100644 --- a/state/executor.go +++ b/state/executor.go @@ -30,11 +30,11 @@ var ErrAddingValidatorToBased = errors.New("cannot add validators to empty valid // BlockExecutor creates and applies blocks and maintains state. type BlockExecutor struct { - proposerAddress []byte - namespaceID types.NamespaceID - chainID string - proxyApp proxy.AppConnConsensus - mempool mempool.Mempool + proposerPubkey []byte + namespaceID types.NamespaceID + chainID string + proxyApp proxy.AppConnConsensus + mempool mempool.Mempool eventBus *cmtypes.EventBus @@ -43,15 +43,15 @@ type BlockExecutor struct { // NewBlockExecutor creates new instance of BlockExecutor. // Proposer address and namespace ID will be used in all newly created blocks. -func NewBlockExecutor(proposerAddress []byte, namespaceID [8]byte, chainID string, mempool mempool.Mempool, proxyApp proxy.AppConnConsensus, eventBus *cmtypes.EventBus, logger log.Logger) *BlockExecutor { +func NewBlockExecutor(proposerPubkey []byte, namespaceID [8]byte, chainID string, mempool mempool.Mempool, proxyApp proxy.AppConnConsensus, eventBus *cmtypes.EventBus, logger log.Logger) *BlockExecutor { return &BlockExecutor{ - proposerAddress: proposerAddress, - namespaceID: namespaceID, - chainID: chainID, - proxyApp: proxyApp, - mempool: mempool, - eventBus: eventBus, - logger: logger, + proposerPubkey: proposerPubkey, + namespaceID: namespaceID, + chainID: chainID, + proxyApp: proxyApp, + mempool: mempool, + eventBus: eventBus, + logger: logger, } } @@ -115,7 +115,7 @@ func (e *BlockExecutor) CreateBlock(height uint64, lastCommit *types.Commit, las ConsensusHash: make(types.Hash, 32), AppHash: state.AppHash, LastResultsHash: state.LastResultsHash, - ProposerAddress: e.proposerAddress, + ProposerPubkey: e.proposerPubkey, }, Commit: *lastCommit, }, @@ -126,7 +126,7 @@ func (e *BlockExecutor) CreateBlock(height uint64, lastCommit *types.Commit, las // Evidence: types.EvidenceData{Evidence: nil}, }, } - block.SignedHeader.LastCommitHash = lastCommit.GetCommitHash(&block.SignedHeader.Header, e.proposerAddress) + block.SignedHeader.LastCommitHash = lastCommit.GetCommitHash(&block.SignedHeader.Header, e.proposerPubkey) block.SignedHeader.LastHeaderHash = lastHeaderHash return block diff --git a/state/executor_test.go b/state/executor_test.go index 9703965979..3d70dba5b7 100644 --- a/state/executor_test.go +++ b/state/executor_test.go @@ -133,14 +133,7 @@ func doTestApplyBlock(t *testing.T) { require.NotNil(headerSub) vKey := ed25519.GenPrivKey() - validators := []*cmtypes.Validator{ - { - Address: vKey.PubKey().Address(), - PubKey: vKey.PubKey(), - VotingPower: int64(100), - ProposerPriority: int64(1), - }, - } + state := types.State{} state.InitialHeight = 1 state.LastBlockHeight = 0 @@ -164,7 +157,6 @@ func doTestApplyBlock(t *testing.T) { block.SignedHeader.Commit = types.Commit{ Signatures: []types.Signature{sig}, } - block.SignedHeader.Validators = cmtypes.NewValidatorSet(validators) newState, resp, err := executor.ApplyBlock(context.Background(), state, block) require.NoError(err) @@ -192,7 +184,6 @@ func doTestApplyBlock(t *testing.T) { block.SignedHeader.Commit = types.Commit{ Signatures: []types.Signature{sig}, } - block.SignedHeader.Validators = cmtypes.NewValidatorSet(validators) newState, resp, err = executor.ApplyBlock(context.Background(), newState, block) require.NoError(err) diff --git a/store/store_test.go b/store/store_test.go index 934059d485..c44a70ab4b 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -105,7 +105,6 @@ func TestStoreLoad(t *testing.T) { for _, block := range c.blocks { commit := &types.Commit{} block.SignedHeader.Commit = *lastCommit - block.SignedHeader.Validators = types.GetRandomValidatorSet() err := bstore.SaveBlock(block, commit) require.NoError(err) lastCommit = commit diff --git a/types/abci/block.go b/types/abci/block.go index eaea9edf53..8f80027ab0 100644 --- a/types/abci/block.go +++ b/types/abci/block.go @@ -1,6 +1,7 @@ package abci import ( + "github.com/cometbft/cometbft/crypto/ed25519" cmbytes "github.com/cometbft/cometbft/libs/bytes" cmproto "github.com/cometbft/cometbft/proto/tendermint/types" cmversion "github.com/cometbft/cometbft/proto/tendermint/version" @@ -12,6 +13,7 @@ import ( // ToABCIHeaderPB converts Rollkit header to Header format defined in ABCI. // Caller should fill all the fields that are not available in Rollkit header (like ChainID). func ToABCIHeaderPB(header *types.Header) (cmproto.Header, error) { + var pubkey ed25519.PubKey = header.ProposerPubkey return cmproto.Header{ Version: cmversion.Consensus{ Block: header.Version.Block, @@ -32,7 +34,7 @@ func ToABCIHeaderPB(header *types.Header) (cmproto.Header, error) { AppHash: header.AppHash[:], LastResultsHash: header.LastResultsHash[:], EvidenceHash: new(cmtypes.EvidenceData).Hash(), - ProposerAddress: header.ProposerAddress, + ProposerAddress: pubkey.Address().Bytes(), ChainID: header.ChainID(), }, nil } @@ -40,6 +42,7 @@ func ToABCIHeaderPB(header *types.Header) (cmproto.Header, error) { // ToABCIHeader converts Rollkit header to Header format defined in ABCI. // Caller should fill all the fields that are not available in Rollkit header (like ChainID). func ToABCIHeader(header *types.Header) (cmtypes.Header, error) { + var pubkey ed25519.PubKey = header.ProposerPubkey return cmtypes.Header{ Version: cmversion.Consensus{ Block: header.Version.Block, @@ -60,7 +63,7 @@ func ToABCIHeader(header *types.Header) (cmtypes.Header, error) { AppHash: cmbytes.HexBytes(header.AppHash), LastResultsHash: cmbytes.HexBytes(header.LastResultsHash), EvidenceHash: new(cmtypes.EvidenceData).Hash(), - ProposerAddress: header.ProposerAddress, + ProposerAddress: pubkey.Address().Bytes(), ChainID: header.ChainID(), }, nil } @@ -68,6 +71,7 @@ func ToABCIHeader(header *types.Header) (cmtypes.Header, error) { // ToABCIBlock converts Rolkit block into block format defined by ABCI. // Returned block should pass `ValidateBasic`. func ToABCIBlock(block *types.Block) (*cmtypes.Block, error) { + var pubkey ed25519.PubKey = block.SignedHeader.Header.ProposerPubkey abciHeader, err := ToABCIHeader(&block.SignedHeader.Header) if err != nil { return nil, err @@ -75,7 +79,7 @@ func ToABCIBlock(block *types.Block) (*cmtypes.Block, error) { abciCommit := block.SignedHeader.Commit.ToABCICommit(block.Height(), block.Hash()) // This assumes that we have only one signature if len(abciCommit.Signatures) == 1 { - abciCommit.Signatures[0].ValidatorAddress = block.SignedHeader.ProposerAddress + abciCommit.Signatures[0].ValidatorAddress = pubkey.Address() } abciBlock := cmtypes.Block{ Header: abciHeader, diff --git a/types/abci/block_test.go b/types/abci/block_test.go index caba0cf0a7..c8ee2ade97 100644 --- a/types/abci/block_test.go +++ b/types/abci/block_test.go @@ -1,6 +1,7 @@ package abci import ( + "github.com/cometbft/cometbft/crypto/ed25519" cmbytes "github.com/cometbft/cometbft/libs/bytes" cmproto "github.com/cometbft/cometbft/proto/tendermint/types" @@ -17,6 +18,7 @@ import ( func TestToABCIHeaderPB(t *testing.T) { header := types.GetRandomHeader() + var pubkey ed25519.PubKey = header.ProposerPubkey expected := cmproto.Header{ Version: cmversion.Consensus{ Block: header.Version.Block, @@ -37,7 +39,7 @@ func TestToABCIHeaderPB(t *testing.T) { AppHash: header.AppHash[:], LastResultsHash: header.LastResultsHash[:], EvidenceHash: new(cmtypes.EvidenceData).Hash(), - ProposerAddress: header.ProposerAddress, + ProposerAddress: pubkey.Address().Bytes(), ChainID: header.ChainID(), } @@ -51,6 +53,7 @@ func TestToABCIHeaderPB(t *testing.T) { func TestToABCIHeader(t *testing.T) { header := types.GetRandomHeader() + var pubkey ed25519.PubKey = header.ProposerPubkey expected := cmtypes.Header{ Version: cmversion.Consensus{ Block: header.Version.Block, @@ -71,7 +74,7 @@ func TestToABCIHeader(t *testing.T) { AppHash: cmbytes.HexBytes(header.AppHash), LastResultsHash: cmbytes.HexBytes(header.LastResultsHash), EvidenceHash: new(cmtypes.EvidenceData).Hash(), - ProposerAddress: header.ProposerAddress, + ProposerAddress: pubkey.Address().Bytes(), ChainID: header.ChainID(), } @@ -86,6 +89,7 @@ func TestToABCIHeader(t *testing.T) { func TestToABCIBlock(t *testing.T) { blockHeight, nTxs := uint64(1), 2 block := types.GetRandomBlock(blockHeight, nTxs) + var pubkey ed25519.PubKey = block.SignedHeader.ProposerPubkey abciHeader, err := ToABCIHeader(&block.SignedHeader.Header) if err != nil { t.Fatal(err) @@ -94,7 +98,7 @@ func TestToABCIBlock(t *testing.T) { abciCommit := block.SignedHeader.Commit.ToABCICommit(block.Height(), block.Hash()) if len(abciCommit.Signatures) == 1 { - abciCommit.Signatures[0].ValidatorAddress = block.SignedHeader.ProposerAddress + abciCommit.Signatures[0].ValidatorAddress = pubkey.Address() } abciBlock := cmtypes.Block{ diff --git a/types/hashing.go b/types/hashing.go index bec54fc07f..07cff88ee0 100644 --- a/types/hashing.go +++ b/types/hashing.go @@ -1,6 +1,7 @@ package types import ( + "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/crypto/merkle" cmbytes "github.com/cometbft/cometbft/libs/bytes" cmversion "github.com/cometbft/cometbft/proto/tendermint/version" @@ -9,6 +10,7 @@ import ( // Hash returns ABCI-compatible hash of a header. func (h *Header) Hash() Hash { + var pubkey ed25519.PubKey = h.ProposerPubkey abciHeader := cmtypes.Header{ Version: cmversion.Consensus{ Block: h.Version.Block, @@ -29,10 +31,13 @@ func (h *Header) Hash() Hash { AppHash: cmbytes.HexBytes(h.AppHash), LastResultsHash: cmbytes.HexBytes(h.LastResultsHash), EvidenceHash: new(cmtypes.EvidenceData).Hash(), - ProposerAddress: h.ProposerAddress, + ProposerAddress: pubkey.Address(), // Backward compatibility - ValidatorsHash: h.ProposerAddress, - NextValidatorsHash: h.ProposerAddress, + /* Eventually, these will need to be populated with + something that passes validation from the IBC Tendermint Light Client. + */ + ValidatorsHash: pubkey.Address(), + NextValidatorsHash: pubkey.Address(), ChainID: h.ChainID(), } return Hash(abciHeader.Hash()) diff --git a/types/header.go b/types/header.go index 919d6392ba..14a2bd84b5 100644 --- a/types/header.go +++ b/types/header.go @@ -46,7 +46,7 @@ type Header struct { // from the signature when using secp256k. // We keep this in case users choose another signature format where the // pubkey can't be recovered by the signature (e.g. ed25519). - ProposerAddress []byte // original proposer of the block + ProposerPubkey []byte // original proposer of the block } // New creates a new Header. @@ -81,11 +81,11 @@ func (h *Header) Time() time.Time { // Verify verifies the header. func (h *Header) Verify(untrstH *Header) error { - if !bytes.Equal(untrstH.ProposerAddress, h.ProposerAddress) { + if !bytes.Equal(untrstH.ProposerPubkey, h.ProposerPubkey) { return &header.VerifyError{ Reason: fmt.Errorf("expected proposer (%X) got (%X)", - h.ProposerAddress, - untrstH.ProposerAddress, + h.ProposerPubkey, + untrstH.ProposerPubkey, ), } } @@ -99,8 +99,8 @@ func (h *Header) Validate() error { // ValidateBasic performs basic validation of a header. func (h *Header) ValidateBasic() error { - if len(h.ProposerAddress) == 0 { - return ErrNoProposerAddress + if len(h.ProposerPubkey) == 0 { + return ErrNoProposerPubkey } return nil diff --git a/types/signed_header.go b/types/signed_header.go index 63338c6fbc..6631fba8f0 100644 --- a/types/signed_header.go +++ b/types/signed_header.go @@ -31,8 +31,8 @@ var ( // ErrNonAdjacentHeaders is returned when the headers are not adjacent. ErrNonAdjacentHeaders = errors.New("non-adjacent headers") - // ErrNoProposerAddress is returned when the proposer address is not set. - ErrNoProposerAddress = errors.New("no proposer address") + // ErrNoProposerPubkey is returned when the proposer address is not set. + ErrNoProposerPubkey = errors.New("no proposer address") // ErrLastHeaderHashMismatch is returned when the last header hash doesn't match. ErrLastHeaderHashMismatch = errors.New("last header hash mismatch") @@ -70,7 +70,8 @@ func (sh *SignedHeader) Verify(untrstH *SignedHeader) error { ), } } - sHLastCommitHash := sh.Commit.GetCommitHash(&untrstH.Header, sh.ProposerAddress) + var pubkey ed25519.PubKey = sh.ProposerPubkey + sHLastCommitHash := sh.Commit.GetCommitHash(&untrstH.Header, pubkey.Address()) if !bytes.Equal(untrstH.LastCommitHash[:], sHLastCommitHash) { return &header.VerifyError{ Reason: fmt.Errorf("%w: expected %v, but got %v", @@ -107,8 +108,7 @@ func (sh *SignedHeader) ValidateBasic() error { } signature := sh.Commit.Signatures[0] - proposer := sh.Header.ProposerAddress - var pubKey ed25519.PubKey = proposer.PubKey.Bytes() + var pubKey ed25519.PubKey = sh.ProposerPubkey msg, err := sh.Header.MarshalBinary() if err != nil { return errors.New("signature verification failed, unable to marshal header") diff --git a/types/signed_header_test.go b/types/signed_header_test.go index 406c48e128..cf1e8b26da 100644 --- a/types/signed_header_test.go +++ b/types/signed_header_test.go @@ -137,10 +137,10 @@ func testValidateBasic(t *testing.T, untrustedAdj *SignedHeader, privKey ed25519 { prepare: func() (*SignedHeader, bool) { untrusted := *untrustedAdj - untrusted.ProposerAddress = nil + untrusted.ProposerPubkey = nil return &untrusted, true }, - err: ErrNoProposerAddress, + err: ErrNoProposerPubkey, }, } diff --git a/types/utils.go b/types/utils.go index 6dc14848e7..482957cdbf 100644 --- a/types/utils.go +++ b/types/utils.go @@ -89,7 +89,7 @@ func GetRandomHeader() Header { ConsensusHash: GetRandomBytes(32), AppHash: GetRandomBytes(32), LastResultsHash: GetRandomBytes(32), - ProposerAddress: GetRandomBytes(32), + ProposerPubkey: GetRandomBytes(32), } } @@ -100,18 +100,17 @@ func GetRandomNextHeader(header Header) Header { nextHeader.BaseHeader.Height = header.Height() + 1 nextHeader.BaseHeader.Time = uint64(time.Now().Add(1 * time.Second).UnixNano()) nextHeader.LastHeaderHash = header.Hash() - nextHeader.ProposerAddress = header.ProposerAddress + nextHeader.ProposerPubkey = header.ProposerPubkey return nextHeader } // GetRandomSignedHeader returns a signed header with random data func GetRandomSignedHeader() (*SignedHeader, ed25519.PrivKey, error) { - valSet, privKey := GetRandomValidatorSetWithPrivKey() + _, privKey := GetRandomValidatorSetWithPrivKey() signedHeader := &SignedHeader{ - Header: GetRandomHeader(), - Validators: valSet, + Header: GetRandomHeader(), } - signedHeader.Header.ProposerAddress = valSet.Proposer.Address + signedHeader.Header.ProposerPubkey = privKey.PubKey().Bytes() commit, err := getCommit(signedHeader.Header, privKey) if err != nil { return nil, nil, err @@ -123,13 +122,11 @@ func GetRandomSignedHeader() (*SignedHeader, ed25519.PrivKey, error) { // GetRandomNextSignedHeader returns a signed header with random data and height of +1 from // the provided signed header func GetRandomNextSignedHeader(signedHeader *SignedHeader, privKey ed25519.PrivKey) (*SignedHeader, error) { - valSet := signedHeader.Validators newSignedHeader := &SignedHeader{ - Header: GetRandomNextHeader(signedHeader.Header), - Validators: valSet, + Header: GetRandomNextHeader(signedHeader.Header), } newSignedHeader.LastCommitHash = signedHeader.Commit.GetCommitHash( - &newSignedHeader.Header, signedHeader.ProposerAddress, + &newSignedHeader.Header, signedHeader.ProposerPubkey, ) commit, err := getCommit(newSignedHeader.Header, privKey) if err != nil { From e39391bf863992924f06a7d55f018efc13f62b90 Mon Sep 17 00:00:00 2001 From: Connor O'Hara Date: Tue, 28 Nov 2023 16:54:37 -0500 Subject: [PATCH 03/13] serialization --- proto/rollkit/rollkit.proto | 3 +- types/pb/rollkit/rollkit.pb.go | 166 +++++++++++---------------------- types/serialization.go | 25 ++--- types/serialization_test.go | 15 +-- 4 files changed, 60 insertions(+), 149 deletions(-) diff --git a/proto/rollkit/rollkit.proto b/proto/rollkit/rollkit.proto index f6da6e526a..5828037fad 100644 --- a/proto/rollkit/rollkit.proto +++ b/proto/rollkit/rollkit.proto @@ -47,7 +47,7 @@ message Header { // from the signature when using secp256k. // We keep this in case users choose another signature format where the // pubkey can't be recovered by the signature (e.g. ed25519). - bytes proposer_address = 10; + bytes proposer_pubkey = 10; // Chain ID the block belongs to string chain_id = 11; @@ -60,7 +60,6 @@ message Commit { message SignedHeader { Header header = 1; Commit commit = 2; - tendermint.types.ValidatorSet validators = 3; } message Data { diff --git a/types/pb/rollkit/rollkit.pb.go b/types/pb/rollkit/rollkit.pb.go index dec464fdf6..f5b5b9a06e 100644 --- a/types/pb/rollkit/rollkit.pb.go +++ b/types/pb/rollkit/rollkit.pb.go @@ -5,7 +5,7 @@ package rollkit import ( fmt "fmt" - types "github.com/cometbft/cometbft/proto/tendermint/types" + _ "github.com/cometbft/cometbft/proto/tendermint/types" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -105,7 +105,7 @@ type Header struct { // from the signature when using secp256k. // We keep this in case users choose another signature format where the // pubkey can't be recovered by the signature (e.g. ed25519). - ProposerAddress []byte `protobuf:"bytes,10,opt,name=proposer_address,json=proposerAddress,proto3" json:"proposer_address,omitempty"` + ProposerPubkey []byte `protobuf:"bytes,10,opt,name=proposer_pubkey,json=proposerPubkey,proto3" json:"proposer_pubkey,omitempty"` // Chain ID the block belongs to ChainId string `protobuf:"bytes,11,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` } @@ -206,9 +206,9 @@ func (m *Header) GetLastResultsHash() []byte { return nil } -func (m *Header) GetProposerAddress() []byte { +func (m *Header) GetProposerPubkey() []byte { if m != nil { - return m.ProposerAddress + return m.ProposerPubkey } return nil } @@ -265,9 +265,8 @@ func (m *Commit) GetSignatures() [][]byte { } type SignedHeader struct { - Header *Header `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` - Commit *Commit `protobuf:"bytes,2,opt,name=commit,proto3" json:"commit,omitempty"` - Validators *types.ValidatorSet `protobuf:"bytes,3,opt,name=validators,proto3" json:"validators,omitempty"` + Header *Header `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` + Commit *Commit `protobuf:"bytes,2,opt,name=commit,proto3" json:"commit,omitempty"` } func (m *SignedHeader) Reset() { *m = SignedHeader{} } @@ -317,13 +316,6 @@ func (m *SignedHeader) GetCommit() *Commit { return nil } -func (m *SignedHeader) GetValidators() *types.ValidatorSet { - if m != nil { - return m.Validators - } - return nil -} - type Data struct { Txs [][]byte `protobuf:"bytes,1,rep,name=txs,proto3" json:"txs,omitempty"` IntermediateStateRoots [][]byte `protobuf:"bytes,2,rep,name=intermediate_state_roots,json=intermediateStateRoots,proto3" json:"intermediate_state_roots,omitempty"` @@ -501,45 +493,43 @@ func init() { func init() { proto.RegisterFile("rollkit/rollkit.proto", fileDescriptor_ed489fb7f4d78b3f) } var fileDescriptor_ed489fb7f4d78b3f = []byte{ - // 607 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x93, 0xc1, 0x6e, 0x13, 0x3d, - 0x10, 0xc7, 0xbb, 0x49, 0x9a, 0xb4, 0xd3, 0xb4, 0xcd, 0x67, 0x7d, 0x2d, 0x0b, 0x48, 0xab, 0xb0, - 0x12, 0x22, 0x14, 0x29, 0x11, 0xe5, 0x82, 0x38, 0x20, 0x51, 0x40, 0x6a, 0x6e, 0xc8, 0x41, 0x45, - 0xe2, 0xb2, 0x72, 0xb2, 0x26, 0x6b, 0x35, 0x59, 0x5b, 0xf6, 0xa4, 0x0a, 0x0f, 0xc0, 0x9d, 0x47, - 0xe0, 0x71, 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c, 0x92, 0xbd, - 0x84, 0x58, 0x95, 0x28, 0xed, 0x5c, 0xe6, 0x4a, 0xa0, 0xcc, 0x1c, 0xfa, 0x5f, 0xab, 0x35, 0xba, - 0xb8, 0x46, 0xd8, 0xf1, 0xa6, 0x3f, 0xf2, 0x36, 0xf7, 0x6e, 0xfa, 0x05, 0xb6, 0xcf, 0x68, 0x86, - 0x5f, 0xc1, 0xbe, 0xa3, 0xf2, 0xb3, 0xbf, 0xaa, 0x3e, 0x5a, 0x17, 0xb3, 0x79, 0x39, 0xbc, 0xed, - 0x36, 0xaf, 0xea, 0x11, 0x34, 0xfc, 0x94, 0x54, 0xf5, 0xef, 0xaf, 0xb7, 0xf8, 0xaf, 0xe5, 0x64, - 0xa5, 0x1f, 0x00, 0x3e, 0x2e, 0x3f, 0x29, 0x2c, 0x86, 0x23, 0xee, 0xd8, 0x3d, 0x68, 0x19, 0x2b, - 0x33, 0xe5, 0x42, 0x9a, 0x36, 0x6f, 0x1a, 0x2b, 0x87, 0xce, 0xb2, 0x03, 0xa8, 0xe1, 0x92, 0xce, - 0x69, 0xf3, 0x1a, 0x2e, 0x7d, 0x6b, 0x8d, 0x76, 0x48, 0x64, 0x3d, 0x0c, 0x93, 0x8f, 0x87, 0xce, - 0x9e, 0xbd, 0xff, 0x79, 0x93, 0x44, 0xd7, 0x37, 0x49, 0xf4, 0xfb, 0x26, 0x89, 0xbe, 0xdf, 0x26, - 0x5b, 0xd7, 0xb7, 0xc9, 0xd6, 0xaf, 0xdb, 0x64, 0xeb, 0xf3, 0xb3, 0xa9, 0xc2, 0x62, 0x31, 0xee, - 0x4f, 0xf4, 0x7c, 0xf0, 0xcf, 0xe3, 0xaf, 0x5e, 0xb8, 0x19, 0xaf, 0x84, 0x71, 0x93, 0xde, 0xf8, - 0x8b, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x4f, 0x4f, 0x2e, 0xb0, 0x27, 0x04, 0x00, 0x00, + // 576 bytes of a gzipped FileDescriptorProto +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x44, 0xd5, 0xc3, 0xff, 0x5e, 0x6e, 0x78, 0x9e, 0x7a, 0xbc, 0x14, 0xc6, 0x5d, 0x7a, + 0xa0, 0xaf, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, 0x30, 0x22, 0x22, 0xb7, 0xe4, 0x03, 0x00, 0x00, } func (m *Version) Marshal() (dAtA []byte, err error) { @@ -602,10 +592,10 @@ func (m *Header) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x5a } - if len(m.ProposerAddress) > 0 { - i -= len(m.ProposerAddress) - copy(dAtA[i:], m.ProposerAddress) - i = encodeVarintRollkit(dAtA, i, uint64(len(m.ProposerAddress))) + if len(m.ProposerPubkey) > 0 { + i -= len(m.ProposerPubkey) + copy(dAtA[i:], m.ProposerPubkey) + i = encodeVarintRollkit(dAtA, i, uint64(len(m.ProposerPubkey))) i-- dAtA[i] = 0x52 } @@ -728,18 +718,6 @@ func (m *SignedHeader) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.Validators != nil { - { - size, err := m.Validators.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRollkit(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } if m.Commit != nil { { size, err := m.Commit.MarshalToSizedBuffer(dAtA[:i]) @@ -965,7 +943,7 @@ func (m *Header) Size() (n int) { if l > 0 { n += 1 + l + sovRollkit(uint64(l)) } - l = len(m.ProposerAddress) + l = len(m.ProposerPubkey) if l > 0 { n += 1 + l + sovRollkit(uint64(l)) } @@ -1005,10 +983,6 @@ func (m *SignedHeader) Size() (n int) { l = m.Commit.Size() n += 1 + l + sovRollkit(uint64(l)) } - if m.Validators != nil { - l = m.Validators.Size() - n += 1 + l + sovRollkit(uint64(l)) - } return n } @@ -1474,7 +1448,7 @@ func (m *Header) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 10: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ProposerAddress", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ProposerPubkey", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1501,9 +1475,9 @@ func (m *Header) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.ProposerAddress = append(m.ProposerAddress[:0], dAtA[iNdEx:postIndex]...) - if m.ProposerAddress == nil { - m.ProposerAddress = []byte{} + m.ProposerPubkey = append(m.ProposerPubkey[:0], dAtA[iNdEx:postIndex]...) + if m.ProposerPubkey == nil { + m.ProposerPubkey = []byte{} } iNdEx = postIndex case 11: @@ -1742,42 +1716,6 @@ func (m *SignedHeader) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Validators", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRollkit - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRollkit - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRollkit - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Validators == nil { - m.Validators = &types.ValidatorSet{} - } - if err := m.Validators.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipRollkit(dAtA[iNdEx:]) diff --git a/types/serialization.go b/types/serialization.go index 4353cfca4c..56e3a7d3b5 100644 --- a/types/serialization.go +++ b/types/serialization.go @@ -76,14 +76,9 @@ func (c *Commit) UnmarshalBinary(data []byte) error { // ToProto converts SignedHeader into protobuf representation and returns it. func (sh *SignedHeader) ToProto() (*pb.SignedHeader, error) { - vSet, err := sh.Validators.ToProto() - if err != nil { - return nil, err - } return &pb.SignedHeader{ - Header: sh.Header.ToProto(), - Commit: sh.Commit.ToProto(), - Validators: vSet, + Header: sh.Header.ToProto(), + Commit: sh.Commit.ToProto(), }, nil } @@ -98,14 +93,6 @@ func (sh *SignedHeader) FromProto(other *pb.SignedHeader) error { return err } - if other.Validators != nil && other.Validators.GetProposer() != nil { - validators, err := types.ValidatorSetFromProto(other.Validators) - if err != nil { - return err - } - - sh.Validators = validators - } return nil } @@ -147,7 +134,7 @@ func (h *Header) ToProto() *pb.Header { ConsensusHash: h.ConsensusHash[:], AppHash: h.AppHash[:], LastResultsHash: h.LastResultsHash[:], - ProposerAddress: h.ProposerAddress[:], + ProposerPubkey: h.ProposerPubkey[:], ChainId: h.BaseHeader.ChainID, } } @@ -165,9 +152,9 @@ func (h *Header) FromProto(other *pb.Header) error { h.ConsensusHash = other.ConsensusHash h.AppHash = other.AppHash h.LastResultsHash = other.LastResultsHash - if len(other.ProposerAddress) > 0 { - h.ProposerAddress = make([]byte, len(other.ProposerAddress)) - copy(h.ProposerAddress, other.ProposerAddress) + if len(other.ProposerPubkey) > 0 { + h.ProposerPubkey = make([]byte, len(other.ProposerPubkey)) + copy(h.ProposerPubkey, other.ProposerPubkey) } return nil diff --git a/types/serialization_test.go b/types/serialization_test.go index 698e0d4095..8a0d483941 100644 --- a/types/serialization_test.go +++ b/types/serialization_test.go @@ -8,7 +8,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/cometbft/cometbft/crypto/ed25519" cmstate "github.com/cometbft/cometbft/proto/tendermint/state" cmproto "github.com/cometbft/cometbft/proto/tendermint/types" cmversion "github.com/cometbft/cometbft/proto/tendermint/version" @@ -47,14 +46,9 @@ func TestBlockSerializationRoundTrip(t *testing.T) { ConsensusHash: h[3], AppHash: h[4], LastResultsHash: h[5], - ProposerAddress: []byte{4, 3, 2, 1}, + ProposerPubkey: []byte{4, 3, 2, 1}, } - pubKey1 := ed25519.GenPrivKey().PubKey() - pubKey2 := ed25519.GenPrivKey().PubKey() - validator1 := &cmtypes.Validator{Address: pubKey1.Address(), PubKey: pubKey1} - validator2 := &cmtypes.Validator{Address: pubKey2.Address(), PubKey: pubKey2} - cases := []struct { name string input *Block @@ -66,13 +60,6 @@ func TestBlockSerializationRoundTrip(t *testing.T) { Commit: Commit{ Signatures: []Signature{Signature([]byte{1, 1, 1}), Signature([]byte{2, 2, 2})}, }, - Validators: &cmtypes.ValidatorSet{ - Validators: []*cmtypes.Validator{ - validator1, - validator2, - }, - Proposer: validator1, - }, }, Data: Data{ Txs: nil, From cacab64b26ff028fd534e400403e073b19d3cd8f Mon Sep 17 00:00:00 2001 From: Connor O'Hara Date: Tue, 28 Nov 2023 17:43:39 -0500 Subject: [PATCH 04/13] fix verify test --- types/signed_header.go | 2 +- types/utils.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/types/signed_header.go b/types/signed_header.go index 6631fba8f0..989944778b 100644 --- a/types/signed_header.go +++ b/types/signed_header.go @@ -71,7 +71,7 @@ func (sh *SignedHeader) Verify(untrstH *SignedHeader) error { } } var pubkey ed25519.PubKey = sh.ProposerPubkey - sHLastCommitHash := sh.Commit.GetCommitHash(&untrstH.Header, pubkey.Address()) + sHLastCommitHash := sh.Commit.GetCommitHash(&untrstH.Header, pubkey.Address().Bytes()) if !bytes.Equal(untrstH.LastCommitHash[:], sHLastCommitHash) { return &header.VerifyError{ Reason: fmt.Errorf("%w: expected %v, but got %v", diff --git a/types/utils.go b/types/utils.go index 482957cdbf..b779efec77 100644 --- a/types/utils.go +++ b/types/utils.go @@ -125,8 +125,9 @@ func GetRandomNextSignedHeader(signedHeader *SignedHeader, privKey ed25519.PrivK newSignedHeader := &SignedHeader{ Header: GetRandomNextHeader(signedHeader.Header), } + var pubkey ed25519.PubKey = signedHeader.ProposerPubkey newSignedHeader.LastCommitHash = signedHeader.Commit.GetCommitHash( - &newSignedHeader.Header, signedHeader.ProposerPubkey, + &newSignedHeader.Header, pubkey.Address().Bytes(), ) commit, err := getCommit(newSignedHeader.Header, privKey) if err != nil { From 33105b261abdeaba862f14b3a952543995dcccab Mon Sep 17 00:00:00 2001 From: Connor O'Hara Date: Tue, 28 Nov 2023 18:10:24 -0500 Subject: [PATCH 05/13] fix TestCreateBlockWithFraudProof --- state/executor_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/state/executor_test.go b/state/executor_test.go index 3d70dba5b7..2c2c6bdaac 100644 --- a/state/executor_test.go +++ b/state/executor_test.go @@ -53,7 +53,8 @@ func doTestCreateBlock(t *testing.T) { fmt.Println("Made NID") mpool := mempoolv1.NewTxMempool(logger, cfg.DefaultMempoolConfig(), proxy.NewAppConnMempool(client, proxy.NopMetrics()), 0) fmt.Println("Made a NewTxMempool") - executor := NewBlockExecutor([]byte("test address"), nsID, "test", mpool, proxy.NewAppConnConsensus(client, proxy.NopMetrics()), nil, logger) + proposerKey := ed25519.GenPrivKey().PubKey() + executor := NewBlockExecutor(proposerKey.Bytes(), nsID, "test", mpool, proxy.NewAppConnConsensus(client, proxy.NopMetrics()), nil, logger) fmt.Println("Made a New Block Executor") state := types.State{} From 3a40f4f1846a14c29428e5b788d2140ab844068f Mon Sep 17 00:00:00 2001 From: Connor O'Hara Date: Tue, 28 Nov 2023 19:55:53 -0500 Subject: [PATCH 06/13] fix TestApplyBlockWithFraudProofsDisabled --- state/executor_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/state/executor_test.go b/state/executor_test.go index 2c2c6bdaac..6eb343ef1f 100644 --- a/state/executor_test.go +++ b/state/executor_test.go @@ -119,7 +119,8 @@ func doTestApplyBlock(t *testing.T) { mpool := mempoolv1.NewTxMempool(logger, cfg.DefaultMempoolConfig(), proxy.NewAppConnMempool(client, proxy.NopMetrics()), 0) eventBus := cmtypes.NewEventBus() require.NoError(eventBus.Start()) - executor := NewBlockExecutor([]byte("test address"), nsID, chainID, mpool, proxy.NewAppConnConsensus(client, proxy.NopMetrics()), eventBus, logger) + vKey := ed25519.GenPrivKey() + executor := NewBlockExecutor(vKey.PubKey().Bytes(), nsID, chainID, mpool, proxy.NewAppConnConsensus(client, proxy.NopMetrics()), eventBus, logger) txQuery, err := query.New("tm.event='Tx'") require.NoError(err) @@ -133,8 +134,6 @@ func doTestApplyBlock(t *testing.T) { require.NoError(err) require.NotNil(headerSub) - vKey := ed25519.GenPrivKey() - state := types.State{} state.InitialHeight = 1 state.LastBlockHeight = 0 From 9fe33a71a39e689432a28ce07e5d9ebc98fed0df Mon Sep 17 00:00:00 2001 From: Connor O'Hara Date: Wed, 29 Nov 2023 16:02:07 -0500 Subject: [PATCH 07/13] proposerPubkeyBytes --- block/manager.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/block/manager.go b/block/manager.go index 30271253c8..6e5b21a399 100644 --- a/block/manager.go +++ b/block/manager.go @@ -127,11 +127,6 @@ func NewManager( s.DAHeight = conf.DAStartHeight } - proposerAddress, err := getAddress(proposerKey) - if err != nil { - return nil, err - } - if conf.DABlockTime == 0 { logger.Info("Using default DA block time", "DABlockTime", defaultDABlockTime) conf.DABlockTime = defaultDABlockTime @@ -142,7 +137,11 @@ func NewManager( conf.BlockTime = defaultBlockTime } - exec := state.NewBlockExecutor(proposerAddress, conf.NamespaceID, genesis.ChainID, mempool, proxyApp, eventBus, logger) + proposerPubkeyBytes, err := proposerKey.GetPublic().Raw() + if err != nil { + return nil, err + } + exec := state.NewBlockExecutor(proposerPubkeyBytes, conf.NamespaceID, genesis.ChainID, mempool, proxyApp, eventBus, logger) if s.LastBlockHeight+1 == uint64(genesis.InitialHeight) { res, err := exec.InitChain(genesis) if err != nil { From 50dabb9a944013b5992106869457015fb0f0e348 Mon Sep 17 00:00:00 2001 From: Connor O'Hara Date: Wed, 29 Nov 2023 17:37:08 -0500 Subject: [PATCH 08/13] fix LastCommitHash in executor --- state/executor.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/state/executor.go b/state/executor.go index 145c5c84d7..b656ec4d22 100644 --- a/state/executor.go +++ b/state/executor.go @@ -8,6 +8,7 @@ import ( "time" abci "github.com/cometbft/cometbft/abci/types" + "github.com/cometbft/cometbft/crypto/ed25519" cryptoenc "github.com/cometbft/cometbft/crypto/encoding" cmbytes "github.com/cometbft/cometbft/libs/bytes" cmstate "github.com/cometbft/cometbft/proto/tendermint/state" @@ -126,7 +127,8 @@ func (e *BlockExecutor) CreateBlock(height uint64, lastCommit *types.Commit, las // Evidence: types.EvidenceData{Evidence: nil}, }, } - block.SignedHeader.LastCommitHash = lastCommit.GetCommitHash(&block.SignedHeader.Header, e.proposerPubkey) + var pk ed25519.PubKey = e.proposerPubkey + block.SignedHeader.LastCommitHash = lastCommit.GetCommitHash(&block.SignedHeader.Header, pk.Address().Bytes()) block.SignedHeader.LastHeaderHash = lastHeaderHash return block From f5987ede7afdea99cf512ad4de8b7f4e2308a900 Mon Sep 17 00:00:00 2001 From: Connor O'Hara Date: Wed, 29 Nov 2023 17:44:54 -0500 Subject: [PATCH 09/13] remove unused for lint --- block/manager.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/block/manager.go b/block/manager.go index 6e5b21a399..a51281548c 100644 --- a/block/manager.go +++ b/block/manager.go @@ -13,7 +13,6 @@ import ( goheaderstore "github.com/celestiaorg/go-header/store" abci "github.com/cometbft/cometbft/abci/types" - cmcrypto "github.com/cometbft/cometbft/crypto" "github.com/cometbft/cometbft/crypto/merkle" cmstate "github.com/cometbft/cometbft/proto/tendermint/state" "github.com/cometbft/cometbft/proxy" @@ -189,14 +188,6 @@ func NewManager( return agg, nil } -func getAddress(key crypto.PrivKey) ([]byte, error) { - rawKey, err := key.GetPublic().Raw() - if err != nil { - return nil, err - } - return cmcrypto.AddressHash(rawKey), nil -} - // SetDALC is used to set DataAvailabilityLayerClient used by Manager. func (m *Manager) SetDALC(dalc da.DataAvailabilityLayerClient) { m.dalc = dalc From 9b823b4d90bc3273046dd04a39b0ccdfe7fdf1e9 Mon Sep 17 00:00:00 2001 From: Connor O'Hara Date: Wed, 29 Nov 2023 17:57:01 -0500 Subject: [PATCH 10/13] fix ErrNoProposerPubkey error description --- types/signed_header.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/signed_header.go b/types/signed_header.go index 989944778b..4c9098813e 100644 --- a/types/signed_header.go +++ b/types/signed_header.go @@ -32,7 +32,7 @@ var ( ErrNonAdjacentHeaders = errors.New("non-adjacent headers") // ErrNoProposerPubkey is returned when the proposer address is not set. - ErrNoProposerPubkey = errors.New("no proposer address") + ErrNoProposerPubkey = errors.New("no proposer pubkey") // ErrLastHeaderHashMismatch is returned when the last header hash doesn't match. ErrLastHeaderHashMismatch = errors.New("last header hash mismatch") From 6aee4086b4b507606645b53be7e73e0cd8bca4bb Mon Sep 17 00:00:00 2001 From: Connor O'Hara Date: Wed, 29 Nov 2023 18:06:55 -0500 Subject: [PATCH 11/13] reject invalid blocks/signers in retrieve loop --- block/manager.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/manager.go b/block/manager.go index a51281548c..9683aa1a97 100644 --- a/block/manager.go +++ b/block/manager.go @@ -493,6 +493,14 @@ func (m *Manager) processNextDABlock(ctx context.Context) error { } m.logger.Debug("retrieved potential blocks", "n", len(blockResp.Blocks), "daHeight", daHeight) for _, block := range blockResp.Blocks { + // Don't waste resources on blocks with unexpected signers + if !bytes.Equal(block.SignedHeader.ProposerPubkey, m.genesis.Validators[0].PubKey.Bytes()) { + continue + } + // Don't waste resources on invalid blocks + if block.ValidateBasic() != nil { + continue + } blockHash := block.Hash().String() m.blockCache.setDAIncluded(blockHash) m.logger.Info("block marked as DA included", "blockHeight", block.Height(), "blockHash", blockHash) From d1945d8f3ed3c1f4413d0423dd05e59196daa541 Mon Sep 17 00:00:00 2001 From: Connor O'Hara Date: Wed, 29 Nov 2023 19:25:12 -0500 Subject: [PATCH 12/13] fix TestDAFastSync --- node/full_node_integration_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/node/full_node_integration_test.go b/node/full_node_integration_test.go index e43fc93258..153d7a8293 100644 --- a/node/full_node_integration_test.go +++ b/node/full_node_integration_test.go @@ -14,6 +14,7 @@ import ( "github.com/stretchr/testify/assert" abci "github.com/cometbft/cometbft/abci/types" + "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/libs/log" "github.com/cometbft/cometbft/proxy" cmtypes "github.com/cometbft/cometbft/types" @@ -639,7 +640,17 @@ func createNode(ctx context.Context, n int, aggregator bool, isLight bool, keys ctx = context.Background() } - genesisValidators, signingKey := types.GetGenesisValidatorSetWithSigner() + pubkeyBytes, err := keys[0].GetPublic().Raw() + require.NoError(err) + var pubkey ed25519.PubKey = pubkeyBytes + genesisValidators := []cmtypes.GenesisValidator{ + { + Address: pubkey.Address(), + PubKey: pubkey, + Power: int64(1), + Name: "sequencer", + }, + } genesis := &cmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators} // TODO: need to investigate why this needs to be done for light nodes genesis.InitialHeight = 1 @@ -653,7 +664,7 @@ func createNode(ctx context.Context, n int, aggregator bool, isLight bool, keys Light: isLight, }, keys[n], - signingKey, + keys[n], proxy.NewLocalClientCreator(app), genesis, test.NewFileLoggerCustom(t, test.TempLogFileName(t, fmt.Sprintf("node%v", n))).With("node", n)) From 398a712a4288fb67bc1f2e9ada59eb6d36bf77db Mon Sep 17 00:00:00 2001 From: Connor O'Hara Date: Wed, 29 Nov 2023 20:02:33 -0500 Subject: [PATCH 13/13] call verify. --- block/manager.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/manager.go b/block/manager.go index 9683aa1a97..1fdc6f490e 100644 --- a/block/manager.go +++ b/block/manager.go @@ -354,6 +354,10 @@ func (m *Manager) trySyncNextBlock(ctx context.Context, daHeight uint64) error { var commit *types.Commit currentHeight := m.store.Height() // TODO(tzdybal): maybe store a copy in memory + lastBlock, ok := m.blockCache.getBlock(currentHeight) + if !ok { + return nil + } b, ok := m.blockCache.getBlock(currentHeight + 1) if !ok { return nil @@ -365,6 +369,10 @@ func (m *Manager) trySyncNextBlock(ctx context.Context, daHeight uint64) error { } if b != nil && commit != nil { + err := lastBlock.SignedHeader.Verify(&b.SignedHeader) + if err != nil { + return fmt.Errorf("failed to validate block: %w", err) + } bHeight := uint64(b.Height()) m.logger.Info("Syncing block", "height", bHeight) // Validate the received block before applying