libp2p / go-libp2p-pubsub

The PubSub implementation for go-libp2p
https://github.com/libp2p/specs/tree/master/pubsub
Other
323 stars 187 forks source link

Enables non-atomic validation for peer scoring parameters #499

Closed yhassanzadeh13 closed 2 years ago

yhassanzadeh13 commented 2 years ago

In the context of peer scoring, looking at how the parameters and thresholds are currently set at GossipSub, leaving some parameters unset, yields an error upon initialization of the GossipSub. For some applications and experimentations, we need to selectively set some of the parameters, e.g., only enabling staked participation in a permission setup. However, individual configuration of the scoring parameters is not feasible at the current state of GossipSub without setting all parameters and threshold values at their valid range. Missing even one parameter with a valid configuration fails the GossipSub instantiation.

This PR enables non-atomic validation mode for the parameters and thresholds related to the peer scoring by adding a SkipAtomicValidation member field to the parameters and thresholds struct. By default, this variable is evaluated as false, i.e., zero value for bool data type. !SkipAtomicValidation indicates an atomic mode for validating thresholds and parameters which means all values must be set at their valid ranges. This is synonymous to how the validation is currently done at GossipSub. On the other hand, SkipAtomicValidation indicates a non-atomic mode for validating thresholds and parameters, which relaxes the validation criteria by allowing the application developer to selectively set some of the parameters and threshold values.

In contrast to the atomic validation mode which imposes all parameters and thresholds having a valid value, in the non-atomic mode, the parameters and thresholds can be left at their default (i.e., Golang zero) values as long as either all or none of the parameters related to the same context are set (e.g., mesh failure).