From 335093e60f30e91e108def76737830fddc05132a Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Fri, 6 May 2016 17:35:32 -0400 Subject: [PATCH] Use same fee policies across all networks. Fixes #151. --- mempool.go | 52 +++++++------------------------------------------- mining.go | 11 +---------- policy_test.go | 10 +++++----- rpcserver.go | 11 +---------- 4 files changed, 14 insertions(+), 70 deletions(-) diff --git a/mempool.go b/mempool.go index bd6be14001..7b517c0f7a 100644 --- a/mempool.go +++ b/mempool.go @@ -18,7 +18,6 @@ import ( "github.com/decred/dcrd/blockchain" "github.com/decred/dcrd/blockchain/stake" - "github.com/decred/dcrd/chaincfg" "github.com/decred/dcrd/chaincfg/chainhash" "github.com/decred/dcrd/database" "github.com/decred/dcrd/txscript" @@ -73,24 +72,17 @@ const ( // in a multi-signature transaction output script for it to be // considered standard. maxStandardMultiSigKeys = 3 - // minTxRelayFeeMainNet is the minimum fee in atoms that is required for a + + // minTxRelayFee is the minimum fee in atoms 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 per KB for larger // transactions. This value is in Atom/1000 bytes. - minTxRelayFeeMainNet = 1e6 - - // minTxRelayFeeTestNet is the minimum relay fee for the Test and Simulation - // networks. - minTxRelayFeeTestNet = 1e3 + minTxRelayFee = 1e6 // minTicketFeeMainNet is the minimum fee per KB in atoms that is // required for a ticket to enter the mempool on MainNet. - minTicketFeeMainNet = 1e6 - - // minTicketFeeTestNet is the minimum fee per KB in atoms that is - // required for a ticekt to enter the mempool on TestNet or SimNet. - minTicketFeeTestNet = 1e3 + minTicketFee = 1e6 // maxRelayFeeMultiplier is the factor that we disallow fees / kb above // the minimum tx fee. @@ -481,16 +473,6 @@ func (mp *txMemPool) checkTransactionStandard(tx *dcrutil.Tx, txType stake.TxTyp return txRuleError(rejectCode, str) } - var minTxRelayFee dcrutil.Amount - switch { - case mp.server.chainParams == &chaincfg.MainNetParams: - minTxRelayFee = minTxRelayFeeMainNet - case mp.server.chainParams == &chaincfg.MainNetParams: - minTxRelayFee = minTxRelayFeeTestNet - default: - minTxRelayFee = minTxRelayFeeTestNet - } - // Accumulate the number of outputs which only carry data. For // all other script types, ensure the output value is not // "dust". @@ -1411,16 +1393,6 @@ func (mp *txMemPool) maybeAcceptTransaction(tx *dcrutil.Tx, isNew, return nil, txRuleError(wire.RejectNonstandard, str) } - var minRelayTxFee dcrutil.Amount - switch { - case mp.server.chainParams == &chaincfg.MainNetParams: - minRelayTxFee = minTxRelayFeeMainNet - case mp.server.chainParams == &chaincfg.TestNetParams: - minRelayTxFee = minTxRelayFeeTestNet - default: - minRelayTxFee = minTxRelayFeeTestNet - } - // Don't allow transactions with fees too low to get into a mined block. // // Most miners allow a free transaction area in blocks they mine to go @@ -1434,7 +1406,7 @@ func (mp *txMemPool) maybeAcceptTransaction(tx *dcrutil.Tx, isNew, // high-priority transactions, don't require a fee for it. // This applies to non-stake transactions only. serializedSize := int64(tx.MsgTx().SerializeSize()) - minFee := calcMinRequiredTxRelayFee(serializedSize, int64(minRelayTxFee)) + minFee := calcMinRequiredTxRelayFee(serializedSize, minTxRelayFee) if txType == stake.TxTypeRegular { // Non-stake only if serializedSize >= (defaultBlockPrioritySize-1000) && txFee < minFee { str := fmt.Sprintf("transaction %v has %v fees which is under "+ @@ -1496,17 +1468,7 @@ func (mp *txMemPool) maybeAcceptTransaction(tx *dcrutil.Tx, isNew, // difficulty and generally a window in which they expire. // // This applies to tickets transactions only. - var ticketFeeThreshold int64 - switch { - case mp.server.chainParams == &chaincfg.MainNetParams: - ticketFeeThreshold = minTicketFeeMainNet - case mp.server.chainParams == &chaincfg.TestNetParams: - ticketFeeThreshold = minTicketFeeTestNet - default: - ticketFeeThreshold = minTicketFeeTestNet - } - - minTicketFee := calcMinRequiredTxRelayFee(serializedSize, ticketFeeThreshold) + minTicketFee := calcMinRequiredTxRelayFee(serializedSize, minTicketFee) if (txFee < minTicketFee) && txType == stake.TxTypeSStx { str := fmt.Sprintf("transaction %v has a %v fee which "+ "is under the required threshold amount of %d", txHash, txFee, @@ -1520,7 +1482,7 @@ func (mp *txMemPool) maybeAcceptTransaction(tx *dcrutil.Tx, isNew, // then they can AllowHighFees = true if !allowHighFees { maxFee := calcMinRequiredTxRelayFee(serializedSize*maxRelayFeeMultiplier, - int64(minRelayTxFee)) + minTxRelayFee) if txFee > maxFee { err = fmt.Errorf("transaction %v has %v fee which is above the "+ "allowHighFee check threshold amount of %v", txHash, diff --git a/mining.go b/mining.go index 00222e0e40..1bbe0cbaf3 100644 --- a/mining.go +++ b/mining.go @@ -1412,15 +1412,6 @@ mempoolLoop: // release should fix it. TODO blockSigOps := int64(0) totalFees := int64(0) - var minTxRelayFee dcrutil.Amount - switch { - case mempool.server.chainParams == &chaincfg.MainNetParams: - minTxRelayFee = minTxRelayFeeMainNet - case mempool.server.chainParams == &chaincfg.MainNetParams: - minTxRelayFee = minTxRelayFeeTestNet - default: - minTxRelayFee = minTxRelayFeeTestNet - } numSStx := 0 @@ -1540,7 +1531,7 @@ mempoolLoop: // Skip free transactions once the block is larger than the // minimum block size, except for stake transactions. - if sortedByFee && (prioItem.feePerKB < float64(minTxRelayFee)) && + if sortedByFee && (prioItem.feePerKB < minTxRelayFee) && (tx.Tree() != dcrutil.TxTreeStake) && (blockPlusTxSize >= cfg.BlockMinSize) { diff --git a/policy_test.go b/policy_test.go index f622a134b3..10595433da 100644 --- a/policy_test.go +++ b/policy_test.go @@ -25,19 +25,19 @@ func TestCalcMinRequiredTxRelayFee(t *testing.T) { { "zero value with default minimum relay fee", 0, - minTxRelayFeeMainNet, - int64(minTxRelayFeeMainNet), + minTxRelayFee, + int64(minTxRelayFee), }, { "1000 bytes with default minimum relay fee", 1000, - minTxRelayFeeMainNet, - int64(minTxRelayFeeMainNet), + minTxRelayFee, + int64(minTxRelayFee), }, { "max standard tx size with default minimum relay fee", maxStandardTxSize, - minTxRelayFeeMainNet, + minTxRelayFee, 100000000, }, { diff --git a/rpcserver.go b/rpcserver.go index 1caf288996..88514dc2de 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -3507,15 +3507,6 @@ func handleGetInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (in context := "Failed to get block" return nil, internalRPCError(err.Error(), context) } - var minTxRelayFee dcrutil.Amount - switch { - case s.server.chainParams == &chaincfg.MainNetParams: - minTxRelayFee = minTxRelayFeeMainNet - case s.server.chainParams == &chaincfg.MainNetParams: - minTxRelayFee = minTxRelayFeeTestNet - default: - minTxRelayFee = minTxRelayFeeTestNet - } ret := &dcrjson.InfoChainResult{ Version: int32(1000000*appMajor + 10000*appMinor + 100*appPatch), @@ -3526,7 +3517,7 @@ func handleGetInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (in Proxy: cfg.Proxy, Difficulty: getDifficultyRatio(blkHeader.Bits), TestNet: cfg.TestNet, - RelayFee: float64(minTxRelayFee) / dcrutil.AtomsPerCoin, + RelayFee: minTxRelayFee / dcrutil.AtomsPerCoin, } return ret, nil