Browse Source

peer: keep a single HTLC map for all htlcs.

Not separate "locally-offered" and "remotely-offered" ones; we can
distinguish them by htlc->state now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
1af3428c6c
  1. 18
      daemon/packets.c
  2. 34
      daemon/peer.c
  3. 9
      daemon/peer.h

18
daemon/packets.c

@ -269,21 +269,9 @@ static bool htlcs_changestate(struct peer *peer,
struct htlc *h; struct htlc *h;
bool changed = false; bool changed = false;
for (h = htlc_map_first(&peer->local.htlcs, &it); for (h = htlc_map_first(&peer->htlcs, &it);
h; h;
h = htlc_map_next(&peer->local.htlcs, &it)) { h = htlc_map_next(&peer->htlcs, &it)) {
size_t i;
for (i = 0; i < n; i++) {
if (h->state == table[i].from) {
htlc_changestate(h, table[i].from, table[i].to);
changed = true;
}
}
}
for (h = htlc_map_first(&peer->remote.htlcs, &it);
h;
h = htlc_map_next(&peer->remote.htlcs, &it)) {
size_t i; size_t i;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (h->state == table[i].from) { if (h->state == table[i].from) {
@ -689,7 +677,7 @@ Pkt *accept_pkt_htlc_add(struct peer *peer, const Pkt *pkt)
/* Note that it's not *our* problem if they do this, it's /* Note that it's not *our* problem if they do this, it's
* theirs (future confusion). Nonetheless, we detect and * theirs (future confusion). Nonetheless, we detect and
* error for them. */ * error for them. */
if (htlc_map_get(&peer->remote.htlcs, u->id)) if (htlc_get(&peer->htlcs, u->id, REMOTE))
return pkt_err(peer, "HTLC id %"PRIu64" clashes for you", u->id); return pkt_err(peer, "HTLC id %"PRIu64" clashes for you", u->id);
/* BOLT #2: /* BOLT #2:

34
daemon/peer.c

@ -165,21 +165,9 @@ static bool committed_to_htlcs(const struct peer *peer)
struct htlc_map_iter it; struct htlc_map_iter it;
struct htlc *h; struct htlc *h;
for (h = htlc_map_first(&peer->local.htlcs, &it); for (h = htlc_map_first(&peer->htlcs, &it);
h; h;
h = htlc_map_next(&peer->local.htlcs, &it)) { h = htlc_map_next(&peer->htlcs, &it)) {
/* FIXME: Move these dead ones to a separate hash (or
* just leave in database only). */
if (h->state == RCVD_REMOVE_ACK_REVOCATION)
continue;
if (h->state == SENT_REMOVE_ACK_REVOCATION)
continue;
return true;
}
for (h = htlc_map_first(&peer->remote.htlcs, &it);
h;
h = htlc_map_next(&peer->remote.htlcs, &it)) {
/* FIXME: Move these dead ones to a separate hash (or /* FIXME: Move these dead ones to a separate hash (or
* just leave in database only). */ * just leave in database only). */
if (h->state == RCVD_REMOVE_ACK_REVOCATION) if (h->state == RCVD_REMOVE_ACK_REVOCATION)
@ -990,8 +978,7 @@ static struct peer *new_peer(struct lightningd_state *dstate,
peer->local.commit = peer->remote.commit = NULL; peer->local.commit = peer->remote.commit = NULL;
peer->local.staging_cstate = peer->remote.staging_cstate = NULL; peer->local.staging_cstate = peer->remote.staging_cstate = NULL;
htlc_map_init(&peer->local.htlcs); htlc_map_init(&peer->htlcs);
htlc_map_init(&peer->remote.htlcs);
/* FIXME: Attach IO logging for this peer. */ /* FIXME: Attach IO logging for this peer. */
tal_add_destructor(peer, destroy_peer); tal_add_destructor(peer, destroy_peer);
@ -1014,17 +1001,7 @@ static struct peer *new_peer(struct lightningd_state *dstate,
static void htlc_destroy(struct htlc *htlc) static void htlc_destroy(struct htlc *htlc)
{ {
struct htlc_map *map; if (!htlc_map_del(&htlc->peer->htlcs, htlc))
/* FIXME: make peer->local/remote an array*/
if (htlc_owner(htlc) == LOCAL)
map = &htlc->peer->local.htlcs;
else {
assert(htlc_owner(htlc) == REMOTE);
map = &htlc->peer->remote.htlcs;
}
if (!htlc_map_del(map, htlc))
fatal("Could not find htlc to destroy"); fatal("Could not find htlc to destroy");
} }
@ -1058,11 +1035,10 @@ struct htlc *peer_new_htlc(struct peer *peer,
/* If we're paying, give it a little longer. */ /* If we're paying, give it a little longer. */
h->deadline = expiry h->deadline = expiry
+ peer->dstate->config.min_htlc_expiry; + peer->dstate->config.min_htlc_expiry;
htlc_map_add(&peer->local.htlcs, h);
} else { } else {
assert(htlc_owner(h) == REMOTE); assert(htlc_owner(h) == REMOTE);
htlc_map_add(&peer->remote.htlcs, h);
} }
htlc_map_add(&peer->htlcs, h);
tal_add_destructor(h, htlc_destroy); tal_add_destructor(h, htlc_destroy);
return h; return h;

9
daemon/peer.h

@ -96,10 +96,6 @@ struct peer_visible_state {
/* cstate to generate next commitment tx. */ /* cstate to generate next commitment tx. */
struct channel_state *staging_cstate; struct channel_state *staging_cstate;
/* FIXME: Use single map in struct peer. */
/* HTLCs offered by this side */
struct htlc_map htlcs;
}; };
/* Off peer->outgoing_txs */ /* Off peer->outgoing_txs */
@ -184,7 +180,10 @@ struct peer {
const struct commit_info *ci; const struct commit_info *ci;
const struct bitcoin_tx **resolved; const struct bitcoin_tx **resolved;
} closing_onchain; } closing_onchain;
/* All HTLCs. */
struct htlc_map htlcs;
/* Current ongoing packetflow */ /* Current ongoing packetflow */
struct io_data *io_data; struct io_data *io_data;

Loading…
Cancel
Save