diff --git a/bchain/coins/btc/mempoolspacemedian.go b/bchain/coins/btc/mempoolspacemedian.go index b00ea5ce..8341ed99 100644 --- a/bchain/coins/btc/mempoolspacemedian.go +++ b/bchain/coins/btc/mempoolspacemedian.go @@ -2,6 +2,7 @@ package btc import ( "encoding/json" + "math" "net/http" "strconv" "time" @@ -108,9 +109,13 @@ func (p *mempoolSpaceMedianFeeProvider) mempoolSpaceMedianFeeProcessData(data *[ // But even storing thousands of elements in []alternativeFeeProviderFee should not make a big performance overhead // Depends on Suite requirements + // We want to convert the median fee to 3 significant digits + medianFee := common.RoundToSignificantDigits(block.MedianFee, 3) + feePerKB := int(math.Round(medianFee * 1000)) // convert sat/vB to sat/KB + p.fees = append(p.fees, alternativeFeeProviderFee{ - blocks: i + 1, // simple mapping: index 0 -> 1 block, etc. - feePerKB: int(block.MedianFee * 1000), // convert sat/vB to sat/KB + blocks: i + 1, // simple mapping: index 0 -> 1 block, etc. + feePerKB: feePerKB, }) } diff --git a/bchain/coins/btc/mempoolspacemedian_test.go b/bchain/coins/btc/mempoolspacemedian_test.go index fc529229..ca08f6fe 100644 --- a/bchain/coins/btc/mempoolspacemedian_test.go +++ b/bchain/coins/btc/mempoolspacemedian_test.go @@ -1,3 +1,5 @@ +//go:build unittest + package btc import ( @@ -25,26 +27,26 @@ func Test_mempoolSpaceMedianFeeProvider(t *testing.T) { blocks int want big.Int }{ - {0, *big.NewInt(5123)}, - {1, *big.NewInt(5123)}, - {2, *big.NewInt(4456)}, - {3, *big.NewInt(3789)}, - {4, *big.NewInt(2012)}, - {5, *big.NewInt(1345)}, - {6, *big.NewInt(1345)}, - {7, *big.NewInt(1345)}, - {10, *big.NewInt(1345)}, - {18, *big.NewInt(1345)}, - {19, *big.NewInt(1345)}, - {36, *big.NewInt(1345)}, - {37, *big.NewInt(1345)}, - {100, *big.NewInt(1345)}, - {101, *big.NewInt(1345)}, - {200, *big.NewInt(1345)}, - {201, *big.NewInt(1345)}, - {500, *big.NewInt(1345)}, - {501, *big.NewInt(1345)}, - {5000000, *big.NewInt(1345)}, + {0, *big.NewInt(5120)}, + {1, *big.NewInt(5120)}, + {2, *big.NewInt(4460)}, + {3, *big.NewInt(3790)}, + {4, *big.NewInt(2010)}, + {5, *big.NewInt(1350)}, + {6, *big.NewInt(1350)}, + {7, *big.NewInt(1350)}, + {10, *big.NewInt(1350)}, + {18, *big.NewInt(1350)}, + {19, *big.NewInt(1350)}, + {36, *big.NewInt(1350)}, + {37, *big.NewInt(1350)}, + {100, *big.NewInt(1350)}, + {101, *big.NewInt(1350)}, + {200, *big.NewInt(1350)}, + {201, *big.NewInt(1350)}, + {500, *big.NewInt(1350)}, + {501, *big.NewInt(1350)}, + {5000000, *big.NewInt(1350)}, } for _, tt := range tests { t.Run(strconv.Itoa(tt.blocks), func(t *testing.T) {