@@ -1617,6 +1617,107 @@ 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+ case input .TaprootHtlcAcceptedLocalSuccess :
1673+ preimage := i .Preimage ()
1674+
1675+ preimageInfo = lfn .MapOption (
1676+ func (p lntypes.Preimage ) preimageDesc {
1677+ return preimageDesc {
1678+ preimage : p ,
1679+ witnessIndex : 2 ,
1680+ }
1681+ },
1682+ )(preimage )
1683+
1684+ // This is the case when we're sweeping the HTLC output we received on
1685+ // the remote party's version of the commitment transaction.
1686+ //
1687+ // The final witness stack is:
1688+ // <receiver sig> <preimage> <success_script> <control_block>
1689+ //
1690+ // So we'll place the preimage at index 1.
1691+ case input .TaprootHtlcAcceptedRemoteSuccess :
1692+ preimage := i .Preimage ()
1693+
1694+ preimageInfo = lfn .MapOption (
1695+ func (p lntypes.Preimage ) preimageDesc {
1696+ return preimageDesc {
1697+ preimage : p ,
1698+ witnessIndex : 1 ,
1699+ }
1700+ },
1701+ )(preimage )
1702+
1703+ // For second level sweeps, we don't need to note anything about a
1704+ // preimage, but will note that this is a second level output.
1705+ case input .TaprootHtlcOfferedTimeoutSecondLevel :
1706+ fallthrough
1707+ case input .TaprootHtlcAcceptedSuccessSecondLevel :
1708+ secondLevel = true
1709+ }
1710+
1711+ // We already know this has a blob from the filter in an earlier
1712+ // step.
1713+ return lfn .Ok (blobWithWitnessInfo {
1714+ resolutionBlob : i .ResolutionBlob ().UnwrapOr (nil ),
1715+ input : i ,
1716+ preimageInfo : preimageInfo ,
1717+ secondLevel : secondLevel ,
1718+ })
1719+ }
1720+
16201721// extractInputVPackets extracts the vPackets from the inputs passed in. If
16211722// none of the inputs have any resolution blobs. Then an empty slice will be
16221723// returned.
0 commit comments