protocol: split message update_remove_htlc into update_timedout_htlc and update_routefail_htlc, remove update_remove_htlc_delay.

For the moment, there's no way to remove an in-progress HTLC before
it's timed out.  The other side can remove it with a routefail, but
you can't push for it to be removed.

We may add that later, but by definition it's only a polited request, and
normally we should rely on timeouts.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2015-09-24 15:02:49 +09:30
parent 807ac38308
commit d00eeded9f
7 changed files with 252 additions and 173 deletions

View File

@@ -167,10 +167,10 @@ struct channel_state *gather_updates(const tal_t *ctx,
our_rhash, their_rhash);
break;
case PKT__PKT_UPDATE_REMOVE_HTLC:
case PKT__PKT_UPDATE_TIMEDOUT_HTLC:
if (received) {
n = find_htlc(&cstate->b,
pkt->update_remove_htlc->r_hash);
pkt->update_timedout_htlc->r_hash);
if (n == tal_count(cstate->b.htlcs))
errx(1, "Unknown R hash in %s", *argv);
amount = cstate->b.htlcs[n]->amount_msat;
@@ -181,7 +181,7 @@ struct channel_state *gather_updates(const tal_t *ctx,
remove_htlc(&cstate->b, n);
} else {
n = find_htlc(&cstate->a,
pkt->update_remove_htlc->r_hash);
pkt->update_timedout_htlc->r_hash);
if (n == tal_count(cstate->a.htlcs))
errx(1, "Unknown R hash in %s", *argv);
amount = cstate->a.htlcs[n]->amount_msat;
@@ -191,12 +191,43 @@ struct channel_state *gather_updates(const tal_t *ctx,
(long long)amount, *argv);
remove_htlc(&cstate->a, n);
}
update_rhash(pkt->update_remove_htlc->revocation_hash,
update_rhash(pkt->update_timedout_htlc->revocation_hash,
received, num_updates,
&old_our_rhash, &old_their_rhash,
our_rhash, their_rhash);
break;
/* HTLC acceptor sends this to initiator. */
case PKT__PKT_UPDATE_ROUTEFAIL_HTLC:
if (received) {
n = find_htlc(&cstate->a,
pkt->update_routefail_htlc->r_hash);
if (n == tal_count(cstate->a.htlcs))
errx(1, "Unknown R hash in %s", *argv);
amount = cstate->a.htlcs[n]->amount;
if (!funding_delta(o1, o2, oa, 0, -amount,
&cstate->a, &cstate->b))
errx(1, "Impossible htlc %llu %s",
(long long)amount, *argv);
remove_htlc(&cstate->a, n);
} else {
n = find_htlc(&cstate->b,
pkt->update_routefail_htlc->r_hash);
if (n == tal_count(cstate->b.htlcs))
errx(1, "Unknown R hash in %s", *argv);
amount = cstate->b.htlcs[n]->amount;
if (!funding_delta(o2, o1, oa, 0, -amount,
&cstate->b, &cstate->a))
errx(1, "Impossible htlc %llu %s",
(long long)amount, *argv);
remove_htlc(&cstate->b, n);
}
update_rhash(pkt->update_routefail_htlc->revocation_hash,
received, num_updates,
&old_our_rhash, &old_their_rhash,
our_rhash, their_rhash);
break;
case PKT__PKT_UPDATE_COMPLETE_HTLC: {
struct sha256 r_hash, r_val;
Sha256Hash *rh;

View File

@@ -25,13 +25,16 @@ int main(int argc, char *argv[])
struct pkt *pkt;
unsigned update_num;
UpdateAddHtlc *u;
bool routefail = false;
err_set_progname(argv[0]);
opt_register_noarg("--help|-h", opt_usage_and_exit,
"<seed> <update-number> <update-pkt>\n"
"Create a new HTLC remove message",
"Create a new HTLC (timedout) remove message",
"Print this message.");
opt_register_noarg("--routefail", opt_set_bool, &routefail,
"Generate a routefail instead of timedout");
opt_register_version();
opt_parse(&argc, argv, opt_log_stderr_exit);
@@ -53,7 +56,12 @@ int main(int argc, char *argv[])
sha256(&revocation_hash,
revocation_hash.u.u8, sizeof(revocation_hash.u.u8));
pkt = update_htlc_remove_pkt(ctx, &revocation_hash, &htlc_rhash);
if (routefail)
pkt = update_htlc_routefail_pkt(ctx, &revocation_hash,
&htlc_rhash);
else
pkt = update_htlc_timedout_pkt(ctx, &revocation_hash,
&htlc_rhash);
if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
err(1, "Writing out packet");