Apply suggestions from code review

Co-authored-by: M. J. Fromberger <fromberger@interchain.io>
This commit is contained in:
Thane Thomson
2022-05-09 06:32:53 -04:00
committed by GitHub
parent 9483b42f0b
commit b1896ebca6
7 changed files with 17 additions and 22 deletions

View File

@@ -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,

View File

@@ -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,

View File

@@ -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 {

View File

@@ -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{

View File

@@ -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

View File

@@ -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

View File

@@ -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