erigon-pulse/cl/antiquary/antiquary.go

47 lines
1.1 KiB
Go
Raw Normal View History

2023-08-16 02:32:40 +00:00
package antiquary
import (
"context"
2023-09-14 00:56:29 +00:00
"database/sql"
2023-08-16 02:32:40 +00:00
"github.com/ledgerwatch/erigon/cl/clparams"
"github.com/ledgerwatch/erigon/cl/persistence"
2023-08-16 02:32:40 +00:00
)
type Downloader struct {
source persistence.BlockSource
config *clparams.BeaconChainConfig
beacondDB persistence.BeaconChainDatabase
2023-08-16 02:32:40 +00:00
}
func NewDownloader(
beacondDB persistence.BeaconChainDatabase,
source persistence.BlockSource,
2023-08-16 02:32:40 +00:00
config *clparams.BeaconChainConfig,
) *Downloader {
return &Downloader{
beacondDB: beacondDB,
source: source,
config: config,
2023-08-16 02:32:40 +00:00
}
}
2023-09-14 00:56:29 +00:00
func (d *Downloader) DownloadEpoch(tx *sql.Tx, ctx context.Context, epoch uint64) error {
2023-08-16 02:32:40 +00:00
// convert the epoch to a block
startBlock := epoch * d.config.SlotsPerEpoch
2023-09-14 00:56:29 +00:00
blocks, err := d.source.GetRange(tx, ctx, startBlock, d.config.SlotsPerEpoch)
2023-08-16 02:32:40 +00:00
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 {
2023-09-14 00:56:29 +00:00
err := d.beacondDB.WriteBlock(tx, ctx, v.Data, true)
2023-08-16 02:32:40 +00:00
if err != nil {
return err
}
}
return nil
}