Skip to content

Commit

Permalink
Channel Queries: don't return optional TLVs if they are empty
Browse files Browse the repository at this point in the history
Don't return optional TLVs (timestamps, checksums, ...) if the short channel id list is empty, as it creates problems with c-lighting (and it seems logical to do so).
  • Loading branch information
sstone committed Jan 16, 2020
1 parent fc99017 commit fee09e1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ object Router {
queryFlags_opt: Option[QueryChannelRangeTlv.QueryFlags],
encodingType: EncodingType): (Option[ReplyChannelRangeTlv.EncodedTimestamps], Option[ReplyChannelRangeTlv.EncodedChecksums]) = {
val (timestamps, checksums) = queryFlags_opt match {
case Some(extension) if extension.wantChecksums | extension.wantTimestamps =>
case Some(extension) if shortChannelIds.nonEmpty && (extension.wantChecksums | extension.wantTimestamps) =>
// we always compute timestamps and checksums even if we don't need both, overhead is negligible
val (timestamps, checksums) = shortChannelIds.map(getChannelDigestInfo(channels)).unzip
val encodedTimestamps = if (extension.wantTimestamps) Some(ReplyChannelRangeTlv.EncodedTimestamps(encodingType, timestamps)) else None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
package fr.acinq.eclair.router

import fr.acinq.bitcoin.ByteVector32
import fr.acinq.eclair
import fr.acinq.eclair.router.Router.ShortChannelIdsChunk
import fr.acinq.eclair.wire.{EncodingType, ReplyChannelRangeTlv}
import fr.acinq.eclair.wire.QueryChannelRangeTlv.QueryFlags
import fr.acinq.eclair.wire.ReplyChannelRangeTlv._
import fr.acinq.eclair.{LongToBtcAmount, ShortChannelId, randomKey}
import org.scalatest.FunSuite
Expand Down Expand Up @@ -357,4 +360,37 @@ class ChannelRangeQueriesSpec extends FunSuite {
validateChunks(chunks.toList, pruned)
}
}

test("compute extended query information") {
import QueryFlags._

val ids = makeShortChannelIds(42, 100) ++ makeShortChannelIds(43, 70) ++ makeShortChannelIds(44, 50) ++ makeShortChannelIds(45, 30) ++ makeShortChannelIds(50, 120)
val channels = SortedMap.empty[ShortChannelId, PublicChannel] ++ ids.map(id => id -> RoutingSyncSpec.makeFakeRoutingInfo(id)._1).toMap

def validate(timestamps: Option[ReplyChannelRangeTlv.EncodedTimestamps], checksums: Option[ReplyChannelRangeTlv.EncodedChecksums], ids: List[ShortChannelId], queryFlags_opt: Option[QueryFlags], encodingType: EncodingType) = {
queryFlags_opt match {
case None =>
require(timestamps.isEmpty)
require(checksums.isEmpty)
case _ if ids.isEmpty =>
require(timestamps.isEmpty)
require(checksums.isEmpty)
case Some(extension) =>
if (extension.wantTimestamps) {
require(timestamps.map(_.timestamps.size) == Some(ids.size))
require(timestamps.map(_.encoding) == Some(encodingType))
}
if (extension.wantChecksums) require(checksums.map(_.checksums.size) == Some(ids.size))
}
}

for (scids <- List(ids, Nil)) {
for (flag <- List(None, Some(QueryFlags(WANT_TIMESTAMPS)), Some(QueryFlags(WANT_CHECKSUMS)), Some(QueryFlags(WANT_TIMESTAMPS | WANT_CHECKSUMS)))) {
for (encodingType <- List(EncodingType.UNCOMPRESSED, EncodingType.COMPRESSED_ZLIB)) {
val (timestamps, checksums) = Router.computeExtendedInformation(scids, channels, flag, encodingType)
validate(timestamps, checksums, scids, flag, encodingType)
}
}
}
}
}

0 comments on commit fee09e1

Please sign in to comment.