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 )
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 ¶
New returns a registry holding at most maxEntries entries for roughly ttl each (an entry survives between ttl/2 and ttl).