htlcswitch+lnwallet: use CustomRecords for aux sig blobs

In this commit, we start to use the set of CustomRecords instead of ExtraData for the aux sig blobs.
This commit is contained in:
Olaoluwa Osuntokun 2024-08-29 21:19:31 -05:00
parent 7dd3a5b361
commit f41dd862d0
No known key found for this signature in database
GPG Key ID: 3BBD59E99B280306
2 changed files with 48 additions and 14 deletions

View File

@ -2164,11 +2164,21 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
// We just received a new updates to our local commitment
// chain, validate this new commitment, closing the link if
// invalid.
auxSigBlob, err := msg.CustomRecords.Serialize()
if err != nil {
l.fail(
LinkFailureError{code: ErrInternalError},
"unable to serialize custom records: %v",
err,
)
return
}
err = l.channel.ReceiveNewCommitment(&lnwallet.CommitSigs{
CommitSig: msg.CommitSig,
HtlcSigs: msg.HtlcSigs,
PartialSig: msg.PartialSig,
AuxSigBlob: msg.ExtraData,
AuxSigBlob: auxSigBlob,
})
if err != nil {
// If we were unable to reconstruct their proposed
@ -2577,12 +2587,17 @@ func (l *channelLink) updateCommitTx() error {
default:
}
auxBlobRecords, err := lnwire.ParseCustomRecords(newCommit.AuxSigBlob)
if err != nil {
return fmt.Errorf("error parsing aux sigs: %w", err)
}
commitSig := &lnwire.CommitSig{
ChanID: l.ChanID(),
CommitSig: newCommit.CommitSig,
HtlcSigs: newCommit.HtlcSigs,
PartialSig: newCommit.PartialSig,
ExtraData: newCommit.AuxSigBlob,
ChanID: l.ChanID(),
CommitSig: newCommit.CommitSig,
HtlcSigs: newCommit.HtlcSigs,
PartialSig: newCommit.PartialSig,
CustomRecords: auxBlobRecords,
}
l.cfg.Peer.SendMessage(false, commitSig)

View File

@ -4028,6 +4028,10 @@ func (lc *LightningChannel) createCommitDiff(newCommit *commitment,
if err != nil {
return nil, fmt.Errorf("error packing aux sigs: %w", err)
}
auxBlobRecords, err := lnwire.ParseCustomRecords(auxSigBlob)
if err != nil {
return nil, fmt.Errorf("error parsing aux sigs: %w", err)
}
return &channeldb.CommitDiff{
Commitment: *diskCommit,
@ -4035,9 +4039,9 @@ func (lc *LightningChannel) createCommitDiff(newCommit *commitment,
ChanID: lnwire.NewChanIDFromOutPoint(
lc.channelState.FundingOutpoint,
),
CommitSig: commitSig,
HtlcSigs: htlcSigs,
ExtraData: auxSigBlob,
CommitSig: commitSig,
HtlcSigs: htlcSigs,
CustomRecords: auxBlobRecords,
},
LogUpdates: logUpdates,
OpenedCircuitKeys: openCircuitKeys,
@ -4737,12 +4741,18 @@ func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) {
// latest commitment update.
lc.remoteCommitChain.addCommitment(newCommitView)
auxSigBlob, err := commitDiff.CommitSig.CustomRecords.Serialize()
if err != nil {
return nil, fmt.Errorf("unable to serialize aux sig "+
"blob: %v", err)
}
return &NewCommitState{
CommitSigs: &CommitSigs{
CommitSig: sig,
HtlcSigs: htlcSigs,
PartialSig: lnwire.MaybePartialSigWithNonce(partialSig),
AuxSigBlob: commitDiff.CommitSig.ExtraData,
AuxSigBlob: auxSigBlob,
},
PendingHTLCs: commitDiff.Commitment.Htlcs,
}, nil
@ -4960,14 +4970,23 @@ func (lc *LightningChannel) ProcessChanSyncMsg(
// If we signed this state, then we'll accumulate
// another update to send over.
case err == nil:
blobRecords, err := lnwire.ParseCustomRecords(
newCommit.AuxSigBlob,
)
if err != nil {
sErr := fmt.Errorf("error parsing "+
"aux sigs: %w", err)
return nil, nil, nil, sErr
}
commitSig := &lnwire.CommitSig{
ChanID: lnwire.NewChanIDFromOutPoint(
lc.channelState.FundingOutpoint,
),
CommitSig: newCommit.CommitSig,
HtlcSigs: newCommit.HtlcSigs,
PartialSig: newCommit.PartialSig,
ExtraData: newCommit.AuxSigBlob,
CommitSig: newCommit.CommitSig,
HtlcSigs: newCommit.HtlcSigs,
PartialSig: newCommit.PartialSig,
CustomRecords: blobRecords,
}
updates = append(updates, commitSig)