@@ -1617,6 +1617,110 @@ func (a *AuxSweeper) resolveContract(
16171617 )
16181618}
16191619
1620+ // preimageDesc is a helper struct that contains the preimage and the witness
1621+ // index that the preimage should be placed within the witness stack. This is
1622+ // useful as in an earlier step, we've already pre-signed the witness, but will
1623+ // learn of the preimage later.
1624+ type preimageDesc struct {
1625+ // preimage is the preimage that we'll use to update the witness stack.
1626+ preimage lntypes.Preimage
1627+
1628+ // witnessIndex is the index within the witness stack that the preimage
1629+ // should be placed at.
1630+ witnessIndex int
1631+ }
1632+
1633+ // blobWithWitnessInfo is a helper struct that contains a resolution blob, along
1634+ // with optional preimage information. If the preimage information is present,
1635+ // then we'll use this to update the witness stack of the final vPacket before
1636+ // we anchor it into the sweep output.
1637+ type blobWithWitnessInfo struct {
1638+ // resolutionBlob is the serialized resolution blob that contains the
1639+ // vPackets.
1640+ resolutionBlob tlv.Blob
1641+
1642+ // input is the sweep input that we created this blob using.
1643+ input input.Input
1644+
1645+ // preimageInfo is an optional field that contains the preimage and info
1646+ // w.r.t where to place it in the witness stack.
1647+ preimageInfo lfn.Option [preimageDesc ]
1648+
1649+ // secondLevel indicates if this is a second level sweep.
1650+ secondLevel bool
1651+ }
1652+
1653+ // newBlobWithWitnessInfo creates a new blobWithWitnessInfo struct from a passed
1654+ // input.Input, which stores the resolution blob and other information.
1655+ func newBlobWithWitnessInfo (i input.Input ) lfn.Result [blobWithWitnessInfo ] {
1656+ // If this is a success input, then we'll need to extract the preimage
1657+ // from the inner struct, so we can update the witness stack.
1658+ var (
1659+ preimageInfo lfn.Option [preimageDesc ]
1660+ secondLevel bool
1661+ )
1662+ switch i .WitnessType () {
1663+
1664+ // This is the case when we're sweeping the HTLC output on our local
1665+ // commitment transaction via a second level HTLC.
1666+ //
1667+ // The final witness stack is:
1668+ // * <sender sig> <receiver sig> <preimage> <success_script>
1669+ // <control_block>
1670+ //
1671+ // So we'll place the preimage at index 2.
1672+ //
1673+ // TODO(roasbeef): diff case entirely? as need to insert other sig as
1674+ // well -- sweeper at index 1
1675+ case input .TaprootHtlcAcceptedLocalSuccess :
1676+ preimage := i .Preimage ()
1677+
1678+ preimageInfo = lfn .MapOption (
1679+ func (p lntypes.Preimage ) preimageDesc {
1680+ return preimageDesc {
1681+ preimage : p ,
1682+ witnessIndex : 2 ,
1683+ }
1684+ },
1685+ )(preimage )
1686+
1687+ // This is the case when we're sweeping the HTLC output we received on the
1688+ // remote party's version of the commitment transaction.
1689+ //
1690+ // The final witness stack is:
1691+ // <receiver sig> <preimage> <success_script> <control_block>
1692+ //
1693+ // So we'll place the preimage at index 1.
1694+ case input .TaprootHtlcAcceptedRemoteSuccess :
1695+ preimage := i .Preimage ()
1696+
1697+ preimageInfo = lfn .MapOption (
1698+ func (p lntypes.Preimage ) preimageDesc {
1699+ return preimageDesc {
1700+ preimage : p ,
1701+ witnessIndex : 1 ,
1702+ }
1703+ },
1704+ )(preimage )
1705+
1706+ // For second level sweeps, we don't need to note anything about a
1707+ // preimage, but will note that this is a second level output.
1708+ case input .TaprootHtlcOfferedTimeoutSecondLevel :
1709+ fallthrough
1710+ case input .TaprootHtlcAcceptedSuccessSecondLevel :
1711+ secondLevel = true
1712+ }
1713+
1714+ // We already know this has a blob from the filter in an earlier
1715+ // step.
1716+ return lfn .Ok (blobWithWitnessInfo {
1717+ resolutionBlob : i .ResolutionBlob ().UnwrapOr (nil ),
1718+ input : i ,
1719+ preimageInfo : preimageInfo ,
1720+ secondLevel : secondLevel ,
1721+ })
1722+ }
1723+
16201724// extractInputVPackets extracts the vPackets from the inputs passed in. If
16211725// none of the inputs have any resolution blobs. Then an empty slice will be
16221726// returned.
0 commit comments