seen

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 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 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

View Source
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

View Source
var ErrFormat = errors.New("seen: not a beefcat seen-output file")

ErrFormat is a file that is not a seen-output log.

View Source
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

func Open(path string) (*Log, error)

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

func (l *Log) Add(o Outpoint, carrier [32]byte, height uint32) error

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) Close

func (l *Log) Close() error

Close syncs and releases the file and its lock.

func (*Log) Floor

func (l *Log) Floor() uint32

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) Len

func (l *Log) Len() int

Len is how many outputs are recorded.

func (*Log) Lookup

func (l *Log) Lookup(o Outpoint) (carrier [32]byte, ok bool)

Lookup reports the carrier recorded on an output, if any.

func (*Log) Prune

func (l *Log) Prune(height uint32) (int, error)

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.

func (*Log) Sync

func (l *Log) Sync() error

Sync makes every record added so far durable.

type Outpoint

type Outpoint [36]byte

Outpoint names a funding output: a transaction id and an output index, big-endian.

func NewOutpoint

func NewOutpoint(txid [32]byte, vout uint32) Outpoint

NewOutpoint builds an Outpoint.

Jump to

Keyboard shortcuts

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