config

package
v3.0.0-...-5980f66 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxRetries   = 3
	RetryBackoff = time.Second * 5
)

Variables

This section is empty.

Functions

func Init

func Init()

Init should be called at the beginning of execution to load base configuration and generate dependent configuration files. The defaults for the config package will be loaded from values defined in defaults.yaml in this package, then overridden the corresponding environment variables.

func InitBifrost

func InitBifrost()

func InitThornode

func InitThornode(ctx context.Context)

Types

type Bifrost

type Bifrost struct {
	Signer    BifrostSignerConfiguration  `mapstructure:"signer"`
	Thorchain BifrostClientConfiguration  `mapstructure:"thorchain"`
	Metrics   BifrostMetricsConfiguration `mapstructure:"metrics"`
	Chains    struct {
		AVAX BifrostChainConfiguration `mapstructure:"avax"`
		BCH  BifrostChainConfiguration `mapstructure:"bch"`
		BSC  BifrostChainConfiguration `mapstructure:"bsc"`
		BTC  BifrostChainConfiguration `mapstructure:"btc"`
		DOGE BifrostChainConfiguration `mapstructure:"doge"`
		ETH  BifrostChainConfiguration `mapstructure:"eth"`
		GAIA BifrostChainConfiguration `mapstructure:"gaia"`
		LTC  BifrostChainConfiguration `mapstructure:"ltc"`
	} `mapstructure:"chains"`
	TSS             BifrostTSSConfiguration `mapstructure:"tss"`
	ObserverLevelDB LevelDBOptions          `mapstructure:"observer_leveldb"`
}

func GetBifrost

func GetBifrost() Bifrost

GetBifrost returns the global thornode configuration.

func (Bifrost) GetChains

func (b Bifrost) GetChains() map[common.Chain]BifrostChainConfiguration

type BifrostBlockScannerConfiguration

type BifrostBlockScannerConfiguration struct {
	RPCHost                    string        `mapstructure:"rpc_host"`
	StartBlockHeight           int64         `mapstructure:"start_block_height"`
	BlockScanProcessors        int           `mapstructure:"block_scan_processors"`
	HTTPRequestTimeout         time.Duration `mapstructure:"http_request_timeout"`
	HTTPRequestReadTimeout     time.Duration `mapstructure:"http_request_read_timeout"`
	HTTPRequestWriteTimeout    time.Duration `mapstructure:"http_request_write_timeout"`
	MaxHTTPRequestRetry        int           `mapstructure:"max_http_request_retry"`
	BlockHeightDiscoverBackoff time.Duration `mapstructure:"block_height_discover_back_off"`
	BlockRetryInterval         time.Duration `mapstructure:"block_retry_interval"`
	EnforceBlockHeight         bool          `mapstructure:"enforce_block_height"`
	DBPath                     string        `mapstructure:"db_path"`
	ChainID                    common.Chain  `mapstructure:"chain_id"`

	// ScanBlocks indicates whether mempool transactions should be scanned.
	ScanMemPool bool `mapstructure:"scan_mempool"`

	// CosmosGRPCHost is the <host>:<port> of the gRPC endpoint of the Cosmos SDK chain.
	CosmosGRPCHost string `mapstructure:"cosmos_grpc_host"`

	// CosmosGRPCTLS is a boolean value indicating whether the gRPC host is using TLS.
	CosmosGRPCTLS bool `mapstructure:"cosmos_grpc_tls"`

	// GasCacheBlocks is the number of blocks worth of gas price data cached to determine
	// the gas price reported to Thorchain.
	GasCacheBlocks int `mapstructure:"gas_cache_blocks"`

	// Concurrency is the number of goroutines used for RPC requests on data within a
	// block - e.g. transactions, receipts, logs, etc. Blocks are processed sequentially.
	Concurrency int64 `mapstructure:"concurrency"`

	// FixedGasRate will force the scanner to only report the defined gas rate.
	FixedGasRate int64 `mapstructure:"fixed_gas_rate"`

	// GasPriceResolution is the resolution of price per gas unit in the base asset of the
	// chain (wei, tavax, uatom, satoshi, etc) and is transitively the floor price. The
	// gas price will be rounded up to the nearest multiple of this value.
	GasPriceResolution int64 `mapstructure:"gas_price_resolution"`

	// ObservationFlexibilityBlocks is the number of blocks behind the current tip we will
	// submit network fee and solvency observations.
	ObservationFlexibilityBlocks int64 `mapstructure:"observation_flexibility_blocks"`

	// MaxGasLimit is the maximum gas allowed for non-aggregator outbounds. This is used
	// as the limit in the estimate gas call, and the estimate gas (lower) is used in the
	// final outbound.
	MaxGasLimit uint64 `mapstructure:"max_gas_limit"`

	// MaxContractTxLogs is the maximum logs allowed for an inbound EVM tx. This is used to prevent
	// bifrost being bogged down during smart contract log parsing down by large txs.
	MaxContractTxLogs int `mapstructure:"max_contract_tx_logs"`

	// WhitelistTokens is the set of whitelisted token addresses. Inbounds for all other
	// tokens are ignored.
	WhitelistTokens []string `mapstructure:"whitelist_tokens"`

	// MaxResumeBlockLag is the max duration to lag behind the latest current consensus
	// inbound height upon startup. If there is a local scanner position we will start
	// from that height up to this threshold. The local scanner height is compared to the
	// height from the lastblock response, which contains the height of the latest
	// consensus inbound. This is necessary to avoid a race, as there could be a consensus
	// inbound after an outbound which has not reached consensus, causing double spend.
	MaxResumeBlockLag time.Duration `mapstructure:"max_resume_block_lag"`

	// MaxHealthyLag is the max duration to lag behind the latest block before the scanner
	// is considered unhealthy.
	MaxHealthyLag time.Duration `mapstructure:"max_healthy_lag"`

	// TransactionBatchSize is the number of transactions to batch in a single request.
	// This is used as the limit for one iteration of mempool checks and fanout in
	// fetching block transactions.
	//
	// TODO: This is redundant with the UTXO config, but needs to be on this object for
	// EVM chains - use common config when we refactor to consolidate the config object.
	TransactionBatchSize int `mapstructure:"transaction_batch_size"`

	// MaxReorgRescanBlocks is the maximum number of blocks to rescan during a reorg.
	MaxReorgRescanBlocks int64 `mapstructure:"max_reorg_rescan_blocks"`
}

func (*BifrostBlockScannerConfiguration) Validate

func (b *BifrostBlockScannerConfiguration) Validate()

type BifrostChainConfiguration

type BifrostChainConfiguration struct {
	ChainID             common.Chain                     `mapstructure:"chain_id"`
	ChainHost           string                           `mapstructure:"chain_host"`
	ChainNetwork        string                           `mapstructure:"chain_network"`
	UserName            string                           `mapstructure:"username"`
	Password            string                           `mapstructure:"password"`
	RPCHost             string                           `mapstructure:"rpc_host"`
	CosmosGRPCHost      string                           `mapstructure:"cosmos_grpc_host"`
	CosmosGRPCTLS       bool                             `mapstructure:"cosmos_grpc_tls"`
	HTTPostMode         bool                             `mapstructure:"http_post_mode"` // Bitcoin core only supports HTTP POST mode
	DisableTLS          bool                             `mapstructure:"disable_tls"`    // Bitcoin core does not provide TLS by default
	OptToRetire         bool                             `mapstructure:"opt_to_retire"`  // don't emit support for this chain during keygen process
	ParallelMempoolScan int                              `mapstructure:"parallel_mempool_scan"`
	Disabled            bool                             `mapstructure:"disabled"`
	SolvencyBlocks      int64                            `mapstructure:"solvency_blocks"`
	BlockScanner        BifrostBlockScannerConfiguration `mapstructure:"block_scanner"`

	// MemPoolTxIDCacheSize is the number of transaction ids to cache in memory. This
	// prevents read on LevelDB which may hit disk for every transaction in the mempool in
	// a loop - which causes concern in recent times with growing Bitcoin mempool.
	MempoolTxIDCacheSize int `mapstructure:"mempool_tx_id_cache_size"`

	// ScannerLevelDB is the LevelDB configuration for the block scanner.
	ScannerLevelDB LevelDBOptions `mapstructure:"scanner_leveldb"`

	// MinConfirmations is the minimum number of confirmations to require before an
	// observed inbound transaction is considered valid.
	MinConfirmations uint64 `mapstructure:"min_confirmations"`

	// MaxRPCRetries is the maximum number of retries for RPC requests.
	MaxRPCRetries int `mapstructure:"max_rpc_retries"`

	// MaxGasTipPercentage is the percentage of the max fee to set for the max tip cap on
	// dynamic fee EVM transactions.
	MaxGasTipPercentage int `mapstructure:"max_gas_tip_percentage"`

	// TokenMaxGasMultiplier is a multiplier applied to max gas for outbounds which are
	// not the gas asset. This compensates for variance in gas units when contracts for
	// pool assets use more than the configured MaxGasLimit gas units in transferOut.
	TokenMaxGasMultiplier int64 `mapstructure:"token_max_gas_multiplier"`

	// AggregatorMaxGasMultiplier is a multiplier applied to max gas for outbounds which
	// swap out via an aggregator contract. This compensates for variance in gas units when
	// aggregator swaps outs use more than the configured MaxGasLimit gas units.
	AggregatorMaxGasMultiplier int64 `mapstructure:"aggregator_max_gas_multiplier"`

	// MaxPendingNonces is the maximum number of pending nonces to allow before aborting
	// new signing attempts.
	MaxPendingNonces uint64 `mapstructure:"max_pending_nonces"`

	// UTXO contains UTXO chain specific configuration.
	UTXO struct {
		// BlockCacheCount is the number of blocks to cache in storage.
		BlockCacheCount uint64 `mapstructure:"block_cache_count"`

		// TransactionBatchSize is the number of transactions to batch in a single request.
		// This is used as the limit for one iteration of the mempool check, and for fanout
		// in fetching block transactions for chains that do not yet support verbosity level
		// 2 on getblock (dogecoin).
		TransactionBatchSize int `mapstructure:"transaction_batch_size"`

		// MaxMempoolBatches is the maximum number of batches to fetch from the mempool in
		// a single scanning pass.
		MaxMempoolBatches int `mapstructure:"max_mempool_batches"`

		// EstimatedAverageTxSize is the estimated average transaction size in bytes.
		EstimatedAverageTxSize uint64 `mapstructure:"estimated_average_tx_size"`

		// DefaultMinRelayFee is the default minimum relay fee in sats.
		DefaultMinRelayFeeSats uint64 `mapstructure:"default_min_relay_fee_sats"`

		// DefaultSatsPerVByte is the default fee rate in sats per vbyte. It is only used as
		// a fallback when local fee information is unavailable.
		DefaultSatsPerVByte int64 `mapstructure:"default_sats_per_vbyte"`

		// MaxSatsPerVByte is the maximum fee rate in sats per vbyte. It is used to cap the
		// fee rate, since overpaid fees may be rejected by the chain daemon.
		MaxSatsPerVByte int64 `mapstructure:"max_sats_per_vbyte"`

		// MinSatsPerVByte is the minimum fee rate in sats per vbyte. It is used floor the
		// fee rate in order to prevent inbound transactions from being stuck in the
		// mempool.
		MinSatsPerVByte int64 `mapstructure:"min_sats_per_vbyte"`

		// MinUTXOConfirmations is the minimum number of confirmations required for a UTXO to
		// be considered for spending from an asgard vault.
		MinUTXOConfirmations int64 `mapstructure:"min_utxo_confirmations"`

		// MaxUTXOsToSpend is the maximum number of UTXOs to spend in a single transaction.
		// This is overridden at runtime by the `MaxUTXOsToSpend` mimir value.
		MaxUTXOsToSpend int64 `mapstructure:"max_utxos_to_spend"`
	} `mapstructure:"utxo"`
}

func (*BifrostChainConfiguration) Validate

func (b *BifrostChainConfiguration) Validate()

type BifrostClientConfiguration

type BifrostClientConfiguration struct {
	ChainID         common.Chain `mapstructure:"chain_id" `
	ChainHost       string       `mapstructure:"chain_host"`
	ChainRPC        string       `mapstructure:"chain_rpc"`
	ChainHomeFolder string       `mapstructure:"chain_home_folder"`
	SignerName      string       `mapstructure:"signer_name"`
	SignerPasswd    string
}

type BifrostMetricsConfiguration

type BifrostMetricsConfiguration struct {
	Enabled      bool           `mapstructure:"enabled"`
	PprofEnabled bool           `mapstructure:"pprof_enabled"`
	ListenPort   int            `mapstructure:"listen_port"`
	ReadTimeout  time.Duration  `mapstructure:"read_timeout"`
	WriteTimeout time.Duration  `mapstructure:"write_timeout"`
	Chains       []common.Chain `mapstructure:"chains"`
}

type BifrostSignerConfiguration

type BifrostSignerConfiguration struct {
	BackupKeyshares bool                             `mapstructure:"backup_keyshares"`
	SignerDbPath    string                           `mapstructure:"signer_db_path"`
	BlockScanner    BifrostBlockScannerConfiguration `mapstructure:"block_scanner"`
	RetryInterval   time.Duration                    `mapstructure:"retry_interval"`

	// RescheduleBufferBlocks is the number of blocks before reschedule we will stop
	// attempting to sign and broadcast (for outbounds not in round 7 retry).
	RescheduleBufferBlocks int64          `mapstructure:"reschedule_buffer_blocks"`
	LevelDB                LevelDBOptions `mapstructure:"leveldb"`

	// AutoObserve will automatically submit the observation for outbound transactions once
	// they are signed - regardless of broadcast success.
	AutoObserve bool `mapstructure:"auto_observe"`

	KeygenTimeout   time.Duration `mapstructure:"keygen_timeout"`
	KeysignTimeout  time.Duration `mapstructure:"keysign_timeout"`
	PartyTimeout    time.Duration `mapstructure:"party_timeout"`
	PreParamTimeout time.Duration `mapstructure:"pre_param_timeout"`
}

type BifrostTSSConfiguration

type BifrostTSSConfiguration struct {
	BootstrapPeers               []string `mapstructure:"bootstrap_peers"`
	Rendezvous                   string   `mapstructure:"rendezvous"`
	P2PPort                      int      `mapstructure:"p2p_port"`
	InfoAddress                  string   `mapstructure:"info_address"`
	ExternalIP                   string   `mapstructure:"external_ip"`
	MaxKeyshareRecoverScanBlocks int64    `mapstructure:"max_keyshare_recover_scan_blocks"`
}

func (BifrostTSSConfiguration) GetBootstrapPeers

func (c BifrostTSSConfiguration) GetBootstrapPeers() ([]maddr.Multiaddr, error)

GetBootstrapPeers return the internal bootstrap peers in a slice of maddr.Multiaddr

type Config

type Config struct {
	Thornode Thornode `mapstructure:"thor"`
	Bifrost  Bifrost  `mapstructure:"bifrost"`
}

type LevelDBOptions

type LevelDBOptions struct {
	// FilterBitsPerKey is the number of bits per key for the bloom filter.
	FilterBitsPerKey int `mapstructure:"filter_bits_per_key"`

	// CompactionTableSizeMultiplier is the multiplier for compaction (table size is 2Mb).
	CompactionTableSizeMultiplier float64 `mapstructure:"compaction_table_size_multiplier"`

	// WriteBuffer is the size of the write buffer in bytes. LevelDB default is 4Mb.
	WriteBuffer int `mapstructure:"write_buffer"`

	// BlockCacheCapacity is the size of the block cache in bytes. LevelDB default is 8Mb.
	BlockCacheCapacity int `mapstructure:"block_cache_capacity"`

	// CompactOnInit will trigger a full compaction at init.
	CompactOnInit bool `mapstructure:"compact_on_init"`
}

LevelDBOptions are a superset of the options passed to the LevelDB constructor.

func (LevelDBOptions) Options

func (b LevelDBOptions) Options() *opt.Options

Options returns the corresponding LevelDB options for the constructor.

type Thornode

type Thornode struct {
	// NodeRelayURL is the URL of the node relay service.
	NodeRelayURL string `mapstructure:"node_relay_url"`

	// VaultPubkeysCutoffBlocks is the max age in blocks for inactive vaults to be
	// included in the vaults pubkeys response. Vaults older than this age will not be
	// observed by bifrost.
	VaultPubkeysCutoffBlocks int64 `mapstructure:"vault_pubkeys_cutoff_blocks"`

	// SeedNodesEndpoint is the full URL to a /thorchain/nodes endpoint for finding active
	// validators to seed genesis and peers.
	SeedNodesEndpoint string `mapstructure:"seed_nodes_endpoint"`

	// StagenetAdminAddresses is only leveraged in stagenet builds to allow for running
	// independent stagenet networks with their own admin addresses. This must remain
	// constant in the configuration for the lifetime of the stagenet instance to avoid
	// consensus failure on sync from genesis.
	StagenetAdminAddresses []string `mapstructure:"stagenet_admin_addresses"`

	// LogFilter will drop logs matching the modules and messages when not in debug level.
	LogFilter struct {
		// Modules is a list of modules to filter.
		Modules []string `mapstructure:"modules"`

		// Messages is a list of messages to filter.
		Messages []string `mapstructure:"messages"`
	} `mapstructure:"log_filter"`

	AutoStateSync struct {
		Enabled bool `mapstructure:"enabled"`

		// BlockBuffer is the number of blocks in the past we will automatically reference
		// for the trust state from one of the configured RPC endpoints.
		BlockBuffer int64 `mapstructure:"block_buffer"`

		// Peers will be used to template the persistent peers in the Tendermint P2P config
		// on the first launch. These peers are static and typically provided by benevolent
		// community members, since the statesync snapshot creation is very expensive and
		// cannot be enabled on nodes unless they are willing to fall behind for a few hours
		// while the snapshots create. Once the initial snapshot is recovered, subsequent
		// restarts will unset the fixed persistent peers to free up peer slots on nodes
		// that are known statesync providers.
		Peers []string `mapstructure:"peers"`
	} `mapstructure:"auto_state_sync"`

	// Cosmos contains values used in templating the Cosmos app.toml.
	Cosmos struct {
		Pruning         string `mapstructure:"pruning"`
		HaltHeight      int64  `mapstructure:"halt_height"`
		MinRetainBlocks int64  `mapstructure:"min_retain_blocks"`

		Telemetry struct {
			Enabled                 bool  `mapstructure:"enabled"`
			PrometheusRetentionTime int64 `mapstructure:"prometheus_retention_time"`
		} `mapstructure:"telemetry"`

		API struct {
			Enable            bool   `mapstructure:"enable"`
			EnabledUnsafeCORS bool   `mapstructure:"enabled_unsafe_cors"`
			Address           string `mapstructure:"address"`
		} `mapstructure:"api"`

		GRPC struct {
			Enable  bool   `mapstructure:"enable"`
			Address string `mapstructure:"address"`
		} `mapstructure:"grpc"`

		StateSync struct {
			SnapshotInterval   int64 `mapstructure:"snapshot_interval"`
			SnapshotKeepRecent int64 `mapstructure:"snapshot_keep_recent"`
		} `mapstructure:"state_sync"`
	} `mapstructure:"cosmos"`

	// Tendermint contains values used in templating the Tendermint config.toml.
	Tendermint struct {
		Consensus struct {
			TimeoutProposeDelta   time.Duration `mapstructure:"timeout_propose_delta"`
			TimeoutPrevoteDelta   time.Duration `mapstructure:"timeout_prevote_delta"`
			TimeoutPrecommitDelta time.Duration `mapstructure:"timeout_precommit_delta"`
			TimeoutCommit         time.Duration `mapstructure:"timeout_commit"`
		} `mapstructure:"consensus"`

		Log struct {
			Level  string `mapstructure:"level"`
			Format string `mapstructure:"format"`
		} `mapstructure:"log"`

		RPC struct {
			ListenAddress                        string `mapstructure:"listen_address"`
			CORSAllowedOrigin                    string `mapstructure:"cors_allowed_origin"`
			ExperimentalSubscriptionBufferSize   int64  `mapstructure:"experimental_subscription_buffer_size"`
			ExperimentalWebsocketWriteBufferSize int64  `mapstructure:"experimental_websocket_write_buffer_size"`
		} `mapstructure:"rpc"`

		P2P struct {
			ExternalAddress     string `mapstructure:"external_address"`
			ListenAddress       string `mapstructure:"listen_address"`
			PersistentPeers     string `mapstructure:"persistent_peers"`
			AddrBookStrict      bool   `mapstructure:"addr_book_strict"`
			MaxNumInboundPeers  int64  `mapstructure:"max_num_inbound_peers"`
			MaxNumOutboundPeers int64  `mapstructure:"max_num_outbound_peers"`
			AllowDuplicateIP    bool   `mapstructure:"allow_duplicate_ip"`
			Seeds               string `mapstructure:"seeds"`
		} `mapstructure:"p2p"`

		StateSync struct {
			Enable      bool   `mapstructure:"enable"`
			RPCServers  string `mapstructure:"rpc_servers"`
			TrustHeight int64  `mapstructure:"trust_height"`
			TrustHash   string `mapstructure:"trust_hash"`
			TrustPeriod string `mapstructure:"trust_period"`
		} `mapstructure:"state_sync"`

		Instrumentation struct {
			Prometheus bool `mapstructure:"prometheus"`
		} `mapstructure:"instrumentation"`
	} `mapstructure:"tendermint"`
}

func GetThornode

func GetThornode() Thornode

GetThornode returns the global thornode configuration.

Jump to

Keyboard shortcuts

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