Skip to content

Commit

Permalink
eth: explicitly commented the code were bor could get into snap-sync …
Browse files Browse the repository at this point in the history
…mode (#1243)

* eth: explicitly commented the code were bor could get into snap-sync mode

* addressed comment
  • Loading branch information
pratikspatil024 authored May 9, 2024
1 parent 8fc2a95 commit 902c1ce
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 43 deletions.
4 changes: 3 additions & 1 deletion eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
72 changes: 30 additions & 42 deletions eth/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 902c1ce

Please sign in to comment.