Skip to content

Commit

Permalink
Reject trampoline payments with expired outgoing cltv (#1727)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
akumaigorodski authored Mar 10, 2021
1 parent 9ff2f83 commit 6364ae3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ object NodeRelay {
Some(TrampolineFeeInsufficient)
} else if (upstream.expiryIn - payloadOut.outgoingCltv < nodeParams.expiryDelta) {
Some(TrampolineExpiryTooSoon)
} else if (payloadOut.outgoingCltv <= CltvExpiry(nodeParams.currentBlockHeight)) {
Some(TrampolineExpiryTooSoon)
} else {
None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,21 @@ class NodeRelayerSpec extends ScalaTestWithActorTestKit(ConfigFactory.load("appl
register.expectNoMessage(100 millis)
}

test("fail to relay when final expiry is below chain height") { f =>
import f._

val expiryIn = CltvExpiry(500000)
val expiryOut = CltvExpiry(300000) // not ok (chain heigh = 400000)
val p = createValidIncomingPacket(2000000 msat, 2000000 msat, expiryIn, 1000000 msat, expiryOut)
nodeRelayer ! NodeRelay.Relay(p)

val fwd = register.expectMessageType[Register.Forward[CMD_FAIL_HTLC]]
assert(fwd.channelId === p.add.channelId)
assert(fwd.message === CMD_FAIL_HTLC(p.add.id, Right(TrampolineExpiryTooSoon), commit = true))

register.expectNoMessage(100 millis)
}

test("fail to relay when expiry is too soon (multi-part)") { f =>
import f._

Expand Down

0 comments on commit 6364ae3

Please sign in to comment.