snapshotsync

package
v0.0.0-...-92d349b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2023 License: GPL-3.0 Imports: 48 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyTxHash = common2.Hash{}

Functions

func BodiesIdx

func BodiesIdx(ctx context.Context, segmentFilePath string, firstBlockNumInSegment uint64, tmpDir string, p *background.Progress, lvl log.Lvl) (err error)

func BuildMissedIndices

func BuildMissedIndices(logPrefix string, ctx context.Context, dirs datadir.Dirs, chainID uint256.Int, workers int) error

func BuildProtoRequest

func BuildProtoRequest(downloadRequest []DownloadRequest) *proto_downloader.DownloadRequest

func CanDeleteTo

func CanDeleteTo(curBlockNum uint64, snapshots *RoSnapshots) (blockTo uint64)

func CanRetire

func CanRetire(curBlockNum uint64, snapshots *RoSnapshots) (blockFrom, blockTo uint64, can bool)

func DumpBlocks

func DumpBlocks(ctx context.Context, blockFrom, blockTo, blocksPerFile uint64, tmpDir, snapDir string, chainDB kv.RoDB, workers int, lvl log.Lvl) error

func DumpBodies

func DumpBodies(ctx context.Context, db kv.RoDB, segmentFilePath, tmpDir string, blockFrom, blockTo uint64, workers int, lvl log.Lvl) error

DumpBodies - [from, to)

func DumpHeaders

func DumpHeaders(ctx context.Context, db kv.RoDB, segmentFilePath, tmpDir string, blockFrom, blockTo uint64, workers int, lvl log.Lvl) error

DumpHeaders - [from, to)

func DumpTxs

func DumpTxs(ctx context.Context, db kv.RoDB, segmentFile, tmpDir string, blockFrom, blockTo uint64, workers int, lvl log.Lvl) (firstTxID uint64, err error)

DumpTxs - [from, to) Format: hash[0]_1byte + sender_address_2bytes + txnRlp

func ForEachHeader

func ForEachHeader(ctx context.Context, s *RoSnapshots, walker func(header *types.Header) error) error

func HeadersIdx

func HeadersIdx(ctx context.Context, segmentFilePath string, firstBlockNumInSegment uint64, tmpDir string, p *background.Progress, lvl log.Lvl) (err error)

HeadersIdx - headerHash -> offset (analog of kv.HeaderNumber)

func Idx

func Idx(ctx context.Context, d *compress.Decompressor, firstDataID uint64, tmpDir string, lvl log.Lvl, walker func(idx *recsplit.RecSplit, i, offset uint64, word []byte) error) error

Idx - iterate over segment and building .idx file

func RequestSnapshotsDownload

func RequestSnapshotsDownload(ctx context.Context, downloadRequest []DownloadRequest, downloader proto_downloader.DownloaderClient) error

RequestSnapshotsDownload - builds the snapshots download request and downloads them

func TransactionsIdx

func TransactionsIdx(ctx context.Context, chainID uint256.Int, blockFrom, blockTo uint64, snapDir string, tmpDir string, p *background.Progress, lvl log.Lvl) (err error)

Types

type BackgroundResult

type BackgroundResult struct {
	// contains filtered or unexported fields
}

BackgroundResult - used only indicate that some work is done no much reason to pass exact results by this object, just get latest state when need

func (*BackgroundResult) GetAndReset

func (br *BackgroundResult) GetAndReset() (bool, error)

func (*BackgroundResult) Has

func (br *BackgroundResult) Has() bool

func (*BackgroundResult) Set

func (br *BackgroundResult) Set(err error)

type BlockReaderWithSnapshots

type BlockReaderWithSnapshots struct {
	TransactionsV3 bool
	// contains filtered or unexported fields
}

BlockReaderWithSnapshots can read blocks from db and snapshots

func NewBlockReaderWithSnapshots

func NewBlockReaderWithSnapshots(snapshots *RoSnapshots, transactionsV3 bool) *BlockReaderWithSnapshots

func (*BlockReaderWithSnapshots) BlockWithSenders

func (back *BlockReaderWithSnapshots) BlockWithSenders(ctx context.Context, tx kv.Getter, hash libcommon.Hash, blockHeight uint64) (block *types.Block, senders []libcommon.Address, err error)

func (*BlockReaderWithSnapshots) Body

func (back *BlockReaderWithSnapshots) Body(ctx context.Context, tx kv.Getter, hash libcommon.Hash, blockHeight uint64) (body *types.Body, txAmount uint32, err error)

func (*BlockReaderWithSnapshots) BodyRlp

func (back *BlockReaderWithSnapshots) BodyRlp(ctx context.Context, tx kv.Getter, hash libcommon.Hash, blockHeight uint64) (bodyRlp rlp.RawValue, err error)

func (*BlockReaderWithSnapshots) BodyWithTransactions

func (back *BlockReaderWithSnapshots) BodyWithTransactions(ctx context.Context, tx kv.Getter, hash libcommon.Hash, blockHeight uint64) (body *types.Body, err error)

func (*BlockReaderWithSnapshots) CanonicalHash

func (back *BlockReaderWithSnapshots) CanonicalHash(ctx context.Context, tx kv.Getter, blockHeight uint64) (h libcommon.Hash, err error)

func (*BlockReaderWithSnapshots) Header

func (back *BlockReaderWithSnapshots) Header(ctx context.Context, tx kv.Getter, hash libcommon.Hash, blockHeight uint64) (h *types.Header, err error)

func (*BlockReaderWithSnapshots) HeaderByHash

func (back *BlockReaderWithSnapshots) HeaderByHash(ctx context.Context, tx kv.Getter, hash libcommon.Hash) (h *types.Header, err error)

HeaderByHash - will search header in all snapshots starting from recent

func (*BlockReaderWithSnapshots) HeaderByNumber

func (back *BlockReaderWithSnapshots) HeaderByNumber(ctx context.Context, tx kv.Getter, blockHeight uint64) (h *types.Header, err error)

func (*BlockReaderWithSnapshots) Snapshots

func (back *BlockReaderWithSnapshots) Snapshots() *RoSnapshots

func (*BlockReaderWithSnapshots) TxnByIdxInBlock

func (back *BlockReaderWithSnapshots) TxnByIdxInBlock(ctx context.Context, tx kv.Getter, blockNum uint64, i int) (txn types.Transaction, err error)

TxnByIdxInBlock - doesn't include system-transactions in the begin/end of block return nil if 0 < i < body.TxAmount

func (*BlockReaderWithSnapshots) TxnEffectiveGasPricePercentage

func (back *BlockReaderWithSnapshots) TxnEffectiveGasPricePercentage(ctx context.Context, tx kv.Tx, txnHash libcommon.Hash) (uint8, error)

func (*BlockReaderWithSnapshots) TxnLookup

func (back *BlockReaderWithSnapshots) TxnLookup(ctx context.Context, tx kv.Getter, txnHash libcommon.Hash) (uint64, bool, error)

TxnLookup - find blockNumber and txnID by txnHash

type BlockRetire

type BlockRetire struct {
	// contains filtered or unexported fields
}

func NewBlockRetire

func NewBlockRetire(workers int, tmpDir string, snapshots *RoSnapshots, db kv.RoDB, downloader proto_downloader.DownloaderClient, notifier DBEventNotifier) *BlockRetire

func (*BlockRetire) NeedSaveFilesListInDB

func (br *BlockRetire) NeedSaveFilesListInDB() bool

func (*BlockRetire) PruneAncientBlocks

func (br *BlockRetire) PruneAncientBlocks(tx kv.RwTx, limit int) error

func (*BlockRetire) RetireBlocks

func (br *BlockRetire) RetireBlocks(ctx context.Context, blockFrom, blockTo uint64, lvl log.Lvl) error

func (*BlockRetire) RetireBlocksInBackground

func (br *BlockRetire) RetireBlocksInBackground(ctx context.Context, forwardProgress uint64, lvl log.Lvl)

func (*BlockRetire) Snapshots

func (br *BlockRetire) Snapshots() *RoSnapshots

type BodiesIterator

type BodiesIterator struct{}

func (BodiesIterator) ForEach

func (i BodiesIterator) ForEach(tx kv.Tx, s *RoSnapshots, f func(blockNum uint64, baseTxNum uint64, txAmount uint64) error) error

type BodySegment

type BodySegment struct {
	// contains filtered or unexported fields
}

func (*BodySegment) Iterate

func (sn *BodySegment) Iterate(f func(blockNum, baseTxNum, txAmount uint64) error) error

type DBEventNotifier

type DBEventNotifier interface {
	OnNewSnapshot()
}

type DownloadRequest

type DownloadRequest struct {
	// contains filtered or unexported fields
}

func NewDownloadRequest

func NewDownloadRequest(ranges *Range, path string, torrentHash string) DownloadRequest

type HeaderSegment

type HeaderSegment struct {
	// contains filtered or unexported fields
}

type Merger

type Merger struct {
	// contains filtered or unexported fields
}

func NewMerger

func NewMerger(tmpDir string, compressWorkers int, lvl log.Lvl, chainID uint256.Int, notifier DBEventNotifier) *Merger

func (*Merger) FindMergeRanges

func (*Merger) FindMergeRanges(currentRanges []Range) (toMerge []Range)

func (*Merger) Merge

func (m *Merger) Merge(ctx context.Context, snapshots *RoSnapshots, mergeRanges []Range, snapDir string, doIndex bool) error

Merge does merge segments in given ranges

type Range

type Range struct {
	// contains filtered or unexported fields
}

func Segments

func Segments(dir string) (res []snaptype.FileInfo, missingSnapshots []Range, err error)

func (Range) String

func (r Range) String() string

type RemoteBlockReader

type RemoteBlockReader struct {
	// contains filtered or unexported fields
}

func NewRemoteBlockReader

func NewRemoteBlockReader(client remote.ETHBACKENDClient) *RemoteBlockReader

func (*RemoteBlockReader) BlockWithSenders

func (back *RemoteBlockReader) BlockWithSenders(ctx context.Context, _ kv.Getter, hash libcommon.Hash, blockHeight uint64) (block *types.Block, senders []libcommon.Address, err error)

func (*RemoteBlockReader) Body

func (back *RemoteBlockReader) Body(ctx context.Context, tx kv.Getter, hash libcommon.Hash, blockHeight uint64) (body *types.Body, txAmount uint32, err error)

func (*RemoteBlockReader) BodyRlp

func (back *RemoteBlockReader) BodyRlp(ctx context.Context, tx kv.Getter, hash libcommon.Hash, blockHeight uint64) (bodyRlp rlp.RawValue, err error)

func (*RemoteBlockReader) BodyWithTransactions

func (back *RemoteBlockReader) BodyWithTransactions(ctx context.Context, tx kv.Getter, hash libcommon.Hash, blockHeight uint64) (body *types.Body, err error)

func (*RemoteBlockReader) CanonicalHash

func (back *RemoteBlockReader) CanonicalHash(ctx context.Context, tx kv.Getter, blockHeight uint64) (libcommon.Hash, error)

func (*RemoteBlockReader) Header

func (back *RemoteBlockReader) Header(ctx context.Context, tx kv.Getter, hash libcommon.Hash, blockHeight uint64) (*types.Header, error)

func (*RemoteBlockReader) HeaderByHash

func (back *RemoteBlockReader) HeaderByHash(ctx context.Context, tx kv.Getter, hash libcommon.Hash) (*types.Header, error)

func (*RemoteBlockReader) HeaderByNumber

func (back *RemoteBlockReader) HeaderByNumber(ctx context.Context, tx kv.Getter, blockHeight uint64) (*types.Header, error)

func (*RemoteBlockReader) Snapshots

func (back *RemoteBlockReader) Snapshots() *RoSnapshots

func (*RemoteBlockReader) TxnByIdxInBlock

func (back *RemoteBlockReader) TxnByIdxInBlock(ctx context.Context, tx kv.Getter, blockNum uint64, i int) (txn types.Transaction, err error)

func (*RemoteBlockReader) TxnEffectiveGasPricePercentage

func (back *RemoteBlockReader) TxnEffectiveGasPricePercentage(ctx context.Context, tx kv.Tx, txnHash libcommon.Hash) (uint8, error)

func (*RemoteBlockReader) TxnLookup

func (back *RemoteBlockReader) TxnLookup(ctx context.Context, tx kv.Getter, txnHash libcommon.Hash) (uint64, bool, error)

type RoSnapshots

type RoSnapshots struct {
	Headers *headerSegments
	Bodies  *bodySegments
	Txs     *txnSegments
	// contains filtered or unexported fields
}

func NewRoSnapshots

func NewRoSnapshots(cfg ethconfig.Snapshot, snapDir string) *RoSnapshots

NewRoSnapshots - opens all snapshots. But to simplify everything:

  • it opens snapshots only on App start and immutable after
  • all snapshots of given blocks range must exist - to make this blocks range available
  • gaps are not allowed
  • segment have [from:to) semantic

func (*RoSnapshots) BlocksAvailable

func (s *RoSnapshots) BlocksAvailable() uint64

func (*RoSnapshots) Cfg

func (s *RoSnapshots) Cfg() ethconfig.Snapshot

func (*RoSnapshots) Close

func (s *RoSnapshots) Close()

func (*RoSnapshots) Dir

func (s *RoSnapshots) Dir() string

func (*RoSnapshots) DisableReadAhead

func (s *RoSnapshots) DisableReadAhead()

DisableReadAhead - usage: `defer d.EnableReadAhead().DisableReadAhead()`. Please don't use this funcs without `defer` to avoid leak.

func (*RoSnapshots) EnableMadvNormal

func (s *RoSnapshots) EnableMadvNormal() *RoSnapshots

func (*RoSnapshots) EnableMadvWillNeed

func (s *RoSnapshots) EnableMadvWillNeed() *RoSnapshots

func (*RoSnapshots) EnableReadAhead

func (s *RoSnapshots) EnableReadAhead() *RoSnapshots

func (*RoSnapshots) EnsureExpectedBlocksAreAvailable

func (s *RoSnapshots) EnsureExpectedBlocksAreAvailable(cfg *snapcfg.Cfg) error

func (*RoSnapshots) Files

func (s *RoSnapshots) Files() (list []string)

func (*RoSnapshots) IndicesMax

func (s *RoSnapshots) IndicesMax() uint64

func (*RoSnapshots) IndicesReady

func (s *RoSnapshots) IndicesReady() bool

func (*RoSnapshots) LogStat

func (s *RoSnapshots) LogStat()

func (*RoSnapshots) OptimisticReopenWithDB

func (s *RoSnapshots) OptimisticReopenWithDB(db kv.RoDB)

OptimisticReopenWithDB - optimistically open snapshots (ignoring error), useful at App startup because: - user must be able: delete any snapshot file and Erigon will self-heal by re-downloading - RPC return Nil for historical blocks if snapshots are not open

func (*RoSnapshots) OptimisticalyReopenFolder

func (s *RoSnapshots) OptimisticalyReopenFolder()

func (*RoSnapshots) OptimisticalyReopenWithDB

func (s *RoSnapshots) OptimisticalyReopenWithDB(db kv.RoDB)

func (*RoSnapshots) PrintDebug

func (s *RoSnapshots) PrintDebug()

func (*RoSnapshots) Ranges

func (s *RoSnapshots) Ranges() (ranges []Range)

func (*RoSnapshots) ReopenFolder

func (s *RoSnapshots) ReopenFolder() error

func (*RoSnapshots) ReopenList

func (s *RoSnapshots) ReopenList(fileNames []string, optimistic bool) error

ReopenList stops on optimistic=false, continue opening files on optimistic=true

func (*RoSnapshots) ReopenWithDB

func (s *RoSnapshots) ReopenWithDB(db kv.RoDB) error

func (*RoSnapshots) SegmentsMax

func (s *RoSnapshots) SegmentsMax() uint64

func (*RoSnapshots) SegmentsReady

func (s *RoSnapshots) SegmentsReady() bool

func (*RoSnapshots) ViewBodies

func (s *RoSnapshots) ViewBodies(blockNum uint64, f func(sn *BodySegment) error) (found bool, err error)

func (*RoSnapshots) ViewHeaders

func (s *RoSnapshots) ViewHeaders(blockNum uint64, f func(sn *HeaderSegment) error) (found bool, err error)

func (*RoSnapshots) ViewTxs

func (s *RoSnapshots) ViewTxs(blockNum uint64, f func(sn *TxnSegment) error) (found bool, err error)

type TxnSegment

type TxnSegment struct {
	Seg                 *compress.Decompressor // value: first_byte_of_transaction_hash + sender_address + transaction_rlp
	IdxTxnHash          *recsplit.Index        // transaction_hash  -> transactions_segment_offset
	IdxTxnHash2BlockNum *recsplit.Index        // transaction_hash  -> block_number
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL