erigon-pulse/cl/antiquary/antiquary.go
Giulio rebuffo 8f29ca7405
Same range parallel downloader (#8554)
will do a more advanced version later
2023-10-22 17:30:27 +02:00

47 lines
1.1 KiB
Go

package antiquary
import (
"context"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/cl/clparams"
"github.com/ledgerwatch/erigon/cl/persistence"
)
type Downloader struct {
source persistence.BlockSource
config *clparams.BeaconChainConfig
beacondDB persistence.BeaconChainDatabase
}
func NewDownloader(
beacondDB persistence.BeaconChainDatabase,
source persistence.BlockSource,
config *clparams.BeaconChainConfig,
) *Downloader {
return &Downloader{
beacondDB: beacondDB,
source: source,
config: config,
}
}
func (d *Downloader) DownloadEpoch(tx kv.RwTx, ctx context.Context, epoch uint64) error {
// convert the epoch to a block
startBlock := epoch * d.config.SlotsPerEpoch
blocks, err := d.source.GetRange(ctx, tx, startBlock, d.config.SlotsPerEpoch)
if err != nil {
return err
}
// NOTE: the downloader does not perform any real verification on these blocks
// validation must be done separately
for _, v := range blocks.Data {
err := d.beacondDB.WriteBlock(ctx, tx, v, true)
if err != nil {
return err
}
}
return nil
}