module

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 25 Imported by: 2 modules, 1 package

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 module is bdns's overlay module, against bcommon's engine-neutral contract: tm_bdns_<z> for each chain BDNS_ZONES names, and ls_bdns for all of them. A Go overlay host mounts it as it mounts bweb's.

| Variable | Meaning | | BDNS_ZONES | identifiers of record sets and origins, lower-case hex, comma | | | separated: the topics mounted | | BDNS_HEADERS_URL | a native header source proofs are checked against; else | | | OVERLAY_CHAIN_TRACKER_URL when it is an http or https URL | | BDNS_MAX_BEEF | the BEEF bound, at least 262144 (the default) |

Metrics, each label value preset at zero:

| Metric | Labels | Counts | | bdns_admitted_total | kind | admissions: record-set, origin, leaves, member, finding, | | | | challenge, host | | bdns_refused_total | reason | refusals, by zonerec.Reason label | | bdns_unrenderable_total | check | states admitted and marked: C2 to C7's labels, or guard | | bdns_expired_total | kind | records dropped at their expiry | | bdns_carriers_deleted_total | result | carriers of replaced or expired records deleted from the | | | | host's storage: ok, error | | bdns_lookups_total | kind | questions, by kind | | bdns_zones, bdns_states, | | gauges: chains carried, states kept, pieces held | | bdns_pieces | | | | bdns_members, | | gauges: live records of each kind | | bdns_findings, | | | | bdns_challenges, | | | | bdns_hosts | | |

Index

Constants

View Source
const (
	KindState  = "state"  // freeform: the latest state, whether it is mined and renderable
	KindLog    = "log"    // the chain's states from a seq onward, as outputs
	KindLeaves = "leaves" // a state's leaves object: its pieces in order, as outputs
	KindProof  = "proof"  // freeform: a proof for a name and type, or a whole name, against the latest state
	// The live records of spec section 12.7, as outputs.
	KindMembers    = "members"
	KindHosts      = "hosts"
	KindFindings   = "findings"
	KindChallenges = "challenges"
)

The kinds of question.

View Source
const MaxAnswer = 1000

MaxAnswer bounds the outputs one answer lists.

View Source
const MaxQuestion = 4096

MaxQuestion bounds a question's bytes.

View Source
const MaxZones = 4096

MaxZones bounds BDNS_ZONES: each chain is a topic.

View Source
const Name = "bdns"

Name is the module's name, as a host's module list names it.

Variables

View Source
var Build = "unversioned"

Build is the version the host logs; a binary sets it.

View Source
var ErrNoSubmission = errors.New("bdns: 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).

Kinds lists every kind, for documentation and metrics.

Functions

func CheckNoSync

func CheckNoSync(raw string) error

CheckNoSync refuses OVERLAY_SYNC_PEERS naming a bdns topic: a state is admitted only after the state before it and its leaves, which synchronizing unspent outputs carries in no order, so a node takes a chain as it is published or by replay from seq 0, never by sync.

func ParseZone

func ParseZone(s string) ([32]byte, bool)

ParseZone reads an identifier: 64 lower-case hex digits.

Types

type Config

type Config struct {
	Zones      [][32]byte
	HeadersURL string
	MaxBEEF    int
}

Config is the module's configuration.

func ParseConfig

func ParseConfig(getenv func(string) string) (*Config, error)

ParseConfig reads the configuration from getenv.

type Deleter added in v0.4.0

type Deleter interface {
	DeleteOutput(ctx context.Context, outpoint *transaction.Outpoint, topic string) error
}

Deleter is a storage that can delete an output: what dropping a record's carrier needs beyond the contract's RestoreStorage. The Go overlay engine's restore storage has it. A host whose storage cannot delete keeps the carriers, unanswered, and reads each again at every restore.

type Mounted

type Mounted struct {
	Module bmodule.Module
	LS     *Service
	// contains filtered or unexported fields
}

Mounted is the module for one configuration.

func Mount

func Mount(host bmodule.Host, c *Config, hdrs chaintracker.ChainTracker, now func() time.Time) (*Mounted, error)

Mount builds the module for c. hdrs replaces the configured header source and now the clock, for tests.

func New

func New(host bmodule.Host, getenv func(string) string) (*Mounted, error)

New is the factory a host calls: the configuration from getenv, checked against OVERLAY_SYNC_PEERS.

func (*Mounted) Start

func (m *Mounted) Start(ctx context.Context) error

Start runs the module's background work until ctx ends: dropping records past their expiry, and deleting the carriers of dropped and replaced records from the host's storage.

type ProofAnswer

type ProofAnswer struct {
	StateAnswer
	Count *uint64 `json:"count,omitempty"`
	Root  string  `json:"root,omitempty"`
	Proof string  `json:"proof,omitempty"`
}

ProofAnswer is the proof answer: the state, and when it is renderable its count and root and the proof's byte form (zonerec.Proof), in base64.

type Query

type Query struct {
	Kind string `json:"kind"`
	Zone string `json:"zone"`
	// From and Limit page a log: states from seq From, at most Limit.
	From  uint64 `json:"from,omitempty"`
	Limit int    `json:"limit,omitempty"`
	// Seq names the state whose leaves are asked for; absent is the latest.
	Seq *uint64 `json:"seq,omitempty"`
	// Name, Type and Scope name what a proof is about: a name's labels,
	// leftmost first (no labels is the apex); a type, 0 or absent for the
	// whole name; a scope in hex, absent for none.
	Name  *[]string `json:"name,omitempty"`
	Type  uint16    `json:"type,omitempty"`
	Scope string    `json:"scope,omitempty"`
	// Host narrows a records question to the records about one host key,
	// in 66 lower-case hex digits: members and findings that name it, its
	// host record.
	Host string `json:"host,omitempty"`
}

Query is a question to ls_bdns, as JSON. Kind is one of the Kinds; Zone is an identifier in lower-case hex.

func ParseQuery

func ParseQuery(raw []byte) (*Query, error)

ParseQuery reads a question: at most MaxQuestion bytes, one JSON object of the known members and nothing after it, a known kind, a zone, and what its kind needs.

type Refused

type Refused struct {
	Reason string
	Detail string
}

Refused is raised for every refusal, so the engine stores nothing and marks nothing spent. A refusal returned as empty instructions would be recorded as applied, and a later submission of the same txid never shown to a manager again: a state refused while its leaves were still on their way, or while the host's headers lagged, would stay refused.

func (*Refused) Error

func (r *Refused) Error() string

func (*Refused) Refused added in v0.2.0

func (r *Refused) Refused() bool

Refused says the error is a refusal of what was submitted, not a fault of the host. Hosts that know the convention (an error with Refused() true) answer it as a refusal, a 4xx, so a publisher can tell refused from broken.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is ls_bdns: every chain this host carries, indexed from what its topics admit, rebuilt from the host's rows at startup (Restore). Its one lock is never held across a read of the host's storage or headers.

func NewService

func NewService(host bmodule.Host, headers chaintracker.ChainTracker, now func() time.Time) *Service

NewService is an empty index. headers is what a stored proof is checked against; now is the clock a lapse time is read against, nil is time.Now.

func (*Service) AdmissionMode

func (*Service) AdmissionMode() bmodule.AdmissionMode

AdmissionMode implements module.LookupService: the whole transaction, since a token's BEEF shows whether it and the state before it are proven.

func (*Service) Buffered

func (s *Service) Buffered() int

Buffered is how many piece bytes the service keeps itself.

func (*Service) Builds

func (s *Service) Builds() int64

Builds is how many times a state's leaves were built into a tree.

func (*Service) Carry

func (s *Service) Carry(zone [32]byte) zonerec.View

Carry adds a chain the host carries and returns admission's view of it.

func (*Service) GetDocumentation

func (*Service) GetDocumentation() string

GetDocumentation implements module.LookupService.

func (*Service) GetMetaData

func (*Service) GetMetaData() *overlay.MetaData

GetMetaData implements module.LookupService.

func (*Service) Lookup

Lookup implements module.LookupService. log, leaves and the records questions are formula answers, outpoints the engine hydrates with their BEEF; state and proof are freeform. A chain the host does not carry, or holds nothing of, is an empty answer, never an error.

func (*Service) OutputAdmittedByTopic

func (s *Service) OutputAdmittedByTopic(_ context.Context, p *bmodule.OutputAdmittedByTopic) error

OutputAdmittedByTopic implements module.LookupService. What a topic manager admitted is indexed; an output the index cannot place (which the manager would not have admitted) is logged and left out, never an error that would fail the engine's admission.

func (*Service) OutputEvicted

func (s *Service) OutputEvicted(_ context.Context, op *transaction.Outpoint) error

OutputEvicted implements module.LookupService: a state or a piece the host no longer holds is never answered again. A state takes every state after it with it, since the chain is kept without a gap.

func (*Service) Pieces

func (s *Service) Pieces() int

Pieces is how many leaves pieces the index holds.

func (*Service) Prune added in v0.3.0

func (s *Service) Prune()

Prune drops every record past its expiry, counting each (spec section 12.7: a host keeps a record until its expiry), then deletes from the host's storage the carriers of the records dropped or replaced since the last Prune, oldest first. The deletes run with no lock held, each bounded by deleteTimeout; after one times out the rest wait for the next Prune, so a storage that hangs holds up no pruning. At most maxRetries deletes are kept to try again. A carrier of a record the index keeps is never deleted. Before a restore there is no storage to delete from, and nothing is queued: the restore finds the same carriers and queues them itself.

func (*Service) Records added in v0.3.0

func (s *Service) Records(kind zonerec.Kind) int

Records is how many live records of kind the index keeps.

func (*Service) Restore

func (s *Service) Restore(ctx context.Context, outputs []bmodule.Output, storage bmodule.RestoreStorage) (int, error)

Restore implements module.Restorer: the index from the host's unspent rows. A chain's spent tokens are not among them, so each unspent token is walked back to seq 0 through storage. Where two states stand at one seq (an unmined rival a mined state replaced stays in the host's storage) the mined one is kept, else the one admitted first. The new index is built beside the old one, with no lock held while storage is read, and then put in its place.

func (*Service) SpendNotificationMode

func (*Service) SpendNotificationMode() bmodule.SpendNotificationMode

SpendNotificationMode implements module.LookupService: a chain's order is its states' seq, so no spend is read.

func (*Service) States

func (s *Service) States() int

States is how many states the index keeps.

type StateAnswer

type StateAnswer struct {
	Zone  string `json:"zone"`
	Chain string `json:"chain"`
	Seq   uint64 `json:"seq"`
	// Token is the state's token, "<txid>.<vout>".
	Token string `json:"token"`
	// Mined says the host knows the token mined; Height is its block.
	Mined  bool   `json:"mined"`
	Height uint32 `json:"height,omitempty"`
	Lapse  uint64 `json:"lapse"`
	// Renderable is false when the state, or a state before it in the
	// chain, has a critical extension this host does not know (Critical is
	// the kind of the first such), or when the state itself fails one of
	// checks C2 to C7 or the guard check (Check is its label, C2 to C7's
	// when both apply).
	Renderable bool    `json:"renderable"`
	Critical   *uint64 `json:"critical,omitempty"`
	Check      string  `json:"check,omitempty"`
	// Held is the highest seq the host keeps: above Seq while an unmined
	// state past its lapse time is not answered.
	Held uint64 `json:"held"`
}

StateAnswer is the state answer, and the head of the proof answer: which state the host answers from, and what a token's bytes do not show.

type TopicManager

type TopicManager struct {
	Topic string
	Zone  [32]byte
	// contains filtered or unexported fields
}

TopicManager is tm_bdns_<z>, one chain's topic. The rules are zonerec.Admit's, on the submission's own bytes, the host's headers and clock, and what section 12 lets a verdict read of the topic: the state before, a rival at the same seq, the guarded state before, the leaves pieces, and the attached and host records kept.

func NewTopicManager

func NewTopicManager(host bmodule.Host, h zonerec.Admitter) (*TopicManager, error)

NewTopicManager makes the manager of one chain's topic. h carries the chain, the headers, the bound, the clock and the view of the topic.

func (*TopicManager) Admit

func (t *TopicManager) Admit(ctx context.Context, raw []byte, held []int) (overlay.AdmittanceInstructions, error)

Admit applies the rules to the submission's bytes with the held inputs.

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, _ *transaction.Beef, _ *chainhash.Hash, previousCoins []uint32) (overlay.AdmittanceInstructions, error)

IdentifyAdmissibleOutputs implements bcommon's module.TopicManager over the submission's bytes in ctx: the rules read the wire form (which transactions a BEEF carries, with which proofs), which a parsed and merged BEEF no longer shows.

func (*TopicManager) IdentifyNeededInputs

IdentifyNeededInputs implements module.InputIdentifier: nothing, since a token carries what its inputs spend and a leaves piece its funding tree.

Jump to

Keyboard shortcuts

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