cosmos

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Address string
	// Alias is a human-readable name for the account, e.g. cosmoshub-validator.
	Alias  string
	Denoms []string
}

type AccountBalance

type AccountBalance struct {
	Account string
	Denom   string
	Amount  float64
}

type AccountClient

type AccountClient interface {
	AccountBalance(ctx context.Context, address, denom string) (AccountBalance, error)
}

type AccountMetrics

type AccountMetrics interface {
	SetAccountBalance(chain, alias, address, denom string, balance float64)
}

type AccountTask

type AccountTask struct {
	// contains filtered or unexported fields
}

AccountTask queries the Cosmos REST (aka LCD) API for account data and records metrics.

func NewAccountTasks

func NewAccountTasks(metrics AccountMetrics, client AccountClient, chain Chain) []AccountTask

func (AccountTask) Group

func (task AccountTask) Group() string

func (AccountTask) ID

func (task AccountTask) ID() string

func (AccountTask) Interval

func (task AccountTask) Interval() time.Duration

Interval is how often to poll the Endpoint server for data. Defaults to 5s.

func (AccountTask) Run

func (task AccountTask) Run(ctx context.Context) error

Run queries the Endpoint server for data and records various metrics.

type Block

type Block struct {
	BlockID struct {
		Hash  string `json:"hash"`
		Parts struct {
			Total int    `json:"total"`
			Hash  string `json:"hash"`
		} `json:"parts"`
	} `json:"block_id"`
	Block struct {
		Header struct {
			Version struct {
				Block string `json:"block"`
			} `json:"version"`
			ChainID     string    `json:"chain_id"`
			Height      string    `json:"height"`
			Time        time.Time `json:"time"`
			LastBlockID struct {
				Hash  string `json:"hash"`
				Parts struct {
					Total int    `json:"total"`
					Hash  string `json:"hash"`
				} `json:"parts"`
			} `json:"last_block_id"`
			LastCommitHash     string `json:"last_commit_hash"`
			DataHash           string `json:"data_hash"`
			ValidatorsHash     string `json:"validators_hash"`
			NextValidatorsHash string `json:"next_validators_hash"`
			ConsensusHash      string `json:"consensus_hash"`
			AppHash            string `json:"app_hash"`
			LastResultsHash    string `json:"last_results_hash"`
			EvidenceHash       string `json:"evidence_hash"`
			ProposerAddress    string `json:"proposer_address"`
		} `json:"header"`
		Data struct {
			Txs []string `json:"txs"`
		} `json:"data"`
		Evidence struct {
			Evidence []any `json:"evidence"`
		} `json:"evidence"`
		LastCommit struct {
			Height  string `json:"height"`
			Round   int    `json:"round"`
			BlockID struct {
				Hash  string `json:"hash"`
				Parts struct {
					Total int    `json:"total"`
					Hash  string `json:"hash"`
				} `json:"parts"`
			} `json:"block_id"`
			Signatures []struct {
				BlockIDFlag      string    `json:"block_id_flag"`
				ValidatorAddress string    `json:"validator_address"`
				Timestamp        time.Time `json:"timestamp"`
				Signature        string    `json:"signature"`
			} `json:"signatures"`
		} `json:"last_commit"`
	} `json:"block"`
}

type BlockHeightTask

type BlockHeightTask struct {
	// contains filtered or unexported fields
}

BlockHeightTask queries the Cosmos REST (aka LCD) API for data and records various metrics.

func NewBlockHeightTask

func NewBlockHeightTask(metrics Metrics, client Client, chain Chain) BlockHeightTask

func (BlockHeightTask) Group

func (task BlockHeightTask) Group() string

func (BlockHeightTask) ID

func (task BlockHeightTask) ID() string

func (BlockHeightTask) Interval

func (task BlockHeightTask) Interval() time.Duration

Interval is how often to poll the Endpoint server for data. Defaults to 5s.

func (BlockHeightTask) Run

func (task BlockHeightTask) Run(ctx context.Context) error

Run queries the Endpoint server for data and records various metrics.

type Chain

type Chain struct {
	ChainID string
	// Interval is how often to poll the endpoints for data.
	Interval time.Duration
	// Rest are the Cosmos REST (aka LCD) endpoints to poll for data.
	Rest       []Endpoint
	Accounts   []Account
	Validators []Validator
}

type Client

type Client interface {
	LatestBlock(ctx context.Context) (Block, error)
}

type Endpoint

type Endpoint struct {
	URL string
}

type HTTPClient

type HTTPClient interface {
	Get(ctx context.Context, path url.URL) (*http.Response, error)
}

type JailStatus

type JailStatus int

JailStatus is the status of a validator.

const (
	JailStatusActive JailStatus = iota
	JailStatusJailed
	JailStatusTombstoned
)

type Metrics

type Metrics interface {
	SetNodeHeight(chain string, height float64)
}

Metrics records metrics for Cosmos chains.

type RestClient

type RestClient struct {
	// contains filtered or unexported fields
}

RestClient is a client for the Cosmos REST API. To find a list of endpoints, try: https://docs.cosmos.network/swagger/

func NewRestClient

func NewRestClient(c HTTPClient) *RestClient

func (RestClient) AccountBalance

func (c RestClient) AccountBalance(ctx context.Context, account, denom string) (AccountBalance, error)

AccountBalance returns the balance of an account. The account is a bech32 address with prefix. The denom is likely lowercase, e.g. "uatom". To query ibc denoms use the prefix "ibc/hash", e.g. "ibc/E7D5E9D0E9BF8B7354929A817DD28D4D017E745F638954764AA88522A7A409EC" If the denom is not found, API returns a balance of 0 instead of an error.

func (RestClient) LatestBlock

func (c RestClient) LatestBlock(ctx context.Context) (Block, error)

LatestBlock queries the latest block from the Cosmos REST API given the baseURL.

func (RestClient) SigningInfo

func (c RestClient) SigningInfo(ctx context.Context, consaddress string) (SigningInfo, error)

SigningInfo returns the signing status of a validator given the consensus address. Docs: https://docs.cosmos.network/swagger/#/Query/SigningInfo

func (RestClient) SlashingParams

func (c RestClient) SlashingParams(ctx context.Context) (SlashingParams, error)

SlashingParams returns the slashing parameters. Docs: https://docs.cosmos.network/swagger/#/Query/SlashingParams

type SigningInfo

type SigningInfo struct {
	ValSigningInfo struct {
		Address             string    `json:"address"`
		StartHeight         string    `json:"start_height"`
		IndexOffset         string    `json:"index_offset"`
		JailedUntil         time.Time `json:"jailed_until"`
		Tombstoned          bool      `json:"tombstoned"`
		MissedBlocksCounter string    `json:"missed_blocks_counter"`
	} `json:"val_signing_info"`
}

SigningInfo determines whether a validator is jailed or not.

type SlashingParams

type SlashingParams struct {
	Params struct {
		SignedBlocksWindow      string `json:"signed_blocks_window"`
		MinSignedPerWindow      string `json:"min_signed_per_window"`
		DowntimeJailDuration    string `json:"downtime_jail_duration"`
		SlashFractionDoubleSign string `json:"slash_fraction_double_sign"`
		SlashFractionDowntime   string `json:"slash_fraction_downtime"`
	} `json:"params"`
}

func (SlashingParams) SignedBlocksWindow

func (s SlashingParams) SignedBlocksWindow() float64

type ValParamsClient

type ValParamsClient interface {
	SlashingParams(ctx context.Context) (SlashingParams, error)
}

type ValParamsMetrics

type ValParamsMetrics interface {
	SetValSlashingParams(chain string, window float64)
}

type ValParamsTask

type ValParamsTask struct {
	// contains filtered or unexported fields
}

func NewValParamsTask

func NewValParamsTask(metrics ValParamsMetrics, client ValParamsClient, chain Chain) ValParamsTask

func (ValParamsTask) Group

func (p ValParamsTask) Group() string

func (ValParamsTask) ID

func (p ValParamsTask) ID() string

func (ValParamsTask) Interval

func (p ValParamsTask) Interval() time.Duration

Interval is hardcoded to a longer duration because params rarely change. They require a gov proposal. Additionally, longer duration minimizes API calls to prevent hitting rate limits.

func (ValParamsTask) Run

func (p ValParamsTask) Run(ctx context.Context) error

type Validator

type Validator struct {
	// The validator's consensus address. Example prefix: cosmosvalcons...
	ConsAddress string
}

type ValidatorClient

type ValidatorClient interface {
	LatestBlock(ctx context.Context) (Block, error)
	SigningInfo(ctx context.Context, consaddress string) (SigningInfo, error)
}

type ValidatorMetrics

type ValidatorMetrics interface {
	IncValSignedBlocks(chain, consaddress string)
	SetValJailStatus(chain, consaddress string, status JailStatus)
	SetValSignedBlock(chain, consaddress string, height float64)
	SetValMissedBlocks(chain, consaddress string, missed float64)
}

type ValidatorTask

type ValidatorTask struct {
	// contains filtered or unexported fields
}

ValidatorTask queries the Cosmos REST (aka LCD) API for data and records metrics specific to a validator. It records: - whether the validator is jailed or tombstoned - the number of blocks signed by the validator - the number of validator missed blocks

func BuildValidatorTasks

func BuildValidatorTasks(metrics ValidatorMetrics, client ValidatorClient, chain Chain) []ValidatorTask

func (ValidatorTask) Group

func (task ValidatorTask) Group() string

func (ValidatorTask) ID

func (task ValidatorTask) ID() string

func (ValidatorTask) Interval

func (task ValidatorTask) Interval() time.Duration

func (ValidatorTask) Run

func (task ValidatorTask) Run(ctx context.Context) error

Run executes the task gathering a variety of metrics for cosmos validators.

Jump to

Keyboard shortcuts

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