Documentation
¶
Overview ¶
Package seen is a receiver's memory of the funding outputs it has accepted carriers on: an append-only file of fixed records, read into a map when it is opened.
A carrier is never mined, so the chain keeps no record of a funding output having been used, and a stream that verified once verifies again. A receiver that records each output as it accepts a carrier on it, before it writes that carrier's data, can refuse the output the second time. A crash between the record and the write loses data and never opens a replay.
The file grows by one record per carrier. Prune drops the records of outputs mined below a height, and keeps that height as a floor: a receiver that also refuses postage older than a limit needs no memory of outputs older than that, so long as it takes nothing from below the floor again.
Index ¶
Constants ¶
const (
RecordLen = 72
)
The file: an 8-byte magic, then records of RecordLen bytes.
offset size field 0 32 funding transaction id 32 4 funding output index, big-endian 36 32 id of the carrier accepted on that output 68 4 height the funding transaction was mined at, big-endian
A record whose first 36 bytes are zero names no output: its height is the floor.
Variables ¶
var ErrFormat = errors.New("seen: not a beefcat seen-output file")
ErrFormat is a file that is not a seen-output log.
var ErrLocked = errors.New("the seen-output file is in use by another beefcat command")
ErrLocked is a seen-output file another beefcat command is using.
Functions ¶
This section is empty.
Types ¶
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log is an open seen-output file. One process holds it at a time. It is not safe for use by several goroutines.
func Open ¶
Open opens the file at path, creating it when it is not there, and takes its lock (path with ".lock" appended). A record cut short at the end of the file, left by a crash, is dropped.
func (*Log) Add ¶
Add records a carrier accepted on an output mined at height. The record is durable only after Sync. An output already recorded keeps its first carrier.
func (*Log) Floor ¶
Floor is the height below which the log no longer holds records: the highest height it was ever pruned to. An output mined below it may have been seen and forgotten, so a reader does not take one.
func (*Log) Prune ¶
Prune drops the records of outputs mined below height, raises the floor to height, and returns how many records it dropped. The floor is kept in the file and never falls, so a later prune to a lower height, as after a header source reports a lower tip, forgets nothing and admits nothing that was forgotten. The file is rewritten whole and replaced.