diff --git a/routing/result_interpretation.go b/routing/result_interpretation.go index 74c740149..d89f959af 100644 --- a/routing/result_interpretation.go +++ b/routing/result_interpretation.go @@ -26,6 +26,20 @@ type pairResult struct { success bool } +// failPairResult creates a new result struct for a failure. +func failPairResult(minPenalizeAmt lnwire.MilliSatoshi) pairResult { + return pairResult{ + minPenalizeAmt: minPenalizeAmt, + } +} + +// successPairResult creates a new result struct for a success. +func successPairResult() pairResult { + return pairResult{ + success: true, + } +} + // String returns the human-readable representation of a pair result. func (p pairResult) String() string { if p.success { @@ -387,8 +401,8 @@ func (i *interpretedResult) failPair( pair, _ := getPair(rt, idx) // Report pair in both directions without a minimum penalization amount. - i.pairResults[pair] = pairResult{} - i.pairResults[pair.Reverse()] = pairResult{} + i.pairResults[pair] = failPairResult(0) + i.pairResults[pair.Reverse()] = failPairResult(0) } // failPairBalance marks a pair as failed with a minimum penalization amount. @@ -397,9 +411,7 @@ func (i *interpretedResult) failPairBalance( pair, amt := getPair(rt, channelIdx) - i.pairResults[pair] = pairResult{ - minPenalizeAmt: amt, - } + i.pairResults[pair] = failPairResult(amt) } // successPairRange marks the node pairs from node fromIdx to node toIdx as @@ -410,9 +422,7 @@ func (i *interpretedResult) successPairRange( for idx := fromIdx; idx <= toIdx; idx++ { pair, _ := getPair(rt, idx) - i.pairResults[pair] = pairResult{ - success: true, - } + i.pairResults[pair] = successPairResult() } } diff --git a/routing/result_interpretation_test.go b/routing/result_interpretation_test.go index 8c4498b06..23ea5d1ed 100644 --- a/routing/result_interpretation_test.go +++ b/routing/result_interpretation_test.go @@ -68,12 +68,8 @@ var resultTestCases = []resultTestCase{ expectedResult: &interpretedResult{ pairResults: map[DirectedNodePair]pairResult{ - getTestPair(0, 1): { - success: true, - }, - getTestPair(1, 2): { - minPenalizeAmt: 99, - }, + getTestPair(0, 1): successPairResult(), + getTestPair(1, 2): failPairResult(99), }, }, }, @@ -87,12 +83,12 @@ var resultTestCases = []resultTestCase{ expectedResult: &interpretedResult{ pairResults: map[DirectedNodePair]pairResult{ - getTestPair(0, 1): {}, - getTestPair(1, 0): {}, - getTestPair(1, 2): {}, - getTestPair(2, 1): {}, - getTestPair(2, 3): {}, - getTestPair(3, 2): {}, + getTestPair(0, 1): failPairResult(0), + getTestPair(1, 0): failPairResult(0), + getTestPair(1, 2): failPairResult(0), + getTestPair(2, 1): failPairResult(0), + getTestPair(2, 3): failPairResult(0), + getTestPair(3, 2): failPairResult(0), }, }, }, @@ -107,12 +103,8 @@ var resultTestCases = []resultTestCase{ expectedResult: &interpretedResult{ pairResults: map[DirectedNodePair]pairResult{ - getTestPair(0, 1): { - success: true, - }, - getTestPair(1, 2): { - success: true, - }, + getTestPair(0, 1): successPairResult(), + getTestPair(1, 2): successPairResult(), }, finalFailureReason: &reasonIncorrectDetails, }, @@ -126,9 +118,7 @@ var resultTestCases = []resultTestCase{ expectedResult: &interpretedResult{ pairResults: map[DirectedNodePair]pairResult{ - getTestPair(0, 1): { - success: true, - }, + getTestPair(0, 1): successPairResult(), }, }, }, @@ -141,12 +131,8 @@ var resultTestCases = []resultTestCase{ expectedResult: &interpretedResult{ pairResults: map[DirectedNodePair]pairResult{ - getTestPair(0, 1): { - success: true, - }, - getTestPair(1, 2): { - success: true, - }, + getTestPair(0, 1): successPairResult(), + getTestPair(1, 2): successPairResult(), }, }, },