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:
1 file changed
+32
-4
@@ -1571,6 +1571,7 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
htlcBlobs := newAuxHtlcBlobs()
|
||||||
for _, htlc := range c.HtlcResolutions.IncomingHTLCs {
|
for _, htlc := range c.HtlcResolutions.IncomingHTLCs {
|
||||||
htlc := htlc
|
htlc := htlc
|
||||||
|
|
||||||
@@ -1581,8 +1582,9 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var resID resolverID
|
||||||
if htlc.SignedSuccessTx != nil {
|
if htlc.SignedSuccessTx != nil {
|
||||||
resID := newResolverID(
|
resID = newResolverID(
|
||||||
htlc.SignedSuccessTx.TxIn[0].PreviousOutPoint,
|
htlc.SignedSuccessTx.TxIn[0].PreviousOutPoint,
|
||||||
)
|
)
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
@@ -1598,10 +1600,14 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
|||||||
tapCase.CtrlBlocks.Val.IncomingHtlcCtrlBlocks[resID] = bridgeCtrlBlock
|
tapCase.CtrlBlocks.Val.IncomingHtlcCtrlBlocks[resID] = bridgeCtrlBlock
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resID := newResolverID(htlc.ClaimOutpoint)
|
resID = newResolverID(htlc.ClaimOutpoint)
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
tapCase.CtrlBlocks.Val.IncomingHtlcCtrlBlocks[resID] = ctrlBlock
|
tapCase.CtrlBlocks.Val.IncomingHtlcCtrlBlocks[resID] = ctrlBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
|
htlc.ResolutionBlob.WhenSome(func(b []byte) {
|
||||||
|
htlcBlobs[resID] = b
|
||||||
|
})
|
||||||
}
|
}
|
||||||
for _, htlc := range c.HtlcResolutions.OutgoingHTLCs {
|
for _, htlc := range c.HtlcResolutions.OutgoingHTLCs {
|
||||||
htlc := htlc
|
htlc := htlc
|
||||||
@@ -1613,8 +1619,9 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var resID resolverID
|
||||||
if htlc.SignedTimeoutTx != nil {
|
if htlc.SignedTimeoutTx != nil {
|
||||||
resID := newResolverID(
|
resID = newResolverID(
|
||||||
htlc.SignedTimeoutTx.TxIn[0].PreviousOutPoint,
|
htlc.SignedTimeoutTx.TxIn[0].PreviousOutPoint,
|
||||||
)
|
)
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
@@ -1632,10 +1639,14 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
|||||||
tapCase.CtrlBlocks.Val.OutgoingHtlcCtrlBlocks[resID] = bridgeCtrlBlock
|
tapCase.CtrlBlocks.Val.OutgoingHtlcCtrlBlocks[resID] = bridgeCtrlBlock
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resID := newResolverID(htlc.ClaimOutpoint)
|
resID = newResolverID(htlc.ClaimOutpoint)
|
||||||
//nolint:lll
|
//nolint:lll
|
||||||
tapCase.CtrlBlocks.Val.OutgoingHtlcCtrlBlocks[resID] = ctrlBlock
|
tapCase.CtrlBlocks.Val.OutgoingHtlcCtrlBlocks[resID] = ctrlBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
|
htlc.ResolutionBlob.WhenSome(func(b []byte) {
|
||||||
|
htlcBlobs[resID] = b
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.AnchorResolution != nil {
|
if c.AnchorResolution != nil {
|
||||||
@@ -1643,6 +1654,12 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
|||||||
tapCase.TapTweaks.Val.AnchorTweak = anchorSignDesc.TapTweak
|
tapCase.TapTweaks.Val.AnchorTweak = anchorSignDesc.TapTweak
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(htlcBlobs) != 0 {
|
||||||
|
tapCase.HtlcBlobs = tlv.SomeRecordT(
|
||||||
|
tlv.NewRecordT[tlv.TlvType4](htlcBlobs),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return tapCase.Encode(w)
|
return tapCase.Encode(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1661,6 +1678,8 @@ func decodeTapRootAuxData(r io.Reader, c *ContractResolutions) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
htlcBlobs := tapCase.HtlcBlobs.ValOpt().UnwrapOr(newAuxHtlcBlobs())
|
||||||
|
|
||||||
for i := range c.HtlcResolutions.IncomingHTLCs {
|
for i := range c.HtlcResolutions.IncomingHTLCs {
|
||||||
htlc := c.HtlcResolutions.IncomingHTLCs[i]
|
htlc := c.HtlcResolutions.IncomingHTLCs[i]
|
||||||
|
|
||||||
@@ -1687,7 +1706,12 @@ func decodeTapRootAuxData(r io.Reader, c *ContractResolutions) error {
|
|||||||
htlc.SweepSignDesc.ControlBlock = ctrlBlock
|
htlc.SweepSignDesc.ControlBlock = ctrlBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if htlcBlob, ok := htlcBlobs[resID]; ok {
|
||||||
|
htlc.ResolutionBlob = fn.Some(htlcBlob)
|
||||||
|
}
|
||||||
|
|
||||||
c.HtlcResolutions.IncomingHTLCs[i] = htlc
|
c.HtlcResolutions.IncomingHTLCs[i] = htlc
|
||||||
|
|
||||||
}
|
}
|
||||||
for i := range c.HtlcResolutions.OutgoingHTLCs {
|
for i := range c.HtlcResolutions.OutgoingHTLCs {
|
||||||
htlc := c.HtlcResolutions.OutgoingHTLCs[i]
|
htlc := c.HtlcResolutions.OutgoingHTLCs[i]
|
||||||
@@ -1715,6 +1739,10 @@ func decodeTapRootAuxData(r io.Reader, c *ContractResolutions) error {
|
|||||||
htlc.SweepSignDesc.ControlBlock = ctrlBlock
|
htlc.SweepSignDesc.ControlBlock = ctrlBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if htlcBlob, ok := htlcBlobs[resID]; ok {
|
||||||
|
htlc.ResolutionBlob = fn.Some(htlcBlob)
|
||||||
|
}
|
||||||
|
|
||||||
c.HtlcResolutions.OutgoingHTLCs[i] = htlc
|
c.HtlcResolutions.OutgoingHTLCs[i] = htlc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user