store

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 29 Imported by: 1 module, 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 store is the Go overlay engine's own storage: an INDEX store (the outpoint index, small, hot, updated on spend) and a BEEF BLOB store (large, written once per transaction, read on lookup and GASP, unlinked by retention), behind one URL-scheme factory, Teranode-style. Ruling R-h (1bsv-ops decisions.md §7, storage-options.md §7).

Backends:

pebble:///path/to/index     Pebble v2 (default; WAL synced on a timer)
sqlite:///path/to/index.db  modernc.org/sqlite, WAL, synchronous=NORMAL, rowid tables
file:///path/to/blobs       one file per txid, sharded by txid prefix, temp + rename

Store composes the two into the plain engine.Storage interface. It does NOT advertise overlay-admission-v1, so the engine takes its ordinary path (a duplicate answers empty arrays, exactly as the TypeScript host does).

Write order: the BEEF blob is written BEFORE the index rows, so a crash never leaves an output without its bytes. Durability is a policy: the WAL is synced on a timer (bounded loss, recovered from the plane by re-delivery and GASP, ruling R-j), or on every batch when the timer is 0.

Index

Constants

View Source
const (
	ManifestFile = "checkpoint.json"
	StatesDir    = "states"

	// StagingDir is made beside the index directory (the SQLite file's
	// directory) for the pause's links, and removed after each checkpoint.
	StagingDir = ".checkpoint-staging"
)

Checkpoint names.

Variables

View Source
var (
	// ErrScope is a store created for another chain (genesis) being opened.
	ErrScope = errors.New("store: index was created for another chain")
	// ErrLocked is an index another process holds open.
	ErrLocked = errors.New("store: index is open in another process")
)

Errors.

Functions

func Backend

func Backend(raw string) string

Backend names the backend of a URL, for the build info gauge.

func RememberApplied added in v0.13.0

func RememberApplied(ctx context.Context, txid chainhash.Hash, topic string, applied bool)

RememberApplied leaves the answer just read for (txid, topic) in ctx's memo for the next asker. Without a memo it does nothing.

func WithAppliedMemo added in v0.13.0

func WithAppliedMemo(ctx context.Context) context.Context

WithAppliedMemo returns ctx carrying an empty memo for one submission.

Types

type AppliedRecord added in v0.12.0

type AppliedRecord struct {
	Txid chainhash.Hash
	// At is when it was written, microseconds since the epoch; 0 when the
	// index kept no time for it.
	At uint64
}

AppliedRecord is one applied record of a topic.

type Blobs

type Blobs interface {
	Put(ctx context.Context, txid chainhash.Hash, data []byte) error
	// Get returns nil, nil when absent.
	Get(ctx context.Context, txid chainhash.Hash) ([]byte, error)
	Has(ctx context.Context, txid chainhash.Hash) (bool, error)
	// Delete of an absent blob is not an error.
	Delete(ctx context.Context, txid chainhash.Hash) error
	// Walk visits every blob.
	Walk(ctx context.Context, fn func(txid chainhash.Hash, size int64) error) error
	// Snapshot links or copies every blob into dir (which must not exist).
	Snapshot(ctx context.Context, dir string) (files int, err error)
	// Temp visits the temporary files a write left behind (a process that
	// died between create and rename) that are older than age, removing
	// each unless dryRun.
	Temp(ctx context.Context, age time.Duration, dryRun bool, fn func(path string, size int64)) error
	Close() error
}

Blobs is the BEEF blob store, keyed by txid.

func OpenBlobs

func OpenBlobs(rawURL string, cfg Config) (Blobs, error)

OpenBlobs opens the blob store named by a URL.

type CheckReport

type CheckReport struct {
	Transactions uint64
	Outputs      uint64
	Blobs        uint64
	// MissingBlobs are transactions the index says hold a blob whose file is
	// absent: an output without its bytes. The one inconsistency the write
	// order is designed to prevent.
	MissingBlobs []chainhash.Hash
	// OrphanRows are output rows whose transaction row is absent.
	OrphanRows []string
	// Unreferenced are blobs no transaction row claims: a blob written for
	// an admission whose index batch never committed (a crash between the
	// two). Harmless; the next retention or a re-delivery resolves it.
	Unreferenced []chainhash.Hash
}

CheckReport is what Check found.

func (CheckReport) OK

func (r CheckReport) OK() bool

OK is true when nothing is missing (unreferenced blobs do not count).

func (CheckReport) String

func (r CheckReport) String() string

type CheckpointOptions added in v0.12.0

type CheckpointOptions struct {
	// Blobs hard-links the blob store into blobs/.
	Blobs bool
	// States are the directories of state kept beside the index, by name
	// (a module's): each is copied into states/<name> at the instant of
	// the index copy.
	States map[string]string
	// Hold, when set, holds admissions for that instant: it returns once
	// every admission in flight has left the engine and none can enter,
	// with the release (the host's pipeline).
	Hold func() (release func())
	// Version is the engine's, for the manifest.
	Version string
}

CheckpointOptions say what a checkpoint holds beside the index.

type CheckpointResult added in v0.12.0

type CheckpointResult struct {
	Dir string `json:"dir"`
	Manifest
}

CheckpointResult is what Checkpoint wrote.

type Config

type Config struct {
	// IndexURL: pebble:///dir or sqlite:///file.db.
	IndexURL string
	// BlobsURL: file:///dir.
	BlobsURL string
	// WALSync is how often Pebble's WAL is synced; 0 syncs every batch.
	WALSync time.Duration
	// BlobFsync fsyncs each blob file before its rename.
	BlobFsync bool
	// CacheMB is the index block cache (Pebble) or page cache (SQLite).
	CacheMB int
	// Network and Genesis scope the store: an index created for another
	// genesis refuses to open (a lab genesis reset means a wipe, not a mix).
	Network string
	Genesis string
	// Metrics may be nil (the CLI).
	Metrics *metrics.Metrics
}

Config is what Open needs.

type Forgotten added in v0.12.0

type Forgotten struct {
	// Rows is how many of the named rows it removed.
	Rows int
	// Applied: the topic's applied record of the transaction.
	Applied bool
	// Meta: the transaction's meta, nothing being left that refers to the
	// transaction; Blob and BlobBytes are what it said of the blob.
	Meta      bool
	Blob      bool
	BlobBytes uint64
}

Forgotten is what Index.Forget removed.

type GCClass added in v0.12.0

type GCClass struct {
	Found        uint64 `json:"found"`
	Bytes        uint64 `json:"bytes"`
	Removed      uint64 `json:"removed"`
	RemovedBytes uint64 `json:"removed_bytes"`
}

GCClass is one class of a run: found (dry: what would go) and removed.

type GCOptions added in v0.12.0

type GCOptions struct {
	// DryRun counts and removes nothing.
	DryRun bool
	// Rowless also removes the blobs of the rowless class.
	Rowless bool
	// Batch is transactions or files per batch; 0 is 512.
	Batch int
	// TempAge is how old a temporary file must be; 0 is an hour.
	TempAge time.Duration
}

GCOptions configure one run.

type GCResult added in v0.12.0

type GCResult struct {
	DryRun  bool `json:"dry_run"`
	Rowless bool `json:"with_rowless"`
	// Transactions and Files are the metas and the blob files read.
	Transactions uint64  `json:"transactions"`
	Files        uint64  `json:"files"`
	Dropped      GCClass `json:"dropped"`
	RowlessTxs   GCClass `json:"rowless"`
	Unreferenced GCClass `json:"unreferenced"`
	Metas        GCClass `json:"meta"`
	Temp         GCClass `json:"temp"`
	// Protected are rowless transactions a held row names as ancillary:
	// kept.
	Protected GCClass `json:"protected"`
	TookMS    float64 `json:"took_ms"`
}

GCResult is what one run found and did.

type Index

type Index interface {
	// Meta reads the scope record; nil when the index is new.
	Meta(ctx context.Context) (*Meta, error)
	SetMeta(ctx context.Context, m Meta) error

	// Get returns the rows of one outpoint, in every topic when topic is nil.
	Get(ctx context.Context, op transaction.Outpoint, topic *string) ([]*Record, error)
	ByTxid(ctx context.Context, txid chainhash.Hash) ([]*Record, error)
	// Scan lists a topic's rows with score >= since in score order, at most
	// limit (0 = no limit), filtered by spent when non-nil. With spent nil
	// the order is the backend's primary key order and since is ignored.
	Scan(ctx context.Context, topic string, since uint64, limit uint32, spent *bool) ([]*Record, error)

	// Insert writes rows that do not exist yet (an existing row is left as
	// is) and the transaction's meta, in one atomic batch.
	Insert(ctx context.Context, recs []*Record, tx *TxMeta) error
	// Delete removes a row; when it was the transaction's last, the
	// transaction's meta records that (tip is the best known height).
	Delete(ctx context.Context, topic string, op transaction.Outpoint, tip uint32) error
	// MarkSpent marks rows spent by spendTxid and flags transactions whose
	// rows are now all spent.
	MarkSpent(ctx context.Context, topic string, ops []transaction.Outpoint, spendTxid chainhash.Hash) error
	SetConsumedBy(ctx context.Context, topic string, op transaction.Outpoint, consumedBy []transaction.Outpoint) error
	SetBlock(ctx context.Context, topic string, op transaction.Outpoint, height uint32, idx uint64) error
	// SetMerkleRoot records the root a transaction's proof computes to, on
	// every row of the transaction; a nil root clears it (unmined).
	SetMerkleRoot(ctx context.Context, txid chainhash.Hash, root *chainhash.Hash, height uint32, idx uint64) error
	ByMerkleState(ctx context.Context, topic string, state uint8, limit uint32) ([]transaction.Outpoint, error)
	AtHeight(ctx context.Context, topic string, height uint32) ([]*Record, error)
	SetMerkleStates(ctx context.Context, updates []StateUpdate) error

	PutApplied(ctx context.Context, txid chainhash.Hash, topic string) error
	HasApplied(ctx context.Context, txid chainhash.Hash, topic string) (bool, error)
	// DeleteApplied forgets that topic applied txid, so the transaction
	// offered again is decided afresh; absent is no error.
	DeleteApplied(ctx context.Context, txid chainhash.Hash, topic string) error
	// Applied lists the transactions topic applied (a full walk of the
	// applied records: an operator's tool, never the admission path).
	Applied(ctx context.Context, topic string) ([]chainhash.Hash, error)
	SetInteraction(ctx context.Context, host, topic string, since float64) error
	Interaction(ctx context.Context, host, topic string) (float64, error)

	// Tx reads a transaction's meta; nil when absent.
	Tx(ctx context.Context, txid chainhash.Hash) (*TxMeta, error)
	// SetTxBlob records whether the blob is held (retention clears it).
	SetTxBlob(ctx context.Context, txid chainhash.Hash, present bool, size uint64) error
	// RetentionCandidates lists transactions whose blob is held and whose
	// rows are all spent and all proven (merkle state validated or
	// immutable) at heights no greater than maxHeight, or whose rows the
	// engine removed and that were proven, or removed, at such a height.
	RetentionCandidates(ctx context.Context, maxHeight uint32, limit int) ([]chainhash.Hash, error)
	// Tip and SetTip keep the best chain height the store has seen (SetTip
	// never lowers it).
	Tip(ctx context.Context) (uint32, error)
	SetTip(ctx context.Context, height uint32) error
	// Txs walks every transaction row (consistency checks).
	Txs(ctx context.Context, fn func(TxMeta) error) error
	// Topics lists the topics that have rows.
	Topics(ctx context.Context) ([]string, error)

	Stats(ctx context.Context) (Stats, error)
	// Checkpoint writes a consistent copy of the index into dir (which must
	// not exist).
	Checkpoint(ctx context.Context, dir string) error
	// Flush writes what the index holds in memory to its files, so that a
	// checkpoint right after copies little log.
	Flush() error
	// Sync forces the write-ahead log to disk.
	Sync() error
	Close() error

	// Rows streams every row of a topic, spent or not, in key order.
	Rows(ctx context.Context, topic string, fn func(*Record) error) error
	// Expired lists a topic's rows, spent or not, whose score is below
	// before, oldest first, at most limit.
	Expired(ctx context.Context, topic string, before uint64, limit int) ([]*Record, error)
	// Forget removes the named rows of one transaction in one topic and,
	// in the same atomic batch, what then refers to nothing: the topic's
	// applied record of the transaction once none of its rows is left in
	// the topic, if the record was written before appliedBefore
	// (microseconds; a record with no time counts as older than any), and
	// the transaction's meta once no row and no applied record of it is
	// left in any topic (its blob may then go). Removing the last row
	// otherwise records it on the meta as Delete does.
	Forget(ctx context.Context, topic string, txid chainhash.Hash, vouts []uint32, appliedBefore uint64, tip uint32) (Forgotten, error)
	// Refs reports whether any row and any applied record of txid exist,
	// in any topic.
	Refs(ctx context.Context, txid chainhash.Hash) (rows, applied bool, err error)
	// DeleteTx removes a transaction's meta, atomically with the check
	// that no row and no applied record of it is left, and answers the
	// meta it removed (nil when it removed none).
	DeleteTx(ctx context.Context, txid chainhash.Hash) (*TxMeta, error)
	// TxPage lists transaction metas in key order after after (nil: from
	// the first), at most limit.
	TxPage(ctx context.Context, after *chainhash.Hash, limit int) ([]TxMeta, error)
	// AppliedPage lists a topic's applied records in key order after after
	// (nil: from the first), at most limit, each with the time it was
	// written (0 for one written before the index kept times).
	AppliedPage(ctx context.Context, topic string, after *chainhash.Hash, limit int) ([]AppliedRecord, error)
}

Index is the outpoint index. Every method is safe for concurrent use. Secondary orderings a backend must serve: (topic, spent, score) for Scan, txid for ByTxid, (topic, merkle state) for ByMerkleState and (topic, block height) for AtHeight.

func OpenIndex

func OpenIndex(ctx context.Context, rawURL string, cfg Config) (Index, error)

OpenIndex opens the index named by a URL.

type Manifest added in v0.12.0

type Manifest struct {
	Format  int    `json:"format"`
	Engine  string `json:"engine,omitempty"`
	Created string `json:"created"`
	// Index is the backend: pebble or sqlite.
	Index     string `json:"index"`
	Blobs     bool   `json:"blobs"`
	BlobFiles int    `json:"blob_files"`
	// States are the state directories copied, by name.
	States map[string]StateCopy `json:"states"`
	// PauseMS is how long admissions and index writes were held.
	PauseMS float64 `json:"pause_ms"`
	TookMS  float64 `json:"took_ms"`
}

Manifest is a checkpoint's checkpoint.json.

func ReadManifest added in v0.12.0

func ReadManifest(dir string) (*Manifest, error)

ReadManifest reads a checkpoint's manifest; nil, nil for a checkpoint written before manifests (an index and blobs, no state).

type Meta

type Meta struct {
	Network string `json:"network"`
	Genesis string `json:"genesis"`
	// Created is when the index was created, RFC 3339.
	Created string `json:"created"`
}

Meta is what the index remembers about the store it belongs to.

type PruneOptions added in v0.12.0

type PruneOptions struct {
	// Topics are the topics pruned.
	Topics []string
	// Keep is how long a row is kept after it was admitted (its score).
	Keep time.Duration
	// Batch is rows (or applied records) per batch; 0 is 512.
	Batch int
	// DryRun counts and removes nothing.
	DryRun bool
	// Now is the clock; nil is time.Now.
	Now func() time.Time
}

PruneOptions configure one pass.

type PruneResult added in v0.12.0

type PruneResult struct {
	DryRun bool      `json:"dry_run"`
	Cut    time.Time `json:"cut"`
	// Topics is by topic.
	Topics map[string]*PruneTopic `json:"topics"`
	// Transactions forgotten: meta (and blob) removed.
	Transactions int     `json:"transactions"`
	Blobs        int     `json:"blobs"`
	BlobBytes    uint64  `json:"blob_bytes"`
	TookMS       float64 `json:"took_ms"`
}

PruneResult is what one pass did.

type PruneTopic added in v0.12.0

type PruneTopic struct {
	// Outputs are rows removed (or, dry, older than the cut).
	Outputs int `json:"outputs"`
	// Applied are applied records removed (dry: older than the cut with no
	// row left in the topic, the expired rows' transactions not counted).
	Applied int `json:"applied"`
	// Transactions are the distinct transactions of the rows (dry only).
	Transactions int `json:"transactions,omitempty"`
	// OldestSeconds is the age of the oldest row left; -1 when none.
	OldestSeconds float64 `json:"oldest_seconds"`
}

PruneTopic is one topic's part of a pass.

type Record

type Record struct {
	Topic    string
	Outpoint transaction.Outpoint
	Spent    bool
	// SpendTxid is set once Spent.
	SpendTxid *chainhash.Hash
	// Score orders a topic's outputs for GASP paging: microseconds since the
	// epoch, monotonic within one store process.
	Score       uint64
	BlockHeight uint32
	BlockIdx    uint64
	MerkleRoot  *chainhash.Hash
	MerkleState uint8
	// OutputsConsumed are the outpoints this output's transaction consumed in
	// its topic; ConsumedBy the outputs that later consumed this one.
	OutputsConsumed []transaction.Outpoint
	ConsumedBy      []transaction.Outpoint
	AncillaryTxids  []chainhash.Hash
}

Record is one output row of the index.

type RestoreOptions added in v0.12.0

type RestoreOptions struct {
	IndexURL string
	BlobsURL string
	// States are the state directories as configured now, by name. A
	// state the checkpoint holds that is not named here goes back where it
	// was copied from.
	States map[string]string
	// KeepLive are file names kept from the live state directory when they
	// continue the checkpoint's copy (the payment ledgers).
	KeepLive []string
	// Aside is the suffix of what is moved out of the way.
	Aside string
}

RestoreOptions say where a checkpoint goes back to.

type RestoreResult added in v0.12.0

type RestoreResult struct {
	// Manifest is nil for a checkpoint written before manifests.
	Manifest    *Manifest                `json:"manifest"`
	Index       string                   `json:"index"`
	IndexAside  string                   `json:"index_aside,omitempty"`
	BlobsLinked int                      `json:"blobs_linked"`
	BlobsHeld   int                      `json:"blobs_held"`
	States      map[string]RestoredState `json:"states"`
	Warnings    []string                 `json:"warnings,omitempty"`
}

RestoreResult is what Restore did.

func Restore added in v0.12.0

func Restore(ctx context.Context, dir string, o RestoreOptions) (RestoreResult, error)

Restore restores the checkpoint in dir.

type RestoredState added in v0.12.0

type RestoredState struct {
	Dir   string `json:"dir"`
	Aside string `json:"aside,omitempty"`
	Files int    `json:"files"`
	// KeptLive are the files kept from the live directory.
	KeptLive []string `json:"kept_live,omitempty"`
	// Absent: the checkpoint holds no such directory (the module had
	// written nothing): none is left in place.
	Absent bool `json:"absent,omitempty"`
}

RestoredState is one state directory put back.

type RetentionResult

type RetentionResult struct {
	// MaxHeight is the newest height whose spent-and-proven transactions
	// were eligible (tip - blocks).
	MaxHeight uint32
	// Candidates is how many transactions were all-spent with a blob held
	// before the pass.
	Candidates int
	Unlinked   int
	Bytes      uint64
}

RetentionResult is what one retention pass did.

type StateCopy added in v0.12.0

type StateCopy struct {
	// Dir is where it was copied from.
	Dir string `json:"dir"`
	// Absent: the directory did not exist (a module that has written no
	// state yet).
	Absent bool  `json:"absent,omitempty"`
	Files  int   `json:"files"`
	Bytes  int64 `json:"bytes"`
}

StateCopy is one state directory in a checkpoint.

type StateUpdate

type StateUpdate struct {
	Topic    string
	Outpoint transaction.Outpoint
	State    uint8
}

StateUpdate is one merkle-state change for SetMerkleStates.

type Stats

type Stats struct {
	Backend string                `json:"index"`
	Topics  map[string]TopicStats `json:"topics"`
	// Transactions is the number of transaction rows; WithBlob those whose
	// BEEF blob is held; Candidates those whose outputs are all spent and
	// whose blob is held (retention looks only at these).
	Transactions uint64 `json:"transactions"`
	WithBlob     uint64 `json:"with_blob"`
	BlobBytes    uint64 `json:"blob_bytes"`
	Candidates   uint64 `json:"candidates"`
	Applied      uint64 `json:"applied"`
}

Stats is what Index.Stats reports.

type Store

type Store struct {
	Index Index
	Blobs Blobs
	// contains filtered or unexported fields
}

Store is the engine's storage: an Index and a Blobs composed into the plain engine.Storage interface. It deliberately does not implement the admission capability (engine.AdmissionStorage).

func Open

func Open(ctx context.Context, cfg Config) (*Store, error)

Open opens both halves, writes or checks the scope record and returns the composed store.

func (*Store) Check

func (s *Store) Check(ctx context.Context) (CheckReport, error)

Check walks the index and the blobs and reports what disagrees.

func (*Store) Checkpoint

func (s *Store) Checkpoint(ctx context.Context, dir string, o CheckpointOptions) (CheckpointResult, error)

Checkpoint writes a checkpoint into dir, which must not exist. On a failure it removes what it wrote.

func (*Store) Close

func (s *Store) Close() (err error)

Close closes both halves; a second call does nothing.

func (*Store) DeleteAppliedTransaction added in v0.4.0

func (s *Store) DeleteAppliedTransaction(ctx context.Context, txid *chainhash.Hash, topic string) error

DeleteAppliedTransaction forgets that topic applied txid, so the same transaction offered again is shown to the topic's manager afresh: what a lookup service that drops an object it indexed (bstore's retention and retractions) asks for beside DeleteOutput. Not part of engine.Storage; the module seam asserts for it.

func (*Store) DeleteOutput

func (s *Store) DeleteOutput(ctx context.Context, outpoint *transaction.Outpoint, topic string) error

func (*Store) DoesAppliedTransactionExist

func (s *Store) DoesAppliedTransactionExist(ctx context.Context, tx *overlay.AppliedTransaction) (bool, error)

func (*Store) DropTopic added in v0.5.0

func (s *Store) DropTopic(ctx context.Context, topic string) (rows, applied int, err error)

DropTopic forgets a topic: every row of it, spent or not, and every applied record, so that the same objects offered again are decided afresh by whatever manages the topic now. Blobs and transaction meta stay (another topic may hold the transaction; retention reclaims the rest). The operator's tool for handing a topic from one module to another (store drop-topic); never called by the engine.

func (*Store) FindOutpointsByMerkleState

func (s *Store) FindOutpointsByMerkleState(ctx context.Context, topic string, state engine.MerkleState, limit uint32) ([]*transaction.Outpoint, error)

func (*Store) FindOutput

func (s *Store) FindOutput(ctx context.Context, outpoint *transaction.Outpoint, topic *string, spent *bool, includeBEEF bool) (*engine.Output, error)

FindOutput returns one output, or nil, nil when absent.

func (*Store) FindOutputs

func (s *Store) FindOutputs(ctx context.Context, outpoints []*transaction.Outpoint, topic string, spent *bool, includeBEEF bool) ([]*engine.Output, error)

FindOutputs is slot-aligned with outpoints: a nil for each one absent.

func (*Store) FindOutputsForTransaction

func (s *Store) FindOutputsForTransaction(ctx context.Context, txid *chainhash.Hash, includeBEEF bool) ([]*engine.Output, error)

func (*Store) FindUTXOsForTopic

func (s *Store) FindUTXOsForTopic(ctx context.Context, topic string, since float64, limit uint32, includeBEEF bool) ([]*engine.Output, error)

FindUTXOsForTopic lists unspent outputs with score >= since in score order (the TypeScript reference's comparison), at most limit.

func (*Store) GC added in v0.12.0

func (s *Store) GC(ctx context.Context, o GCOptions) (GCResult, error)

GC runs once, after any maintenance pass (retention, prune, gc) running.

func (*Store) GetLastInteraction

func (s *Store) GetLastInteraction(ctx context.Context, host, topic string) (float64, error)

func (*Store) InsertAppliedTransaction

func (s *Store) InsertAppliedTransaction(ctx context.Context, tx *overlay.AppliedTransaction) error

func (*Store) InsertOutputs

func (s *Store) InsertOutputs(ctx context.Context, topic string, txid *chainhash.Hash, outputs []uint32, outpointsConsumed []*transaction.Outpoint, beef *transaction.Beef, ancillaryTxids []*chainhash.Hash) error

InsertOutputs writes the BEEF once per txid (before any row), then the output rows, the transaction's meta and, when the BEEF carries the subject's proof, its block coordinates and root.

func (*Store) LoadAncillaryBeef

func (s *Store) LoadAncillaryBeef(ctx context.Context, output *engine.Output) error

LoadAncillaryBeef merges the blobs of the output's ancillary transactions into its Beef. A blob retention removed is skipped, as upstream skips an absent one.

func (*Store) MarkUTXOsAsSpent

func (s *Store) MarkUTXOsAsSpent(ctx context.Context, outpoints []*transaction.Outpoint, topic string, spendTxid *chainhash.Hash) error

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping is the readiness check: the index answers.

func (*Store) Prune added in v0.12.0

func (s *Store) Prune(ctx context.Context, o PruneOptions) (PruneResult, error)

Prune runs one pass, after any maintenance pass (retention, prune, gc) running.

func (*Store) ReconcileMerkleRoot

func (s *Store) ReconcileMerkleRoot(ctx context.Context, topic string, blockHeight uint32, merkleRoot *chainhash.Hash) error

ReconcileMerkleRoot applies upstream's rule to every row of the topic at the height: no stored root stays Unmined, a matching root becomes Validated, a differing one Invalidated. (Immutable is never set here: the engine's "old enough" promotion is a lookup-side policy this host does not run.)

func (*Store) Retention

func (s *Store) Retention(ctx context.Context, tip, blocks uint32) (RetentionResult, error)

Retention unlinks the BEEF blobs of transactions whose outputs are all spent and all proven at heights at least blocks below tip. Index rows stay: the outpoint, its spend and its proof state remain answerable; only the bytes go. A transaction consumed later by LoadAncillaryBeef or a lookup with BEEF then answers without them, as upstream does for an absent blob.

func (*Store) RunPrune added in v0.12.0

func (s *Store) RunPrune(ctx context.Context, o PruneOptions, every time.Duration, log *slog.Logger)

RunPrune runs a pass every interval until ctx ends, the first one interval after it starts. No topics or no keep: it returns at once.

func (*Store) RunRetention

func (s *Store) RunRetention(ctx context.Context, tip Tip, blocks uint32, every time.Duration, log *slog.Logger)

RunRetention runs Retention every interval until ctx ends. blocks 0 disables it.

func (*Store) SeenHeight

func (s *Store) SeenHeight(ctx context.Context, height uint32)

SeenHeight tells the store the chain reached height (reconciliation and retention do); it is remembered across restarts and never lowered.

func (*Store) Stats added in v0.12.0

func (s *Store) Stats(ctx context.Context, files bool) (StoreStats, error)

Stats counts the index and, with files, walks the blob files: what `store stats` prints, from a stopped engine's store or a running one's.

func (*Store) Transaction added in v0.7.0

func (s *Store) Transaction(ctx context.Context, txid chainhash.Hash) (*transaction.Transaction, error)

Transaction returns a held transaction with the ancestry and proofs its blob carries, or nil, nil when no blob is held (never admitted, or unlinked by retention). One blob serves every topic. GASP catch-up reads it so that an ancestor this host already holds is never fetched from a peer.

func (*Store) TryGC added in v0.12.0

func (s *Store) TryGC(ctx context.Context, o GCOptions) (res GCResult, ok bool, err error)

TryGC is GC unless a maintenance pass is running, when it answers ok false at once.

func (*Store) TryPrune added in v0.12.0

func (s *Store) TryPrune(ctx context.Context, o PruneOptions) (res PruneResult, ok bool, err error)

TryPrune is Prune unless a maintenance pass is running, when it answers ok false at once.

func (*Store) UpdateConsumedBy

func (s *Store) UpdateConsumedBy(ctx context.Context, outpoint *transaction.Outpoint, topic string, consumedBy []*transaction.Outpoint) error

func (*Store) UpdateLastInteraction

func (s *Store) UpdateLastInteraction(ctx context.Context, host, topic string, since float64) error

func (*Store) UpdateOutputBlockHeight

func (s *Store) UpdateOutputBlockHeight(ctx context.Context, outpoint *transaction.Outpoint, topic string, blockHeight uint32, blockIndex uint64) error

func (*Store) UpdateTransactionBEEF

func (s *Store) UpdateTransactionBEEF(ctx context.Context, txid *chainhash.Hash, beef *transaction.Beef) error

UpdateTransactionBEEF replaces the blob (a proof arrived) and records the root and block coordinates the new proof computes to on every row of the transaction, so ReconcileMerkleRoot has something to compare.

type StoreStats added in v0.12.0

type StoreStats struct {
	Stats
	Meta *Meta `json:"scope,omitempty"`
	// Files and FileBytes are the blob files on disk (Files -1: not
	// counted).
	Files     int64 `json:"files"`
	FileBytes int64 `json:"file_bytes"`
}

StoreStats is the index's counts and, when asked, the blob files.

type Tip

type Tip interface {
	FreshHeight(ctx context.Context) (uint32, error)
}

Tip is where the retention job asks for the chain height.

type TopicStats

type TopicStats struct {
	Outputs uint64 `json:"outputs"`
	Unspent uint64 `json:"unspent"`
}

TopicStats are per-topic counts.

type TxMeta

type TxMeta struct {
	Txid      chainhash.Hash
	Blob      bool
	BlobBytes uint64
	AllSpent  bool
	// ProvenHeight is the height its rows were proven at when the engine
	// removed them (spent, not retained), 0 if they were unproven then.
	ProvenHeight uint32
	// DeletedHeight is the store's best known chain height when its last
	// row was removed, 0 if unknown.
	DeletedHeight uint32
}

TxMeta is the index's row per transaction: whether its BEEF blob is held and whether every output row of it is spent (a retention candidate).

Jump to

Keyboard shortcuts

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