Documentation
¶
Overview ¶
Package module is the blogs overlay module in Go: `tm_log_<name>_<suffix>` for each configured stream and `ls_log` 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: bug fixes only), built from the Go core: the admission rules are logrec.Admit, the questions logrec.ParseQuery, the interval roots logrec.IntervalRoot.
Configuration is the TypeScript module's, read from the environment when the host calls the factory (docs/host.md): BLOGS_STREAMS, and for retention BLOGS_KEEP_DAYS with BLOGS_STATE_DIR. Every mistake is an error, and the host refuses to start.
Index ¶
- Constants
- Variables
- type CoinSource
- type Config
- type Counts
- type Deleter
- type FileStore
- type Formula
- type IntervalReport
- type Mark
- type MemoryStore
- type Mounted
- type Retention
- type RetentionConfig
- type RetentionPass
- type RetentionState
- type Service
- func (*Service) AdmissionMode() bmodule.AdmissionMode
- func (s *Service) Answer(ctx context.Context, service string, query []byte) ([]Formula, error)
- func (s *Service) BatchStatusOf(producer, name, txid string) (string, bool)
- func (s *Service) Coin(ctx context.Context, topic string, op transaction.Outpoint) (logrec.Coin, bool, error)
- func (s *Service) Counts() Counts
- func (*Service) GetDocumentation() string
- func (*Service) GetMetaData() *overlay.MetaData
- func (s *Service) Lookup(ctx context.Context, q *lookup.LookupQuestion) (*lookup.LookupAnswer, error)
- func (s *Service) OutputAdmittedByTopic(_ 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) Report(name string) []StreamReport
- func (s *Service) Restore(ctx context.Context, outputs []bmodule.Output, storage bmodule.RestoreStorage) (int, error)
- func (s *Service) Restored() bool
- func (s *Service) Retain(ctx context.Context) RetentionPass
- func (*Service) SpendNotificationMode() bmodule.SpendNotificationMode
- type StateStore
- type StreamConfig
- type StreamReport
- type TokenReport
- type TopicManager
- func (t *TopicManager) Admit(ctx context.Context, beef []byte, previousCoins []uint32) (overlay.AdmittanceInstructions, error)
- func (t *TopicManager) GetDocumentation() string
- func (t *TopicManager) GetMetaData() *overlay.MetaData
- func (t *TopicManager) IdentifyAdmissibleOutputs(ctx context.Context, beef *transaction.Beef, txid *chainhash.Hash, ...) (overlay.AdmittanceInstructions, error)
- func (*TopicManager) IdentifyNeededInputs(context.Context, *transaction.Beef, *chainhash.Hash) ([]*transaction.Outpoint, error)
- type TreeLow
- type Unrecorded
Constants ¶
const ( BatchRetracted = "retracted" BatchFork = "fork" BatchGap = "gap" BatchLinked = "linked" TokenCanonical = "canonical" TokenBranch = "anchor-branch" TokenJoin = "anchor-join" TokenPending = "pending" IntervalComplete = "complete" IntervalIncomplete = "incomplete" IntervalRootMismatch = "root-mismatch" )
The statuses of spec sections 8.2 and 8.3.
const MaxCandidates = 8
MaxCandidates is how many candidates are kept and answered per seq, and anchor tokens per interval (spec section 11).
const MinKeepDays = 1
MinKeepDays is the least BLOGS_KEEP_DAYS a host may set.
const Name = "blogs"
Name is the module's name, as a host's module list names it.
const RetentionEvery = time.Hour
RetentionEvery is how often a retention pass runs after the one that follows restore.
const StateFile = "blogs-retention.json"
StateFile is the state file's name in BLOGS_STATE_DIR.
const TickEvery = 30 * time.Second
TickEvery is how often the background tick looks for a retention pass to run: the first once the index is restored, then every RetentionEvery.
Variables ¶
var AdmitKinds = []string{"batch", "anchor", "funding", "spend", "none"}
AdmitKinds are what an accepted transaction was: a batch carrier, an anchor token, a mined funding tree or sweep, a spend of held outputs, or none of these (it claims nothing, spends nothing held and admits nothing).
var Build = "unversioned"
Build is the version the host logs; a binary sets it (the TypeScript bundle's BLOGS_BUILD banner).
var DeferredReasons = []string{"anchor-input", "unmined"}
DeferredReasons are refusals whose verdict can change with what the host holds or its headers.
var EngineVerified chaintracker.ChainTracker = engineVerified{}
EngineVerified is engineVerified as a chain tracker.
var ErrNoTransaction = errors.New("blogs: the submission's BEEF holds no transaction")
ErrNoTransaction is a submission whose BEEF names no transaction.
var Reasons = []string{
"too-large", "cbor", "key-type", "magic", "missing", "type", "range", "producer", "stream", "prev", "profile-shape",
"locator", "content", "carrier-shape", "anchor-shape", "producer-policy", "mineable", "lock", "signature", "funding",
"unlock", "anchor-input", "unmined",
}
Reasons are every refusal label, for presetting the refusal counter.
Functions ¶
This section is empty.
Types ¶
type CoinSource ¶
type CoinSource func(ctx context.Context, topic string, op transaction.Outpoint) (logrec.Coin, bool, error)
CoinSource is the output the topic holds at an outpoint, or false. The lookup service provides it: from the engine's storage once the host has handed it over, otherwise from the outputs it has indexed.
type Config ¶
type Config struct {
Streams []StreamConfig
// Retention is nil when BLOGS_KEEP_DAYS is unset.
Retention *RetentionConfig
}
Config is the module's configuration.
type Counts ¶
type Counts struct {
Streams, Batches, Tokens, Trees, Retracted, ForkSeqs int
Missing, Retired uint64
}
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 retention asserts for on the restore seam, beyond the contract's RestoreStorage.
type FileStore ¶
type FileStore struct{ Dir string }
FileStore is the state file in Dir: written whole, flushed, then renamed over the last.
func (FileStore) Load ¶
func (f FileStore) Load() (RetentionState, error)
Load implements StateStore. A missing file is the empty state; a file that does not parse stops the host, because a dropped position read as held again would be counted a hole.
type IntervalReport ¶
type IntervalReport struct {
Interval uint64
First uint64
Count uint64
Txid string
Status string
// Missing are the seqs the interval covers that no batch and no receipt
// holds.
Missing []uint64
// Retired is a complete interval whose carriers retention dropped.
Retired bool
}
IntervalReport is one interval of a canonical chain.
type Mark ¶
type Mark struct {
Producer string `json:"producer"`
Stream string `json:"stream"`
Interval uint64 `json:"interval"`
Seq uint64 `json:"seq"`
C string `json:"c"`
}
Mark is one stream's dropped prefix: intervals 1 to Interval, seqs 1 to Seq, and C, the commitment kept at Seq (hash byte order, hex): what Seq + 1's prev must equal to be linked.
type MemoryStore ¶
type MemoryStore struct {
State RetentionState
Saved int
// Fail, when set, fails every Save.
Fail error
// contains filtered or unexported fields
}
MemoryStore is a StateStore in memory, for tests.
func (*MemoryStore) Load ¶
func (m *MemoryStore) Load() (RetentionState, error)
Load implements StateStore.
func (*MemoryStore) Save ¶
func (m *MemoryStore) Save(s RetentionState) error
Save implements StateStore.
type Mounted ¶
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, store StateStore, headers chaintracker.ChainTracker, now func() int64) (*Mounted, error)
Mount builds the module for c. overlayTopics is OVERLAY_TOPICS, when known; store replaces the retention state file, headers the topic managers' engine-verified tracker and now the host's clock in Unix milliseconds, for tests.
type Retention ¶
type Retention struct {
KeepMs float64
Store StateStore
Now func() int64
}
Retention is a host's policy: how long a proven carrier is kept, where the state is kept, and the host's clock in Unix milliseconds.
type RetentionConfig ¶
type RetentionConfig struct {
// KeepMs is how long a proven carrier is kept, in milliseconds.
KeepMs float64
StateDir string
}
RetentionConfig is BLOGS_KEEP_DAYS and BLOGS_STATE_DIR.
func ParseRetention ¶
func ParseRetention(getenv func(string) string) (*RetentionConfig, error)
ParseRetention reads BLOGS_KEEP_DAYS and BLOGS_STATE_DIR; nil when retention is off.
type RetentionPass ¶
type RetentionPass struct {
// Intervals is how many intervals had their carriers dropped.
Intervals int
// Carriers is how many carriers left the index.
Carriers int
// Deleted is how many carrier outputs were deleted from storage, this
// pass's and any left from before.
Deleted int
}
RetentionPass is what a retention pass did.
type RetentionState ¶
RetentionState is what the state file holds.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is ls_log: one lookup service for every stream a host carries (spec sections 7.2 and 8.2 to 8.5).
It indexes what the topic managers admitted, per (producer, stream): batches by seq (at most 8 candidates per seq), anchor tokens by interval (at most 8 per interval), and, per outpoint, the transactions that spent it, read from each admitted transaction's own inputs. Every status is a function of that set, computed when asked, so arrival order and restart order never change it. It answers exactly the three free question classes and refuses every other query with an error. Statuses are reported by Report, the metrics and the log, never inside an answer.
func NewService ¶
NewService makes ls_log for these topics. retention nil keeps everything.
func (*Service) AdmissionMode ¶
func (*Service) AdmissionMode() bmodule.AdmissionMode
AdmissionMode implements module.LookupService: the whole transaction, as a carrier's funding outpoint and every spend are its inputs.
func (*Service) BatchStatusOf ¶
BatchStatusOf is the status of the batch whose carrier is txid (display hex) on a stream, if held.
func (*Service) Coin ¶
func (s *Service) Coin(ctx context.Context, topic string, op transaction.Outpoint) (logrec.Coin, bool, error)
Coin is the output the topic holds at an outpoint: from the engine's storage once restore has handed it over (the host calls restore before it accepts a submission), otherwise from what this service indexed.
func (*Service) GetDocumentation ¶
GetDocumentation implements module.LookupService.
func (*Service) GetMetaData ¶
GetMetaData implements module.LookupService.
func (*Service) Lookup ¶
func (s *Service) Lookup(ctx context.Context, q *lookup.LookupQuestion) (*lookup.LookupAnswer, error)
Lookup implements module.LookupService: a formula answer, which the engine hydrates from its storage as the TypeScript engine does.
func (*Service) OutputAdmittedByTopic ¶
OutputAdmittedByTopic implements module.LookupService.
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) Report ¶
func (s *Service) Report(name string) []StreamReport
Report is the statuses of every (producer, stream) held, or of one stream when name is not empty, ordered by producer then stream.
func (*Service) Restore ¶
func (s *Service) Restore(ctx context.Context, outputs []bmodule.Output, storage bmodule.RestoreStorage) (int, error)
Restore implements module.Restorer: it rebuilds the index from storage (spec section 8.5). The host hands the unspent outputs of this module's topics with their BEEF (a row handed without it is read again from storage with it); the index also needs spent ones (each anchor token but the newest is spent by the next, and a carrier's funding output by the carrier and by any sweep), so it walks from every row to the outputs its transaction spent (OutputsConsumed), the outputs that spent it (ConsumedBy), and its transaction's other outputs, asking storage for each. Every output connected to an unspent one is found, whatever order storage returns them in; statuses are functions of the set. Storage is kept for the topic managers' previous coins. A storage failure propagates: a restore that skipped a retraction would serve retracted batches.
func (*Service) Retain ¶
func (s *Service) Retain(ctx context.Context) RetentionPass
Retain is one retention pass at the host's time: for each stream, its oldest intervals not yet dropped, in order, while each is canonical, complete and older than the policy, have every carrier dropped from the index; the state file is written; then the dropped carriers' outputs are deleted from storage. Nothing happens before a restore has handed storage over. Passes never overlap.
func (*Service) SpendNotificationMode ¶
func (*Service) SpendNotificationMode() bmodule.SpendNotificationMode
SpendNotificationMode implements module.LookupService: spends are read from admitted transactions, never from the engine's notices.
type StateStore ¶
type StateStore interface {
Load() (RetentionState, error)
Save(RetentionState) error
}
StateStore is where the state lives.
type StreamConfig ¶
StreamConfig is one stream and its producer policy.
func ParseStreams ¶
func ParseStreams(raw string) ([]StreamConfig, error)
ParseStreams parses BLOGS_STREAMS: a comma list of `<stream>=open` or `<stream>=<key>[+<key>...]`, each key 66 lowercase hex characters, a compressed secp256k1 key. Openness is stated, never inferred.
type StreamReport ¶
type StreamReport struct {
Producer string
Stream string
// Highest is the highest seq held.
Highest uint64
// Holes are the seqs from 1 to Highest with no batch and no receipt, as
// inclusive ranges.
Holes [][2]uint64
// Forks are the seqs with the status fork.
Forks []uint64
// Retracted are the seqs whose every candidate is retracted.
Retracted []uint64
// Intervals are the canonical chain's, in order.
Intervals []IntervalReport
// Tokens are those outside the canonical chain.
Tokens []TokenReport
}
StreamReport is the statuses of one (producer, stream).
type TokenReport ¶
TokenReport is a token outside the canonical chain, with why.
type TopicManager ¶
TopicManager is tm_log_<name>_<suffix>: the topic manager of one stream (spec section 8.1). The rules are logrec.Admit's; this is the engine seam: it reads the previous coins, runs the rules, and turns the verdict into admittance instructions.
How a refusal reaches the engine matters, because the engine records every transaction a topic manager returns instructions for as applied, empty instructions included, and treats a later submission of the same transaction as a duplicate that no topic manager sees again. It also marks spent, or deletes, every held output the transaction spends. A refusal is therefore returned (recorded) only when its verdict can never change and the transaction spends nothing the topic holds. Otherwise it is raised, and the engine records nothing.
func NewTopicManager ¶
func NewTopicManager(topic string, policy logrec.Policy, coins CoinSource, host bmodule.Host, headers chaintracker.ChainTracker) (*TopicManager, error)
NewTopicManager makes the manager of one topic. headers nil is the engine-verified tracker a host uses.
func (*TopicManager) Admit ¶
func (t *TopicManager) Admit(ctx context.Context, beef []byte, previousCoins []uint32) (overlay.AdmittanceInstructions, error)
Admit runs the rules on one submission's BEEF with the previous coins (by input index), as the TypeScript manager's identifyAdmissibleOutputs does.
func (*TopicManager) GetDocumentation ¶
func (t *TopicManager) GetDocumentation() string
GetDocumentation implements module.TopicManager.
func (*TopicManager) GetMetaData ¶
func (t *TopicManager) GetMetaData() *overlay.MetaData
GetMetaData implements module.TopicManager.
func (*TopicManager) IdentifyAdmissibleOutputs ¶
func (t *TopicManager) IdentifyAdmissibleOutputs(ctx context.Context, beef *transaction.Beef, txid *chainhash.Hash, previousCoins []uint32) (overlay.AdmittanceInstructions, error)
IdentifyAdmissibleOutputs implements bcommon's module.TopicManager. The rules read the submission as it arrived (bcommon module.WithSubmission), as the TypeScript manager reads the submitted BEEF; a host that does not hand the bytes over is answered from the parsed BEEF's transaction.
func (*TopicManager) IdentifyNeededInputs ¶
func (*TopicManager) IdentifyNeededInputs(context.Context, *transaction.Beef, *chainhash.Hash) ([]*transaction.Outpoint, error)
IdentifyNeededInputs implements module.InputIdentifier: nothing is needed, since a carrier carries its ancestry and an anchor's spent outputs are held.
type TreeLow ¶
TreeLow is, for one tree, the lowest funding output whose carrier retention dropped. Key is "topic|tree txid".
type Unrecorded ¶
Unrecorded is raised for a refusal the engine must not record: the engine counts it as a failed topic for this submission and stores nothing.
func (*Unrecorded) Error ¶
func (u *Unrecorded) Error() string