Skip to content

Commit fafe604

Browse files
committed
tapchannel: only update vOut internal keys if we have an ExtraTxOut
If the sweeper is broadcasting _just_ a second level txn with an asset, then we won't have an extra change output. This transaction also already has its internal key bound.
1 parent 74e83ea commit fafe604

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

tapchannel/aux_sweeper.go

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,33 +2174,46 @@ func (a *AuxSweeper) registerAndBroadcastSweep(req *sweep.BumpRequest,
21742174
return nil
21752175
}
21762176

2177-
ourSweepOutput, err := req.ExtraTxOut.UnwrapOrErr(
2178-
fmt.Errorf("extra tx out not populated"),
2179-
)
2180-
if err != nil {
2181-
return err
2182-
}
2183-
internalKey, err := ourSweepOutput.InternalKey.UnwrapOrErr(
2184-
fmt.Errorf("internal key not populated"),
2177+
// If this is a transaction that's only sweeping HTLC outputs via a
2178+
// pre-signed transaction, then we won't actually have an extra sweep
2179+
// output.
2180+
err = lfn.MapOptionZ(
2181+
req.ExtraTxOut,
2182+
func(extraTxOut sweep.SweepOutput) error {
2183+
ourSweepOutput, err := req.ExtraTxOut.UnwrapOrErr(
2184+
fmt.Errorf("extra tx out not populated"),
2185+
)
2186+
if err != nil {
2187+
return err
2188+
}
2189+
iKey, err := ourSweepOutput.InternalKey.UnwrapOrErr(
2190+
fmt.Errorf("internal key not populated"),
2191+
)
2192+
if err != nil {
2193+
return err
2194+
}
2195+
2196+
// We'll also use the passed in context to set the
2197+
// anchor key again for all the vOuts, but only for
2198+
// first level vPkts, as second level packets already
2199+
// commit to the internal key of the vOut.
2200+
vPkts := vPkts.directSpendPkts()
2201+
for idx := range vPkts {
2202+
for _, vOut := range vPkts[idx].Outputs {
2203+
vOut.SetAnchorInternalKey(
2204+
iKey,
2205+
a.cfg.ChainParams.HDCoinType,
2206+
)
2207+
}
2208+
}
2209+
2210+
return nil
2211+
},
21852212
)
21862213
if err != nil {
21872214
return err
21882215
}
21892216

2190-
log.Infof("Using %x for internal key: ",
2191-
internalKey.PubKey.SerializeCompressed())
2192-
2193-
// We'll also use the passed in context to set the anchor key again for
2194-
// all the vOuts, but only for first level vPkts, as second level
2195-
// packets already commit to the internal key of the vOut.
2196-
for idx := range vPkts.firstLevelPkts() {
2197-
for _, vOut := range vPkts.firstLevelPkts()[idx].Outputs {
2198-
vOut.SetAnchorInternalKey(
2199-
internalKey, a.cfg.ChainParams.HDCoinType,
2200-
)
2201-
}
2202-
}
2203-
22042217
// For any second level outputs we're sweeping, we'll need to sign for
22052218
// it, as now we know the txid of the sweeping transaction.
22062219
for _, sweepSet := range vPkts.secondLevel {

0 commit comments

Comments
 (0)