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 ¶
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 ¶
Info describes a parsed snapshot.
func Load ¶
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.