internal/era/eradl: add DownloadEpochRange

This commit is contained in:
Felix Lange 2025-05-14 09:59:15 +02:00
parent 925f5d2c0c
commit 4159c31216

View file

@ -86,21 +86,25 @@ func (l *Loader) DownloadAll(destDir string) error {
// DownloadBlockRange fetches the era1 files for the given block range. // DownloadBlockRange fetches the era1 files for the given block range.
func (l *Loader) DownloadBlockRange(start, end uint64, destDir string) error { func (l *Loader) DownloadBlockRange(start, end uint64, destDir string) error {
startEpoch := int(start / uint64(era.MaxEra1Size)) startEpoch := start / uint64(era.MaxEra1Size)
endEpoch := int(end / uint64(era.MaxEra1Size)) endEpoch := end / uint64(era.MaxEra1Size)
return l.DownloadEpochRange(startEpoch, endEpoch, destDir)
}
// DownloadEpochRange fetches the era1 files in the given epoch range.
func (l *Loader) DownloadEpochRange(start, end uint64, destDir string) error {
pat := regexp.MustCompile(regexp.QuoteMeta(l.network) + "-([0-9]+)-[0-9a-f]+\\.era1") pat := regexp.MustCompile(regexp.QuoteMeta(l.network) + "-([0-9]+)-[0-9a-f]+\\.era1")
for file := range l.csdb.Files() { for file := range l.csdb.Files() {
m := pat.FindStringSubmatch(file) m := pat.FindStringSubmatch(file)
if len(m) == 2 { if len(m) == 2 {
fileEpoch, _ := strconv.Atoi(m[1]) fileEpoch, _ := strconv.Atoi(m[1])
if fileEpoch >= startEpoch && fileEpoch <= endEpoch { if uint64(fileEpoch) >= start && uint64(fileEpoch) <= end {
if err := l.download(file, destDir); err != nil { if err := l.download(file, destDir); err != nil {
return err return err
} }
} }
} }
} }
// TODO: detect if blocks are out available era1 range.
return nil return nil
} }