-
Notifications
You must be signed in to change notification settings - Fork 21.6k
eth/downloader: retrieve pivot header from local chain if necessary #24610
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
Changes from 2 commits
91ed02e
8f8cba6
b1b5690
8d651cd
b59d235
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,6 +158,9 @@ type LightChain interface { | |
| // GetHeaderByHash retrieves a header from the local chain. | ||
| GetHeaderByHash(common.Hash) *types.Header | ||
|
|
||
| // GetHeaderByNumber retrieves a block header from the local chain by number. | ||
| GetHeaderByNumber(number uint64) *types.Header | ||
|
|
||
| // CurrentHeader retrieves the head header from the local chain. | ||
| CurrentHeader() *types.Header | ||
|
|
||
|
|
@@ -477,15 +480,22 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td, ttd * | |
| return err | ||
| } | ||
| if latest.Number.Uint64() > uint64(fsMinFullBlocks) { | ||
| pivot = d.skeleton.Header(latest.Number.Uint64() - uint64(fsMinFullBlocks)) | ||
| number := latest.Number.Uint64() - uint64(fsMinFullBlocks) | ||
| pivot = d.skeleton.Header(number) | ||
| if pivot == nil { | ||
| // Retrieve the pivot point from the local chain if it's | ||
| // not in the range of skeleton. | ||
| pivot = d.lightchain.GetHeaderByNumber(number) | ||
| } | ||
| } | ||
| } | ||
| // If no pivot block was returned, the head is below the min full block | ||
| // threshold (i.e. new chain). In that case we won't really snap sync | ||
| // anyway, but still need a valid pivot block to avoid some code hitting | ||
| // nil panics on access. | ||
| var syncState = true // means whether state sync is required in this cycle | ||
| if mode == SnapSync && pivot == nil { | ||
| pivot = d.blockchain.CurrentBlock().Header() | ||
| pivot, syncState = d.blockchain.CurrentBlock().Header(), false | ||
|
||
| } | ||
| height := latest.Number.Uint64() | ||
|
|
||
|
|
@@ -516,7 +526,9 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td, ttd * | |
| origin = 0 | ||
| } else { | ||
| pivotNumber := pivot.Number.Uint64() | ||
| if pivotNumber <= origin { | ||
|
|
||
| // Cap the sync origin by pivot header when state sync is required. | ||
| if pivotNumber <= origin && syncState { | ||
| origin = pivotNumber - 1 | ||
| } | ||
| // Write out the pivot into the database so a rollback beyond it will | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.