cmd, eth: implement full-sync tester (#26035)

This PR adds a parameter to startup, --synctarget. The synctarget flag is a developer-flag, that can be useful in some scenarios as a replacement for a CL node. It defines a fixed block sync target:

geth --syncmode=full --synctarget=./block_15816882.hex_rlp 

The --synctarget is only made available during syncmode=full
This commit is contained in:
rjl493456442
2022-10-28 14:48:08 +02:00
committed by GitHub
parent 0f4942214d
commit 2c1af8b1ec
5 changed files with 150 additions and 0 deletions
+1
View File
@@ -86,6 +86,7 @@ var (
utils.TxPoolGlobalQueueFlag,
utils.TxPoolLifetimeFlag,
utils.SyncModeFlag,
utils.SyncTargetFlag,
utils.ExitWhenSyncedFlag,
utils.GCModeFlag,
utils.SnapshotFlag,
+37
View File
@@ -18,6 +18,7 @@
package utils
import (
"bytes"
"context"
"crypto/ecdsa"
"errors"
@@ -36,10 +37,12 @@ import (
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/fdlimit"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
@@ -68,6 +71,7 @@ import (
"github.com/ethereum/go-ethereum/p2p/nat"
"github.com/ethereum/go-ethereum/p2p/netutil"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
pcsclite "github.com/gballet/go-libpcsclite"
gopsutil "github.com/shirou/gopsutil/mem"
@@ -664,11 +668,18 @@ var (
Category: flags.LoggingCategory,
}
// MISC settings
IgnoreLegacyReceiptsFlag = &cli.BoolFlag{
Name: "ignore-legacy-receipts",
Usage: "Geth will start up even if there are legacy receipts in freezer",
Category: flags.MiscCategory,
}
SyncTargetFlag = &cli.PathFlag{
Name: "synctarget",
Usage: `File for containing the hex-encoded block-rlp as sync target(dev feature)`,
TakesFile: true,
Category: flags.MiscCategory,
}
// RPC settings
IPCDisabledFlag = &cli.BoolFlag{
@@ -1874,6 +1885,25 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
cfg.EthDiscoveryURLs = SplitAndTrim(urls)
}
}
if ctx.IsSet(SyncTargetFlag.Name) {
path := ctx.Path(SyncTargetFlag.Name)
if path == "" {
Fatalf("Failed to resolve file path")
}
blob, err := os.ReadFile(path)
if err != nil {
Fatalf("Failed to read block file: %v", err)
}
rlpBlob, err := hexutil.Decode(string(bytes.TrimRight(blob, "\r\n")))
if err != nil {
Fatalf("Failed to decode block blob: %v", err)
}
var block types.Block
if err := rlp.DecodeBytes(rlpBlob, &block); err != nil {
Fatalf("Failed to decode block: %v", err)
}
cfg.SyncTarget = &block
}
// Override any default configs for hard coded networks.
switch {
case ctx.Bool(MainnetFlag.Name):
@@ -2027,6 +2057,13 @@ func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) (ethapi.Backend
Fatalf("Failed to register the Engine API service: %v", err)
}
stack.RegisterAPIs(tracers.APIs(backend.APIBackend))
// Register the auxiliary full-sync tester service in case the sync
// target is configured.
if cfg.SyncTarget != nil && cfg.SyncMode == downloader.FullSync {
ethcatalyst.RegisterFullSyncTester(stack, backend, cfg.SyncTarget)
log.Info("Registered full-sync tester", "number", cfg.SyncTarget.NumberU64(), "hash", cfg.SyncTarget.Hash())
}
return backend.APIBackend, backend
}