From ecaf84368b36f9f87322e80f19091fc3233adf01 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Fri, 13 May 2022 17:30:45 -0400 Subject: [PATCH] use helper methods in prepareproposal --- internal/state/execution.go | 17 ++++++----------- types/block.go | 6 ++++-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/internal/state/execution.go b/internal/state/execution.go index b7aa23b33..68de931db 100644 --- a/internal/state/execution.go +++ b/internal/state/execution.go @@ -108,7 +108,7 @@ func (blockExec *BlockExecutor) CreateProposalBlock( &abci.RequestPrepareProposal{ MaxTxBytes: maxDataBytes, Txs: block.Txs.ToSliceOfBytes(), - LocalLastCommit: buildExtendedCommitInfo(lastExtCommit, blockExec.store, state.InitialHeight, state.ConsensusParams.Vote.ExtensionRequireHeight), + LocalLastCommit: buildExtendedCommitInfo(lastExtCommit, blockExec.store, state.InitialHeight, state.ConsensusParams.Vote), ByzantineValidators: block.Evidence.ToABCI(), Height: block.Height, Time: block.Time, @@ -428,7 +428,7 @@ func buildLastCommitInfo(block *types.Block, store Store, initialHeight int64) a // data, it returns an empty record. // // Assumes that the commit signatures are sorted according to validator index. -func buildExtendedCommitInfo(ec *types.ExtendedCommit, store Store, initialHeight, extensionRequireHeight int64) abci.ExtendedCommitInfo { +func buildExtendedCommitInfo(ec *types.ExtendedCommit, store Store, initialHeight int64, vp types.VoteParams) abci.ExtendedCommitInfo { if ec.Height < initialHeight { // There are no extended commits for heights below the initial height. return abci.ExtendedCommitInfo{} @@ -466,17 +466,12 @@ func buildExtendedCommitInfo(ec *types.ExtendedCommit, store Store, initialHeigh } var ext []byte - if ecs.BlockIDFlag == types.BlockIDFlagCommit { - // We only care about vote extensions if a validator has voted to - // commit. - if ecs.Extension == nil && ecs.ExtensionSignature == nil && - extensionRequireHeight != 0 && ec.Height >= extensionRequireHeight { - // TODO: this error is akward, make it better - panic(fmt.Errorf("commit received with missing vote extension data")) - } - ext = ecs.Extension + if err := ecs.EnsureExtension(); err != nil && vp.RequireExtensions(ec.Height) { + panic(fmt.Errorf("commit at height %d received with missing vote extensions data", ec.Height)) } + ext = ecs.Extension + votes[i] = abci.ExtendedVoteInfo{ Validator: types.TM2PB.Validator(val), SignedLastBlock: ecs.BlockIDFlag != types.BlockIDFlagAbsent, diff --git a/types/block.go b/types/block.go index dfb6e1ed5..cf3e047ca 100644 --- a/types/block.go +++ b/types/block.go @@ -772,8 +772,10 @@ func (ecs ExtendedCommitSig) ValidateBasic() error { // EnsureExtensions validates that a vote extensions signature is present for // this ExtendedCommitSig. func (ecs ExtendedCommitSig) EnsureExtension() error { - if len(ecs.ExtensionSignature) == 0 { - return errors.New("vote extension signature is missing") + if ecs.BlockIDFlag == BlockIDFlagCommit { + if len(ecs.ExtensionSignature) == 0 { + return errors.New("vote extension signature is missing") + } } return nil }