Skip to content

Commit 6364ae3

Browse files
Reject trampoline payments with expired outgoing cltv (#1727)
When we receive a trampoline payment asking us to relay with an expiry that is already below the current chain height, we know that this payment will fail when it reaches the next trampoline node. Instead of waiting for the next trampoline node to reject it, we reject it immediately.
1 parent 9ff2f83 commit 6364ae3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

eclair-core/src/main/scala/fr/acinq/eclair/payment/relay/NodeRelay.scala

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ object NodeRelay {
8989
Some(TrampolineFeeInsufficient)
9090
} else if (upstream.expiryIn - payloadOut.outgoingCltv < nodeParams.expiryDelta) {
9191
Some(TrampolineExpiryTooSoon)
92+
} else if (payloadOut.outgoingCltv <= CltvExpiry(nodeParams.currentBlockHeight)) {
93+
Some(TrampolineExpiryTooSoon)
9294
} else {
9395
None
9496
}

eclair-core/src/test/scala/fr/acinq/eclair/payment/relay/NodeRelayerSpec.scala

+15
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,21 @@ class NodeRelayerSpec extends ScalaTestWithActorTestKit(ConfigFactory.load("appl
256256
register.expectNoMessage(100 millis)
257257
}
258258

259+
test("fail to relay when final expiry is below chain height") { f =>
260+
import f._
261+
262+
val expiryIn = CltvExpiry(500000)
263+
val expiryOut = CltvExpiry(300000) // not ok (chain heigh = 400000)
264+
val p = createValidIncomingPacket(2000000 msat, 2000000 msat, expiryIn, 1000000 msat, expiryOut)
265+
nodeRelayer ! NodeRelay.Relay(p)
266+
267+
val fwd = register.expectMessageType[Register.Forward[CMD_FAIL_HTLC]]
268+
assert(fwd.channelId === p.add.channelId)
269+
assert(fwd.message === CMD_FAIL_HTLC(p.add.id, Right(TrampolineExpiryTooSoon), commit = true))
270+
271+
register.expectNoMessage(100 millis)
272+
}
273+
259274
test("fail to relay when expiry is too soon (multi-part)") { f =>
260275
import f._
261276

0 commit comments

Comments
 (0)