Skip to content

Commit

Permalink
feat: wait miner finish the later multi-proposals when restarting;
Browse files Browse the repository at this point in the history
  • Loading branch information
galaio committed Jan 7, 2025
1 parent 35d9b04 commit 3b843c8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
6 changes: 1 addition & 5 deletions consensus/parlia/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,8 @@ func (s *Snapshot) nexValidatorsChangeBlock() uint64 {
// nextProposalBlock returns the validator next proposal block.
func (s *Snapshot) nextProposalBlock(proposer common.Address) (uint64, uint64, error) {
validators := s.validators()
currentProposer := validators[s.Number/uint64(s.TurnLength)%uint64(len(validators))]
currentIndex := s.indexOfVal(currentProposer)
currentIndex := int(s.Number / uint64(s.TurnLength) % uint64(len(validators)))
expectIndex := s.indexOfVal(proposer)
if currentIndex < 0 {
return 0, 0, errors.New("currentProposer not in validator set")
}
if expectIndex < 0 {
return 0, 0, errors.New("proposer not in validator set")
}
Expand Down
6 changes: 2 additions & 4 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ func (w *worker) tryWaitProposalDoneWhenStopping() {
currentBlock := currentHeader.Number.Uint64()
startBlock, endBlock, err := posa.NextProposalBlock(w.chain, currentHeader, w.coinbase)
if err != nil {
log.Warn("Failed to get next proposal block", "err", err)
log.Warn("Failed to get next proposal block, skip waiting", "err", err)
return
}

Expand All @@ -1534,7 +1534,7 @@ func (w *worker) tryWaitProposalDoneWhenStopping() {
return
}

// wait a more block for safety
// wait one more block for safety
waitSecs := (endBlock - currentBlock + 1) * posa.BlockInterval()
log.Info("The miner will propose in later, waiting for the proposal to be done",
"currentBlock", currentBlock, "nextProposalStart", startBlock, "nextProposalEnd", endBlock, "waitTime", waitSecs)
Expand Down Expand Up @@ -1571,5 +1571,3 @@ func signalToErr(signal int32) error {
panic(fmt.Errorf("undefined signal %d", signal))
}
}

// signalToErr converts the interruption signal to a concrete error type for return.

0 comments on commit 3b843c8

Please sign in to comment.