Skip to content

Commit

Permalink
Fix preverified toml (#12132)
Browse files Browse the repository at this point in the history
Moved code which set preverified files list from preverified.toml before
torrent whitelist is generated.
Fix for #12031
  • Loading branch information
dvovk authored Sep 29, 2024
1 parent 40bb103 commit 443fabe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
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

0 comments on commit 443fabe

Please sign in to comment.