Skip to content

Commit

Permalink
Reject 0-value trampoline payments (#1851)
Browse files Browse the repository at this point in the history
It doesn't make any sense to forward empty payments.
This is also checked when adding the htlcs in the outgoing channel, but
we should fail early here.
  • Loading branch information
t-bast authored Jun 28, 2021
1 parent 45204e2 commit 85ed433
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ object NodeRelay {
Some(TrampolineExpiryTooSoon)
} else if (payloadOut.invoiceFeatures.isDefined && payloadOut.paymentSecret.isEmpty) {
Some(InvalidOnionPayload(UInt64(8), 0)) // payment secret field is missing
} else if (payloadOut.amountToForward <= MilliSatoshi(0)) {
Some(InvalidOnionPayload(UInt64(2), 0))
} else {
None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,39 @@ class NodeRelayerSpec extends ScalaTestWithActorTestKit(ConfigFactory.load("appl
register.expectNoMessage(100 millis)
}

test("fail to relay when amount is 0 (single-part)") { f =>
import f._

val p = createValidIncomingPacket(5000000 msat, 5000000 msat, CltvExpiry(500000), 0 msat, CltvExpiry(490000))
val (nodeRelayer, _) = f.createNodeRelay(p)
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(InvalidOnionPayload(UInt64(2), 0)), commit = true))

register.expectNoMessage(100 millis)
}

test("fail to relay when amount is 0 (multi-part)") { f =>
import f._

val p = Seq(
createValidIncomingPacket(4000000 msat, 5000000 msat, CltvExpiry(500000), 0 msat, CltvExpiry(490000)),
createValidIncomingPacket(1000000 msat, 5000000 msat, CltvExpiry(500000), 0 msat, CltvExpiry(490000))
)
val (nodeRelayer, _) = f.createNodeRelay(p.head)
p.foreach(p => nodeRelayer ! NodeRelay.Relay(p))

p.foreach { 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(InvalidOnionPayload(UInt64(2), 0)), commit = true))
}

register.expectNoMessage(100 millis)
}

test("fail to relay because outgoing balance isn't sufficient (low fees)") { f =>
import f._

Expand Down

0 comments on commit 85ed433

Please sign in to comment.