Skip to content

Commit

Permalink
Relax cltv-expiry-delta requirement when selecting a channel to relay (
Browse files Browse the repository at this point in the history
…#1655)

We only need the `cltv-expiry-delta` offered to be greater than our
requirement instead of strictly equal.

Co-authored-by: t-bast <[email protected]>
  • Loading branch information
akumaigorodski and t-bast authored Dec 29, 2020
1 parent b75f6c3 commit 5f9d0d9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class ChannelRelay private(nodeParams: NodeParams,
RelayFailure(CMD_FAIL_HTLC(add.id, Right(ChannelDisabled(channelUpdate.messageFlags, channelUpdate.channelFlags, channelUpdate)), commit = true))
case Some(channelUpdate) if payload.amountToForward < channelUpdate.htlcMinimumMsat =>
RelayFailure(CMD_FAIL_HTLC(add.id, Right(AmountBelowMinimum(payload.amountToForward, channelUpdate)), commit = true))
case Some(channelUpdate) if r.expiryDelta != channelUpdate.cltvExpiryDelta =>
case Some(channelUpdate) if r.expiryDelta < channelUpdate.cltvExpiryDelta =>
RelayFailure(CMD_FAIL_HTLC(add.id, Right(IncorrectCltvExpiry(payload.outgoingCltv, channelUpdate)), commit = true))
case Some(channelUpdate) if r.relayFeeMsat < nodeFee(channelUpdate.feeBaseMsat, channelUpdate.feeProportionalMillionths, payload.amountToForward) =>
RelayFailure(CMD_FAIL_HTLC(add.id, Right(FeeInsufficient(add.amountMsat, channelUpdate)), commit = true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,25 +198,25 @@ class ChannelRelayerSpec extends ScalaTestWithActorTestKit(ConfigFactory.load("a
expectFwdFail(register, r.add.channelId, CMD_FAIL_HTLC(r.add.id, Right(AmountBelowMinimum(outgoingAmount, u.channelUpdate)), commit = true))
}

test("fail to relay an htlc-add (expiry too small)") { f =>
test("relay an htlc-add (expiry larger than our requirements)") { f =>
import f._

val payload = RelayLegacyPayload(shortId1, outgoingAmount, outgoingExpiry - CltvExpiryDelta(1))
val r = createValidIncomingPacket(1100000 msat, CltvExpiry(400100), payload)
val payload = RelayLegacyPayload(shortId1, outgoingAmount, outgoingExpiry)
val u = createLocalUpdate(shortId1)
val r = createValidIncomingPacket(1100000 msat, outgoingExpiry + u.channelUpdate.cltvExpiryDelta + CltvExpiryDelta(1), payload)

channelRelayer ! WrappedLocalChannelUpdate(u)
channelRelayer ! Relay(r)

expectFwdFail(register, r.add.channelId, CMD_FAIL_HTLC(r.add.id, Right(IncorrectCltvExpiry(payload.outgoingCltv, u.channelUpdate)), commit = true))
expectFwdAdd(register, shortId1, payload.amountToForward, payload.outgoingCltv).message
}

test("fail to relay an htlc-add (expiry too large)") { f =>
test("fail to relay an htlc-add (expiry too small)") { f =>
import f._

val payload = RelayLegacyPayload(shortId1, outgoingAmount, outgoingExpiry + CltvExpiryDelta(1))
val r = createValidIncomingPacket(1100000 msat, CltvExpiry(400100), payload)
val payload = RelayLegacyPayload(shortId1, outgoingAmount, outgoingExpiry)
val u = createLocalUpdate(shortId1)
val r = createValidIncomingPacket(1100000 msat, outgoingExpiry + u.channelUpdate.cltvExpiryDelta - CltvExpiryDelta(1), payload)

channelRelayer ! WrappedLocalChannelUpdate(u)
channelRelayer ! Relay(r)
Expand Down Expand Up @@ -330,11 +330,18 @@ class ChannelRelayerSpec extends ScalaTestWithActorTestKit(ConfigFactory.load("a
expectFwdAdd(register, ShortChannelId(12345), payload.amountToForward, payload.outgoingCltv).message
}
{
// invalid cltv expiry, no suitable channel found
val payload = RelayLegacyPayload(ShortChannelId(12345), 998900 msat, CltvExpiry(40))
// cltv expiry larger than our requirements
val payload = RelayLegacyPayload(ShortChannelId(12345), 998900 msat, CltvExpiry(50))
val r = createValidIncomingPacket(1000000 msat, CltvExpiry(70), payload)
channelRelayer ! Relay(r)
expectFwdAdd(register, ShortChannelId(22223), payload.amountToForward, payload.outgoingCltv).message
}
{
// cltv expiry too small, no suitable channel found
val payload = RelayLegacyPayload(ShortChannelId(12345), 998900 msat, CltvExpiry(61))
val r = createValidIncomingPacket(1000000 msat, CltvExpiry(70), payload)
channelRelayer ! Relay(r)
expectFwdFail(register, r.add.channelId, CMD_FAIL_HTLC(r.add.id, Right(IncorrectCltvExpiry(CltvExpiry(40), channelUpdates(ShortChannelId(12345)).channelUpdate)), commit = true))
expectFwdFail(register, r.add.channelId, CMD_FAIL_HTLC(r.add.id, Right(IncorrectCltvExpiry(CltvExpiry(61), channelUpdates(ShortChannelId(12345)).channelUpdate)), commit = true))
}
}

Expand Down

0 comments on commit 5f9d0d9

Please sign in to comment.