-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Router computes network stats #1116
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7f1465c
Router: add comments and small warnings clean-up
t-bast cd7bac7
Estimate htlcMaximumMsat for invoice routing hints
t-bast a05a156
Compute network statistics.
t-bast 5a0f269
Use Guava to compute percentiles.
t-bast de32783
Make network stats refresh configurable.
t-bast 540c0ca
Merge branch 'master' into router-network-stats
t-bast 8fcc56e
Fix PR comments
t-bast 280beda
Merge branch 'master' into router-network-stats
t-bast 655e3bb
Merge branch 'master' into router-network-stats
t-bast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
eclair-core/src/main/scala/fr/acinq/eclair/router/NetworkStats.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2019 ACINQ SAS | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package fr.acinq.eclair.router | ||
|
||
import com.google.common.math.Quantiles.percentiles | ||
import fr.acinq.bitcoin.Satoshi | ||
import fr.acinq.eclair.wire.ChannelUpdate | ||
import fr.acinq.eclair.{CltvExpiryDelta, MilliSatoshi} | ||
|
||
import scala.collection.JavaConverters._ | ||
|
||
/** | ||
* Created by t-bast on 30/08/2019. | ||
*/ | ||
|
||
case class Stats[T](median: T, percentile5: T, percentile10: T, percentile25: T, percentile75: T, percentile90: T, percentile95: T) | ||
|
||
object Stats { | ||
def apply[T](values: Seq[Long], fromDouble: Double => T): Stats[T] = { | ||
require(values.nonEmpty, "can't compute stats on empty values") | ||
val stats = percentiles().indexes(5, 10, 25, 50, 75, 90, 95).compute(values.map(java.lang.Long.valueOf).asJavaCollection) | ||
Stats(fromDouble(stats.get(50)), fromDouble(stats.get(5)), fromDouble(stats.get(10)), fromDouble(stats.get(25)), fromDouble(stats.get(75)), fromDouble(stats.get(90)), fromDouble(stats.get(95))) | ||
} | ||
} | ||
|
||
case class NetworkStats(channels: Int, nodes: Int, capacity: Stats[Satoshi], cltvExpiryDelta: Stats[CltvExpiryDelta], feeBase: Stats[MilliSatoshi], feeProportional: Stats[Long]) | ||
|
||
object NetworkStats { | ||
/** | ||
* Computes various network statistics (expensive). | ||
* Network statistics won't change noticeably very quickly, so this should not be re-computed too often. | ||
*/ | ||
def apply(publicChannels: Seq[PublicChannel]): Option[NetworkStats] = { | ||
// We need at least one channel update to be able to compute stats. | ||
if (publicChannels.isEmpty || publicChannels.flatMap(pc => getChannelUpdateField(pc, _ => true)).isEmpty) { | ||
None | ||
} else { | ||
val capacityStats = Stats(publicChannels.map(_.capacity.toLong), d => Satoshi(d.toLong)) | ||
val cltvStats = Stats(publicChannels.flatMap(pc => getChannelUpdateField(pc, u => u.cltvExpiryDelta.toInt.toLong)), d => CltvExpiryDelta(d.toInt)) | ||
val feeBaseStats = Stats(publicChannels.flatMap(pc => getChannelUpdateField(pc, u => u.feeBaseMsat.toLong)), d => MilliSatoshi(d.toLong)) | ||
val feeProportionalStats = Stats(publicChannels.flatMap(pc => getChannelUpdateField(pc, u => u.feeProportionalMillionths)), d => d.toLong) | ||
val nodes = publicChannels.flatMap(pc => pc.ann.nodeId1 :: pc.ann.nodeId2 :: Nil).toSet.size | ||
Some(NetworkStats(publicChannels.size, nodes, capacityStats, cltvStats, feeBaseStats, feeProportionalStats)) | ||
} | ||
} | ||
|
||
private def getChannelUpdateField[T](pc: PublicChannel, f: ChannelUpdate => T): Seq[T] = | ||
pc.update_1_opt.map(u => f(u) :: Nil).getOrElse(Nil) ++ pc.update_2_opt.map(u => f(u) :: Nil).getOrElse(Nil) | ||
t-bast marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's currently possible to set values such as
capacityFactor=1234.5
andageFactor=-1234.4
which summed would lie within the interval [0, 1] but effectively screw up the cost function. How about adding a check to enforce individual correctness of the parameters?