From 833bb04775cc123cc0221b94b33588cd68e61736 Mon Sep 17 00:00:00 2001 From: David Hill Date: Mon, 23 Feb 2015 10:28:31 -0500 Subject: [PATCH] Reject free/low-fee transactions with insufficient priority. By default, have the mempool reject free and low-fee transactions that have insufficient priority to be mined in the next block. Addtionally, add a new configuration option, -norelaypriority, to disable the check. --- config.go | 1 + mempool.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/config.go b/config.go index 86811b8f..6c8b7647 100644 --- a/config.go +++ b/config.go @@ -103,6 +103,7 @@ type config struct { 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"` 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"` Generate bool `long:"generate" description:"Generate (mine) bitcoins using the CPU"` MiningAddrs []string `long:"miningaddr" description:"Add the specified payment address to the list of addresses to use for generated blocks -- At least one address is required if the generate option is set"` BlockMinSize uint32 `long:"blockminsize" description:"Mininum block size in bytes to be used when creating a block"` diff --git a/mempool.go b/mempool.go index a59528ea..6da0293c 100644 --- a/mempool.go +++ b/mempool.go @@ -1179,6 +1179,24 @@ func (mp *txMemPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit boo return nil, txRuleError(wire.RejectInsufficientFee, str) } + // Require that free transactions have sufficient priority to be mined + // in the next block. + if !cfg.NoRelayPriority && txFee < minFee { + txD := &TxDesc{ + Tx: tx, + Added: time.Now(), + Height: curHeight, + Fee: txFee, + } + currentPriority := txD.CurrentPriority(txStore, nextBlockHeight) + if currentPriority <= minHighPriority { + str := fmt.Sprintf("transaction %v has insufficient "+ + "priority (%g <= %g)", txHash, + currentPriority, minHighPriority) + return nil, txRuleError(wire.RejectInsufficientFee, str) + } + } + // Free-to-relay transactions are rate limited here to prevent // penny-flooding with tiny transactions as a form of attack. if rateLimit && txFee < minFee {