mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
eth, internal/cli: allow bor to run in snap sync (#1532)
This PR enables snap sync download mechanism. It allows users to use it as sync mode via setting the flag `syncmode` to `snap`. Snap sync instead of executing every block, downloads the state and chain from the p2p network trusting the peer(s) it's downloading from.
This commit is contained in:
parent
adad83d6ac
commit
f0d4401c51
6 changed files with 33 additions and 49 deletions
|
|
@ -13,7 +13,7 @@ ancient = "" # Data directory for ancient chain segments (def
|
||||||
keystore = "" # Path of the directory where keystores are located
|
keystore = "" # Path of the directory where keystores are located
|
||||||
"rpc.batchlimit" = 100 # Maximum number of messages in a batch (default=100, use 0 for no limits)
|
"rpc.batchlimit" = 100 # Maximum number of messages in a batch (default=100, use 0 for no limits)
|
||||||
"rpc.returndatalimit" = 100000 # Maximum size (in bytes) a result of an rpc request could have (default=100000, use 0 for no limits)
|
"rpc.returndatalimit" = 100000 # Maximum size (in bytes) a result of an rpc request could have (default=100000, use 0 for no limits)
|
||||||
syncmode = "full" # Blockchain sync mode (only "full" sync supported)
|
syncmode = "full" # Blockchain sync mode ("full" or "snap")
|
||||||
gcmode = "full" # Blockchain garbage collection mode ("full", "archive")
|
gcmode = "full" # Blockchain garbage collection mode ("full", "archive")
|
||||||
snapshot = true # Enables the snapshot-database mode
|
snapshot = true # Enables the snapshot-database mode
|
||||||
"bor.logs" = false # Enables bor log retrieval
|
"bor.logs" = false # Enables bor log retrieval
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ The ```bor server``` command runs the Bor client.
|
||||||
|
|
||||||
- ```state.scheme```: Scheme to use for storing ethereum state ('hash' or 'path') (default: path)
|
- ```state.scheme```: Scheme to use for storing ethereum state ('hash' or 'path') (default: path)
|
||||||
|
|
||||||
- ```syncmode```: Blockchain sync mode (only "full" sync supported) (default: full)
|
- ```syncmode```: Blockchain sync mode ("full" or "snap") (default: full)
|
||||||
|
|
||||||
- ```verbosity```: Logging verbosity for the server (5=trace|4=debug|3=info|2=warn|1=error|0=crit) (default: 3)
|
- ```verbosity```: Logging verbosity for the server (5=trace|4=debug|3=info|2=warn|1=error|0=crit) (default: 3)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -175,19 +175,14 @@ func newHandler(config *handlerConfig) (*handler, error) {
|
||||||
// * the last snap sync is not finished while user specifies a full sync this
|
// * the last snap sync is not finished while user specifies a full sync this
|
||||||
// time. But we don't have any recent state for full sync.
|
// time. But we don't have any recent state for full sync.
|
||||||
// In these cases however it's safe to reenable snap sync.
|
// In these cases however it's safe to reenable snap sync.
|
||||||
|
fullBlock, snapBlock := h.chain.CurrentBlock(), h.chain.CurrentSnapBlock()
|
||||||
// TODO - uncomment when we (Polygon-PoS, bor) have snap sync/pbss
|
if fullBlock.Number.Uint64() == 0 && snapBlock.Number.Uint64() > 0 {
|
||||||
// fullBlock, snapBlock := h.chain.CurrentBlock(), h.chain.CurrentSnapBlock()
|
h.snapSync.Store(true)
|
||||||
|
log.Warn("Switch sync mode from full sync to snap sync", "reason", "snap sync incomplete")
|
||||||
// TODO - uncomment when we (Polygon-PoS, bor) have snap sync/pbss
|
} else if !h.chain.HasState(fullBlock.Root) {
|
||||||
// For more info - https://github.com/ethereum/go-ethereum/pull/28171
|
h.snapSync.Store(true)
|
||||||
// if fullBlock.Number.Uint64() == 0 && snapBlock.Number.Uint64() > 0 {
|
log.Warn("Switch sync mode from full sync to snap sync", "reason", "head state missing")
|
||||||
// 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)
|
|
||||||
// log.Warn("Switch sync mode from full sync to snap sync", "reason", "head state missing")
|
|
||||||
// }
|
|
||||||
} else {
|
} else {
|
||||||
head := h.chain.CurrentBlock()
|
head := h.chain.CurrentBlock()
|
||||||
if head.Number.Uint64() > 0 && h.chain.HasState(head.Root) {
|
if head.Number.Uint64() > 0 && h.chain.HasState(head.Root) {
|
||||||
|
|
|
||||||
50
eth/sync.go
50
eth/sync.go
|
|
@ -201,43 +201,35 @@ 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) {
|
||||||
// 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() {
|
||||||
// If we're in snap sync mode, return that directly
|
block := cs.handler.chain.CurrentSnapBlock()
|
||||||
if cs.handler.snapSync.Load() {
|
td := cs.handler.chain.GetTd(block.Hash(), block.Number.Uint64())
|
||||||
block := cs.handler.chain.CurrentSnapBlock()
|
return downloader.SnapSync, td
|
||||||
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
|
// 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.
|
// snap sync pivot, check if we should re-enable snap sync.
|
||||||
head := cs.handler.chain.CurrentBlock()
|
head := cs.handler.chain.CurrentBlock()
|
||||||
// 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 {
|
||||||
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()
|
block := cs.handler.chain.CurrentSnapBlock()
|
||||||
td := cs.handler.chain.GetTd(block.Hash(), block.Number.Uint64())
|
td := cs.handler.chain.GetTd(block.Hash(), block.Number.Uint64())
|
||||||
log.Info("Reenabled snap sync as chain is stateless")
|
|
||||||
return downloader.SnapSync, td
|
return downloader.SnapSync, td
|
||||||
}
|
}
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
// Nope, we're really full syncing
|
// Nope, we're really full syncing
|
||||||
td := cs.handler.chain.GetTd(head.Hash(), head.Number.Uint64())
|
td := cs.handler.chain.GetTd(head.Hash(), head.Number.Uint64())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1161,10 +1161,7 @@ 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 // TODO(snap): Uncomment when we have snap sync working
|
n.SyncMode = downloader.SnapSync
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ func (c *Command) Flags(config *Config) *flagset.Flagset {
|
||||||
})
|
})
|
||||||
f.StringFlag(&flagset.StringFlag{
|
f.StringFlag(&flagset.StringFlag{
|
||||||
Name: "syncmode",
|
Name: "syncmode",
|
||||||
Usage: `Blockchain sync mode (only "full" sync supported)`,
|
Usage: `Blockchain sync mode ("full" or "snap")`,
|
||||||
Value: &c.cliConfig.SyncMode,
|
Value: &c.cliConfig.SyncMode,
|
||||||
Default: c.cliConfig.SyncMode,
|
Default: c.cliConfig.SyncMode,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue