alspmgr

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSpamRecordCacheSizeNotSet is returned when the spam record cache size is not set, it is a fatal irrecoverable error,
	// and the ALSP module cannot be initialized.
	ErrSpamRecordCacheSizeNotSet = errors.New("spam record cache size is not set")
	// ErrSpamReportQueueSizeNotSet is returned when the spam report queue size is not set, it is a fatal irrecoverable error,
	// and the ALSP module cannot be initialized.
	ErrSpamReportQueueSizeNotSet = errors.New("spam report queue size is not set")
	// ErrHeartBeatIntervalNotSet is returned when the heartbeat interval is not set, it is a fatal irrecoverable error,
	// and the ALSP module cannot be initialized.
	ErrHeartBeatIntervalNotSet = errors.New("heartbeat interval is not set")
)

Functions

This section is empty.

Types

type MisbehaviorReportManager

type MisbehaviorReportManager struct {
	component.Component
	// contains filtered or unexported fields
}

MisbehaviorReportManager is responsible for handling misbehavior reports. The current version is at the minimum viable product stage and only logs the reports. TODO: the mature version should be able to handle the reports and take actions accordingly, i.e., penalize the misbehaving node

and report the node to be disallow-listed if the overall penalty of the misbehaving node drops below the disallow-listing threshold.

func NewMisbehaviorReportManager

func NewMisbehaviorReportManager(cfg *MisbehaviorReportManagerConfig) (*MisbehaviorReportManager, error)

NewMisbehaviorReportManager creates a new instance of the MisbehaviorReportManager. Args:

logger: the logger instance.
metrics: the metrics instance.
cache: the spam record cache instance.

Returns:

	A new instance of the MisbehaviorReportManager.
 An error if the config is invalid. The error is considered irrecoverable.

func (*MisbehaviorReportManager) HandleMisbehaviorReport

func (m *MisbehaviorReportManager) HandleMisbehaviorReport(channel channels.Channel, report network.MisbehaviorReport)

HandleMisbehaviorReport is called upon a new misbehavior is reported. The implementation of this function should be thread-safe and non-blocking. Args:

channel: the channel on which the misbehavior is reported.
report: the misbehavior report.

Returns:

none.

type MisbehaviorReportManagerConfig

type MisbehaviorReportManagerConfig struct {
	Logger zerolog.Logger
	// SpamRecordCacheSize is the size of the spam record cache that stores the spam records for the authorized nodes.
	// It should be as big as the number of authorized nodes in Flow network.
	// Recommendation: for small network sizes 10 * number of authorized nodes to ensure that the cache can hold all the spam records of the authorized nodes.
	SpamRecordCacheSize uint32
	// SpamReportQueueSize is the size of the queue that stores the spam records to be processed by the worker pool.
	SpamReportQueueSize uint32
	// AlspMetrics is the metrics instance for the alsp module (collecting spam reports).
	AlspMetrics module.AlspMetrics
	// HeroCacheMetricsFactory is the metrics factory for the HeroCache-related metrics.
	// Having factory as part of the config allows to create the metrics locally in the module.
	HeroCacheMetricsFactory metrics.HeroCacheMetricsFactory
	// DisablePenalty indicates whether applying the penalty to the misbehaving node is disabled.
	// When disabled, the ALSP module logs the misbehavior reports and updates the metrics, but does not apply the penalty.
	// This is useful for managing production incidents.
	// Note: under normal circumstances, the ALSP module should not be disabled.
	DisablePenalty bool
	// NetworkType is the type of the network it is used to determine whether the ALSP module is utilized in the
	// public (unstaked) or private (staked) network.
	NetworkType network.NetworkingType
	// HeartBeatInterval is the interval between the heartbeats. Heartbeat is a recurring event that is used to
	// apply recurring actions, e.g., decay the penalty of the misbehaving nodes.
	HeartBeatInterval time.Duration
	Opts              []MisbehaviorReportManagerOption
}

type MisbehaviorReportManagerOption

type MisbehaviorReportManagerOption func(*MisbehaviorReportManager)

func WithSpamRecordsCacheFactory

func WithSpamRecordsCacheFactory(f SpamRecordCacheFactory) MisbehaviorReportManagerOption

WithSpamRecordsCacheFactory sets the spam record cache factory for the MisbehaviorReportManager. Args:

f: the spam record cache factory.

Returns:

a MisbehaviorReportManagerOption that sets the spam record cache for the MisbehaviorReportManager.

Note: this option is useful primarily for testing purposes. The default factory should be sufficient for the production, and do not change it unless you are confident that you know what you are doing.

Jump to

Keyboard shortcuts

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