Skip to content

Commit 957557a

Browse files
committed
htlcswitch+lnwallet: remove PaymentDescriptor from ReceiveRevocation returns
This is part of a systematic removal of PaymentDescriptor from the public API of the lnwallet package. This marks the last change needed before we make the PaymentDescriptor structure private.
1 parent 1ae5705 commit 957557a

File tree

7 files changed

+120
-114
lines changed

7 files changed

+120
-114
lines changed

htlcswitch/link.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,8 +2321,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
23212321

23222322
// We now process the message and advance our remote commit
23232323
// chain.
2324-
fwdPkg, _, _, remoteHTLCs, err := l.channel.
2325-
ReceiveRevocation(msg)
2324+
fwdPkg, remoteHTLCs, err := l.channel.ReceiveRevocation(msg)
23262325
if err != nil {
23272326
// TODO(halseth): force close?
23282327
l.failf(

htlcswitch/link_isolated_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (l *linkTestContext) receiveRevAndAckAliceToBob() {
129129
l.t.Fatalf("expected RevokeAndAck, got %T", msg)
130130
}
131131

132-
_, _, _, _, err := l.bobChannel.ReceiveRevocation(rev)
132+
_, _, err := l.bobChannel.ReceiveRevocation(rev)
133133
if err != nil {
134134
l.t.Fatalf("bob failed receiving revocation: %v", err)
135135
}

htlcswitch/link_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,7 +2335,7 @@ func handleStateUpdate(link *channelLink,
23352335
if !ok {
23362336
return fmt.Errorf("expected RevokeAndAck got %T", msg)
23372337
}
2338-
_, _, _, _, err = remoteChannel.ReceiveRevocation(revoke)
2338+
_, _, err = remoteChannel.ReceiveRevocation(revoke)
23392339
if err != nil {
23402340
return fmt.Errorf("unable to receive "+
23412341
"revocation: %v", err)
@@ -2389,7 +2389,7 @@ func updateState(batchTick chan time.Time, link *channelLink,
23892389
return fmt.Errorf("expected RevokeAndAck got %T",
23902390
msg)
23912391
}
2392-
_, _, _, _, err = remoteChannel.ReceiveRevocation(revoke)
2392+
_, _, err = remoteChannel.ReceiveRevocation(revoke)
23932393
if err != nil {
23942394
return fmt.Errorf("unable to receive "+
23952395
"revocation: %v", err)
@@ -3643,7 +3643,7 @@ func TestChannelLinkTrimCircuitsRemoteCommit(t *testing.T) {
36433643
rev, _, _, err := harness.bobChannel.RevokeCurrentCommitment()
36443644
require.NoError(t, err, "unable to revoke current commitment")
36453645

3646-
_, _, _, _, err = alice.channel.ReceiveRevocation(rev)
3646+
_, _, err = alice.channel.ReceiveRevocation(rev)
36473647
require.NoError(t, err, "unable to receive revocation")
36483648

36493649
// Restart Alice's link, which simulates a disconnection with the remote

lnwallet/channel.go

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5375,15 +5375,10 @@ func (lc *LightningChannel) RevokeCurrentCommitment() (*lnwire.RevokeAndAck,
53755375
// The returned values correspond to:
53765376
// 1. The forwarding package corresponding to the remote commitment height
53775377
// that was revoked.
5378-
// 2. The PaymentDescriptor of any Add HTLCs that were locked in by this
5379-
// revocation.
5380-
// 3. The PaymentDescriptor of any Settle/Fail HTLCs that were locked in by
5381-
// this revocation.
5382-
// 4. The set of HTLCs present on the current valid commitment transaction
5378+
// 2. The set of HTLCs present on the current valid commitment transaction
53835379
// for the remote party.
53845380
func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
5385-
*channeldb.FwdPkg, []*PaymentDescriptor, []*PaymentDescriptor,
5386-
[]channeldb.HTLC, error) {
5381+
*channeldb.FwdPkg, []channeldb.HTLC, error) {
53875382

53885383
lc.Lock()
53895384
defer lc.Unlock()
@@ -5392,10 +5387,10 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
53925387
store := lc.channelState.RevocationStore
53935388
revocation, err := chainhash.NewHash(revMsg.Revocation[:])
53945389
if err != nil {
5395-
return nil, nil, nil, nil, err
5390+
return nil, nil, err
53965391
}
53975392
if err := store.AddNextEntry(revocation); err != nil {
5398-
return nil, nil, nil, nil, err
5393+
return nil, nil, err
53995394
}
54005395

54015396
// Verify that if we use the commitment point computed based off of the
@@ -5404,7 +5399,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
54045399
currentCommitPoint := lc.channelState.RemoteCurrentRevocation
54055400
derivedCommitPoint := input.ComputeCommitmentPoint(revMsg.Revocation[:])
54065401
if !derivedCommitPoint.IsEqual(currentCommitPoint) {
5407-
return nil, nil, nil, nil, fmt.Errorf("revocation key mismatch")
5402+
return nil, nil, fmt.Errorf("revocation key mismatch")
54085403
}
54095404

54105405
// Now that we've verified that the prior commitment has been properly
@@ -5434,10 +5429,8 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
54345429
// updates to disk and optimistically buffer the forwarding package in
54355430
// memory.
54365431
var (
5437-
addsToForward []*PaymentDescriptor
5438-
addUpdates []channeldb.LogUpdate
5439-
settleFailsToForward []*PaymentDescriptor
5440-
settleFailUpdates []channeldb.LogUpdate
5432+
addUpdatesToForward []channeldb.LogUpdate
5433+
settleFailUpdatesToForward []channeldb.LogUpdate
54415434
)
54425435

54435436
var addIndex, settleFailIndex uint16
@@ -5489,7 +5482,13 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
54895482
addIndex++
54905483

54915484
pd.isForwarded = true
5492-
addsToForward = append(addsToForward, pd)
5485+
5486+
// At this point we put the update into our list of
5487+
// updates that we will eventually put into the
5488+
// FwdPkg at this height.
5489+
addUpdatesToForward = append(
5490+
addUpdatesToForward, pd.ToLogUpdate(),
5491+
)
54935492

54945493
case pd.EntryType != Add && committedRmv && shouldFwdRmv:
54955494
// Construct a reference specifying the location that
@@ -5503,28 +5502,17 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
55035502
settleFailIndex++
55045503

55055504
pd.isForwarded = true
5506-
settleFailsToForward = append(settleFailsToForward, pd)
5505+
5506+
// At this point we put the update into our list of
5507+
// updates that we will eventually put into the
5508+
// FwdPkg at this height.
5509+
settleFailUpdatesToForward = append(
5510+
settleFailUpdatesToForward, pd.ToLogUpdate(),
5511+
)
55075512

55085513
default:
55095514
continue
55105515
}
5511-
5512-
// If we've reached this point, this HTLC will be added to the
5513-
// forwarding package at the height of the remote commitment.
5514-
// We'll map the type of the PaymentDescriptor to one of the
5515-
// four messages that it corresponds to and separate the
5516-
// updates into Adds and Settle/Fail/MalformedFail such that
5517-
// they can be written in the forwarding package. Adds are
5518-
// aggregated separately from the other types of HTLCs.
5519-
switch pd.EntryType {
5520-
case Add:
5521-
addUpdates = append(addUpdates, pd.ToLogUpdate())
5522-
5523-
case Settle, Fail, MalformedFail:
5524-
settleFailUpdates = append(
5525-
settleFailUpdates, pd.ToLogUpdate(),
5526-
)
5527-
}
55285516
}
55295517

55305518
// We use the remote commitment chain's tip as it will soon become the tail
@@ -5540,7 +5528,8 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
55405528
// type, construct a forwarding package using the height that the remote
55415529
// commitment chain will be extended after persisting the revocation.
55425530
fwdPkg := channeldb.NewFwdPkg(
5543-
source, remoteChainTail, addUpdates, settleFailUpdates,
5531+
source, remoteChainTail, addUpdatesToForward,
5532+
settleFailUpdatesToForward,
55445533
)
55455534

55465535
// We will soon be saving the current remote commitment to revocation
@@ -5553,15 +5542,15 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
55535542
revocation, lc.channelState, lc.leafStore,
55545543
)
55555544
if err != nil {
5556-
return nil, nil, nil, nil, err
5545+
return nil, nil, err
55575546
}
55585547

55595548
// Now that we have a new verification nonce from them, we can refresh
55605549
// our remote musig2 session which allows us to create another state.
55615550
if lc.channelState.ChanType.IsTaproot() {
55625551
localNonce, err := revMsg.LocalNonce.UnwrapOrErrV(errNoNonce)
55635552
if err != nil {
5564-
return nil, nil, nil, nil, err
5553+
return nil, nil, err
55655554
}
55665555

55675556
session, err := lc.musigSessions.RemoteSession.Refresh(
@@ -5570,7 +5559,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
55705559
},
55715560
)
55725561
if err != nil {
5573-
return nil, nil, nil, nil, err
5562+
return nil, nil, err
55745563
}
55755564

55765565
lc.musigSessions.RemoteSession = session
@@ -5586,7 +5575,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
55865575
ourOutputIndex, theirOutputIndex,
55875576
)
55885577
if err != nil {
5589-
return nil, nil, nil, nil, err
5578+
return nil, nil, err
55905579
}
55915580

55925581
// Since they revoked the current lowest height in their commitment
@@ -5603,7 +5592,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) (
56035592

56045593
remoteHTLCs := lc.channelState.RemoteCommitment.Htlcs
56055594

5606-
return fwdPkg, addsToForward, settleFailsToForward, remoteHTLCs, nil
5595+
return fwdPkg, remoteHTLCs, nil
56075596
}
56085597

56095598
// LoadFwdPkgs loads any pending log updates from disk and returns the payment

0 commit comments

Comments
 (0)