Skip to content

Commit

Permalink
simplify and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pm47 committed Jun 15, 2022
1 parent 4f6385b commit 04fc0e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ trait ChannelOpenSingleFunder extends FundingHandlers with ErrorHandlers {
log.info("received remoteAlias={}", remoteAlias)
context.system.eventStream.publish(ShortChannelIdAssigned(self, d.commitments.channelId, shortIds = shortIds1, remoteNodeId = remoteNodeId))
}
log.info("shortIds={}", shortIds1)
log.info("shortIds: real={} localAlias={} remoteAlias={}", shortIds1.real.toOption.getOrElse("none"), shortIds1.localAlias, shortIds1.remoteAlias_opt.getOrElse("none"))
// we create a channel_update early so that we can use it to send payments through this channel, but it won't be propagated to other nodes since the channel is not yet announced
val scidForChannelUpdate = Helpers.scidForChannelUpdate(channelAnnouncement_opt = None, shortIds1)
log.info("using shortChannelId={} for initial channel_update", scidForChannelUpdate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ class ZeroConfAliasIntegrationSpec extends FixtureSpec with IntegrationPatience
private def sendPaymentAliceToCarol(f: FixtureParam, useHint: Boolean = false, overrideHintScid_opt: Option[RealShortChannelId] = None): PaymentSent = {
import f._
val hint = if (useHint) {
val Some(hint) = getRouterData(carol).privateChannels.values.head.toIncomingExtraHop
Seq(hint.modify(_.shortChannelId).setToIfDefined(overrideHintScid_opt))
val Some(carolHint) = getRouterData(carol).privateChannels.values.head.toIncomingExtraHop
// due to how node ids are built, bob < carol so carol is always the node 2
val bobAlias = getRouterData(bob).privateChannels.values.find(_.nodeId2 == carol.nodeParams.nodeId).value.shortIds.localAlias
// the hint is always using the alias
assert(carolHint.shortChannelId == bobAlias)
Seq(carolHint.modify(_.shortChannelId).setToIfDefined(overrideHintScid_opt))
} else Seq.empty
sendPayment(alice, carol, 100_000 msat, hints = Seq(hint))
}
Expand Down Expand Up @@ -138,14 +142,9 @@ class ZeroConfAliasIntegrationSpec extends FixtureSpec with IntegrationPatience
bcZeroConf = false,
bcScidAlias = false,
paymentWorksWithoutHint = false, // alice can't find a route to carol because bob-carol isn't announced
paymentWorksWithHint_opt = Some(true), // with a routing hint the payment works
paymentWorksWithHint_opt = Some(true), // with a routing hint the payment works (and it will use the alias, even if the feature isn't enabled)
paymentWorksWithRealScidHint_opt = Some(true) // if alice uses the real scid instead of the bob-carol alias, it still works
)

// Bob and Carol understand scid aliases even when the feature isn't enabled.
val carolHint = getRouterData(carol).privateChannels.values.head.toIncomingExtraHop.value
val bobAlias = getRouterData(bob).privateChannels.values.head.shortIds.localAlias
assert(carolHint.shortChannelId == bobAlias)
}

test("a->b->c (b-c scid-alias private)", Tag(ScidAliasBobCarol)) { f =>
Expand All @@ -160,11 +159,6 @@ class ZeroConfAliasIntegrationSpec extends FixtureSpec with IntegrationPatience
paymentWorksWithHint_opt = Some(true), // with a routing hint the payment works
paymentWorksWithRealScidHint_opt = Some(false) // if alice uses the real scid instead of the bob-carol alias, it doesn't work due to option_scid_alias
)

// Carol must use Bob's scid alias in her routing hints.
val carolHint = getRouterData(carol).privateChannels.values.head.toIncomingExtraHop.value
val bobAlias = getRouterData(bob).privateChannels.values.head.shortIds.localAlias
assert(carolHint.shortChannelId == bobAlias)
}

test("a->b->c (b-c zero-conf unconfirmed private)", Tag(ZeroConfBobCarol)) { f =>
Expand All @@ -179,11 +173,6 @@ class ZeroConfAliasIntegrationSpec extends FixtureSpec with IntegrationPatience
paymentWorksWithHint_opt = Some(true), // with a routing hint the payment works
paymentWorksWithRealScidHint_opt = None // there is no real scid for bob-carol yet
)

// Carol uses Bob's scid alias until the channel confirms.
val carolHint = getRouterData(carol).privateChannels.values.head.toIncomingExtraHop.value
val bobAlias = getRouterData(bob).privateChannels.values.collectFirst { case pc if pc.remoteNodeId == carol.nodeParams.nodeId => pc.shortIds.localAlias }.value
assert(carolHint.shortChannelId == bobAlias)
}

test("a->b->c (b-c zero-conf deeply confirmed private)", Tag(ZeroConfBobCarol)) { f =>
Expand Down

0 comments on commit 04fc0e6

Please sign in to comment.