lnwallet: remove mutateState from evaluateHTLCView

In line with previous commits we are progressively removing the
mutateState argument from this call stack for a more principled
software design approach.

NOTE FOR REVIEWERS:
We take a naive approach to updating the tests here and simply
take the functionality we are removing from evaluateHTLCView and
run it directly after the function in the test suite.

It's possible that we should instead remove this from the test
suite altogether but I opted to take a more conservative approach
with respect to reducing the scope of tests. If you have opinions
here, please make them known.
This commit is contained in:
Keagan McClelland committed 2024-10-14 09:33:16 -06:00
1 parent 819239c5c8
commit d82d02831d
4 files changed
+146 -97

No files matched your search

+28 -2
View File
@@ -8956,14 +8956,40 @@ func TestEvaluateView(t *testing.T) {
)
// Evaluate the htlc view, mutate as test expects.
result, err := lc.evaluateHTLCView(
result, uncommitted, err := lc.evaluateHTLCView(
view, &ourBalance, &theirBalance, nextHeight,
test.whoseCommitChain, test.mutateState,
test.whoseCommitChain,
)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// TODO(proofofkeags): This block is here because we
// extracted this code from a previous implementation
// of evaluateHTLCView, due to a reduced scope of
// responsibility of that function. Consider removing
// it from the test altogether.
if test.mutateState {
for _, party := range lntypes.BothParties {
us := uncommitted.GetForParty(party)
for _, u := range us {
u.setCommitHeight(
test.whoseCommitChain,
nextHeight,
)
if test.whoseCommitChain ==
lntypes.Local &&
u.EntryType == Settle {
lc.recordSettlement(
party, u.Amount,
)
}
}
}
}
if result.FeePerKw != test.expectedFee {
t.Fatalf("expected fee: %v, got: %v",
test.expectedFee, result.FeePerKw)