Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wait miner finish the later multi-proposals when restarting the node; #2845

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion consensus/parlia/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,13 @@ func (s *Snapshot) nextProposalBlock(proposer common.Address) (uint64, uint64, e
currentProposer := validators[s.Number/uint64(s.TurnLength)%uint64(len(validators))]
currentIndex := s.indexOfVal(currentProposer)
expectIndex := s.indexOfVal(proposer)
if currentIndex < 0 {
galaio marked this conversation as resolved.
Show resolved Hide resolved
return 0, 0, errors.New("currentProposer not in validator set")
}
if expectIndex < 0 {
return 0, 0, errors.New("proposer not in validator set")
}
startBlock := uint64((expectIndex+len(validators)-currentIndex)%len(validators)*int(s.TurnLength)) + s.Number
startBlock := s.Number + uint64(((expectIndex+len(validators)-currentIndex)%len(validators))*int(s.TurnLength))
startBlock = startBlock - startBlock%uint64(s.TurnLength)
endBlock := startBlock + uint64(s.TurnLength) - 1

Expand Down
4 changes: 2 additions & 2 deletions miner/minerconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Config struct {
GasPrice *big.Int // Minimum gas price for mining a transaction
Recommit time.Duration // The time interval for miner to re-create mining work.
VoteEnable bool // Whether to vote when mining
MaxWaitProposalInSecs uint64 // The maximum time to wait for the proposal to be done, it's aimed to prevent validator slashed when restarting
MaxWaitProposalInSecs uint64 // The maximum time to wait for the proposal to be done, it's aimed to prevent validator being slashed when restarting

DisableVoteAttestation bool // Whether to skip assembling vote attestation

Expand All @@ -56,7 +56,7 @@ var DefaultConfig = Config{
DelayLeftOver: 50 * time.Millisecond,

// The default value is set to 30 seconds.
// Because the avg restart time in mainnet is around 30s, so the node try to wait for next proposal done.
// Because the avg restart time in mainnet is around 30s, so the node try to wait for the next multi-proposals to be done.
MaxWaitProposalInSecs: 30,

Mev: DefaultMevConfig,
Expand Down
15 changes: 8 additions & 7 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1516,24 +1516,25 @@ func (w *worker) tryWaitProposalDoneWhenStopping() {
}

currentHeader := w.chain.CurrentBlock()
startBlock, endBlock, err := posa.NextProposalBlock(w.chain, w.chain.CurrentBlock(), w.coinbase)
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)
return
}
log.Info("Checking miner's next proposal block", "current", currentBlock,
"proposalStart", startBlock, "proposalEnd", endBlock, "maxWait", w.config.MaxWaitProposalInSecs)

currentBlock := currentHeader.Number.Uint64()
if endBlock < currentBlock {
log.Warn("next proposal end block has passed, ignore")
return
}
waitSecs := (endBlock - currentBlock) * posa.BlockInterval()
Copy link
Collaborator

@buddh0 buddh0 Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: endBlock - currentBlock?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can wait more time to avoid shutdown immediately after miner producing the end block for safety, maybe another 10 second?

if waitSecs > 0 && waitSecs <= w.config.MaxWaitProposalInSecs {
galaio marked this conversation as resolved.
Show resolved Hide resolved
log.Info("The miner will propose in later, waiting for the proposal to be done",
"currentBlock", currentBlock, "nextProposalStart", startBlock, "nextProposalEnd", endBlock, "waitTime", waitSecs)
time.Sleep(time.Duration(waitSecs) * time.Second)
}
if startBlock <= currentBlock && currentBlock < endBlock {
log.Info("The miner is proposing, waiting for the proposal to be done",
"currentBlock", currentBlock, "nextProposalStart", startBlock, "nextProposalEnd", endBlock, "waitTime", waitSecs)
time.Sleep(time.Duration(waitSecs) * time.Second)
}
}

// copyReceipts makes a deep copy of the given receipts.
Expand Down