Skip to content

Commit f41dd86

Browse files
committed
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.
1 parent 7dd3a5b commit f41dd86

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-14
lines changed

htlcswitch/link.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,11 +2164,21 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
21642164
// We just received a new updates to our local commitment
21652165
// chain, validate this new commitment, closing the link if
21662166
// invalid.
2167+
auxSigBlob, err := msg.CustomRecords.Serialize()
2168+
if err != nil {
2169+
l.fail(
2170+
LinkFailureError{code: ErrInternalError},
2171+
"unable to serialize custom records: %v",
2172+
err,
2173+
)
2174+
2175+
return
2176+
}
21672177
err = l.channel.ReceiveNewCommitment(&lnwallet.CommitSigs{
21682178
CommitSig: msg.CommitSig,
21692179
HtlcSigs: msg.HtlcSigs,
21702180
PartialSig: msg.PartialSig,
2171-
AuxSigBlob: msg.ExtraData,
2181+
AuxSigBlob: auxSigBlob,
21722182
})
21732183
if err != nil {
21742184
// If we were unable to reconstruct their proposed
@@ -2577,12 +2587,17 @@ func (l *channelLink) updateCommitTx() error {
25772587
default:
25782588
}
25792589

2590+
auxBlobRecords, err := lnwire.ParseCustomRecords(newCommit.AuxSigBlob)
2591+
if err != nil {
2592+
return fmt.Errorf("error parsing aux sigs: %w", err)
2593+
}
2594+
25802595
commitSig := &lnwire.CommitSig{
2581-
ChanID: l.ChanID(),
2582-
CommitSig: newCommit.CommitSig,
2583-
HtlcSigs: newCommit.HtlcSigs,
2584-
PartialSig: newCommit.PartialSig,
2585-
ExtraData: newCommit.AuxSigBlob,
2596+
ChanID: l.ChanID(),
2597+
CommitSig: newCommit.CommitSig,
2598+
HtlcSigs: newCommit.HtlcSigs,
2599+
PartialSig: newCommit.PartialSig,
2600+
CustomRecords: auxBlobRecords,
25862601
}
25872602
l.cfg.Peer.SendMessage(false, commitSig)
25882603

lnwallet/channel.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4028,16 +4028,20 @@ func (lc *LightningChannel) createCommitDiff(newCommit *commitment,
40284028
if err != nil {
40294029
return nil, fmt.Errorf("error packing aux sigs: %w", err)
40304030
}
4031+
auxBlobRecords, err := lnwire.ParseCustomRecords(auxSigBlob)
4032+
if err != nil {
4033+
return nil, fmt.Errorf("error parsing aux sigs: %w", err)
4034+
}
40314035

40324036
return &channeldb.CommitDiff{
40334037
Commitment: *diskCommit,
40344038
CommitSig: &lnwire.CommitSig{
40354039
ChanID: lnwire.NewChanIDFromOutPoint(
40364040
lc.channelState.FundingOutpoint,
40374041
),
4038-
CommitSig: commitSig,
4039-
HtlcSigs: htlcSigs,
4040-
ExtraData: auxSigBlob,
4042+
CommitSig: commitSig,
4043+
HtlcSigs: htlcSigs,
4044+
CustomRecords: auxBlobRecords,
40414045
},
40424046
LogUpdates: logUpdates,
40434047
OpenedCircuitKeys: openCircuitKeys,
@@ -4737,12 +4741,18 @@ func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) {
47374741
// latest commitment update.
47384742
lc.remoteCommitChain.addCommitment(newCommitView)
47394743

4744+
auxSigBlob, err := commitDiff.CommitSig.CustomRecords.Serialize()
4745+
if err != nil {
4746+
return nil, fmt.Errorf("unable to serialize aux sig "+
4747+
"blob: %v", err)
4748+
}
4749+
47404750
return &NewCommitState{
47414751
CommitSigs: &CommitSigs{
47424752
CommitSig: sig,
47434753
HtlcSigs: htlcSigs,
47444754
PartialSig: lnwire.MaybePartialSigWithNonce(partialSig),
4745-
AuxSigBlob: commitDiff.CommitSig.ExtraData,
4755+
AuxSigBlob: auxSigBlob,
47464756
},
47474757
PendingHTLCs: commitDiff.Commitment.Htlcs,
47484758
}, nil
@@ -4960,14 +4970,23 @@ func (lc *LightningChannel) ProcessChanSyncMsg(
49604970
// If we signed this state, then we'll accumulate
49614971
// another update to send over.
49624972
case err == nil:
4973+
blobRecords, err := lnwire.ParseCustomRecords(
4974+
newCommit.AuxSigBlob,
4975+
)
4976+
if err != nil {
4977+
sErr := fmt.Errorf("error parsing "+
4978+
"aux sigs: %w", err)
4979+
return nil, nil, nil, sErr
4980+
}
4981+
49634982
commitSig := &lnwire.CommitSig{
49644983
ChanID: lnwire.NewChanIDFromOutPoint(
49654984
lc.channelState.FundingOutpoint,
49664985
),
4967-
CommitSig: newCommit.CommitSig,
4968-
HtlcSigs: newCommit.HtlcSigs,
4969-
PartialSig: newCommit.PartialSig,
4970-
ExtraData: newCommit.AuxSigBlob,
4986+
CommitSig: newCommit.CommitSig,
4987+
HtlcSigs: newCommit.HtlcSigs,
4988+
PartialSig: newCommit.PartialSig,
4989+
CustomRecords: blobRecords,
49714990
}
49724991

49734992
updates = append(updates, commitSig)

0 commit comments

Comments
 (0)