lnwallet: change bool isIncoming to new lntypes.ChannelParty
This commit removes another raw boolean value and replaces it with a more clear type/name. This will also assist us when we later try and consolidate the logic of evaluateHTLCView into a single coherent computation.
This commit is contained in:
2 files changed
+32
-27
No files matched your search
+16
-11
@@ -2954,7 +2954,8 @@ func (lc *LightningChannel) evaluateHTLCView(view *HtlcView, ourBalance,
|
|||||||
)
|
)
|
||||||
if rmvHeight == 0 {
|
if rmvHeight == 0 {
|
||||||
processRemoveEntry(
|
processRemoveEntry(
|
||||||
entry, ourBalance, theirBalance, true,
|
entry, ourBalance, theirBalance,
|
||||||
|
lntypes.Remote,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2998,7 +2999,7 @@ func (lc *LightningChannel) evaluateHTLCView(view *HtlcView, ourBalance,
|
|||||||
)
|
)
|
||||||
if rmvHeight == 0 {
|
if rmvHeight == 0 {
|
||||||
processRemoveEntry(
|
processRemoveEntry(
|
||||||
entry, ourBalance, theirBalance, false,
|
entry, ourBalance, theirBalance, lntypes.Local,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3019,7 +3020,7 @@ func (lc *LightningChannel) evaluateHTLCView(view *HtlcView, ourBalance,
|
|||||||
)
|
)
|
||||||
if addHeight == 0 {
|
if addHeight == 0 {
|
||||||
processAddEntry(
|
processAddEntry(
|
||||||
entry, ourBalance, theirBalance, false,
|
entry, ourBalance, theirBalance, lntypes.Local,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3040,7 +3041,7 @@ func (lc *LightningChannel) evaluateHTLCView(view *HtlcView, ourBalance,
|
|||||||
)
|
)
|
||||||
if addHeight == 0 {
|
if addHeight == 0 {
|
||||||
processAddEntry(
|
processAddEntry(
|
||||||
entry, ourBalance, theirBalance, true,
|
entry, ourBalance, theirBalance, lntypes.Remote,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3131,9 +3132,9 @@ func (lc *LightningChannel) fetchParent(entry *paymentDescriptor,
|
|||||||
// was committed is updated. Keeping track of this inclusion height allows us to
|
// was committed is updated. Keeping track of this inclusion height allows us to
|
||||||
// later compact the log once the change is fully committed in both chains.
|
// later compact the log once the change is fully committed in both chains.
|
||||||
func processAddEntry(htlc *paymentDescriptor, ourBalance,
|
func processAddEntry(htlc *paymentDescriptor, ourBalance,
|
||||||
theirBalance *lnwire.MilliSatoshi, isIncoming bool) {
|
theirBalance *lnwire.MilliSatoshi, originator lntypes.ChannelParty) {
|
||||||
|
|
||||||
if isIncoming {
|
if originator == lntypes.Remote {
|
||||||
// If this is a new incoming (un-committed) HTLC, then we need
|
// If this is a new incoming (un-committed) HTLC, then we need
|
||||||
// to update their balance accordingly by subtracting the
|
// to update their balance accordingly by subtracting the
|
||||||
// amount of the HTLC that are funds pending.
|
// amount of the HTLC that are funds pending.
|
||||||
@@ -3149,31 +3150,35 @@ func processAddEntry(htlc *paymentDescriptor, ourBalance,
|
|||||||
// previously added HTLC. If the removal entry has already been processed, it
|
// previously added HTLC. If the removal entry has already been processed, it
|
||||||
// is skipped.
|
// is skipped.
|
||||||
func processRemoveEntry(htlc *paymentDescriptor, ourBalance,
|
func processRemoveEntry(htlc *paymentDescriptor, ourBalance,
|
||||||
theirBalance *lnwire.MilliSatoshi, isIncoming bool) {
|
theirBalance *lnwire.MilliSatoshi, originator lntypes.ChannelParty) {
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
// If an incoming HTLC is being settled, then this means that we've
|
// If an incoming HTLC is being settled, then this means that we've
|
||||||
// received the preimage either from another subsystem, or the
|
// received the preimage either from another subsystem, or the
|
||||||
// upstream peer in the route. Therefore, we increase our balance by
|
// upstream peer in the route. Therefore, we increase our balance by
|
||||||
// the HTLC amount.
|
// the HTLC amount.
|
||||||
case isIncoming && htlc.EntryType == Settle:
|
case originator == lntypes.Remote && htlc.EntryType == Settle:
|
||||||
*ourBalance += htlc.Amount
|
*ourBalance += htlc.Amount
|
||||||
|
|
||||||
// Otherwise, this HTLC is being failed out, therefore the value of the
|
// Otherwise, this HTLC is being failed out, therefore the value of the
|
||||||
// HTLC should return to the remote party.
|
// HTLC should return to the remote party.
|
||||||
case isIncoming && (htlc.EntryType == Fail || htlc.EntryType == MalformedFail):
|
case originator == lntypes.Remote &&
|
||||||
|
(htlc.EntryType == Fail || htlc.EntryType == MalformedFail):
|
||||||
|
|
||||||
*theirBalance += htlc.Amount
|
*theirBalance += htlc.Amount
|
||||||
|
|
||||||
// If an outgoing HTLC is being settled, then this means that the
|
// If an outgoing HTLC is being settled, then this means that the
|
||||||
// downstream party resented the preimage or learned of it via a
|
// downstream party resented the preimage or learned of it via a
|
||||||
// downstream peer. In either case, we credit their settled value with
|
// downstream peer. In either case, we credit their settled value with
|
||||||
// the value of the HTLC.
|
// the value of the HTLC.
|
||||||
case !isIncoming && htlc.EntryType == Settle:
|
case originator == lntypes.Local && htlc.EntryType == Settle:
|
||||||
*theirBalance += htlc.Amount
|
*theirBalance += htlc.Amount
|
||||||
|
|
||||||
// Otherwise, one of our outgoing HTLC's has timed out, so the value of
|
// Otherwise, one of our outgoing HTLC's has timed out, so the value of
|
||||||
// the HTLC should be returned to our settled balance.
|
// the HTLC should be returned to our settled balance.
|
||||||
case !isIncoming && (htlc.EntryType == Fail || htlc.EntryType == MalformedFail):
|
case originator == lntypes.Local &&
|
||||||
|
(htlc.EntryType == Fail || htlc.EntryType == MalformedFail):
|
||||||
|
|
||||||
*ourBalance += htlc.Amount
|
*ourBalance += htlc.Amount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-16
@@ -9089,7 +9089,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
startHeights heights
|
startHeights heights
|
||||||
whoseCommitChain lntypes.ChannelParty
|
whoseCommitChain lntypes.ChannelParty
|
||||||
isIncoming bool
|
originator lntypes.ChannelParty
|
||||||
mutateState bool
|
mutateState bool
|
||||||
ourExpectedBalance lnwire.MilliSatoshi
|
ourExpectedBalance lnwire.MilliSatoshi
|
||||||
theirExpectedBalance lnwire.MilliSatoshi
|
theirExpectedBalance lnwire.MilliSatoshi
|
||||||
@@ -9105,7 +9105,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||||||
remoteRemove: 0,
|
remoteRemove: 0,
|
||||||
},
|
},
|
||||||
whoseCommitChain: lntypes.Remote,
|
whoseCommitChain: lntypes.Remote,
|
||||||
isIncoming: false,
|
originator: lntypes.Local,
|
||||||
mutateState: false,
|
mutateState: false,
|
||||||
ourExpectedBalance: startBalance,
|
ourExpectedBalance: startBalance,
|
||||||
theirExpectedBalance: startBalance,
|
theirExpectedBalance: startBalance,
|
||||||
@@ -9126,7 +9126,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||||||
remoteRemove: 0,
|
remoteRemove: 0,
|
||||||
},
|
},
|
||||||
whoseCommitChain: lntypes.Local,
|
whoseCommitChain: lntypes.Local,
|
||||||
isIncoming: false,
|
originator: lntypes.Local,
|
||||||
mutateState: false,
|
mutateState: false,
|
||||||
ourExpectedBalance: startBalance,
|
ourExpectedBalance: startBalance,
|
||||||
theirExpectedBalance: startBalance,
|
theirExpectedBalance: startBalance,
|
||||||
@@ -9147,7 +9147,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||||||
remoteRemove: 0,
|
remoteRemove: 0,
|
||||||
},
|
},
|
||||||
whoseCommitChain: lntypes.Local,
|
whoseCommitChain: lntypes.Local,
|
||||||
isIncoming: true,
|
originator: lntypes.Remote,
|
||||||
mutateState: false,
|
mutateState: false,
|
||||||
ourExpectedBalance: startBalance,
|
ourExpectedBalance: startBalance,
|
||||||
theirExpectedBalance: startBalance - updateAmount,
|
theirExpectedBalance: startBalance - updateAmount,
|
||||||
@@ -9168,7 +9168,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||||||
remoteRemove: 0,
|
remoteRemove: 0,
|
||||||
},
|
},
|
||||||
whoseCommitChain: lntypes.Local,
|
whoseCommitChain: lntypes.Local,
|
||||||
isIncoming: true,
|
originator: lntypes.Remote,
|
||||||
mutateState: true,
|
mutateState: true,
|
||||||
ourExpectedBalance: startBalance,
|
ourExpectedBalance: startBalance,
|
||||||
theirExpectedBalance: startBalance - updateAmount,
|
theirExpectedBalance: startBalance - updateAmount,
|
||||||
@@ -9190,7 +9190,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||||||
remoteRemove: 0,
|
remoteRemove: 0,
|
||||||
},
|
},
|
||||||
whoseCommitChain: lntypes.Remote,
|
whoseCommitChain: lntypes.Remote,
|
||||||
isIncoming: false,
|
originator: lntypes.Local,
|
||||||
mutateState: false,
|
mutateState: false,
|
||||||
ourExpectedBalance: startBalance - updateAmount,
|
ourExpectedBalance: startBalance - updateAmount,
|
||||||
theirExpectedBalance: startBalance,
|
theirExpectedBalance: startBalance,
|
||||||
@@ -9211,7 +9211,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||||||
remoteRemove: 0,
|
remoteRemove: 0,
|
||||||
},
|
},
|
||||||
whoseCommitChain: lntypes.Remote,
|
whoseCommitChain: lntypes.Remote,
|
||||||
isIncoming: false,
|
originator: lntypes.Local,
|
||||||
mutateState: true,
|
mutateState: true,
|
||||||
ourExpectedBalance: startBalance - updateAmount,
|
ourExpectedBalance: startBalance - updateAmount,
|
||||||
theirExpectedBalance: startBalance,
|
theirExpectedBalance: startBalance,
|
||||||
@@ -9232,7 +9232,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||||||
remoteRemove: removeHeight,
|
remoteRemove: removeHeight,
|
||||||
},
|
},
|
||||||
whoseCommitChain: lntypes.Remote,
|
whoseCommitChain: lntypes.Remote,
|
||||||
isIncoming: false,
|
originator: lntypes.Local,
|
||||||
mutateState: false,
|
mutateState: false,
|
||||||
ourExpectedBalance: startBalance,
|
ourExpectedBalance: startBalance,
|
||||||
theirExpectedBalance: startBalance,
|
theirExpectedBalance: startBalance,
|
||||||
@@ -9253,7 +9253,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||||||
remoteRemove: 0,
|
remoteRemove: 0,
|
||||||
},
|
},
|
||||||
whoseCommitChain: lntypes.Local,
|
whoseCommitChain: lntypes.Local,
|
||||||
isIncoming: false,
|
originator: lntypes.Local,
|
||||||
mutateState: false,
|
mutateState: false,
|
||||||
ourExpectedBalance: startBalance,
|
ourExpectedBalance: startBalance,
|
||||||
theirExpectedBalance: startBalance,
|
theirExpectedBalance: startBalance,
|
||||||
@@ -9276,7 +9276,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||||||
remoteRemove: 0,
|
remoteRemove: 0,
|
||||||
},
|
},
|
||||||
whoseCommitChain: lntypes.Remote,
|
whoseCommitChain: lntypes.Remote,
|
||||||
isIncoming: true,
|
originator: lntypes.Remote,
|
||||||
mutateState: false,
|
mutateState: false,
|
||||||
ourExpectedBalance: startBalance + updateAmount,
|
ourExpectedBalance: startBalance + updateAmount,
|
||||||
theirExpectedBalance: startBalance,
|
theirExpectedBalance: startBalance,
|
||||||
@@ -9299,7 +9299,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||||||
remoteRemove: 0,
|
remoteRemove: 0,
|
||||||
},
|
},
|
||||||
whoseCommitChain: lntypes.Remote,
|
whoseCommitChain: lntypes.Remote,
|
||||||
isIncoming: false,
|
originator: lntypes.Local,
|
||||||
mutateState: false,
|
mutateState: false,
|
||||||
ourExpectedBalance: startBalance,
|
ourExpectedBalance: startBalance,
|
||||||
theirExpectedBalance: startBalance + updateAmount,
|
theirExpectedBalance: startBalance + updateAmount,
|
||||||
@@ -9322,7 +9322,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||||||
remoteRemove: 0,
|
remoteRemove: 0,
|
||||||
},
|
},
|
||||||
whoseCommitChain: lntypes.Remote,
|
whoseCommitChain: lntypes.Remote,
|
||||||
isIncoming: true,
|
originator: lntypes.Remote,
|
||||||
mutateState: false,
|
mutateState: false,
|
||||||
ourExpectedBalance: startBalance,
|
ourExpectedBalance: startBalance,
|
||||||
theirExpectedBalance: startBalance + updateAmount,
|
theirExpectedBalance: startBalance + updateAmount,
|
||||||
@@ -9345,7 +9345,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||||||
remoteRemove: 0,
|
remoteRemove: 0,
|
||||||
},
|
},
|
||||||
whoseCommitChain: lntypes.Remote,
|
whoseCommitChain: lntypes.Remote,
|
||||||
isIncoming: false,
|
originator: lntypes.Local,
|
||||||
mutateState: false,
|
mutateState: false,
|
||||||
ourExpectedBalance: startBalance + updateAmount,
|
ourExpectedBalance: startBalance + updateAmount,
|
||||||
theirExpectedBalance: startBalance,
|
theirExpectedBalance: startBalance,
|
||||||
@@ -9370,7 +9370,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||||||
remoteRemove: 0,
|
remoteRemove: 0,
|
||||||
},
|
},
|
||||||
whoseCommitChain: lntypes.Local,
|
whoseCommitChain: lntypes.Local,
|
||||||
isIncoming: true,
|
originator: lntypes.Remote,
|
||||||
mutateState: true,
|
mutateState: true,
|
||||||
ourExpectedBalance: startBalance + updateAmount,
|
ourExpectedBalance: startBalance + updateAmount,
|
||||||
theirExpectedBalance: startBalance,
|
theirExpectedBalance: startBalance,
|
||||||
@@ -9395,7 +9395,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||||||
remoteRemove: 0,
|
remoteRemove: 0,
|
||||||
},
|
},
|
||||||
whoseCommitChain: lntypes.Remote,
|
whoseCommitChain: lntypes.Remote,
|
||||||
isIncoming: true,
|
originator: lntypes.Remote,
|
||||||
mutateState: true,
|
mutateState: true,
|
||||||
ourExpectedBalance: startBalance + updateAmount,
|
ourExpectedBalance: startBalance + updateAmount,
|
||||||
theirExpectedBalance: startBalance,
|
theirExpectedBalance: startBalance,
|
||||||
@@ -9450,7 +9450,7 @@ func TestProcessAddRemoveEntry(t *testing.T) {
|
|||||||
if heightDual.GetForParty(test.whoseCommitChain) == 0 {
|
if heightDual.GetForParty(test.whoseCommitChain) == 0 {
|
||||||
process(
|
process(
|
||||||
update, &ourBalance, &theirBalance,
|
update, &ourBalance, &theirBalance,
|
||||||
test.isIncoming,
|
test.originator,
|
||||||
)
|
)
|
||||||
|
|
||||||
if test.mutateState {
|
if test.mutateState {
|
||||||
|
|||||||
Reference in new issue
Block a user