mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-23 17:14:22 +01:00
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 <decker.christian@gmail.com>
This commit is contained in:
committed by
Rusty Russell
parent
896a67d1d6
commit
cfac9a1f73
@@ -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)) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user