Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trampoline fast fail #1727

Merged
merged 9 commits into from
Mar 10, 2021
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 (CltvExpiry(nodeParams.currentBlockHeight) > payloadOut.outgoingCltv) {
Some(IncorrectOrUnknownPaymentDetails(upstream.adds.head.amountMsat, nodeParams.currentBlockHeight))
} 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(IncorrectOrUnknownPaymentDetails(2000000 msat, 400000)), commit = true))

register.expectNoMessage(100 millis)
}

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

Expand Down