Documentation
¶
Overview ¶
Package module is the bstore overlay module in Go: `tm_bstore_<bucket>` for each configured bucket, `tm_bstoreblob_<bucket>` where the host's topics name one, and `ls_bstore` for all of them, written to bcommon's engine-neutral contract (github.com/lightwebinc/bcommon/module) so that any Go overlay host that carries the adapter mounts it. It is the twin of the TypeScript module under host/src (frozen), built from the Go core: the admission rules are storerec.Admit, the fold and the map answers storerec's, and the questions storerec's classes.
Configuration is the TypeScript module's, read from the environment when the host calls the factory (docs/host.md): BSTORE_BUCKETS, BSTORE_STATE_DIR, BSTORE_HEADERS_URL, BSTORE_SERVED, BSTORE_KEEP_DAYS, BSTORE_PENDING_DAYS, BSTORE_OTHER_HOURS, BSTORE_MAX_BEEF, BSTORE_MAX_SWEEP_INPUTS, BSTORE_LISTEN, BSTORE_PRICES, BSTORE_PAYEE_KEY, BSTORE_SESSIONS, BSTORE_SESSION_TTL, the handshake and response budgets, BSTORE_ARCADE_URL, BSTORE_ASSET_URL, BSTORE_CHAIN, BSTORE_WOC_KEY and the BSTORE_ACCEPT_* rule, and one of its own, BSTORE_JOURNAL_SYNC_MS (the rows journal's group commit window). Every mistake is an error, and the host refuses to start.
Index ¶
- Constants
- Variables
- func CheckNoSync(raw string) error
- func ParseBuckets(raw string) ([]string, error)
- func ParseListen(raw string) (string, error)
- func ParseServed(raw string, buckets []string) ([]string, error)
- type AppliedChecker
- type BlobTopicManager
- func (t *BlobTopicManager) GetDocumentation() string
- func (t *BlobTopicManager) GetMetaData() *overlay.MetaData
- func (t *BlobTopicManager) IdentifyAdmissibleOutputs(context.Context, *transaction.Beef, *chainhash.Hash, []uint32) (overlay.AdmittanceInstructions, error)
- func (*BlobTopicManager) IdentifyNeededInputs(context.Context, *transaction.Beef, *chainhash.Hash) ([]*transaction.Outpoint, error)
- type Classified
- type Config
- type Counts
- type Deleter
- type Evicter
- type FileJournal
- type FilePositions
- type Formula
- type Front
- type Journal
- type Line
- type MemoryJournal
- type MemoryPositions
- type Mounted
- type Options
- type OutputList
- type Positions
- type RecordsTopicManager
- func (t *RecordsTopicManager) Admit(ctx context.Context, raw []byte, held []int) (overlay.AdmittanceInstructions, error)
- func (t *RecordsTopicManager) GetDocumentation() string
- func (t *RecordsTopicManager) GetMetaData() *overlay.MetaData
- func (t *RecordsTopicManager) IdentifyAdmissibleOutputs(ctx context.Context, _ *transaction.Beef, _ *chainhash.Hash, ...) (overlay.AdmittanceInstructions, error)
- func (*RecordsTopicManager) IdentifyNeededInputs(context.Context, *transaction.Beef, *chainhash.Hash) ([]*transaction.Outpoint, error)
- func (t *RecordsTopicManager) Precheck(ctx context.Context) context.Context
- type Refused
- type RouteAnswerer
- type Service
- func (*Service) AdmissionMode() bmodule.AdmissionMode
- func (s *Service) Answer(ctx context.Context, c *Classified, paid bool) ([]Formula, error)
- func (s *Service) Classify(service string, query []byte) (*Classified, error)
- func (s *Service) Counts() Counts
- func (s *Service) FirstOn(op string) (string, bool)
- func (s *Service) Flush(ctx context.Context)
- func (*Service) GetDocumentation() string
- func (*Service) GetMetaData() *overlay.MetaData
- func (s *Service) HoldsCarrier(c string) bool
- func (s *Service) Hydrate(ctx context.Context, formulas []Formula) ([]bmodule.HydratedOutput, error)
- func (s *Service) Lookup(ctx context.Context, q *lookup.LookupQuestion) (*lookup.LookupAnswer, error)
- func (s *Service) Mark(op string) (key string, at int64, life bool, ok bool)
- func (s *Service) OutputAdmittedByTopic(ctx context.Context, p *bmodule.OutputAdmittedByTopic) error
- func (s *Service) OutputEvicted(_ context.Context, op *transaction.Outpoint) error
- func (s *Service) OutputNoLongerRetainedInHistory(_ context.Context, op *transaction.Outpoint, topic string) error
- func (s *Service) Prune(ctx context.Context) int
- func (s *Service) Replay(ctx context.Context, r *bmodule.ReplayRequest) (*bmodule.ReplayAnswer, error)
- func (s *Service) Restore(ctx context.Context, outputs []bmodule.Output, storage bmodule.RestoreStorage) (int, error)
- func (s *Service) Restored() bool
- func (*Service) SpendNotificationMode() bmodule.SpendNotificationMode
- func (s *Service) Swept(op string) bool
- func (s *Service) TokenStatus(txid string) (string, bool)
Constants ¶
const ( FloorKeepDays = 31 FloorPendingDays = 7 FloorOtherHours = 24 )
The retention floors (spec section 12.3): the long floor, the floor of unnamed entries, and everything else.
const ( DefaultJournalSyncMs = 100 MaxJournalSyncMs = 60_000 )
The rows journal's group commit window (BSTORE_JOURNAL_SYNC_MS): lines are written at once and fsynced together this often, off the lookup service's lock; 0 fsyncs each line before the admission goes on. The default and the bound are the engine store's (OVERLAY_STORE_WAL_SYNC_MS).
const ( // PageLimit is the outputs of a page of ads, unanchored, outcomes, // outcome-history, history and chain (tokens, for history and chain). PageLimit = 64 // PerSeq is the tokens answered at one seq and kept at one seq of a // chain; PerSmall the classes answered eight at a time (pending, ad, // fronts, front, sweep). PerSeq = 8 PerSmall = 8 // UnanchoredDays is how far back unanchored answers by admission; // OutcomeWindowDays the same for outcomes and its kin. UnanchoredDays = 7 OutcomeWindowDays = 31 // FrontsPerAdvertiser is the front statements kept the long floor per // advertiser of a root the map names, by first sight. FrontsPerAdvertiser = 16 // ReorgDepth is how many seqs below the highest the latest tokens are // looked for among those whose proof verifies, before the highest is // taken. ReorgDepth = 64 // ChoiceTTL is how long the latest tokens found against the headers // are reused. ChoiceTTL = time.Minute // SettleMs is how long a drop waits for the engine to record the // admission it drops. SettleMs = time.Minute )
The index's bounds (spec section 12.2 to 12.4).
const ( PruneEvery = time.Hour FlushEvery = 2 * time.Second WatchEvery = 30 * time.Second )
How often retention runs; how often drops still waiting are tried again (and the payment watch, at most every WatchEvery).
const ( ReplayPendingMargin = 24 * time.Hour ReplayOtherMargin = time.Hour ReplayMinedBlocks = 4032 // ReplaySkew is how far ahead of the host's clock a record may be dated // and still be replayed. ReplaySkew = 5 * time.Minute )
The margins and the window above.
const DefaultListenPort = 8294
DefaultListenPort is the terms route's port on the Go host. The TypeScript host's is 8094; the Go engine runs beside it on the same hosts until a cutover, so the Go route takes its own.
const FlushChunk = 64
FlushChunk is how many drops one hold of the lock deletes in a Flush.
const JournalFile = "bstore-rows.jsonl"
JournalFile is the journal's file name in the state directory.
const Name = "bstore"
Name is the module's name, as a host's module list names it.
const PositionsFile = "bstore-replay.json"
PositionsFile is the file of positions reached, in the state directory.
const RecentAdmissions = 4096
RecentAdmissions is how many admitted txids a manager remembers to count each once.
const SinceTries = 3
SinceTries is how many walks answer an object from a since page before the position moves past it unapplied.
Variables ¶
var AdmitKinds = []string{"entry", "outcome", "front", "bucket-token", "mined", "sweep"}
AdmitKinds are what an admitted transaction was.
var Build = "unversioned"
Build is the version the host logs; a binary sets it.
var Classes = func() []termsroute.PricedClass { all := storerec.AllClasses() out := make([]termsroute.PricedClass, len(all)) for i, c := range all { out[i] = termsroute.PricedClass{Name: c.Name, Free: c.Free} } return out }()
Classes are the lookup classes as the route prices them, in the order of spec section 11.1.
var DropReasons = []string{"retracted", "retention", "second-carrier", "unmatched-sweep"}
DropReasons are why the index drops an object.
var ErrNoSubmission = errors.New("bstore: the host did not hand the manager the submission's bytes (bcommon module.WithSubmission)")
ErrNoSubmission is a host that hands the manager a parsed BEEF without the submission's bytes (bcommon module.WithSubmission): the manager decides on the wire form (which transactions a BEEF carries, in what order, with which proofs), which a parsed and merged BEEF no longer shows.
var KindsReplayed = []string{replay.KindToken, "entry", "ad", "hold", "front", "outcome", "sweep"}
KindsReplayed are the kinds a walk answers objects as.
var Reasons = []string{
"too-large", "cbor", "key-type", "magic", "missing", "type", "bucket", "identity", "seq", "writers", "changes", "count", "created",
"consumed", "first", "objkey", "kind", "size", "profile", "content-type", "etag", "meta", "hold", "empty", "request", "outcome",
"response-signature", "url", "shape", "beef", "mineable", "unlock", "lock", "signature", "funding", "unmined", "token-input",
"bucket-id", "too-many", "piece", "not-bstore", "host-config", "range", "list",
}
Reasons are every label a host counts a refused submission by: the record rules of spec sections 3.2, 4.2, 8.1 and 8.2 and the transaction rules of section 12.1. A reader's labels and query are never an admission verdict.
var TokenStatuses = []string{"pending", "rooted", "consistent", "map-mismatch"}
TokenStatuses are the token statuses the index reports, each counted.
Functions ¶
func CheckNoSync ¶
CheckNoSync refuses a host configured to synchronise a tm_bstore_ or tm_bstoreblob_ topic with a peer (OVERLAY_SYNC_PEERS, topic=url,...;topic=...): that synchronisation carries only unspent outputs, so it never carries a chain's spent tokens, and it drops what a topic manager refuses without trying it again. A host joins a bucket by replay (spec section 12.6).
func ParseBuckets ¶
ParseBuckets parses BSTORE_BUCKETS: bucket identifiers, once each.
func ParseListen ¶
ParseListen parses BSTORE_LISTEN, host:port, an IPv6 host in brackets or not, as the TypeScript module reads it; the answer is host:port as Go listens on it.
Types ¶
type AppliedChecker ¶
type AppliedChecker interface {
DoesAppliedTransactionExist(ctx context.Context, txid *chainhash.Hash, topic string) (bool, error)
}
AppliedChecker is a storage that says whether a topic applied a transaction: a drop decided while the engine admits the object waits until the engine has recorded the admission.
type BlobTopicManager ¶
type BlobTopicManager struct {
Topic string
Bucket string
// contains filtered or unexported fields
}
BlobTopicManager is a bucket's blob topic on a host: it carries pieces only, and no host admits a piece or holds bytes (spec sections 5 and 12.1), so every submission is refused, raised and counted as piece. Mounted only where the operator names the topic, so that the host's default manager never admits anything on it.
func NewBlobTopicManager ¶
func NewBlobTopicManager(topic string, host bmodule.Host) (*BlobTopicManager, error)
NewBlobTopicManager makes the blob manager of one topic.
func (*BlobTopicManager) GetDocumentation ¶
func (t *BlobTopicManager) GetDocumentation() string
GetDocumentation implements module.TopicManager.
func (*BlobTopicManager) GetMetaData ¶
func (t *BlobTopicManager) GetMetaData() *overlay.MetaData
GetMetaData implements module.TopicManager.
func (*BlobTopicManager) IdentifyAdmissibleOutputs ¶
func (t *BlobTopicManager) IdentifyAdmissibleOutputs(context.Context, *transaction.Beef, *chainhash.Hash, []uint32) (overlay.AdmittanceInstructions, error)
IdentifyAdmissibleOutputs implements module.TopicManager: refused, piece.
func (*BlobTopicManager) IdentifyNeededInputs ¶
func (*BlobTopicManager) IdentifyNeededInputs(context.Context, *transaction.Beef, *chainhash.Hash) ([]*transaction.Outpoint, error)
IdentifyNeededInputs implements module.InputIdentifier.
type Classified ¶
Classified is a question, validated, and whether this host prices it.
type Config ¶
type Config struct {
Buckets []string
StateDir string
// Positions keeps what PositionsFile keeps, for a host that keeps it
// elsewhere; nil is that file in StateDir beside a journal file, and
// memory beside a journal the host supplies.
Positions Positions
HeadersURL string
// Served are the chains this host serves: <bucket>|<owner hex>|<id hex>.
Served []string
KeepDays int
PendingDays int
OtherHours int
MaxBEEF int
MaxSweepInputs int
// JournalSync is the rows journal's group commit window; 0 syncs every
// line.
JournalSync time.Duration
// Listen is the terms route's host:port; empty for none.
Listen string
Prices map[string]uint64
PayeeKey *ec.PrivateKey
Sessions termsroute.SessionBound
Budget termsroute.BudgetConfig
Response termsroute.ResponseBudgetConfig
Accept termsroute.AcceptConfig
}
Config is the module's configuration.
type Counts ¶
type Counts struct {
Tokens, PendingTokens, Entries, Outcomes, Fronts, Ads, Holds, Sweeps, SweepOutpoints, Marks, Rows, PendingDrops int
Tally tally
}
Counts are the gauges' values.
type Deleter ¶
type Deleter interface {
DeleteOutput(ctx context.Context, outpoint *transaction.Outpoint, topic string) error
}
Deleter is a storage that can delete an output: what drops need beyond the contract's RestoreStorage. A host whose storage cannot delete keeps what the index dropped, unanswered.
type Evicter ¶
type Evicter interface {
DeleteAppliedTransaction(ctx context.Context, txid *chainhash.Hash, topic string) error
}
Evicter is a storage that can forget that a topic applied a transaction, so that the same object offered again is decided afresh. Without it a dropped object offered again is a duplicate the engine never shows the manager.
type FileJournal ¶
type FileJournal struct {
Dir string
Path string
// SyncEvery is the group commit window; zero syncs every line.
SyncEvery time.Duration
// OnSync, when set, is called after each timed fsync with the lines it
// covered, how long it took and its error. It runs on the timer's
// goroutine, holding no lock of the journal's.
OnSync func(lines int, took time.Duration, err error)
// contains filtered or unexported fields
}
FileJournal is the journal as a file, bstore-rows.jsonl in a directory. Each line is written to the file before Append returns, so a process that dies loses nothing (the line is in the page cache). When it reaches the disk is SyncEvery: zero flushes each line before Append returns; more is a group commit, one fsync for every line written in the window, run by a timer off the caller's path, so a power loss loses at most the window (the posture of the engine's own store, OVERLAY_STORE_WAL_SYNC_MS). Close and Rewrite flush. A last line cut short by a crash is cut off on load; any other line that does not parse stops the load, because a mark or a sweep's outpoint silently skipped could let a retracted carrier be answered again. A rewrite goes to a new file that is flushed and then renamed over the old one, so a crash leaves one or the other whole.
func NewFileJournal ¶
func NewFileJournal(dir string) (*FileJournal, error)
NewFileJournal makes the directory and names the file. The journal syncs every line until SyncEvery is set.
func (*FileJournal) Append ¶
func (j *FileJournal) Append(l Line) error
Append implements Journal: the line is in the file when it returns, and on disk too when SyncEvery is zero; otherwise a timed fsync takes it there within SyncEvery. An error of an earlier timed fsync is returned once, by the next Append, after its line is written.
func (*FileJournal) Close ¶
func (j *FileJournal) Close() error
Close flushes what is pending and closes the file. A later Append opens it again.
func (*FileJournal) Rewrite ¶
func (j *FileJournal) Rewrite(lines []Line) error
Rewrite implements Journal. Lines pending in the old file need no fsync: the new file holds the state they were part of, and is flushed before it replaces the old one.
func (*FileJournal) Sync ¶
func (j *FileJournal) Sync() error
Sync flushes every line written so far to disk now.
type FilePositions ¶ added in v0.28.0
type FilePositions struct {
Path string
// contains filtered or unexported fields
}
FilePositions is Positions in one JSON file, replaced atomically.
type Front ¶
type Front struct {
*termsroute.Front
Addr string
}
Front is the terms route and where it listens.
type Journal ¶
type Journal interface {
Load() ([]Line, error)
Append(l Line) error
// Rewrite replaces everything with lines, atomically.
Rewrite(lines []Line) error
}
Journal is where the state lives. Rewrite is durable when it returns; Append is durable when it returns or within the journal's sync window (FileJournal.SyncEvery).
type Line ¶
type Line struct {
K string
Op string
C string
B string
Key string
At int64
Life bool
S string
Txid string
Vout int64
}
Line is one journal line: what ls_bstore keeps beside the engine's storage (spec sections 12.2 to 12.5), as an append-only journal that retention compacts. The engine's storage holds the outputs a host still keeps; it cannot hold what must outlive them, or what it has no column for: which carrier a funding outpoint admitted first, the input outpoints of every admitted sweep, the retraction marks, when the host first saw each object, and which held outputs a later transaction spent. One JSON object a line:
{"k":"c","op":"<txid>.<vout>","c":"<C>","at":<ms>} the first carrier admitted on a funding outpoint
{"k":"cf","op":"..."} that row was dropped by retention
{"k":"a","b":"<bucket>","c":"<C>","at":<ms>} a carrier, first seen
{"k":"af","c":"<C>"} the carrier was dropped
{"k":"x","op":"...","key":"<owner>","at":<ms>,"life":<bool>,"b":"..."}
a retraction mark (b optional)
{"k":"xl","op":"..."} the mark is kept for the host's life
{"k":"xf","op":"..."} the mark was dropped by retention
{"k":"p","op":"...","s":"<sweep txid>","at":<ms>} an input outpoint of an admitted sweep
{"k":"pf","op":"..."} that outpoint was dropped by retention
{"k":"t","b":"...","txid":"<txid>","vout":<n>,"at":<ms>} a bucket token, first seen
{"k":"tf","txid":"<txid>"} the token was dropped
{"k":"o","b":"...","txid":"...","vout":<n>,"at":<ms>} an advertisement, hold output or sweep output, first seen
{"k":"w","b":"...","txid":"...","vout":<n>} a held output a later admitted transaction spent
{"k":"of","b":"...","txid":"...","vout":<n>} the output was dropped
Commitments are in hash byte order and txids in display order, both lowercase hex; keys are 66 hex digits; at is the host's time in Unix milliseconds. Replayed in order the lines rebuild the state; the first line about a thing sets it and a later one only forgets or upgrades it. The bytes are the TypeScript module's, key for key, so one journal reads under either.
type MemoryJournal ¶
type MemoryJournal struct {
Lines []Line
// contains filtered or unexported fields
}
MemoryJournal is a journal in memory, for tests and for a host that accepts losing it.
func (*MemoryJournal) Append ¶
func (m *MemoryJournal) Append(l Line) error
Append implements Journal.
func (*MemoryJournal) Load ¶
func (m *MemoryJournal) Load() ([]Line, error)
Load implements Journal.
func (*MemoryJournal) Rewrite ¶
func (m *MemoryJournal) Rewrite(lines []Line) error
Rewrite implements Journal.
type MemoryPositions ¶ added in v0.28.0
type MemoryPositions struct {
// contains filtered or unexported fields
}
MemoryPositions is Positions in memory, for tests and for a host that accepts reading every peer in full after a restart.
type Mounted ¶
type Mounted struct {
Module bmodule.Module
LS *Service
// Front is the terms route, when configured.
Front *Front
// contains filtered or unexported fields
}
Mounted is the module for one configuration: the contract's Module, the lookup service, and what Start runs.
func Mount ¶
func Mount(host bmodule.Host, c *Config, overlayTopics []string, journal Journal, hdrs chaintracker.ChainTracker, now func() time.Time) (*Mounted, error)
Mount builds the module for c. overlayTopics is OVERLAY_TOPICS, when known: a blob topic is mounted only where it names one. journal replaces the state directory's, hdrs the configured header source and now the host's clock, for tests.
func New ¶
New is the factory a host calls: the configuration from getenv, checked against OVERLAY_TOPICS and OVERLAY_SYNC_PEERS.
func (*Mounted) Close ¶
Close flushes the rows journal and closes it (Start does when its context ends). A host that stops without it leaves at most the last sync window's lines in the page cache: written, not yet on disk.
func (*Mounted) Start ¶
Start serves the terms route (when configured) until ctx ends, and runs the background tick: drops still waiting every FlushEvery, the payment watch every WatchEvery, and retention once the index is restored and every PruneEvery after. It returns when ctx ends, after closing the rows journal (Close).
type Options ¶
type Options struct {
Buckets []string
// Served are the chains this host serves: <bucket>|<owner hex>|<id hex>.
Served []string
Host bmodule.Host
Journal Journal
// Priced are the priceable classes this host prices: asked through the
// engine, they are refused.
Priced map[string]bool
// The retention floors; their floors when zero.
KeepDays, PendingDays, OtherHours int
Headers chaintracker.ChainTracker
// Now is the host's clock; time.Now when nil.
Now func() time.Time
// Trees is the chain view a replay reads a chain's first token's parent
// from (Replay); nil when the host has none.
Trees replay.TreeSource
// MaxBEEF and MaxSweepInputs are the topic managers' bounds, which a
// replay holds a token it assembles to; storerec's defaults when zero.
MaxBEEF, MaxSweepInputs int
// Positions keeps the position a replay reached with each peer, and
// where since lists what it listed again, across a restart; nil keeps
// them in memory only.
Positions Positions
}
Options build a Service.
type OutputList ¶
type OutputList struct {
Type string `json:"type"`
Outputs []outputJSON `json:"outputs"`
}
OutputList is the engine's lookup answer as JSON.
type RecordsTopicManager ¶
type RecordsTopicManager struct {
Topic string
Bucket string
// contains filtered or unexported fields
}
RecordsTopicManager is tm_bstore_<bucket>, the records topic of one bucket (spec section 12.1). The rules are storerec.Admit's; this is the engine seam: it runs them on the submission and turns the verdict into admittance instructions.
The engine records every transaction a topic manager returns instructions for as applied, empty instructions included, and a later submission of the same txid is a duplicate no topic manager is shown again. A refusal returned as empty instructions would therefore be permanent for that txid: anyone could suppress a genuine object by submitting it first in a different BEEF, and a token refused because the host's headers lagged would stay refused. So every refusal is raised, and the engine records nothing and marks nothing spent. No rule reads another topic, another record or anything this topic holds; the previous coins decide only which held outputs an accepted transaction retains: every one, so no admitted output is deleted when something spends it.
func NewRecordsTopicManager ¶
func NewRecordsTopicManager(topic string, host bmodule.Host, headers chaintracker.ChainTracker, maxBEEF, maxSweepInputs int) (*RecordsTopicManager, error)
NewRecordsTopicManager makes the records manager of one topic; a bound below its floor is refused.
func (*RecordsTopicManager) Admit ¶
func (t *RecordsTopicManager) Admit(ctx context.Context, raw []byte, held []int) (overlay.AdmittanceInstructions, error)
Admit applies the rules to the submission's bytes with the held inputs, as the TypeScript manager's identifyAdmissibleOutputs does. A verdict Precheck left in ctx for these bytes is finished with held instead.
func (*RecordsTopicManager) GetDocumentation ¶
func (t *RecordsTopicManager) GetDocumentation() string
GetDocumentation implements module.TopicManager.
func (*RecordsTopicManager) GetMetaData ¶
func (t *RecordsTopicManager) GetMetaData() *overlay.MetaData
GetMetaData implements module.TopicManager.
func (*RecordsTopicManager) IdentifyAdmissibleOutputs ¶
func (t *RecordsTopicManager) IdentifyAdmissibleOutputs(ctx context.Context, _ *transaction.Beef, _ *chainhash.Hash, previousCoins []uint32) (overlay.AdmittanceInstructions, error)
IdentifyAdmissibleOutputs implements bcommon's module.TopicManager over the submission's bytes in ctx.
func (*RecordsTopicManager) IdentifyNeededInputs ¶
func (*RecordsTopicManager) IdentifyNeededInputs(context.Context, *transaction.Beef, *chainhash.Hash) ([]*transaction.Outpoint, error)
IdentifyNeededInputs implements module.InputIdentifier: nothing is needed, since a carrier carries its funding tree, a token its parent and a mined object its own proof.
func (*RecordsTopicManager) Precheck ¶
func (t *RecordsTopicManager) Precheck(ctx context.Context) context.Context
Precheck decides the submission in ctx (bcommon module.WithSubmission) on every rule but the range of its previous coins (storerec.Prepare) and returns ctx carrying the verdict, which Admit finishes under the lock. No rule reads what the topic holds, so a host that runs this before it takes the topic's lock (a Go host's admission pipeline can) holds the lock only for what the topic holds. It counts and logs nothing: Admit does, when the host shows it the transaction.
type Refused ¶
Refused is raised for every refusal. The engine counts it as a failed topic for this submission and stores nothing.
type RouteAnswerer ¶
type RouteAnswerer struct{ LS *Service }
RouteAnswerer is ls_bstore as the terms route asks its questions: a priced answer is hydrated as the engine hydrates one.
func (RouteAnswerer) Answer ¶
func (r RouteAnswerer) Answer(ctx context.Context, q termsroute.Question) (any, error)
Answer implements termsroute.Answerer.
func (RouteAnswerer) Classify ¶
func (r RouteAnswerer) Classify(_ context.Context, q termsroute.Question) (string, error)
Classify implements termsroute.Answerer.
func (RouteAnswerer) Restored ¶
func (r RouteAnswerer) Restored() bool
Restored implements termsroute.Answerer.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is ls_bstore: one lookup service for every bucket a host carries (spec sections 11 and 12.2 to 12.6).
Two stores back it. The engine's storage holds the outputs the host keeps: bucket tokens, entry, outcome and front carriers, advertisements, hold outputs and sweeps' output 0, which this service indexes in memory and rebuilds from storage on start. The journal holds what storage cannot: the first carrier of each funding outpoint, the input outpoints of every admitted sweep, the retraction marks, first sights, and which held outputs a later transaction spent.
Every status is a function of what the host holds, never of arrival order, except where the contract makes it one (the first carrier per funding outpoint, the first 16 front statements, first sights):
- a token is rooted when the host holds every token from it back to its chain's first by spends, pending until then; a rooted token of a served chain takes the status its branch's fold gives it (consistent, or map-mismatch, sticky). Only rooted, consistent tokens are answered as latest;
- an entry is anchored while a served chain's current map holds it, replaced once a consistent token named it and the map no longer does, pending while no token of the chain names it, and retracted when an admitted sweep spends its funding outpoint or the outpoint carries a retraction mark. A retracted carrier is dropped at once and never answered;
- an advertisement is live until a renewal (or any admitted transaction) spends it or its expiry passes the host's clock.
To drop an object is to delete its output from the topic and evict the engine's record that its transaction was applied, so the same object offered again is decided afresh, through the storage a restore is handed (Deleter, Evicter).
func NewService ¶
NewService builds ls_bstore and loads the journal.
func (*Service) AdmissionMode ¶
func (*Service) AdmissionMode() bmodule.AdmissionMode
AdmissionMode implements module.LookupService.
func (*Service) Answer ¶
Answer answers a validated question. paid says the question was paid for (or asked where no payment is due); a class this host prices is refused otherwise.
func (*Service) Classify ¶
func (s *Service) Classify(service string, query []byte) (*Classified, error)
Classify validates a question and names its class, as the terms route and the engine ask it: exactly the members of one class, every value checked, a bucket this host carries, and a chain it serves for a map class; anything else is an error.
func (*Service) Flush ¶
Flush deletes dropped outputs from storage and evicts the engine's record that their transactions were applied once the index holds no output of them, so the same object offered again is decided afresh. A drop decided while the engine admits the object waits until the engine has recorded the admission (it records it after the lookup services are told), for at most SettleMs. A store that cannot delete keeps what was dropped, unanswered; a store that cannot evict leaves a dropped object a duplicate when it is offered again. Each is said once in the log.
Flush takes the drops waiting when it starts in chunks of FlushChunk, releasing the lock between chunks: under a put load nearly every object leaves a drop (the entry it supersedes), so one pass every FlushEvery can carry thousands of storage deletes, and admissions (OutputAdmittedByTopic) and lookups wait on the lock while a chunk runs, never for the whole pass. Each drop is decided under the lock when its chunk runs, as before.
func (*Service) GetDocumentation ¶
GetDocumentation implements module.LookupService.
func (*Service) GetMetaData ¶
GetMetaData implements module.LookupService.
func (*Service) HoldsCarrier ¶
HoldsCarrier is whether the host holds the carrier with commitment c (hash byte order hex).
func (*Service) Hydrate ¶
func (s *Service) Hydrate(ctx context.Context, formulas []Formula) ([]bmodule.HydratedOutput, error)
Hydrate is an answer with each output's BEEF, as the engine hydrates one, read from the host's storage. A context rides along.
func (*Service) Lookup ¶
func (s *Service) Lookup(ctx context.Context, q *lookup.LookupQuestion) (*lookup.LookupAnswer, error)
Lookup implements module.LookupService: asked through the engine, a class the host prices is refused here. The answer is hydrated here and carries each output's context (bcommon module.HydratedOutput).
func (*Service) Mark ¶
Mark is the retraction mark of outpoint op, when the host keeps one: its owner, its time and whether it is kept for the host's life.
func (*Service) OutputAdmittedByTopic ¶
func (s *Service) OutputAdmittedByTopic(ctx context.Context, p *bmodule.OutputAdmittedByTopic) error
OutputAdmittedByTopic implements module.LookupService: it indexes an admitted output, then reads back tokens whose predecessor is rooted now. What it drops is deleted by the next Flush, once the engine has recorded the admission.
func (*Service) OutputEvicted ¶
OutputEvicted implements module.LookupService.
func (*Service) OutputNoLongerRetainedInHistory ¶
func (s *Service) OutputNoLongerRetainedInHistory(_ context.Context, op *transaction.Outpoint, topic string) error
OutputNoLongerRetainedInHistory implements module.RetentionListener.
func (*Service) Prune ¶
Prune applies retention at the host's time (spec section 12.3), never against a restore in flight: it drops every carrier, token, advertisement, hold output and sweep whose floor has passed, forgets the outpoints, marks and rows whose floor has passed, ages the windows unanchored, outcomes and ads answer from, and rewrites the journal. It answers how many objects were dropped.
func (*Service) Replay ¶
func (s *Service) Replay(ctx context.Context, r *bmodule.ReplayRequest) (*bmodule.ReplayAnswer, error)
Replay implements bcommon module.Replayer for tm_bstore_ topics. A blob topic holds nothing (no host admits a piece), so its walk is over at once.
func (*Service) Restore ¶
func (s *Service) Restore(ctx context.Context, outputs []bmodule.Output, storage bmodule.RestoreStorage) (int, error)
Restore implements module.Restorer (spec section 12.5): it rebuilds the index. The journal's state, then every output of this module's topics the host hands over (a row handed without its BEEF is read again with it), then every token and mined output the journal names that the unspent rows did not carry, and then each held token's predecessors through the input that spends them. A token is read as the engine stores it. Chains are rooted and folded from seq 0 whatever order storage returns rows in. A storage failure propagates: a restore that skipped a sweep would answer retracted carriers.
func (*Service) SpendNotificationMode ¶
func (*Service) SpendNotificationMode() bmodule.SpendNotificationMode
SpendNotificationMode implements module.LookupService.