Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use same fee policies across all networks. #160

Merged
merged 1 commit into from
May 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 7 additions & 45 deletions mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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".
Expand Down Expand Up @@ -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
Expand All @@ -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 "+
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
11 changes: 1 addition & 10 deletions mining.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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) {

Expand Down
10 changes: 5 additions & 5 deletions policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
{
Expand Down
11 changes: 1 addition & 10 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down