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

Filter out non-standard channels from channelInfo API #2107

Merged
merged 20 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
38f94ef
Add `replyToCommand` method, use it in Channel
akumaigorodski Nov 13, 2020
b3ff039
Merge remote-tracking branch 'origin/master'
akumaigorodski Dec 29, 2020
b96f3e0
Fix Channel
akumaigorodski Dec 29, 2020
4bf3bb5
Merge branch 'master' of https://github.com/btcontract/eclair
akumaigorodski Aug 24, 2021
77a3b3c
Add description_hash in createinvoice
akumaigorodski Aug 24, 2021
9553ec0
Merge remote-tracking branch 'upstream/master'
akumaigorodski Aug 26, 2021
869620a
Update eclair-node/src/main/scala/fr/acinq/eclair/api/handlers/Invoic…
akumaigorodski Aug 31, 2021
6c2eae3
Merge branch 'master' into master
akumaigorodski Aug 31, 2021
f91ba55
Merge remote-tracking branch 'upstream/master'
akumaigorodski Sep 15, 2021
e197340
Merge remote-tracking branch 'origin/master'
akumaigorodski Sep 15, 2021
733b61d
Merge branch 'master' of https://github.com/ACINQ/eclair
akumaigorodski Oct 17, 2021
5f27f87
Filter out non-standard channels in `channelsInfo` API
akumaigorodski Dec 14, 2021
db64a8c
Take changes into account, remove code duplication in `channelsInfo`
akumaigorodski Dec 15, 2021
67d38ca
Improve `ChannelInfo` return type
akumaigorodski Dec 15, 2021
291bee1
Improve `ChannelInfo` return type
akumaigorodski Dec 15, 2021
d7ad653
Add a test
akumaigorodski Dec 15, 2021
ec59e11
Filter out non-standard channels in `channelsInfo` API
akumaigorodski Dec 15, 2021
990c41b
Merge remote-tracking branch 'origin/api-hc' into api-hc
akumaigorodski Dec 15, 2021
8d30923
Update eclair-core/src/test/scala/fr/acinq/eclair/EclairImplSpec.scala
akumaigorodski Dec 15, 2021
13dbb63
Fix imports
akumaigorodski Dec 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions eclair-core/src/main/scala/fr/acinq/eclair/Eclair.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ trait Eclair {

def channelsInfo(toRemoteNode_opt: Option[PublicKey])(implicit timeout: Timeout): Future[Iterable[RES_GETINFO]]

def channelInfo(channel: ApiTypes.ChannelIdentifier)(implicit timeout: Timeout): Future[RES_GETINFO]
def channelInfo(channel: ApiTypes.ChannelIdentifier)(implicit timeout: Timeout): Future[CommandResponse[CMD_GETINFO]]

def peers()(implicit timeout: Timeout): Future[Iterable[PeerInfo]]

Expand Down Expand Up @@ -212,19 +212,22 @@ class EclairImpl(appKit: Kit) extends Eclair with Logging {
.map(_.filter(n => nodeIds_opt.forall(_.contains(n.nodeId))))
}

override def channelsInfo(toRemoteNode_opt: Option[PublicKey])(implicit timeout: Timeout): Future[Iterable[RES_GETINFO]] = toRemoteNode_opt match {
case Some(pk) => for {
channelIds <- (appKit.register ? Symbol("channelsTo")).mapTo[Map[ByteVector32, PublicKey]].map(_.filter(_._2 == pk).keys)
channels <- Future.sequence(channelIds.map(channelId => sendToChannel[CMD_GETINFO, RES_GETINFO](Left(channelId), CMD_GETINFO(ActorRef.noSender))))
} yield channels
case None => for {
channelIds <- (appKit.register ? Symbol("channels")).mapTo[Map[ByteVector32, ActorRef]].map(_.keys)
channels <- Future.sequence(channelIds.map(channelId => sendToChannel[CMD_GETINFO, RES_GETINFO](Left(channelId), CMD_GETINFO(ActorRef.noSender))))
} yield channels
override def channelsInfo(toRemoteNode_opt: Option[PublicKey])(implicit timeout: Timeout): Future[Iterable[RES_GETINFO]] = {
val futureResponse = toRemoteNode_opt match {
case Some(pk) => (appKit.register ? Symbol("channelsTo")).mapTo[Map[ByteVector32, PublicKey]].map(_.filter(_._2 == pk).keys)
case None => (appKit.register ? Symbol("channels")).mapTo[Map[ByteVector32, ActorRef]].map(_.keys)
}

for {
channelIds <- futureResponse
channels <- Future.sequence(channelIds.map(channelId => sendToChannel[CMD_GETINFO, CommandResponse[CMD_GETINFO]](Left(channelId), CMD_GETINFO(ActorRef.noSender))))
} yield channels.collect {
case properResponse: RES_GETINFO => properResponse
}
}

override def channelInfo(channel: ApiTypes.ChannelIdentifier)(implicit timeout: Timeout): Future[RES_GETINFO] = {
sendToChannel[CMD_GETINFO, RES_GETINFO](channel, CMD_GETINFO(ActorRef.noSender))
override def channelInfo(channel: ApiTypes.ChannelIdentifier)(implicit timeout: Timeout): Future[CommandResponse[CMD_GETINFO]] = {
sendToChannel[CMD_GETINFO, CommandResponse[CMD_GETINFO]](channel, CMD_GETINFO(ActorRef.noSender))
}

override def allChannels()(implicit timeout: Timeout): Future[Iterable[ChannelDesc]] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class EclairImplSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with I
assert(verifiedMessage.publicKey !== kit.nodeParams.nodeId)
}

test("get channel info (all channels)") { f =>
test("get channel info (filtered channels)") { f =>
import f._

val eclair = new EclairImpl(kit)
Expand All @@ -468,8 +468,8 @@ class EclairImplSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with I

val c1 = register.expectMsgType[Register.Forward[CMD_GETINFO]]
register.reply(RES_GETINFO(map(c1.channelId), c1.channelId, NORMAL, ChannelCodecsSpec.normal))
val c2 = register.expectMsgType[Register.Forward[CMD_GETINFO]]
register.reply(RES_GETINFO(map(c2.channelId), c2.channelId, NORMAL, ChannelCodecsSpec.normal))
register.expectMsgType[Register.Forward[CMD_GETINFO]]
register.reply(RES_FAILURE(CMD_GETINFO(ActorRef.noSender), new IllegalArgumentException("Non-standard channel")))
val c3 = register.expectMsgType[Register.Forward[CMD_GETINFO]]
register.reply(RES_GETINFO(map(c3.channelId), c3.channelId, NORMAL, ChannelCodecsSpec.normal))
register.expectNoMessage()
Expand All @@ -478,7 +478,6 @@ class EclairImplSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with I

assert(res.value.get.get.toSet === Set(
RES_GETINFO(a, a1, NORMAL, ChannelCodecsSpec.normal),
RES_GETINFO(a, a2, NORMAL, ChannelCodecsSpec.normal),
RES_GETINFO(b, b1, NORMAL, ChannelCodecsSpec.normal),
))
}
Expand Down