From cfac9a1f736e65de3d3ade398e7e121b4d732e6f Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 10 Oct 2017 19:47:38 +0200 Subject: [PATCH] htlcs: Remove in-memory htlc_stubs We pull them from the database on-demand, where we're storing them anyway. No need to keep them in memory as well. Signed-off-by: Christian Decker --- lightningd/lightningd.c | 1 - lightningd/peer_control.c | 1 - lightningd/peer_control.h | 3 --- lightningd/peer_htlcs.c | 29 ----------------------------- 4 files changed, 34 deletions(-) diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index bdae17e7d..25a8a1ea6 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -290,7 +290,6 @@ int main(int argc, char *argv[]) populate_peer(ld, peer); peer->seed = tal(peer, struct privkey); derive_peer_seed(ld, peer->seed, &peer->id, peer->channel->id); - peer->htlcs = tal_arr(peer, struct htlc_stub, 0); peer->owner = NULL; if (!wallet_htlcs_load_for_channel(ld->wallet, peer->channel, &ld->htlcs_in, &ld->htlcs_out)) { diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index f1f2870fa..c184b9be7 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -635,7 +635,6 @@ void add_peer(struct lightningd *ld, u64 unique_id, peer->next_index[LOCAL] = peer->next_index[REMOTE] = 0; peer->next_htlc_id = 0; - peer->htlcs = tal_arr(peer, struct htlc_stub, 0); wallet_shachain_init(ld->wallet, &peer->their_shachain); /* If we have the peer in the DB, this'll populate the fields, diff --git a/lightningd/peer_control.h b/lightningd/peer_control.h index c787abc90..50c888eb7 100644 --- a/lightningd/peer_control.h +++ b/lightningd/peer_control.h @@ -98,9 +98,6 @@ struct peer { bool last_was_revoke; struct changed_htlc *last_sent_commit; - /* FIXME: Just leave this in the db. */ - struct htlc_stub *htlcs; - struct wallet_channel *channel; }; diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index e79027b3b..047ec516a 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -79,24 +79,6 @@ static bool htlc_out_update_state(struct peer *peer, return true; } -/* This is where we write to the database the minimal HTLC info - * required to do penalty transaction */ -static void save_htlc_stub(struct lightningd *ld, - struct peer *peer, - enum side owner, - u32 cltv_value, - const struct sha256 *payment_hash) -{ - size_t n = tal_count(peer->htlcs); - tal_resize(&peer->htlcs, n+1); - peer->htlcs[n].owner = owner; - peer->htlcs[n].cltv_expiry = cltv_value; - ripemd160(&peer->htlcs[n].ripemd, - payment_hash->u.u8, sizeof(payment_hash->u)); - - /* FIXME: save to db instead! */ -} - static void fail_in_htlc(struct htlc_in *hin, enum onion_type malformed, const u8 *failuremsg) @@ -934,10 +916,6 @@ static bool update_out_htlc(struct peer *peer, u64 id, enum htlc_state newstate) tal_del_destructor(hout, hout_subd_died); tal_steal(peer->ld, hout); - /* From now onwards, penalty tx might need this */ - save_htlc_stub(peer->ld, peer, LOCAL, - hout->cltv_expiry, - &hout->payment_hash); } else if (newstate == RCVD_REMOVE_ACK_REVOCATION) { remove_htlc_out(peer, hout); } @@ -1072,13 +1050,6 @@ static void added_their_htlc(struct peer *peer, log_debug(peer->log, "Adding their HTLC %"PRIu64, added->id); connect_htlc_in(&peer->ld->htlcs_in, hin); - /* Technically this can't be needed for a penalty transaction until - * after we send revoke_and_ack, then commit, then receive their - * revoke_and_ack. But might as well record it while we have it: - * a few extra entries won't hurt */ - save_htlc_stub(peer->ld, peer, REMOTE, hin->cltv_expiry, - &hin->payment_hash); - } /* The peer doesn't tell us this separately, but logically it's a separate