From 902c1ce97edd428a8f8ee0e35d24b3bff60f5415 Mon Sep 17 00:00:00 2001 From: Pratik Patil Date: Thu, 9 May 2024 08:42:55 +0530 Subject: [PATCH] eth: explicitly commented the code were bor could get into snap-sync mode (#1243) * eth: explicitly commented the code were bor could get into snap-sync mode * addressed comment --- eth/handler.go | 4 ++- eth/sync.go | 72 +++++++++++++++++++++----------------------------- 2 files changed, 33 insertions(+), 43 deletions(-) diff --git a/eth/handler.go b/eth/handler.go index 8804921918..bbc3cf18a4 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -178,7 +178,9 @@ func newHandler(config *handlerConfig) (*handler, error) { h.snapSync.Store(true) log.Warn("Switch sync mode from full sync to snap sync", "reason", "snap sync incomplete") } else if !h.chain.HasState(fullBlock.Root) { - h.snapSync.Store(true) + // TODO - uncomment when we (Polygon-PoS, bor) have snap sync/pbss + // For more info - https://github.com/ethereum/go-ethereum/pull/28171 + // h.snapSync.Store(true) log.Warn("Switch sync mode from full sync to snap sync", "reason", "head state missing") } } else { diff --git a/eth/sync.go b/eth/sync.go index 4fffa5e288..44c0ff6d38 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -200,59 +200,47 @@ func peerToSyncOp(mode downloader.SyncMode, p *eth.Peer) *chainSyncOp { } func (cs *chainSyncer) modeAndLocalHead() (downloader.SyncMode, *big.Int) { - // If we're in snap sync mode, return that directly - if cs.handler.snapSync.Load() { - block := cs.handler.chain.CurrentSnapBlock() - td := cs.handler.chain.GetTd(block.Hash(), block.Number.Uint64()) - return downloader.SnapSync, td - } + // TODO - uncomment when we (Polygon-PoS, bor) have snap sync/pbss + /* + // If we're in snap sync mode, return that directly + if cs.handler.snapSync.Load() { + block := cs.handler.chain.CurrentSnapBlock() + td := cs.handler.chain.GetTd(block.Hash(), block.Number.Uint64()) + return downloader.SnapSync, td + } + */ + // We are probably in full sync, but we might have rewound to before the // snap sync pivot, check if we should re-enable snap sync. head := cs.handler.chain.CurrentBlock() - if pivot := rawdb.ReadLastPivotNumber(cs.handler.database); pivot != nil { - if head.Number.Uint64() < *pivot { + // TODO - uncomment when we (Polygon-PoS, bor) have snap sync/pbss + /* + if pivot := rawdb.ReadLastPivotNumber(cs.handler.database); pivot != nil { + if head.Number.Uint64() < *pivot { + block := cs.handler.chain.CurrentSnapBlock() + td := cs.handler.chain.GetTd(block.Hash(), block.Number.Uint64()) + return downloader.SnapSync, td + } + } + */ + + // TODO - uncomment when we (Polygon-PoS, bor) have snap sync/pbss + // For more info - https://github.com/ethereum/go-ethereum/pull/28171 + /* + // We are in a full sync, but the associated head state is missing. To complete + // the head state, forcefully rerun the snap sync. Note it doesn't mean the + // persistent state is corrupted, just mismatch with the head block. + if !cs.handler.chain.HasState(head.Root) { block := cs.handler.chain.CurrentSnapBlock() td := cs.handler.chain.GetTd(block.Hash(), block.Number.Uint64()) + log.Info("Reenabled snap sync as chain is stateless") return downloader.SnapSync, td } - } - // We are in a full sync, but the associated head state is missing. To complete - // the head state, forcefully rerun the snap sync. Note it doesn't mean the - // persistent state is corrupted, just mismatch with the head block. - if !cs.handler.chain.HasState(head.Root) { - block := cs.handler.chain.CurrentSnapBlock() - td := cs.handler.chain.GetTd(block.Hash(), block.Number.Uint64()) - log.Info("Reenabled snap sync as chain is stateless") - return downloader.SnapSync, td - } + */ // Nope, we're really full syncing td := cs.handler.chain.GetTd(head.Hash(), head.Number.Uint64()) return downloader.FullSync, td - // TODO(snap): Uncomment when we have snap sync working - // If we're in snap sync mode, return that directly - // - // if atomic.LoadUint32(&cs.handler.snapSync) == 1 { - // block := cs.handler.chain.CurrentFastBlock() - // td := cs.handler.chain.GetTd(block.Hash(), block.NumberU64()) - // return downloader.SnapSync, td - // } - // - // // We are probably in full sync, but we might have rewound to before the - // // snap sync pivot, check if we should reenable - // - // if pivot := rawdb.ReadLastPivotNumber(cs.handler.database); pivot != nil { - // if head := cs.handler.chain.CurrentBlock(); head.NumberU64() < *pivot { - // block := cs.handler.chain.CurrentFastBlock() - // td := cs.handler.chain.GetTd(block.Hash(), block.NumberU64()) - // return downloader.SnapSync, td - // } - // } - // - // // Nope, we're really full syncing - // head := cs.handler.chain.CurrentBlock() - // td := cs.handler.chain.GetTd(head.Hash(), head.NumberU64()) - // return downloader.FullSync, td } // startSync launches doSync in a new goroutine.