github.com/onflow/flow-go@v0.33.17/network/p2p/config/gossipsub_rpc_inspectors.go (about)

     1  package p2pconfig
     2  
     3  // RpcInspectorParameters keys.
     4  const (
     5  	ValidationConfigKey      = "validation"
     6  	MetricsConfigKey         = "metrics"
     7  	NotificationCacheSizeKey = "notification-cache-size"
     8  )
     9  
    10  // RpcInspectorParameters contains the "numerical values" for the gossipsub RPC control message inspectors parameters.
    11  type RpcInspectorParameters struct {
    12  	// RpcValidationInspector control message validation inspector validation configuration and limits.
    13  	Validation RpcValidationInspector `mapstructure:"validation"`
    14  	// NotificationCacheSize size of the queue for notifications about invalid RPC messages.
    15  	NotificationCacheSize uint32 `mapstructure:"notification-cache-size"`
    16  }
    17  
    18  // RpcValidationInspectorParameters keys.
    19  const (
    20  	ClusterPrefixedMessageConfigKey = "cluster-prefixed-messages"
    21  	IWantConfigKey                  = "iwant"
    22  	IHaveConfigKey                  = "ihave"
    23  	GraftPruneKey                   = "graft-and-prune"
    24  	PublishMessagesConfigKey        = "publish-messages"
    25  	InspectionQueueConfigKey        = "inspection-queue"
    26  )
    27  
    28  // RpcValidationInspector validation limits used for gossipsub RPC control message inspection.
    29  type RpcValidationInspector struct {
    30  	ClusterPrefixedMessage ClusterPrefixedMessageInspectionParameters `mapstructure:"cluster-prefixed-messages"`
    31  	IWant                  IWantRpcInspectionParameters               `mapstructure:"iwant"`
    32  	IHave                  IHaveRpcInspectionParameters               `mapstructure:"ihave"`
    33  	GraftPrune             GraftPruneRpcInspectionParameters          `mapstructure:"graft-and-prune"`
    34  	PublishMessages        PublishMessageInspectionParameters         `mapstructure:"publish-messages"`
    35  	InspectionQueue        InspectionQueueParameters                  `mapstructure:"inspection-queue"`
    36  }
    37  
    38  const (
    39  	QueueSizeKey = "queue-size"
    40  )
    41  
    42  // InspectionQueueParameters contains the "numerical values" for the control message validation inspector.
    43  // Incoming GossipSub RPCs are queued for async inspection by a worker pool. This worker pool is configured
    44  // by the parameters in this struct.
    45  // Each RPC has a number of "publish messages" accompanied by control messages.
    46  type InspectionQueueParameters struct {
    47  	// NumberOfWorkers number of worker pool workers.
    48  	NumberOfWorkers int `validate:"gte=1" mapstructure:"workers"`
    49  	// Size size of the queue used by worker pool for the control message validation inspector.
    50  	Size uint32 `validate:"gte=100" mapstructure:"queue-size"`
    51  }
    52  
    53  const (
    54  	MaxSampleSizeKey         = "max-sample-size"
    55  	MessageErrorThresholdKey = "error-threshold"
    56  )
    57  
    58  // PublishMessageInspectionParameters contains the "numerical values" for the publish control message inspection.
    59  // Each RPC has a number of "publish messages" accompanied by control messages. This struct contains the limits
    60  // for the inspection of these publish messages.
    61  type PublishMessageInspectionParameters struct {
    62  	// MaxSampleSize is the maximum number of messages in a single RPC message that are randomly sampled for async inspection.
    63  	// When the size of a single RPC message exceeds this threshold, a random sample is taken for inspection, but the RPC message is not truncated.
    64  	MaxSampleSize int `validate:"gte=0" mapstructure:"max-sample-size"`
    65  	// ErrorThreshold the threshold at which an error will be returned if the number of invalid RPC messages exceeds this value.
    66  	ErrorThreshold int `validate:"gte=0" mapstructure:"error-threshold"`
    67  }
    68  
    69  // GraftPruneRpcInspectionParameters contains the "numerical values" for the graft and prune control message inspection.
    70  // Each RPC has a number of "publish messages" accompanied by control messages. This struct contains the limits
    71  // for the inspection of these graft and prune control messages.
    72  type GraftPruneRpcInspectionParameters struct {
    73  	// MessageCountThreshold is the maximum number of GRAFT or PRUNE messages in a single RPC message.
    74  	// When the total number of GRAFT or PRUNE messages in a single RPC message exceeds this threshold,
    75  	// a random sample of GRAFT or PRUNE messages will be taken and the RPC message will be truncated to this sample size.
    76  	MessageCountThreshold int `validate:"gte=0" mapstructure:"message-count-threshold"`
    77  
    78  	// DuplicateTopicIdThreshold is the tolerance threshold for having duplicate topics in a single GRAFT or PRUNE message under inspection.
    79  	// Ideally, a GRAFT or PRUNE message should not have any duplicate topics, hence a topic ID is counted as a duplicate only if it is repeated more than once.
    80  	// When the total number of duplicate topic ids in a single GRAFT or PRUNE message exceeds this threshold, the inspection of message will fail.
    81  	DuplicateTopicIdThreshold int `validate:"gte=0" mapstructure:"duplicate-topic-id-threshold"`
    82  }
    83  
    84  const (
    85  	MessageCountThreshold      = "message-count-threshold"
    86  	MessageIdCountThreshold    = "message-id-count-threshold"
    87  	CacheMissThresholdKey      = "cache-miss-threshold"
    88  	DuplicateMsgIDThresholdKey = "duplicate-message-id-threshold"
    89  )
    90  
    91  // IWantRpcInspectionParameters contains the "numerical values" for iwant rpc control inspection.
    92  // Each RPC has a number of "publish messages" accompanied by control messages. This struct contains the limits
    93  // for the inspection of the iwant control messages.
    94  type IWantRpcInspectionParameters struct {
    95  	// MessageCountThreshold is the maximum allowed number of iWant messages in a single RPC message.
    96  	// Each iWant message represents the list of message ids. When the total number of iWant messages
    97  	// in a single RPC message exceeds this threshold, a random sample of iWant messages will be taken and the RPC message will be truncated to this sample size.
    98  	// The sample size is equal to the configured MessageCountThreshold.
    99  	MessageCountThreshold uint `validate:"gt=0" mapstructure:"message-count-threshold"`
   100  	// MessageIdCountThreshold is the maximum allowed number of message ids in a single iWant message.
   101  	// Each iWant message represents the list of message ids for a specific topic, and this parameter controls the maximum number of message ids
   102  	// that can be included in a single iWant message. When the total number of message ids in a single iWant message exceeds this threshold,
   103  	// a random sample of message ids will be taken and the iWant message will be truncated to this sample size.
   104  	// The sample size is equal to the configured MessageIdCountThreshold.
   105  	MessageIdCountThreshold int `validate:"gte=0" mapstructure:"message-id-count-threshold"`
   106  	// CacheMissThreshold is the threshold of tolerance for the total cache misses in all iWant messages in a single RPC message.
   107  	// When the total number of cache misses in all iWant messages in a single RPC message exceeds this threshold, the inspection of message will fail.
   108  	// An iWant message is considered a cache miss if it contains a message id that is not present in the local cache for iHave messages, i.e., the node
   109  	// does not have a record of an iHave message for this message id.
   110  	// When the total number of cache misses in all iWant messages in a single RPC message exceeds this threshold, the inspection of message will fail, and
   111  	// a single misbehavior notification will be reported.
   112  	CacheMissThreshold int `validate:"gt=0" mapstructure:"cache-miss-threshold"`
   113  	// DuplicateMsgIdThreshold is the maximum allowed number of duplicate message ids in a all iWant messages in a single RPC message.
   114  	// Each iWant message represents the list of message ids, and this parameter controls the maximum number of duplicate message ids
   115  	// that can be included in all iWant messages in a single RPC message. When the total number of duplicate message ids in a single iWant message exceeds this threshold,
   116  	// a single misbehavior notification will be reported, and the inspection of message will fail.
   117  	DuplicateMsgIdThreshold int `validate:"gt=0" mapstructure:"duplicate-message-id-threshold"`
   118  }
   119  
   120  const (
   121  	DuplicateTopicIdThresholdKey   = "duplicate-topic-id-threshold"
   122  	DuplicateMessageIdThresholdKey = "duplicate-message-id-threshold"
   123  )
   124  
   125  // IHaveRpcInspectionParameters contains the "numerical values" for ihave rpc control inspection.
   126  // Each RPC has a number of "publish messages" accompanied by control messages. This struct contains the limits
   127  // for the inspection of the ihave control messages.
   128  type IHaveRpcInspectionParameters struct {
   129  	// MessageCountThreshold is the maximum allowed number of iHave messages in a single RPC message.
   130  	// Each iHave message represents the list of message ids for a specific topic. When the total number of iHave messages
   131  	// in a single RPC message exceeds this threshold, a random sample of iHave messages will be taken and the RPC message will be truncated to this sample size.
   132  	// The sample size is equal to the configured MessageCountThreshold.
   133  	MessageCountThreshold int `validate:"gte=0" mapstructure:"message-count-threshold"`
   134  	// MessageIdCountThreshold is the maximum allowed number of message ids in a single iHave message.
   135  	// Each iHave message represents the list of message ids for a specific topic, and this parameter controls the maximum number of message ids
   136  	// that can be included in a single iHave message. When the total number of message ids in a single iHave message exceeds this threshold,
   137  	// a random sample of message ids will be taken and the iHave message will be truncated to this sample size.
   138  	// The sample size is equal to the configured MessageIdCountThreshold.
   139  	MessageIdCountThreshold int `validate:"gte=0" mapstructure:"message-id-count-threshold"`
   140  
   141  	// DuplicateTopicIdThreshold is the tolerance threshold for having duplicate topics in an iHave message under inspection.
   142  	// When the total number of duplicate topic ids in a single iHave message exceeds this threshold, the inspection of message will fail.
   143  	// Note that a topic ID is counted as a duplicate only if it is repeated more than DuplicateTopicIdThreshold times.
   144  	DuplicateTopicIdThreshold int `validate:"gte=0" mapstructure:"duplicate-topic-id-threshold"`
   145  
   146  	// DuplicateMessageIdThreshold is the threshold of tolerance for having duplicate message IDs in a single iHave message under inspection.
   147  	// When the total number of duplicate message ids in a single iHave message exceeds this threshold, the inspection of message will fail.
   148  	// Ideally, an iHave message should not have any duplicate message IDs, hence a message id is considered duplicate when it is repeated more than once
   149  	// within the same iHave message. When the total number of duplicate message ids in a single iHave message exceeds this threshold, the inspection of message will fail.
   150  	DuplicateMessageIdThreshold int `validate:"gte=0" mapstructure:"duplicate-message-id-threshold"`
   151  }
   152  
   153  const (
   154  	HardThresholdKey     = "hard-threshold"
   155  	TrackerCacheSizeKey  = "tracker-cache-size"
   156  	TrackerCacheDecayKey = "tracker-cache-decay"
   157  )
   158  
   159  // ClusterPrefixedMessageInspectionParameters contains the "numerical values" for cluster prefixed control message inspection.
   160  // Each RPC has a number of "publish messages" accompanied by control messages. This struct contains the limits for the inspection
   161  // of messages (publish messages and control messages) that belongs to cluster prefixed topics.
   162  // Cluster-prefixed topics are topics that are prefixed with the cluster ID of the node that published the message.
   163  type ClusterPrefixedMessageInspectionParameters struct {
   164  	// HardThreshold the upper bound on the amount of cluster prefixed control messages that will be processed
   165  	// before a node starts to get penalized. This allows LN nodes to process some cluster prefixed control messages during startup
   166  	// when the cluster ID's provider is set asynchronously. It also allows processing of some stale messages that may be sent by nodes
   167  	// that fall behind in the protocol. After the amount of cluster prefixed control messages processed exceeds this threshold the node
   168  	// will be pushed to the edge of the network mesh.
   169  	HardThreshold float64 `validate:"gte=0" mapstructure:"hard-threshold"`
   170  	// ControlMsgsReceivedCacheSize size of the cache used to track the amount of cluster prefixed topics received by peers.
   171  	ControlMsgsReceivedCacheSize uint32 `validate:"gt=0" mapstructure:"tracker-cache-size"`
   172  	// ControlMsgsReceivedCacheDecay decay val used for the geometric decay of cache counters used to keep track of cluster prefixed topics received by peers.
   173  	ControlMsgsReceivedCacheDecay float64 `validate:"gt=0" mapstructure:"tracker-cache-decay"`
   174  }
   175  
   176  const (
   177  	NumberOfWorkersKey = "workers"
   178  )