Browse Source

createProposalBlock explicit returns

pull/8094/head
William Banfield 3 years ago
parent
commit
a843d8bf28
No known key found for this signature in database GPG Key ID: EFAD3442BF29E3AC
1 changed files with 4 additions and 9 deletions
  1. +4
    -9
      internal/consensus/state.go

+ 4
- 9
internal/consensus/state.go View File

@ -1293,8 +1293,7 @@ func (cs *State) defaultDecideProposal(ctx context.Context, height int64, round
if err != nil { if err != nil {
cs.logger.Error("unable to create proposal block", "error", err) cs.logger.Error("unable to create proposal block", "error", err)
return return
}
if block == nil {
} else if block == nil {
return return
} }
blockParts, err = block.MakePartSet(types.BlockPartSizeBytes) blockParts, err = block.MakePartSet(types.BlockPartSizeBytes)
@ -1351,10 +1350,6 @@ func (cs *State) isProposalComplete() bool {
} }
// TODO: createProposalBlock should not naked return
// It has two cases that appear to be error cases, but nothing is returned during
// these cases.
// Create the next block to propose and return it. Returns nil block upon error. // Create the next block to propose and return it. Returns nil block upon error.
// //
// We really only need to return the parts, but the block is returned for // We really only need to return the parts, but the block is returned for
@ -1362,7 +1357,7 @@ func (cs *State) isProposalComplete() bool {
// //
// NOTE: keep it side-effect free for clarity. // NOTE: keep it side-effect free for clarity.
// CONTRACT: cs.privValidator is not nil. // CONTRACT: cs.privValidator is not nil.
func (cs *State) createProposalBlock(ctx context.Context) (block *types.Block, err error) {
func (cs *State) createProposalBlock(ctx context.Context) (*types.Block, error) {
if cs.privValidator == nil { if cs.privValidator == nil {
return nil, errors.New("entered createProposalBlock with privValidator being nil") return nil, errors.New("entered createProposalBlock with privValidator being nil")
} }
@ -1380,14 +1375,14 @@ func (cs *State) createProposalBlock(ctx context.Context) (block *types.Block, e
default: // This shouldn't happen. default: // This shouldn't happen.
cs.logger.Error("propose step; cannot propose anything without commit for the previous block") cs.logger.Error("propose step; cannot propose anything without commit for the previous block")
return
return nil, nil
} }
if cs.privValidatorPubKey == nil { if cs.privValidatorPubKey == nil {
// If this node is a validator & proposer in the current round, it will // If this node is a validator & proposer in the current round, it will
// miss the opportunity to create a block. // miss the opportunity to create a block.
cs.logger.Error("propose step; empty priv validator public key", "err", errPubKeyIsNotSet) cs.logger.Error("propose step; empty priv validator public key", "err", errPubKeyIsNotSet)
return
return nil, nil
} }
proposerAddr := cs.privValidatorPubKey.Address() proposerAddr := cs.privValidatorPubKey.Address()


Loading…
Cancel
Save