config: New option --minrelaytxfee

--minrelaytxfee allows the user to specify the minimum transaction
fee in BTC/kB in which the fee is considered a non-zero fee.
This commit is contained in:
David Hill 2015-10-19 16:21:31 -04:00
parent 5a9bac9668
commit a56db22e9b
6 changed files with 31 additions and 12 deletions

View file

@ -106,6 +106,7 @@ type config struct {
CPUProfile string `long:"cpuprofile" description:"Write CPU profile to the specified file"`
DebugLevel string `short:"d" long:"debuglevel" description:"Logging level for all subsystems {trace, debug, info, warn, error, critical} -- You may also specify <subsystem>=<level>,<subsystem2>=<level>,... to set the log level for individual subsystems -- Use show to list available subsystems"`
Upnp bool `long:"upnp" description:"Use UPnP to map our listening port outside of NAT"`
MinRelayTxFee float64 `long:"minrelaytxfee" description:"The minimum transaction fee in BTC/kB to be considered a non-zero fee."`
FreeTxRelayLimit float64 `long:"limitfreerelay" description:"Limit relay of transactions with no transaction fee to the given amount in thousands of bytes per minute"`
NoRelayPriority bool `long:"norelaypriority" description:"Do not require free or low-fee transactions to have high priority for relaying"`
MaxOrphanTxs int `long:"maxorphantx" description:"Max number of orphan transactions to keep in memory"`
@ -124,6 +125,7 @@ type config struct {
oniondial func(string, string) (net.Conn, error)
dial func(string, string) (net.Conn, error)
miningAddrs []btcutil.Address
minRelayTxFee btcutil.Amount
}
// serviceOptions defines the configuration options for btcd as a service on
@ -320,6 +322,7 @@ func loadConfig() (*config, []string, error) {
DbType: defaultDbType,
RPCKey: defaultRPCKeyFile,
RPCCert: defaultRPCCertFile,
MinRelayTxFee: defaultMinRelayTxFee.ToBTC(),
FreeTxRelayLimit: defaultFreeTxRelayLimit,
BlockMinSize: defaultBlockMinSize,
BlockMaxSize: defaultBlockMaxSize,
@ -594,6 +597,16 @@ func loadConfig() (*config, []string, error) {
}
}
// Validate the the minrelaytxfee.
cfg.minRelayTxFee, err = btcutil.NewAmount(cfg.MinRelayTxFee)
if err != nil {
str := "%s: invalid minrelaytxfee: %v"
err := fmt.Errorf(str, funcName, err)
fmt.Fprintln(os.Stderr, err)
fmt.Fprintln(os.Stderr, usageMessage)
return nil, nil, err
}
// Limit the max block size to a sane value.
if cfg.BlockMaxSize < blockMaxSizeMin || cfg.BlockMaxSize >
blockMaxSizeMax {

2
doc.go
View file

@ -81,6 +81,8 @@ Application Options:
the log level for individual subsystems -- Use show
to list available subsystems (info)
--upnp Use UPnP to map our listening port outside of NAT
--minrelaytxfee= The minimum transaction fee in BTC/kB to be
considered a non-zero fee.
--limitfreerelay= Limit relay of transactions with no transaction fee
to the given amount in thousands of bytes per
minute (15)

View file

@ -68,12 +68,12 @@ const (
// considered standard.
maxStandardMultiSigKeys = 3
// minTxRelayFee is the minimum fee in satoshi that is required for a
// transaction to be treated as free for relay and mining purposes. It
// is also used to help determine if a transaction is considered dust
// and as a base for calculating minimum required fees for larger
// transactions. This value is in Satoshi/1000 bytes.
minTxRelayFee = 1000
// defaultMinRelayTxFee is the minimum fee in satoshi that is required
// for a transaction to be treated as free for relay and mining
// purposes. It is also used to help determine if a transaction is
// considered dust and as a base for calculating minimum required fees
// for larger transactions. This value is in Satoshi/1000 bytes.
defaultMinRelayTxFee = btcutil.Amount(1000)
)
// TxDesc is a descriptor containing a transaction in the mempool and the
@ -168,7 +168,7 @@ func isDust(txOut *wire.TxOut) bool {
//
// The following is equivalent to (value/totalSize) * (1/3) * 1000
// without needing to do floating point math.
return txOut.Value*1000/(3*int64(totalSize)) < minTxRelayFee
return txOut.Value*1000/(3*int64(totalSize)) < int64(cfg.minRelayTxFee)
}
// checkPkScriptStandard performs a series of checks on a transaction ouput
@ -377,11 +377,11 @@ func checkInputsStandard(tx *btcutil.Tx, txStore blockchain.TxStore) error {
func calcMinRequiredTxRelayFee(serializedSize int64) int64 {
// Calculate the minimum fee for a transaction to be allowed into the
// mempool and relayed by scaling the base fee (which is the minimum
// free transaction relay fee). minTxRelayFee is in Satoshi/KB, so
// free transaction relay fee). cfg.minRelayTxFee is in Satoshi/KB, so
// divide the transaction size by 1000 to convert to kilobytes. Also,
// integer division is used so fees only increase on full kilobyte
// boundaries.
minFee := (1 + serializedSize/1000) * minTxRelayFee
minFee := (1 + serializedSize/1000) * int64(cfg.minRelayTxFee)
// Set the minimum fee to the maximum possible value if the calculated
// fee is not in the valid range for monetary amounts.

View file

@ -604,13 +604,14 @@ mempoolLoop:
// Skip free transactions once the block is larger than the
// minimum block size.
if sortedByFee && prioItem.feePerKB < minTxRelayFee &&
if sortedByFee &&
prioItem.feePerKB < float64(cfg.minRelayTxFee) &&
blockPlusTxSize >= cfg.BlockMinSize {
minrLog.Tracef("Skipping tx %s with feePerKB %.2f "+
"< minTxRelayFee %d and block size %d >= "+
"minBlockSize %d", tx.Sha(), prioItem.feePerKB,
minTxRelayFee, blockPlusTxSize,
cfg.minRelayTxFee, blockPlusTxSize,
cfg.BlockMinSize)
logSkippedDeps(tx, deps)
continue

View file

@ -2103,7 +2103,7 @@ func handleGetInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (in
Proxy: cfg.Proxy,
Difficulty: getDifficultyRatio(blkHeader.Bits),
TestNet: cfg.TestNet3,
RelayFee: float64(minTxRelayFee) / btcutil.SatoshiPerBitcoin,
RelayFee: cfg.minRelayTxFee.ToBTC(),
}
return ret, nil

View file

@ -214,6 +214,9 @@
; Mempool Settings - The following options
; ------------------------------------------------------------------------------
; Set the minimum transaction fee to be considered a non-zero fee,
; minrelaytxfee=0.00001
; Rate-limit free transactions to the value 15 * 1000 bytes per
; minute.
; limitfreerelay=15