Update minimum fee calculations to match Core.
Calculate rate*fee first before dividing by 1000. Add more unit tests around the fee calculations.
This commit is contained in:
parent
7811770d31
commit
489ba8d31d
2 changed files with 46 additions and 11 deletions
13
policy.go
13
policy.go
|
@ -26,11 +26,14 @@ const (
|
|||
func calcMinRequiredTxRelayFee(serializedSize int64, minRelayTxFee btcutil.Amount) 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). minRelayTxFee 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 + serializedSize/1000) * int64(minRelayTxFee)
|
||||
// free transaction relay fee). minTxRelayFee is in Satoshi/kB so
|
||||
// multiply by serializedSize (which is in bytes) and divide by 1000 to get
|
||||
// minimum Satoshis.
|
||||
minFee := (serializedSize * int64(minRelayTxFee)) / 1000
|
||||
|
||||
if minFee == 0 && minRelayTxFee > 0 {
|
||||
minFee = int64(minRelayTxFee)
|
||||
}
|
||||
|
||||
// Set the minimum fee to the maximum possible value if the calculated
|
||||
// fee is not in the valid range for monetary amounts.
|
||||
|
|
|
@ -22,22 +22,24 @@ func TestCalcMinRequiredTxRelayFee(t *testing.T) {
|
|||
want int64 // Expected fee.
|
||||
}{
|
||||
{
|
||||
"zero value with default minimum relay fee",
|
||||
0,
|
||||
defaultMinRelayTxFee,
|
||||
int64(defaultMinRelayTxFee),
|
||||
// Ensure combination of size and fee that are less than 1000
|
||||
// produce a non-zero fee.
|
||||
"250 bytes with relay fee of 3",
|
||||
250,
|
||||
3,
|
||||
3,
|
||||
},
|
||||
{
|
||||
"100 bytes with default minimum relay fee",
|
||||
100,
|
||||
defaultMinRelayTxFee,
|
||||
int64(defaultMinRelayTxFee),
|
||||
100,
|
||||
},
|
||||
{
|
||||
"max standard tx size with default minimum relay fee",
|
||||
maxStandardTxSize,
|
||||
defaultMinRelayTxFee,
|
||||
101000,
|
||||
100000,
|
||||
},
|
||||
{
|
||||
"max standard tx size with max satoshi relay fee",
|
||||
|
@ -45,6 +47,36 @@ func TestCalcMinRequiredTxRelayFee(t *testing.T) {
|
|||
btcutil.MaxSatoshi,
|
||||
btcutil.MaxSatoshi,
|
||||
},
|
||||
{
|
||||
"1500 bytes with 5000 relay fee",
|
||||
1500,
|
||||
5000,
|
||||
7500,
|
||||
},
|
||||
{
|
||||
"1500 bytes with 3000 relay fee",
|
||||
1500,
|
||||
3000,
|
||||
4500,
|
||||
},
|
||||
{
|
||||
"782 bytes with 5000 relay fee",
|
||||
782,
|
||||
5000,
|
||||
3910,
|
||||
},
|
||||
{
|
||||
"782 bytes with 3000 relay fee",
|
||||
782,
|
||||
3000,
|
||||
2346,
|
||||
},
|
||||
{
|
||||
"782 bytes with 2550 relay fee",
|
||||
782,
|
||||
2550,
|
||||
1994,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
|
Loading…
Reference in a new issue