@ -30,6 +30,7 @@ import (
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state/snapshot"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/protocols/snap"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
@ -69,6 +70,17 @@ var (
errNoPivotHeader = errors . New ( "pivot header is not found" )
)
// SyncMode defines the sync method of the downloader.
// Deprecated: use ethconfig.SyncMode instead
type SyncMode = ethconfig . SyncMode
const (
// Deprecated: use ethconfig.FullSync
FullSync = ethconfig . FullSync
// Deprecated: use ethconfig.SnapSync
SnapSync = ethconfig . SnapSync
)
// peerDropFn is a callback type for dropping a peer detected as malicious.
type peerDropFn func ( id string )
@ -230,9 +242,9 @@ func (d *Downloader) Progress() ethereum.SyncProgress {
current := uint64 ( 0 )
mode := d . getMode ( )
switch mode {
case FullSync :
case ethconfig . FullSync :
current = d . blockchain . CurrentBlock ( ) . Number . Uint64 ( )
case SnapSync :
case ethconfig . SnapSync :
current = d . blockchain . CurrentSnapBlock ( ) . Number . Uint64 ( )
default :
log . Error ( "Unknown downloader mode" , "mode" , mode )
@ -326,7 +338,7 @@ func (d *Downloader) synchronise(mode SyncMode, beaconPing chan struct{}) error
if d . notified . CompareAndSwap ( false , true ) {
log . Info ( "Block synchronisation started" )
}
if mode == SnapSync {
if mode == ethconfig . SnapSync {
// Snap sync will directly modify the persistent state, making the entire
// trie database unusable until the state is fully synced. To prevent any
// subsequent state reads, explicitly disable the trie database and state
@ -434,7 +446,7 @@ func (d *Downloader) syncToHead() (err error) {
// 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.
if mode == SnapSync && pivot == nil {
if mode == ethconfig . SnapSync && pivot == nil {
pivot = d . blockchain . CurrentBlock ( )
}
height := latest . Number . Uint64 ( )
@ -452,7 +464,7 @@ func (d *Downloader) syncToHead() (err error) {
d . syncStatsLock . Unlock ( )
// Ensure our origin point is below any snap sync pivot point
if mode == SnapSync {
if mode == ethconfig . SnapSync {
if height <= uint64 ( fsMinFullBlocks ) {
origin = 0
} else {
@ -466,10 +478,10 @@ func (d *Downloader) syncToHead() (err error) {
}
}
d . committed . Store ( true )
if mode == SnapSync && pivot . Number . Uint64 ( ) != 0 {
if mode == ethconfig . SnapSync && pivot . Number . Uint64 ( ) != 0 {
d . committed . Store ( false )
}
if mode == SnapSync {
if mode == ethconfig . SnapSync {
// Set the ancient data limitation. If we are running snap sync, all block
// data older than ancientLimit will be written to the ancient store. More
// recent data will be written to the active database and will wait for the
@ -523,13 +535,13 @@ func (d *Downloader) syncToHead() (err error) {
func ( ) error { return d . fetchReceipts ( origin + 1 ) } , // Receipts are retrieved during snap sync
func ( ) error { return d . processHeaders ( origin + 1 ) } ,
}
if mode == SnapSync {
if mode == ethconfig . SnapSync {
d . pivotLock . Lock ( )
d . pivotHeader = pivot
d . pivotLock . Unlock ( )
fetchers = append ( fetchers , func ( ) error { return d . processSnapSyncContent ( ) } )
} else if mode == FullSync {
} else if mode == ethconfig . FullSync {
fetchers = append ( fetchers , func ( ) error { return d . processFullSyncContent ( ) } )
}
return d . spawnSync ( fetchers )
@ -676,7 +688,7 @@ func (d *Downloader) processHeaders(origin uint64) error {
chunkHashes := hashes [ : limit ]
// In case of header only syncing, validate the chunk immediately
if mode == SnapSync {
if mode == ethconfig . SnapSync {
// Although the received headers might be all valid, a legacy
// PoW/PoA sync must not accept post-merge headers. Make sure
// that any transition is rejected at this point.