mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
eth, cli: prevent snap sync mode migration - v0.3.x (#494)
* handle snap sync mode switches * fix linters
This commit is contained in:
parent
0b28230c22
commit
2aacbde097
4 changed files with 47 additions and 19 deletions
|
|
@ -1620,6 +1620,13 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
||||||
|
|
||||||
if ctx.GlobalIsSet(SyncModeFlag.Name) {
|
if ctx.GlobalIsSet(SyncModeFlag.Name) {
|
||||||
cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)
|
cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)
|
||||||
|
|
||||||
|
// To be extra preventive, we won't allow the node to start
|
||||||
|
// in snap sync mode until we have it working
|
||||||
|
// TODO(snap): Comment when we have snap sync working
|
||||||
|
if cfg.SyncMode == downloader.SnapSync {
|
||||||
|
cfg.SyncMode = downloader.FullSync
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ctx.GlobalIsSet(NetworkIdFlag.Name) {
|
if ctx.GlobalIsSet(NetworkIdFlag.Name) {
|
||||||
cfg.NetworkId = ctx.GlobalUint64(NetworkIdFlag.Name)
|
cfg.NetworkId = ctx.GlobalUint64(NetworkIdFlag.Name)
|
||||||
|
|
|
||||||
|
|
@ -161,8 +161,15 @@ func newHandler(config *handlerConfig) (*handler, error) {
|
||||||
// In these cases however it's safe to reenable snap sync.
|
// In these cases however it's safe to reenable snap sync.
|
||||||
fullBlock, fastBlock := h.chain.CurrentBlock(), h.chain.CurrentFastBlock()
|
fullBlock, fastBlock := h.chain.CurrentBlock(), h.chain.CurrentFastBlock()
|
||||||
if fullBlock.NumberU64() == 0 && fastBlock.NumberU64() > 0 {
|
if fullBlock.NumberU64() == 0 && fastBlock.NumberU64() > 0 {
|
||||||
h.snapSync = uint32(1)
|
// Note: Ideally this should never happen with bor, but to be extra
|
||||||
log.Warn("Switch sync mode from full sync to snap sync")
|
// preventive we won't allow it to roll over to snap sync until
|
||||||
|
// we have it working
|
||||||
|
|
||||||
|
// TODO(snap): Uncomment when we have snap sync working
|
||||||
|
// h.snapSync = uint32(1)
|
||||||
|
// log.Warn("Switch sync mode from full sync to snap sync")
|
||||||
|
|
||||||
|
log.Warn("Preventing switching sync mode from full sync to snap sync")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if h.chain.CurrentBlock().NumberU64() > 0 {
|
if h.chain.CurrentBlock().NumberU64() > 0 {
|
||||||
|
|
|
||||||
43
eth/sync.go
43
eth/sync.go
|
|
@ -204,25 +204,36 @@ func peerToSyncOp(mode downloader.SyncMode, p *eth.Peer) *chainSyncOp {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *chainSyncer) modeAndLocalHead() (downloader.SyncMode, *big.Int) {
|
func (cs *chainSyncer) modeAndLocalHead() (downloader.SyncMode, *big.Int) {
|
||||||
// If we're in snap sync mode, return that directly
|
// Note: Ideally this should never happen with bor, but to be extra
|
||||||
if atomic.LoadUint32(&cs.handler.snapSync) == 1 {
|
// preventive we won't allow it to roll over to snap sync until
|
||||||
block := cs.handler.chain.CurrentFastBlock()
|
// we have it working
|
||||||
td := cs.handler.chain.GetTd(block.Hash(), block.NumberU64())
|
|
||||||
return downloader.SnapSync, td
|
// Handle full sync mode only
|
||||||
}
|
|
||||||
// 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()
|
head := cs.handler.chain.CurrentBlock()
|
||||||
td := cs.handler.chain.GetTd(head.Hash(), head.NumberU64())
|
td := cs.handler.chain.GetTd(head.Hash(), head.NumberU64())
|
||||||
return downloader.FullSync, td
|
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.
|
// startSync launches doSync in a new goroutine.
|
||||||
|
|
|
||||||
|
|
@ -843,7 +843,10 @@ func (c *Config) buildEth(stack *node.Node, accountManager *accounts.Manager) (*
|
||||||
case "full":
|
case "full":
|
||||||
n.SyncMode = downloader.FullSync
|
n.SyncMode = downloader.FullSync
|
||||||
case "snap":
|
case "snap":
|
||||||
n.SyncMode = downloader.SnapSync
|
// n.SyncMode = downloader.SnapSync // TODO(snap): Uncomment when we have snap sync working
|
||||||
|
n.SyncMode = downloader.FullSync
|
||||||
|
|
||||||
|
log.Warn("Bor doesn't support Snap Sync yet, switching to Full Sync mode")
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("sync mode '%s' not found", c.SyncMode)
|
return nil, fmt.Errorf("sync mode '%s' not found", c.SyncMode)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue