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