Documentation
¶
Index ¶
- Variables
- func Every(ctx context.Context, log log.Logger, gossiper Gossiper, ...)
- func MarshalAppGossip(gossip [][]byte) ([]byte, error)
- func MarshalAppRequest(filter, salt []byte) ([]byte, error)
- func MarshalAppResponse(gossip [][]byte) ([]byte, error)
- func ParseAppGossip(bytes []byte) ([][]byte, error)
- func ParseAppRequest(bytes []byte) ([]byte, ids.ID, error)
- func ParseAppResponse(bytes []byte) ([][]byte, error)
- func ResetBloomFilterIfNeeded(bloomFilter *BloomFilter, targetElements int) (bool, error)
- type BloomChecker
- type BloomFilter
- type BranchingFactor
- type Cacher
- type Deque
- type EmptyCache
- type FullSet
- type Gossipable
- type Gossiper
- type Handler
- type Marshaller
- type Metrics
- type NoOpGossiper
- type PullGossiper
- type PushGossiper
- type Set
- type TestGossiper
- type ValidatorGossiper
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidNumValidators = errors.New("num validators cannot be negative") ErrInvalidNumNonValidators = errors.New("num non-validators cannot be negative") ErrInvalidNumPeers = errors.New("num peers cannot be negative") ErrInvalidNumToGossip = errors.New("must gossip to at least one peer") ErrInvalidDiscardedSize = errors.New("discarded size cannot be negative") ErrInvalidTargetGossipSize = errors.New("target gossip size cannot be negative") ErrInvalidRegossipFrequency = errors.New("re-gossip frequency cannot be negative") )
Functions ¶
func MarshalAppGossip ¶
MarshalAppGossip marshals push gossip to bytes
func MarshalAppRequest ¶
MarshalAppRequest marshals a pull gossip request to bytes
func MarshalAppResponse ¶
MarshalAppResponse marshals gossip items to bytes
func ParseAppGossip ¶
ParseAppGossip parses bytes to push gossip
func ParseAppRequest ¶
ParseAppRequest parses bytes to a pull gossip request
func ParseAppResponse ¶
ParseAppResponse parses bytes to gossip items
func ResetBloomFilterIfNeeded ¶
func ResetBloomFilterIfNeeded( bloomFilter *BloomFilter, targetElements int, ) (bool, error)
ResetBloomFilterIfNeeded resets the bloom filter if it has exceeded the maximum allowed count. The targetElements parameter allows the filter to grow if the expected number of elements has increased.
Returns true if the filter was reset, false otherwise.
Types ¶
type BloomChecker ¶
BloomChecker checks membership in a bloom filter
type BloomFilter ¶
type BloomFilter struct {
// contains filtered or unexported fields
}
BloomFilter is a probabilistic data structure for membership testing. It is safe for concurrent use after construction.
func NewBloomFilter ¶
func NewBloomFilter( registerer metric.Registerer, namespace string, minTargetElements int, targetFalsePositiveProbability, resetFalsePositiveProbability float64, ) (*BloomFilter, error)
NewBloomFilter creates a new bloom filter for gossip membership tracking.
Parameters:
- registerer: metrics registerer for tracking filter statistics
- namespace: metrics namespace prefix
- minTargetElements: minimum expected number of elements
- targetFalsePositiveProbability: desired false positive rate during normal operation
- resetFalsePositiveProbability: threshold at which the filter should be reset
The filter is safe for concurrent reads after construction, but must not be reset concurrently with other operations.
func (*BloomFilter) Add ¶
func (b *BloomFilter) Add(gossipable Gossipable)
Add adds a gossipable item to the bloom filter.
func (*BloomFilter) Has ¶
func (b *BloomFilter) Has(gossipable Gossipable) bool
Has returns true if the gossipable item may be in the bloom filter. False positives are possible; false negatives are not.
func (*BloomFilter) Marshal ¶
func (b *BloomFilter) Marshal() ([]byte, []byte)
Marshal returns the serialized bloom filter and salt.
func (*BloomFilter) Salt ¶
func (b *BloomFilter) Salt() ids.ID
Salt returns the current salt value used for hashing.
type BranchingFactor ¶
type BranchingFactor struct {
// StakePercentage determines the percentage of stake that should have
// gossip sent to based on the inverse CDF of stake weights. This value does
// not account for the connectivity of the nodes.
StakePercentage float64
// Validators specifies the number of connected validators, in addition to
// any validators sent from the StakePercentage parameter, to send gossip
// to. These validators are sampled uniformly rather than by stake.
Validators int
// NonValidators specifies the number of connected non-validators to send
// gossip to.
NonValidators int
// Peers specifies the number of connected validators or non-validators, in
// addition to the number sent due to other configs, to send gossip to.
Peers int
}
func (*BranchingFactor) Verify ¶
func (b *BranchingFactor) Verify() error
type Cacher ¶
type Cacher[K comparable, V any] interface { Get(key K) (V, bool) Put(key K, value V) }
Cacher interface for cache operations (internal use)
type EmptyCache ¶
type EmptyCache[K comparable, V any] struct{}
EmptyCache is a no-op cache
func (EmptyCache[K, V]) Get ¶
func (EmptyCache[K, V]) Get(key K) (V, bool)
func (EmptyCache[K, V]) Put ¶
func (EmptyCache[K, V]) Put(key K, value V)
type FullSet ¶
type FullSet[T Gossipable] struct{}
type Gossipable ¶
Gossipable is an item that can be gossiped across the network
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]( log log.Logger, marshaller Marshaller[T], set Set[T], metrics Metrics, targetResponseSize int, bloomChecker BloomChecker, ) *Handler[T]
type Marshaller ¶
type Marshaller[T Gossipable] interface { MarshalGossip(T) ([]byte, error) UnmarshalGossip([]byte) (T, error) }
Marshaller handles parsing logic for a concrete Gossipable type
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics that are tracked across a gossip protocol. A given protocol should only use a single instance of Metrics.
func NewMetrics ¶
func NewMetrics( metrics metric.Registerer, namespace string, ) (Metrics, error)
NewMetrics returns a common set of metrics
type NoOpGossiper ¶
type NoOpGossiper struct{}
type PullGossiper ¶
type PullGossiper[T Gossipable] struct { // contains filtered or unexported fields }
func NewPullGossiper ¶
func NewPullGossiper[T Gossipable]( log log.Logger, marshaller Marshaller[T], set Set[T], client *p2p.Client, metrics Metrics, pollSize int, ) *PullGossiper[T]
type PushGossiper ¶
type PushGossiper[T Gossipable] struct { // contains filtered or unexported fields }
PushGossiper broadcasts gossip to peers randomly in the network
func NewPushGossiper ¶
func NewPushGossiper[T Gossipable]( marshaller Marshaller[T], mempool Set[T], validators p2p.ValidatorSubset, client *p2p.Client, metrics Metrics, gossipParams BranchingFactor, regossipParams BranchingFactor, discardedSize int, targetGossipSize int, maxRegossipFrequency time.Duration, ) (*PushGossiper[T], error)
NewPushGossiper returns an instance of PushGossiper
func (*PushGossiper[T]) Add ¶
func (p *PushGossiper[T]) Add(gossipables ...T)
Add enqueues new gossipables to be pushed. If a gossipable is already tracked, it is not added again.
type Set ¶
type Set[T Gossipable] interface { // Add adds a Gossipable to the set. Returns an error if gossipable was not // added. Add(gossipable T) error // Has returns true if the gossipable is in the set. Has(gossipID ids.ID) bool // 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) }
Set holds a set of known Gossipable items
type TestGossiper ¶
type ValidatorGossiper ¶
type ValidatorGossiper struct {
Gossiper
NodeID ids.NodeID
Validators p2p.ValidatorSet
}
ValidatorGossiper only calls [Gossip] if the given node is a validator