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

thor/node: improve pack loop #346

Merged
merged 1 commit into from Mar 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 15 additions & 21 deletions cmd/thor/node/packer_loop.go
Expand Up @@ -66,30 +66,24 @@ func (n *Node) packerLoop(ctx context.Context) {
}
log.Debug("scheduled to pack block", "after", time.Duration(flow.When()-now)*time.Second)

const halfBlockInterval = thor.BlockInterval / 2

for {
now := uint64(time.Now().Unix())
if flow.When() > now+halfBlockInterval {
delaySec := flow.When() - (now + halfBlockInterval)
select {
case <-ctx.Done():
return
case <-ticker.C():
if n.repo.BestBlock().Header().TotalScore() > flow.TotalScore() {
log.Debug("re-schedule packer due to new best block")
goto RE_SCHEDULE
}
case <-time.After(time.Duration(delaySec) * time.Second):
goto PACK
if uint64(time.Now().Unix())+thor.BlockInterval/2 > flow.When() {
// time to pack block
// blockInterval/2 early to allow more time for processing txs
if err := n.pack(flow); err != nil {
log.Error("failed to pack block", "err", err)
}
break
}
select {
case <-ctx.Done():
return
case <-time.After(time.Second):
if n.repo.BestBlock().Header().TotalScore() > flow.TotalScore() {
log.Debug("re-schedule packer due to new best block")
goto RE_SCHEDULE
}
} else {
goto PACK
}
}
PACK:
if err := n.pack(flow); err != nil {
log.Error("failed to pack block", "err", err)
}
RE_SCHEDULE:
}
Expand Down