From fcc5d412c4ccb592bb84cd5d15bac0f5a667f700 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Mon, 19 Aug 2024 12:28:39 -0300 Subject: [PATCH] . fix for "sweepbatcher: add mixed batches option" Real SignOutputRaw requires prevOuts for all inputs, not only the ones being signed. This commit will be squashed. --- sweepbatcher/sweep_batch.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/sweepbatcher/sweep_batch.go b/sweepbatcher/sweep_batch.go index 922b3ea64..b85e9cb62 100644 --- a/sweepbatcher/sweep_batch.go +++ b/sweepbatcher/sweep_batch.go @@ -1330,9 +1330,17 @@ func (b *batch) publishMixedBatch(ctx context.Context) (btcutil.Amount, error, // Now sign the remaining sweeps' inputs non-cooperatively. // For that, first collect sign descriptors for the signatures. + // Also collect prevOuts for all inputs. signDescs := make([]*lndclient.SignDescriptor, 0, nonCoopInputs) - prevOutsList := make([]*wire.TxOut, 0, nonCoopInputs) + prevOutsList := make([]*wire.TxOut, 0, len(sweeps)) for i, sweep := range sweeps { + // Create and store the previous outpoint for this sweep. + prevOut := &wire.TxOut{ + Value: int64(sweep.value), + PkScript: sweep.htlc.PkScript, + } + prevOutsList = append(prevOutsList, prevOut) + // Skip cooperative sweeps. if !sweep.nonCoopHint && !sweep.coopFailed { continue @@ -1346,13 +1354,6 @@ func (b *batch) publishMixedBatch(ctx context.Context) (btcutil.Amount, error, err), false } - // Create and store the previous outpoint for this sweep. - prevOut := &wire.TxOut{ - Value: int64(sweep.value), - PkScript: sweep.htlc.PkScript, - } - prevOutsList = append(prevOutsList, prevOut) - // Create and store the sign descriptor for this sweep. signDesc := lndclient.SignDescriptor{ WitnessScript: sweep.htlc.SuccessScript(), @@ -1377,10 +1378,10 @@ func (b *batch) publishMixedBatch(ctx context.Context) (btcutil.Amount, error, return 0, fmt.Errorf("unexpected size of signDescs: %d != %d", len(signDescs), nonCoopInputs), false } - if len(prevOutsList) != nonCoopInputs { + if len(prevOutsList) != len(sweeps) { // This must not happen by construction. return 0, fmt.Errorf("unexpected size of prevOutsList: "+ - "%d != %d", len(prevOutsList), nonCoopInputs), false + "%d != %d", len(prevOutsList), len(sweeps)), false } var rawSigs [][]byte