Documentation ¶
Index ¶
- type MetricHistoryJSON
- type MetricTicker
- type TestTicker
- type Ticker
- type TrustMetric
- func (tm *TrustMetric) BadEvents(num int)
- func (tm *TrustMetric) Copy() *TrustMetric
- func (tm *TrustMetric) GoodEvents(num int)
- func (tm *TrustMetric) HistoryJSON() MetricHistoryJSON
- func (tm *TrustMetric) Init(hist MetricHistoryJSON)
- func (tm *TrustMetric) NextTimeInterval()
- func (tm *TrustMetric) OnStart() error
- func (tm *TrustMetric) OnStop()
- func (tm *TrustMetric) Pause()
- func (tm *TrustMetric) SetTicker(ticker MetricTicker)
- func (tm *TrustMetric) TrustScore() int
- func (tm *TrustMetric) TrustValue() float64
- type TrustMetricConfig
- type TrustMetricStore
- func (tms *TrustMetricStore) AddPeerTrustMetric(key string, tm *TrustMetric)
- func (tms *TrustMetricStore) GetPeerTrustMetric(key string) *TrustMetric
- func (tms *TrustMetricStore) OnStart() error
- func (tms *TrustMetricStore) OnStop()
- func (tms *TrustMetricStore) PeerDisconnected(key string)
- func (tms *TrustMetricStore) SaveToDB()
- func (tms *TrustMetricStore) Size() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MetricHistoryJSON ¶
type MetricHistoryJSON struct { NumIntervals int `json:"intervals"` History []float64 `json:"history"` }
MetricHistoryJSON - history data necessary to save the trust metric
type MetricTicker ¶
type MetricTicker interface { // GetChannel returns the receive only channel that fires at each time interval GetChannel() <-chan time.Time // Stop will halt further activity on the ticker channel Stop() }
MetricTicker provides a single ticker interface for the trust metric
type TestTicker ¶
The ticker used during testing that provides manual control over time intervals
func NewTestTicker ¶
func NewTestTicker() *TestTicker
NewTestTicker returns our ticker used within test routines
func (*TestTicker) GetChannel ¶
func (t *TestTicker) GetChannel() <-chan time.Time
func (*TestTicker) NextTick ¶
func (t *TestTicker) NextTick()
NextInterval manually sends Time on the ticker channel
func (*TestTicker) Stop ¶
func (t *TestTicker) Stop()
type Ticker ¶
Ticker is just a wrap around time.Ticker that allows it to meet the requirements of our interface
func NewTicker ¶
NewTicker returns a normal time.Ticker wrapped to meet our interface
type TrustMetric ¶
type TrustMetric struct { cmn.BaseService // contains filtered or unexported fields }
TrustMetric - keeps track of peer reliability See tendermint/docs/architecture/adr-006-trust-metric.md for details
func NewMetric ¶
func NewMetric() *TrustMetric
NewMetric returns a trust metric with the default configuration. Use Start to begin tracking the quality of peer behavior over time
func NewMetricWithConfig ¶
func NewMetricWithConfig(tmc TrustMetricConfig) *TrustMetric
NewMetricWithConfig returns a trust metric with a custom configuration. Use Start to begin tracking the quality of peer behavior over time
func (*TrustMetric) BadEvents ¶
func (tm *TrustMetric) BadEvents(num int)
BadEvents indicates that an undesirable event(s) took place
func (*TrustMetric) Copy ¶
func (tm *TrustMetric) Copy() *TrustMetric
Copy returns a new trust metric with members containing the same values
func (*TrustMetric) GoodEvents ¶
func (tm *TrustMetric) GoodEvents(num int)
GoodEvents indicates that a desirable event(s) took place
func (*TrustMetric) HistoryJSON ¶
func (tm *TrustMetric) HistoryJSON() MetricHistoryJSON
Returns a snapshot of the trust metric history data
func (*TrustMetric) Init ¶
func (tm *TrustMetric) Init(hist MetricHistoryJSON)
Instantiates a trust metric by loading the history data for a single peer. This is called only once and only right after creation, which is why the lock is not held while accessing the trust metric struct members
func (*TrustMetric) NextTimeInterval ¶
func (tm *TrustMetric) NextTimeInterval()
NextTimeInterval saves current time interval data and prepares for the following interval
func (*TrustMetric) OnStop ¶
func (tm *TrustMetric) OnStop()
OnStop implements Service Nothing to do since the goroutine shuts down by itself via BaseService.Quit()
func (*TrustMetric) Pause ¶
func (tm *TrustMetric) Pause()
Pause tells the metric to pause recording data over time intervals. All method calls that indicate events will unpause the metric
func (*TrustMetric) SetTicker ¶
func (tm *TrustMetric) SetTicker(ticker MetricTicker)
SetTicker allows a TestTicker to be provided that will manually control the passing of time from the perspective of the TrustMetric. The ticker must be set before Start is called on the metric
func (*TrustMetric) TrustScore ¶
func (tm *TrustMetric) TrustScore() int
TrustScore gets a score based on the trust value always between 0 and 100
func (*TrustMetric) TrustValue ¶
func (tm *TrustMetric) TrustValue() float64
TrustValue gets the dependable trust value; always between 0 and 1
type TrustMetricConfig ¶
type TrustMetricConfig struct { // Determines the percentage given to current behavior ProportionalWeight float64 // Determines the percentage given to prior behavior IntegralWeight float64 // The window of time that the trust metric will track events across. // This can be set to cover many days without issue TrackingWindow time.Duration // Each interval should be short for adapability. // Less than 30 seconds is too sensitive, // and greater than 5 minutes will make the metric numb IntervalLength time.Duration }
TrustMetricConfig - Configures the weight functions and time intervals for the metric
func DefaultConfig ¶
func DefaultConfig() TrustMetricConfig
DefaultConfig returns a config with values that have been tested and produce desirable results
type TrustMetricStore ¶
type TrustMetricStore struct { cmn.BaseService // contains filtered or unexported fields }
TrustMetricStore - Manages all trust metrics for peers
func NewTrustMetricStore ¶
func NewTrustMetricStore(db dbm.DB, tmc TrustMetricConfig) *TrustMetricStore
NewTrustMetricStore returns a store that saves data to the DB and uses the config when creating new trust metrics. Use Start to to initialize the trust metric store
func (*TrustMetricStore) AddPeerTrustMetric ¶
func (tms *TrustMetricStore) AddPeerTrustMetric(key string, tm *TrustMetric)
AddPeerTrustMetric takes an existing trust metric and associates it with a peer key. The caller is expected to call Start on the TrustMetric being added
func (*TrustMetricStore) GetPeerTrustMetric ¶
func (tms *TrustMetricStore) GetPeerTrustMetric(key string) *TrustMetric
GetPeerTrustMetric returns a trust metric by peer key
func (*TrustMetricStore) OnStart ¶
func (tms *TrustMetricStore) OnStart() error
OnStart implements Service
func (*TrustMetricStore) PeerDisconnected ¶
func (tms *TrustMetricStore) PeerDisconnected(key string)
PeerDisconnected pauses the trust metric associated with the peer identified by the key
func (*TrustMetricStore) SaveToDB ¶
func (tms *TrustMetricStore) SaveToDB()
Saves the history data for all peers to the store DB. This public method acquires the trust metric store lock
func (*TrustMetricStore) Size ¶
func (tms *TrustMetricStore) Size() int
Size returns the number of entries in the trust metric store