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

hotfix for handling slow sync of Bali #577

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 10 additions & 2 deletions eth/stagedsync/stage_finish.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/ledgerwatch/erigon/ethdb/cbor"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/turbo/engineapi"
"math"
)

type FinishCfg struct {
Expand Down Expand Up @@ -134,22 +135,29 @@ func NotifyNewHeaders(ctx context.Context, finishStageBeforeSync uint64, finishS
// Notify all headers we have (either canonical or not) in a maximum range span of 1024
var notifyFrom uint64
var isUnwind bool
var heightSpan uint64
if unwindTo != nil && *unwindTo != 0 && (*unwindTo) < finishStageBeforeSync {
notifyFrom = *unwindTo
isUnwind = true
} else {
heightSpan := finishStageAfterSync - finishStageBeforeSync
heightSpan = finishStageAfterSync - finishStageBeforeSync
if heightSpan > 1024 {
heightSpan = 1024
}
notifyFrom = finishStageAfterSync - heightSpan

// check if the height span is greater than the max uint32 value and cap it there if it is
if heightSpan > math.MaxUint32 {
heightSpan = math.MaxUint32
}
}
notifyFrom++

var notifyTo = notifyFrom
var notifyToHash libcommon.Hash
var headersRlp [][]byte
if err := tx.ForEach(kv.Headers, hexutility.EncodeTs(notifyFrom), func(k, headerRLP []byte) error {

if err := tx.ForAmount(kv.Headers, hexutility.EncodeTs(notifyFrom), uint32(heightSpan), func(k, headerRLP []byte) error {
if len(headerRLP) == 0 {
return nil
}
Expand Down
12 changes: 9 additions & 3 deletions zk/stages/stage_batches.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ func SpawnStageBatches(
return fmt.Errorf("failed to get stage exec progress, %w", err)
}

// just exit the stage early if there is more execution work to do
if stageExecProgress < lastBlockHeight {
log.Info(fmt.Sprintf("[%s] Execution behind, skipping stage", logPrefix))
return nil
}

lastHash := emptyHash
atLeastOneBlockWritten := false
startTime := time.Now()
Expand Down Expand Up @@ -359,9 +365,9 @@ LOOP:
log.Warn(fmt.Sprintf("[%s] Context done", logPrefix))
endLoop = true
default:
// wait at least one block to be written, before continuing
// or if stage_exec is ahead - don't wait here, but rather continue so exec catches up
if atLeastOneBlockWritten || stageExecProgress < lastBlockHeight {
if atLeastOneBlockWritten {
// first check to see if anything has come in from the stream yet, if it has then wait a little longer
// because there could be more.
// if no blocks available should and time since last block written is > 500ms
// consider that we are at the tip and blocks come in the datastream as they are produced
// stop the current iteration of the stage
Expand Down
Loading