estimate

package
v0.0.0-...-242325e Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package estimate produces estimates of the models defined in package sim (TxSource / BlockSource).

Index

Constants

This section is empty.

Variables

View Source
var ErrInsufficientBlocks = errors.New("too few blocks to estimate blocksource")

This error should rarely happen, if block coverage is met.

Functions

func IndBlockSource

func IndBlockSource(height int64, c IndBlockSourceConfig, db BlockStatDB) (*sim.IndBlockSource, error)

IndBlockSource returns an estimate of sim.IndBlockSource based on BlockStats from heights [height-window+1, height].

func IndBlockSourceSMFR

func IndBlockSourceSMFR(height int64, c IndBlockSourceConfig, db BlockStatDB) (*sim.IndBlockSource, error)

IndBlockSourceSMFR is IndBlockSource with a static minfeerate. The reason for this is that the miner policy estimation wasn't designed to work with constantly full blocks. Constantly full blocks causes minfeerate policy estimates to be inflated, which in turn inflates fee estimates. To avoid this, we just assume that miner minfeerates are equal to the lowest observed sfr.

func MultiTxSource

func MultiTxSource(t int64, c *MultiTxSourceConfig, db TxDB) (*sim.MultiTxSource, error)

Types

type BlockCoverageError

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

func (BlockCoverageError) Error

func (err BlockCoverageError) Error() string

type BlockSFRData

type BlockSFRData []struct {
	// contains filtered or unexported fields
}

func (BlockSFRData) Len

func (b BlockSFRData) Len() int

func (BlockSFRData) Less

func (b BlockSFRData) Less(i, j int) bool

func (BlockSFRData) Swap

func (b BlockSFRData) Swap(i, j int)

type BlockSizeData

type BlockSizeData []struct {
	// contains filtered or unexported fields
}

func (BlockSizeData) Len

func (b BlockSizeData) Len() int

func (BlockSizeData) Less

func (b BlockSizeData) Less(i, j int) bool

func (BlockSizeData) Swap

func (b BlockSizeData) Swap(i, j int)

type BlockSourceEstimator

type BlockSourceEstimator func(h int64) (sim.BlockSource, error)

Successive calls have non-decreasing h.

type BlockStat

type BlockStat struct {
	// Block height
	Height int64 `json:"height"`

	// Block size
	Size int64 `json:"size"`

	// Stranding fee rate stats
	SFRStat SFRStat `json:"sfrstat"`

	// Mempool size just prior to block discovery
	MempoolSize int64 `json:"mempoolsize"`

	// Mempool size just after block discovery
	MempoolSizeRemain int64 `json:"mempoolsizeremain"`

	// Block time (as measured locally; not the block timestamp)
	// Unit is Unix time in seconds.
	Time int64 `json:"time"`

	// Expected number of hashes used to solve this block (function of nBits)
	NumHashes float64 `json:"numhashes"`
}

type BlockStatDB

type BlockStatDB interface {
	Get(start, end int64) ([]*BlockStat, error) // Result must be height-sorted
}

type IndBlockSourceConfig

type IndBlockSourceConfig struct {
	Window        int64   `yaml:"window" json:"window"`
	MinCov        float64 `yaml:"mincov" json:"mincov"`
	GuardInterval int64   `yaml:"guardinterval" json:"guardinterval"`
	TailPct       float64 `yaml:"tailpct" json:"tailpct"`
}

type MultiTxSourceConfig

type MultiTxSourceConfig struct {
	// All in seconds
	MinWindow int64 `yaml:"minwindow" json:"minwindow"`
	MaxWindow int64 `yaml:"maxwindow" json:"maxwindow"`
	Halflife  int64 `yaml:"halflife" json:"halflife"`
	MaxTxs    int   `yaml:"maxtxs" json:"maxtxs"`
}

type SFRStat

type SFRStat struct {
	SFR sim.FeeRate `json:"sfr"`
	AK  int64       `json:"ak"`
	AN  int64       `json:"an"`
	BK  int64       `json:"bk"`
	BN  int64       `json:"bn"`
}

func (SFRStat) String

func (s SFRStat) String() string

type SFRTx

type SFRTx struct {
	FeeRate sim.FeeRate
	InBlock bool
}

type SFRTxSlice

type SFRTxSlice []SFRTx

func (SFRTxSlice) ABKN

func (t SFRTxSlice) ABKN(sfr sim.FeeRate) (ak, an, bk, bn int64)

Calculate the Above/Below K/N values

func (SFRTxSlice) Len

func (t SFRTxSlice) Len() int

func (SFRTxSlice) Less

func (t SFRTxSlice) Less(i, j int) bool

func (SFRTxSlice) Sort

func (t SFRTxSlice) Sort()

func (SFRTxSlice) StrandingFeeRate

func (t SFRTxSlice) StrandingFeeRate(minrelaytxfee sim.FeeRate) (stat SFRStat)

func (SFRTxSlice) Swap

func (t SFRTxSlice) Swap(i, j int)

type Tx

type Tx struct {
	FeeRate sim.FeeRate `json:"feerate"`
	Size    sim.TxSize  `json:"size"`
	Time    int64       `json:"time"` // Unix time in seconds
	Type    int64       // Reserved; in the future we might want to model RBF txs
}

type TxDB

type TxDB interface {
	// Get returns all transactions with entry time within [start, end].
	// Txs are to be sorted by increasing time.
	Get(start, end int64) ([]Tx, error)
}

type TxSourceEstimator

type TxSourceEstimator func(t int64) (sim.TxSource, error)

Successive calls have non-decreasing t.

type TxWindowError

type TxWindowError struct {
	Window, MinWindow int64
}

func (TxWindowError) Error

func (err TxWindowError) Error() string

type UniTxSource

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

func NewUniTxSource

func NewUniTxSource(db TxDB, cfg UniTxSourceConfig, rng *rand.Rand) *UniTxSource

func (*UniTxSource) Estimate

func (s *UniTxSource) Estimate(currTime int64) (*sim.UniTxSource, error)

type UniTxSourceConfig

type UniTxSourceConfig struct {
	MinWindow int64 `yaml:"minwindow" json:"minwindow"`
	MaxWindow int64 `yaml:"maxwindow" json:"maxwindow"`
	Halflife  int64 `yaml:"halflife" json:"halflife"`
}

Jump to

Keyboard shortcuts

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