htlcswitch+lnwallet: quarantine paymentDescriptor to lnwallet
The objective of this commit is to make paymentDescriptor a private data structure so we can quarantine it to the lnwallet package. To accomplish this we had to prevent it from leaking out via the arguments or return values of the public functions in lnwallet. This naturally had consequences for the htlcswitch package as we choose other mechanisms for tracking the data that paymentDescriptor was responsible for. Astoundingly, this was highly successful and allowed us to remove a ton of redundant code. The diff for this commit represents a substantial reduction in total lines of code as well as extraneous arguments and return values from key functions. This also sets the stage for future commits where we actually will be attempting to rid lnwallet of paymentDescriptor completely.
This commit is contained in:
5 files changed
+150
-148
No files matched your search
+37
-37
@@ -6934,8 +6934,8 @@ func TestNewBreachRetributionSkipsDustHtlcs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// compareHtlcs compares two PaymentDescriptors.
|
||||
func compareHtlcs(htlc1, htlc2 *PaymentDescriptor) error {
|
||||
// compareHtlcs compares two paymentDescriptors.
|
||||
func compareHtlcs(htlc1, htlc2 *paymentDescriptor) error {
|
||||
if htlc1.LogIndex != htlc2.LogIndex {
|
||||
return fmt.Errorf("htlc log index did not match")
|
||||
}
|
||||
@@ -6953,7 +6953,7 @@ func compareHtlcs(htlc1, htlc2 *PaymentDescriptor) error {
|
||||
}
|
||||
|
||||
// compareIndexes is a helper method to compare two index maps.
|
||||
func compareIndexes(a, b map[uint64]*fn.Node[*PaymentDescriptor]) error {
|
||||
func compareIndexes(a, b map[uint64]*fn.Node[*paymentDescriptor]) error {
|
||||
for k1, e1 := range a {
|
||||
e2, ok := b[k1]
|
||||
if !ok {
|
||||
@@ -7422,7 +7422,7 @@ func TestChannelRestoreCommitHeight(t *testing.T) {
|
||||
t.Fatalf("unable to create new channel: %v", err)
|
||||
}
|
||||
|
||||
var pd *PaymentDescriptor
|
||||
var pd *paymentDescriptor
|
||||
if remoteLog {
|
||||
h := newChannel.updateLogs.Local.lookupHtlc(htlcIndex)
|
||||
if h != nil {
|
||||
@@ -8191,8 +8191,8 @@ func TestFetchParent(t *testing.T) {
|
||||
name string
|
||||
whoseCommitChain lntypes.ChannelParty
|
||||
whoseUpdateLog lntypes.ChannelParty
|
||||
localEntries []*PaymentDescriptor
|
||||
remoteEntries []*PaymentDescriptor
|
||||
localEntries []*paymentDescriptor
|
||||
remoteEntries []*paymentDescriptor
|
||||
|
||||
// parentIndex is the parent index of the entry that we will
|
||||
// lookup with fetch parent.
|
||||
@@ -8226,7 +8226,7 @@ func TestFetchParent(t *testing.T) {
|
||||
{
|
||||
name: "remote log + chain, remote add height 0",
|
||||
localEntries: nil,
|
||||
remoteEntries: []*PaymentDescriptor{
|
||||
remoteEntries: []*paymentDescriptor{
|
||||
// This entry will be added at log index =0.
|
||||
{
|
||||
HtlcIndex: 1,
|
||||
@@ -8248,7 +8248,7 @@ func TestFetchParent(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "remote log, local chain, local add height 0",
|
||||
remoteEntries: []*PaymentDescriptor{
|
||||
remoteEntries: []*paymentDescriptor{
|
||||
// This entry will be added at log index =0.
|
||||
{
|
||||
HtlcIndex: 1,
|
||||
@@ -8271,7 +8271,7 @@ func TestFetchParent(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "local log + chain, local add height 0",
|
||||
localEntries: []*PaymentDescriptor{
|
||||
localEntries: []*paymentDescriptor{
|
||||
// This entry will be added at log index =0.
|
||||
{
|
||||
HtlcIndex: 1,
|
||||
@@ -8295,7 +8295,7 @@ func TestFetchParent(t *testing.T) {
|
||||
|
||||
{
|
||||
name: "local log + remote chain, remote add height 0",
|
||||
localEntries: []*PaymentDescriptor{
|
||||
localEntries: []*paymentDescriptor{
|
||||
// This entry will be added at log index =0.
|
||||
{
|
||||
HtlcIndex: 1,
|
||||
@@ -8319,7 +8319,7 @@ func TestFetchParent(t *testing.T) {
|
||||
{
|
||||
name: "remote log found",
|
||||
localEntries: nil,
|
||||
remoteEntries: []*PaymentDescriptor{
|
||||
remoteEntries: []*paymentDescriptor{
|
||||
// This entry will be added at log index =0.
|
||||
{
|
||||
HtlcIndex: 1,
|
||||
@@ -8342,7 +8342,7 @@ func TestFetchParent(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "local log found",
|
||||
localEntries: []*PaymentDescriptor{
|
||||
localEntries: []*paymentDescriptor{
|
||||
// This entry will be added at log index =0.
|
||||
{
|
||||
HtlcIndex: 1,
|
||||
@@ -8388,7 +8388,7 @@ func TestFetchParent(t *testing.T) {
|
||||
}
|
||||
|
||||
parent, err := lc.fetchParent(
|
||||
&PaymentDescriptor{
|
||||
&paymentDescriptor{
|
||||
ParentIndex: test.parentIndex,
|
||||
},
|
||||
test.whoseCommitChain,
|
||||
@@ -8451,8 +8451,8 @@ func TestEvaluateView(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
ourHtlcs []*PaymentDescriptor
|
||||
theirHtlcs []*PaymentDescriptor
|
||||
ourHtlcs []*paymentDescriptor
|
||||
theirHtlcs []*paymentDescriptor
|
||||
whoseCommitChain lntypes.ChannelParty
|
||||
mutateState bool
|
||||
|
||||
@@ -8484,7 +8484,7 @@ func TestEvaluateView(t *testing.T) {
|
||||
name: "our fee update is applied",
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutateState: false,
|
||||
ourHtlcs: []*PaymentDescriptor{
|
||||
ourHtlcs: []*paymentDescriptor{
|
||||
{
|
||||
Amount: ourFeeUpdateAmt,
|
||||
EntryType: FeeUpdate,
|
||||
@@ -8501,8 +8501,8 @@ func TestEvaluateView(t *testing.T) {
|
||||
name: "their fee update is applied",
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutateState: false,
|
||||
ourHtlcs: []*PaymentDescriptor{},
|
||||
theirHtlcs: []*PaymentDescriptor{
|
||||
ourHtlcs: []*paymentDescriptor{},
|
||||
theirHtlcs: []*paymentDescriptor{
|
||||
{
|
||||
Amount: theirFeeUpdateAmt,
|
||||
EntryType: FeeUpdate,
|
||||
@@ -8519,14 +8519,14 @@ func TestEvaluateView(t *testing.T) {
|
||||
name: "htlcs adds without settles",
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutateState: false,
|
||||
ourHtlcs: []*PaymentDescriptor{
|
||||
ourHtlcs: []*paymentDescriptor{
|
||||
{
|
||||
HtlcIndex: 0,
|
||||
Amount: htlcAddAmount,
|
||||
EntryType: Add,
|
||||
},
|
||||
},
|
||||
theirHtlcs: []*PaymentDescriptor{
|
||||
theirHtlcs: []*paymentDescriptor{
|
||||
{
|
||||
HtlcIndex: 0,
|
||||
Amount: htlcAddAmount,
|
||||
@@ -8553,7 +8553,7 @@ func TestEvaluateView(t *testing.T) {
|
||||
name: "our htlc settled, state mutated",
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutateState: true,
|
||||
ourHtlcs: []*PaymentDescriptor{
|
||||
ourHtlcs: []*paymentDescriptor{
|
||||
{
|
||||
HtlcIndex: 0,
|
||||
Amount: htlcAddAmount,
|
||||
@@ -8561,7 +8561,7 @@ func TestEvaluateView(t *testing.T) {
|
||||
addCommitHeightLocal: addHeight,
|
||||
},
|
||||
},
|
||||
theirHtlcs: []*PaymentDescriptor{
|
||||
theirHtlcs: []*paymentDescriptor{
|
||||
{
|
||||
HtlcIndex: 0,
|
||||
Amount: htlcAddAmount,
|
||||
@@ -8588,7 +8588,7 @@ func TestEvaluateView(t *testing.T) {
|
||||
name: "our htlc settled, state not mutated",
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutateState: false,
|
||||
ourHtlcs: []*PaymentDescriptor{
|
||||
ourHtlcs: []*paymentDescriptor{
|
||||
{
|
||||
HtlcIndex: 0,
|
||||
Amount: htlcAddAmount,
|
||||
@@ -8596,7 +8596,7 @@ func TestEvaluateView(t *testing.T) {
|
||||
addCommitHeightLocal: addHeight,
|
||||
},
|
||||
},
|
||||
theirHtlcs: []*PaymentDescriptor{
|
||||
theirHtlcs: []*paymentDescriptor{
|
||||
{
|
||||
HtlcIndex: 0,
|
||||
Amount: htlcAddAmount,
|
||||
@@ -8623,7 +8623,7 @@ func TestEvaluateView(t *testing.T) {
|
||||
name: "their htlc settled, state mutated",
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutateState: true,
|
||||
ourHtlcs: []*PaymentDescriptor{
|
||||
ourHtlcs: []*paymentDescriptor{
|
||||
{
|
||||
HtlcIndex: 0,
|
||||
Amount: htlcAddAmount,
|
||||
@@ -8638,7 +8638,7 @@ func TestEvaluateView(t *testing.T) {
|
||||
ParentIndex: 1,
|
||||
},
|
||||
},
|
||||
theirHtlcs: []*PaymentDescriptor{
|
||||
theirHtlcs: []*paymentDescriptor{
|
||||
{
|
||||
HtlcIndex: 0,
|
||||
Amount: htlcAddAmount,
|
||||
@@ -8667,7 +8667,7 @@ func TestEvaluateView(t *testing.T) {
|
||||
|
||||
whoseCommitChain: lntypes.Local,
|
||||
mutateState: false,
|
||||
ourHtlcs: []*PaymentDescriptor{
|
||||
ourHtlcs: []*paymentDescriptor{
|
||||
{
|
||||
HtlcIndex: 0,
|
||||
Amount: htlcAddAmount,
|
||||
@@ -8682,7 +8682,7 @@ func TestEvaluateView(t *testing.T) {
|
||||
ParentIndex: 0,
|
||||
},
|
||||
},
|
||||
theirHtlcs: []*PaymentDescriptor{
|
||||
theirHtlcs: []*paymentDescriptor{
|
||||
{
|
||||
HtlcIndex: 0,
|
||||
Amount: htlcAddAmount,
|
||||
@@ -8789,7 +8789,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 []*paymentDescriptor,
|
||||
expected map[uint64]bool) {
|
||||
|
||||
if len(expected) != len(actual) {
|
||||
@@ -8981,7 +8981,7 @@ func TestProcessFeeUpdate(t *testing.T) {
|
||||
// Create a fee update with add and remove heights as
|
||||
// set in the test.
|
||||
heights := test.startHeights
|
||||
update := &PaymentDescriptor{
|
||||
update := &paymentDescriptor{
|
||||
Amount: ourFeeUpdateAmt,
|
||||
addCommitHeightRemote: heights.remoteAdd,
|
||||
addCommitHeightLocal: heights.localAdd,
|
||||
@@ -9008,7 +9008,7 @@ func TestProcessFeeUpdate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func checkHeights(t *testing.T, update *PaymentDescriptor, expected heights) {
|
||||
func checkHeights(t *testing.T, update *paymentDescriptor, expected heights) {
|
||||
updateHeights := heights{
|
||||
localAdd: update.addCommitHeightLocal,
|
||||
localRemove: update.removeCommitHeightLocal,
|
||||
@@ -9377,7 +9377,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
heights := test.startHeights
|
||||
update := &PaymentDescriptor{
|
||||
update := &paymentDescriptor{
|
||||
Amount: updateAmount,
|
||||
addCommitHeightLocal: heights.localAdd,
|
||||
addCommitHeightRemote: heights.remoteAdd,
|
||||
@@ -10572,7 +10572,7 @@ func testNewBreachRetribution(t *testing.T, chanType channeldb.ChannelType) {
|
||||
}
|
||||
|
||||
// TestExtractPayDescs asserts that `extractPayDescs` can correctly turn a
|
||||
// slice of htlcs into two slices of PaymentDescriptors.
|
||||
// slice of htlcs into two slices of paymentDescriptors.
|
||||
func TestExtractPayDescs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -10609,22 +10609,22 @@ func TestExtractPayDescs(t *testing.T) {
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Assert the incoming PaymentDescriptors are matched.
|
||||
// Assert the incoming paymentDescriptors are matched.
|
||||
for i, pd := range incomingPDs {
|
||||
htlc := incomings[i]
|
||||
assertPayDescMatchHTLC(t, pd, htlc)
|
||||
}
|
||||
|
||||
// Assert the outgoing PaymentDescriptors are matched.
|
||||
// Assert the outgoing paymentDescriptors are matched.
|
||||
for i, pd := range outgoingPDs {
|
||||
htlc := outgoings[i]
|
||||
assertPayDescMatchHTLC(t, pd, htlc)
|
||||
}
|
||||
}
|
||||
|
||||
// assertPayDescMatchHTLC compares a PaymentDescriptor to a channeldb.HTLC and
|
||||
// assertPayDescMatchHTLC compares a paymentDescriptor to a channeldb.HTLC and
|
||||
// asserts that the fields are matched.
|
||||
func assertPayDescMatchHTLC(t *testing.T, pd PaymentDescriptor,
|
||||
func assertPayDescMatchHTLC(t *testing.T, pd paymentDescriptor,
|
||||
htlc channeldb.HTLC) {
|
||||
|
||||
require := require.New(t)
|
||||
|
||||
Reference in new issue
Block a user