Skip to content

Commit

Permalink
Reject free/low-fee transactions with insufficient priority.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dajohi committed Feb 25, 2015
1 parent 637fbca commit 833bb04
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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"`
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"`
Expand Down
18 changes: 18 additions & 0 deletions mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 833bb04

Please sign in to comment.