Skip to content
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

Add API call to get general network statistics #1100

Closed
wants to merge 1 commit into from

Conversation

n1bor
Copy link
Contributor

@n1bor n1bor commented Aug 19, 2019

allchannels is now so slow it timesout.

This API call returns general stats on the network that is useful to know.

@codecov-io
Copy link

codecov-io commented Aug 19, 2019

Codecov Report

Merging #1100 into master will increase coverage by 0.01%.
The diff coverage is 90.9%.

@@            Coverage Diff             @@
##           master    #1100      +/-   ##
==========================================
+ Coverage   82.56%   82.57%   +0.01%     
==========================================
  Files         101      101              
  Lines        7697     7708      +11     
  Branches      302      306       +4     
==========================================
+ Hits         6355     6365      +10     
- Misses       1342     1343       +1
Impacted Files Coverage Δ
...r-core/src/main/scala/fr/acinq/eclair/Eclair.scala 61.03% <100%> (+8.86%) ⬆️
...e/src/main/scala/fr/acinq/eclair/api/Service.scala 69.87% <66.66%> (-0.06%) ⬇️
...clair/blockchain/electrum/ElectrumClientPool.scala 75.26% <0%> (-3.23%) ⬇️
...-core/src/main/scala/fr/acinq/eclair/io/Peer.scala 74.92% <0%> (-0.31%) ⬇️
...src/main/scala/fr/acinq/eclair/router/Router.scala 85.71% <0%> (-0.24%) ⬇️
...c/main/scala/fr/acinq/eclair/channel/Channel.scala 84.18% <0%> (-0.1%) ⬇️
...nq/eclair/blockchain/electrum/ElectrumClient.scala 73.6% <0%> (+0.37%) ⬆️
...cinq/eclair/blockchain/bitcoind/zmq/ZMQActor.scala 94.87% <0%> (+5.12%) ⬆️

(updateCount: Long,avgCltvExpiryDelta: Long,avgHtlcMinimumMsat: Long,avgFeeBaseMsat: Long,avgFeeProportionalMillionths: Long,avgHtlcMaximumMsat: Long, mf: FlagCounter, cf:FlagCounter ) <- allUpdates(None).map{
updates => updates.foldLeft(Tuple8(0L, 0L, 0L, 0L, 0L, 0L,FlagCounter(), FlagCounter())) {
(t, c) =>
Tuple8(t._1 + 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this hard-to-read Tuple8 why don't you directly use a GetNetworkInfoResponse here?
I think it would be cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is possible. As GetNetworkInfoResponse include results of the earlier futures too.
Could fill with dummy zeros but think that would make more confusing.
Especially if additional calls/futures were added to get more data.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do something like (I slightly renamed the fields, you'll have to adapt):

override def getNetworkInfoResponse()(implicit timeout: Timeout): Future[GetNetworkInfoResponse] = {
    for {
      nodeCount <- allNodes().map(_.size)
      channelCount <- allChannels().map(_.size)
      channelUpdates <- allUpdates(None)
      val networkInfo = channelUpdates.foldLeft(GetNetworkInfoResponse(channelCount, nodeCount, channelUpdates.size, 0, MilliSatoshi(0), MilliSatoshi(0), 0, MilliSatoshi(0))) {
        (current, next) => current.copy(
          avgCltvExpiryDelta = current.avgCltvExpiryDelta + next.cltvExpiryDelta,
          avgFeeBaseMsat = current.avgFeeBaseMsat + next.feeBaseMsat
          // etc
        )
      }
    } yield networkInfo.copy(
      avgFeeBaseMsat = networkInfo.avgFeeBaseMsat / networkInfo.updates
      // etc
    )
  }

And I would refactor to make dividing all avg fields by the updateCount be done in a method in the case class or something like that.

Copy link
Member

@t-bast t-bast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution, I think this is a useful addition to the API and we can enrich this response later (I'm thinking that average channel capacity would be useful to get).
I have a couple of code clean-up comments but concept ack.

f.router.expectMsg('channels)
val channelId_ab = ShortChannelId(420000, 1, 0)
val channelId_bc = ShortChannelId(420000, 2, 0)
val chan_ab = fr.acinq.eclair.router.BaseRouterSpec.channelAnnouncement(channelId_ab, randomKey, randomKey, randomKey, randomKey)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove fr.acinq.eclair.router

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am in EclairImpSpec so do need it. Wanted to make clear was coming from another Spec.

@t-bast
Copy link
Member

t-bast commented Sep 6, 2019

@n1bor I merged #1116 which might be useful to you: you could now simply expose that via the API. Would that be enough information for your use-case?

@pm47 pm47 closed this Sep 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants