Documentation ¶
Index ¶
- Variables
- func Every(ctx context.Context, log logging.Logger, gossiper Gossiper, ...)
- func ResetBloomFilterIfNeeded(bloomFilter *BloomFilter, falsePositiveProbability float64) (bool, error)
- type BloomFilter
- type Config
- type Gossipable
- type GossipableAny
- type Gossiper
- type Handler
- type HandlerConfig
- type PullGossiper
- type Set
- type ValidatorGossiper
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidID = errors.New("invalid id")
)
Functions ¶
func ResetBloomFilterIfNeeded ¶
func ResetBloomFilterIfNeeded( bloomFilter *BloomFilter, falsePositiveProbability float64, ) (bool, error)
ResetBloomFilterIfNeeded resets a bloom filter if it breaches a target false positive probability. Returns true if the bloom filter was reset.
Types ¶
type BloomFilter ¶
type BloomFilter struct { Bloom *bloomfilter.Filter // Salt is provided to eventually unblock collisions in Bloom. It's possible // that conflicting Gossipable items collide in the bloom filter, so a salt // is generated to eventually resolve collisions. Salt ids.ID }
func NewBloomFilter ¶
func NewBloomFilter( maxExpectedElements uint64, falsePositiveProbability float64, ) (*BloomFilter, error)
NewBloomFilter returns a new instance of a bloom filter with at most [maxExpectedElements] elements anticipated at any moment, and a false positive probability of [falsePositiveProbability].
func (*BloomFilter) Add ¶
func (b *BloomFilter) Add(gossipable Gossipable)
func (*BloomFilter) Has ¶
func (b *BloomFilter) Has(gossipable Gossipable) bool
type Gossipable ¶
type Gossipable interface { GetID() ids.ID Marshal() ([]byte, error) Unmarshal(bytes []byte) error }
Gossipable is an item that can be gossiped across the network
type GossipableAny ¶
type GossipableAny[T any] interface { *T Gossipable }
GossipableAny exists to help create non-nil pointers to a concrete Gossipable ref: https://stackoverflow.com/questions/69573113/how-can-i-instantiate-a-non-nil-pointer-of-type-argument-with-generic-go
type Gossiper ¶
type Gossiper interface { // Gossip runs a cycle of gossip. Returns an error if we failed to gossip. Gossip(ctx context.Context) error }
Gossiper gossips Gossipables to other nodes
type Handler ¶
type Handler[T Gossipable] struct { p2p.Handler // contains filtered or unexported fields }
func NewHandler ¶
func NewHandler[T Gossipable]( set Set[T], config HandlerConfig, metrics prometheus.Registerer, ) (*Handler[T], error)
type HandlerConfig ¶
type PullGossiper ¶
type PullGossiper[T any, U GossipableAny[T]] struct { // contains filtered or unexported fields }
func NewPullGossiper ¶
func NewPullGossiper[T any, U GossipableAny[T]]( config Config, log logging.Logger, set Set[U], client *p2p.Client, metrics prometheus.Registerer, ) (*PullGossiper[T, U], error)
type Set ¶
type Set[T Gossipable] interface { // Add adds a Gossipable to the set Add(gossipable T) error // Iterate iterates over elements until [f] returns false Iterate(f func(gossipable T) bool) // GetFilter returns the byte representation of bloom filter and its // corresponding salt. GetFilter() (bloom []byte, salt []byte, err error) }
Set holds a set of known Gossipable items
type ValidatorGossiper ¶
type ValidatorGossiper struct { Gossiper NodeID ids.NodeID Validators p2p.ValidatorSet }
ValidatorGossiper only calls [Gossip] if the given node is a validator