Skip to content

Commit

Permalink
downloader: don't block erigon startup if devs deploy new hashes (of …
Browse files Browse the repository at this point in the history
…same files) (#10761)
  • Loading branch information
AskAlexSharov authored Jun 17, 2024
1 parent fabed0c commit cac1c2d
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions erigon-lib/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,6 @@ func New(ctx context.Context, cfg *downloadercfg.Cfg, logger log.Logger, verbosi
d.ctx, d.stopMainLoop = context.WithCancel(ctx)

if cfg.AddTorrentsFromDisk {
var downloadMismatches []string

for _, download := range lock.Downloads {
if info, err := d.torrentInfo(download.Name); err == nil {
if info.Completed != nil {
Expand All @@ -357,29 +355,15 @@ func New(ctx context.Context, cfg *downloadercfg.Cfg, logger log.Logger, verbosi
fileHash := hex.EncodeToString(fileHashBytes)

if fileHash != download.Hash && fileHash != hash {
d.logger.Error("[snapshots] download db mismatch", "file", download.Name, "lock", download.Hash, "db", hash, "disk", fileHash, "downloaded", *info.Completed)
downloadMismatches = append(downloadMismatches, download.Name)
d.logger.Debug("[snapshots] download db mismatch", "file", download.Name, "lock", download.Hash, "db", hash, "disk", fileHash, "downloaded", *info.Completed)
} else {
d.logger.Warn("[snapshots] lock hash does not match completed download", "file", download.Name, "lock", hash, "download", download.Hash, "downloaded", *info.Completed)
d.logger.Debug("[snapshots] lock hash does not match completed download", "file", download.Name, "lock", hash, "download", download.Hash, "downloaded", *info.Completed)
}
}
}
}
}

if len(downloadMismatches) > 0 {
return nil, fmt.Errorf("downloaded files have mismatched hashes: %s", strings.Join(downloadMismatches, ","))
}

//TODO: why do we need it if we have `addTorrentFilesFromDisk`? what if they are conflict?
//TODO: why it's before `BuildTorrentFilesIfNeed`? what if they are conflict?
//TODO: even if hash is saved in "snapshots-lock.json" - it still must preserve `prohibit_new_downloads.lock` and don't download new files ("user restart" must be fast, "erigon3 has .kv files which never-ending merge and delete small files")
//for _, it := range lock.Downloads {
// if err := d.AddMagnetLink(ctx, snaptype.Hex2InfoHash(it.Hash), it.Name); err != nil {
// return nil, err
// }
//}

if err := d.BuildTorrentFilesIfNeed(d.ctx, lock.Chain, lock.Downloads); err != nil {
return nil, err
}
Expand Down

0 comments on commit cac1c2d

Please sign in to comment.