record

package
v0.0.0-...-477d63b Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Sometimes ThorNode state is updated but the events doesn't reflect that perfectly.

In these cases we open a bug report so future events are correct, but the old events will stay the same, and we apply these corrections to the existing events.

Package event provides the blockchain data in a structured way.

All asset amounts are fixed to 8 decimals. The resolution is made explicit with an E8 in the respective names.

Numeric values are 64 bits wide, instead of the conventional 256 bits used by most blockchains.

9 223 372 036 854 775 807  64-bit signed integer maximum
               00 000 000  decimals for fractions
   50 000 000 0·· ··· ···  500 M Rune total
    2 100 000 0·· ··· ···  21 M BitCoin total
   20 000 000 0·· ··· ···  200 M Ether total

Index

Constants

View Source
const ChainIDMainnet202104 = "thorchain"
View Source
const ChainIDTestnet20211106 = "thorchain-testnet-v0"

Testnet started on 2021-11-06

View Source
const MidgardBalanceCorrectionAddress = "MidgardBalanceCorrectionAddress"

Variables

View Source
var (
	EventProcTime = metrics.Must1LabelHistogram("midgard_chain_event_process_seconds", "type", 0.001, 0.01, 0.1)

	EventTotal            = metrics.Must1LabelCounter("midgard_chain_events_total", "group")
	DeliverTxEventsTotal  = EventTotal("deliver_tx")
	BeginBlockEventsTotal = EventTotal("begin_block")
	EndBlockEventsTotal   = EventTotal("end_block")
	IgnoresTotal          = metrics.MustCounter("midgard_chain_event_ignores_total", "Number of known types not in use seen.")
	UnknownsTotal         = metrics.MustCounter("midgard_chain_event_unknowns_total", "Number of unknown types discarded.")

	AttrPerEvent = metrics.MustHistogram("midgard_chain_event_attrs", "Number of attributes per event.", 0, 1, 7, 21, 144)

	PoolRewardsTotal = metrics.MustCounter("midgard_pool_rewards_total", "Number of asset amounts on rewards events seen.")
)

Package Metrics

View Source
var AdditionalEvents = AddEventsFuncMap{}
View Source
var FeeAcceptFuncs = FeeAcceptMap{}
View Source
var Recorder = &eventRecorder{
	runningTotals: *newRunningTotals(),
	chainInfo:     *newChainInfo(),
}

Recorder gets initialised by Setup.

View Source
var TimestampCorrections = map[int64]db.Second{}
View Source
var WithdrawCorrections = WithdrawCorrectionMap{}

Functions

func AddMissingEvents

func AddMissingEvents(meta *Metadata)

func AddressIsRune

func AddressIsRune(address string) bool

func CorrectionsFeeEventIsOK

func CorrectionsFeeEventIsOK(fee *Fee, meta *Metadata) bool

func FormatAttributes

func FormatAttributes(attrs []abci.EventAttribute) string

func GetNativeAsset

func GetNativeAsset(asset []byte) []byte

GetNativeAsset returns native asset from a synth

func InsertWithMeta

func InsertWithMeta(table string, meta *Metadata, cols []string, values ...interface{}) error

func IsRune

func IsRune(asset []byte) bool

IsRune returns whether asset matches any of the supported $RUNE assets.

func LoadCorrections

func LoadCorrections(chainID string)

func LoadGenesis

func LoadGenesis()

func ParseArrayInt

func ParseArrayInt(s []string) ([]int64, error)

func ParseAsset

func ParseAsset(asset []byte) (chain, ticker, id []byte)

ParseAsset decomposes the notation.

asset  :≡ chain '.' symbol | symbol
symbol :≡ ticker '-' ID | ticker

func ParseBool

func ParseBool(s string) (bool, error)

func ParseInt

func ParseInt(s string) (int64, error)

func ProcessBlock

func ProcessBlock(block *chain.Block)

Block invokes Listener for each transaction event in block.

func ResetRecorderForTest

func ResetRecorderForTest()

func RuneAsset

func RuneAsset() string

RuneAsset returns a matching RUNE asset given a running environment (Logic is copied from THORnode code)

Types

type ActiveVault

type ActiveVault struct {
	AddAsgardAddr []byte
}

ActiveVault defines the "ActiveVault" event type.

func (*ActiveVault) LoadTendermint

func (e *ActiveVault) LoadTendermint(attrs []abci.EventAttribute) error

type Add

type Add struct {
	Tx       []byte
	Chain    []byte
	FromAddr []byte
	ToAddr   []byte
	Asset    []byte
	AssetE8  int64 // Asset quantity times 100 M
	Memo     []byte

	RuneE8 int64 // Number of runes times 100 M

	Pool []byte
}

Add defines the "donate" event type.

func (*Add) LoadTendermint

func (e *Add) LoadTendermint(attrs []abci.EventAttribute) error

type AddBase

type AddBase struct {
	Pool       []byte // asset ID
	AssetTx    []byte // transfer transaction ID (may equal RuneTx)
	AssetChain []byte // transfer backend ID
	AssetAddr  []byte // pool contender address
	AssetE8    int64  // transfer asset quantity times 100 M
	RuneTx     []byte // pool transaction ID
	RuneChain  []byte // pool backend ID
	RuneAddr   []byte // pool contender address
	RuneE8     int64  // pool transaction quantity times 100 M
}

type AddEventsFunc

type AddEventsFunc func(meta *Metadata)

type AddEventsFuncMap

type AddEventsFuncMap map[int64]AddEventsFunc

func (AddEventsFuncMap) Add

func (m AddEventsFuncMap) Add(height int64, f AddEventsFunc)

type AdditionalWithdraw

type AdditionalWithdraw struct {
	Pool     string
	FromAddr string
	Reason   string
	RuneE8   int64
	AssetE8  int64
	Units    int64
}

func (*AdditionalWithdraw) Record

func (w *AdditionalWithdraw) Record(meta *Metadata)

type Amount

type Amount struct {
	Asset []byte
	E8    int64
}

type AsgardFundYggdrasil

type AsgardFundYggdrasil struct {
	Tx       []byte // THORChain transaction identifier
	Asset    []byte
	AssetE8  int64  // Asset quantity times 100 M
	VaultKey []byte // public key of yggdrasil
}

AsgardFundYggdrasil defines the "asgard_fund_yggdrasil" event type.

func (*AsgardFundYggdrasil) LoadTendermint

func (e *AsgardFundYggdrasil) LoadTendermint(attrs []abci.EventAttribute) error

type Bond

type Bond struct {
	Tx       []byte
	Chain    []byte
	FromAddr []byte
	ToAddr   []byte
	Asset    []byte
	AssetE8  int64 // Asset quantity times 100 M
	Memo     []byte

	BondType string
	E8       int64
}

Bond defines the "bond" event type.

func (*Bond) LoadTendermint

func (e *Bond) LoadTendermint(attrs []abci.EventAttribute) error

type Burn

type Burn struct {
	Asset   []byte
	AssetE8 int64
	Burner  []byte
}

type CoinType

type CoinType int
const (
	// Rune rune coin type
	Rune CoinType = iota
	// AssetNative coin native to a chain
	AssetNative
	// AssetSynth synth coin
	AssetSynth
	// UnknownCoin unknown coin
	UnknownCoin
	//Derived Asset coin, mostly made for THORFi
	AssetDerived
)

func GetCoinType

func GetCoinType(asset []byte) CoinType

type Coinbase

type Coinbase struct {
	Asset    []byte
	AssetE8  int64
	Receiver []byte
}

type Errata

type Errata struct {
	InTx    []byte
	Asset   []byte
	AssetE8 int64 // Asset quantity times 100 M
	RuneE8  int64 // Number of runes times 100 M
}

Errata defines the "errata" event type.

func (*Errata) LoadTendermint

func (e *Errata) LoadTendermint(attrs []abci.EventAttribute) error

type Fee

type Fee struct {
	Tx         []byte // THORChain transaction identifier
	Asset      []byte
	AssetE8    int64 // Asset quantity times 100 M
	PoolDeduct int64 // rune quantity times 100 M
}

Fee defines the "fee" event type, which records network fees applied to outbound transactions

func (*Fee) LoadTendermint

func (e *Fee) LoadTendermint(attrs []abci.EventAttribute) error

type FeeAcceptFunc

type FeeAcceptFunc func(fee *Fee, meta *Metadata) bool

type FeeAcceptMap

type FeeAcceptMap map[int64]FeeAcceptFunc

func (FeeAcceptMap) Add

func (m FeeAcceptMap) Add(height int64, f FeeAcceptFunc)

type Gas

type Gas struct {
	Asset   []byte
	AssetE8 int64 // Asset quantity times 100 M
	RuneE8  int64 // Number of runes times 100 M
	TxCount int64
}

Gas defines the "gas" event type.

func (*Gas) LoadTendermint

func (e *Gas) LoadTendermint(attrs []abci.EventAttribute) error

type InactiveVault

type InactiveVault struct {
	AddAsgardAddr []byte
}

InactiveVault defines the "InactiveVault" event type.

func (*InactiveVault) LoadTendermint

func (e *InactiveVault) LoadTendermint(attrs []abci.EventAttribute) error

type KeepOrDiscard

type KeepOrDiscard int
const (
	Keep KeepOrDiscard = iota
	Discard
)

func CorrectWithdraw

func CorrectWithdraw(withdraw *Withdraw, meta *Metadata) (ret KeepOrDiscard)

type LoanOpen

type LoanOpen struct {
	CollateralDeposited    int64
	DebtIssued             int64
	CollateralAsset        []byte
	CollateralizationRatio int64
	Owner                  []byte
	TargetAsset            []byte
	TxID                   []byte
}

func (*LoanOpen) LoadTendermint

func (e *LoanOpen) LoadTendermint(attrs []abci.EventAttribute) error

type LoanRepayment

type LoanRepayment struct {
	CollateralWithdrawn int64
	DebtRepaid          int64
	CollateralAsset     []byte
	Owner               []byte
	TxID                []byte
}

func (*LoanRepayment) LoadTendermint

func (e *LoanRepayment) LoadTendermint(attrs []abci.EventAttribute) error

type Message

type Message struct {
	FromAddr []byte // optional sender
	Action   []byte
}

Message defines the "message" event type.

func (*Message) LoadTendermint

func (e *Message) LoadTendermint(attrs []abci.EventAttribute) error

type Metadata

type Metadata struct {
	BlockHeight    int64
	BlockTimestamp time.Time
	EventId        db.EventId
}

Metadata has metadata for a block (from the chain).

type MintBurn

type MintBurn struct {
	Asset   []byte
	AssetE8 int64 // Asset quantity times 100 M
	Reason  []byte
	Supply  []byte
}

func (*MintBurn) LoadTendermint

func (e *MintBurn) LoadTendermint(attrs []abci.EventAttribute) error

type NewNode

type NewNode struct {
	NodeAddr []byte // THOR address
}

NewNode defines the "new_node" event type.

func (*NewNode) LoadTendermint

func (e *NewNode) LoadTendermint(attrs []abci.EventAttribute) error

type Outbound

type Outbound struct {
	Tx       []byte // THORChain transaction ID
	Chain    []byte // transfer backend ID
	FromAddr []byte // transfer pool address
	ToAddr   []byte // transfer contender address
	Asset    []byte // transfer unit ID
	AssetE8  int64  // transfer quantity times 100 M
	Memo     []byte // transfer description
	InTx     []byte // THORChain transaction ID reference
}

Outbound defines the "outbound" event type, which records a transfer confirmation from pools. Each Swap, Withdraw, UnBond or Refunds event is completed with an Outbound.

All zeros on Tx are ignored, thus keeping a nil value. E.g., the Outbound of the “to RUNE swap” on double-swaps has no transaction ID.

func (*Outbound) LoadTendermint

func (e *Outbound) LoadTendermint(attrs []abci.EventAttribute) error

type PendingLiquidity

type PendingLiquidity struct {
	AddBase
	PendingType []byte
}

PendingLiquidity defines the "pending_liquidity" event type, which records a partially received add_liquidity.

func (*PendingLiquidity) LoadTendermint

func (e *PendingLiquidity) LoadTendermint(attrs []abci.EventAttribute) error

type Pool

type Pool struct {
	Asset  []byte
	Status []byte
}

Pool defines the "pool" event type.

func (*Pool) LoadTendermint

func (e *Pool) LoadTendermint(attrs []abci.EventAttribute) error

type PoolBalanceChange

type PoolBalanceChange struct {
	Asset    []byte // pool
	RuneAmt  int64  // RuneE8
	RuneAdd  bool   // add or remove, ThorNode uses uints
	AssetAmt int64  // AssetE8
	AssetAdd bool   // add or remove, ThorNode uses uints
	Reason   string
}

PoolBalanceChange defines the "pool_balance_change" event type. https://gitlab.com/thorchain/thornode/-/blob/63ae90ef91a178fdfb6834189820bf368027fd00/proto/thorchain/v1/x/thorchain/types/type_events.proto#L142

func (*PoolBalanceChange) LoadTendermint

func (e *PoolBalanceChange) LoadTendermint(attrs []abci.EventAttribute) error

type Refund

type Refund struct {
	Tx         []byte
	Chain      []byte
	FromAddr   []byte
	ToAddr     []byte
	Asset      []byte
	AssetE8    int64 // Asset quantity times 100 M
	Asset2nd   []byte
	Asset2ndE8 int64 // Asset2 quantity times 100 M
	Memo       []byte

	Code   int64
	Reason []byte
}

Refund defines the "refund" event type.

func (*Refund) LoadTendermint

func (e *Refund) LoadTendermint(attrs []abci.EventAttribute) error

type Reserve

type Reserve struct {
	Tx       []byte
	Chain    []byte // redundant to asset
	FromAddr []byte
	ToAddr   []byte // may have multiple, separated by space
	Asset    []byte
	AssetE8  int64 // Asset quantity times 100 M
	Memo     []byte

	Addr []byte
	E8   int64 // Number of runes times 100 M
}

Reserve defines the "reserve" event type.

func (*Reserve) LoadTendermint

func (e *Reserve) LoadTendermint(attrs []abci.EventAttribute) error

type Rewards

type Rewards struct {
	BondE8 int64 // rune amount times 100 M
	// PerPool has the RUNE amounts specified per pool (in .Asset).
	PerPool []Amount
}

Rewards defines the "rewards" event type.

func (*Rewards) LoadTendermint

func (e *Rewards) LoadTendermint(attrs []abci.EventAttribute) error

type ScheduledOutbound

type ScheduledOutbound struct {
	Chain         []byte // transfer backend ID
	ToAddr        []byte // transfer contender address
	Asset         []byte // transfer unit ID
	AssetE8       int64  // transfer quantity times 100 M
	AssetDecimals int64
	Memo          []byte // transfer description
	InHash        []byte // THORChain transaction ID reference
	OutHash       []byte // THORChain transaction ID reference
	MaxGas        []int64
	MaxGasAsset   []string
	MaxGasDecimal []int64
	GasRate       int64
	ModuleName    []byte
	VaultPubKey   []byte
}

func (*ScheduledOutbound) LoadTendermint

func (e *ScheduledOutbound) LoadTendermint(attrs []abci.EventAttribute) error

type SetIPAddress

type SetIPAddress struct {
	NodeAddr []byte // THOR address
	IPAddr   []byte
}

SetIPAddr defines the "set_ip_address" event type.

func (*SetIPAddress) LoadTendermint

func (e *SetIPAddress) LoadTendermint(attrs []abci.EventAttribute) error

type SetMimir

type SetMimir struct {
	Key   []byte
	Value []byte
}

SetMimir defines the "set_mimir" event type.

func (*SetMimir) LoadTendermint

func (e *SetMimir) LoadTendermint(attrs []abci.EventAttribute) error

type SetNodeKeys

type SetNodeKeys struct {
	NodeAddr           []byte // THOR address
	Secp256k1          []byte // public key
	Ed25519            []byte // public key
	ValidatorConsensus []byte // public key
}

SetNodeKeys defines the "set_node_keys" event type.

func (*SetNodeKeys) LoadTendermint

func (e *SetNodeKeys) LoadTendermint(attrs []abci.EventAttribute) error

type SetNodeMimir

type SetNodeMimir struct {
	Address []byte
	Key     int64
	Value   []byte
}

func (*SetNodeMimir) LoadTendermint

func (e *SetNodeMimir) LoadTendermint(attrs []abci.EventAttribute) error

type SetVersion

type SetVersion struct {
	NodeAddr []byte // THOR address
	Version  string
}

SetVersion defines the "set_version" event type.

func (*SetVersion) LoadTendermint

func (e *SetVersion) LoadTendermint(attrs []abci.EventAttribute) error

type Slash

type Slash struct {
	Pool    []byte
	Amounts []Amount
}

Slash defines the "slash" event type.

func (*Slash) LoadTendermint

func (e *Slash) LoadTendermint(attrs []abci.EventAttribute) error

type SlashPoints

type SlashPoints struct {
	NodeAddress []byte
	SlashPoints int64
	Reason      []byte
}

func (*SlashPoints) LoadTendermint

func (e *SlashPoints) LoadTendermint(attrs []abci.EventAttribute) error

type Stake

type Stake struct {
	AddBase
	StakeUnits int64 // pool's liquidiy tokens—gained quantity
}

Stake defines the "stake" event type, which records a participation result."

func (*Stake) LoadTendermint

func (e *Stake) LoadTendermint(attrs []abci.EventAttribute) error

type StreamingSwapDetails

type StreamingSwapDetails struct {
	TxID          []byte
	Interval      int64
	Quantity      int64
	Count         int64
	LastHeight    int64
	DepositAsset  []byte
	DepoitE8      int64
	InAsset       []byte
	InE8          int64
	OutAsset      []byte
	OutE8         int64
	FailedSwaps   []int64
	FailedReasons []string
}

func (*StreamingSwapDetails) LoadTendermint

func (e *StreamingSwapDetails) LoadTendermint(attrs []abci.EventAttribute) error

type Swap

type Swap struct {
	Tx                []byte // THOR transaction identifier
	Chain             []byte // backend identifier
	FromAddr          []byte // input address on Chain
	ToAddr            []byte // output address on Chain
	FromAsset         []byte // input unit
	FromE8            int64  // FromAsset quantity times 100 M
	ToAsset           []byte // output unit
	ToE8              int64  // ToAsset quantity times 100 M
	Memo              []byte // encoded parameters
	Pool              []byte // asset identifier
	ToE8Min           int64  // output quantity constraint
	SwapSlipBP        int64  // ‱ the trader experienced
	LiqFeeE8          int64  // Pool asset quantity times 100 M
	LiqFeeInRuneE8    int64  // equivalent in RUNE times 100 M
	StreamingQuantity int64  // Streaming: Number of swaps events which already happened
	StreamingCount    int64  // Streaming: Number of swaps which thorchain is planning to execute
}

Swap defines the "swap" event type, which records an exchange between the .Pool asset and RUNE.

FromAsset is the input unit of a Swap. The value equals .Pool if and only if the trader sells the pool's asset for RUNE. In all other cases .FromAsset will be a RUNE, because the trader buys .Pool asset.

The liquidity fee is included. Network fees are recorded as separate Fee events (with a matching .Tx value).

func (*Swap) LoadTendermint

func (e *Swap) LoadTendermint(attrs []abci.EventAttribute) error

type Switch

type Switch struct {
	Tx        []byte
	FromAddr  []byte
	ToAddr    []byte
	BurnAsset []byte
	BurnE8    int64
	MintE8    int64
}

Upgrade Rune to Native rune.

func (*Switch) LoadTendermint

func (e *Switch) LoadTendermint(attrs []abci.EventAttribute) error

type THORNameChange

type THORNameChange struct {
	Name              []byte
	Chain             []byte
	Address           []byte
	RegistrationFeeE8 int64
	FundAmountE8      int64
	ExpireHeight      int64
	Owner             []byte
}

func (*THORNameChange) LoadTendermint

func (e *THORNameChange) LoadTendermint(attrs []abci.EventAttribute) error

type TSSKeygenFailure

type TSSKeygenFailure struct {
	Reason     []byte
	IsUniCast  bool
	BlameNodes []string
	Round      []byte
	Height     int64
}

func (*TSSKeygenFailure) LoadTendermint

func (e *TSSKeygenFailure) LoadTendermint(attrs []abci.EventAttribute) error

type TSSKeygenSuccess

type TSSKeygenSuccess struct {
	PubKey  []byte
	Members []string
	Height  int64
}

func (*TSSKeygenSuccess) LoadTendermint

func (e *TSSKeygenSuccess) LoadTendermint(attrs []abci.EventAttribute) error

type TradeAccountDeposit

type TradeAccountDeposit struct {
	Tx        []byte
	Asset     []byte
	AssetAddr []byte
	RuneAddr  []byte
	AmtE8     int64
}

func (*TradeAccountDeposit) LoadTendermint

func (e *TradeAccountDeposit) LoadTendermint(attrs []abci.EventAttribute) error

type TradeAccountWithdraw

type TradeAccountWithdraw struct {
	Tx        []byte
	Asset     []byte
	AssetAddr []byte
	RuneAddr  []byte
	AmtE8     int64
}

func (*TradeAccountWithdraw) LoadTendermint

func (e *TradeAccountWithdraw) LoadTendermint(attrs []abci.EventAttribute) error

type Transfer

type Transfer struct {
	FromAddr []byte // sender
	ToAddr   []byte // recipient
	Asset    []byte // asset converted to uppercase
	AmountE8 int64  // amount of asset
}

Transfer defines the "transfer" event type. https://github.com/cosmos/cosmos-sdk/blob/da064e13d56add466548135739c5860a9f7ed842/x/bank/keeper/send.go#L136

func (*Transfer) LoadTendermint

func (e *Transfer) LoadTendermint(attrs []abci.EventAttribute) error

type UpdateNodeAccountStatus

type UpdateNodeAccountStatus struct {
	NodeAddr []byte // THORChain address
	Former   []byte // previous status label
	Current  []byte // new status label
}

UpdateNodeAccountStatus defines the "UpdateNodeAccountStatus" event type.

func (*UpdateNodeAccountStatus) LoadTendermint

func (e *UpdateNodeAccountStatus) LoadTendermint(attrs []abci.EventAttribute) error

type ValidatorRequestLeave

type ValidatorRequestLeave struct {
	Tx       []byte // THORChain transaction identifier
	FromAddr []byte // signer THOR node
	NodeAddr []byte // subject THOR node
}

ValidatorRequestLeave defines the "validator_request_leave" event type.

func (*ValidatorRequestLeave) LoadTendermint

func (e *ValidatorRequestLeave) LoadTendermint(attrs []abci.EventAttribute) error

type Version

type Version struct {
	Version []byte
}

func (*Version) LoadTendermint

func (e *Version) LoadTendermint(attrs []abci.EventAttribute) error

type Withdraw

type Withdraw struct {
	Tx                  []byte  // THORChain transaction ID
	Chain               []byte  // transfer backend ID
	FromAddr            []byte  // transfer staker address
	ToAddr              []byte  // transfer pool address
	Asset               []byte  // transfer unit ID
	AssetE8             int64   // transfer quantity times 100 M
	EmitAssetE8         int64   // asset amount withdrawn
	EmitRuneE8          int64   // rune amount withdrawn
	Memo                []byte  // description code which triggered the event
	Pool                []byte  // asset ID
	StakeUnits          int64   // pool's liquidiy tokens—lost quantity
	BasisPoints         int64   // ‱ of total owned liquidity withdrawn
	Asymmetry           float64 // lossy conversion of what?
	ImpLossProtectionE8 int64   // rune amount added as impermanent loss protection
}

Withdraw defines the "withdraw" event type, which records a pool withdrawal request. Requests are made by wiring a (probably small) “donation” to the reserve. The actual withdrawal that follows is confirmed by an Outbound.

func (*Withdraw) LoadTendermint

func (e *Withdraw) LoadTendermint(attrs []abci.EventAttribute) error

type WithdrawCorrection

type WithdrawCorrection func(withdraw *Withdraw, meta *Metadata) KeepOrDiscard
var GlobalWithdrawCorrection WithdrawCorrection = nil

type WithdrawCorrectionMap

type WithdrawCorrectionMap map[int64]WithdrawCorrection

func (WithdrawCorrectionMap) Add

Notes

Bugs

  • Duplicate keys in Tendermint transactions overwrite on another.

Jump to

Keyboard shortcuts

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