Skip to content

Commit 4e7f06d

Browse files
rjl493456442howjmay
authored andcommitted
eth/downloader: fix ancient limit in snap sync (ethereum#32188)
This pull request fixes an issue in disabling direct-ancient mode in snap sync. Specifically, if `origin >= frozen && origin != 0`, it implies a part of chain data has been written into the key-value store, all the following writes into ancient store scheduled by downloader will be rejected with error `ERROR[07-10|03:46:57.924] Error importing chain data to ancients err="can't add block 1166 hash: the append operation is out-order: have 1166 want 0"`. This issue is detected by the https://github.com/ethpandaops/kurtosis-sync-test, which initiates the first snap sync cycle without the finalized header and implicitly disables the direct-ancient mode. A few seconds later the second snap sync cycle is initiated with the finalized information and direct-ancient mode is enabled incorrectly.
1 parent e48ab5a commit 4e7f06d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

eth/downloader/downloader.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,15 @@ func (d *Downloader) syncToHead() (err error) {
535535

536536
// If a part of blockchain data has already been written into active store,
537537
// disable the ancient style insertion explicitly.
538-
if origin >= frozen && frozen != 0 {
538+
if origin >= frozen && origin != 0 {
539539
d.ancientLimit = 0
540-
log.Info("Disabling direct-ancient mode", "origin", origin, "ancient", frozen-1)
540+
var ancient string
541+
if frozen == 0 {
542+
ancient = "null"
543+
} else {
544+
ancient = fmt.Sprintf("%d", frozen-1)
545+
}
546+
log.Info("Disabling direct-ancient mode", "origin", origin, "ancient", ancient)
541547
} else if d.ancientLimit > 0 {
542548
log.Debug("Enabling direct-ancient mode", "ancient", d.ancientLimit)
543549
}

0 commit comments

Comments
 (0)