routing: use pairResult constructors

To make it explicit whether a failure or a success result is
instantiated.
This commit is contained in:
Joost Jager 2019-09-30 19:45:49 +02:00
parent 37ef46bc48
commit aefbee78d6
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
2 changed files with 31 additions and 35 deletions

@ -26,6 +26,20 @@ type pairResult struct {
success bool 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. // String returns the human-readable representation of a pair result.
func (p pairResult) String() string { func (p pairResult) String() string {
if p.success { if p.success {
@ -387,8 +401,8 @@ func (i *interpretedResult) failPair(
pair, _ := getPair(rt, idx) pair, _ := getPair(rt, idx)
// Report pair in both directions without a minimum penalization amount. // Report pair in both directions without a minimum penalization amount.
i.pairResults[pair] = pairResult{} i.pairResults[pair] = failPairResult(0)
i.pairResults[pair.Reverse()] = pairResult{} i.pairResults[pair.Reverse()] = failPairResult(0)
} }
// failPairBalance marks a pair as failed with a minimum penalization amount. // failPairBalance marks a pair as failed with a minimum penalization amount.
@ -397,9 +411,7 @@ func (i *interpretedResult) failPairBalance(
pair, amt := getPair(rt, channelIdx) pair, amt := getPair(rt, channelIdx)
i.pairResults[pair] = pairResult{ i.pairResults[pair] = failPairResult(amt)
minPenalizeAmt: amt,
}
} }
// successPairRange marks the node pairs from node fromIdx to node toIdx as // 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++ { for idx := fromIdx; idx <= toIdx; idx++ {
pair, _ := getPair(rt, idx) pair, _ := getPair(rt, idx)
i.pairResults[pair] = pairResult{ i.pairResults[pair] = successPairResult()
success: true,
}
} }
} }

@ -68,12 +68,8 @@ var resultTestCases = []resultTestCase{
expectedResult: &interpretedResult{ expectedResult: &interpretedResult{
pairResults: map[DirectedNodePair]pairResult{ pairResults: map[DirectedNodePair]pairResult{
getTestPair(0, 1): { getTestPair(0, 1): successPairResult(),
success: true, getTestPair(1, 2): failPairResult(99),
},
getTestPair(1, 2): {
minPenalizeAmt: 99,
},
}, },
}, },
}, },
@ -87,12 +83,12 @@ var resultTestCases = []resultTestCase{
expectedResult: &interpretedResult{ expectedResult: &interpretedResult{
pairResults: map[DirectedNodePair]pairResult{ pairResults: map[DirectedNodePair]pairResult{
getTestPair(0, 1): {}, getTestPair(0, 1): failPairResult(0),
getTestPair(1, 0): {}, getTestPair(1, 0): failPairResult(0),
getTestPair(1, 2): {}, getTestPair(1, 2): failPairResult(0),
getTestPair(2, 1): {}, getTestPair(2, 1): failPairResult(0),
getTestPair(2, 3): {}, getTestPair(2, 3): failPairResult(0),
getTestPair(3, 2): {}, getTestPair(3, 2): failPairResult(0),
}, },
}, },
}, },
@ -107,12 +103,8 @@ var resultTestCases = []resultTestCase{
expectedResult: &interpretedResult{ expectedResult: &interpretedResult{
pairResults: map[DirectedNodePair]pairResult{ pairResults: map[DirectedNodePair]pairResult{
getTestPair(0, 1): { getTestPair(0, 1): successPairResult(),
success: true, getTestPair(1, 2): successPairResult(),
},
getTestPair(1, 2): {
success: true,
},
}, },
finalFailureReason: &reasonIncorrectDetails, finalFailureReason: &reasonIncorrectDetails,
}, },
@ -126,9 +118,7 @@ var resultTestCases = []resultTestCase{
expectedResult: &interpretedResult{ expectedResult: &interpretedResult{
pairResults: map[DirectedNodePair]pairResult{ pairResults: map[DirectedNodePair]pairResult{
getTestPair(0, 1): { getTestPair(0, 1): successPairResult(),
success: true,
},
}, },
}, },
}, },
@ -141,12 +131,8 @@ var resultTestCases = []resultTestCase{
expectedResult: &interpretedResult{ expectedResult: &interpretedResult{
pairResults: map[DirectedNodePair]pairResult{ pairResults: map[DirectedNodePair]pairResult{
getTestPair(0, 1): { getTestPair(0, 1): successPairResult(),
success: true, getTestPair(1, 2): successPairResult(),
},
getTestPair(1, 2): {
success: true,
},
}, },
}, },
}, },