lnwallet: pack commit chains into Dual
This commit packs the LightningChannel's localCommitmentChain and remoteCommitmentChain into a Dual structure for better symmetric access. This will be leveraged by an upcoming commit where we want to more concisely express how we compute the number of pending updates.
This commit is contained in:
2 files changed
+93
-85
No files matched your search
+31
-25
@@ -1435,12 +1435,12 @@ func TestHTLCDustLimit(t *testing.T) {
|
||||
// while Bob's should not, because the value falls beneath his dust
|
||||
// limit. The amount of the HTLC should be applied to fees in Bob's
|
||||
// commitment transaction.
|
||||
aliceCommitment := aliceChannel.localCommitChain.tip()
|
||||
aliceCommitment := aliceChannel.commitChains.Local.tip()
|
||||
if len(aliceCommitment.txn.TxOut) != 3 {
|
||||
t.Fatalf("incorrect # of outputs: expected %v, got %v",
|
||||
3, len(aliceCommitment.txn.TxOut))
|
||||
}
|
||||
bobCommitment := bobChannel.localCommitChain.tip()
|
||||
bobCommitment := bobChannel.commitChains.Local.tip()
|
||||
if len(bobCommitment.txn.TxOut) != 2 {
|
||||
t.Fatalf("incorrect # of outputs: expected %v, got %v",
|
||||
2, len(bobCommitment.txn.TxOut))
|
||||
@@ -1465,7 +1465,7 @@ func TestHTLCDustLimit(t *testing.T) {
|
||||
|
||||
// At this point, for Alice's commitment chains, the value of the HTLC
|
||||
// should have been added to Alice's balance and TotalSatoshisSent.
|
||||
commitment := aliceChannel.localCommitChain.tip()
|
||||
commitment := aliceChannel.commitChains.Local.tip()
|
||||
if len(commitment.txn.TxOut) != 2 {
|
||||
t.Fatalf("incorrect # of outputs: expected %v, got %v",
|
||||
2, len(commitment.txn.TxOut))
|
||||
@@ -1698,7 +1698,7 @@ func TestChannelBalanceDustLimit(t *testing.T) {
|
||||
// output for Alice's balance should have been removed as dust, leaving
|
||||
// only a single output that will send the remaining funds in the
|
||||
// channel to Bob.
|
||||
commitment := bobChannel.localCommitChain.tip()
|
||||
commitment := bobChannel.commitChains.Local.tip()
|
||||
if len(commitment.txn.TxOut) != 1 {
|
||||
t.Fatalf("incorrect # of outputs: expected %v, got %v",
|
||||
1, len(commitment.txn.TxOut))
|
||||
@@ -1816,25 +1816,25 @@ func TestStateUpdatePersistence(t *testing.T) {
|
||||
|
||||
// After the state transition the fee update is fully locked in, and
|
||||
// should've been removed from both channels' update logs.
|
||||
if aliceChannel.localCommitChain.tail().feePerKw != fee {
|
||||
if aliceChannel.commitChains.Local.tail().feePerKw != fee {
|
||||
t.Fatalf("fee not locked in")
|
||||
}
|
||||
if bobChannel.localCommitChain.tail().feePerKw != fee {
|
||||
if bobChannel.commitChains.Local.tail().feePerKw != fee {
|
||||
t.Fatalf("fee not locked in")
|
||||
}
|
||||
assertNumLogUpdates(3, 1)
|
||||
|
||||
// The latest commitment from both sides should have all the HTLCs.
|
||||
numAliceOutgoing := aliceChannel.localCommitChain.tail().outgoingHTLCs
|
||||
numAliceIncoming := aliceChannel.localCommitChain.tail().incomingHTLCs
|
||||
numAliceOutgoing := aliceChannel.commitChains.Local.tail().outgoingHTLCs
|
||||
numAliceIncoming := aliceChannel.commitChains.Local.tail().incomingHTLCs
|
||||
if len(numAliceOutgoing) != 3 {
|
||||
t.Fatalf("expected %v htlcs, instead got %v", 3, numAliceOutgoing)
|
||||
}
|
||||
if len(numAliceIncoming) != 1 {
|
||||
t.Fatalf("expected %v htlcs, instead got %v", 1, numAliceIncoming)
|
||||
}
|
||||
numBobOutgoing := bobChannel.localCommitChain.tail().outgoingHTLCs
|
||||
numBobIncoming := bobChannel.localCommitChain.tail().incomingHTLCs
|
||||
numBobOutgoing := bobChannel.commitChains.Local.tail().outgoingHTLCs
|
||||
numBobIncoming := bobChannel.commitChains.Local.tail().incomingHTLCs
|
||||
if len(numBobOutgoing) != 1 {
|
||||
t.Fatalf("expected %v htlcs, instead got %v", 1, numBobOutgoing)
|
||||
}
|
||||
@@ -2090,20 +2090,24 @@ func TestCancelHTLC(t *testing.T) {
|
||||
|
||||
// Now HTLCs should be present on the commitment transaction for either
|
||||
// side.
|
||||
if len(aliceChannel.localCommitChain.tip().outgoingHTLCs) != 0 ||
|
||||
len(aliceChannel.remoteCommitChain.tip().outgoingHTLCs) != 0 {
|
||||
if len(aliceChannel.commitChains.Local.tip().outgoingHTLCs) != 0 ||
|
||||
len(aliceChannel.commitChains.Remote.tip().outgoingHTLCs) != 0 {
|
||||
|
||||
t.Fatalf("htlc's still active from alice's POV")
|
||||
}
|
||||
if len(aliceChannel.localCommitChain.tip().incomingHTLCs) != 0 ||
|
||||
len(aliceChannel.remoteCommitChain.tip().incomingHTLCs) != 0 {
|
||||
if len(aliceChannel.commitChains.Local.tip().incomingHTLCs) != 0 ||
|
||||
len(aliceChannel.commitChains.Remote.tip().incomingHTLCs) != 0 {
|
||||
|
||||
t.Fatalf("htlc's still active from alice's POV")
|
||||
}
|
||||
if len(bobChannel.localCommitChain.tip().outgoingHTLCs) != 0 ||
|
||||
len(bobChannel.remoteCommitChain.tip().outgoingHTLCs) != 0 {
|
||||
if len(bobChannel.commitChains.Local.tip().outgoingHTLCs) != 0 ||
|
||||
len(bobChannel.commitChains.Remote.tip().outgoingHTLCs) != 0 {
|
||||
|
||||
t.Fatalf("htlc's still active from bob's POV")
|
||||
}
|
||||
if len(bobChannel.localCommitChain.tip().incomingHTLCs) != 0 ||
|
||||
len(bobChannel.remoteCommitChain.tip().incomingHTLCs) != 0 {
|
||||
if len(bobChannel.commitChains.Local.tip().incomingHTLCs) != 0 ||
|
||||
len(bobChannel.commitChains.Remote.tip().incomingHTLCs) != 0 {
|
||||
|
||||
t.Fatalf("htlc's still active from bob's POV")
|
||||
}
|
||||
|
||||
@@ -5207,7 +5211,9 @@ func TestChanCommitWeightDustHtlcs(t *testing.T) {
|
||||
// When sending htlcs we enforce the feebuffer on the commitment
|
||||
// transaction.
|
||||
remoteCommitWeight := func(lc *LightningChannel) lntypes.WeightUnit {
|
||||
remoteACKedIndex := lc.localCommitChain.tip().theirMessageIndex
|
||||
remoteACKedIndex :=
|
||||
lc.commitChains.Local.tip().theirMessageIndex
|
||||
|
||||
htlcView := lc.fetchHTLCView(remoteACKedIndex,
|
||||
lc.localUpdateLog.logIndex)
|
||||
|
||||
@@ -5830,7 +5836,7 @@ func TestChannelUnilateralClosePendingCommit(t *testing.T) {
|
||||
// At this point, Alice's commitment chain should have a new pending
|
||||
// commit for Bob. We'll extract it so we can simulate Bob broadcasting
|
||||
// the commitment due to an issue.
|
||||
bobCommit := aliceChannel.remoteCommitChain.tip().txn
|
||||
bobCommit := aliceChannel.commitChains.Remote.tip().txn
|
||||
bobTxHash := bobCommit.TxHash()
|
||||
spendDetail := &chainntnfs.SpendDetail{
|
||||
SpenderTxHash: &bobTxHash,
|
||||
@@ -7523,7 +7529,7 @@ func TestForceCloseBorkedState(t *testing.T) {
|
||||
|
||||
// We manually advance the commitment tail here since the above
|
||||
// ReceiveRevocation call will fail before it's actually advanced.
|
||||
aliceChannel.remoteCommitChain.advanceTail()
|
||||
aliceChannel.commitChains.Remote.advanceTail()
|
||||
_, err = aliceChannel.SignNextCommitment()
|
||||
if err != channeldb.ErrChanBorked {
|
||||
t.Fatalf("sign commitment should have failed: %v", err)
|
||||
@@ -7739,7 +7745,7 @@ func TestIdealCommitFeeRate(t *testing.T) {
|
||||
maxFeeAlloc float64) chainfee.SatPerKWeight {
|
||||
|
||||
balance, weight := c.availableBalance(AdditionalHtlc)
|
||||
feeRate := c.localCommitChain.tip().feePerKw
|
||||
feeRate := c.commitChains.Local.tip().feePerKw
|
||||
currentFee := feeRate.FeeForWeight(weight)
|
||||
|
||||
maxBalance := balance.ToSatoshis() + currentFee
|
||||
@@ -7756,7 +7762,7 @@ func TestIdealCommitFeeRate(t *testing.T) {
|
||||
// currentFeeRate calculates the current fee rate of the channel. The
|
||||
// ideal fee rate is floored at the current fee rate of the channel.
|
||||
currentFeeRate := func(c *LightningChannel) chainfee.SatPerKWeight {
|
||||
return c.localCommitChain.tip().feePerKw
|
||||
return c.commitChains.Local.tip().feePerKw
|
||||
}
|
||||
|
||||
// testCase definies the test cases when calculating the ideal fee rate
|
||||
@@ -11099,7 +11105,7 @@ func TestBlindingPointPersistence(t *testing.T) {
|
||||
require.NoError(t, err, "unable to restart alice")
|
||||
|
||||
// Assert that the blinding point is restored from disk.
|
||||
remoteCommit := aliceChannel.remoteCommitChain.tip()
|
||||
remoteCommit := aliceChannel.commitChains.Remote.tip()
|
||||
require.Len(t, remoteCommit.outgoingHTLCs, 1)
|
||||
require.Equal(t, blinding,
|
||||
remoteCommit.outgoingHTLCs[0].BlindingPoint.UnwrapOrFailV(t))
|
||||
@@ -11116,7 +11122,7 @@ func TestBlindingPointPersistence(t *testing.T) {
|
||||
require.NoError(t, err, "unable to restart bob's channel")
|
||||
|
||||
// Assert that Bob is able to recover the blinding point from disk.
|
||||
bobCommit := bobChannel.localCommitChain.tip()
|
||||
bobCommit := bobChannel.commitChains.Local.tip()
|
||||
require.Len(t, bobCommit.incomingHTLCs, 1)
|
||||
require.Equal(t, blinding,
|
||||
bobCommit.incomingHTLCs[0].BlindingPoint.UnwrapOrFailV(t))
|
||||
|
||||
Reference in new issue
Block a user