From f41dd862d06642f15cb47fac21227f3ab88d07fe Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 29 Aug 2024 21:19:31 -0500 Subject: [PATCH] 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. --- htlcswitch/link.go | 27 +++++++++++++++++++++------ lnwallet/channel.go | 35 +++++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 468eba131..a59cedf06 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -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) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 0c3e4c9ce..b420b6134 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -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)