chainfee

package
v0.18.3-beta.rc3 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxBlockTarget is the highest number of blocks confirmations that
	// a WebAPIEstimator will cache fees for. This number is chosen
	// because it's the highest number of confs bitcoind will return a fee
	// estimate for.
	MaxBlockTarget uint32 = 1008

	// WebAPIConnectionTimeout specifies the timeout value for connecting
	// to the api source.
	WebAPIConnectionTimeout = 5 * time.Second

	// WebAPIResponseTimeout specifies the timeout value for receiving a
	// fee response from the api source.
	WebAPIResponseTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

Types

type BitcoindEstimator

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

BitcoindEstimator is an implementation of the Estimator interface backed by the RPC interface of an active bitcoind node. This implementation will proxy any fee estimation requests to bitcoind's RPC interface.

func NewBitcoindEstimator

func NewBitcoindEstimator(rpcConfig rpcclient.ConnConfig, feeMode string,
	fallBackFeeRate SatPerKWeight) (*BitcoindEstimator, error)

NewBitcoindEstimator creates a new BitcoindEstimator given a fully populated rpc config that is able to successfully connect and authenticate with the bitcoind node, and also a fall back fee rate. The fallback fee rate is used in the occasion that the estimator has insufficient data, or returns zero for a fee estimate.

func (*BitcoindEstimator) EstimateFeePerKW

func (b *BitcoindEstimator) EstimateFeePerKW(
	numBlocks uint32) (SatPerKWeight, error)

EstimateFeePerKW takes in a target for the number of blocks until an initial confirmation and returns the estimated fee expressed in sat/kw.

NOTE: This method is part of the Estimator interface.

func (*BitcoindEstimator) RelayFeePerKW

func (b *BitcoindEstimator) RelayFeePerKW() SatPerKWeight

RelayFeePerKW returns the minimum fee rate required for transactions to be relayed.

NOTE: This method is part of the Estimator interface.

func (*BitcoindEstimator) Start

func (b *BitcoindEstimator) Start() error

Start signals the Estimator to start any processes or goroutines it needs to perform its duty.

NOTE: This method is part of the Estimator interface.

func (*BitcoindEstimator) Stop

func (b *BitcoindEstimator) Stop() error

Stop stops any spawned goroutines and cleans up the resources used by the fee estimator.

NOTE: This method is part of the Estimator interface.

type BtcdEstimator

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

BtcdEstimator is an implementation of the Estimator interface backed by the RPC interface of an active btcd node. This implementation will proxy any fee estimation requests to btcd's RPC interface.

func NewBtcdEstimator

func NewBtcdEstimator(rpcConfig rpcclient.ConnConfig,
	fallBackFeeRate SatPerKWeight) (*BtcdEstimator, error)

NewBtcdEstimator creates a new BtcdEstimator given a fully populated rpc config that is able to successfully connect and authenticate with the btcd node, and also a fall back fee rate. The fallback fee rate is used in the occasion that the estimator has insufficient data, or returns zero for a fee estimate.

func (*BtcdEstimator) EstimateFeePerKW

func (b *BtcdEstimator) EstimateFeePerKW(numBlocks uint32) (SatPerKWeight, error)

EstimateFeePerKW takes in a target for the number of blocks until an initial confirmation and returns the estimated fee expressed in sat/kw.

NOTE: This method is part of the Estimator interface.

func (*BtcdEstimator) RelayFeePerKW

func (b *BtcdEstimator) RelayFeePerKW() SatPerKWeight

RelayFeePerKW returns the minimum fee rate required for transactions to be relayed.

NOTE: This method is part of the Estimator interface.

func (*BtcdEstimator) Start

func (b *BtcdEstimator) Start() error

Start signals the Estimator to start any processes or goroutines it needs to perform its duty.

NOTE: This method is part of the Estimator interface.

func (*BtcdEstimator) Stop

func (b *BtcdEstimator) Stop() error

Stop stops any spawned goroutines and cleans up the resources used by the fee estimator.

NOTE: This method is part of the Estimator interface.

type Estimator

type Estimator interface {
	// EstimateFeePerKW takes in a target for the number of blocks until an
	// initial confirmation and returns the estimated fee expressed in
	// sat/kw.
	EstimateFeePerKW(numBlocks uint32) (SatPerKWeight, error)

	// Start signals the Estimator to start any processes or goroutines
	// it needs to perform its duty.
	Start() error

	// Stop stops any spawned goroutines and cleans up the resources used
	// by the fee estimator.
	Stop() error

	// RelayFeePerKW returns the minimum fee rate required for transactions
	// to be relayed. This is also the basis for calculation of the dust
	// limit.
	RelayFeePerKW() SatPerKWeight
}

Estimator provides the ability to estimate on-chain transaction fees for various combinations of transaction sizes and desired confirmation time (measured by number of blocks).

type MockEstimator

type MockEstimator struct {
	mock.Mock
}

MockEstimator implements the `Estimator` interface and is used by other packages for mock testing.

func (*MockEstimator) EstimateFeePerKW

func (m *MockEstimator) EstimateFeePerKW(
	numBlocks uint32) (SatPerKWeight, error)

EstimateFeePerKW takes in a target for the number of blocks until an initial confirmation and returns the estimated fee expressed in sat/kw.

func (*MockEstimator) RelayFeePerKW

func (m *MockEstimator) RelayFeePerKW() SatPerKWeight

RelayFeePerKW returns the minimum fee rate required for transactions to be relayed. This is also the basis for calculation of the dust limit.

func (*MockEstimator) Start

func (m *MockEstimator) Start() error

Start signals the Estimator to start any processes or goroutines it needs to perform its duty.

func (*MockEstimator) Stop

func (m *MockEstimator) Stop() error

Stop stops any spawned goroutines and cleans up the resources used by the fee estimator.

type SatPerKVByte

type SatPerKVByte btcutil.Amount

SatPerKVByte represents a fee rate in sat/kb.

func (SatPerKVByte) FeeForVSize

func (s SatPerKVByte) FeeForVSize(vbytes lntypes.VByte) btcutil.Amount

FeeForVSize calculates the fee resulting from this fee rate and the given vsize in vbytes.

func (SatPerKVByte) FeePerKWeight

func (s SatPerKVByte) FeePerKWeight() SatPerKWeight

FeePerKWeight converts the current fee rate from sat/kb to sat/kw.

func (SatPerKVByte) String

func (s SatPerKVByte) String() string

String returns a human-readable string of the fee rate.

type SatPerKWeight

type SatPerKWeight btcutil.Amount

SatPerKWeight represents a fee rate in sat/kw.

const (
	// FeePerKwFloor is the lowest fee rate in sat/kw that we should use for
	// estimating transaction fees before signing.
	FeePerKwFloor SatPerKWeight = 253

	// AbsoluteFeePerKwFloor is the lowest fee rate in sat/kw of a
	// transaction that we should ever _create_. This is the equivalent
	// of 1 sat/byte in sat/kw.
	AbsoluteFeePerKwFloor SatPerKWeight = 250
)

func NewSatPerKWeight

func NewSatPerKWeight(fee btcutil.Amount, wu lntypes.WeightUnit) SatPerKWeight

NewSatPerKWeight creates a new fee rate in sat/kw.

func (SatPerKWeight) FeeForVByte

func (s SatPerKWeight) FeeForVByte(vb lntypes.VByte) btcutil.Amount

FeeForVByte calculates the fee resulting from this fee rate and the given size in vbytes (vb).

func (SatPerKWeight) FeeForWeight

func (s SatPerKWeight) FeeForWeight(wu lntypes.WeightUnit) btcutil.Amount

FeeForWeight calculates the fee resulting from this fee rate and the given weight in weight units (wu).

func (SatPerKWeight) FeePerKVByte

func (s SatPerKWeight) FeePerKVByte() SatPerKVByte

FeePerKVByte converts the current fee rate from sat/kw to sat/kb.

func (SatPerKWeight) FeePerVByte

func (s SatPerKWeight) FeePerVByte() SatPerVByte

FeePerVByte converts the current fee rate from sat/kw to sat/vb.

func (SatPerKWeight) String

func (s SatPerKWeight) String() string

String returns a human-readable string of the fee rate.

type SatPerVByte

type SatPerVByte btcutil.Amount

SatPerVByte represents a fee rate in sat/vbyte.

func (SatPerVByte) FeePerKVByte

func (s SatPerVByte) FeePerKVByte() SatPerKVByte

FeePerKVByte converts the current fee rate from sat/vb to sat/kvb.

func (SatPerVByte) FeePerKWeight

func (s SatPerVByte) FeePerKWeight() SatPerKWeight

FeePerKWeight converts the current fee rate from sat/vb to sat/kw.

func (SatPerVByte) String

func (s SatPerVByte) String() string

String returns a human-readable string of the fee rate.

type SparseConfFeeSource

type SparseConfFeeSource struct {
	// URL is the fee estimation API specified by the user.
	URL string
}

SparseConfFeeSource is an implementation of the WebAPIFeeSource that utilizes a user-specified fee estimation API for Bitcoin. It expects the response to be in the JSON format: `fee_by_block_target: { ... }` where the value maps block targets to fee estimates (in sat per kilovbyte).

func (SparseConfFeeSource) GetFeeInfo

func (s SparseConfFeeSource) GetFeeInfo() (WebAPIResponse, error)

GetFeeInfo will query the web API, parse the response and return a map of confirmation targets to sat/kw fees and min relay feerate in a parsed response.

type StaticEstimator

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

StaticEstimator will return a static value for all fee calculation requests. It is designed to be replaced by a proper fee calculation implementation. The fees are not accessible directly, because changing them would not be thread safe.

func NewStaticEstimator

func NewStaticEstimator(feePerKW, relayFee SatPerKWeight) *StaticEstimator

NewStaticEstimator returns a new static fee estimator instance.

func (StaticEstimator) EstimateFeePerKW

func (e StaticEstimator) EstimateFeePerKW(numBlocks uint32) (SatPerKWeight, error)

EstimateFeePerKW will return a static value for fee calculations.

NOTE: This method is part of the Estimator interface.

func (StaticEstimator) RelayFeePerKW

func (e StaticEstimator) RelayFeePerKW() SatPerKWeight

RelayFeePerKW returns the minimum fee rate required for transactions to be relayed.

NOTE: This method is part of the Estimator interface.

func (StaticEstimator) Start

func (e StaticEstimator) Start() error

Start signals the Estimator to start any processes or goroutines it needs to perform its duty.

NOTE: This method is part of the Estimator interface.

func (StaticEstimator) Stop

func (e StaticEstimator) Stop() error

Stop stops any spawned goroutines and cleans up the resources used by the fee estimator.

NOTE: This method is part of the Estimator interface.

type WebAPIEstimator

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

WebAPIEstimator is an implementation of the Estimator interface that queries an HTTP-based fee estimation from an existing web API.

func NewWebAPIEstimator

func NewWebAPIEstimator(api WebAPIFeeSource, noCache bool,
	minFeeUpdateTimeout time.Duration,
	maxFeeUpdateTimeout time.Duration) (*WebAPIEstimator, error)

NewWebAPIEstimator creates a new WebAPIEstimator from a given URL and a fallback default fee. The fees are updated whenever a new block is mined.

func (*WebAPIEstimator) EstimateFeePerKW

func (w *WebAPIEstimator) EstimateFeePerKW(numBlocks uint32) (
	SatPerKWeight, error)

EstimateFeePerKW takes in a target for the number of blocks until an initial confirmation and returns the estimated fee expressed in sat/kw.

NOTE: This method is part of the Estimator interface.

func (*WebAPIEstimator) RelayFeePerKW

func (w *WebAPIEstimator) RelayFeePerKW() SatPerKWeight

RelayFeePerKW returns the minimum fee rate required for transactions to be relayed.

NOTE: This method is part of the Estimator interface.

func (*WebAPIEstimator) Start

func (w *WebAPIEstimator) Start() error

Start signals the Estimator to start any processes or goroutines it needs to perform its duty.

NOTE: This method is part of the Estimator interface.

func (*WebAPIEstimator) Stop

func (w *WebAPIEstimator) Stop() error

Stop stops any spawned goroutines and cleans up the resources used by the fee estimator.

NOTE: This method is part of the Estimator interface.

type WebAPIFeeSource

type WebAPIFeeSource interface {
	// GetFeeInfo will query the web API, parse the response into a
	// WebAPIResponse which contains a map of confirmation targets to
	// sat/kw fees and min relay feerate.
	GetFeeInfo() (WebAPIResponse, error)
}

WebAPIFeeSource is an interface allows the WebAPIEstimator to query an arbitrary HTTP-based fee estimator. Each new set/network will gain an implementation of this interface in order to allow the WebAPIEstimator to be fully generic in its logic.

type WebAPIResponse

type WebAPIResponse struct {
	// FeeByBlockTarget is a map of confirmation targets to sat/kvb fees.
	FeeByBlockTarget map[uint32]uint32 `json:"fee_by_block_target"`

	// MinRelayFeerate is the minimum relay fee in sat/kvb.
	MinRelayFeerate SatPerKVByte `json:"min_relay_feerate"`
}

WebAPIResponse is the response returned by the fee estimation API.

Jump to

Keyboard shortcuts

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