mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-03 22:34:21 +01:00
liquidity-ads: persist channel blockheight states to disk
Adds new tables to database, backfills, basically copies the fee_rates state machine for channeld.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <ccan/ccan/tal/tal.h>
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <common/amount.h>
|
||||
#include <common/blockheight_states.h>
|
||||
#include <common/channel_config.h>
|
||||
#include <common/channel_id.h>
|
||||
#include <common/derive_basepoints.h>
|
||||
@@ -1116,7 +1117,8 @@ wallet_update_channel(struct lightningd *ld,
|
||||
const u32 lease_expiry,
|
||||
secp256k1_ecdsa_signature *lease_commit_sig STEALS,
|
||||
const u32 lease_chan_max_msat,
|
||||
const u16 lease_chan_max_ppt)
|
||||
const u16 lease_chan_max_ppt,
|
||||
const u32 lease_blockheight_start)
|
||||
{
|
||||
struct amount_msat our_msat;
|
||||
struct channel_inflight *inflight;
|
||||
@@ -1143,6 +1145,11 @@ wallet_update_channel(struct lightningd *ld,
|
||||
channel->lease_chan_max_msat = lease_chan_max_msat;
|
||||
channel->lease_chan_max_ppt = lease_chan_max_ppt;
|
||||
|
||||
tal_free(channel->blockheight_states);
|
||||
channel->blockheight_states = new_height_states(channel,
|
||||
channel->opener,
|
||||
&lease_blockheight_start);
|
||||
|
||||
channel_set_last_tx(channel,
|
||||
tal_steal(channel, remote_commit),
|
||||
remote_commit_sig,
|
||||
@@ -1164,7 +1171,8 @@ wallet_update_channel(struct lightningd *ld,
|
||||
channel->lease_expiry,
|
||||
channel->lease_commit_sig,
|
||||
channel->lease_chan_max_msat,
|
||||
channel->lease_chan_max_ppt);
|
||||
channel->lease_chan_max_ppt,
|
||||
lease_blockheight_start);
|
||||
wallet_inflight_add(ld->wallet, inflight);
|
||||
|
||||
return inflight;
|
||||
@@ -1186,6 +1194,7 @@ wallet_commit_channel(struct lightningd *ld,
|
||||
const u8 *our_upfront_shutdown_script,
|
||||
const u8 *remote_upfront_shutdown_script,
|
||||
struct wally_psbt *psbt STEALS,
|
||||
const u32 lease_blockheight_start,
|
||||
const u32 lease_expiry,
|
||||
secp256k1_ecdsa_signature *lease_commit_sig STEALS,
|
||||
const u32 lease_chan_max_msat,
|
||||
@@ -1257,6 +1266,9 @@ wallet_commit_channel(struct lightningd *ld,
|
||||
channel->first_blocknum = get_block_height(ld->topology);
|
||||
|
||||
/* Update lease info for channel */
|
||||
channel->blockheight_states = new_height_states(channel,
|
||||
channel->opener,
|
||||
&lease_blockheight_start);
|
||||
channel->lease_expiry = lease_expiry;
|
||||
|
||||
tal_free(channel->lease_commit_sig);
|
||||
@@ -1281,7 +1293,8 @@ wallet_commit_channel(struct lightningd *ld,
|
||||
channel->lease_expiry,
|
||||
channel->lease_commit_sig,
|
||||
channel->lease_chan_max_msat,
|
||||
channel->lease_chan_max_ppt);
|
||||
channel->lease_chan_max_ppt,
|
||||
lease_blockheight_start);
|
||||
wallet_inflight_add(ld->wallet, inflight);
|
||||
|
||||
return inflight;
|
||||
@@ -2837,7 +2850,7 @@ static void handle_commit_received(struct subd *dualopend,
|
||||
struct bitcoin_txid funding_txid;
|
||||
u16 funding_outnum, lease_chan_max_ppt;
|
||||
u32 feerate_funding, feerate_commitment, lease_expiry,
|
||||
lease_chan_max_msat;
|
||||
lease_chan_max_msat, lease_blockheight_start;
|
||||
struct amount_sat total_funding, funding_ours;
|
||||
u8 *remote_upfront_shutdown_script,
|
||||
*local_upfront_shutdown_script;
|
||||
@@ -2870,6 +2883,7 @@ static void handle_commit_received(struct subd *dualopend,
|
||||
&feerate_commitment,
|
||||
&local_upfront_shutdown_script,
|
||||
&remote_upfront_shutdown_script,
|
||||
&lease_blockheight_start,
|
||||
&lease_expiry,
|
||||
&lease_commit_sig,
|
||||
&lease_chan_max_msat,
|
||||
@@ -2915,6 +2929,7 @@ static void handle_commit_received(struct subd *dualopend,
|
||||
local_upfront_shutdown_script,
|
||||
remote_upfront_shutdown_script,
|
||||
psbt,
|
||||
lease_blockheight_start,
|
||||
lease_expiry,
|
||||
lease_commit_sig,
|
||||
lease_chan_max_msat,
|
||||
@@ -2951,7 +2966,8 @@ static void handle_commit_received(struct subd *dualopend,
|
||||
lease_expiry,
|
||||
lease_commit_sig,
|
||||
lease_chan_max_msat,
|
||||
lease_chan_max_ppt))) {
|
||||
lease_chan_max_ppt,
|
||||
lease_blockheight_start))) {
|
||||
channel_internal_error(channel,
|
||||
"wallet_update_channel failed"
|
||||
" (chan %s)",
|
||||
@@ -3224,7 +3240,7 @@ void peer_restart_dualopend(struct peer *peer,
|
||||
struct per_peer_state *pps,
|
||||
struct channel *channel)
|
||||
{
|
||||
u32 max_to_self_delay;
|
||||
u32 max_to_self_delay, blockheight;
|
||||
struct amount_msat min_effective_htlc_capacity;
|
||||
struct channel_config unused_config;
|
||||
struct channel_inflight *inflight;
|
||||
@@ -3268,6 +3284,8 @@ void peer_restart_dualopend(struct peer *peer,
|
||||
|
||||
inflight = channel_current_inflight(channel);
|
||||
assert(inflight);
|
||||
blockheight = get_blockheight(channel->blockheight_states,
|
||||
channel->opener, LOCAL);
|
||||
|
||||
msg = towire_dualopend_reinit(NULL,
|
||||
chainparams,
|
||||
@@ -3301,6 +3319,7 @@ void peer_restart_dualopend(struct peer *peer,
|
||||
inflight->remote_tx_sigs,
|
||||
channel->fee_states,
|
||||
channel->channel_flags,
|
||||
blockheight,
|
||||
inflight->lease_expiry,
|
||||
inflight->lease_commit_sig,
|
||||
inflight->lease_chan_max_msat,
|
||||
|
||||
Reference in New Issue
Block a user