diff --git a/mempool.go b/mempool.go index 376eb71e..380b1a54 100644 --- a/mempool.go +++ b/mempool.go @@ -370,16 +370,17 @@ func checkInputsStandard(tx *btcutil.Tx, txStore btcchain.TxStore) error { return nil } -// calcTxFee returns the minimum transaction fee required for the passed -// transaction. -func calcTxFee(size int) int64 { +// calcMinRequiredTxRelayFee returns the minimum transaction fee required for a +// transaction with the passed serialized size to be accepted into the memory +// pool and relayed. +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 // 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 + size/1000) * minTxRelayFee + minFee := (1 + serializedSize/1000) * minTxRelayFee // Set the minimum fee to the maximum possible value if the calculated // fee is not in the valid range for monetary amounts. @@ -387,26 +388,7 @@ func calcTxFee(size int) int64 { minFee = btcutil.MaxSatoshi } - return int64(minFee) -} - -// calcMinRelayFee retuns the minimum transaction fee required for the passed -// transaction to be accepted into the memory pool and relayed. -func calcMinTxRelayFee(size int) int64 { - // Most miners allow a free transaction area in blocks they mine to go - // alongside the area used for high-priority transactions as well as - // transactions with fees. A transaction size of up to 1000 bytes is - // considered safe to go into this section. Further, the minimum fee - // calculated below on its own would encourage several small - // transactions to avoid fees rather than one single larger transaction - // which is more desirable. Therefore, as long as the size of the - // transaction does not exceeed 1000 less than the reserved space for - // high-priority transactions, don't require a fee for it. - if size < (defaultBlockPrioritySize - 1000) { - return 0 - } - - return calcTxFee(size) + return minFee } // removeOrphan removes the passed orphan transaction from the orphan pool and @@ -895,18 +877,28 @@ func (mp *txMemPool) maybeAcceptTransaction(tx *btcutil.Tx, isOrphan *bool, isNe // reasonable number of ECDSA signature verifications. // Don't allow transactions with fees too low to get into a mined block. - serializedSize := tx.MsgTx().SerializeSize() - minRequiredFee := calcMinTxRelayFee(serializedSize) - if txFee < minRequiredFee { + // + // Most miners allow a free transaction area in blocks they mine to go + // alongside the area used for high-priority transactions as well as + // transactions with fees. A transaction size of up to 1000 bytes is + // considered safe to go into this section. Further, the minimum fee + // calculated below on its own would encourage several small + // transactions to avoid fees rather than one single larger transaction + // which is more desirable. Therefore, as long as the size of the + // transaction does not exceeed 1000 less than the reserved space for + // high-priority transactions, don't require a fee for it. + serializedSize := int64(tx.MsgTx().SerializeSize()) + minFee := calcMinRequiredTxRelayFee(serializedSize) + if serializedSize >= (defaultBlockPrioritySize-1000) && txFee < minFee { str := fmt.Sprintf("transaction %v has %d fees which is under "+ "the required amount of %d", txHash, txFee, - minRequiredFee) + minFee) return txRuleError(btcwire.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 < calcTxFee(serializedSize) { + if rateLimit && txFee < minFee { nowUnix := time.Now().Unix() // we decay passed data with an exponentially decaying ~10 // minutes window - matches bitcoind handling.