1
0
Fork 0
mirror of https://github.com/ACINQ/eclair.git synced 2025-02-22 14:22:39 +01:00

Don't send updates if no filter has been set (#912)

We mistakenly implemented `Peer.timestampInRange` as opt-out whereas it
should be opt-in.
This commit is contained in:
Pierre-Marie Padiou 2019-03-25 14:37:12 +01:00 committed by GitHub
parent 3fda5ddede
commit 8ea4bd0468
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 9 deletions

View file

@ -325,7 +325,7 @@ class Peer(nodeParams: NodeParams, remoteNodeId: PublicKey, authenticator: Actor
case (count, (_, origins)) if origins.contains(self) =>
// the announcement came from this peer, we don't send it back
count
case (count, (msg: HasTimestamp, _)) if !timestampInRange(msg, d.gossipTimestampFilter) =>
case (count, (msg, _)) if !timestampInRange(msg, d.gossipTimestampFilter) =>
// the peer has set up a filter on timestamp and this message is out of range
count
case (count, (msg, _)) =>
@ -596,14 +596,15 @@ object Peer {
*
* @param gossipTimestampFilter_opt optional gossip timestamp range
* @return
* - true if the msg's timestamp is in the requested range, or if there is no filtering
* - true if there is a filter and msg has no timestamp, or has one that matches the filter
* - false otherwise
*/
def timestampInRange(msg: HasTimestamp, gossipTimestampFilter_opt: Option[GossipTimestampFilter]): Boolean = {
def timestampInRange(msg: RoutingMessage, gossipTimestampFilter_opt: Option[GossipTimestampFilter]): Boolean = {
// check if this message has a timestamp that matches our timestamp filter
gossipTimestampFilter_opt match {
case None => true // no filtering
case Some(GossipTimestampFilter(_, firstTimestamp, timestampRange)) => msg.timestamp >= firstTimestamp && msg.timestamp <= firstTimestamp + timestampRange
(msg, gossipTimestampFilter_opt) match {
case (_, None) => false // BOLT 7: A node which wants any gossip messages would have to send this, otherwise [...] no gossip messages would be received.
case (hasTs: HasTimestamp, Some(GossipTimestampFilter(_, firstTimestamp, timestampRange))) => hasTs.timestamp >= firstTimestamp && hasTs.timestamp <= firstTimestamp + timestampRange
case _ => true // if there is a filter and message doesn't have a timestamp (e.g. channel_announcement), then we send it
}
}
}

View file

@ -109,9 +109,7 @@ class PeerSpec extends TestkitBaseClass {
connect(remoteNodeId, authenticator, watcher, router, relayer, connection, transport, peer)
val rebroadcast = Rebroadcast(channels.map(_ -> Set.empty[ActorRef]).toMap, updates.map(_ -> Set.empty[ActorRef]).toMap, nodes.map(_ -> Set.empty[ActorRef]).toMap)
probe.send(peer, rebroadcast)
channels.foreach(transport.expectMsg(_))
updates.foreach(transport.expectMsg(_))
nodes.foreach(transport.expectMsg(_))
transport.expectNoMsg(2 seconds)
}
test("filter gossip message (filtered by origin)") { f =>
@ -122,6 +120,8 @@ class PeerSpec extends TestkitBaseClass {
channels.map(_ -> Set.empty[ActorRef]).toMap + (channels(5) -> Set(peer)),
updates.map(_ -> Set.empty[ActorRef]).toMap + (updates(6) -> Set(peer)) + (updates(10) -> Set(peer)),
nodes.map(_ -> Set.empty[ActorRef]).toMap + (nodes(4) -> Set(peer)))
val filter = wire.GossipTimestampFilter(Alice.nodeParams.chainHash, 0, Long.MaxValue) // no filtering on timestamps
probe.send(peer, filter)
probe.send(peer, rebroadcast)
// peer won't send out announcements that came from itself
(channels.toSet - channels(5)).foreach(transport.expectMsg(_))