snapshot

package
v2.8.4-rc1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: BSD-3-Clause Imports: 20 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package snapshot rebuilds the postage batch store from a pre-computed snapshot of postage contract events instead of replaying the whole contract history from the chain. A snapshot is NDJSON, one types.Log per line, sorted by block number, optionally gzip-compressed.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrParseSnapshot is returned when a snapshot does not decode as sorted
	// NDJSON of logs.
	ErrParseSnapshot = errors.New("failed to parse snapshot data")
	// ErrEmptySnapshot is returned when a strict snapshot holds no logs.
	ErrEmptySnapshot = errors.New("snapshot: no logs")
	// ErrContractMismatch is returned when a strict snapshot holds a log from a
	// contract other than the configured postage contract.
	ErrContractMismatch = errors.New("snapshot: log from unexpected contract")
	// ErrBlockHeightTooLow is returned when a strict snapshot does not reach far
	// enough past the start block for the replay to make progress.
	ErrBlockHeightTooLow = errors.New("snapshot: max block not ahead of start block")
)

Functions

func Parse

func Parse(logger log.Logger, src Source, contract common.Address) (*SnapshotLogFilterer, Info, error)

Parse reads src to the end and indexes its logs, which must be sorted by block number and emitted by contract. Blank lines are skipped. A log from another contract would be filtered out during replay while the chain state still advanced past it, silently skipping history; checking it here also rejects a snapshot for another network at its first line.

The snapshot comes from ethersphere/batch-export in its slim encoding: only address, topics, data, blockNumber, transactionHash and logIndex are set, every other types.Log field decodes to its zero value without error. Extend SlimLog in batch-export before reading a new field from snapshot logs.

Types

type Config

type Config struct {
	Contract        common.Address
	ABI             abi.ABI
	StartBlock      uint64 // the postage contract start block
	BlockTime       time.Duration
	StallingTimeout time.Duration
	BackoffTimeout  time.Duration
}

Config holds what Load needs to validate a snapshot and build its replay listener.

type Info

type Info struct {
	LogCount int
	MaxBlock uint64
}

Info describes a parsed snapshot.

func Load

func Load(logger log.Logger, src Source, cfg Config) (*batchservice.Snapshot, Info, error)

Load parses src, rejects a snapshot that is empty, holds logs from another contract, or does not reach far enough past StartBlock for the replay to make progress, and wraps it in the listener that replays it into the batch store. All of this happens eagerly so a bad snapshot fails here, not after the sync timeout.

type SnapshotGetter

type SnapshotGetter interface {
	GetBatchSnapshot() []byte
}

SnapshotGetter provides the snapshot blob embedded in the binary.

type SnapshotLogFilterer

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

SnapshotLogFilterer serves a parsed snapshot to the postage listener as if it were a chain backend: BlockNumber is the snapshot's max block, and FilterLogs answers from the in-memory, block-sorted logs.

func (*SnapshotLogFilterer) BlockNumber

func (f *SnapshotLogFilterer) BlockNumber(_ context.Context) (uint64, error)

func (*SnapshotLogFilterer) FilterLogs

func (f *SnapshotLogFilterer) FilterLogs(_ context.Context, query ethereum.FilterQuery) ([]types.Log, error)

type Source

type Source interface {
	// Name identifies the kind of source in logs: "embedded" or "file".
	Name() string
	// Open returns the snapshot as a stream of NDJSON, already decompressed.
	Open() (io.ReadCloser, error)
}

Source is where a snapshot is read from.

func Embedded

func Embedded(getter SnapshotGetter) Source

Embedded returns the source backed by the gzip blob embedded in the binary.

func File

func File(path string) Source

File returns the source backed by the snapshot file at path. The content decides the format, not the file name: gzip (possibly multi-member) is recognized by its magic bytes, anything else is read as plain NDJSON.

Directories

Path Synopsis
Package archive provides a snapshot.SnapshotGetter backed by the postage batch snapshot blob embedded in the binary at build time.
Package archive provides a snapshot.SnapshotGetter backed by the postage batch snapshot blob embedded in the binary at build time.

Jump to

Keyboard shortcuts

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