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