Enter: `timeoutPrevote` after any +2/3 prevotes. Enter: `timeoutPrecommit` after any +2/3 precommits. Enter: +2/3 precomits for block or nil. Lock & precommit the ProposalBlock if we have enough prevotes for it (a POL in this round) else, unlock an existing lock and precommit nil if +2/3 of prevotes
(height int64, round int32)
| 1320 | // else, unlock an existing lock and precommit nil if +2/3 of prevotes were nil, |
| 1321 | // else, precommit nil otherwise. |
| 1322 | func (cs *State) enterPrecommit(height int64, round int32) { |
| 1323 | logger := cs.Logger.With("height", height, "round", round) |
| 1324 | |
| 1325 | if cs.Height != height || round < cs.Round || (cs.Round == round && cstypes.RoundStepPrecommit <= cs.Step) { |
| 1326 | logger.Debug( |
| 1327 | "entering precommit step with invalid args", |
| 1328 | "current", log.NewLazySprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step), |
| 1329 | ) |
| 1330 | return |
| 1331 | } |
| 1332 | |
| 1333 | logger.Debug("entering precommit step", "current", log.NewLazySprintf("%v/%v/%v", cs.Height, cs.Round, cs.Step)) |
| 1334 | |
| 1335 | defer func() { |
| 1336 | // Done enterPrecommit: |
| 1337 | cs.updateRoundStep(round, cstypes.RoundStepPrecommit) |
| 1338 | cs.newStep() |
| 1339 | }() |
| 1340 | |
| 1341 | // check for a polka |
| 1342 | blockID, ok := cs.Votes.Prevotes(round).TwoThirdsMajority() |
| 1343 | |
| 1344 | // If we don't have a polka, we must precommit nil. |
| 1345 | if !ok { |
| 1346 | if cs.LockedBlock != nil { |
| 1347 | logger.Debug("precommit step; no +2/3 prevotes during enterPrecommit while we are locked; precommitting nil") |
| 1348 | } else { |
| 1349 | logger.Debug("precommit step; no +2/3 prevotes during enterPrecommit; precommitting nil") |
| 1350 | } |
| 1351 | |
| 1352 | cs.signAddVote(tmproto.PrecommitType, nil, types.PartSetHeader{}) |
| 1353 | return |
| 1354 | } |
| 1355 | |
| 1356 | // At this point +2/3 prevoted for a particular block or nil. |
| 1357 | if err := cs.eventBus.PublishEventPolka(cs.RoundStateEvent()); err != nil { |
| 1358 | logger.Error("failed publishing polka", "err", err) |
| 1359 | } |
| 1360 | |
| 1361 | // the latest POLRound should be this round. |
| 1362 | polRound, _ := cs.Votes.POLInfo() |
| 1363 | if polRound < round { |
| 1364 | panic(fmt.Sprintf("this POLRound should be %v but got %v", round, polRound)) |
| 1365 | } |
| 1366 | |
| 1367 | // +2/3 prevoted nil. Unlock and precommit nil. |
| 1368 | if len(blockID.Hash) == 0 { |
| 1369 | if cs.LockedBlock == nil { |
| 1370 | logger.Debug("precommit step; +2/3 prevoted for nil") |
| 1371 | } else { |
| 1372 | logger.Debug("precommit step; +2/3 prevoted for nil; unlocking") |
| 1373 | cs.LockedRound = -1 |
| 1374 | cs.LockedBlock = nil |
| 1375 | cs.LockedBlockParts = nil |
| 1376 | |
| 1377 | if err := cs.eventBus.PublishEventUnlock(cs.RoundStateEvent()); err != nil { |
| 1378 | logger.Error("failed publishing event unlock", "err", err) |
| 1379 | } |
no test coverage detected