Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix preverified toml #12132

Merged
merged 5 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions erigon-lib/downloader/downloadercfg/downloadercfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ func New(dirs datadir.Dirs, version string, verbosity lg.Level, downloadRate, up
webseedFileProviders = append(webseedFileProviders, localCfgFile)
}

// setup snapcfg
if err := loadSnapshotsEitherFromDiskIfNeeded(dirs, chainName); err != nil {
return nil, err
}

return &Cfg{Dirs: dirs, ChainName: chainName,
ClientConfig: torrentConfig, DownloadSlots: downloadSlots,
WebSeedUrls: webseedHttpProviders, WebSeedFileProviders: webseedFileProviders,
Expand All @@ -227,6 +232,25 @@ func New(dirs datadir.Dirs, version string, verbosity lg.Level, downloadRate, up
}, nil
}

func loadSnapshotsEitherFromDiskIfNeeded(dirs datadir.Dirs, chainName string) error {
preverifiedToml := filepath.Join(dirs.Snap, "preverified.toml")

exists, err := dir.FileExist(preverifiedToml)
if err != nil {
return err
}
if exists {
// Read the preverified.toml and load the snapshots
haveToml, err := os.ReadFile(preverifiedToml)
if err != nil {
return err
}
snapcfg.SetToml(chainName, haveToml)
return nil
}
return dir.WriteFileWithFsync(preverifiedToml, snapcfg.GetToml(chainName), 0644)
}

func getIpv6Enabled() bool {
if runtime.GOOS == "linux" {
file, err := os.ReadFile("/sys/module/ipv6/parameters/disable")
Expand Down
25 changes: 0 additions & 25 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,11 +728,6 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
ethashApi = casted.APIs(nil)[1].Service.(*ethash.API)
}

// setup snapcfg
if err := loadSnapshotsEitherFromDiskIfNeeded(dirs, chainConfig.ChainName); err != nil {
return nil, err
}

// proof-of-stake mining
assembleBlockPOS := func(param *core.BlockBuilderParameters, interrupt *int32) (*types.BlockWithReceipts, error) {
miningStatePos := stagedsync.NewMiningState(&config.Miner)
Expand Down Expand Up @@ -1336,26 +1331,6 @@ func (s *Ethereum) StartMining(ctx context.Context, db kv.RwDB, stateDiffClient
return nil
}

// loadSnapshotsEitherFromDiskOrRemotely loads the snapshots to be downloaded from the disk if they exist, otherwise it loads them from the remote.
func loadSnapshotsEitherFromDiskIfNeeded(dirs datadir.Dirs, chainName string) error {
preverifiedToml := filepath.Join(dirs.Snap, "preverified.toml")

exists, err := dir.FileExist(preverifiedToml)
if err != nil {
return err
}
if exists {
// Read the preverified.toml and load the snapshots
haveToml, err := os.ReadFile(preverifiedToml)
if err != nil {
return err
}
snapcfg.SetToml(chainName, haveToml)
return nil
}
return dir.WriteFileWithFsync(preverifiedToml, snapcfg.GetToml(chainName), 0644)
}

func (s *Ethereum) IsMining() bool { return s.config.Miner.Enabled }

func (s *Ethereum) ChainKV() kv.RwDB { return s.chainDB }
Expand Down
Loading