txrules

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: May 9, 2022 License: ISC Imports: 10 Imported by: 6

Documentation

Overview

Package txrules provides functions that are help establish whether or not a transaction abides by non-consensus rules for things like the daemon and stake pool.

Dust and Fee Per KB Calculation

Please refer to mempool.go in dcrd for more information about the importance of these function.

Pool Fees

The pool fee is calculated from the percentage given according to the following formula:

       ps(v+z)
f = --------------
         s+v

where f = absolute pool fee as an amount
      p = proportion (e.g. 0.5000 = 50.00%)
      s = subsidy (adjusted two difficulty periods into the future)
      v = price of the ticket
      z = the ticket fees

This can be derived from the known relation that
ps = (f * (v+z)/(v+s)) obtained from the knowledge
that the outputs of the vote are the amounts
of the stake ticket plus subsidy (v+s) scaled by
the proportional input of the stake pool fee
f/(v+z).

f is then adjusted for the fact that at least one subsidy reduction is likely to occur before it can vote on a block.

Index

Constants

View Source
const DefaultRelayFeePerKb dcrutil.Amount = 1e4

DefaultRelayFeePerKb is the default minimum relay fee policy for a mempool.

Variables

This section is empty.

Functions

func CheckOutput

func CheckOutput(output *wire.TxOut, relayFeePerKb dcrutil.Amount) error

CheckOutput performs simple consensus and policy tests on a transaction output. Returns with errors.Invalid if output violates consensus rules, and errors.Policy if the output violates a non-consensus policy.

func FeeForSerializeSize

func FeeForSerializeSize(relayFeePerKb dcrutil.Amount, txSerializeSize int) dcrutil.Amount

FeeForSerializeSize calculates the required fee for a transaction of some arbitrary size given a mempool's relay fee policy.

func IsDustAmount

func IsDustAmount(amount dcrutil.Amount, scriptSize int, relayFeePerKb dcrutil.Amount) bool

IsDustAmount determines whether a transaction output value and script length would cause the output to be considered dust. Transactions with dust outputs are not standard and are rejected by mempools with default policies.

func IsDustOutput

func IsDustOutput(output *wire.TxOut, relayFeePerKb dcrutil.Amount) bool

IsDustOutput determines whether a transaction output is considered dust. Transactions with dust outputs are not standard and are rejected by mempools with default policies.

func PaysHighFees

func PaysHighFees(totalInput dcrutil.Amount, tx *wire.MsgTx) bool

PaysHighFees checks whether the signed transaction pays insanely high fees. Transactons are defined to have a high fee if they have pay a fee rate that is 1000 time higher than the default fee.

func StakePoolTicketFee

func StakePoolTicketFee(stakeDiff dcrutil.Amount, relayFee dcrutil.Amount,
	height int32, poolFee float64, params *chaincfg.Params,
	dcp0010Active bool) dcrutil.Amount

StakePoolTicketFee determines the stake pool ticket fee for a given ticket from the passed percentage. Pool fee as a percentage is truncated from 0.01% to 100.00%. This all must be done with integers, so bear with the big.Int usage below.

See the included doc.go of this package for more information about the calculation of this fee.

func StakeSubScriptType

func StakeSubScriptType(scriptType stdscript.ScriptType) (stdscript.ScriptType, bool)

StakeSubScriptType potentially transforms the provided script type by converting the various stake-specific script types to their associated sub type. It will be returned unmodified otherwise.

func TxPaysHighFees

func TxPaysHighFees(tx *wire.MsgTx) (bool, error)

TxPaysHighFees checks whether the signed transaction pays insanely high fees. Transactons are defined to have a high fee if they have pay a fee rate that is 1000 time higher than the default fee. Total transaction input value is determined by summing the ValueIn fields of each input, and an error is returned if any input values were the null value.

func ValidPoolFeeRate

func ValidPoolFeeRate(feeRate float64) bool

ValidPoolFeeRate tests to see if a pool fee is a valid percentage from 0.01% to 100.00%.

Types

This section is empty.

Jump to

Keyboard shortcuts

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