diff --git a/internal/blocksync/reactor.go b/internal/blocksync/reactor.go index e7aef05f4..60b334fab 100644 --- a/internal/blocksync/reactor.go +++ b/internal/blocksync/reactor.go @@ -188,7 +188,7 @@ func (r *Reactor) respondToPeer(ctx context.Context, msg *bcproto.BlockRequest, if block != nil { extCommit := r.store.LoadBlockExtendedCommit(msg.Height) if extCommit == nil { - return fmt.Errorf("blockstore has block but not extended commit (block: %v)", block) + return fmt.Errorf("found block in store without extended commit: %v", block) } blockProto, err := block.ToProto() if err != nil { @@ -465,7 +465,7 @@ func (r *Reactor) poolRoutine(ctx context.Context, stateSynced bool, blockSyncCh switch { //case state.LastBlockHeight > 0 && r.store.LoadBlockExtCommit(state.LastBlockHeight) == nil: case state.LastBlockHeight > 0 && blocksSynced == 0: - //If we have state-synced, we need to blocksync at least one block + // Having state-synced, we need to blocksync at least one block r.logger.Info( "no seen commit yet", "height", height, diff --git a/internal/evidence/pool_test.go b/internal/evidence/pool_test.go index d6a5631e6..35766a9e6 100644 --- a/internal/evidence/pool_test.go +++ b/internal/evidence/pool_test.go @@ -589,7 +589,6 @@ func initializeBlockStore(db dbm.DB, state sm.State, valAddr []byte) (*store.Blo func makeExtCommit(height int64, valAddr []byte) *types.ExtendedCommit { return &types.ExtendedCommit{ Height: height, - BlockID: types.BlockID{}, ExtendedSignatures: []types.ExtendedCommitSig{{ CommitSig: types.CommitSig{ BlockIDFlag: types.BlockIDFlagCommit, diff --git a/internal/state/execution.go b/internal/state/execution.go index b9e81da21..2ca2be6ad 100644 --- a/internal/state/execution.go +++ b/internal/state/execution.go @@ -414,11 +414,13 @@ func buildLastCommitInfo(block *types.Block, store Store, initialHeight int64) a } } -// buildLastExtendedCommitInfo expects an ExtendedCommitInfo, which includes -// the original precommit votes along with their vote extensions from the last -// commit. It populates the corresponding ABCI protobuf structures using the -// validator set obtained from the store at the height of the last extended -// commit. +// buildLastExtendedCommitInfo populates an ABCI extended commit from the +// corresponding Tendermint extended commit ec, using the stored validator set from +// ec. It requires ec to include the original precommit votes along +// with the vote extensions from the last commit. +// +// For heights below the initial height, for which we do not have the +// required data, it returns an empty record. func buildLastExtendedCommitInfo(ec *types.ExtendedCommit, store Store, initialHeight int64) abci.ExtendedCommitInfo { // We assume the current height is ec.Height + 1. if ec.Height < initialHeight { diff --git a/internal/state/execution_test.go b/internal/state/execution_test.go index 62c2725ec..ffe9cb6f8 100644 --- a/internal/state/execution_test.go +++ b/internal/state/execution_test.go @@ -328,11 +328,10 @@ func TestProcessProposal(t *testing.T) { lastCommitSig = append(lastCommitSig, vote.CommitSig()) } - lastCommit := &types.Commit{ + block1 := sf.MakeBlock(state, height, &types.Commit{ Height: height - 1, Signatures: lastCommitSig, - } - block1 := sf.MakeBlock(state, height, lastCommit) + }) block1.Txs = txs expectedRpp := &abci.RequestProcessProposal{ diff --git a/internal/store/store.go b/internal/store/store.go index b88e24e2b..5617674a2 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -273,16 +273,16 @@ func (bs *BlockStore) LoadBlockCommit(height int64) *types.Commit { } commit, err := types.CommitFromProto(pbc) if err != nil { - panic(fmt.Errorf("error from proto block commit: %w", err)) + panic(fmt.Errorf("converting commit to proto: %w", err)) } return commit } func (bs *BlockStore) LoadBlockExtendedCommit(height int64) *types.ExtendedCommit { - var pbec = new(tmproto.ExtendedCommit) + pbec := new(tmproto.ExtendedCommit) bz, err := bs.db.Get(extCommitKey(height)) if err != nil { - panic(err) + panic(fmt.Errorf("fetching extended commit: %w", err)) } if len(bz) == 0 { return nil diff --git a/internal/store/store_test.go b/internal/store/store_test.go index c40288186..9df3eed9f 100644 --- a/internal/store/store_test.go +++ b/internal/store/store_test.go @@ -310,7 +310,7 @@ func TestLoadBlockPart(t *testing.T) { require.NoError(t, err) bs, db := newInMemoryBlockStore() - height, index := int64(10), 1 + const height, index = 10, 1 loadPart := func() (interface{}, error) { part := bs.LoadBlockPart(height, index) return part, nil diff --git a/types/block.go b/types/block.go index 2e3b67e37..4a87db59a 100644 --- a/types/block.go +++ b/types/block.go @@ -1074,9 +1074,7 @@ func (ec *ExtendedCommit) Type() byte { return byte(tmproto.PrecommitType) } // GetHeight returns height of the extended commit. // Implements VoteSetReader. -func (ec *ExtendedCommit) GetHeight() int64 { - return ec.Height -} +func (ec *ExtendedCommit) GetHeight() int64 { return ec.Height } // GetRound returns height of the extended commit. // Implements VoteSetReader. @@ -1175,9 +1173,7 @@ func ExtendedCommitFromProto(ecp *tmproto.ExtendedCommit) (*ExtendedCommit, erro return nil, errors.New("nil ExtendedCommit") } - var ( - extCommit = new(ExtendedCommit) - ) + extCommit := new(ExtendedCommit) bi, err := BlockIDFromProto(&ecp.BlockID) if err != nil { @@ -1191,7 +1187,6 @@ func ExtendedCommitFromProto(ecp *tmproto.ExtendedCommit) (*ExtendedCommit, erro } } extCommit.ExtendedSignatures = sigs - extCommit.Height = ecp.Height extCommit.Round = ecp.Round extCommit.BlockID = *bi