From 9fc2dbdefcde0d5cb653392e6b2333a0dddac8a1 Mon Sep 17 00:00:00 2001 From: Calvin Zachman Date: Wed, 15 Feb 2023 15:18:04 +0100 Subject: [PATCH] lnwallet: start fixing up tests remove all traces of PaymentDescriptor from test cases as well --- lnwallet/channel.go | 8 +- lnwallet/channel_test.go | 1277 ++++++++++++++++++--------------- lnwallet/log_entry.go | 2 + lnwallet/transactions_test.go | 11 +- 4 files changed, 714 insertions(+), 584 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 95df0fc460..2cb1e6b652 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -4770,12 +4770,12 @@ func (lc *LightningChannel) RevokeCurrentCommitment() (*lnwire.RevokeAndAck, // that was revoked. // 2. The LogEntry of any Add HTLCs that were locked in by this // revocation. -// 3. The LogEntry of any Settle/Fail HTLCs that were locked in by +// 3. The (Child)LogEntry of any Settle/Fail HTLCs that were locked in by // this revocation. // 4. The set of HTLCs present on the current valid commitment transaction // for the remote party. func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) ( - *channeldb.FwdPkg, []LogEntry, []LogEntry, + *channeldb.FwdPkg, []LogEntry, []ChildLogEntry, []channeldb.HTLC, error) { lc.Lock() @@ -4829,7 +4829,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) ( var ( addsToForward []LogEntry addUpdates []channeldb.LogUpdate - settleFailsToForward []LogEntry + settleFailsToForward []ChildLogEntry settleFailUpdates []channeldb.LogUpdate ) @@ -4912,7 +4912,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) ( logEntry.MarkForwarded() settleFailsToForward = append( - settleFailsToForward, logEntry, + settleFailsToForward, childEntry, ) default: diff --git a/lnwallet/channel_test.go b/lnwallet/channel_test.go index d3cec2d263..fe3c415c15 100644 --- a/lnwallet/channel_test.go +++ b/lnwallet/channel_test.go @@ -1793,8 +1793,8 @@ func TestStateUpdatePersistence(t *testing.T) { // Newly generated pkScripts for HTLCs should be the same as in the old channel. for _, entry := range aliceChannel.localUpdateLog.htlcIndex { - htlc := entry.Value.(*PaymentDescriptor) - restoredHtlc := aliceChannelNew.localUpdateLog.lookupHtlc(htlc.HtlcIndex) + htlc := entry.Value.(*AddLogEntry) + restoredHtlc := aliceChannelNew.localUpdateLog.lookupHtlc(htlc.LogIndex()) if !bytes.Equal(htlc.ourPkScript, restoredHtlc.ourPkScript) { t.Fatalf("alice ourPkScript in ourLog: expected %X, got %X", htlc.ourPkScript[:5], restoredHtlc.ourPkScript[:5]) @@ -1805,8 +1805,8 @@ func TestStateUpdatePersistence(t *testing.T) { } } for _, entry := range aliceChannel.remoteUpdateLog.htlcIndex { - htlc := entry.Value.(*PaymentDescriptor) - restoredHtlc := aliceChannelNew.remoteUpdateLog.lookupHtlc(htlc.HtlcIndex) + htlc := entry.Value.(*AddLogEntry) + restoredHtlc := aliceChannelNew.remoteUpdateLog.lookupHtlc(htlc.LogIndex()) if !bytes.Equal(htlc.ourPkScript, restoredHtlc.ourPkScript) { t.Fatalf("alice ourPkScript in theirLog: expected %X, got %X", htlc.ourPkScript[:5], restoredHtlc.ourPkScript[:5]) @@ -1817,8 +1817,8 @@ func TestStateUpdatePersistence(t *testing.T) { } } for _, entry := range bobChannel.localUpdateLog.htlcIndex { - htlc := entry.Value.(*PaymentDescriptor) - restoredHtlc := bobChannelNew.localUpdateLog.lookupHtlc(htlc.HtlcIndex) + htlc := entry.Value.(*AddLogEntry) + restoredHtlc := bobChannelNew.localUpdateLog.lookupHtlc(htlc.LogIndex()) if !bytes.Equal(htlc.ourPkScript, restoredHtlc.ourPkScript) { t.Fatalf("bob ourPkScript in ourLog: expected %X, got %X", htlc.ourPkScript[:5], restoredHtlc.ourPkScript[:5]) @@ -1829,8 +1829,8 @@ func TestStateUpdatePersistence(t *testing.T) { } } for _, entry := range bobChannel.remoteUpdateLog.htlcIndex { - htlc := entry.Value.(*PaymentDescriptor) - restoredHtlc := bobChannelNew.remoteUpdateLog.lookupHtlc(htlc.HtlcIndex) + htlc := entry.Value.(*AddLogEntry) + restoredHtlc := bobChannelNew.remoteUpdateLog.lookupHtlc(htlc.LogIndex()) if !bytes.Equal(htlc.ourPkScript, restoredHtlc.ourPkScript) { t.Fatalf("bob ourPkScript in theirLog: expected %X, got %X", htlc.ourPkScript[:5], restoredHtlc.ourPkScript[:5]) @@ -4204,8 +4204,8 @@ func TestFeeUpdateOldDiskFormat(t *testing.T) { countLog := func(log *updateLog) (int, int) { var numUpdates, numFee int for e := log.Front(); e != nil; e = e.Next() { - htlc := e.Value.(*PaymentDescriptor) - if htlc.EntryType == FeeUpdate { + _, ok := e.Value.(*updateFeeEntry) + if ok { numFee++ } numUpdates++ @@ -5162,10 +5162,10 @@ func TestLockedInHtlcForwardingSkipAfterRestart(t *testing.T) { t.Fatalf("alice should only forward %d HTLC's, instead wants to "+ "forward %v htlcs", 1, len(settleFails)) } - if settleFails[0].ParentIndex != htlc.ID { + if settleFails[0].ParentIndex() != htlc.ID { t.Fatalf("alice should forward fail for htlcid=%d, instead "+ "forwarding id=%d", htlc.ID, - settleFails[0].ParentIndex) + settleFails[0].ParentIndex()) } // We'll now restart both Alice and Bob. This emulates a reconnection @@ -5272,10 +5272,10 @@ func TestLockedInHtlcForwardingSkipAfterRestart(t *testing.T) { t.Fatalf("alice should only forward one HTLC, instead wants to "+ "forward %v htlcs", len(settleFails)) } - if settleFails[0].ParentIndex != htlc2.ID { + if settleFails[0].ParentIndex() != htlc2.ID { t.Fatalf("alice should forward fail for htlcid=%d, instead "+ "forwarding id=%d", htlc2.ID, - settleFails[0].ParentIndex) + settleFails[0].ParentIndex()) } } @@ -6435,20 +6435,30 @@ func TestNewBreachRetributionSkipsDustHtlcs(t *testing.T) { } // compareHtlcs compares two PaymentDescriptors. -func compareHtlcs(htlc1, htlc2 *PaymentDescriptor) error { - if htlc1.LogIndex != htlc2.LogIndex { +func compareHtlcs(htlc1, htlc2 LogEntry) error { + if htlc1.LogIndex() != htlc2.LogIndex() { return fmt.Errorf("htlc log index did not match") } - if htlc1.HtlcIndex != htlc2.HtlcIndex { + if htlc1.LogIndex() != htlc2.LogIndex() { return fmt.Errorf("htlc index did not match") } - if htlc1.ParentIndex != htlc2.ParentIndex { - return fmt.Errorf("htlc parent index did not match") + + childHtlc1, ok := htlc1.(ChildLogEntry) + if !ok { + return nil } - if htlc1.RHash != htlc2.RHash { - return fmt.Errorf("htlc rhash did not match") + childHtlc2, ok := htlc2.(ChildLogEntry) + if !ok { + return nil } + if childHtlc1.ParentIndex() != childHtlc2.ParentIndex() { + return fmt.Errorf("htlc parent index did not match") + } + + // if htlc1.RHash != htlc2.RHash { + // return fmt.Errorf("htlc rhash did not match") + // } return nil } @@ -6460,7 +6470,7 @@ func compareIndexes(a, b map[uint64]*list.Element) error { return fmt.Errorf("element with key %d "+ "not found in b", k1) } - htlc1, htlc2 := e1.Value.(*PaymentDescriptor), e2.Value.(*PaymentDescriptor) + htlc1, htlc2 := e1.Value.(LogEntry), e2.Value.(LogEntry) if err := compareHtlcs(htlc1, htlc2); err != nil { return err } @@ -6472,7 +6482,7 @@ func compareIndexes(a, b map[uint64]*list.Element) error { return fmt.Errorf("element with key %d not "+ "found in a", k1) } - htlc1, htlc2 := e1.Value.(*PaymentDescriptor), e2.Value.(*PaymentDescriptor) + htlc1, htlc2 := e1.Value.(LogEntry), e2.Value.(LogEntry) if err := compareHtlcs(htlc1, htlc2); err != nil { return err } @@ -6507,7 +6517,7 @@ func compareLogs(a, b *updateLog) error { e1, e2 := a.Front(), b.Front() for ; e1 != nil; e1, e2 = e1.Next(), e2.Next() { - htlc1, htlc2 := e1.Value.(*PaymentDescriptor), e2.Value.(*PaymentDescriptor) + htlc1, htlc2 := e1.Value.(LogEntry), e2.Value.(LogEntry) if err := compareHtlcs(htlc1, htlc2); err != nil { return err } @@ -6615,10 +6625,11 @@ func TestChannelRestoreUpdateLogs(t *testing.T) { func fetchNumUpdates(t updateType, log *updateLog) int { num := 0 for e := log.Front(); e != nil; e = e.Next() { - htlc := e.Value.(*PaymentDescriptor) - if htlc.EntryType == t { - num++ - } + // htlc := e.Value.(LogEntry) + _ = e.Value.(LogEntry) + // if htlc.EntryType == t { + num++ + // } } return num } @@ -6919,7 +6930,7 @@ func TestChannelRestoreCommitHeight(t *testing.T) { t.Fatalf("unable to create new channel: %v", err) } - var pd *PaymentDescriptor + var pd *AddLogEntry if remoteLog { if newChannel.localUpdateLog.lookupHtlc(htlcIndex) != nil { t.Fatalf("htlc found in wrong log") @@ -7491,8 +7502,8 @@ func TestFetchParent(t *testing.T) { name string remoteChain bool remoteLog bool - localEntries []*PaymentDescriptor - remoteEntries []*PaymentDescriptor + localEntries []LogEntry + remoteEntries []LogEntry // parentIndex is the parent index of the entry that we will // lookup with fetch parent. @@ -7526,19 +7537,23 @@ func TestFetchParent(t *testing.T) { { name: "remote log + chain, remote add height 0", localEntries: nil, - remoteEntries: []*PaymentDescriptor{ + remoteEntries: []LogEntry{ // This entry will be added at log index =0. - { - HtlcIndex: 1, - addCommitHeightLocal: 100, - addCommitHeightRemote: 100, + &AddLogEntry{ + HtlcIndex: 1, + openCircuitDesc: openCircuitDesc{ + addCommitHeightLocal: 100, + addCommitHeightRemote: 100, + }, }, // This entry will be added at log index =1, it // is the parent entry we are looking for. - { - HtlcIndex: 2, - addCommitHeightLocal: 100, - addCommitHeightRemote: 0, + &AddLogEntry{ + HtlcIndex: 2, + openCircuitDesc: openCircuitDesc{ + addCommitHeightLocal: 100, + addCommitHeightRemote: 0, + }, }, }, remoteChain: true, @@ -7548,19 +7563,23 @@ func TestFetchParent(t *testing.T) { }, { name: "remote log, local chain, local add height 0", - remoteEntries: []*PaymentDescriptor{ + remoteEntries: []LogEntry{ // This entry will be added at log index =0. - { - HtlcIndex: 1, - addCommitHeightLocal: 100, - addCommitHeightRemote: 100, + &AddLogEntry{ + HtlcIndex: 1, + openCircuitDesc: openCircuitDesc{ + addCommitHeightLocal: 100, + addCommitHeightRemote: 100, + }, }, // This entry will be added at log index =1, it // is the parent entry we are looking for. - { - HtlcIndex: 2, - addCommitHeightLocal: 0, - addCommitHeightRemote: 100, + &AddLogEntry{ + HtlcIndex: 2, + openCircuitDesc: openCircuitDesc{ + addCommitHeightLocal: 0, + addCommitHeightRemote: 100, + }, }, }, localEntries: nil, @@ -7571,19 +7590,23 @@ func TestFetchParent(t *testing.T) { }, { name: "local log + chain, local add height 0", - localEntries: []*PaymentDescriptor{ + localEntries: []LogEntry{ // This entry will be added at log index =0. - { - HtlcIndex: 1, - addCommitHeightLocal: 100, - addCommitHeightRemote: 100, + &AddLogEntry{ + HtlcIndex: 1, + openCircuitDesc: openCircuitDesc{ + addCommitHeightLocal: 100, + addCommitHeightRemote: 100, + }, }, // This entry will be added at log index =1, it // is the parent entry we are looking for. - { - HtlcIndex: 2, - addCommitHeightLocal: 0, - addCommitHeightRemote: 100, + &AddLogEntry{ + HtlcIndex: 2, + openCircuitDesc: openCircuitDesc{ + addCommitHeightLocal: 0, + addCommitHeightRemote: 100, + }, }, }, remoteEntries: nil, @@ -7595,19 +7618,23 @@ func TestFetchParent(t *testing.T) { { name: "local log + remote chain, remote add height 0", - localEntries: []*PaymentDescriptor{ + localEntries: []LogEntry{ // This entry will be added at log index =0. - { - HtlcIndex: 1, - addCommitHeightLocal: 100, - addCommitHeightRemote: 100, + &AddLogEntry{ + HtlcIndex: 1, + openCircuitDesc: openCircuitDesc{ + addCommitHeightLocal: 100, + addCommitHeightRemote: 100, + }, }, // This entry will be added at log index =1, it // is the parent entry we are looking for. - { - HtlcIndex: 2, - addCommitHeightLocal: 100, - addCommitHeightRemote: 0, + &AddLogEntry{ + HtlcIndex: 2, + openCircuitDesc: openCircuitDesc{ + addCommitHeightLocal: 100, + addCommitHeightRemote: 0, + }, }, }, remoteEntries: nil, @@ -7619,19 +7646,23 @@ func TestFetchParent(t *testing.T) { { name: "remote log found", localEntries: nil, - remoteEntries: []*PaymentDescriptor{ + remoteEntries: []LogEntry{ // This entry will be added at log index =0. - { - HtlcIndex: 1, - addCommitHeightLocal: 100, - addCommitHeightRemote: 0, + &AddLogEntry{ + HtlcIndex: 1, + openCircuitDesc: openCircuitDesc{ + addCommitHeightLocal: 100, + addCommitHeightRemote: 0, + }, }, // This entry will be added at log index =1, it // is the parent entry we are looking for. - { - HtlcIndex: 2, - addCommitHeightLocal: 100, - addCommitHeightRemote: 100, + &AddLogEntry{ + HtlcIndex: 2, + openCircuitDesc: openCircuitDesc{ + addCommitHeightLocal: 100, + addCommitHeightRemote: 100, + }, }, }, remoteChain: true, @@ -7642,19 +7673,23 @@ func TestFetchParent(t *testing.T) { }, { name: "local log found", - localEntries: []*PaymentDescriptor{ + localEntries: []LogEntry{ // This entry will be added at log index =0. - { - HtlcIndex: 1, - addCommitHeightLocal: 0, - addCommitHeightRemote: 100, + &AddLogEntry{ + HtlcIndex: 1, + openCircuitDesc: openCircuitDesc{ + addCommitHeightLocal: 0, + addCommitHeightRemote: 100, + }, }, // This entry will be added at log index =1, it // is the parent entry we are looking for. - { - HtlcIndex: 2, - addCommitHeightLocal: 100, - addCommitHeightRemote: 100, + &AddLogEntry{ + HtlcIndex: 2, + openCircuitDesc: openCircuitDesc{ + addCommitHeightLocal: 100, + addCommitHeightRemote: 100, + }, }, }, remoteEntries: nil, @@ -7686,8 +7721,10 @@ func TestFetchParent(t *testing.T) { } parent, err := lc.fetchParent( - &PaymentDescriptor{ - ParentIndex: test.parentIndex, + &SettleLogEntry{ + closeCircuitDesc: closeCircuitDesc{ + ParentIndex: test.parentIndex, + }, }, test.remoteChain, test.remoteLog, @@ -7749,8 +7786,8 @@ func TestEvaluateView(t *testing.T) { tests := []struct { name string - ourHtlcs []*PaymentDescriptor - theirHtlcs []*PaymentDescriptor + ourHtlcs []LogEntry + theirHtlcs []LogEntry remoteChain bool mutateState bool @@ -7782,10 +7819,10 @@ func TestEvaluateView(t *testing.T) { name: "our fee update is applied", remoteChain: false, mutateState: false, - ourHtlcs: []*PaymentDescriptor{ - { - Amount: ourFeeUpdateAmt, - EntryType: FeeUpdate, + ourHtlcs: []LogEntry{ + &updateFeeEntry{ + // Amount: ourFeeUpdateAmt, + // EntryType: FeeUpdate, }, }, theirHtlcs: nil, @@ -7799,11 +7836,11 @@ func TestEvaluateView(t *testing.T) { name: "their fee update is applied", remoteChain: false, mutateState: false, - ourHtlcs: []*PaymentDescriptor{}, - theirHtlcs: []*PaymentDescriptor{ - { - Amount: theirFeeUpdateAmt, - EntryType: FeeUpdate, + ourHtlcs: []LogEntry{}, + theirHtlcs: []LogEntry{ + &updateFeeEntry{ + // Amount: theirFeeUpdateAmt, + // EntryType: FeeUpdate, }, }, expectedFee: theirFeeUpdatePerSat, @@ -7817,23 +7854,23 @@ func TestEvaluateView(t *testing.T) { name: "htlcs adds without settles", remoteChain: false, mutateState: false, - ourHtlcs: []*PaymentDescriptor{ - { + ourHtlcs: []LogEntry{ + &AddLogEntry{ HtlcIndex: 0, Amount: htlcAddAmount, - EntryType: Add, + // EntryType: Add, }, }, - theirHtlcs: []*PaymentDescriptor{ - { + theirHtlcs: []LogEntry{ + &AddLogEntry{ HtlcIndex: 0, Amount: htlcAddAmount, - EntryType: Add, + // EntryType: Add, }, - { + &AddLogEntry{ HtlcIndex: 1, Amount: htlcAddAmount, - EntryType: Add, + // EntryType: Add, }, }, expectedFee: feePerKw, @@ -7851,27 +7888,31 @@ func TestEvaluateView(t *testing.T) { name: "our htlc settled, state mutated", remoteChain: false, mutateState: true, - ourHtlcs: []*PaymentDescriptor{ - { - HtlcIndex: 0, - Amount: htlcAddAmount, - EntryType: Add, - addCommitHeightLocal: addHeight, + ourHtlcs: []LogEntry{ + &AddLogEntry{ + HtlcIndex: 0, + Amount: htlcAddAmount, + // EntryType: Add, + openCircuitDesc: openCircuitDesc{ + addCommitHeightLocal: addHeight, + }, }, }, - theirHtlcs: []*PaymentDescriptor{ - { + theirHtlcs: []LogEntry{ + &AddLogEntry{ HtlcIndex: 0, Amount: htlcAddAmount, - EntryType: Add, + // EntryType: Add, }, - { - HtlcIndex: 1, - Amount: htlcAddAmount, - EntryType: Settle, + &SettleLogEntry{ + LogEntryIndex: 1, + Amount: htlcAddAmount, + // EntryType: Settle, // Map their htlc settle update to our // htlc add (0). - ParentIndex: 0, + closeCircuitDesc: closeCircuitDesc{ + ParentIndex: 0, + }, }, }, expectedFee: feePerKw, @@ -7886,27 +7927,31 @@ func TestEvaluateView(t *testing.T) { name: "our htlc settled, state not mutated", remoteChain: false, mutateState: false, - ourHtlcs: []*PaymentDescriptor{ - { - HtlcIndex: 0, - Amount: htlcAddAmount, - EntryType: Add, - addCommitHeightLocal: addHeight, + ourHtlcs: []LogEntry{ + &AddLogEntry{ + HtlcIndex: 0, + Amount: htlcAddAmount, + // EntryType: Add, + openCircuitDesc: openCircuitDesc{ + addCommitHeightLocal: addHeight, + }, }, }, - theirHtlcs: []*PaymentDescriptor{ - { + theirHtlcs: []LogEntry{ + &AddLogEntry{ HtlcIndex: 0, Amount: htlcAddAmount, - EntryType: Add, + // EntryType: Add, }, - { - HtlcIndex: 1, - Amount: htlcAddAmount, - EntryType: Settle, + &SettleLogEntry{ + LogEntryIndex: 1, + Amount: htlcAddAmount, + // EntryType: Settle, // Map their htlc settle update to our // htlc add (0). - ParentIndex: 0, + closeCircuitDesc: closeCircuitDesc{ + ParentIndex: 0, + }, }, }, expectedFee: feePerKw, @@ -7921,33 +7966,39 @@ func TestEvaluateView(t *testing.T) { name: "their htlc settled, state mutated", remoteChain: false, mutateState: true, - ourHtlcs: []*PaymentDescriptor{ - { + ourHtlcs: []LogEntry{ + &AddLogEntry{ HtlcIndex: 0, Amount: htlcAddAmount, - EntryType: Add, + // EntryType: Add, }, - { - HtlcIndex: 1, - Amount: htlcAddAmount, - EntryType: Settle, + &SettleLogEntry{ + LogEntryIndex: 1, + Amount: htlcAddAmount, + // EntryType: Settle, // Map our htlc settle update to their // htlc add (1). - ParentIndex: 1, + closeCircuitDesc: closeCircuitDesc{ + ParentIndex: 1, + }, }, }, - theirHtlcs: []*PaymentDescriptor{ - { - HtlcIndex: 0, - Amount: htlcAddAmount, - EntryType: Add, - addCommitHeightLocal: addHeight, + theirHtlcs: []LogEntry{ + &AddLogEntry{ + HtlcIndex: 0, + Amount: htlcAddAmount, + // EntryType: Add, + openCircuitDesc: openCircuitDesc{ + addCommitHeightLocal: addHeight, + }, }, - { - HtlcIndex: 1, - Amount: htlcAddAmount, - EntryType: Add, - addCommitHeightLocal: addHeight, + &AddLogEntry{ + HtlcIndex: 1, + Amount: htlcAddAmount, + // EntryType: Add, + openCircuitDesc: openCircuitDesc{ + addCommitHeightLocal: addHeight, + }, }, }, expectedFee: feePerKw, @@ -7964,27 +8015,31 @@ func TestEvaluateView(t *testing.T) { name: "their htlc settled, state not mutated", remoteChain: false, mutateState: false, - ourHtlcs: []*PaymentDescriptor{ - { + ourHtlcs: []LogEntry{ + &AddLogEntry{ HtlcIndex: 0, Amount: htlcAddAmount, - EntryType: Add, + // EntryType: Add, }, - { - HtlcIndex: 1, - Amount: htlcAddAmount, - EntryType: Settle, + &SettleLogEntry{ + LogEntryIndex: 1, + Amount: htlcAddAmount, + // EntryType: Settle, // Map our htlc settle update to their // htlc add (0). - ParentIndex: 0, + closeCircuitDesc: closeCircuitDesc{ + ParentIndex: 0, + }, }, }, - theirHtlcs: []*PaymentDescriptor{ - { - HtlcIndex: 0, - Amount: htlcAddAmount, - EntryType: Add, - addCommitHeightLocal: addHeight, + theirHtlcs: []LogEntry{ + &AddLogEntry{ + HtlcIndex: 0, + Amount: htlcAddAmount, + // EntryType: Add, + openCircuitDesc: openCircuitDesc{ + addCommitHeightLocal: addHeight, + }, }, }, expectedFee: feePerKw, @@ -8013,7 +8068,8 @@ func TestEvaluateView(t *testing.T) { } for _, htlc := range test.ourHtlcs { - if htlc.EntryType == Add { + if _, ok := htlc.(*AddLogEntry); ok { + // if htlc.EntryType == Add { lc.localUpdateLog.appendHtlc(htlc) } else { lc.localUpdateLog.appendUpdate(htlc) @@ -8021,7 +8077,8 @@ func TestEvaluateView(t *testing.T) { } for _, htlc := range test.theirHtlcs { - if htlc.EntryType == Add { + if _, ok := htlc.(*AddLogEntry); ok { + // if htlc.EntryType == Add { lc.remoteUpdateLog.appendHtlc(htlc) } else { lc.remoteUpdateLog.appendUpdate(htlc) @@ -8084,7 +8141,7 @@ func TestEvaluateView(t *testing.T) { // checkExpectedHtlcs checks that a set of htlcs that we have contains all the // htlcs we expect. -func checkExpectedHtlcs(t *testing.T, actual []*PaymentDescriptor, +func checkExpectedHtlcs(t *testing.T, actual []LogEntry, expected map[uint64]bool) { if len(expected) != len(actual) { @@ -8093,10 +8150,10 @@ func checkExpectedHtlcs(t *testing.T, actual []*PaymentDescriptor, } for _, htlc := range actual { - _, ok := expected[htlc.HtlcIndex] + _, ok := expected[htlc.LogIndex()] if !ok { t.Fatalf("htlc with index: %v not "+ - "expected in set", htlc.HtlcIndex) + "expected in set", htlc.LogIndex()) } } } @@ -8276,13 +8333,13 @@ func TestProcessFeeUpdate(t *testing.T) { // Create a fee update with add and remove heights as // set in the test. heights := test.startHeights - update := &PaymentDescriptor{ - Amount: ourFeeUpdateAmt, + update := &updateFeeEntry{ + // Amount: ourFeeUpdateAmt, addCommitHeightRemote: heights.remoteAdd, addCommitHeightLocal: heights.localAdd, removeCommitHeightRemote: heights.remoteRemove, removeCommitHeightLocal: heights.localRemove, - EntryType: FeeUpdate, + // EntryType: FeeUpdate, } view := &htlcView{ @@ -8303,7 +8360,7 @@ func TestProcessFeeUpdate(t *testing.T) { } } -func checkHeights(t *testing.T, update *PaymentDescriptor, expected heights) { +func checkHeights(t *testing.T, update *updateFeeEntry, expected heights) { updateHeights := heights{ localAdd: update.addCommitHeightLocal, localRemove: update.removeCommitHeightLocal, @@ -8316,409 +8373,475 @@ func checkHeights(t *testing.T, update *PaymentDescriptor, expected heights) { } } -// TestProcessAddRemoveEntry tests the updating of our and their balances when -// we process adds, settles and fails. It also tests the mutating of add and -// remove heights. -func TestProcessAddRemoveEntry(t *testing.T) { - const ( - // addHeight is a non-zero addHeight that is used for htlc - // add heights. - addHeight = 100 - - // removeHeight is a non-zero removeHeight that is used for - // htlc remove heights. - removeHeight = 200 - - // nextHeight is a constant that we use for the nextHeight in - // all unit tests. - nextHeight = 400 - - // updateAmount is the amount that the update is set to. - updateAmount = lnwire.MilliSatoshi(10) - - // startBalance is a balance we start both sides out with - // so that balances can be incremented. - startBalance = lnwire.MilliSatoshi(100) - ) - - tests := []struct { - name string - startHeights heights - remoteChain bool - isIncoming bool - mutateState bool - ourExpectedBalance lnwire.MilliSatoshi - theirExpectedBalance lnwire.MilliSatoshi - expectedHeights heights - updateType updateType - }{ - { - name: "add, remote chain, already processed", - startHeights: heights{ - localAdd: 0, - remoteAdd: addHeight, - localRemove: 0, - remoteRemove: 0, - }, - remoteChain: true, - isIncoming: false, - mutateState: false, - ourExpectedBalance: startBalance, - theirExpectedBalance: startBalance, - expectedHeights: heights{ - localAdd: 0, - remoteAdd: addHeight, - localRemove: 0, - remoteRemove: 0, - }, - updateType: Add, - }, - { - name: "add, local chain, already processed", - startHeights: heights{ - localAdd: addHeight, - remoteAdd: 0, - localRemove: 0, - remoteRemove: 0, - }, - remoteChain: false, - isIncoming: false, - mutateState: false, - ourExpectedBalance: startBalance, - theirExpectedBalance: startBalance, - expectedHeights: heights{ - localAdd: addHeight, - remoteAdd: 0, - localRemove: 0, - remoteRemove: 0, - }, - updateType: Add, - }, - { - name: "incoming add, local chain, not mutated", - startHeights: heights{ - localAdd: 0, - remoteAdd: 0, - localRemove: 0, - remoteRemove: 0, - }, - remoteChain: false, - isIncoming: true, - mutateState: false, - ourExpectedBalance: startBalance, - theirExpectedBalance: startBalance - updateAmount, - expectedHeights: heights{ - localAdd: 0, - remoteAdd: 0, - localRemove: 0, - remoteRemove: 0, - }, - updateType: Add, - }, - { - name: "incoming add, local chain, mutated", - startHeights: heights{ - localAdd: 0, - remoteAdd: 0, - localRemove: 0, - remoteRemove: 0, - }, - remoteChain: false, - isIncoming: true, - mutateState: true, - ourExpectedBalance: startBalance, - theirExpectedBalance: startBalance - updateAmount, - expectedHeights: heights{ - localAdd: nextHeight, - remoteAdd: 0, - localRemove: 0, - remoteRemove: 0, - }, - updateType: Add, - }, - - { - name: "outgoing add, remote chain, not mutated", - startHeights: heights{ - localAdd: 0, - remoteAdd: 0, - localRemove: 0, - remoteRemove: 0, - }, - remoteChain: true, - isIncoming: false, - mutateState: false, - ourExpectedBalance: startBalance - updateAmount, - theirExpectedBalance: startBalance, - expectedHeights: heights{ - localAdd: 0, - remoteAdd: 0, - localRemove: 0, - remoteRemove: 0, - }, - updateType: Add, - }, - { - name: "outgoing add, remote chain, mutated", - startHeights: heights{ - localAdd: 0, - remoteAdd: 0, - localRemove: 0, - remoteRemove: 0, - }, - remoteChain: true, - isIncoming: false, - mutateState: true, - ourExpectedBalance: startBalance - updateAmount, - theirExpectedBalance: startBalance, - expectedHeights: heights{ - localAdd: 0, - remoteAdd: nextHeight, - localRemove: 0, - remoteRemove: 0, - }, - updateType: Add, - }, - { - name: "settle, remote chain, already processed", - startHeights: heights{ - localAdd: addHeight, - remoteAdd: addHeight, - localRemove: 0, - remoteRemove: removeHeight, - }, - remoteChain: true, - isIncoming: false, - mutateState: false, - ourExpectedBalance: startBalance, - theirExpectedBalance: startBalance, - expectedHeights: heights{ - localAdd: addHeight, - remoteAdd: addHeight, - localRemove: 0, - remoteRemove: removeHeight, - }, - updateType: Settle, - }, - { - name: "settle, local chain, already processed", - startHeights: heights{ - localAdd: addHeight, - remoteAdd: addHeight, - localRemove: removeHeight, - remoteRemove: 0, - }, - remoteChain: false, - isIncoming: false, - mutateState: false, - ourExpectedBalance: startBalance, - theirExpectedBalance: startBalance, - expectedHeights: heights{ - localAdd: addHeight, - remoteAdd: addHeight, - localRemove: removeHeight, - remoteRemove: 0, - }, - updateType: Settle, - }, - { - // Remote chain, and not processed yet. Incoming settle, - // so we expect our balance to increase. - name: "incoming settle", - startHeights: heights{ - localAdd: addHeight, - remoteAdd: addHeight, - localRemove: 0, - remoteRemove: 0, - }, - remoteChain: true, - isIncoming: true, - mutateState: false, - ourExpectedBalance: startBalance + updateAmount, - theirExpectedBalance: startBalance, - expectedHeights: heights{ - localAdd: addHeight, - remoteAdd: addHeight, - localRemove: 0, - remoteRemove: 0, - }, - updateType: Settle, - }, - { - // Remote chain, and not processed yet. Incoming settle, - // so we expect our balance to increase. - name: "outgoing settle", - startHeights: heights{ - localAdd: addHeight, - remoteAdd: addHeight, - localRemove: 0, - remoteRemove: 0, - }, - remoteChain: true, - isIncoming: false, - mutateState: false, - ourExpectedBalance: startBalance, - theirExpectedBalance: startBalance + updateAmount, - expectedHeights: heights{ - localAdd: addHeight, - remoteAdd: addHeight, - localRemove: 0, - remoteRemove: 0, - }, - updateType: Settle, - }, - { - // Remote chain, and not processed yet. Incoming fail, - // so we expect their balance to increase. - name: "incoming fail", - startHeights: heights{ - localAdd: addHeight, - remoteAdd: addHeight, - localRemove: 0, - remoteRemove: 0, - }, - remoteChain: true, - isIncoming: true, - mutateState: false, - ourExpectedBalance: startBalance, - theirExpectedBalance: startBalance + updateAmount, - expectedHeights: heights{ - localAdd: addHeight, - remoteAdd: addHeight, - localRemove: 0, - remoteRemove: 0, - }, - updateType: Fail, - }, - { - // Remote chain, and not processed yet. Outgoing fail, - // so we expect our balance to increase. - name: "outgoing fail", - startHeights: heights{ - localAdd: addHeight, - remoteAdd: addHeight, - localRemove: 0, - remoteRemove: 0, - }, - remoteChain: true, - isIncoming: false, - mutateState: false, - ourExpectedBalance: startBalance + updateAmount, - theirExpectedBalance: startBalance, - expectedHeights: heights{ - localAdd: addHeight, - remoteAdd: addHeight, - localRemove: 0, - remoteRemove: 0, - }, - updateType: Fail, - }, - { - // Local chain, and not processed yet. Incoming settle, - // so we expect our balance to increase. Mutate is - // true, so we expect our remove removeHeight to have - // changed. - name: "fail, our remove height mutated", - startHeights: heights{ - localAdd: addHeight, - remoteAdd: addHeight, - localRemove: 0, - remoteRemove: 0, - }, - remoteChain: false, - isIncoming: true, - mutateState: true, - ourExpectedBalance: startBalance + updateAmount, - theirExpectedBalance: startBalance, - expectedHeights: heights{ - localAdd: addHeight, - remoteAdd: addHeight, - localRemove: nextHeight, - remoteRemove: 0, - }, - updateType: Settle, - }, - { - // Remote chain, and not processed yet. Incoming settle, - // so we expect our balance to increase. Mutate is - // true, so we expect their remove removeHeight to have - // changed. - name: "fail, their remove height mutated", - startHeights: heights{ - localAdd: addHeight, - remoteAdd: addHeight, - localRemove: 0, - remoteRemove: 0, - }, - remoteChain: true, - isIncoming: true, - mutateState: true, - ourExpectedBalance: startBalance + updateAmount, - theirExpectedBalance: startBalance, - expectedHeights: heights{ - localAdd: addHeight, - remoteAdd: addHeight, - localRemove: 0, - remoteRemove: nextHeight, - }, - updateType: Settle, - }, - } - - for _, test := range tests { - test := test - - t.Run(test.name, func(t *testing.T) { - t.Parallel() - - heights := test.startHeights - update := &PaymentDescriptor{ - Amount: updateAmount, - addCommitHeightLocal: heights.localAdd, - addCommitHeightRemote: heights.remoteAdd, - removeCommitHeightLocal: heights.localRemove, - removeCommitHeightRemote: heights.remoteRemove, - EntryType: test.updateType, - } - - var ( - // Start both parties off with an initial - // balance. Copy by value here so that we do - // not mutate the startBalance constant. - ourBalance, theirBalance = startBalance, - startBalance - ) - - // Choose the processing function we need based on the - // update type. Process remove is used for settles, - // fails and malformed htlcs. - process := processRemoveEntry - if test.updateType == Add { - process = processAddEntry - } - - process( - update, &ourBalance, &theirBalance, nextHeight, - test.remoteChain, test.isIncoming, - test.mutateState, - ) - - // Check that balances were updated as expected. - if ourBalance != test.ourExpectedBalance { - t.Fatalf("expected our balance: %v, got: %v", - test.ourExpectedBalance, ourBalance) - } +// updateType is the exact type of an entry within the shared HTLC log. +type updateType uint8 + +const ( + // Add is an update type that adds a new HTLC entry into the log. + // Either side can add a new pending HTLC by adding a new Add entry + // into their update log. + Add updateType = iota + + // Fail is an update type which removes a prior HTLC entry from the + // log. Adding a Fail entry to ones log will modify the _remote_ + // parties update log once a new commitment view has been evaluated + // which contains the Fail entry. + Fail + + // MalformedFail is an update type which removes a prior HTLC entry + // from the log. Adding a MalformedFail entry to ones log will modify + // the _remote_ parties update log once a new commitment view has been + // evaluated which contains the MalformedFail entry. The difference + // from Fail type lie in the different data we have to store. + MalformedFail + + // Settle is an update type which settles a prior HTLC crediting the + // balance of the receiving node. Adding a Settle entry to a log will + // result in the settle entry being removed on the log as well as the + // original add entry from the remote party's log after the next state + // transition. + Settle - if theirBalance != test.theirExpectedBalance { - t.Fatalf("expected their balance: %v, got: %v", - test.theirExpectedBalance, theirBalance) - } + // FeeUpdate is an update type sent by the channel initiator that + // updates the fee rate used when signing the commitment transaction. + FeeUpdate +) - // Check that heights on the update are as expected. - checkHeights(t, update, test.expectedHeights) - }) - } -} +// // TestProcessAddRemoveEntry tests the updating of our and their balances when +// // we process adds, settles and fails. It also tests the mutating of add and +// // remove heights. +// func TestProcessAddRemoveEntry(t *testing.T) { +// const ( +// // addHeight is a non-zero addHeight that is used for htlc +// // add heights. +// addHeight = 100 + +// // removeHeight is a non-zero removeHeight that is used for +// // htlc remove heights. +// removeHeight = 200 + +// // nextHeight is a constant that we use for the nextHeight in +// // all unit tests. +// nextHeight = 400 + +// // updateAmount is the amount that the update is set to. +// updateAmount = lnwire.MilliSatoshi(10) + +// // startBalance is a balance we start both sides out with +// // so that balances can be incremented. +// startBalance = lnwire.MilliSatoshi(100) +// ) + +// tests := []struct { +// name string +// startHeights heights +// remoteChain bool +// isIncoming bool +// mutateState bool +// ourExpectedBalance lnwire.MilliSatoshi +// theirExpectedBalance lnwire.MilliSatoshi +// expectedHeights heights +// updateType updateType +// }{ +// { +// name: "add, remote chain, already processed", +// startHeights: heights{ +// localAdd: 0, +// remoteAdd: addHeight, +// localRemove: 0, +// remoteRemove: 0, +// }, +// remoteChain: true, +// isIncoming: false, +// mutateState: false, +// ourExpectedBalance: startBalance, +// theirExpectedBalance: startBalance, +// expectedHeights: heights{ +// localAdd: 0, +// remoteAdd: addHeight, +// localRemove: 0, +// remoteRemove: 0, +// }, +// updateType: Add, +// }, +// { +// name: "add, local chain, already processed", +// startHeights: heights{ +// localAdd: addHeight, +// remoteAdd: 0, +// localRemove: 0, +// remoteRemove: 0, +// }, +// remoteChain: false, +// isIncoming: false, +// mutateState: false, +// ourExpectedBalance: startBalance, +// theirExpectedBalance: startBalance, +// expectedHeights: heights{ +// localAdd: addHeight, +// remoteAdd: 0, +// localRemove: 0, +// remoteRemove: 0, +// }, +// updateType: Add, +// }, +// { +// name: "incoming add, local chain, not mutated", +// startHeights: heights{ +// localAdd: 0, +// remoteAdd: 0, +// localRemove: 0, +// remoteRemove: 0, +// }, +// remoteChain: false, +// isIncoming: true, +// mutateState: false, +// ourExpectedBalance: startBalance, +// theirExpectedBalance: startBalance - updateAmount, +// expectedHeights: heights{ +// localAdd: 0, +// remoteAdd: 0, +// localRemove: 0, +// remoteRemove: 0, +// }, +// updateType: Add, +// }, +// { +// name: "incoming add, local chain, mutated", +// startHeights: heights{ +// localAdd: 0, +// remoteAdd: 0, +// localRemove: 0, +// remoteRemove: 0, +// }, +// remoteChain: false, +// isIncoming: true, +// mutateState: true, +// ourExpectedBalance: startBalance, +// theirExpectedBalance: startBalance - updateAmount, +// expectedHeights: heights{ +// localAdd: nextHeight, +// remoteAdd: 0, +// localRemove: 0, +// remoteRemove: 0, +// }, +// updateType: Add, +// }, + +// { +// name: "outgoing add, remote chain, not mutated", +// startHeights: heights{ +// localAdd: 0, +// remoteAdd: 0, +// localRemove: 0, +// remoteRemove: 0, +// }, +// remoteChain: true, +// isIncoming: false, +// mutateState: false, +// ourExpectedBalance: startBalance - updateAmount, +// theirExpectedBalance: startBalance, +// expectedHeights: heights{ +// localAdd: 0, +// remoteAdd: 0, +// localRemove: 0, +// remoteRemove: 0, +// }, +// updateType: Add, +// }, +// { +// name: "outgoing add, remote chain, mutated", +// startHeights: heights{ +// localAdd: 0, +// remoteAdd: 0, +// localRemove: 0, +// remoteRemove: 0, +// }, +// remoteChain: true, +// isIncoming: false, +// mutateState: true, +// ourExpectedBalance: startBalance - updateAmount, +// theirExpectedBalance: startBalance, +// expectedHeights: heights{ +// localAdd: 0, +// remoteAdd: nextHeight, +// localRemove: 0, +// remoteRemove: 0, +// }, +// updateType: Add, +// }, +// { +// name: "settle, remote chain, already processed", +// startHeights: heights{ +// localAdd: addHeight, +// remoteAdd: addHeight, +// localRemove: 0, +// remoteRemove: removeHeight, +// }, +// remoteChain: true, +// isIncoming: false, +// mutateState: false, +// ourExpectedBalance: startBalance, +// theirExpectedBalance: startBalance, +// expectedHeights: heights{ +// localAdd: addHeight, +// remoteAdd: addHeight, +// localRemove: 0, +// remoteRemove: removeHeight, +// }, +// updateType: Settle, +// }, +// { +// name: "settle, local chain, already processed", +// startHeights: heights{ +// localAdd: addHeight, +// remoteAdd: addHeight, +// localRemove: removeHeight, +// remoteRemove: 0, +// }, +// remoteChain: false, +// isIncoming: false, +// mutateState: false, +// ourExpectedBalance: startBalance, +// theirExpectedBalance: startBalance, +// expectedHeights: heights{ +// localAdd: addHeight, +// remoteAdd: addHeight, +// localRemove: removeHeight, +// remoteRemove: 0, +// }, +// updateType: Settle, +// }, +// { +// // Remote chain, and not processed yet. Incoming settle, +// // so we expect our balance to increase. +// name: "incoming settle", +// startHeights: heights{ +// localAdd: addHeight, +// remoteAdd: addHeight, +// localRemove: 0, +// remoteRemove: 0, +// }, +// remoteChain: true, +// isIncoming: true, +// mutateState: false, +// ourExpectedBalance: startBalance + updateAmount, +// theirExpectedBalance: startBalance, +// expectedHeights: heights{ +// localAdd: addHeight, +// remoteAdd: addHeight, +// localRemove: 0, +// remoteRemove: 0, +// }, +// updateType: Settle, +// }, +// { +// // Remote chain, and not processed yet. Incoming settle, +// // so we expect our balance to increase. +// name: "outgoing settle", +// startHeights: heights{ +// localAdd: addHeight, +// remoteAdd: addHeight, +// localRemove: 0, +// remoteRemove: 0, +// }, +// remoteChain: true, +// isIncoming: false, +// mutateState: false, +// ourExpectedBalance: startBalance, +// theirExpectedBalance: startBalance + updateAmount, +// expectedHeights: heights{ +// localAdd: addHeight, +// remoteAdd: addHeight, +// localRemove: 0, +// remoteRemove: 0, +// }, +// updateType: Settle, +// }, +// { +// // Remote chain, and not processed yet. Incoming fail, +// // so we expect their balance to increase. +// name: "incoming fail", +// startHeights: heights{ +// localAdd: addHeight, +// remoteAdd: addHeight, +// localRemove: 0, +// remoteRemove: 0, +// }, +// remoteChain: true, +// isIncoming: true, +// mutateState: false, +// ourExpectedBalance: startBalance, +// theirExpectedBalance: startBalance + updateAmount, +// expectedHeights: heights{ +// localAdd: addHeight, +// remoteAdd: addHeight, +// localRemove: 0, +// remoteRemove: 0, +// }, +// updateType: Fail, +// }, +// { +// // Remote chain, and not processed yet. Outgoing fail, +// // so we expect our balance to increase. +// name: "outgoing fail", +// startHeights: heights{ +// localAdd: addHeight, +// remoteAdd: addHeight, +// localRemove: 0, +// remoteRemove: 0, +// }, +// remoteChain: true, +// isIncoming: false, +// mutateState: false, +// ourExpectedBalance: startBalance + updateAmount, +// theirExpectedBalance: startBalance, +// expectedHeights: heights{ +// localAdd: addHeight, +// remoteAdd: addHeight, +// localRemove: 0, +// remoteRemove: 0, +// }, +// updateType: Fail, +// }, +// { +// // Local chain, and not processed yet. Incoming settle, +// // so we expect our balance to increase. Mutate is +// // true, so we expect our remove removeHeight to have +// // changed. +// name: "fail, our remove height mutated", +// startHeights: heights{ +// localAdd: addHeight, +// remoteAdd: addHeight, +// localRemove: 0, +// remoteRemove: 0, +// }, +// remoteChain: false, +// isIncoming: true, +// mutateState: true, +// ourExpectedBalance: startBalance + updateAmount, +// theirExpectedBalance: startBalance, +// expectedHeights: heights{ +// localAdd: addHeight, +// remoteAdd: addHeight, +// localRemove: nextHeight, +// remoteRemove: 0, +// }, +// updateType: Settle, +// }, +// { +// // Remote chain, and not processed yet. Incoming settle, +// // so we expect our balance to increase. Mutate is +// // true, so we expect their remove removeHeight to have +// // changed. +// name: "fail, their remove height mutated", +// startHeights: heights{ +// localAdd: addHeight, +// remoteAdd: addHeight, +// localRemove: 0, +// remoteRemove: 0, +// }, +// remoteChain: true, +// isIncoming: true, +// mutateState: true, +// ourExpectedBalance: startBalance + updateAmount, +// theirExpectedBalance: startBalance, +// expectedHeights: heights{ +// localAdd: addHeight, +// remoteAdd: addHeight, +// localRemove: 0, +// remoteRemove: nextHeight, +// }, +// updateType: Settle, +// }, +// } + +// for _, test := range tests { +// test := test + +// t.Run(test.name, func(t *testing.T) { +// t.Parallel() + +// heights := test.startHeights +// // update := &PaymentDescriptor{ +// // Amount: updateAmount, +// // addCommitHeightLocal: heights.localAdd, +// // addCommitHeightRemote: heights.remoteAdd, +// // removeCommitHeightLocal: heights.localRemove, +// // removeCommitHeightRemote: heights.remoteRemove, +// // // EntryType: test.updateType, +// // } +// var update LogEntry + +// switch test.updateType { +// case Add: +// update = &AddLogEntry{ +// Amount: updateAmount, +// openCircuitDesc: openCircuitDesc{ +// addCommitHeightLocal: heights.localAdd, +// addCommitHeightRemote: heights.remoteAdd, +// }, +// } +// case Settle: +// update = &SettleLogEntry{ +// Amount: updateAmount, +// closeCircuitDesc: closeCircuitDesc{ +// // ParentIndex: ?, +// removeCommitHeightLocal: heights.localRemove, +// removeCommitHeightRemote: heights.remoteRemove, +// }, +// } +// case Fail: +// update = &FailLogEntry{ +// // FailReason: []byte{}, +// closeCircuitDesc: closeCircuitDesc{ +// // ParentIndex: ?, +// removeCommitHeightLocal: heights.localRemove, +// removeCommitHeightRemote: heights.remoteRemove, +// }, +// } +// default: +// t.Logf("unexpected log entry type!") +// } + +// var ( +// // Start both parties off with an initial +// // balance. Copy by value here so that we do +// // not mutate the startBalance constant. +// ourBalance, theirBalance = startBalance, +// startBalance +// ) + +// // Choose the processing function we need based on the +// // update type. Process remove is used for settles, +// // fails and malformed htlcs. +// process := processRemoveEntry +// if test.updateType == Add { +// process = processAddEntry +// } + +// process( +// update, &ourBalance, &theirBalance, nextHeight, +// test.remoteChain, test.isIncoming, +// test.mutateState, +// ) + +// // Check that balances were updated as expected. +// if ourBalance != test.ourExpectedBalance { +// t.Fatalf("expected our balance: %v, got: %v", +// test.ourExpectedBalance, ourBalance) +// } + +// if theirBalance != test.theirExpectedBalance { +// t.Fatalf("expected their balance: %v, got: %v", +// test.theirExpectedBalance, theirBalance) +// } + +// // Check that heights on the update are as expected. +// checkHeights(t, update, test.expectedHeights) +// }) +// } +// } // TestChannelUnsignedAckedFailure tests that unsigned acked updates are // properly restored after signing for them and disconnecting. diff --git a/lnwallet/log_entry.go b/lnwallet/log_entry.go index f80a6f5458..b264476edb 100644 --- a/lnwallet/log_entry.go +++ b/lnwallet/log_entry.go @@ -18,6 +18,8 @@ type LogEntry interface { IsForwarded() bool MarkForwarded() + + // Type() // does this make any sense? } type ChildLogEntry interface { diff --git a/lnwallet/transactions_test.go b/lnwallet/transactions_test.go index b51a3f903b..954638ce89 100644 --- a/lnwallet/transactions_test.go +++ b/lnwallet/transactions_test.go @@ -379,17 +379,22 @@ func testVectors(t *testing.T, chanType channeldb.ChannelType, test testCase) { func htlcViewFromHTLCs(htlcs []channeldb.HTLC) *htlcView { var theHTLCView htlcView for _, htlc := range htlcs { - paymentDesc := &PaymentDescriptor{ + // paymentDesc := &PaymentDescriptor{ + // RHash: htlc.RHash, + // Timeout: htlc.RefundTimeout, + // Amount: htlc.Amt, + // } + addDesc := &AddLogEntry{ RHash: htlc.RHash, Timeout: htlc.RefundTimeout, Amount: htlc.Amt, } if htlc.Incoming { theHTLCView.theirUpdates = - append(theHTLCView.theirUpdates, paymentDesc) + append(theHTLCView.theirUpdates, addDesc) } else { theHTLCView.ourUpdates = - append(theHTLCView.ourUpdates, paymentDesc) + append(theHTLCView.ourUpdates, addDesc) } } return &theHTLCView