github.com/onflow/flow-go@v0.33.17/network/netconf/flags.go (about) 1 package netconf 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/spf13/pflag" 8 "github.com/spf13/viper" 9 10 p2pconfig "github.com/onflow/flow-go/network/p2p/config" 11 ) 12 13 const ( 14 // All constant strings are used for CLI flag names and corresponding keys for config values. 15 // network configuration 16 networkingConnectionPruning = "networking-connection-pruning" 17 preferredUnicastsProtocols = "preferred-unicast-protocols" 18 receivedMessageCacheSize = "received-message-cache-size" 19 peerUpdateInterval = "peerupdate-interval" 20 dnsCacheTTL = "dns-cache-ttl" 21 disallowListNotificationCacheSize = "disallow-list-notification-cache-size" 22 // resource manager config 23 rootResourceManagerPrefix = "libp2p-resource-manager" 24 memoryLimitRatioPrefix = "memory-limit-ratio" 25 fileDescriptorsRatioPrefix = "file-descriptors-ratio" 26 limitsOverridePrefix = "limits-override" 27 systemScope = "system" 28 transientScope = "transient" 29 protocolScope = "protocol" 30 peerScope = "peer" 31 peerProtocolScope = "peer-protocol" 32 inboundStreamLimit = "streams-inbound" 33 outboundStreamLimit = "streams-outbound" 34 inboundConnectionLimit = "connections-inbound" 35 outboundConnectionLimit = "connections-outbound" 36 fileDescriptorsLimit = "fd" 37 memoryLimitBytes = "memory-bytes" 38 39 alspDisabled = "alsp-disable-penalty" 40 alspSpamRecordCacheSize = "alsp-spam-record-cache-size" 41 alspSpamRecordQueueSize = "alsp-spam-report-queue-size" 42 alspHearBeatInterval = "alsp-heart-beat-interval" 43 alspSyncEngineBatchRequestBaseProb = "alsp-sync-engine-batch-request-base-prob" 44 alspSyncEngineRangeRequestBaseProb = "alsp-sync-engine-range-request-base-prob" 45 alspSyncEngineSyncRequestProb = "alsp-sync-engine-sync-request-prob" 46 ) 47 48 func AllFlagNames() []string { 49 allFlags := []string{ 50 networkingConnectionPruning, 51 preferredUnicastsProtocols, 52 receivedMessageCacheSize, 53 peerUpdateInterval, 54 BuildFlagName(unicastKey, MessageTimeoutKey), 55 BuildFlagName(unicastKey, unicastManagerKey, createStreamBackoffDelayKey), 56 BuildFlagName(unicastKey, unicastManagerKey, streamZeroRetryResetThresholdKey), 57 BuildFlagName(unicastKey, unicastManagerKey, maxStreamCreationRetryAttemptTimesKey), 58 BuildFlagName(unicastKey, unicastManagerKey, configCacheSizeKey), 59 dnsCacheTTL, 60 disallowListNotificationCacheSize, 61 BuildFlagName(unicastKey, rateLimiterKey, messageRateLimitKey), 62 BuildFlagName(unicastKey, rateLimiterKey, BandwidthRateLimitKey), 63 BuildFlagName(unicastKey, rateLimiterKey, BandwidthBurstLimitKey), 64 BuildFlagName(unicastKey, rateLimiterKey, LockoutDurationKey), 65 BuildFlagName(unicastKey, rateLimiterKey, DryRunKey), 66 BuildFlagName(unicastKey, enableStreamProtectionKey), 67 BuildFlagName(rootResourceManagerPrefix, memoryLimitRatioPrefix), 68 BuildFlagName(rootResourceManagerPrefix, fileDescriptorsRatioPrefix), 69 BuildFlagName(connectionManagerKey, highWatermarkKey), 70 BuildFlagName(connectionManagerKey, lowWatermarkKey), 71 BuildFlagName(connectionManagerKey, silencePeriodKey), 72 BuildFlagName(connectionManagerKey, gracePeriodKey), 73 alspDisabled, 74 alspSpamRecordCacheSize, 75 alspSpamRecordQueueSize, 76 alspHearBeatInterval, 77 alspSyncEngineBatchRequestBaseProb, 78 alspSyncEngineRangeRequestBaseProb, 79 alspSyncEngineSyncRequestProb, 80 BuildFlagName(gossipsubKey, p2pconfig.PeerScoringEnabledKey), 81 BuildFlagName(gossipsubKey, p2pconfig.RpcTracerKey, p2pconfig.LocalMeshLogIntervalKey), 82 BuildFlagName(gossipsubKey, p2pconfig.RpcTracerKey, p2pconfig.ScoreTracerIntervalKey), 83 BuildFlagName(gossipsubKey, p2pconfig.RpcTracerKey, p2pconfig.RPCSentTrackerCacheSizeKey), 84 BuildFlagName(gossipsubKey, p2pconfig.RpcTracerKey, p2pconfig.RPCSentTrackerQueueCacheSizeKey), 85 BuildFlagName(gossipsubKey, p2pconfig.RpcTracerKey, p2pconfig.RPCSentTrackerNumOfWorkersKey), 86 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.InspectionQueueConfigKey, p2pconfig.NumberOfWorkersKey), 87 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.InspectionQueueConfigKey, p2pconfig.QueueSizeKey), 88 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.ClusterPrefixedMessageConfigKey, p2pconfig.TrackerCacheSizeKey), 89 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.ClusterPrefixedMessageConfigKey, p2pconfig.TrackerCacheDecayKey), 90 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.ClusterPrefixedMessageConfigKey, p2pconfig.HardThresholdKey), 91 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.NotificationCacheSizeKey), 92 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.IHaveConfigKey, p2pconfig.MessageCountThreshold), 93 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.IHaveConfigKey, p2pconfig.MessageIdCountThreshold), 94 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.IHaveConfigKey, p2pconfig.DuplicateTopicIdThresholdKey), 95 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.IHaveConfigKey, p2pconfig.DuplicateMessageIdThresholdKey), 96 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.GraftPruneKey, p2pconfig.DuplicateTopicIdThresholdKey), 97 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.GraftPruneKey, p2pconfig.MessageCountThreshold), 98 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.IWantConfigKey, p2pconfig.MessageCountThreshold), 99 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.IWantConfigKey, p2pconfig.MessageIdCountThreshold), 100 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.IWantConfigKey, p2pconfig.CacheMissThresholdKey), 101 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.IWantConfigKey, p2pconfig.DuplicateMsgIDThresholdKey), 102 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.PublishMessagesConfigKey, p2pconfig.MaxSampleSizeKey), 103 BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.PublishMessagesConfigKey, p2pconfig.MessageErrorThresholdKey), 104 BuildFlagName(gossipsubKey, p2pconfig.SubscriptionProviderKey, p2pconfig.UpdateIntervalKey), 105 BuildFlagName(gossipsubKey, p2pconfig.SubscriptionProviderKey, p2pconfig.CacheSizeKey), 106 107 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.AppSpecificScoreWeightKey), 108 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.DecayIntervalKey), 109 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.DecayToZeroKey), 110 111 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.SkipAtomicValidationKey), 112 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.InvalidMessageDeliveriesWeightKey), 113 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.InvalidMessageDeliveriesDecayKey), 114 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.TimeInMeshQuantumKey), 115 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.TopicWeightKey), 116 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.MeshMessageDeliveriesDecayKey), 117 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.MeshMessageDeliveriesCapKey), 118 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.MeshMessageDeliveryThresholdKey), 119 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.MeshDeliveriesWeightKey), 120 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.MeshMessageDeliveriesWindowKey), 121 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.MeshMessageDeliveryActivationKey), 122 123 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.ThresholdsKey, p2pconfig.GossipThresholdKey), 124 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.ThresholdsKey, p2pconfig.PublishThresholdKey), 125 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.ThresholdsKey, p2pconfig.GraylistThresholdKey), 126 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.ThresholdsKey, p2pconfig.AcceptPXThresholdKey), 127 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.ThresholdsKey, p2pconfig.OpportunisticGraftThresholdKey), 128 129 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.BehaviourKey, p2pconfig.BehaviourPenaltyThresholdKey), 130 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.BehaviourKey, p2pconfig.BehaviourPenaltyWeightKey), 131 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.BehaviourKey, p2pconfig.BehaviourPenaltyDecayKey), 132 133 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.ProtocolKey, p2pconfig.MaxDebugLogsKey), 134 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.ProtocolKey, p2pconfig.AppSpecificKey, p2pconfig.MaxAppSpecificKey, p2pconfig.PenaltyKey), 135 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.ProtocolKey, p2pconfig.AppSpecificKey, p2pconfig.MinAppSpecificKey, p2pconfig.PenaltyKey), 136 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.ProtocolKey, p2pconfig.AppSpecificKey, p2pconfig.UnknownIdentityKey, p2pconfig.PenaltyKey), 137 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.ProtocolKey, p2pconfig.AppSpecificKey, p2pconfig.InvalidSubscriptionKey, p2pconfig.PenaltyKey), 138 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.ProtocolKey, p2pconfig.AppSpecificKey, p2pconfig.MaxAppSpecificKey, p2pconfig.RewardKey), 139 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.ProtocolKey, p2pconfig.AppSpecificKey, p2pconfig.StakedIdentityKey, p2pconfig.RewardKey), 140 141 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.StartupSilenceDurationKey), 142 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.AppSpecificScoreRegistryKey, p2pconfig.ScoreUpdateWorkerNumKey), 143 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.AppSpecificScoreRegistryKey, p2pconfig.ScoreUpdateRequestQueueSizeKey), 144 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.AppSpecificScoreRegistryKey, p2pconfig.ScoreTTLKey), 145 146 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.SpamRecordCacheKey, p2pconfig.CacheSizeKey), 147 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.SpamRecordCacheKey, p2pconfig.DecayKey, p2pconfig.PenaltyDecaySlowdownThresholdKey), 148 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.SpamRecordCacheKey, p2pconfig.DecayKey, p2pconfig.DecayRateReductionFactorKey), 149 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.SpamRecordCacheKey, p2pconfig.DecayKey, p2pconfig.PenaltyDecayEvaluationPeriodKey), 150 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.SpamRecordCacheKey, p2pconfig.DecayKey, p2pconfig.MinimumSpamPenaltyDecayFactorKey), 151 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.SpamRecordCacheKey, p2pconfig.DecayKey, p2pconfig.MaximumSpamPenaltyDecayFactorKey), 152 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.SpamRecordCacheKey, p2pconfig.DecayKey, p2pconfig.SkipDecayThresholdKey), 153 154 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.MisbehaviourPenaltiesKey, p2pconfig.GraftMisbehaviourKey), 155 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.MisbehaviourPenaltiesKey, p2pconfig.PruneMisbehaviourKey), 156 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.MisbehaviourPenaltiesKey, p2pconfig.IHaveMisbehaviourKey), 157 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.MisbehaviourPenaltiesKey, p2pconfig.IWantMisbehaviourKey), 158 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.MisbehaviourPenaltiesKey, p2pconfig.PublishMisbehaviourKey), 159 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.MisbehaviourPenaltiesKey, p2pconfig.ClusterPrefixedReductionFactorKey), 160 } 161 162 for _, scope := range []string{systemScope, transientScope, protocolScope, peerScope, peerProtocolScope} { 163 for _, resource := range []string{inboundStreamLimit, 164 outboundStreamLimit, 165 inboundConnectionLimit, 166 outboundConnectionLimit, 167 fileDescriptorsLimit, 168 memoryLimitBytes} { 169 allFlags = append(allFlags, fmt.Sprintf("%s-%s-%s-%s", rootResourceManagerPrefix, limitsOverridePrefix, scope, resource)) 170 } 171 } 172 173 return allFlags 174 } 175 176 // InitializeNetworkFlags initializes all CLI flags for the Flow network configuration on the provided pflag set. 177 // Args: 178 // 179 // *pflag.FlagSet: the pflag set of the Flow node. 180 // *Config: the default network config used to set default values on the flags 181 func InitializeNetworkFlags(flags *pflag.FlagSet, config *Config) { 182 flags.Bool(networkingConnectionPruning, config.NetworkConnectionPruning, "enabling connection trimming") 183 flags.Duration(dnsCacheTTL, config.DNSCacheTTL, "time-to-live for dns cache") 184 flags.StringSlice( 185 preferredUnicastsProtocols, config.PreferredUnicastProtocols, "preferred unicast protocols in ascending order of preference") 186 flags.Uint32(receivedMessageCacheSize, config.NetworkReceivedMessageCacheSize, "incoming message cache size at networking layer") 187 flags.Uint32( 188 disallowListNotificationCacheSize, 189 config.DisallowListNotificationCacheSize, 190 "cache size for notification events from disallow list") 191 flags.Duration(peerUpdateInterval, config.PeerUpdateInterval, "how often to refresh the peer connections for the node") 192 flags.Duration(BuildFlagName(unicastKey, MessageTimeoutKey), config.Unicast.MessageTimeout, "how long a unicast transmission can take to complete") 193 flags.Duration(BuildFlagName(unicastKey, unicastManagerKey, createStreamBackoffDelayKey), config.Unicast.UnicastManager.CreateStreamBackoffDelay, 194 "initial backoff delay between failing to establish a connection with another node and retrying, "+ 195 "this delay increases exponentially with the number of subsequent failures to establish a connection.") 196 flags.Uint64(BuildFlagName(unicastKey, unicastManagerKey, streamZeroRetryResetThresholdKey), config.Unicast.UnicastManager.StreamZeroRetryResetThreshold, 197 "reset stream creation retry budget from zero to the maximum after consecutive successful streams reach this threshold.") 198 flags.Uint64(BuildFlagName(unicastKey, unicastManagerKey, maxStreamCreationRetryAttemptTimesKey), 199 config.Unicast.UnicastManager.MaxStreamCreationRetryAttemptTimes, 200 "max attempts to create a unicast stream.") 201 flags.Uint32(BuildFlagName(unicastKey, unicastManagerKey, configCacheSizeKey), config.Unicast.UnicastManager.ConfigCacheSize, 202 "cache size of the dial config cache, recommended to be big enough to accommodate the entire nodes in the network.") 203 204 // unicast stream handler rate limits 205 flags.Int(BuildFlagName(unicastKey, rateLimiterKey, messageRateLimitKey), config.Unicast.RateLimiter.MessageRateLimit, "maximum number of unicast messages that a peer can send per second") 206 flags.Int(BuildFlagName(unicastKey, rateLimiterKey, BandwidthRateLimitKey), config.Unicast.RateLimiter.BandwidthRateLimit, 207 "bandwidth size in bytes a peer is allowed to send via unicast streams per second") 208 flags.Int(BuildFlagName(unicastKey, rateLimiterKey, BandwidthBurstLimitKey), config.Unicast.RateLimiter.BandwidthBurstLimit, "bandwidth size in bytes a peer is allowed to send at one time") 209 flags.Duration(BuildFlagName(unicastKey, rateLimiterKey, LockoutDurationKey), config.Unicast.RateLimiter.LockoutDuration, 210 "the number of seconds a peer will be forced to wait before being allowed to successful reconnect to the node after being rate limited") 211 flags.Bool(BuildFlagName(unicastKey, rateLimiterKey, DryRunKey), config.Unicast.RateLimiter.DryRun, "disable peer disconnects and connections gating when rate limiting peers") 212 flags.Bool(BuildFlagName(unicastKey, enableStreamProtectionKey), 213 config.Unicast.EnableStreamProtection, 214 "enable stream protection for unicast streams, when enabled, all connections that are being established or have been already established for unicast streams are protected") 215 216 LoadLibP2PResourceManagerFlags(flags, config) 217 218 flags.Int(BuildFlagName(connectionManagerKey, lowWatermarkKey), config.ConnectionManager.LowWatermark, "low watermarking for libp2p connection manager") 219 flags.Int(BuildFlagName(connectionManagerKey, highWatermarkKey), config.ConnectionManager.HighWatermark, "high watermarking for libp2p connection manager") 220 flags.Duration(BuildFlagName(connectionManagerKey, gracePeriodKey), config.ConnectionManager.GracePeriod, "grace period for libp2p connection manager") 221 flags.Duration(BuildFlagName(connectionManagerKey, silencePeriodKey), config.ConnectionManager.SilencePeriod, "silence period for libp2p connection manager") 222 flags.Bool(BuildFlagName(gossipsubKey, p2pconfig.PeerScoringEnabledKey), config.GossipSub.PeerScoringEnabled, "enabling peer scoring on pubsub network") 223 flags.Duration(BuildFlagName(gossipsubKey, p2pconfig.RpcTracerKey, p2pconfig.LocalMeshLogIntervalKey), 224 config.GossipSub.RpcTracer.LocalMeshLogInterval, 225 "logging interval for local mesh in gossipsub tracer") 226 flags.Duration(BuildFlagName(gossipsubKey, p2pconfig.RpcTracerKey, p2pconfig.ScoreTracerIntervalKey), config.GossipSub.RpcTracer.ScoreTracerInterval, 227 "logging interval for peer score tracer in gossipsub, set to 0 to disable") 228 flags.Uint32(BuildFlagName(gossipsubKey, p2pconfig.RpcTracerKey, p2pconfig.RPCSentTrackerCacheSizeKey), config.GossipSub.RpcTracer.RPCSentTrackerCacheSize, 229 "cache size of the rpc sent tracker used by the gossipsub mesh tracer.") 230 flags.Uint32(BuildFlagName(gossipsubKey, p2pconfig.RpcTracerKey, p2pconfig.RPCSentTrackerQueueCacheSizeKey), config.GossipSub.RpcTracer.RPCSentTrackerQueueCacheSize, 231 "cache size of the rpc sent tracker worker queue.") 232 flags.Int(BuildFlagName(gossipsubKey, p2pconfig.RpcTracerKey, p2pconfig.RPCSentTrackerNumOfWorkersKey), config.GossipSub.RpcTracer.RpcSentTrackerNumOfWorkers, 233 "number of workers for the rpc sent tracker worker pool.") 234 // gossipsub RPC control message validation limits used for validation configuration and rate limiting 235 flags.Int(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.InspectionQueueConfigKey, p2pconfig.NumberOfWorkersKey), 236 config.GossipSub.RpcInspector.Validation.InspectionQueue.NumberOfWorkers, 237 "number of gossipsub RPC control message validation inspector component workers") 238 flags.Uint32(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.InspectionQueueConfigKey, p2pconfig.QueueSizeKey), 239 config.GossipSub.RpcInspector.Validation.InspectionQueue.Size, 240 "queue size for gossipsub RPC validation inspector events worker pool queue.") 241 flags.Uint32(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.ClusterPrefixedMessageConfigKey, p2pconfig.TrackerCacheSizeKey), 242 config.GossipSub.RpcInspector.Validation.ClusterPrefixedMessage.ControlMsgsReceivedCacheSize, 243 "cache size for gossipsub RPC validation inspector cluster prefix received tracker.") 244 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.ClusterPrefixedMessageConfigKey, p2pconfig.TrackerCacheDecayKey), 245 config.GossipSub.RpcInspector.Validation.ClusterPrefixedMessage.ControlMsgsReceivedCacheDecay, 246 "the decay value used to decay cluster prefix received topics received cached counters.") 247 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.ClusterPrefixedMessageConfigKey, p2pconfig.HardThresholdKey), 248 config.GossipSub.RpcInspector.Validation.ClusterPrefixedMessage.HardThreshold, 249 "the maximum number of cluster-prefixed control messages allowed to be processed when the active cluster id is unset or a mismatch is detected, exceeding this threshold will result in node penalization by gossipsub.") 250 // networking event notifications 251 flags.Uint32(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.NotificationCacheSizeKey), config.GossipSub.RpcInspector.NotificationCacheSize, 252 "cache size for notification events from gossipsub rpc inspector") 253 // application layer spam prevention (alsp) protocol 254 flags.Bool(alspDisabled, config.AlspConfig.DisablePenalty, "disable the penalty mechanism of the alsp protocol. default value (recommended) is false") 255 flags.Uint32(alspSpamRecordCacheSize, config.AlspConfig.SpamRecordCacheSize, "size of spam record cache, recommended to be 10x the number of authorized nodes") 256 flags.Uint32(alspSpamRecordQueueSize, config.AlspConfig.SpamReportQueueSize, "size of spam report queue, recommended to be 100x the number of authorized nodes") 257 flags.Duration(alspHearBeatInterval, 258 config.AlspConfig.HearBeatInterval, 259 "interval between two consecutive heartbeat events at alsp, recommended to leave it as default unless you know what you are doing.") 260 flags.Float32(alspSyncEngineBatchRequestBaseProb, 261 config.AlspConfig.SyncEngine.BatchRequestBaseProb, 262 "base probability of creating a misbehavior report for a batch request message") 263 flags.Float32(alspSyncEngineRangeRequestBaseProb, 264 config.AlspConfig.SyncEngine.RangeRequestBaseProb, 265 "base probability of creating a misbehavior report for a range request message") 266 flags.Float32(alspSyncEngineSyncRequestProb, config.AlspConfig.SyncEngine.SyncRequestProb, "probability of creating a misbehavior report for a sync request message") 267 flags.Int(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.IHaveConfigKey, p2pconfig.MessageCountThreshold), 268 config.GossipSub.RpcInspector.Validation.IHave.MessageCountThreshold, 269 "threshold for the number of ihave control messages to accept on a single RPC message, if exceeded the RPC message will be sampled and truncated") 270 flags.Int(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.IHaveConfigKey, p2pconfig.MessageIdCountThreshold), 271 config.GossipSub.RpcInspector.Validation.IHave.MessageIdCountThreshold, 272 "threshold for the number of message ids on a single ihave control message to accept, if exceeded the RPC message ids will be sampled and truncated") 273 flags.Int(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.IHaveConfigKey, p2pconfig.DuplicateTopicIdThresholdKey), 274 config.GossipSub.RpcInspector.Validation.IHave.DuplicateTopicIdThreshold, 275 "the max allowed duplicate topic IDs across all ihave control messages in a single RPC message, if exceeded a misbehavior report will be created") 276 flags.Int(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.IHaveConfigKey, p2pconfig.DuplicateMessageIdThresholdKey), 277 config.GossipSub.RpcInspector.Validation.IHave.DuplicateMessageIdThreshold, 278 "the max allowed duplicate message IDs in a single ihave control message, if exceeded a misbehavior report will be created") 279 flags.Int(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.GraftPruneKey, p2pconfig.MessageCountThreshold), 280 config.GossipSub.RpcInspector.Validation.GraftPrune.MessageCountThreshold, 281 "threshold for the number of graft or prune control messages to accept on a single RPC message, if exceeded the RPC message will be sampled and truncated") 282 flags.Uint(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.IWantConfigKey, p2pconfig.MessageCountThreshold), 283 config.GossipSub.RpcInspector.Validation.IWant.MessageCountThreshold, 284 "threshold for the number of iwant control messages to accept on a single RPC message, if exceeded the RPC message will be sampled and truncated") 285 flags.Int(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.IWantConfigKey, p2pconfig.MessageIdCountThreshold), 286 config.GossipSub.RpcInspector.Validation.IWant.MessageIdCountThreshold, 287 "threshold for the number of message ids on a single iwant control message to accept, if exceeded the RPC message ids will be sampled and truncated") 288 flags.Int(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.IWantConfigKey, p2pconfig.CacheMissThresholdKey), 289 config.GossipSub.RpcInspector.Validation.IWant.CacheMissThreshold, 290 "max number of cache misses (untracked) allowed in a single iWant control message, if exceeded a misbehavior report will be created") 291 flags.Int(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.IWantConfigKey, p2pconfig.DuplicateMsgIDThresholdKey), 292 config.GossipSub.RpcInspector.Validation.IWant.DuplicateMsgIdThreshold, 293 "max allowed duplicate message IDs in a single iWant control message, if exceeded a misbehavior report will be created") 294 flags.Int(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.PublishMessagesConfigKey, p2pconfig.MaxSampleSizeKey), 295 config.GossipSub.RpcInspector.Validation.PublishMessages.MaxSampleSize, 296 "the max sample size for async validation of publish messages, if exceeded the message will be sampled for inspection, but is not truncated") 297 flags.Int(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.PublishMessagesConfigKey, p2pconfig.MessageErrorThresholdKey), 298 config.GossipSub.RpcInspector.Validation.PublishMessages.ErrorThreshold, 299 "the max number of errors allowed in a (sampled) set of publish messages on a single rpc, if exceeded a misbehavior report will be created") 300 flags.Int(BuildFlagName(gossipsubKey, p2pconfig.RpcInspectorKey, p2pconfig.ValidationConfigKey, p2pconfig.GraftPruneKey, p2pconfig.DuplicateTopicIdThresholdKey), 301 config.GossipSub.RpcInspector.Validation.GraftPrune.DuplicateTopicIdThreshold, 302 "the max allowed duplicate topic IDs across all graft or prune control messages in a single RPC message, if exceeded a misbehavior report will be created") 303 flags.Duration(BuildFlagName(gossipsubKey, p2pconfig.SubscriptionProviderKey, p2pconfig.UpdateIntervalKey), 304 config.GossipSub.SubscriptionProvider.UpdateInterval, 305 "interval for updating the list of subscribed topics for all peers in the gossipsub, recommended value is a few minutes") 306 flags.Uint32(BuildFlagName(gossipsubKey, p2pconfig.SubscriptionProviderKey, p2pconfig.CacheSizeKey), 307 config.GossipSub.SubscriptionProvider.CacheSize, 308 "size of the cache that keeps the list of topics each peer has subscribed to, recommended size is 10x the number of authorized nodes") 309 310 flags.Duration(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.DecayIntervalKey), 311 config.GossipSub.ScoringParameters.PeerScoring.Internal.DecayInterval, 312 "interval at which the counters associated with a peer behavior in GossipSub system are decayed, recommended value is one minute") 313 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.AppSpecificScoreWeightKey), 314 config.GossipSub.ScoringParameters.PeerScoring.Internal.AppSpecificScoreWeight, 315 "the weight for app-specific scores") 316 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.DecayToZeroKey), 317 config.GossipSub.ScoringParameters.PeerScoring.Internal.DecayToZero, 318 "the maximum value below which a peer scoring counter is reset to zero") 319 320 flags.Bool(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.SkipAtomicValidationKey), 321 config.GossipSub.ScoringParameters.PeerScoring.Internal.TopicParameters.SkipAtomicValidation, 322 "the default value for the skip atomic validation flag for topics") 323 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.InvalidMessageDeliveriesWeightKey), 324 config.GossipSub.ScoringParameters.PeerScoring.Internal.TopicParameters.InvalidMessageDeliveriesWeight, 325 "this value is applied to the square of the number of invalid message deliveries on a topic") 326 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.InvalidMessageDeliveriesDecayKey), 327 config.GossipSub.ScoringParameters.PeerScoring.Internal.TopicParameters.InvalidMessageDeliveriesDecay, 328 "the decay factor used to decay the number of invalid message deliveries") 329 flags.Duration(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.TimeInMeshQuantumKey), 330 config.GossipSub.ScoringParameters.PeerScoring.Internal.TopicParameters.TimeInMeshQuantum, 331 "the time in mesh quantum for the GossipSub scoring system") 332 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.TopicWeightKey), 333 config.GossipSub.ScoringParameters.PeerScoring.Internal.TopicParameters.TopicWeight, 334 "the weight of a topic in the GossipSub scoring system") 335 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.MeshMessageDeliveriesDecayKey), 336 config.GossipSub.ScoringParameters.PeerScoring.Internal.TopicParameters.MeshMessageDeliveriesDecay, 337 "this is applied to the number of actual message deliveries in a topic mesh at each decay interval (i.e., DecayInterval)") 338 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.MeshMessageDeliveriesCapKey), 339 config.GossipSub.ScoringParameters.PeerScoring.Internal.TopicParameters.MeshMessageDeliveriesCap, 340 "The maximum number of actual message deliveries in a topic mesh that is used to calculate the score of a peer in that topic mesh") 341 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.MeshMessageDeliveryThresholdKey), 342 config.GossipSub.ScoringParameters.PeerScoring.Internal.TopicParameters.MeshMessageDeliveryThreshold, 343 "The threshold for the number of actual message deliveries in a topic mesh that is used to calculate the score of a peer in that topic mesh") 344 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.MeshDeliveriesWeightKey), 345 config.GossipSub.ScoringParameters.PeerScoring.Internal.TopicParameters.MeshDeliveriesWeight, 346 "the weight for applying penalty when a peer is under-performing in a topic mesh") 347 flags.Duration(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.MeshMessageDeliveriesWindowKey), 348 config.GossipSub.ScoringParameters.PeerScoring.Internal.TopicParameters.MeshMessageDeliveriesWindow, 349 "the window size is time interval that we count a delivery of an already seen message towards the score of a peer in a topic mesh. The delivery is counted by GossipSub only if the previous sender of the message is different from the current sender") 350 flags.Duration(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.TopicKey, p2pconfig.MeshMessageDeliveryActivationKey), 351 config.GossipSub.ScoringParameters.PeerScoring.Internal.TopicParameters.MeshMessageDeliveryActivation, 352 "the time interval that we wait for a new peer that joins a topic mesh till start counting the number of actual message deliveries of that peer in that topic mesh") 353 354 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.ThresholdsKey, p2pconfig.GossipThresholdKey), 355 config.GossipSub.ScoringParameters.PeerScoring.Internal.Thresholds.Gossip, 356 "the threshold when a peer's penalty drops below this threshold, no gossip is emitted towards that peer and gossip from that peer is ignored") 357 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.ThresholdsKey, p2pconfig.PublishThresholdKey), 358 config.GossipSub.ScoringParameters.PeerScoring.Internal.Thresholds.Publish, 359 "the threshold when a peer's penalty drops below this threshold, self-published messages are not propagated towards this peer") 360 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.ThresholdsKey, p2pconfig.GraylistThresholdKey), 361 config.GossipSub.ScoringParameters.PeerScoring.Internal.Thresholds.Graylist, 362 "the threshold when a peer's penalty drops below this threshold, the peer is graylisted, i.e., incoming RPCs from the peer are ignored") 363 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.ThresholdsKey, p2pconfig.AcceptPXThresholdKey), 364 config.GossipSub.ScoringParameters.PeerScoring.Internal.Thresholds.AcceptPX, 365 "the threshold when a peer sends us PX information with a prune, we only accept it and connect to the supplied peers if the originating peer's penalty exceeds this threshold") 366 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.ThresholdsKey, p2pconfig.OpportunisticGraftThresholdKey), 367 config.GossipSub.ScoringParameters.PeerScoring.Internal.Thresholds.OpportunisticGraft, 368 "the threshold when the median peer penalty in the mesh drops below this value, the peer may select more peers with penalty above the median to opportunistically graft on the mesh") 369 370 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.BehaviourKey, p2pconfig.BehaviourPenaltyThresholdKey), 371 config.GossipSub.ScoringParameters.PeerScoring.Internal.Behaviour.PenaltyThreshold, 372 "the threshold when the behavior of a peer is considered as bad by GossipSub") 373 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.BehaviourKey, p2pconfig.BehaviourPenaltyWeightKey), 374 config.GossipSub.ScoringParameters.PeerScoring.Internal.Behaviour.PenaltyWeight, 375 "the weight for applying penalty when a peer misbehavior goes beyond the threshold") 376 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.InternalKey, p2pconfig.BehaviourKey, p2pconfig.BehaviourPenaltyDecayKey), 377 config.GossipSub.ScoringParameters.PeerScoring.Internal.Behaviour.PenaltyDecay, 378 "the decay interval for the misbehavior counter of a peer. The misbehavior counter is incremented by GossipSub for iHave broken promises or the GRAFT flooding attacks (i.e., each GRAFT received from a remote peer while that peer is on a PRUNE backoff)") 379 380 flags.Uint32(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.ProtocolKey, p2pconfig.MaxDebugLogsKey), 381 config.GossipSub.ScoringParameters.PeerScoring.Protocol.MaxDebugLogs, 382 "the max number of debug/trace log events per second. Logs emitted above this threshold are dropped") 383 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.ProtocolKey, p2pconfig.AppSpecificKey, p2pconfig.MaxAppSpecificKey, p2pconfig.PenaltyKey), 384 config.GossipSub.ScoringParameters.PeerScoring.Protocol.AppSpecificScore.MaxAppSpecificPenalty, 385 "the maximum penalty for sever offenses that we apply to a remote node score") 386 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.ProtocolKey, p2pconfig.AppSpecificKey, p2pconfig.MinAppSpecificKey, p2pconfig.PenaltyKey), 387 config.GossipSub.ScoringParameters.PeerScoring.Protocol.AppSpecificScore.MinAppSpecificPenalty, 388 "the minimum penalty for sever offenses that we apply to a remote node score") 389 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.ProtocolKey, p2pconfig.AppSpecificKey, p2pconfig.UnknownIdentityKey, p2pconfig.PenaltyKey), 390 config.GossipSub.ScoringParameters.PeerScoring.Protocol.AppSpecificScore.UnknownIdentityPenalty, 391 "the penalty for unknown identity. It is applied to the peer's score when the peer is not in the identity list") 392 flags.Float64(BuildFlagName(gossipsubKey, 393 p2pconfig.ScoreParamsKey, 394 p2pconfig.PeerScoringKey, 395 p2pconfig.ProtocolKey, 396 p2pconfig.AppSpecificKey, 397 p2pconfig.InvalidSubscriptionKey, 398 p2pconfig.PenaltyKey), 399 config.GossipSub.ScoringParameters.PeerScoring.Protocol.AppSpecificScore.InvalidSubscriptionPenalty, 400 "the penalty for invalid subscription. It is applied to the peer's score when the peer subscribes to a topic that it is not authorized to subscribe to") 401 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.ProtocolKey, p2pconfig.AppSpecificKey, p2pconfig.MaxAppSpecificKey, p2pconfig.RewardKey), 402 config.GossipSub.ScoringParameters.PeerScoring.Protocol.AppSpecificScore.MaxAppSpecificReward, 403 "the reward for well-behaving staked peers") 404 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.PeerScoringKey, p2pconfig.ProtocolKey, p2pconfig.AppSpecificKey, p2pconfig.StakedIdentityKey, p2pconfig.RewardKey), 405 config.GossipSub.ScoringParameters.PeerScoring.Protocol.AppSpecificScore.StakedIdentityReward, 406 "the reward for staking peers") 407 408 flags.Duration(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.StartupSilenceDurationKey), 409 config.GossipSub.ScoringParameters.ScoringRegistryParameters.StartupSilenceDuration, 410 "the duration of time, after the node startup, during which the scoring registry remains inactive before penalizing nodes.") 411 flags.Int(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.AppSpecificScoreRegistryKey, p2pconfig.ScoreUpdateWorkerNumKey), 412 config.GossipSub.ScoringParameters.ScoringRegistryParameters.AppSpecificScore.ScoreUpdateWorkerNum, 413 "number of workers for the app specific score update worker pool") 414 flags.Uint32(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.AppSpecificScoreRegistryKey, p2pconfig.ScoreUpdateRequestQueueSizeKey), 415 config.GossipSub.ScoringParameters.ScoringRegistryParameters.AppSpecificScore.ScoreUpdateRequestQueueSize, 416 "size of the app specific score update worker pool queue") 417 flags.Duration(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.AppSpecificScoreRegistryKey, p2pconfig.ScoreTTLKey), 418 config.GossipSub.ScoringParameters.ScoringRegistryParameters.AppSpecificScore.ScoreTTL, 419 "time to live for app specific scores; when expired a new request will be sent to the score update worker pool; till then the expired score will be used") 420 421 flags.Uint32(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.SpamRecordCacheKey, p2pconfig.CacheSizeKey), 422 config.GossipSub.ScoringParameters.ScoringRegistryParameters.SpamRecordCache.CacheSize, 423 "size of the spam record cache, recommended size is 10x the number of authorized nodes") 424 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.SpamRecordCacheKey, p2pconfig.DecayKey, p2pconfig.PenaltyDecaySlowdownThresholdKey), 425 config.GossipSub.ScoringParameters.ScoringRegistryParameters.SpamRecordCache.Decay.PenaltyDecaySlowdownThreshold, 426 fmt.Sprintf("the penalty level at which the decay rate is reduced by --%s", 427 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.SpamRecordCacheKey, p2pconfig.DecayKey, p2pconfig.DecayRateReductionFactorKey))) 428 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.SpamRecordCacheKey, p2pconfig.DecayKey, p2pconfig.DecayRateReductionFactorKey), 429 config.GossipSub.ScoringParameters.ScoringRegistryParameters.SpamRecordCache.Decay.DecayRateReductionFactor, 430 fmt.Sprintf("defines the value by which the decay rate is decreased every time the penalty is below the --%s", 431 BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.SpamRecordCacheKey, p2pconfig.DecayKey, p2pconfig.PenaltyDecaySlowdownThresholdKey))) 432 flags.Duration(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.SpamRecordCacheKey, p2pconfig.DecayKey, p2pconfig.PenaltyDecayEvaluationPeriodKey), 433 config.GossipSub.ScoringParameters.ScoringRegistryParameters.SpamRecordCache.Decay.PenaltyDecayEvaluationPeriod, 434 "defines the period at which the decay for a spam record is okay to be adjusted.") 435 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.SpamRecordCacheKey, p2pconfig.DecayKey, p2pconfig.MinimumSpamPenaltyDecayFactorKey), 436 config.GossipSub.ScoringParameters.ScoringRegistryParameters.SpamRecordCache.Decay.MinimumSpamPenaltyDecayFactor, 437 "the minimum speed at which the spam penalty value of a peer is decayed") 438 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.SpamRecordCacheKey, p2pconfig.DecayKey, p2pconfig.MaximumSpamPenaltyDecayFactorKey), 439 config.GossipSub.ScoringParameters.ScoringRegistryParameters.SpamRecordCache.Decay.MaximumSpamPenaltyDecayFactor, 440 "the maximum rate at which the spam penalty value of a peer decays") 441 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.SpamRecordCacheKey, p2pconfig.DecayKey, p2pconfig.SkipDecayThresholdKey), 442 config.GossipSub.ScoringParameters.ScoringRegistryParameters.SpamRecordCache.Decay.SkipDecayThreshold, 443 "the threshold for which when the negative penalty is above this value, the decay function will not be called") 444 445 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.MisbehaviourPenaltiesKey, p2pconfig.GraftMisbehaviourKey), 446 config.GossipSub.ScoringParameters.ScoringRegistryParameters.MisbehaviourPenalties.GraftMisbehaviour, 447 "the penalty applied to the application specific penalty when a peer conducts a graft misbehaviour") 448 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.MisbehaviourPenaltiesKey, p2pconfig.PruneMisbehaviourKey), 449 config.GossipSub.ScoringParameters.ScoringRegistryParameters.MisbehaviourPenalties.PruneMisbehaviour, 450 "the penalty applied to the application specific penalty when a peer conducts a prune misbehaviour") 451 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.MisbehaviourPenaltiesKey, p2pconfig.IHaveMisbehaviourKey), 452 config.GossipSub.ScoringParameters.ScoringRegistryParameters.MisbehaviourPenalties.IHaveMisbehaviour, 453 "the penalty applied to the application specific penalty when a peer conducts a iHave misbehaviour") 454 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.MisbehaviourPenaltiesKey, p2pconfig.IWantMisbehaviourKey), 455 config.GossipSub.ScoringParameters.ScoringRegistryParameters.MisbehaviourPenalties.IWantMisbehaviour, 456 "the penalty applied to the application specific penalty when a peer conducts a iWant misbehaviour") 457 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.MisbehaviourPenaltiesKey, p2pconfig.PublishMisbehaviourKey), 458 config.GossipSub.ScoringParameters.ScoringRegistryParameters.MisbehaviourPenalties.PublishMisbehaviour, 459 "the penalty applied to the application specific penalty when a peer conducts a rpc publish message misbehaviour") 460 flags.Float64(BuildFlagName(gossipsubKey, p2pconfig.ScoreParamsKey, p2pconfig.ScoringRegistryKey, p2pconfig.MisbehaviourPenaltiesKey, p2pconfig.ClusterPrefixedReductionFactorKey), 461 config.GossipSub.ScoringParameters.ScoringRegistryParameters.MisbehaviourPenalties.ClusterPrefixedReductionFactor, 462 "the factor used to reduce the penalty for control message misbehaviours on cluster prefixed topics") 463 464 } 465 466 // LoadLibP2PResourceManagerFlags loads all CLI flags for the libp2p resource manager configuration on the provided pflag set. 467 // Args: 468 // *pflag.FlagSet: the pflag set of the Flow node. 469 // *Config: the default network config used to set default values on the flags 470 func LoadLibP2PResourceManagerFlags(flags *pflag.FlagSet, config *Config) { 471 flags.Float64(fmt.Sprintf("%s-%s", rootResourceManagerPrefix, fileDescriptorsRatioPrefix), 472 config.ResourceManager.FileDescriptorsRatio, 473 "ratio of available file descriptors to be used by libp2p (in (0,1])") 474 flags.Float64(fmt.Sprintf("%s-%s", rootResourceManagerPrefix, memoryLimitRatioPrefix), 475 config.ResourceManager.MemoryLimitRatio, 476 "ratio of available memory to be used by libp2p (in (0,1])") 477 loadLibP2PResourceManagerFlagsForScope(systemScope, flags, &config.ResourceManager.Override.System) 478 loadLibP2PResourceManagerFlagsForScope(transientScope, flags, &config.ResourceManager.Override.Transient) 479 loadLibP2PResourceManagerFlagsForScope(protocolScope, flags, &config.ResourceManager.Override.Protocol) 480 loadLibP2PResourceManagerFlagsForScope(peerScope, flags, &config.ResourceManager.Override.Peer) 481 loadLibP2PResourceManagerFlagsForScope(peerProtocolScope, flags, &config.ResourceManager.Override.PeerProtocol) 482 } 483 484 // loadLibP2PResourceManagerFlagsForScope loads all CLI flags for the libp2p resource manager configuration on the provided pflag set for the specific scope. 485 // Args: 486 // *p2pconf.ResourceScope: the resource scope to load flags for. 487 // *pflag.FlagSet: the pflag set of the Flow node. 488 // *Config: the default network config used to set default values on the flags. 489 func loadLibP2PResourceManagerFlagsForScope(scope p2pconfig.ResourceScope, flags *pflag.FlagSet, override *p2pconfig.ResourceManagerOverrideLimit) { 490 flags.Int(fmt.Sprintf("%s-%s-%s-%s", rootResourceManagerPrefix, limitsOverridePrefix, scope, inboundStreamLimit), 491 override.StreamsInbound, 492 fmt.Sprintf("the limit on the number of inbound streams at %s scope, 0 means use the default value", scope)) 493 flags.Int(fmt.Sprintf("%s-%s-%s-%s", rootResourceManagerPrefix, limitsOverridePrefix, scope, outboundStreamLimit), 494 override.StreamsOutbound, 495 fmt.Sprintf("the limit on the number of outbound streams at %s scope, 0 means use the default value", scope)) 496 flags.Int(fmt.Sprintf("%s-%s-%s-%s", rootResourceManagerPrefix, limitsOverridePrefix, scope, inboundConnectionLimit), 497 override.ConnectionsInbound, 498 fmt.Sprintf("the limit on the number of inbound connections at %s scope, 0 means use the default value", scope)) 499 flags.Int(fmt.Sprintf("%s-%s-%s-%s", rootResourceManagerPrefix, limitsOverridePrefix, scope, outboundConnectionLimit), 500 override.ConnectionsOutbound, 501 fmt.Sprintf("the limit on the number of outbound connections at %s scope, 0 means use the default value", scope)) 502 flags.Int(fmt.Sprintf("%s-%s-%s-%s", rootResourceManagerPrefix, limitsOverridePrefix, scope, fileDescriptorsLimit), 503 override.FD, 504 fmt.Sprintf("the limit on the number of file descriptors at %s scope, 0 means use the default value", scope)) 505 flags.Int(fmt.Sprintf("%s-%s-%s-%s", rootResourceManagerPrefix, limitsOverridePrefix, scope, memoryLimitBytes), 506 override.Memory, 507 fmt.Sprintf("the limit on the amount of memory (bytes) at %s scope, 0 means use the default value", scope)) 508 } 509 510 // SetAliases this func sets an aliases for each CLI flag defined for network config overrides to it's corresponding 511 // full key in the viper config store. This is required because in our p2pconfig.yml file all configuration values for the 512 // Flow network are stored one level down on the network-config property. When the default config is bootstrapped viper will 513 // store these values with the "network-p2pconfig." prefix on the config key, because we do not want to use CLI flags like --network-p2pconfig.networking-connection-pruning 514 // to override default values we instead use cleans flags like --networking-connection-pruning and create an alias from networking-connection-pruning -> network-p2pconfig.networking-connection-pruning 515 // to ensure overrides happen as expected. 516 // Args: 517 // *viper.Viper: instance of the viper store to register network config aliases on. 518 // Returns: 519 // error: if a flag does not have a corresponding key in the viper store; all returned errors are fatal. 520 func SetAliases(conf *viper.Viper) error { 521 m := make(map[string]string) 522 // create map of key -> full pathkey 523 // ie: "networking-connection-pruning" -> "network-p2pconfig.networking-connection-pruning" 524 for _, key := range conf.AllKeys() { 525 s := strings.Split(key, ".") 526 // Each networking config has the format of network-p2pconfig.key1.key2.key3... in the config file 527 // which is translated to key1-key2-key3... in the CLI flags 528 // Hence, we map the CLI flag name to the full key in the config store 529 // TODO: all networking flags should also be prefixed with "network-config". Hence, this 530 // mapping should be from network-p2pconfig.key1.key2.key3... to network-config-key1-key2-key3... 531 m[strings.Join(s[1:], "-")] = key 532 } 533 // each flag name should correspond to exactly one key in our config store after it is loaded with the default config 534 for _, flagName := range AllFlagNames() { 535 fullKey, ok := m[flagName] 536 if !ok { 537 return fmt.Errorf("invalid network configuration missing configuration key flag name %s check config file and cli flags", flagName) 538 } 539 540 conf.RegisterAlias(fullKey, flagName) 541 } 542 return nil 543 } 544 545 func BuildFlagName(keys ...string) string { 546 return strings.Join(keys, "-") 547 }