Merge pull request #9989 from hieblmi/round-up
chainfee: method to round up the fee for a given transaction weight
This commit is contained in:
3 files changed
+24
No files matched your search
@@ -33,6 +33,10 @@
|
|||||||
|
|
||||||
## Functional Enhancements
|
## Functional Enhancements
|
||||||
|
|
||||||
|
- [Adds](https://github.com/lightningnetwork/lnd/pull/9989) a method
|
||||||
|
`FeeForWeightRoundUp` to the `chainfee` package which rounds up a calculated
|
||||||
|
fee value to the nearest satoshi.
|
||||||
|
|
||||||
## RPC Additions
|
## RPC Additions
|
||||||
|
|
||||||
## lncli Additions
|
## lncli Additions
|
||||||
@@ -78,4 +82,5 @@ much more slowly.
|
|||||||
## Tooling and Documentation
|
## Tooling and Documentation
|
||||||
|
|
||||||
# Contributors (Alphabetical Order)
|
# Contributors (Alphabetical Order)
|
||||||
|
* hieblmi
|
||||||
* Yong Yu
|
* Yong Yu
|
||||||
@@ -71,6 +71,14 @@ func (s SatPerKWeight) FeeForWeight(wu lntypes.WeightUnit) btcutil.Amount {
|
|||||||
return btcutil.Amount(s) * btcutil.Amount(wu) / 1000
|
return btcutil.Amount(s) * btcutil.Amount(wu) / 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FeeForWeightRoundUp calculates the fee resulting from this fee rate and the
|
||||||
|
// given weight in weight units (wu), rounding up to the nearest satoshi.
|
||||||
|
func (s SatPerKWeight) FeeForWeightRoundUp(
|
||||||
|
wu lntypes.WeightUnit) btcutil.Amount {
|
||||||
|
|
||||||
|
return (btcutil.Amount(s)*btcutil.Amount(wu) + 999) / 1000
|
||||||
|
}
|
||||||
|
|
||||||
// FeeForVByte calculates the fee resulting from this fee rate and the given
|
// FeeForVByte calculates the fee resulting from this fee rate and the given
|
||||||
// size in vbytes (vb).
|
// size in vbytes (vb).
|
||||||
func (s SatPerKWeight) FeeForVByte(vb lntypes.VByte) btcutil.Amount {
|
func (s SatPerKWeight) FeeForVByte(vb lntypes.VByte) btcutil.Amount {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package chainfee
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,3 +21,13 @@ func TestSatPerVByteConversion(t *testing.T) {
|
|||||||
// 1 sat/vb should be equal to 250 sat/kw.
|
// 1 sat/vb should be equal to 250 sat/kw.
|
||||||
require.Equal(t, SatPerKWeight(250), rate.FeePerKWeight())
|
require.Equal(t, SatPerKWeight(250), rate.FeePerKWeight())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestFeeForWeightRoundUp checks that the FeeForWeightRoundUp method correctly
|
||||||
|
// rounds up the fee for a given weight.
|
||||||
|
func TestFeeForWeightRoundUp(t *testing.T) {
|
||||||
|
feeRate := SatPerVByte(1).FeePerKWeight()
|
||||||
|
txWeight := lntypes.WeightUnit(674) // 674 weight units is 168.5 vb.
|
||||||
|
|
||||||
|
require.EqualValues(t, 168, feeRate.FeeForWeight(txWeight))
|
||||||
|
require.EqualValues(t, 169, feeRate.FeeForWeightRoundUp(txWeight))
|
||||||
|
}
|
||||||
Reference in new issue
Block a user