mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
routing: export TimedPairResult
Prepares for this data structure being accessed in mission control rpc implementations.
This commit is contained in:
parent
912a8201f9
commit
57911faa98
@ -53,7 +53,7 @@ const (
|
||||
)
|
||||
|
||||
// NodeResults contains previous results from a node to its peers.
|
||||
type NodeResults map[route.Vertex]timedPairResult
|
||||
type NodeResults map[route.Vertex]TimedPairResult
|
||||
|
||||
// MissionControl contains state which summarizes the past attempts of HTLC
|
||||
// routing by external callers when sending payments throughout the network. It
|
||||
@ -120,28 +120,28 @@ type MissionControlConfig struct {
|
||||
AprioriWeight float64
|
||||
}
|
||||
|
||||
// timedPairResult describes a timestamped pair result.
|
||||
type timedPairResult struct {
|
||||
// TimedPairResult describes a timestamped pair result.
|
||||
type TimedPairResult struct {
|
||||
// timestamp is the time when this result was obtained.
|
||||
timestamp time.Time
|
||||
Timestamp time.Time
|
||||
|
||||
// minPenalizeAmt is the minimum amount for which a penalty should be
|
||||
// applied based on this result. Only applies to fail results.
|
||||
minPenalizeAmt lnwire.MilliSatoshi
|
||||
MinPenalizeAmt lnwire.MilliSatoshi
|
||||
|
||||
// success indicates whether the payment attempt was successful through
|
||||
// this pair.
|
||||
success bool
|
||||
Success bool
|
||||
}
|
||||
|
||||
// newTimedPairResult wraps a pair result with a timestamp.
|
||||
func newTimedPairResult(timestamp time.Time,
|
||||
result pairResult) timedPairResult {
|
||||
result pairResult) TimedPairResult {
|
||||
|
||||
return timedPairResult{
|
||||
timestamp: timestamp,
|
||||
minPenalizeAmt: result.minPenalizeAmt,
|
||||
success: result.success,
|
||||
return TimedPairResult{
|
||||
Timestamp: timestamp,
|
||||
MinPenalizeAmt: result.minPenalizeAmt,
|
||||
Success: result.success,
|
||||
}
|
||||
}
|
||||
|
||||
@ -274,7 +274,7 @@ func (m *MissionControl) GetProbability(fromNode, toNode route.Vertex,
|
||||
|
||||
// setLastPairResult stores a result for a node pair.
|
||||
func (m *MissionControl) setLastPairResult(fromNode,
|
||||
toNode route.Vertex, result timedPairResult) {
|
||||
toNode route.Vertex, result TimedPairResult) {
|
||||
|
||||
nodePairs, ok := m.lastPairResult[fromNode]
|
||||
if !ok {
|
||||
@ -350,9 +350,9 @@ func (m *MissionControl) GetHistorySnapshot() *MissionControlSnapshot {
|
||||
|
||||
pairSnapshot := MissionControlPairSnapshot{
|
||||
Pair: pair,
|
||||
MinPenalizeAmt: result.minPenalizeAmt,
|
||||
Timestamp: result.timestamp,
|
||||
LastAttemptSuccessful: result.success,
|
||||
MinPenalizeAmt: result.MinPenalizeAmt,
|
||||
Timestamp: result.Timestamp,
|
||||
LastAttemptSuccessful: result.Success,
|
||||
}
|
||||
|
||||
pairs = append(pairs, pairSnapshot)
|
||||
|
@ -80,19 +80,19 @@ func (p *probabilityEstimator) getNodeProbability(now time.Time,
|
||||
totalWeight := aprioriFactor
|
||||
|
||||
for _, result := range results {
|
||||
age := now.Sub(result.timestamp)
|
||||
age := now.Sub(result.Timestamp)
|
||||
|
||||
switch {
|
||||
// Weigh success with a constant high weight of 1. There is no
|
||||
// decay.
|
||||
case result.success:
|
||||
case result.Success:
|
||||
totalWeight++
|
||||
probabilitiesTotal += p.prevSuccessProbability
|
||||
|
||||
// Weigh failures in accordance with their age. The base
|
||||
// probability of a failure is considered zero, so nothing needs
|
||||
// to be added to probabilitiesTotal.
|
||||
case amt >= result.minPenalizeAmt:
|
||||
case amt >= result.MinPenalizeAmt:
|
||||
totalWeight += p.getWeight(age)
|
||||
}
|
||||
}
|
||||
@ -127,7 +127,7 @@ func (p *probabilityEstimator) getPairProbability(
|
||||
|
||||
// For successes, we have a fixed (high) probability. Those pairs
|
||||
// will be assumed good until proven otherwise.
|
||||
if lastPairResult.success {
|
||||
if lastPairResult.Success {
|
||||
return p.prevSuccessProbability
|
||||
}
|
||||
|
||||
@ -138,11 +138,11 @@ func (p *probabilityEstimator) getPairProbability(
|
||||
// penalization. If the current amount is smaller than the amount that
|
||||
// previously triggered a failure, we act as if this is an untried
|
||||
// channel.
|
||||
if amt < lastPairResult.minPenalizeAmt {
|
||||
if amt < lastPairResult.MinPenalizeAmt {
|
||||
return nodeProbability
|
||||
}
|
||||
|
||||
timeSinceLastFailure := now.Sub(lastPairResult.timestamp)
|
||||
timeSinceLastFailure := now.Sub(lastPairResult.Timestamp)
|
||||
|
||||
// Calculate success probability based on the weight of the last
|
||||
// failure. When the failure is fresh, its weight is 1 and we'll return
|
||||
|
@ -33,7 +33,7 @@ type estimatorTestContext struct {
|
||||
// corresponds to the last result towards a node. The list index equals
|
||||
// the node id. So the first element in the list is the result towards
|
||||
// node 0.
|
||||
results map[int]timedPairResult
|
||||
results map[int]TimedPairResult
|
||||
}
|
||||
|
||||
func newEstimatorTestContext(t *testing.T) *estimatorTestContext {
|
||||
@ -83,7 +83,7 @@ func TestProbabilityEstimatorNoResults(t *testing.T) {
|
||||
func TestProbabilityEstimatorOneSuccess(t *testing.T) {
|
||||
ctx := newEstimatorTestContext(t)
|
||||
|
||||
ctx.results = map[int]timedPairResult{
|
||||
ctx.results = map[int]TimedPairResult{
|
||||
node1: newTimedPairResult(
|
||||
testTime.Add(-time.Hour),
|
||||
successPairResult(),
|
||||
@ -107,7 +107,7 @@ func TestProbabilityEstimatorOneSuccess(t *testing.T) {
|
||||
func TestProbabilityEstimatorOneFailure(t *testing.T) {
|
||||
ctx := newEstimatorTestContext(t)
|
||||
|
||||
ctx.results = map[int]timedPairResult{
|
||||
ctx.results = map[int]TimedPairResult{
|
||||
node1: newTimedPairResult(
|
||||
testTime.Add(-time.Hour),
|
||||
failPairResult(0),
|
||||
@ -130,7 +130,7 @@ func TestProbabilityEstimatorOneFailure(t *testing.T) {
|
||||
func TestProbabilityEstimatorMix(t *testing.T) {
|
||||
ctx := newEstimatorTestContext(t)
|
||||
|
||||
ctx.results = map[int]timedPairResult{
|
||||
ctx.results = map[int]TimedPairResult{
|
||||
node1: newTimedPairResult(
|
||||
testTime.Add(-time.Hour),
|
||||
successPairResult(),
|
||||
|
Loading…
Reference in New Issue
Block a user