trust

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2023 License: Apache-2.0, 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

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

func (tm *Metric) BadEvents(num int)

BadEvents indicates that an undesirable event(s) took place

func (*Metric) Copy

func (tm *Metric) Copy() *Metric

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

func (*Metric) GoodEvents

func (tm *Metric) GoodEvents(num int)

GoodEvents indicates that a desirable event(s) took place

func (*Metric) HistoryJSON

func (tm *Metric) HistoryJSON() MetricHistoryJSON

Returns a snapshot of the trust metric history data

func (*Metric) Init

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

func (tm *Metric) NextTimeInterval()

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

func (*Metric) OnStart

func (tm *Metric) OnStart() error

OnStart implements Service

func (*Metric) OnStop

func (tm *Metric) OnStop()

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

func (*Metric) Pause

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

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

func (tm *Metric) TrustScore() int

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

func (*Metric) TrustValue

func (tm *Metric) TrustValue() float64

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

type MetricConfig

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

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

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

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

GetPeerTrustMetric returns a trust metric by peer key

func (*MetricStore) OnStart

func (tms *MetricStore) OnStart() error

OnStart implements Service

func (*MetricStore) OnStop

func (tms *MetricStore) OnStop()

OnStop implements Service

func (*MetricStore) PeerDisconnected

func (tms *MetricStore) PeerDisconnected(key string)

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

func (*MetricStore) SaveToDB

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

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