cache

package
v0.37.22-verify-backwa... Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClusterPrefixedMessagesReceivedRecord

type ClusterPrefixedMessagesReceivedRecord struct {
	// NodeID the node ID of the sender.
	NodeID flow.Identifier
	// Gauge represents the approximate amount of cluster prefixed messages received by a peer, this
	// value is decayed back to 0 after some time.
	Gauge float64
	// contains filtered or unexported fields
}

ClusterPrefixedMessagesReceivedRecord cache record that keeps track of the amount of cluster prefixed control messages received from a peer. This struct implements the flow.Entity interface and uses node ID of the sender for deduplication.

func NewClusterPrefixedMessagesReceivedRecord

func NewClusterPrefixedMessagesReceivedRecord(nodeID flow.Identifier) ClusterPrefixedMessagesReceivedRecord

func (ClusterPrefixedMessagesReceivedRecord) Checksum

Checksum returns the node ID of the sender, it does not have any purpose in the cache. It is implemented to satisfy the flow.Entity interface.

func (ClusterPrefixedMessagesReceivedRecord) ID

ID returns the node ID of the sender, which is used as the unique identifier of the entity for maintenance and deduplication purposes in the cache.

type ClusterPrefixedMessagesReceivedTracker

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

ClusterPrefixedMessagesReceivedTracker struct that keeps track of the amount of cluster prefixed control messages received by a peer.

func NewClusterPrefixedMessagesReceivedTracker

func NewClusterPrefixedMessagesReceivedTracker(logger zerolog.Logger, sizeLimit uint32, clusterPrefixedCacheCollector module.HeroCacheMetrics, decay float64) (*ClusterPrefixedMessagesReceivedTracker,
	error)

NewClusterPrefixedMessagesReceivedTracker returns a new *ClusterPrefixedMessagesReceivedTracker.

func (*ClusterPrefixedMessagesReceivedTracker) GetActiveClusterIds

func (c *ClusterPrefixedMessagesReceivedTracker) GetActiveClusterIds() flow.ChainIDList

GetActiveClusterIds gets the active cluster Ids from the underlying record cache.

func (*ClusterPrefixedMessagesReceivedTracker) Inc

Inc increments the cluster prefixed control messages received Gauge for the peer. All errors returned from this func are unexpected and irrecoverable.

func (*ClusterPrefixedMessagesReceivedTracker) Load

Load loads the current number of cluster prefixed control messages received by a peer. All errors returned from this func are unexpected and irrecoverable.

func (*ClusterPrefixedMessagesReceivedTracker) StoreActiveClusterIds

func (c *ClusterPrefixedMessagesReceivedTracker) StoreActiveClusterIds(clusterIdList flow.ChainIDList)

StoreActiveClusterIds stores the active cluster Ids in the underlying record cache.

type RecordCache

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

RecordCache is a cache that stores ClusterPrefixedMessagesReceivedRecord by peer node ID. Each record contains a float64 Gauge field that indicates the current approximate number cluster prefixed control messages that were allowed to bypass validation due to some error that will prevent the message from being validated. Each record contains a float64 Gauge field that is decayed overtime back to 0. This ensures that nodes that fall behind in the protocol can catch up.

func NewRecordCache

func NewRecordCache(config *RecordCacheConfig, recordEntityFactory recordEntityFactory) (*RecordCache, error)

NewRecordCache creates a new *RecordCache. Args: - config: record cache config. - recordEntityFactory: a factory function that creates a new spam record. Returns: - *RecordCache, the created cache. Note that this cache is supposed to keep the cluster prefix control messages received record for the authorized (staked) nodes. Since the number of such nodes is expected to be small, we do not eject any records from the cache. The cache size must be large enough to hold all the records of the authorized nodes. Also, this cache is keeping at most one record per peer id, so the size of the cache must be at least the number of authorized nodes.

func (*RecordCache) GetWithInit added in v0.33.1

func (r *RecordCache) GetWithInit(pid peer.ID) (float64, bool, error)

GetWithInit returns the current number of cluster prefixed control messages received from a peer. The record is initialized before the count is returned. Before the control messages received gauge value is returned it is decayed using the configured decay function. Returns the record and true if the record exists, nil and false otherwise. Args: - pid: the peer ID of the sender of the control message. Returns: - The cluster prefixed control messages received gauge value after the decay and true if the record exists, 0 and false otherwise. No errors are expected during normal operation.

func (*RecordCache) MakeId added in v0.33.30

func (r *RecordCache) MakeId(peerID peer.ID) flow.Identifier

MakeId is a helper function for creating the id field of the duplicateMessagesCounterEntity by hashing the peerID. Returns: - the hash of the peerID as a flow.Identifier.

func (*RecordCache) NodeIDs

func (r *RecordCache) NodeIDs() []flow.Identifier

NodeIDs returns the list of identities of the nodes that have a spam record in the cache.

func (*RecordCache) ReceivedClusterPrefixedMessage

func (r *RecordCache) ReceivedClusterPrefixedMessage(pid peer.ID) (float64, error)

ReceivedClusterPrefixedMessage applies an adjustment that increments the number of cluster prefixed control messages received by a peer. Returns number of cluster prefix control messages received after the adjustment. The record is initialized before the adjustment func is applied that will increment the Gauge. Args: - pid: the peer ID of the sender of the control message. Returns:

  • The cluster prefix control messages received gauge value after the adjustment.
  • exception only in cases of internal data inconsistency or bugs. No errors are expected.

func (*RecordCache) Remove

func (r *RecordCache) Remove(pid peer.ID) bool

Remove removes the record of the given peer id from the cache. Returns true if the record is removed, false otherwise (i.e., the record does not exist). Args: - pid: the peer ID of the sender of the control message. Returns: - true if the record is removed, false otherwise (i.e., the record does not exist).

func (*RecordCache) Size

func (r *RecordCache) Size() uint

Size returns the number of records in the cache.

type RecordCacheConfig

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

Jump to

Keyboard shortcuts

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