From a56db22e9be1c5436c952dbee1af582f5b7c8976 Mon Sep 17 00:00:00 2001 From: David Hill Date: Mon, 19 Oct 2015 16:21:31 -0400 Subject: [PATCH] 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. --- config.go | 13 +++++++++++++ doc.go | 2 ++ mempool.go | 18 +++++++++--------- mining.go | 5 +++-- rpcserver.go | 2 +- sample-btcd.conf | 3 +++ 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/config.go b/config.go index 53d56693..dd758937 100644 --- a/config.go +++ b/config.go @@ -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 =,=,... 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 { diff --git a/doc.go b/doc.go index 90038461..03ab1c58 100644 --- a/doc.go +++ b/doc.go @@ -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) diff --git a/mempool.go b/mempool.go index bd43c72a..69171745 100644 --- a/mempool.go +++ b/mempool.go @@ -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. diff --git a/mining.go b/mining.go index 384da0a6..e222fb76 100644 --- a/mining.go +++ b/mining.go @@ -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 diff --git a/rpcserver.go b/rpcserver.go index 4cd33368..711e6f25 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -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 diff --git a/sample-btcd.conf b/sample-btcd.conf index 1febab98..df2e6879 100644 --- a/sample-btcd.conf +++ b/sample-btcd.conf @@ -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