trust

package
v0.34.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metric added in v0.33.0

type Metric struct {
	service.BaseService
	// contains filtered or unexported fields
}

Metric - keeps track of peer reliability See tendermint/docs/architecture/adr-006-trust-metric.md for details

func NewMetric

func NewMetric() *Metric

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 MetricConfig) *Metric

NewMetricWithConfig returns a trust metric with a custom configuration. Use Start to begin tracking the quality of peer behavior over time

func (*Metric) BadEvents added in v0.33.0

func (tm *Metric) BadEvents(num int)

BadEvents indicates that an undesirable event(s) took place

func (*Metric) Copy added in v0.33.0

func (tm *Metric) Copy() *Metric

Copy returns a new trust metric with members containing the same values

func (*Metric) GoodEvents added in v0.33.0

func (tm *Metric) GoodEvents(num int)

GoodEvents indicates that a desirable event(s) took place

func (*Metric) HistoryJSON added in v0.33.0

func (tm *Metric) HistoryJSON() MetricHistoryJSON

Returns a snapshot of the trust metric history data

func (*Metric) Init added in v0.33.0

func (tm *Metric) 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 (*Metric) NextTimeInterval added in v0.33.0

func (tm *Metric) NextTimeInterval()

NextTimeInterval saves current time interval data and prepares for the following interval

func (*Metric) OnStart added in v0.33.0

func (tm *Metric) OnStart() error

OnStart implements Service

func (*Metric) OnStop added in v0.33.0

func (tm *Metric) OnStop()

OnStop implements Service Nothing to do since the goroutine shuts down by itself via BaseService.Quit()

func (*Metric) Pause added in v0.33.0

func (tm *Metric) Pause()

Pause tells the metric to pause recording data over time intervals. All method calls that indicate events will unpause the metric

func (*Metric) SetTicker added in v0.33.0

func (tm *Metric) SetTicker(ticker MetricTicker)

SetTicker allows a TestTicker to be provided that will manually control the passing of time from the perspective of the Metric. The ticker must be set before Start is called on the metric

func (*Metric) TrustScore added in v0.33.0

func (tm *Metric) TrustScore() int

TrustScore gets a score based on the trust value always between 0 and 100

func (*Metric) TrustValue added in v0.33.0

func (tm *Metric) TrustValue() float64

TrustValue gets the dependable trust value; always between 0 and 1

type MetricConfig added in v0.33.0

type MetricConfig 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
}

MetricConfig - Configures the weight functions and time intervals for the metric

func DefaultConfig

func DefaultConfig() MetricConfig

DefaultConfig returns a config with values that have been tested and produce desirable results

type MetricHistoryJSON

type MetricHistoryJSON struct {
	NumIntervals int       `json:"intervals"`
	History      []float64 `json:"history"`
}

MetricHistoryJSON - history data necessary to save the trust metric

type MetricStore added in v0.33.0

type MetricStore struct {
	service.BaseService
	// contains filtered or unexported fields
}

MetricStore - Manages all trust metrics for peers

func NewTrustMetricStore

func NewTrustMetricStore(db dbm.DB, tmc MetricConfig) *MetricStore

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 (*MetricStore) AddPeerTrustMetric added in v0.33.0

func (tms *MetricStore) AddPeerTrustMetric(key string, tm *Metric)

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 (*MetricStore) GetPeerTrustMetric added in v0.33.0

func (tms *MetricStore) GetPeerTrustMetric(key string) *Metric

GetPeerTrustMetric returns a trust metric by peer key

func (*MetricStore) OnStart added in v0.33.0

func (tms *MetricStore) OnStart() error

OnStart implements Service

func (*MetricStore) OnStop added in v0.33.0

func (tms *MetricStore) OnStop()

OnStop implements Service

func (*MetricStore) PeerDisconnected added in v0.33.0

func (tms *MetricStore) PeerDisconnected(key string)

PeerDisconnected pauses the trust metric associated with the peer identified by the key

func (*MetricStore) SaveToDB added in v0.33.0

func (tms *MetricStore) SaveToDB()

Saves the history data for all peers to the store DB. This public method acquires the trust metric store lock

func (*MetricStore) Size added in v0.33.0

func (tms *MetricStore) Size() int

Size returns the number of entries in the trust metric store

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

type TestTicker struct {
	C chan time.Time
	// contains filtered or unexported fields
}

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

type Ticker struct {
	*time.Ticker
}

Ticker is just a wrap around time.Ticker that allows it to meet the requirements of our interface

func NewTicker

func NewTicker(d time.Duration) *Ticker

NewTicker returns a normal time.Ticker wrapped to meet our interface

func (*Ticker) GetChannel

func (t *Ticker) GetChannel() <-chan time.Time

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL