mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
c477281362
What does this PR do: * Optional Backfilling and Caplin Archive Node * Create antiquary for historical states * Fixed gaps of chain gap related to the Head of the chain and anchor of the chain. * Added basic reader object to Read the Historical state
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package persistence
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"os"
|
|
"sync"
|
|
|
|
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
|
"github.com/ledgerwatch/erigon/cl/clparams"
|
|
"github.com/spf13/afero"
|
|
"go.uber.org/zap/buffer"
|
|
)
|
|
|
|
var bPool = sync.Pool{
|
|
New: func() interface{} {
|
|
return &buffer.Buffer{}
|
|
},
|
|
}
|
|
|
|
type aferoRawBeaconBlockChain struct {
|
|
fs afero.Fs
|
|
cfg *clparams.BeaconChainConfig
|
|
}
|
|
|
|
func NewAferoRawBlockSaver(fs afero.Fs, cfg *clparams.BeaconChainConfig) RawBeaconBlockChain {
|
|
return aferoRawBeaconBlockChain{
|
|
fs: fs,
|
|
cfg: cfg,
|
|
}
|
|
}
|
|
|
|
func AferoRawBeaconBlockChainFromOsPath(cfg *clparams.BeaconChainConfig, path string) (RawBeaconBlockChain, afero.Fs) {
|
|
dataDirFs := afero.NewBasePathFs(afero.NewOsFs(), path)
|
|
return NewAferoRawBlockSaver(dataDirFs, cfg), dataDirFs
|
|
}
|
|
|
|
func (a aferoRawBeaconBlockChain) BlockWriter(ctx context.Context, slot uint64, blockRoot libcommon.Hash) (io.WriteCloser, error) {
|
|
folderPath, path := rootToPaths(slot, blockRoot, a.cfg)
|
|
_ = a.fs.MkdirAll(folderPath, 0o755)
|
|
return a.fs.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0o755)
|
|
}
|
|
|
|
func (a aferoRawBeaconBlockChain) BlockReader(ctx context.Context, slot uint64, blockRoot libcommon.Hash) (io.ReadCloser, error) {
|
|
_, path := rootToPaths(slot, blockRoot, a.cfg)
|
|
return a.fs.OpenFile(path, os.O_RDONLY, 0o755)
|
|
}
|
|
|
|
func (a aferoRawBeaconBlockChain) DeleteBlock(ctx context.Context, slot uint64, blockRoot libcommon.Hash) error {
|
|
_, path := rootToPaths(slot, blockRoot, a.cfg)
|
|
return a.fs.Remove(path)
|
|
}
|