Skip to content

Commit

Permalink
add check for non-nil in entercommit; Log proposer address when corre…
Browse files Browse the repository at this point in the history
…ctly accepting a proposal (#20)
  • Loading branch information
teddyding authored Sep 6, 2023
1 parent c72272c commit ad47306
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ func (cs *State) enterNewRound(height int64, round int32) {
logger.Debug("need to set a buffer and log message here for sanity", "start_time", cs.StartTime, "now", now)
}

logger.Debug("entering new round", "current", log.NewLazySprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step))
prevHeight, prevRound, prevStep := cs.Height, cs.Round, cs.Step

// increment validators if necessary
validators := cs.Validators
Expand All @@ -1010,17 +1010,21 @@ func (cs *State) enterNewRound(height int64, round int32) {
// but we fire an event, so update the round step first
cs.updateRoundStep(round, cstypes.RoundStepNewRound)
cs.Validators = validators
if round == 0 {
// We've already reset these upon new height,
// and meanwhile we might have received a proposal
// for round 0.
} else {
logger.Debug("resetting proposal info")
// If round == 0, we've already reset these upon new height, and meanwhile
// we might have received a proposal for round 0.
propAddress := validators.GetProposer().PubKey.Address()
if round != 0 {
logger.Info("resetting proposal info", "proposer", propAddress)
cs.Proposal = nil
cs.ProposalBlock = nil
cs.ProposalBlockParts = nil
}

logger.Debug("entering new round",
"previous", log.NewLazySprintf("%v/%v/%v", prevHeight, prevRound, prevStep),
"proposer", propAddress,
)

cs.Votes.SetRound(cmtmath.SafeAddInt32(round, 1)) // also track next round (round+1) to allow round-skipping
cs.TriggeredTimeoutPrecommit = false

Expand Down Expand Up @@ -1579,7 +1583,7 @@ func (cs *State) enterCommit(height int64, commitRound int32) {
}()

blockID, ok := cs.Votes.Precommits(commitRound).TwoThirdsMajority()
if !ok {
if !ok || blockID.IsNil() {
panic("RunActionCommit() expects +2/3 precommits")
}

Expand Down Expand Up @@ -1904,7 +1908,8 @@ func (cs *State) defaultSetProposal(proposal *types.Proposal) error {

p := proposal.ToProto()
// Verify signature
if !cs.Validators.GetProposer().PubKey.VerifySignature(
pubKey := cs.Validators.GetProposer().PubKey
if !pubKey.VerifySignature(
types.ProposalSignBytes(cs.state.ChainID, p), proposal.Signature,
) {
return ErrInvalidProposalSignature
Expand All @@ -1919,7 +1924,7 @@ func (cs *State) defaultSetProposal(proposal *types.Proposal) error {
cs.ProposalBlockParts = types.NewPartSetFromHeader(proposal.BlockID.PartSetHeader)
}

cs.Logger.Info("received proposal", "proposal", proposal)
cs.Logger.Info("received proposal", "proposal", proposal, "proposer", pubKey.Address())
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (blockExec *BlockExecutor) ApplyBlock(
return state, 0, err
}
if len(validatorUpdates) > 0 {
blockExec.logger.Debug("updates to validators", "updates", types.ValidatorListString(validatorUpdates))
blockExec.logger.Info("updates to validators", "updates", types.ValidatorListString(validatorUpdates))
blockExec.metrics.ValidatorSetUpdates.Add(1)
}
if abciResponses.EndBlock.ConsensusParamUpdates != nil {
Expand Down

0 comments on commit ad47306

Please sign in to comment.