diff --git a/cl/clparams/config.go b/cl/clparams/config.go index 43100bc9a2e..4bb9050690f 100644 --- a/cl/clparams/config.go +++ b/cl/clparams/config.go @@ -1056,19 +1056,19 @@ func GetConfigsByNetwork(net NetworkType) (*NetworkConfig, *BeaconChainConfig) { func GetConfigsByNetworkName(net string) (*NetworkConfig, *BeaconChainConfig, NetworkType, error) { switch net { - case networkname.MainnetChainName: + case networkname.Mainnet: networkCfg, beaconCfg := GetConfigsByNetwork(MainnetNetwork) return networkCfg, beaconCfg, MainnetNetwork, nil - case networkname.SepoliaChainName: + case networkname.Sepolia: networkCfg, beaconCfg := GetConfigsByNetwork(SepoliaNetwork) return networkCfg, beaconCfg, SepoliaNetwork, nil - case networkname.GnosisChainName: + case networkname.Gnosis: networkCfg, beaconCfg := GetConfigsByNetwork(GnosisNetwork) return networkCfg, beaconCfg, GnosisNetwork, nil - case networkname.ChiadoChainName: + case networkname.Chiado: networkCfg, beaconCfg := GetConfigsByNetwork(ChiadoNetwork) return networkCfg, beaconCfg, ChiadoNetwork, nil - case networkname.HoleskyChainName: + case networkname.Holesky: networkCfg, beaconCfg := GetConfigsByNetwork(HoleskyNetwork) return networkCfg, beaconCfg, HoleskyNetwork, nil default: diff --git a/cmd/devnet/args/node_args.go b/cmd/devnet/args/node_args.go index a0dc0e2cc05..e667142f981 100644 --- a/cmd/devnet/args/node_args.go +++ b/cmd/devnet/args/node_args.go @@ -167,7 +167,7 @@ func (m *BlockProducer) Configure(baseNode NodeArgs, nodeNumber int) error { } switch m.Chain { - case networkname.DevChainName: + case networkname.Dev: if m.DevPeriod == 0 { m.DevPeriod = 30 } @@ -175,7 +175,7 @@ func (m *BlockProducer) Configure(baseNode NodeArgs, nodeNumber int) error { core.DevnetEtherbase = m.account.Address core.DevnetSignPrivateKey = m.account.SigKey() - case networkname.BorDevnetChainName: + case networkname.BorDevnet: m.account = accounts.NewAccount(m.GetName() + "-etherbase") if len(m.HttpApi) == 0 { diff --git a/cmd/devnet/contracts/steps/l1l2transfers.go b/cmd/devnet/contracts/steps/l1l2transfers.go index 08b0ffd0416..53ae2b163de 100644 --- a/cmd/devnet/contracts/steps/l1l2transfers.go +++ b/cmd/devnet/contracts/steps/l1l2transfers.go @@ -52,7 +52,7 @@ func init() { func GenerateSyncEvents(ctx context.Context, senderName string, numberOfTransfers int, minTransfer int, maxTransfer int) error { sender := accounts.GetAccount(senderName) - ctx = devnet.WithCurrentNetwork(ctx, networkname.DevChainName) + ctx = devnet.WithCurrentNetwork(ctx, networkname.Dev) auth, err := contracts.TransactOpts(ctx, sender.Address) @@ -170,7 +170,7 @@ func GenerateSyncEvents(ctx context.Context, senderName string, numberOfTransfer func DeployRootChainSender(ctx context.Context, deployerName string) (context.Context, error) { deployer := accounts.GetAccount(deployerName) - ctx = devnet.WithCurrentNetwork(ctx, networkname.DevChainName) + ctx = devnet.WithCurrentNetwork(ctx, networkname.Dev) auth, backend, err := contracts.DeploymentTransactor(ctx, deployer.Address) @@ -197,7 +197,7 @@ func DeployRootChainSender(ctx context.Context, deployerName string) (context.Co return nil, err } - devnet.Logger(ctx).Info("RootSender deployed", "chain", networkname.DevChainName, "block", block.Number, "addr", address) + devnet.Logger(ctx).Info("RootSender deployed", "chain", networkname.Dev, "block", block.Number, "addr", address) return scenarios.WithParam(ctx, "rootSenderAddress", address). WithParam("rootSender", contract), nil @@ -205,7 +205,7 @@ func DeployRootChainSender(ctx context.Context, deployerName string) (context.Co func DeployChildChainReceiver(ctx context.Context, deployerName string) (context.Context, error) { deployer := accounts.GetAccount(deployerName) - ctx = devnet.WithCurrentNetwork(ctx, networkname.BorDevnetChainName) + ctx = devnet.WithCurrentNetwork(ctx, networkname.BorDevnet) waiter, cancel := blocks.BlockWaiter(ctx, contracts.DeploymentChecker) defer cancel() @@ -222,7 +222,7 @@ func DeployChildChainReceiver(ctx context.Context, deployerName string) (context return nil, err } - devnet.Logger(ctx).Info("ChildReceiver deployed", "chain", networkname.BorDevnetChainName, "block", block.Number, "addr", address) + devnet.Logger(ctx).Info("ChildReceiver deployed", "chain", networkname.BorDevnet, "block", block.Number, "addr", address) return scenarios.WithParam(ctx, "childReceiverAddress", address). WithParam("childReceiver", contract), nil @@ -230,7 +230,7 @@ func DeployChildChainReceiver(ctx context.Context, deployerName string) (context func ProcessRootTransfers(ctx context.Context, sourceName string, numberOfTransfers int, minTransfer int, maxTransfer int) error { source := accounts.GetAccount(sourceName) - ctx = devnet.WithCurrentNetwork(ctx, networkname.DevChainName) + ctx = devnet.WithCurrentNetwork(ctx, networkname.Dev) auth, err := contracts.TransactOpts(ctx, source.Address) @@ -380,7 +380,7 @@ func ProcessRootTransfers(ctx context.Context, sourceName string, numberOfTransf func BatchProcessRootTransfers(ctx context.Context, sourceName string, batches int, transfersPerBatch, minTransfer int, maxTransfer int) error { source := accounts.GetAccount(sourceName) - ctx = devnet.WithCurrentNetwork(ctx, networkname.DevChainName) + ctx = devnet.WithCurrentNetwork(ctx, networkname.Dev) auth, err := contracts.TransactOpts(ctx, source.Address) diff --git a/cmd/devnet/contracts/steps/l2l1transfers.go b/cmd/devnet/contracts/steps/l2l1transfers.go index 35174fcc98d..fc9091c7699 100644 --- a/cmd/devnet/contracts/steps/l2l1transfers.go +++ b/cmd/devnet/contracts/steps/l2l1transfers.go @@ -47,7 +47,7 @@ func init() { func DeployChildChainSender(ctx context.Context, deployerName string) (context.Context, error) { deployer := accounts.GetAccount(deployerName) - ctx = devnet.WithCurrentNetwork(ctx, networkname.BorDevnetChainName) + ctx = devnet.WithCurrentNetwork(ctx, networkname.BorDevnet) auth, backend, err := contracts.DeploymentTransactor(ctx, deployer.Address) @@ -72,7 +72,7 @@ func DeployChildChainSender(ctx context.Context, deployerName string) (context.C return nil, err } - devnet.Logger(ctx).Info("ChildSender deployed", "chain", networkname.BorDevnetChainName, "block", block.Number, "addr", address) + devnet.Logger(ctx).Info("ChildSender deployed", "chain", networkname.BorDevnet, "block", block.Number, "addr", address) return scenarios.WithParam(ctx, "childSenderAddress", address). WithParam("childSender", contract), nil @@ -80,7 +80,7 @@ func DeployChildChainSender(ctx context.Context, deployerName string) (context.C func DeployRootChainReceiver(ctx context.Context, deployerName string) (context.Context, error) { deployer := accounts.GetAccount(deployerName) - ctx = devnet.WithCurrentNetwork(ctx, networkname.DevChainName) + ctx = devnet.WithCurrentNetwork(ctx, networkname.Dev) auth, backend, err := contracts.DeploymentTransactor(ctx, deployer.Address) @@ -105,7 +105,7 @@ func DeployRootChainReceiver(ctx context.Context, deployerName string) (context. return nil, err } - devnet.Logger(ctx).Info("RootReceiver deployed", "chain", networkname.BorDevnetChainName, "block", block.Number, "addr", address) + devnet.Logger(ctx).Info("RootReceiver deployed", "chain", networkname.BorDevnet, "block", block.Number, "addr", address) return scenarios.WithParam(ctx, "rootReceiverAddress", address). WithParam("rootReceiver", contract), nil @@ -113,7 +113,7 @@ func DeployRootChainReceiver(ctx context.Context, deployerName string) (context. func ProcessChildTransfers(ctx context.Context, sourceName string, numberOfTransfers int, minTransfer int, maxTransfer int) error { source := accounts.GetAccount(sourceName) - ctx = devnet.WithCurrentNetwork(ctx, networkname.DevChainName) + ctx = devnet.WithCurrentNetwork(ctx, networkname.Dev) auth, err := contracts.TransactOpts(ctx, source.Address) diff --git a/cmd/devnet/devnet/node.go b/cmd/devnet/devnet/node.go index c5835a73e9d..c2f929bbba2 100644 --- a/cmd/devnet/devnet/node.go +++ b/cmd/devnet/devnet/node.go @@ -176,7 +176,11 @@ func (n *devnetNode) run(ctx *cli.Context) error { logger.Info("Build info", "git_branch", params.GitBranch, "git_tag", params.GitTag, "git_commit", params.GitCommit) - n.nodeCfg = enode.NewNodConfigUrfave(ctx, logger) + nodeConf, err := enode.NewNodConfigUrfave(ctx, logger) + if err != nil { + return err + } + n.nodeCfg = nodeConf n.ethCfg = enode.NewEthConfigUrfave(ctx, n.nodeCfg, logger) // These are set to prevent disk and page size churn which can be excessive diff --git a/cmd/devnet/main.go b/cmd/devnet/main.go index 765366d914f..9ceb6857b8c 100644 --- a/cmd/devnet/main.go +++ b/cmd/devnet/main.go @@ -61,7 +61,7 @@ var ( ChainFlag = cli.StringFlag{ Name: "chain", Usage: "The devnet chain to run (dev,bor-devnet)", - Value: networkname.DevChainName, + Value: networkname.Dev, } ScenariosFlag = cli.StringFlag{ @@ -332,8 +332,8 @@ func allScenarios(cliCtx *cli.Context, runCtx devnet.Context) scenarios.Scenario "state-sync": { Steps: []*scenarios.Step{ {Text: "InitSubscriptions", Args: []any{[]requests.SubMethod{requests.Methods.ETHNewHeads}}}, - {Text: "CreateAccountWithFunds", Args: []any{networkname.DevChainName, "root-funder", 200.0}}, - {Text: "CreateAccountWithFunds", Args: []any{networkname.BorDevnetChainName, "child-funder", 200.0}}, + {Text: "CreateAccountWithFunds", Args: []any{networkname.Dev, "root-funder", 200.0}}, + {Text: "CreateAccountWithFunds", Args: []any{networkname.BorDevnet, "child-funder", 200.0}}, {Text: "DeployChildChainReceiver", Args: []any{"child-funder"}}, {Text: "DeployRootChainSender", Args: []any{"root-funder"}}, {Text: "GenerateSyncEvents", Args: []any{"root-funder", 10, 2, 2}}, @@ -343,8 +343,8 @@ func allScenarios(cliCtx *cli.Context, runCtx devnet.Context) scenarios.Scenario }, "child-chain-exit": { Steps: []*scenarios.Step{ - {Text: "CreateAccountWithFunds", Args: []any{networkname.DevChainName, "root-funder", 200.0}}, - {Text: "CreateAccountWithFunds", Args: []any{networkname.BorDevnetChainName, "child-funder", 200.0}}, + {Text: "CreateAccountWithFunds", Args: []any{networkname.Dev, "root-funder", 200.0}}, + {Text: "CreateAccountWithFunds", Args: []any{networkname.BorDevnet, "child-funder", 200.0}}, {Text: "DeployRootChainReceiver", Args: []any{"root-funder"}}, {Text: "DeployChildChainSender", Args: []any{"child-funder"}}, {Text: "ProcessChildTransfers", Args: []any{"child-funder", 1, 2, 2}}, @@ -420,7 +420,7 @@ func initDevnet(ctx *cli.Context, logger log.Logger) (devnet.Devnet, error) { } switch chainName { - case networkname.BorDevnetChainName: + case networkname.BorDevnet: if ctx.Bool(WithoutHeimdallFlag.Name) { return networks.NewBorDevnetWithoutHeimdall(dataDir, baseRpcHost, baseRpcPort, gasLimit, logger, consoleLogLevel, dirLogLevel), nil } else if ctx.Bool(LocalHeimdallFlag.Name) { @@ -431,7 +431,7 @@ func initDevnet(ctx *cli.Context, logger log.Logger) (devnet.Devnet, error) { return networks.NewBorDevnetWithRemoteHeimdall(dataDir, baseRpcHost, baseRpcPort, producerCount, gasLimit, logger, consoleLogLevel, dirLogLevel), nil } - case networkname.DevChainName: + case networkname.Dev: return networks.NewDevDevnet(dataDir, baseRpcHost, baseRpcPort, producerCount, gasLimit, logger, consoleLogLevel, dirLogLevel), nil default: diff --git a/cmd/devnet/networks/devnet_bor.go b/cmd/devnet/networks/devnet_bor.go index 6b2cf843b17..4c59abc9a4f 100644 --- a/cmd/devnet/networks/devnet_bor.go +++ b/cmd/devnet/networks/devnet_bor.go @@ -47,7 +47,7 @@ func NewBorDevnetWithoutHeimdall( network := devnet.Network{ DataDir: dataDir, - Chain: networkname.BorDevnetChainName, + Chain: networkname.BorDevnet, Logger: logger, BasePort: 40303, BasePrivateApiAddr: "localhost:10090", @@ -61,7 +61,7 @@ func NewBorDevnetWithoutHeimdall( GasLimit: gasLimit, }, Services: []devnet.Service{ - account_services.NewFaucet(networkname.BorDevnetChainName, faucetSource), + account_services.NewFaucet(networkname.BorDevnet, faucetSource), }, Nodes: []devnet.Node{ &args.BlockProducer{ @@ -125,7 +125,7 @@ func NewBorDevnetWithHeimdall( borNetwork := devnet.Network{ DataDir: dataDir, - Chain: networkname.BorDevnetChainName, + Chain: networkname.BorDevnet, Logger: logger, BasePort: 40303, BasePrivateApiAddr: "localhost:10090", @@ -133,7 +133,7 @@ func NewBorDevnetWithHeimdall( BaseRPCPort: baseRpcPort, BorStateSyncDelay: 5 * time.Second, BorWithMilestones: &withMilestones, - Services: append(services, account_services.NewFaucet(networkname.BorDevnetChainName, faucetSource)), + Services: append(services, account_services.NewFaucet(networkname.BorDevnet, faucetSource)), Genesis: &types.Genesis{ Alloc: types.GenesisAlloc{ faucetSource.Address: {Balance: accounts.EtherAmount(200_000)}, @@ -152,13 +152,13 @@ func NewBorDevnetWithHeimdall( devNetwork := devnet.Network{ DataDir: dataDir, - Chain: networkname.DevChainName, + Chain: networkname.Dev, Logger: logger, BasePort: 30403, BasePrivateApiAddr: "localhost:10190", BaseRPCHost: baseRpcHost, BaseRPCPort: baseRpcPort + 1000, - Services: append(services, account_services.NewFaucet(networkname.DevChainName, faucetSource)), + Services: append(services, account_services.NewFaucet(networkname.Dev, faucetSource)), Genesis: &types.Genesis{ Alloc: types.GenesisAlloc{ faucetSource.Address: {Balance: accounts.EtherAmount(200_000)}, diff --git a/cmd/devnet/networks/devnet_dev.go b/cmd/devnet/networks/devnet_dev.go index afd7bd3aec1..6c622244735 100644 --- a/cmd/devnet/networks/devnet_dev.go +++ b/cmd/devnet/networks/devnet_dev.go @@ -58,7 +58,7 @@ func NewDevDevnet( network := devnet.Network{ DataDir: dataDir, - Chain: networkname.DevChainName, + Chain: networkname.Dev, Logger: logger, BasePrivateApiAddr: "localhost:10090", BaseRPCHost: baseRpcHost, @@ -70,7 +70,7 @@ func NewDevDevnet( GasLimit: gasLimit, }, Services: []devnet.Service{ - account_services.NewFaucet(networkname.DevChainName, faucetSource), + account_services.NewFaucet(networkname.Dev, faucetSource), }, MaxNumberOfEmptyBlockChecks: 30, Nodes: append(nodes, diff --git a/cmd/devnet/services/polygon/checkpoint.go b/cmd/devnet/services/polygon/checkpoint.go index cbf809e4436..60529609dca 100644 --- a/cmd/devnet/services/polygon/checkpoint.go +++ b/cmd/devnet/services/polygon/checkpoint.go @@ -393,7 +393,7 @@ func (h *Heimdall) getRootHash(ctx context.Context, start uint64, end uint64) (l return libcommon.Hash{}, errors.New("number of headers requested exceeds") } - return devnet.SelectBlockProducer(devnet.WithCurrentNetwork(ctx, networkname.BorDevnetChainName)).GetRootHash(ctx, start, end) + return devnet.SelectBlockProducer(devnet.WithCurrentNetwork(ctx, networkname.BorDevnet)).GetRootHash(ctx, start, end) } func (h *Heimdall) shouldSendCheckpoint(start uint64, end uint64) (bool, error) { diff --git a/cmd/devnet/services/polygon/proofgenerator.go b/cmd/devnet/services/polygon/proofgenerator.go index 4fd7d98e3f5..b7ee4ef5c31 100644 --- a/cmd/devnet/services/polygon/proofgenerator.go +++ b/cmd/devnet/services/polygon/proofgenerator.go @@ -117,7 +117,7 @@ func (pg *ProofGenerator) GenerateExitPayload(ctx context.Context, burnTxHash li } func (pg *ProofGenerator) getChainBlockInfo(ctx context.Context, burnTxHash libcommon.Hash) (uint64, uint64, error) { - childNode := devnet.SelectBlockProducer(devnet.WithCurrentNetwork(ctx, networkname.BorDevnetChainName)) + childNode := devnet.SelectBlockProducer(devnet.WithCurrentNetwork(ctx, networkname.BorDevnet)) var wg sync.WaitGroup diff --git a/cmd/devnet/tests/bor_devnet_test.go b/cmd/devnet/tests/bor_devnet_test.go index 2d166a3d7ed..f91a3ce8f63 100644 --- a/cmd/devnet/tests/bor_devnet_test.go +++ b/cmd/devnet/tests/bor_devnet_test.go @@ -34,7 +34,7 @@ import ( func TestStateSync(t *testing.T) { t.Skip() - runCtx, err := ContextStart(t, networkname.BorDevnetChainName) + runCtx, err := ContextStart(t, networkname.BorDevnet) require.Nil(t, err) var ctx context.Context = runCtx @@ -42,11 +42,11 @@ func TestStateSync(t *testing.T) { services.InitSubscriptions(ctx, []requests.SubMethod{requests.Methods.ETHNewHeads}) }) t.Run("CreateAccountWithFunds", func(t *testing.T) { - _, err := accounts_steps.CreateAccountWithFunds(ctx, networkname.DevChainName, "root-funder", 200.0) + _, err := accounts_steps.CreateAccountWithFunds(ctx, networkname.Dev, "root-funder", 200.0) require.Nil(t, err) }) t.Run("CreateAccountWithFunds", func(t *testing.T) { - _, err := accounts_steps.CreateAccountWithFunds(ctx, networkname.BorDevnetChainName, "child-funder", 200.0) + _, err := accounts_steps.CreateAccountWithFunds(ctx, networkname.BorDevnet, "child-funder", 200.0) require.Nil(t, err) }) t.Run("DeployChildChainReceiver", func(t *testing.T) { @@ -73,16 +73,16 @@ func TestStateSync(t *testing.T) { func TestChildChainExit(t *testing.T) { t.Skip("FIXME: step CreateAccountWithFunds fails: Failed to get transfer tx: failed to search reserves for hashes: no block heads subscription") - runCtx, err := ContextStart(t, networkname.BorDevnetChainName) + runCtx, err := ContextStart(t, networkname.BorDevnet) require.Nil(t, err) var ctx context.Context = runCtx t.Run("CreateAccountWithFunds", func(t *testing.T) { - _, err := accounts_steps.CreateAccountWithFunds(ctx, networkname.DevChainName, "root-funder", 200.0) + _, err := accounts_steps.CreateAccountWithFunds(ctx, networkname.Dev, "root-funder", 200.0) require.Nil(t, err) }) t.Run("CreateAccountWithFunds", func(t *testing.T) { - _, err := accounts_steps.CreateAccountWithFunds(ctx, networkname.BorDevnetChainName, "child-funder", 200.0) + _, err := accounts_steps.CreateAccountWithFunds(ctx, networkname.BorDevnet, "child-funder", 200.0) require.Nil(t, err) }) t.Run("DeployRootChainReceiver", func(t *testing.T) { diff --git a/cmd/devnet/tests/context.go b/cmd/devnet/tests/context.go index 83d3c877c49..c96d84185b4 100644 --- a/cmd/devnet/tests/context.go +++ b/cmd/devnet/tests/context.go @@ -38,18 +38,18 @@ func initDevnet(chainName string, dataDir string, producerCount int, gasLimit ui const baseRpcPort = 9545 switch chainName { - case networkname.BorDevnetChainName: + case networkname.BorDevnet: heimdallURL := polygon.HeimdallURLDefault const sprintSize uint64 = 0 return networks.NewBorDevnetWithLocalHeimdall(dataDir, baseRpcHost, baseRpcPort, heimdallURL, sprintSize, producerCount, gasLimit, logger, consoleLogLevel, dirLogLevel), nil - case networkname.DevChainName: + case networkname.Dev: return networks.NewDevDevnet(dataDir, baseRpcHost, baseRpcPort, producerCount, gasLimit, logger, consoleLogLevel, dirLogLevel), nil case "": envChainName, _ := os.LookupEnv("DEVNET_CHAIN") if envChainName == "" { - envChainName = networkname.DevChainName + envChainName = networkname.Dev } return initDevnet(envChainName, dataDir, producerCount, gasLimit, logger, consoleLogLevel, dirLogLevel) diff --git a/cmd/downloader/main.go b/cmd/downloader/main.go index baea140425d..0d388589d91 100644 --- a/cmd/downloader/main.go +++ b/cmd/downloader/main.go @@ -240,9 +240,12 @@ func Downloader(ctx context.Context, logger log.Logger) error { webseedsList = append(webseedsList, known...) } if seedbox { - snapcfg.LoadRemotePreverified() + _, err = downloadercfg.LoadSnapshotsHashes(ctx, dirs, chain) + if err != nil { + return err + } } - cfg, err := downloadercfg.New(dirs, version, torrentLogLevel, downloadRate, uploadRate, torrentPort, torrentConnsPerFile, torrentDownloadSlots, staticPeers, webseedsList, chain, true, dbWritemap) + cfg, err := downloadercfg.New(ctx, dirs, version, torrentLogLevel, downloadRate, uploadRate, torrentPort, torrentConnsPerFile, torrentDownloadSlots, staticPeers, webseedsList, chain, true, dbWritemap) if err != nil { return err } diff --git a/cmd/erigon/main.go b/cmd/erigon/main.go index b105ae7acbd..d38196a845a 100644 --- a/cmd/erigon/main.go +++ b/cmd/erigon/main.go @@ -85,7 +85,10 @@ func runErigon(cliCtx *cli.Context) error { erigonInfoGauge := metrics.GetOrCreateGauge(fmt.Sprintf(`erigon_info{version="%s",commit="%s"}`, params.Version, params.GitCommit)) erigonInfoGauge.Set(1) - nodeCfg := node.NewNodConfigUrfave(cliCtx, logger) + nodeCfg, err := node.NewNodConfigUrfave(cliCtx, logger) + if err != nil { + return err + } if err := datadir.ApplyMigrations(nodeCfg.Dirs); err != nil { return err } diff --git a/cmd/snapshots/cmp/cmp.go b/cmd/snapshots/cmp/cmp.go index 9df90cc8fad..c117b015085 100644 --- a/cmd/snapshots/cmp/cmp.go +++ b/cmd/snapshots/cmp/cmp.go @@ -161,7 +161,7 @@ func cmp(cliCtx *cli.Context) error { if loc1.LType == sync.TorrentFs || loc2.LType == sync.TorrentFs { config := sync.NewTorrentClientConfigFromCobra(cliCtx, chain) - torrentCli, err = sync.NewTorrentClient(config) + torrentCli, err = sync.NewTorrentClient(cliCtx.Context, config) if err != nil { return fmt.Errorf("can't create torrent: %w", err) } diff --git a/cmd/snapshots/copy/copy.go b/cmd/snapshots/copy/copy.go index 99c722c9360..2ddedb6ec38 100644 --- a/cmd/snapshots/copy/copy.go +++ b/cmd/snapshots/copy/copy.go @@ -145,7 +145,7 @@ func copy(cliCtx *cli.Context) error { switch src.LType { case sync.TorrentFs: config := sync.NewTorrentClientConfigFromCobra(cliCtx, dst.Chain) - torrentCli, err = sync.NewTorrentClient(config) + torrentCli, err = sync.NewTorrentClient(cliCtx.Context, config) if err != nil { return fmt.Errorf("can't create torrent: %w", err) } diff --git a/cmd/snapshots/sync/sync.go b/cmd/snapshots/sync/sync.go index 5ab2f9b06d6..337df46bd7d 100644 --- a/cmd/snapshots/sync/sync.go +++ b/cmd/snapshots/sync/sync.go @@ -200,7 +200,7 @@ func NewDefaultTorrentClientConfig(chain string, torrentDir string, logger log.L } } -func NewTorrentClient(config CreateNewTorrentClientConfig) (*TorrentClient, error) { +func NewTorrentClient(ctx context.Context, config CreateNewTorrentClientConfig) (*TorrentClient, error) { logger := config.Logger tempDir := config.TempDir @@ -232,7 +232,7 @@ func NewTorrentClient(config CreateNewTorrentClientConfig) (*TorrentClient, erro version := "erigon: " + params.VersionWithCommit(params.GitCommit) - cfg, err := downloadercfg.New(dirs, version, logLevel, downloadRate, uploadRate, + cfg, err := downloadercfg.New(ctx, dirs, version, logLevel, downloadRate, uploadRate, config.TorrentPort, config.ConnsPerFile, 0, nil, webseedsList, config.Chain, true, true) diff --git a/cmd/snapshots/verify/verify.go b/cmd/snapshots/verify/verify.go index 06f76b81a04..15ef7ebc735 100644 --- a/cmd/snapshots/verify/verify.go +++ b/cmd/snapshots/verify/verify.go @@ -118,7 +118,7 @@ func verify(cliCtx *cli.Context) error { switch dst.LType { case sync.TorrentFs: config := sync.NewTorrentClientConfigFromCobra(cliCtx, dst.Chain) - torrentCli, err = sync.NewTorrentClient(config) + torrentCli, err = sync.NewTorrentClient(cliCtx.Context, config) if err != nil { return fmt.Errorf("can't create torrent: %w", err) } @@ -145,7 +145,7 @@ func verify(cliCtx *cli.Context) error { case sync.TorrentFs: if torrentCli == nil { config := sync.NewTorrentClientConfigFromCobra(cliCtx, dst.Chain) - torrentCli, err = sync.NewTorrentClient(config) + torrentCli, err = sync.NewTorrentClient(cliCtx.Context, config) if err != nil { return fmt.Errorf("can't create torrent: %w", err) } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index dc3f2e6b032..294e82d30a9 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -105,7 +105,7 @@ var ( ChainFlag = cli.StringFlag{ Name: "chain", Usage: "name of the network to join", - Value: networkname.MainnetChainName, + Value: networkname.Mainnet, } IdentityFlag = cli.StringFlag{ Name: "identity", @@ -1347,7 +1347,7 @@ func setEtherbase(ctx *cli.Context, cfg *ethconfig.Config) { } } - if chainName := ctx.String(ChainFlag.Name); chainName == networkname.DevChainName || chainName == networkname.BorDevnetChainName { + if chainName := ctx.String(ChainFlag.Name); chainName == networkname.Dev || chainName == networkname.BorDevnet { if etherbase == "" { cfg.Miner.Etherbase = core.DevnetEtherbase } @@ -1409,7 +1409,7 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config, nodeName, datadir string, l cfg.NetRestrict = list } - if ctx.String(ChainFlag.Name) == networkname.DevChainName { + if ctx.String(ChainFlag.Name) == networkname.Dev { // --dev mode can't use p2p networking. //cfg.MaxPeers = 0 // It can have peers otherwise local sync is not possible if !ctx.IsSet(ListenPortFlag.Name) { @@ -1422,12 +1422,15 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config, nodeName, datadir string, l } // SetNodeConfig applies node-related command line flags to the config. -func SetNodeConfig(ctx *cli.Context, cfg *nodecfg.Config, logger log.Logger) { - setDataDir(ctx, cfg) +func SetNodeConfig(ctx *cli.Context, cfg *nodecfg.Config, logger log.Logger) error { + if err := setDataDir(ctx, cfg); err != nil { + return err + } setNodeUserIdent(ctx, cfg) SetP2PConfig(ctx, &cfg.P2P, cfg.NodeName(), cfg.Dirs.DataDir, logger) cfg.SentryLogPeerInfo = ctx.IsSet(SentryLogPeerInfoFlag.Name) + return nil } func SetNodeConfigCobra(cmd *cobra.Command, cfg *nodecfg.Config) { @@ -1437,23 +1440,28 @@ func SetNodeConfigCobra(cmd *cobra.Command, cfg *nodecfg.Config) { setDataDirCobra(flags, cfg) } -func setDataDir(ctx *cli.Context, cfg *nodecfg.Config) { +func setDataDir(ctx *cli.Context, cfg *nodecfg.Config) error { if ctx.IsSet(DataDirFlag.Name) { cfg.Dirs = datadir.New(ctx.String(DataDirFlag.Name)) } else { cfg.Dirs = datadir.New(paths.DataDirForNetwork(paths.DefaultDataDir(), ctx.String(ChainFlag.Name))) } - snapcfg.LoadRemotePreverified() + _, err := downloadercfg2.LoadSnapshotsHashes(ctx.Context, cfg.Dirs, ctx.String(ChainFlag.Name)) + if err != nil { + return err + } cfg.MdbxPageSize = flags.DBPageSizeFlagUnmarshal(ctx, DbPageSizeFlag.Name, DbPageSizeFlag.Usage) if err := cfg.MdbxDBSizeLimit.UnmarshalText([]byte(ctx.String(DbSizeLimitFlag.Name))); err != nil { - panic(err) + return fmt.Errorf("failed to parse --%s: %w", DbSizeLimitFlag.Name, err) } cfg.MdbxWriteMap = ctx.Bool(DbWriteMapFlag.Name) szLimit := cfg.MdbxDBSizeLimit.Bytes() if szLimit%256 != 0 || szLimit < 256 { - panic(fmt.Errorf("invalid --db.size.limit: %s=%d, see: %s", ctx.String(DbSizeLimitFlag.Name), szLimit, DbSizeLimitFlag.Usage)) + return fmt.Errorf("invalid --%s: %s=%d, see: %s", DbSizeLimitFlag.Name, ctx.String(DbSizeLimitFlag.Name), + szLimit, DbSizeLimitFlag.Usage) } + return nil } func setDataDirCobra(f *pflag.FlagSet, cfg *nodecfg.Config) { @@ -1854,7 +1862,7 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C if known, ok := snapcfg.KnownWebseeds[chain]; ok { webseedsList = append(webseedsList, known...) } - cfg.Downloader, err = downloadercfg2.New(cfg.Dirs, version, lvl, downloadRate, uploadRate, + cfg.Downloader, err = downloadercfg2.New(ctx.Context, cfg.Dirs, version, lvl, downloadRate, uploadRate, ctx.Int(TorrentPortFlag.Name), ctx.Int(TorrentConnsPerFileFlag.Name), ctx.Int(TorrentDownloadSlotsFlag.Name), libcommon.CliString2Array(ctx.String(TorrentStaticPeersFlag.Name)), webseedsList, chain, true, ctx.Bool(DbWriteMapFlag.Name), @@ -1928,7 +1936,7 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C if cfg.NetworkID == 1 { SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash) } - case networkname.DevChainName: + case networkname.Dev: // Create new developer account or reuse existing one developer := cfg.Miner.Etherbase if developer == (libcommon.Address{}) { diff --git a/common/paths/paths.go b/common/paths/paths.go index 772c33f7457..60e2516601d 100644 --- a/common/paths/paths.go +++ b/common/paths/paths.go @@ -96,21 +96,21 @@ func DataDirForNetwork(datadir string, network string) string { } switch network { - case networkname.DevChainName: + case networkname.Dev: return "" // unless explicitly requested, use memory databases - case networkname.HoleskyChainName: + case networkname.Holesky: return networkDataDirCheckingLegacy(datadir, "holesky") - case networkname.AmoyChainName: + case networkname.Amoy: return networkDataDirCheckingLegacy(datadir, "amoy") - case networkname.BorMainnetChainName: + case networkname.BorMainnet: return networkDataDirCheckingLegacy(datadir, "bor-mainnet") - case networkname.BorDevnetChainName: + case networkname.BorDevnet: return networkDataDirCheckingLegacy(datadir, "bor-devnet") - case networkname.SepoliaChainName: + case networkname.Sepolia: return networkDataDirCheckingLegacy(datadir, "sepolia") - case networkname.GnosisChainName: + case networkname.Gnosis: return networkDataDirCheckingLegacy(datadir, "gnosis") - case networkname.ChiadoChainName: + case networkname.Chiado: return networkDataDirCheckingLegacy(datadir, "chiado") default: diff --git a/core/genesis_test.go b/core/genesis_test.go index 1d7094018d5..744612efbd0 100644 --- a/core/genesis_test.go +++ b/core/genesis_test.go @@ -113,7 +113,7 @@ func TestCommitGenesisIdempotency(t *testing.T) { require.NoError(t, err) defer tx.Rollback() - genesis := core.GenesisBlockByChainName(networkname.MainnetChainName) + genesis := core.GenesisBlockByChainName(networkname.Mainnet) _, _, err = core.WriteGenesisBlock(tx, genesis, nil, datadir.New(t.TempDir()), logger) require.NoError(t, err) seq, err := tx.ReadSequence(kv.EthTx) diff --git a/core/genesis_write.go b/core/genesis_write.go index 410844581ae..180b705972c 100644 --- a/core/genesis_write.go +++ b/core/genesis_write.go @@ -627,21 +627,21 @@ func readPrealloc(filename string) types.GenesisAlloc { func GenesisBlockByChainName(chain string) *types.Genesis { switch chain { - case networkname.MainnetChainName: + case networkname.Mainnet: return MainnetGenesisBlock() - case networkname.HoleskyChainName: + case networkname.Holesky: return HoleskyGenesisBlock() - case networkname.SepoliaChainName: + case networkname.Sepolia: return SepoliaGenesisBlock() - case networkname.AmoyChainName: + case networkname.Amoy: return AmoyGenesisBlock() - case networkname.BorMainnetChainName: + case networkname.BorMainnet: return BorMainnetGenesisBlock() - case networkname.BorDevnetChainName: + case networkname.BorDevnet: return BorDevnetGenesisBlock() - case networkname.GnosisChainName: + case networkname.Gnosis: return GnosisGenesisBlock() - case networkname.ChiadoChainName: + case networkname.Chiado: return ChiadoGenesisBlock() case networkname.Test: return TestGenesisBlock() diff --git a/core/skip_analysis.go b/core/skip_analysis.go index a6afb6637f5..a6f3ec9f5b6 100644 --- a/core/skip_analysis.go +++ b/core/skip_analysis.go @@ -36,8 +36,8 @@ import ( // 0x21ab7bf7245a87eae265124aaf180d91133377e47db2b1a4866493ec4b371150 (block 13119520) var analysisBlocks = map[string][]uint64{ - networkname.MainnetChainName: {5_800_596, 6_426_298, 6_426_432, 11_079_912, 13_119_520, 15_081_051}, - networkname.BorMainnetChainName: {29_447_463}, + networkname.Mainnet: {5_800_596, 6_426_298, 6_426_432, 11_079_912, 13_119_520, 15_081_051}, + networkname.BorMainnet: {29_447_463}, } func SkipAnalysis(config *chain.Config, blockNumber uint64) bool { diff --git a/core/snaptype/block_types.go b/core/snaptype/block_types.go index 0a31d4dc64b..c52cafcb7c3 100644 --- a/core/snaptype/block_types.go +++ b/core/snaptype/block_types.go @@ -45,11 +45,11 @@ import ( func init() { ethereumTypes := append(BlockSnapshotTypes, snaptype.CaplinSnapshotTypes...) - snapcfg.RegisterKnownTypes(networkname.MainnetChainName, ethereumTypes) - snapcfg.RegisterKnownTypes(networkname.SepoliaChainName, ethereumTypes) - snapcfg.RegisterKnownTypes(networkname.GnosisChainName, ethereumTypes) - snapcfg.RegisterKnownTypes(networkname.ChiadoChainName, ethereumTypes) - snapcfg.RegisterKnownTypes(networkname.HoleskyChainName, ethereumTypes) + snapcfg.RegisterKnownTypes(networkname.Mainnet, ethereumTypes) + snapcfg.RegisterKnownTypes(networkname.Sepolia, ethereumTypes) + snapcfg.RegisterKnownTypes(networkname.Gnosis, ethereumTypes) + snapcfg.RegisterKnownTypes(networkname.Chiado, ethereumTypes) + snapcfg.RegisterKnownTypes(networkname.Holesky, ethereumTypes) } var Enums = struct { diff --git a/core/system_contract_lookup.go b/core/system_contract_lookup.go index 0d7196f40a4..557570d1dae 100644 --- a/core/system_contract_lookup.go +++ b/core/system_contract_lookup.go @@ -32,7 +32,7 @@ import ( func init() { // Initialise SystemContractCodeLookup - for _, chainName := range []string{networkname.BorMainnetChainName, networkname.AmoyChainName, networkname.BorDevnetChainName} { + for _, chainName := range []string{networkname.BorMainnet, networkname.Amoy, networkname.BorDevnet} { byChain := map[libcommon.Address][]libcommon.CodeRecord{} systemcontracts.SystemContractCodeLookup[chainName] = byChain // Apply genesis with the block number 0 @@ -75,7 +75,7 @@ func allocToCodeRecords(alloc types.GenesisAlloc, byChain map[libcommon.Address] // and losing the history for it in the DB. Temporary hack until erigon 3 arrives func addGnosisSpecialCase() { byChain := map[libcommon.Address][]libcommon.CodeRecord{} - systemcontracts.SystemContractCodeLookup[networkname.GnosisChainName] = byChain + systemcontracts.SystemContractCodeLookup[networkname.Gnosis] = byChain address := libcommon.HexToAddress("0xf8d1677c8a0c961938bf2f9adc3f3cfda759a9d9") list := byChain[address] diff --git a/erigon-lib/chain/networkname/network_name.go b/erigon-lib/chain/networkname/network_name.go index bcb57865fa7..3d03ffc984a 100644 --- a/erigon-lib/chain/networkname/network_name.go +++ b/erigon-lib/chain/networkname/network_name.go @@ -17,27 +17,36 @@ package networkname const ( - MainnetChainName = "mainnet" - HoleskyChainName = "holesky" - SepoliaChainName = "sepolia" - DevChainName = "dev" - AmoyChainName = "amoy" - BorMainnetChainName = "bor-mainnet" - BorDevnetChainName = "bor-devnet" - GnosisChainName = "gnosis" - BorE2ETestChain2ValName = "bor-e2e-test-2Val" - ChiadoChainName = "chiado" - Test = "test" + Mainnet = "mainnet" + Holesky = "holesky" + Sepolia = "sepolia" + Dev = "dev" + Amoy = "amoy" + BorMainnet = "bor-mainnet" + BorDevnet = "bor-devnet" + Gnosis = "gnosis" + BorE2ETestChain2Val = "bor-e2e-test-2Val" + Chiado = "chiado" + Test = "test" ) var All = []string{ - MainnetChainName, - HoleskyChainName, - SepoliaChainName, - AmoyChainName, - BorMainnetChainName, - BorDevnetChainName, - GnosisChainName, - ChiadoChainName, + Mainnet, + Holesky, + Sepolia, + Amoy, + BorMainnet, + BorDevnet, + Gnosis, + Chiado, Test, } + +func IsKnownNetwork(s string) bool { + for _, n := range All { + if n == s { + return true + } + } + return false +} diff --git a/erigon-lib/chain/snapcfg/util.go b/erigon-lib/chain/snapcfg/util.go index 0b19b67ea19..f60de31aaff 100644 --- a/erigon-lib/chain/snapcfg/util.go +++ b/erigon-lib/chain/snapcfg/util.go @@ -17,6 +17,7 @@ package snapcfg import ( + "context" _ "embed" "encoding/json" "path/filepath" @@ -362,6 +363,10 @@ func newCfg(networkName string, preverified Preverified) *Cfg { return &Cfg{ExpectBlocks: maxBlockNum, Preverified: preverified, networkName: networkName} } +func NewNonSeededCfg(networkName string) *Cfg { + return newCfg(networkName, Preverified{}) +} + type Cfg struct { ExpectBlocks uint64 Preverified Preverified @@ -425,13 +430,13 @@ func (c Cfg) MergeLimit(t snaptype.Enum, fromBlock uint64) uint64 { } var knownPreverified = map[string]Preverified{ - networkname.MainnetChainName: Mainnet, - networkname.HoleskyChainName: Holesky, - networkname.SepoliaChainName: Sepolia, - networkname.AmoyChainName: Amoy, - networkname.BorMainnetChainName: BorMainnet, - networkname.GnosisChainName: Gnosis, - networkname.ChiadoChainName: Chiado, + networkname.Mainnet: Mainnet, + networkname.Holesky: Holesky, + networkname.Sepolia: Sepolia, + networkname.Amoy: Amoy, + networkname.BorMainnet: BorMainnet, + networkname.Gnosis: Gnosis, + networkname.Chiado: Chiado, } func RegisterKnownTypes(networkName string, types []snaptype.Type) { @@ -504,13 +509,13 @@ func VersionedCfg(networkName string, preferred snaptype.Version, min snaptype.V } var KnownWebseeds = map[string][]string{ - networkname.MainnetChainName: webseedsParse(webseed.Mainnet), - networkname.SepoliaChainName: webseedsParse(webseed.Sepolia), - networkname.AmoyChainName: webseedsParse(webseed.Amoy), - networkname.BorMainnetChainName: webseedsParse(webseed.BorMainnet), - networkname.GnosisChainName: webseedsParse(webseed.Gnosis), - networkname.ChiadoChainName: webseedsParse(webseed.Chiado), - networkname.HoleskyChainName: webseedsParse(webseed.Holesky), + networkname.Mainnet: webseedsParse(webseed.Mainnet), + networkname.Sepolia: webseedsParse(webseed.Sepolia), + networkname.Amoy: webseedsParse(webseed.Amoy), + networkname.BorMainnet: webseedsParse(webseed.BorMainnet), + networkname.Gnosis: webseedsParse(webseed.Gnosis), + networkname.Chiado: webseedsParse(webseed.Chiado), + networkname.Holesky: webseedsParse(webseed.Holesky), } func webseedsParse(in []byte) (res []string) { @@ -525,8 +530,11 @@ func webseedsParse(in []byte) (res []string) { return res } -func LoadRemotePreverified() bool { - couldFetch := snapshothashes.LoadSnapshots() +func LoadRemotePreverified(ctx context.Context) (loaded bool, err error) { + loaded, err = snapshothashes.LoadSnapshots(ctx) + if err != nil { + return false, err + } // Re-load the preverified hashes Mainnet = fromToml(snapshothashes.Mainnet) @@ -538,25 +546,25 @@ func LoadRemotePreverified() bool { Chiado = fromToml(snapshothashes.Chiado) // Update the known preverified hashes KnownWebseeds = map[string][]string{ - networkname.MainnetChainName: webseedsParse(webseed.Mainnet), - networkname.SepoliaChainName: webseedsParse(webseed.Sepolia), - networkname.AmoyChainName: webseedsParse(webseed.Amoy), - networkname.BorMainnetChainName: webseedsParse(webseed.BorMainnet), - networkname.GnosisChainName: webseedsParse(webseed.Gnosis), - networkname.ChiadoChainName: webseedsParse(webseed.Chiado), - networkname.HoleskyChainName: webseedsParse(webseed.Holesky), + networkname.Mainnet: webseedsParse(webseed.Mainnet), + networkname.Sepolia: webseedsParse(webseed.Sepolia), + networkname.Amoy: webseedsParse(webseed.Amoy), + networkname.BorMainnet: webseedsParse(webseed.BorMainnet), + networkname.Gnosis: webseedsParse(webseed.Gnosis), + networkname.Chiado: webseedsParse(webseed.Chiado), + networkname.Holesky: webseedsParse(webseed.Holesky), } knownPreverified = map[string]Preverified{ - networkname.MainnetChainName: Mainnet, - networkname.HoleskyChainName: Holesky, - networkname.SepoliaChainName: Sepolia, - networkname.AmoyChainName: Amoy, - networkname.BorMainnetChainName: BorMainnet, - networkname.GnosisChainName: Gnosis, - networkname.ChiadoChainName: Chiado, - } - return couldFetch + networkname.Mainnet: Mainnet, + networkname.Holesky: Holesky, + networkname.Sepolia: Sepolia, + networkname.Amoy: Amoy, + networkname.BorMainnet: BorMainnet, + networkname.Gnosis: Gnosis, + networkname.Chiado: Chiado, + } + return loaded, nil } func SetToml(networkName string, toml []byte) { @@ -568,19 +576,19 @@ func SetToml(networkName string, toml []byte) { func GetToml(networkName string) []byte { switch networkName { - case networkname.MainnetChainName: + case networkname.Mainnet: return snapshothashes.Mainnet - case networkname.HoleskyChainName: + case networkname.Holesky: return snapshothashes.Holesky - case networkname.SepoliaChainName: + case networkname.Sepolia: return snapshothashes.Sepolia - case networkname.AmoyChainName: + case networkname.Amoy: return snapshothashes.Amoy - case networkname.BorMainnetChainName: + case networkname.BorMainnet: return snapshothashes.BorMainnet - case networkname.GnosisChainName: + case networkname.Gnosis: return snapshothashes.Gnosis - case networkname.ChiadoChainName: + case networkname.Chiado: return snapshothashes.Chiado default: return nil diff --git a/erigon-lib/downloader/downloader_test.go b/erigon-lib/downloader/downloader_test.go index 952acf9d180..1cdff9c2ad0 100644 --- a/erigon-lib/downloader/downloader_test.go +++ b/erigon-lib/downloader/downloader_test.go @@ -38,7 +38,7 @@ func TestChangeInfoHashOfSameFile(t *testing.T) { require := require.New(t) dirs := datadir.New(t.TempDir()) - cfg, err := downloadercfg2.New(dirs, "", lg.Info, 0, 0, 0, 0, 0, nil, nil, "testnet", false, false) + cfg, err := downloadercfg2.New(context.Background(), dirs, "", lg.Info, 0, 0, 0, 0, 0, nil, nil, "testnet", false, false) require.NoError(err) d, err := New(context.Background(), cfg, log.New(), log.LvlInfo, true) require.NoError(err) diff --git a/erigon-lib/downloader/downloadercfg/downloadercfg.go b/erigon-lib/downloader/downloadercfg/downloadercfg.go index 6910ec0e270..b52f29c4ffb 100644 --- a/erigon-lib/downloader/downloadercfg/downloadercfg.go +++ b/erigon-lib/downloader/downloadercfg/downloadercfg.go @@ -17,6 +17,8 @@ package downloadercfg import ( + "context" + "fmt" "net" "net/url" "os" @@ -25,6 +27,8 @@ import ( "strings" "time" + "github.com/erigontech/erigon-lib/chain/networkname" + "github.com/anacrolix/dht/v2" lg "github.com/anacrolix/log" "github.com/anacrolix/torrent" @@ -105,7 +109,7 @@ func Default() *torrent.ClientConfig { return torrentConfig } -func New(dirs datadir.Dirs, version string, verbosity lg.Level, downloadRate, uploadRate datasize.ByteSize, port, connsPerFile, downloadSlots int, staticPeers, webseeds []string, chainName string, lockSnapshots, mdbxWriteMap bool) (*Cfg, error) { +func New(ctx context.Context, dirs datadir.Dirs, version string, verbosity lg.Level, downloadRate, uploadRate datasize.ByteSize, port, connsPerFile, downloadSlots int, staticPeers, webseeds []string, chainName string, lockSnapshots, mdbxWriteMap bool) (*Cfg, error) { torrentConfig := Default() //torrentConfig.PieceHashersPerTorrent = runtime.NumCPU() torrentConfig.DataDir = dirs.Snap // `DataDir` of torrent-client-lib is different from Erigon's `DataDir`. Just same naming. @@ -194,13 +198,13 @@ func New(dirs datadir.Dirs, version string, verbosity lg.Level, downloadRate, up } if strings.HasPrefix(webseed, "v1:") { - withoutVerisonPrefix := webseed[3:] - if !strings.HasPrefix(withoutVerisonPrefix, "https:") { + withoutVersionPrefix := webseed[3:] + if !strings.HasPrefix(withoutVersionPrefix, "https:") { continue } - uri, err := url.ParseRequestURI(withoutVerisonPrefix) + uri, err := url.ParseRequestURI(withoutVersionPrefix) if err != nil { - log.Warn("[webseed] can't parse url", "err", err, "url", withoutVerisonPrefix) + log.Warn("[webseed] can't parse url", "err", err, "url", withoutVersionPrefix) continue } webseedHttpProviders = append(webseedHttpProviders, uri) @@ -218,8 +222,8 @@ func New(dirs datadir.Dirs, version string, verbosity lg.Level, downloadRate, up webseedFileProviders = append(webseedFileProviders, localCfgFile) } - // setup snapcfg - preverifiedCfg, err := loadSnapshotsEitherFromDiskIfNeeded(dirs, chainName) + // TODO: constructor must not do http requests + preverifiedCfg, err := LoadSnapshotsHashes(ctx, dirs, chainName) if err != nil { return nil, err } @@ -233,23 +237,40 @@ func New(dirs datadir.Dirs, version string, verbosity lg.Level, downloadRate, up }, nil } -func loadSnapshotsEitherFromDiskIfNeeded(dirs datadir.Dirs, chainName string) (*snapcfg.Cfg, error) { - preverifiedToml := filepath.Join(dirs.Snap, "preverified.toml") +// LoadSnapshotsHashes checks local preverified.toml. If file exists, used local hashes. +// If there are no such file, try to fetch hashes from the web and create local file. +func LoadSnapshotsHashes(ctx context.Context, dirs datadir.Dirs, chainName string) (*snapcfg.Cfg, error) { + if !networkname.IsKnownNetwork(chainName) { + log.Root().Warn("No snapshot hashes for chain", "chain", chainName) + return snapcfg.NewNonSeededCfg(chainName), nil + } - exists, err := dir.FileExist(preverifiedToml) + preverifiedPath := filepath.Join(dirs.Snap, "preverified.toml") + exists, err := dir.FileExist(preverifiedPath) if err != nil { return nil, err } if exists { - // Read the preverified.toml and load the snapshots - haveToml, err := os.ReadFile(preverifiedToml) + // Load hashes from local preverified.toml + haveToml, err := os.ReadFile(preverifiedPath) if err != nil { return nil, err } snapcfg.SetToml(chainName, haveToml) - } - if err := dir.WriteFileWithFsync(preverifiedToml, snapcfg.GetToml(chainName), 0644); err != nil { - return nil, err + } else { + // Fetch the snapshot hashes from the web + fetched, err := snapcfg.LoadRemotePreverified(ctx) + if err != nil { + log.Root().Crit("Snapshot hashes for supported networks was not loaded. Please check your network connection and/or GitHub status here https://www.githubstatus.com/", "chain", chainName, "err", err) + return nil, fmt.Errorf("failed to fetch remote snapshot hashes for chain %s", chainName) + } + if !fetched { + log.Root().Crit("Snapshot hashes for supported networks was not loaded. Please check your network connection and/or GitHub status here https://www.githubstatus.com/", "chain", chainName) + return nil, fmt.Errorf("remote snapshot hashes was not fetched for chain %s", chainName) + } + if err := dir.WriteFileWithFsync(preverifiedPath, snapcfg.GetToml(chainName), 0644); err != nil { + return nil, err + } } return snapcfg.KnownCfg(chainName), nil } diff --git a/erigon-lib/go.mod b/erigon-lib/go.mod index 8febc6973d5..dc9609d2517 100644 --- a/erigon-lib/go.mod +++ b/erigon-lib/go.mod @@ -3,7 +3,7 @@ module github.com/erigontech/erigon-lib go 1.22.0 require ( - github.com/erigontech/erigon-snapshot v1.3.1-0.20240814160410-2ce37904b978 + github.com/erigontech/erigon-snapshot v1.3.1-0.20241023024258-f64407a77e8e github.com/erigontech/interfaces v0.0.0-20241018125732-814767d1b926 github.com/erigontech/mdbx-go v0.38.4 github.com/erigontech/secp256k1 v1.1.0 diff --git a/erigon-lib/go.sum b/erigon-lib/go.sum index c601a288c57..5b28234a7d8 100644 --- a/erigon-lib/go.sum +++ b/erigon-lib/go.sum @@ -146,8 +146,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/erigontech/erigon-snapshot v1.3.1-0.20240814160410-2ce37904b978 h1:7ECOf7Us3+/706WGZXIX84qQc6zmxQby8fGbFLiqFlU= -github.com/erigontech/erigon-snapshot v1.3.1-0.20240814160410-2ce37904b978/go.mod h1:ooHlCl+eEYzebiPu+FP6Q6SpPUeMADn8Jxabv3IKb9M= +github.com/erigontech/erigon-snapshot v1.3.1-0.20241023024258-f64407a77e8e h1:ZpIO6HeopuZPYDLldL6zR0qyRezj80kQrDOGEF779ts= +github.com/erigontech/erigon-snapshot v1.3.1-0.20241023024258-f64407a77e8e/go.mod h1:ooHlCl+eEYzebiPu+FP6Q6SpPUeMADn8Jxabv3IKb9M= github.com/erigontech/interfaces v0.0.0-20241018125732-814767d1b926 h1:2H5vOO4LT+P0oB82f4AEK7AK+1QJYUL9VNz2KEvqknI= github.com/erigontech/interfaces v0.0.0-20241018125732-814767d1b926/go.mod h1:N7OUkhkcagp9+7yb4ycHsG2VWCOmuJ1ONBecJshxtLE= github.com/erigontech/mdbx-go v0.38.4 h1:S9T7mTe9KPcFe4dOoOtVdI6gPzht9y7wMnYfUBgrQLo= diff --git a/eth/backend.go b/eth/backend.go index c2a0fab4c90..1f363e990e0 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -1162,7 +1162,7 @@ func (s *Ethereum) StartMining(ctx context.Context, db kv.RwDB, stateDiffClient } if miner.MiningConfig.Enabled { - if s.chainConfig.ChainName == networkname.DevChainName { + if s.chainConfig.ChainName == networkname.Dev { miner.MiningConfig.SigKey = core.DevnetSignPrivateKey } if miner.MiningConfig.SigKey == nil { @@ -1199,7 +1199,7 @@ func (s *Ethereum) StartMining(ctx context.Context, db kv.RwDB, stateDiffClient // validator defined in the bor validator set and non mining nodes will reject all blocks // this assumes in this mode we're only running a single validator - if s.chainConfig.ChainName == networkname.BorDevnetChainName && s.config.WithoutHeimdall { + if s.chainConfig.ChainName == networkname.BorDevnet && s.config.WithoutHeimdall { borcfg.Authorize(eb, func(addr libcommon.Address, _ string, _ []byte) ([]byte, error) { return nil, &valset.UnauthorizedSignerError{Number: 0, Signer: addr.Bytes()} }) diff --git a/go.mod b/go.mod index f1a1589a24e..30bd449f341 100644 --- a/go.mod +++ b/go.mod @@ -164,7 +164,7 @@ require ( github.com/docker/go-units v0.5.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/elastic/gosigar v0.14.2 // indirect - github.com/erigontech/erigon-snapshot v1.3.1-0.20240814160410-2ce37904b978 // indirect + github.com/erigontech/erigon-snapshot v1.3.1-0.20241023024258-f64407a77e8e // indirect github.com/flynn/noise v1.1.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect diff --git a/go.sum b/go.sum index 45c2689b4ac..e6dee503a1c 100644 --- a/go.sum +++ b/go.sum @@ -268,8 +268,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/erigontech/erigon-snapshot v1.3.1-0.20240814160410-2ce37904b978 h1:7ECOf7Us3+/706WGZXIX84qQc6zmxQby8fGbFLiqFlU= -github.com/erigontech/erigon-snapshot v1.3.1-0.20240814160410-2ce37904b978/go.mod h1:ooHlCl+eEYzebiPu+FP6Q6SpPUeMADn8Jxabv3IKb9M= +github.com/erigontech/erigon-snapshot v1.3.1-0.20241023024258-f64407a77e8e h1:ZpIO6HeopuZPYDLldL6zR0qyRezj80kQrDOGEF779ts= +github.com/erigontech/erigon-snapshot v1.3.1-0.20241023024258-f64407a77e8e/go.mod h1:ooHlCl+eEYzebiPu+FP6Q6SpPUeMADn8Jxabv3IKb9M= github.com/erigontech/erigonwatch v0.0.0-20240718131902-b6576bde1116 h1:KCFa2uXEfZoBjV4buzjWmCmoqVLXiGCq0ZmQ2OjeRvQ= github.com/erigontech/erigonwatch v0.0.0-20240718131902-b6576bde1116/go.mod h1:8vQ+VjvLu2gkPs8EwdPrOTAAo++WuLuBi54N7NuAF0I= github.com/erigontech/mdbx-go v0.38.4 h1:S9T7mTe9KPcFe4dOoOtVdI6gPzht9y7wMnYfUBgrQLo= diff --git a/p2p/sentry/simulator/sentry_simulator.go b/p2p/sentry/simulator/sentry_simulator.go index 4bb69c3f9b7..51c7666ba81 100644 --- a/p2p/sentry/simulator/sentry_simulator.go +++ b/p2p/sentry/simulator/sentry_simulator.go @@ -109,7 +109,7 @@ func NewSentry(ctx context.Context, chain string, snapshotLocation string, peerC } config := sync.NewDefaultTorrentClientConfig(chain, snapshotLocation, logger) - downloader, err := sync.NewTorrentClient(config) + downloader, err := sync.NewTorrentClient(ctx, config) if err != nil { return nil, err diff --git a/params/bootnodes.go b/params/bootnodes.go index a9dd3c20e09..6e7db03332f 100644 --- a/params/bootnodes.go +++ b/params/bootnodes.go @@ -140,19 +140,19 @@ func KnownDNSNetwork(genesis libcommon.Hash, protocol string) string { func BootnodeURLsOfChain(chain string) []string { switch chain { - case networkname.MainnetChainName: + case networkname.Mainnet: return MainnetBootnodes - case networkname.HoleskyChainName: + case networkname.Holesky: return HoleskyBootnodes - case networkname.SepoliaChainName: + case networkname.Sepolia: return SepoliaBootnodes - case networkname.AmoyChainName: + case networkname.Amoy: return AmoyBootnodes - case networkname.BorMainnetChainName: + case networkname.BorMainnet: return BorMainnetBootnodes - case networkname.GnosisChainName: + case networkname.Gnosis: return GnosisBootnodes - case networkname.ChiadoChainName: + case networkname.Chiado: return ChiadoBootnodes default: return []string{} @@ -161,7 +161,7 @@ func BootnodeURLsOfChain(chain string) []string { func StaticPeerURLsOfChain(chain string) []string { switch chain { - case networkname.SepoliaChainName: + case networkname.Sepolia: return SepoliaStaticPeers default: return []string{} diff --git a/params/config.go b/params/config.go index 70b31615917..681e5856a37 100644 --- a/params/config.go +++ b/params/config.go @@ -206,23 +206,23 @@ func NewSnapshotConfig(checkpointInterval uint64, inmemorySnapshots int, inmemor func ChainConfigByChainName(chain string) *chain.Config { switch chain { - case networkname.MainnetChainName: + case networkname.Mainnet: return MainnetChainConfig - case networkname.DevChainName: + case networkname.Dev: return AllCliqueProtocolChanges - case networkname.HoleskyChainName: + case networkname.Holesky: return HoleskyChainConfig - case networkname.SepoliaChainName: + case networkname.Sepolia: return SepoliaChainConfig - case networkname.AmoyChainName: + case networkname.Amoy: return AmoyChainConfig - case networkname.BorMainnetChainName: + case networkname.BorMainnet: return BorMainnetChainConfig - case networkname.BorDevnetChainName: + case networkname.BorDevnet: return BorDevnetChainConfig - case networkname.GnosisChainName: + case networkname.Gnosis: return GnosisChainConfig - case networkname.ChiadoChainName: + case networkname.Chiado: return ChiadoChainConfig case networkname.Test: return TestChainConfig @@ -233,21 +233,21 @@ func ChainConfigByChainName(chain string) *chain.Config { func GenesisHashByChainName(chain string) *libcommon.Hash { switch chain { - case networkname.MainnetChainName: + case networkname.Mainnet: return &MainnetGenesisHash - case networkname.HoleskyChainName: + case networkname.Holesky: return &HoleskyGenesisHash - case networkname.SepoliaChainName: + case networkname.Sepolia: return &SepoliaGenesisHash - case networkname.AmoyChainName: + case networkname.Amoy: return &AmoyGenesisHash - case networkname.BorMainnetChainName: + case networkname.BorMainnet: return &BorMainnetGenesisHash - case networkname.BorDevnetChainName: + case networkname.BorDevnet: return &BorDevnetGenesisHash - case networkname.GnosisChainName: + case networkname.Gnosis: return &GnosisGenesisHash - case networkname.ChiadoChainName: + case networkname.Chiado: return &ChiadoGenesisHash case networkname.Test: return &TestGenesisHash diff --git a/polygon/bor/snaptype/types.go b/polygon/bor/snaptype/types.go index 45c49315948..74862bbab81 100644 --- a/polygon/bor/snaptype/types.go +++ b/polygon/bor/snaptype/types.go @@ -54,8 +54,8 @@ func initTypes() { borTypes := append(coresnaptype.BlockSnapshotTypes, BorSnapshotTypes()...) borTypes = append(borTypes, coresnaptype.E3StateTypes...) - snapcfg.RegisterKnownTypes(networkname.AmoyChainName, borTypes) - snapcfg.RegisterKnownTypes(networkname.BorMainnetChainName, borTypes) + snapcfg.RegisterKnownTypes(networkname.Amoy, borTypes) + snapcfg.RegisterKnownTypes(networkname.BorMainnet, borTypes) } var Enums = struct { diff --git a/polygon/bor/spanner_test_validators.go b/polygon/bor/spanner_test_validators.go index df3b1462269..5f002fdddbe 100644 --- a/polygon/bor/spanner_test_validators.go +++ b/polygon/bor/spanner_test_validators.go @@ -52,6 +52,6 @@ var BorDevnetChainVals = []*valset.Validator{ } func init() { - NetworkNameVals[networkname.BorE2ETestChain2ValName] = BorE2ETestChain2Valset - NetworkNameVals[networkname.BorDevnetChainName] = BorDevnetChainVals + NetworkNameVals[networkname.BorE2ETestChain2Val] = BorE2ETestChain2Valset + NetworkNameVals[networkname.BorDevnet] = BorDevnetChainVals } diff --git a/tests/bor/helper/miner.go b/tests/bor/helper/miner.go index 6a8e95563d3..67dbcf8ec69 100644 --- a/tests/bor/helper/miner.go +++ b/tests/bor/helper/miner.go @@ -124,7 +124,7 @@ func InitMiner(ctx context.Context, dirName string, genesis *types.Genesis, priv return nil, nil, err } - downloaderConfig, err := downloadercfg.New(datadir.New(dirName), nodeCfg.Version, torrentLogLevel, downloadRate, uploadRate, utils.TorrentPortFlag.Value, utils.TorrentConnsPerFileFlag.Value, utils.TorrentDownloadSlotsFlag.Value, []string{}, []string{}, "", true, utils.DbWriteMapFlag.Value) + downloaderConfig, err := downloadercfg.New(ctx, datadir.New(dirName), nodeCfg.Version, torrentLogLevel, downloadRate, uploadRate, utils.TorrentPortFlag.Value, utils.TorrentConnsPerFileFlag.Value, utils.TorrentDownloadSlotsFlag.Value, []string{}, []string{}, "", true, utils.DbWriteMapFlag.Value) if err != nil { return nil, nil, err } diff --git a/tests/bor/mining_test.go b/tests/bor/mining_test.go index f1761ddf10c..2c9d7eed4db 100644 --- a/tests/bor/mining_test.go +++ b/tests/bor/mining_test.go @@ -62,7 +62,7 @@ func TestMiningBenchmark(t *testing.T) { log.Root().SetHandler(log.LvlFilterHandler(log.LvlWarn, log.StreamHandler(os.Stderr, log.TerminalFormat()))) fdlimit.Raise(2048) - genesis := helper.InitGenesis("./testdata/genesis_2val.json", 64, networkname.BorE2ETestChain2ValName) + genesis := helper.InitGenesis("./testdata/genesis_2val.json", 64, networkname.BorE2ETestChain2Val) var stacks []*node.Node var ethbackends []*eth.Ethereum var enodes []string diff --git a/turbo/app/import_cmd.go b/turbo/app/import_cmd.go index d264fe5c386..ba0f9622b1e 100644 --- a/turbo/app/import_cmd.go +++ b/turbo/app/import_cmd.go @@ -82,7 +82,10 @@ func importChain(cliCtx *cli.Context) error { return err } - nodeCfg := turboNode.NewNodConfigUrfave(cliCtx, logger) + nodeCfg, err := turboNode.NewNodConfigUrfave(cliCtx, logger) + if err != nil { + return err + } ethCfg := turboNode.NewEthConfigUrfave(cliCtx, nodeCfg, logger) stack := makeConfigNode(cliCtx.Context, nodeCfg, logger) diff --git a/turbo/app/init_cmd.go b/turbo/app/init_cmd.go index 269af34b13c..403b087135b 100644 --- a/turbo/app/init_cmd.go +++ b/turbo/app/init_cmd.go @@ -77,7 +77,10 @@ func initGenesis(cliCtx *cli.Context) error { } // Open and initialise both full and light databases - stack := MakeConfigNodeDefault(cliCtx, logger) + stack, err := MakeNodeWithDefaultConfig(cliCtx, logger) + if err != nil { + return err + } defer stack.Close() chaindb, err := node.OpenDatabase(cliCtx.Context, stack.Config(), kv.ChainDB, "", false, logger) diff --git a/turbo/app/make_app.go b/turbo/app/make_app.go index 1e0b76032ad..2d8e2f850fa 100644 --- a/turbo/app/make_app.go +++ b/turbo/app/make_app.go @@ -166,10 +166,13 @@ func doMigrateFlags(ctx *cli.Context) { } } -func NewNodeConfig(ctx *cli.Context, logger log.Logger) *nodecfg.Config { - nodeConfig := enode.NewNodConfigUrfave(ctx, logger) +func NewNodeConfig(ctx *cli.Context, logger log.Logger) (*nodecfg.Config, error) { + nodeConfig, err := enode.NewNodConfigUrfave(ctx, logger) + if err != nil { + return nil, err + } - // see simiar changes in `cmd/geth/config.go#defaultNodeConfig` + // see similar changes in `cmd/geth/config.go#defaultNodeConfig` if commit := params.GitCommit; commit != "" { nodeConfig.Version = params.VersionWithCommit(commit) } else { @@ -183,11 +186,15 @@ func NewNodeConfig(ctx *cli.Context, logger log.Logger) *nodecfg.Config { nodeConfig.Dirs = datadir.New(ctx.String(utils.DataDirFlag.Name)) } - return nodeConfig + return nodeConfig, nil } -func MakeConfigNodeDefault(cliCtx *cli.Context, logger log.Logger) *node.Node { - return makeConfigNode(cliCtx.Context, NewNodeConfig(cliCtx, logger), logger) +func MakeNodeWithDefaultConfig(cliCtx *cli.Context, logger log.Logger) (*node.Node, error) { + conf, err := NewNodeConfig(cliCtx, logger) + if err != nil { + return nil, err + } + return makeConfigNode(cliCtx.Context, conf, logger), nil } func makeConfigNode(ctx context.Context, config *nodecfg.Config, logger log.Logger) *node.Node { diff --git a/turbo/app/snapshots_cmd.go b/turbo/app/snapshots_cmd.go index b9d2666838f..d55c5682b10 100644 --- a/turbo/app/snapshots_cmd.go +++ b/turbo/app/snapshots_cmd.go @@ -1409,7 +1409,10 @@ func doUploaderCommand(cliCtx *cli.Context) error { erigonInfoGauge := metrics.GetOrCreateGauge(fmt.Sprintf(`erigon_info{version="%s",commit="%s"}`, params.Version, params.GitCommit)) erigonInfoGauge.Set(1) - nodeCfg := node.NewNodConfigUrfave(cliCtx, logger) + nodeCfg, err := node.NewNodConfigUrfave(cliCtx, logger) + if err != nil { + return err + } if err := datadir.ApplyMigrations(nodeCfg.Dirs); err != nil { return err } diff --git a/turbo/node/node.go b/turbo/node/node.go index 30d8d608ac9..f3658852b78 100644 --- a/turbo/node/node.go +++ b/turbo/node/node.go @@ -81,23 +81,23 @@ type Params struct { CustomBuckets kv.TableCfg } -func NewNodConfigUrfave(ctx *cli.Context, logger log.Logger) *nodecfg.Config { +func NewNodConfigUrfave(ctx *cli.Context, logger log.Logger) (*nodecfg.Config, error) { // If we're running a known preset, log it for convenience. chain := ctx.String(utils.ChainFlag.Name) switch chain { - case networkname.HoleskyChainName: + case networkname.Holesky: logger.Info("Starting Erigon on Holesky testnet...") - case networkname.SepoliaChainName: + case networkname.Sepolia: logger.Info("Starting Erigon on Sepolia testnet...") - case networkname.DevChainName: + case networkname.Dev: logger.Info("Starting Erigon in ephemeral dev mode...") - case networkname.AmoyChainName: + case networkname.Amoy: logger.Info("Starting Erigon on Amoy testnet...") - case networkname.BorMainnetChainName: + case networkname.BorMainnet: logger.Info("Starting Erigon on Bor Mainnet...") - case networkname.BorDevnetChainName: + case networkname.BorDevnet: logger.Info("Starting Erigon on Bor Devnet...") - case "", networkname.MainnetChainName: + case "", networkname.Mainnet: if !ctx.IsSet(utils.NetworkIdFlag.Name) { logger.Info("Starting Erigon on Ethereum mainnet...") } @@ -106,9 +106,11 @@ func NewNodConfigUrfave(ctx *cli.Context, logger log.Logger) *nodecfg.Config { } nodeConfig := NewNodeConfig() - utils.SetNodeConfig(ctx, nodeConfig, logger) + if err := utils.SetNodeConfig(ctx, nodeConfig, logger); err != nil { + return nil, err + } erigoncli.ApplyFlagsForNodeConfig(ctx, nodeConfig, logger) - return nodeConfig + return nodeConfig, nil } func NewEthConfigUrfave(ctx *cli.Context, nodeConfig *nodecfg.Config, logger log.Logger) *ethconfig.Config { ethConfig := ethconfig.Defaults // Needs to be a copy, not pointer diff --git a/turbo/snapshotsync/freezeblocks/block_reader_test.go b/turbo/snapshotsync/freezeblocks/block_reader_test.go index 2b3232742a5..61cd67631bb 100644 --- a/turbo/snapshotsync/freezeblocks/block_reader_test.go +++ b/turbo/snapshotsync/freezeblocks/block_reader_test.go @@ -44,7 +44,7 @@ func TestBlockReaderLastFrozenSpanIdWhenSegmentFilesArePresent(t *testing.T) { dir := t.TempDir() createTestBorEventSegmentFile(t, 0, 500_000, 132, dir, logger) createTestSegmentFile(t, 0, 500_000, borsnaptype.Enums.BorSpans, dir, 1, logger) - borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnetChainName}, dir, 0, logger) + borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnet}, dir, 0, logger) defer borRoSnapshots.Close() err := borRoSnapshots.OpenFolder() require.NoError(t, err) @@ -58,7 +58,7 @@ func TestBlockReaderLastFrozenSpanIdWhenSegmentFilesAreNotPresent(t *testing.T) logger := testlog.Logger(t, log.LvlInfo) dir := t.TempDir() - borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnetChainName}, dir, 0, logger) + borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnet}, dir, 0, logger) defer borRoSnapshots.Close() err := borRoSnapshots.OpenFolder() require.NoError(t, err) @@ -82,7 +82,7 @@ func TestBlockReaderLastFrozenSpanIdReturnsLastSegWithIdx(t *testing.T) { idxFileToDelete := filepath.Join(dir, snaptype.IdxFileName(1, 1_000_000, 1_500_000, borsnaptype.BorSpans.Name())) err := os.Remove(idxFileToDelete) require.NoError(t, err) - borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnetChainName}, dir, 0, logger) + borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnet}, dir, 0, logger) defer borRoSnapshots.Close() err = borRoSnapshots.OpenFolder() require.NoError(t, err) @@ -112,7 +112,7 @@ func TestBlockReaderLastFrozenSpanIdReturnsZeroWhenAllSegmentsDoNotHaveIdx(t *te idxFileToDelete = filepath.Join(dir, snaptype.IdxFileName(1, 1_000_000, 1_500_000, borsnaptype.BorSpans.Name())) err = os.Remove(idxFileToDelete) require.NoError(t, err) - borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnetChainName}, dir, 0, logger) + borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnet}, dir, 0, logger) defer borRoSnapshots.Close() err = borRoSnapshots.OpenFolder() require.NoError(t, err) @@ -128,7 +128,7 @@ func TestBlockReaderLastFrozenEventIdWhenSegmentFilesArePresent(t *testing.T) { dir := t.TempDir() createTestBorEventSegmentFile(t, 0, 500_000, 132, dir, logger) createTestSegmentFile(t, 0, 500_000, borsnaptype.Enums.BorSpans, dir, 1, logger) - borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnetChainName}, dir, 0, logger) + borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnet}, dir, 0, logger) defer borRoSnapshots.Close() err := borRoSnapshots.OpenFolder() require.NoError(t, err) @@ -142,7 +142,7 @@ func TestBlockReaderLastFrozenEventIdWhenSegmentFilesAreNotPresent(t *testing.T) logger := testlog.Logger(t, log.LvlInfo) dir := t.TempDir() - borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnetChainName}, dir, 0, logger) + borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnet}, dir, 0, logger) defer borRoSnapshots.Close() err := borRoSnapshots.OpenFolder() require.NoError(t, err) @@ -166,7 +166,7 @@ func TestBlockReaderLastFrozenEventIdReturnsLastSegWithIdx(t *testing.T) { idxFileToDelete := filepath.Join(dir, snaptype.IdxFileName(1, 1_000_000, 1_500_000, borsnaptype.BorEvents.Name())) err := os.Remove(idxFileToDelete) require.NoError(t, err) - borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnetChainName}, dir, 0, logger) + borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnet}, dir, 0, logger) defer borRoSnapshots.Close() err = borRoSnapshots.OpenFolder() require.NoError(t, err) @@ -196,7 +196,7 @@ func TestBlockReaderLastFrozenEventIdReturnsZeroWhenAllSegmentsDoNotHaveIdx(t *t idxFileToDelete = filepath.Join(dir, snaptype.IdxFileName(1, 1_000_000, 1_500_000, borsnaptype.BorEvents.Name())) err = os.Remove(idxFileToDelete) require.NoError(t, err) - borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnetChainName}, dir, 0, logger) + borRoSnapshots := NewBorRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.BorMainnet}, dir, 0, logger) defer borRoSnapshots.Close() err = borRoSnapshots.OpenFolder() require.NoError(t, err) diff --git a/turbo/snapshotsync/freezeblocks/block_snapshots_test.go b/turbo/snapshotsync/freezeblocks/block_snapshots_test.go index 26ee815ec42..075bac18ef9 100644 --- a/turbo/snapshotsync/freezeblocks/block_snapshots_test.go +++ b/turbo/snapshotsync/freezeblocks/block_snapshots_test.go @@ -212,7 +212,7 @@ func TestMergeSnapshots(t *testing.T) { for i := uint64(0); i < N; i++ { createFile(i*10_000, (i+1)*10_000) } - s := NewRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.MainnetChainName}, dir, 0, logger) + s := NewRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.Mainnet}, dir, 0, logger) defer s.Close() require.NoError(s.OpenFolder()) { @@ -308,7 +308,7 @@ func TestDeleteSnapshots(t *testing.T) { for i := uint64(0); i < N; i++ { createFile(i*10_000, (i+1)*10_000) } - s := NewRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.MainnetChainName}, dir, 0, logger) + s := NewRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.Mainnet}, dir, 0, logger) defer s.Close() retireFiles := []string{ "v1-000000-000010-bodies.seg", @@ -353,7 +353,7 @@ func TestRemoveOverlaps(t *testing.T) { createFile(200_000+i*10_000, 200_000+(i+1)*10_000) } - s := NewRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.MainnetChainName}, dir, 0, logger) + s := NewRoSnapshots(ethconfig.BlocksFreezing{ChainName: networkname.Mainnet}, dir, 0, logger) defer s.Close() require.NoError(s.OpenSegments(coresnaptype.BlockSnapshotTypes, false)) @@ -403,7 +403,7 @@ func TestOpenAllSnapshot(t *testing.T) { steps := []uint64{500_000, 100_000} - for i, chain := range []string{networkname.MainnetChainName, networkname.AmoyChainName} { + for i, chain := range []string{networkname.Mainnet, networkname.Amoy} { step := steps[i] dir := filepath.Join(baseDir, chain) chainSnapshotCfg := snapcfg.KnownCfg(chain) @@ -547,7 +547,7 @@ func TestCalculateVisibleSegments(t *testing.T) { for i := uint64(0); i < 5; i++ { createFile(i*500_000, (i+1)*500_000, coresnaptype.Transactions) } - cfg := ethconfig.BlocksFreezing{ChainName: networkname.MainnetChainName} + cfg := ethconfig.BlocksFreezing{ChainName: networkname.Mainnet} s := NewRoSnapshots(cfg, dir, 0, logger) defer s.Close() @@ -617,7 +617,7 @@ func TestCalculateVisibleSegmentsWhenGapsInIdx(t *testing.T) { err := os.Remove(missingIdxFile) require.NoError(err) - cfg := ethconfig.BlocksFreezing{ChainName: networkname.MainnetChainName} + cfg := ethconfig.BlocksFreezing{ChainName: networkname.Mainnet} s := NewRoSnapshots(cfg, dir, 0, logger) defer s.Close() diff --git a/turbo/snapshotsync/freezeblocks/dump_test.go b/turbo/snapshotsync/freezeblocks/dump_test.go index 54fc0124f6a..24084d4bde6 100644 --- a/turbo/snapshotsync/freezeblocks/dump_test.go +++ b/turbo/snapshotsync/freezeblocks/dump_test.go @@ -264,7 +264,7 @@ func TestDump(t *testing.T) { logger := log.New() tmpDir, snapDir := t.TempDir(), t.TempDir() - snConfig := snapcfg.KnownCfg(networkname.MainnetChainName) + snConfig := snapcfg.KnownCfg(networkname.Mainnet) snConfig.ExpectBlocks = math.MaxUint64 err := freezeblocks.DumpBlocks(m.Ctx, 0, uint64(test.chainSize), m.ChainConfig, tmpDir, snapDir, m.DB, 1, log.LvlInfo, logger, m.BlockReader)