registry

package
v0.13.5 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 2 Imported by: 2 modules, 3 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 registry remembers which object hashes crossed the bridge, and in which direction.

It does two jobs that look similar but are not:

  • Down (delivery): suppress re-injection of an object we already handed to the cluster. A/B tunnel failover and reconnects legitimately re-deliver.

  • Up (reverse path): decide whether a subtree/block the cluster just accepted actually originated here. Teranode's blockchain notifications carry no local-vs-remote marker (its own p2p announces every one of them), so "did we deliver this to the cluster?" is the origin filter. Anything registered as delivered is remote in origin and must not be pushed back up; anything unseen is ours to publish.

Entries expire: the question is only interesting while an object is in flight.

Structure

Sharded 64 ways by the first key byte (keys are content hashes, so the spread is uniform), and aged GENERATIONALLY: each shard keeps a current and a previous map, and rotation (every ttl/2, or when the current map reaches half the shard's capacity) drops the previous map wholesale and demotes the current one. Expiry is therefore O(1) amortized per operation; a whole-map sweep on every insert at capacity would be most of the process's CPU under a saturated tx lane. The trade is TTL precision: an entry now lives between ttl/2 and ttl (or less under capacity pressure), which is exactly as good for duplicate suppression.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Direction

type Direction uint8

Direction records how a hash became known.

const (
	// Delivered means the object arrived from the fabric and was handed to the
	// cluster. Seeing it again from either side is a duplicate.
	Delivered Direction = iota + 1
	// Submitted means the object originated in the cluster and was sent up the
	// tunnel. It will come back down the delivery lanes (own-traffic exclusion
	// does not cover subtree/block classes) and must be dropped on return.
	Submitted
)

func (Direction) String

func (d Direction) String() string

type Key

type Key [32]byte

Key identifies an object by its hash.

type Registry

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

Registry is a TTL'd set of hashes with the direction they were seen in.

func New

func New(ttl time.Duration, maxEntries int) *Registry

New returns a registry holding at most maxEntries entries for roughly ttl each (an entry survives between ttl/2 and ttl).

func (*Registry) Lookup

func (r *Registry) Lookup(key Key) (Direction, bool)

Lookup reports the direction key was seen in, without recording anything.

func (*Registry) Mark

func (r *Registry) Mark(key Key, dir Direction) (prev Direction, known bool)

Mark records key in direction dir and reports whether it was already known (with the direction it was known in). A hit refreshes the entry's age.

func (*Registry) Stats

func (r *Registry) Stats() Stats

Stats returns a snapshot of the registry's size and counters, aggregated over all shards.

type Stats

type Stats struct {
	Entries            int
	Hits, Adds, Pruned uint64
}

Stats is a snapshot for logging and metrics.

Jump to

Keyboard shortcuts

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