diff options
Diffstat (limited to 'eth/handler.go')
-rw-r--r-- | eth/handler.go | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/eth/handler.go b/eth/handler.go index 58add2eaf..7d2000386 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -121,9 +121,28 @@ func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, ne txsyncCh: make(chan *txsync), quitSync: make(chan struct{}), } - // If fast sync was requested and our database is empty, grant it - if mode == downloader.FastSync && blockchain.CurrentBlock().NumberU64() == 0 { - manager.fastSync = uint32(1) + if mode == downloader.FullSync { + // The database seems empty as the current block is the genesis. Yet the fast + // block is ahead, so fast sync was enabled for this node at a certain point. + // The scenarios where this can happen is + // * if the user manually (or via a bad block) rolled back a fast sync node + // below the sync point. + // * the last fast sync is not finished while user specifies a full sync this + // time. But we don't have any recent state for full sync. + // In these cases however it's safe to reenable fast sync. + fullBlock, fastBlock := blockchain.CurrentBlock(), blockchain.CurrentFastBlock() + if fullBlock.NumberU64() == 0 && fastBlock.NumberU64() > 0 { + manager.fastSync = uint32(1) + log.Warn("Switch sync mode from full sync to fast sync") + } + } else { + if blockchain.CurrentBlock().NumberU64() > 0 { + // Print warning log if database is not empty to run fast sync. + log.Warn("Switch sync mode from fast sync to full sync") + } else { + // If fast sync was requested and our database is empty, grant it + manager.fastSync = uint32(1) + } } // If we have trusted checkpoints, enforce them on the chain if checkpoint, ok := params.TrustedCheckpoints[blockchain.Genesis().Hash()]; ok { |