txrules

package
v0.0.0-...-51a2c09 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: ISC Imports: 10 Imported by: 8

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 hcd 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 hcutil.Amount = 1e5

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

Variables

View Source
var (
	ErrAmountNegative   = errors.New("transaction output amount is negative")
	ErrAmountExceedsMax = errors.New("transaction output amount exceeds maximum value")
	ErrOutputIsDust     = errors.New("transaction output is dust")
)

Transaction rule violations

Functions

func CheckOutput

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

CheckOutput performs simple consensus and policy tests on a transaction output.

func FeeForSerializeSize

func FeeForSerializeSize(relayFeePerKb hcutil.Amount, txSerializeSize int) hcutil.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 hcutil.Amount, scriptSize int, relayFeePerKb hcutil.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 hcutil.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 IsValidPoolFeeRate

func IsValidPoolFeeRate(feeRate float64) error

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

func StakePoolTicketFee

func StakePoolTicketFee(stakeDiff hcutil.Amount, relayFee hcutil.Amount,
	height int32, poolFee float64, params *chaincfg.Params) hcutil.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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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