mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
sweepbatcher: fix fee rate calculation (publish)
We forgot to account for change outputs when checking the feerate of signed transaction. The bug resulted in fee rate overestimation in the log message.
This commit is contained in:
parent
a5871d6f3e
commit
1f15c604ac
2 changed files with 14 additions and 2 deletions
|
|
@ -506,7 +506,10 @@ func (b *batch) publishPresigned(ctx context.Context) (btcutil.Amount, error,
|
||||||
|
|
||||||
// Find actual fee rate of the signed transaction. It may differ from
|
// Find actual fee rate of the signed transaction. It may differ from
|
||||||
// the desired fee rate, because SignTx may return a presigned tx.
|
// the desired fee rate, because SignTx may return a presigned tx.
|
||||||
output := btcutil.Amount(tx.TxOut[0].Value)
|
var output btcutil.Amount
|
||||||
|
for _, txOut := range tx.TxOut {
|
||||||
|
output += btcutil.Amount(txOut.Value)
|
||||||
|
}
|
||||||
fee = batchAmt - output
|
fee = batchAmt - output
|
||||||
signedFeeRate := chainfee.NewSatPerKWeight(fee, realWeight)
|
signedFeeRate := chainfee.NewSatPerKWeight(fee, realWeight)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1270,7 +1270,8 @@ func testPresigned_presigned_group_with_change(t *testing.T,
|
||||||
}
|
}
|
||||||
|
|
||||||
// testPresigned_fee_portion_with_change ensures that the fee portion reported
|
// testPresigned_fee_portion_with_change ensures that the fee portion reported
|
||||||
// to clients accounts for change outputs in the presigned transaction.
|
// to clients accounts for change outputs in the presigned transaction. It also
|
||||||
|
// is a regression test for feerate overestimation when tx is published.
|
||||||
func testPresigned_fee_portion_with_change(t *testing.T,
|
func testPresigned_fee_portion_with_change(t *testing.T,
|
||||||
batcherStore testBatcherStore) {
|
batcherStore testBatcherStore) {
|
||||||
|
|
||||||
|
|
@ -1350,6 +1351,14 @@ func testPresigned_fee_portion_with_change(t *testing.T,
|
||||||
require.Len(t, tx.TxIn, 1)
|
require.Len(t, tx.TxIn, 1)
|
||||||
require.Len(t, tx.TxOut, 2)
|
require.Len(t, tx.TxOut, 2)
|
||||||
|
|
||||||
|
// Mine a blocks to trigger republishing.
|
||||||
|
require.NoError(t, lnd.NotifyHeight(601))
|
||||||
|
|
||||||
|
// Make sure it is the same tx.
|
||||||
|
tx2 := <-lnd.TxPublishChannel
|
||||||
|
require.Len(t, tx2.TxOut, len(tx.TxOut))
|
||||||
|
require.Equal(t, tx.TxOut[0].Value, tx2.TxOut[0].Value)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
outputSum int64
|
outputSum int64
|
||||||
foundChange bool
|
foundChange bool
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue