mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 09:40:19 +01:00
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>
This commit is contained in:
parent
4b5ec85c25
commit
1af3428c6c
3 changed files with 12 additions and 49 deletions
|
@ -269,21 +269,9 @@ static bool htlcs_changestate(struct peer *peer,
|
|||
struct htlc *h;
|
||||
bool changed = false;
|
||||
|
||||
for (h = htlc_map_first(&peer->local.htlcs, &it);
|
||||
for (h = htlc_map_first(&peer->htlcs, &it);
|
||||
h;
|
||||
h = htlc_map_next(&peer->local.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)) {
|
||||
h = htlc_map_next(&peer->htlcs, &it)) {
|
||||
size_t i;
|
||||
for (i = 0; i < n; i++) {
|
||||
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
|
||||
* theirs (future confusion). Nonetheless, we detect and
|
||||
* 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);
|
||||
|
||||
/* BOLT #2:
|
||||
|
|
|
@ -165,21 +165,9 @@ static bool committed_to_htlcs(const struct peer *peer)
|
|||
struct htlc_map_iter it;
|
||||
struct htlc *h;
|
||||
|
||||
for (h = htlc_map_first(&peer->local.htlcs, &it);
|
||||
for (h = htlc_map_first(&peer->htlcs, &it);
|
||||
h;
|
||||
h = htlc_map_next(&peer->local.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)) {
|
||||
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)
|
||||
|
@ -990,8 +978,7 @@ static struct peer *new_peer(struct lightningd_state *dstate,
|
|||
peer->local.commit = peer->remote.commit = NULL;
|
||||
peer->local.staging_cstate = peer->remote.staging_cstate = NULL;
|
||||
|
||||
htlc_map_init(&peer->local.htlcs);
|
||||
htlc_map_init(&peer->remote.htlcs);
|
||||
htlc_map_init(&peer->htlcs);
|
||||
|
||||
/* FIXME: Attach IO logging for this 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)
|
||||
{
|
||||
struct htlc_map *map;
|
||||
|
||||
/* 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))
|
||||
if (!htlc_map_del(&htlc->peer->htlcs, htlc))
|
||||
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. */
|
||||
h->deadline = expiry
|
||||
+ peer->dstate->config.min_htlc_expiry;
|
||||
htlc_map_add(&peer->local.htlcs, h);
|
||||
} else {
|
||||
assert(htlc_owner(h) == REMOTE);
|
||||
htlc_map_add(&peer->remote.htlcs, h);
|
||||
}
|
||||
htlc_map_add(&peer->htlcs, h);
|
||||
tal_add_destructor(h, htlc_destroy);
|
||||
|
||||
return h;
|
||||
|
|
|
@ -96,10 +96,6 @@ struct peer_visible_state {
|
|||
|
||||
/* cstate to generate next commitment tx. */
|
||||
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 */
|
||||
|
@ -184,7 +180,10 @@ struct peer {
|
|||
const struct commit_info *ci;
|
||||
const struct bitcoin_tx **resolved;
|
||||
} closing_onchain;
|
||||
|
||||
|
||||
/* All HTLCs. */
|
||||
struct htlc_map htlcs;
|
||||
|
||||
/* Current ongoing packetflow */
|
||||
struct io_data *io_data;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue