From 9046597344297e8603dfe1f6042c5c3b1c7df54f Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 25 Jun 2016 14:08:47 +0930 Subject: [PATCH] daemon: tighten check for invalid IDs. We don't have to, but helps debugging. Language in latest rev of BOLT#2 has been tightened too (aa2e1919de0826beaf92e0b3b441a6ab9fce6261) Signed-off-by: Rusty Russell --- daemon/packets.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/daemon/packets.c b/daemon/packets.c index df1ce1a5c..1abbc9a97 100644 --- a/daemon/packets.c +++ b/daemon/packets.c @@ -613,15 +613,20 @@ Pkt *accept_pkt_htlc_add(struct peer *peer, const Pkt *pkt) /* BOLT #2: * * A node MUST NOT set `id` equal to another HTLC which is in - * the current staged commitment transaction. + * any unrevoked commitment transaction. */ - if (funding_htlc_by_id(peer->remote.staging_cstate, u->id, THEIRS) != -1) + /* Note that it's not *our* problem if they do this, it's + * theirs (future confusion). Nonetheless, we detect and + * error for them. */ + if (funding_htlc_by_id(peer->remote.staging_cstate, u->id, THEIRS) != -1 + || funding_htlc_by_id(peer->remote.commit->cstate, u->id, THEIRS) != -1) { return pkt_err(peer, "HTLC id %"PRIu64" clashes for you", u->id); + } - /* FIXME: Assert this... */ - /* Note: these should be in sync, so this should be redundant! */ - if (funding_htlc_by_id(peer->local.staging_cstate, u->id, THEIRS) != -1) - return pkt_err(peer, "HTLC id %"PRIu64" clashes for us", u->id); + if (funding_htlc_by_id(peer->local.staging_cstate, u->id, THEIRS) != -1 + || funding_htlc_by_id(peer->local.commit->cstate, u->id, THEIRS) != -1) { + return pkt_err(peer, "HTLC id %"PRIu64" clashes for you", u->id); + } /* BOLT #2: *