Documentation
¶
Overview ¶
Package state is a producer's durable record of one stream: its head (seq and commitment), the carrier persisted before it is published, the commitments not yet anchored, the anchor chain's head and the anchor in flight, and the funding trees carriers and anchors spend.
A producer that loses this file loses its head, and a producer that has lost its head must not restart the stream (docs/spec.md section 12): it creates a new one. So the file is written atomically (a temporary file, fsync, rename, fsync of the directory) at mode 0600, and a stream's directory is locked while a command writes it.
Index ¶
Constants ¶
const ( // SweepRetract spends outputs of a batch funding tree, used or not, // with bcommon carrier.Sweep: output 0 is a funding-shaped tombstone, // and every carrier that spent one of the outputs is retracted once it // mines (docs/spec.md section 6.4). SweepRetract = "retract" // SweepRetire spends only unused outputs of a tree no longer in use, // paying their value back to the coin pool. It retracts nothing. SweepRetire = "retire" )
The kinds of sweep.
const Version = 1
Version is the state file's format version.
Variables ¶
var ErrExists = errors.New("state: stream already exists in this home")
ErrExists is a stream this home already holds.
var ErrLocked = errors.New("state: locked by another blogs process")
ErrLocked is a lock another process holds.
var ErrNoStream = errors.New("state: no such stream in this home")
ErrNoStream is a stream this home holds no state for.
Functions ¶
Types ¶
type Anchor ¶
type Anchor struct {
Interval uint64 `json:"interval"`
First uint64 `json:"first"`
Count uint64 `json:"count"`
Txid string `json:"txid"`
Vout uint32 `json:"vout"`
RawHex string `json:"rawHex"`
// BeefHex is kept while the token is unmined; BumpHex and Height once
// it mined.
BeefHex string `json:"beefHex,omitempty"`
BumpHex string `json:"bumpHex,omitempty"`
Height uint32 `json:"height,omitempty"`
// Submitted is set once the settlement leg accepted the token.
Submitted bool `json:"submitted,omitempty"`
}
Anchor is an anchor token the producer built.
type PendingTree ¶
type PendingTree struct {
// Kind is which trees it belongs to: "batch" or "anchor".
Kind string `json:"kind"`
// Tree is the record the tree is adopted as, without a proof.
Tree funding.Tree `json:"tree"`
// Coin is the fee coin the tree spends, as the pool held it.
Coin bwallet.Output `json:"coin"`
// ReturnedOnce is set when a command found the tree absent from the
// node and the coin unspent, and put the coin back: the record is kept
// for one more command, in case the tree reaches the node after all.
ReturnedOnce bool `json:"returned_once,omitempty"`
}
PendingTree is a funding tree signed for a pool coin and not yet adopted, keyed by the tree's txid.
type Stream ¶
type Stream struct {
Version int `json:"version"`
// Stream is the full identifier <name>_<suffix>.
Stream string `json:"stream"`
// Identity is the producer's identity key, compressed hex.
Identity string `json:"identity"`
// Seq is the last seq built; Head its commitment, hash byte order hex.
// Zero and empty before the first batch.
Seq uint64 `json:"seq"`
Head string `json:"head,omitempty"`
// Pending is the carrier of Seq while it may not have reached the
// facade: persisted before the publish, cleared after it. A run that
// finds it publishes these same bytes again, never a new carrier for
// the same seq.
Pending string `json:"pending,omitempty"`
// Unanchored are the commitments of seq NextFirst to Seq, hash byte
// order hex, in seq order: what the next anchors cover.
Unanchored []string `json:"unanchored,omitempty"`
// NextFirst is the first seq no mined and published anchor covers.
NextFirst uint64 `json:"nextFirst"`
// Anchor is the last anchor token mined and published: the head of the
// anchor chain. Nil before the first.
Anchor *Anchor `json:"anchor,omitempty"`
// Inflight is the anchor built and handed to the settlement leg that
// has not yet been published. At most one is in flight.
Inflight *Anchor `json:"inflight,omitempty"`
// LastAnchorMs is when the last anchor was built, Unix milliseconds.
LastAnchorMs int64 `json:"lastAnchorMs,omitempty"`
// Tree and Trees are the current batch funding tree and every one
// minted; AnchorTree and AnchorTrees the same for the trees anchors
// spend their fee from. Ahead are trees minted ahead and not adopted
// when a run ended: on the chain, in no other list, kept so a sweep
// finds them.
Tree *funding.Tree `json:"tree,omitempty"`
Trees []funding.Tree `json:"trees,omitempty"`
AnchorTree *funding.Tree `json:"anchorTree,omitempty"`
AnchorTrees []funding.Tree `json:"anchorTrees,omitempty"`
Ahead []funding.Tree `json:"ahead,omitempty"`
// PendingTrees are the funding trees signed for a pool coin that the
// stream has not adopted yet, each with its kind and the coin it
// spends: the record made before a tree reaches the settlement leg, so
// a run that stops before the tree is adopted leaves what the next
// command needs to ask the node what became of it. Adopting a tree
// drops its record in the same save.
PendingTrees []PendingTree `json:"pendingTrees,omitempty"`
// Unpublished are the txids of trees adopted into Trees or AnchorTrees
// whose publish to the hosts failed: publish pending. The next command
// that spends publishes them before anything else.
Unpublished []string `json:"unpublished,omitempty"`
// Sweeps are the transactions built to spend funding-tree outputs, in
// the order they were built: retractions and retirements. One neither
// Done nor Failed is in flight, and the next sweep resumes it before
// anything else.
Sweeps []Sweep `json:"sweeps,omitempty"`
// Tail is where a file being followed was read to.
Tail *Tail `json:"tail,omitempty"`
// contains filtered or unexported fields
}
Stream is one stream's state.
func (*Stream) DropPendingTree ¶
DropPendingTree drops the record of the tree txid, and reports whether there was one.
func (*Stream) KeepPendingTree ¶
func (s *Stream) KeepPendingTree(p PendingTree)
KeepPendingTree records p, replacing a record of the same tree.
func (*Stream) MintedAhead ¶
MintedAhead reports whether txid is among the trees minted ahead and not adopted.
func (*Stream) PendingTree ¶
func (s *Stream) PendingTree(txid string) *PendingTree
PendingTree finds the record of the tree txid, or nil.
type Sweep ¶
type Sweep struct {
Kind string `json:"kind"`
Tree string `json:"tree"`
Vouts []uint32 `json:"vouts"`
// Seqs are the batches it retracts, when they were named.
Seqs []uint64 `json:"seqs,omitempty"`
Txid string `json:"txid"`
RawHex string `json:"rawHex"`
// BeefHex is kept while it is unmined; BumpHex and Height once it
// mined.
BeefHex string `json:"beefHex,omitempty"`
BumpHex string `json:"bumpHex,omitempty"`
Height uint32 `json:"height,omitempty"`
// Publish is set when the hosts hold what it spends, so it goes to the
// stream's topic once mined; a tree minted ahead and never published
// is retired without it.
Publish bool `json:"publish,omitempty"`
Submitted bool `json:"submitted,omitempty"`
Done bool `json:"done,omitempty"`
// Fee is the pool coin that pays a retraction's fee, as the pool held
// it, so a retraction the network refuses can give it back. A
// retirement pays its fee from the outputs it spends and has none.
Fee *bwallet.Output `json:"fee,omitempty"`
// Failed is why the network refused it, once it did: the node named
// another transaction as the spender of one of its inputs. It is no
// longer in flight, retracts or retires nothing, and is never Done.
Failed string `json:"failed,omitempty"`
}
Sweep is one mined transaction spending funding-tree outputs.