core, eth: split eth package, implement snap protocol (#21482)
This commit splits the eth package, separating the handling of eth and snap protocols. It also includes the capability to run snap sync (https://github.com/ethereum/devp2p/blob/master/caps/snap.md) , but does not enable it by default. Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de> Co-authored-by: Martin Holst Swende <martin@swende.se>
This commit is contained in:
@ -187,7 +187,7 @@ var (
|
||||
defaultSyncMode = eth.DefaultConfig.SyncMode
|
||||
SyncModeFlag = TextMarshalerFlag{
|
||||
Name: "syncmode",
|
||||
Usage: `Blockchain sync mode ("fast", "full", or "light")`,
|
||||
Usage: `Blockchain sync mode ("fast", "full", "snap" or "light")`,
|
||||
Value: &defaultSyncMode,
|
||||
}
|
||||
GCModeFlag = cli.StringFlag{
|
||||
@ -1555,8 +1555,14 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
||||
cfg.SnapshotCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheSnapshotFlag.Name) / 100
|
||||
}
|
||||
if !ctx.GlobalIsSet(SnapshotFlag.Name) {
|
||||
cfg.TrieCleanCache += cfg.SnapshotCache
|
||||
cfg.SnapshotCache = 0 // Disabled
|
||||
// If snap-sync is requested, this flag is also required
|
||||
if cfg.SyncMode == downloader.SnapSync {
|
||||
log.Info("Snap sync requested, enabling --snapshot")
|
||||
ctx.Set(SnapshotFlag.Name, "true")
|
||||
} else {
|
||||
cfg.TrieCleanCache += cfg.SnapshotCache
|
||||
cfg.SnapshotCache = 0 // Disabled
|
||||
}
|
||||
}
|
||||
if ctx.GlobalIsSet(DocRootFlag.Name) {
|
||||
cfg.DocRoot = ctx.GlobalString(DocRootFlag.Name)
|
||||
@ -1585,16 +1591,15 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
||||
cfg.RPCTxFeeCap = ctx.GlobalFloat64(RPCGlobalTxFeeCapFlag.Name)
|
||||
}
|
||||
if ctx.GlobalIsSet(NoDiscoverFlag.Name) {
|
||||
cfg.DiscoveryURLs = []string{}
|
||||
cfg.EthDiscoveryURLs, cfg.SnapDiscoveryURLs = []string{}, []string{}
|
||||
} else if ctx.GlobalIsSet(DNSDiscoveryFlag.Name) {
|
||||
urls := ctx.GlobalString(DNSDiscoveryFlag.Name)
|
||||
if urls == "" {
|
||||
cfg.DiscoveryURLs = []string{}
|
||||
cfg.EthDiscoveryURLs = []string{}
|
||||
} else {
|
||||
cfg.DiscoveryURLs = SplitAndTrim(urls)
|
||||
cfg.EthDiscoveryURLs = SplitAndTrim(urls)
|
||||
}
|
||||
}
|
||||
|
||||
// Override any default configs for hard coded networks.
|
||||
switch {
|
||||
case ctx.GlobalBool(LegacyTestnetFlag.Name) || ctx.GlobalBool(RopstenFlag.Name):
|
||||
@ -1676,16 +1681,20 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
||||
// SetDNSDiscoveryDefaults configures DNS discovery with the given URL if
|
||||
// no URLs are set.
|
||||
func SetDNSDiscoveryDefaults(cfg *eth.Config, genesis common.Hash) {
|
||||
if cfg.DiscoveryURLs != nil {
|
||||
if cfg.EthDiscoveryURLs != nil {
|
||||
return // already set through flags/config
|
||||
}
|
||||
|
||||
protocol := "all"
|
||||
if cfg.SyncMode == downloader.LightSync {
|
||||
protocol = "les"
|
||||
}
|
||||
if url := params.KnownDNSNetwork(genesis, protocol); url != "" {
|
||||
cfg.DiscoveryURLs = []string{url}
|
||||
cfg.EthDiscoveryURLs = []string{url}
|
||||
}
|
||||
if cfg.SyncMode == downloader.SnapSync {
|
||||
if url := params.KnownDNSNetwork(genesis, "snap"); url != "" {
|
||||
cfg.SnapDiscoveryURLs = []string{url}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user