diff --git a/sweepbatcher/presigned.go b/sweepbatcher/presigned.go index 0e75240b..e7eed04e 100644 --- a/sweepbatcher/presigned.go +++ b/sweepbatcher/presigned.go @@ -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 // 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 signedFeeRate := chainfee.NewSatPerKWeight(fee, realWeight) diff --git a/sweepbatcher/sweep_batcher_presigned_test.go b/sweepbatcher/sweep_batcher_presigned_test.go index 245e1d38..606c5a88 100644 --- a/sweepbatcher/sweep_batcher_presigned_test.go +++ b/sweepbatcher/sweep_batcher_presigned_test.go @@ -1270,7 +1270,8 @@ func testPresigned_presigned_group_with_change(t *testing.T, } // 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, 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.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 ( outputSum int64 foundChange bool