mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-18 19:41:21 +02:00
contractcourt: update encode/decode for taproot aux data
When we read/write the aux data, we need to make sure we always set the new fields for aux HTLCs.
This commit is contained in:
committed by
Oliver Gugger
parent
6914e6a4a5
commit
f1a1c033d1
@@ -1564,6 +1564,7 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
||||
})
|
||||
}
|
||||
|
||||
htlcBlobs := newAuxHtlcBlobs()
|
||||
for _, htlc := range c.HtlcResolutions.IncomingHTLCs {
|
||||
htlc := htlc
|
||||
|
||||
@@ -1574,8 +1575,9 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
||||
continue
|
||||
}
|
||||
|
||||
var resID resolverID
|
||||
if htlc.SignedSuccessTx != nil {
|
||||
resID := newResolverID(
|
||||
resID = newResolverID(
|
||||
htlc.SignedSuccessTx.TxIn[0].PreviousOutPoint,
|
||||
)
|
||||
//nolint:lll
|
||||
@@ -1591,10 +1593,14 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
||||
tapCase.CtrlBlocks.Val.IncomingHtlcCtrlBlocks[resID] = bridgeCtrlBlock
|
||||
}
|
||||
} else {
|
||||
resID := newResolverID(htlc.ClaimOutpoint)
|
||||
resID = newResolverID(htlc.ClaimOutpoint)
|
||||
//nolint:lll
|
||||
tapCase.CtrlBlocks.Val.IncomingHtlcCtrlBlocks[resID] = ctrlBlock
|
||||
}
|
||||
|
||||
htlc.ResolutionBlob.WhenSome(func(b []byte) {
|
||||
htlcBlobs[resID] = b
|
||||
})
|
||||
}
|
||||
for _, htlc := range c.HtlcResolutions.OutgoingHTLCs {
|
||||
htlc := htlc
|
||||
@@ -1606,8 +1612,9 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
||||
continue
|
||||
}
|
||||
|
||||
var resID resolverID
|
||||
if htlc.SignedTimeoutTx != nil {
|
||||
resID := newResolverID(
|
||||
resID = newResolverID(
|
||||
htlc.SignedTimeoutTx.TxIn[0].PreviousOutPoint,
|
||||
)
|
||||
//nolint:lll
|
||||
@@ -1625,10 +1632,14 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
||||
tapCase.CtrlBlocks.Val.OutgoingHtlcCtrlBlocks[resID] = bridgeCtrlBlock
|
||||
}
|
||||
} else {
|
||||
resID := newResolverID(htlc.ClaimOutpoint)
|
||||
resID = newResolverID(htlc.ClaimOutpoint)
|
||||
//nolint:lll
|
||||
tapCase.CtrlBlocks.Val.OutgoingHtlcCtrlBlocks[resID] = ctrlBlock
|
||||
}
|
||||
|
||||
htlc.ResolutionBlob.WhenSome(func(b []byte) {
|
||||
htlcBlobs[resID] = b
|
||||
})
|
||||
}
|
||||
|
||||
if c.AnchorResolution != nil {
|
||||
@@ -1636,6 +1647,12 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
||||
tapCase.TapTweaks.Val.AnchorTweak = anchorSignDesc.TapTweak
|
||||
}
|
||||
|
||||
if len(htlcBlobs) != 0 {
|
||||
tapCase.HtlcBlobs = tlv.SomeRecordT(
|
||||
tlv.NewRecordT[tlv.TlvType4](htlcBlobs),
|
||||
)
|
||||
}
|
||||
|
||||
return tapCase.Encode(w)
|
||||
}
|
||||
|
||||
@@ -1654,6 +1671,8 @@ func decodeTapRootAuxData(r io.Reader, c *ContractResolutions) error {
|
||||
})
|
||||
}
|
||||
|
||||
htlcBlobs := tapCase.HtlcBlobs.ValOpt().UnwrapOr(newAuxHtlcBlobs())
|
||||
|
||||
for i := range c.HtlcResolutions.IncomingHTLCs {
|
||||
htlc := c.HtlcResolutions.IncomingHTLCs[i]
|
||||
|
||||
@@ -1680,7 +1699,12 @@ func decodeTapRootAuxData(r io.Reader, c *ContractResolutions) error {
|
||||
htlc.SweepSignDesc.ControlBlock = ctrlBlock
|
||||
}
|
||||
|
||||
if htlcBlob, ok := htlcBlobs[resID]; ok {
|
||||
htlc.ResolutionBlob = fn.Some(htlcBlob)
|
||||
}
|
||||
|
||||
c.HtlcResolutions.IncomingHTLCs[i] = htlc
|
||||
|
||||
}
|
||||
for i := range c.HtlcResolutions.OutgoingHTLCs {
|
||||
htlc := c.HtlcResolutions.OutgoingHTLCs[i]
|
||||
@@ -1708,6 +1732,10 @@ func decodeTapRootAuxData(r io.Reader, c *ContractResolutions) error {
|
||||
htlc.SweepSignDesc.ControlBlock = ctrlBlock
|
||||
}
|
||||
|
||||
if htlcBlob, ok := htlcBlobs[resID]; ok {
|
||||
htlc.ResolutionBlob = fn.Some(htlcBlob)
|
||||
}
|
||||
|
||||
c.HtlcResolutions.OutgoingHTLCs[i] = htlc
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user