github.com/number571/tendermint@v0.34.11-gost/internal/p2p/trust/config.go (about) 1 package trust 2 3 import "time" 4 5 // MetricConfig - Configures the weight functions and time intervals for the metric 6 type MetricConfig struct { 7 // Determines the percentage given to current behavior 8 ProportionalWeight float64 9 10 // Determines the percentage given to prior behavior 11 IntegralWeight float64 12 13 // The window of time that the trust metric will track events across. 14 // This can be set to cover many days without issue 15 TrackingWindow time.Duration 16 17 // Each interval should be short for adapability. 18 // Less than 30 seconds is too sensitive, 19 // and greater than 5 minutes will make the metric numb 20 IntervalLength time.Duration 21 } 22 23 // DefaultConfig returns a config with values that have been tested and produce desirable results 24 func DefaultConfig() MetricConfig { 25 return MetricConfig{ 26 ProportionalWeight: 0.4, 27 IntegralWeight: 0.6, 28 TrackingWindow: (time.Minute * 60 * 24) * 14, // 14 days. 29 IntervalLength: 1 * time.Minute, 30 } 31 } 32 33 // Ensures that all configuration elements have valid values 34 func customConfig(tmc MetricConfig) MetricConfig { 35 config := DefaultConfig() 36 37 // Check the config for set values, and setup appropriately 38 if tmc.ProportionalWeight > 0 { 39 config.ProportionalWeight = tmc.ProportionalWeight 40 } 41 42 if tmc.IntegralWeight > 0 { 43 config.IntegralWeight = tmc.IntegralWeight 44 } 45 46 if tmc.IntervalLength > time.Duration(0) { 47 config.IntervalLength = tmc.IntervalLength 48 } 49 50 if tmc.TrackingWindow > time.Duration(0) && 51 tmc.TrackingWindow >= config.IntervalLength { 52 config.TrackingWindow = tmc.TrackingWindow 53 } 54 return config 55 }