mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-26 20:30:59 +01:00
lightningd: add last_stable_connection field to db, channel.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
81a280d8a3
commit
0575f8a544
8 changed files with 28 additions and 9 deletions
|
@ -313,6 +313,7 @@ struct channel *new_unsaved_channel(struct peer *peer,
|
|||
|
||||
channel->lease_commit_sig = NULL;
|
||||
channel->ignore_fee_limits = ld->config.ignore_fee_limits;
|
||||
channel->last_stable_connection = 0;
|
||||
|
||||
/* No shachain yet */
|
||||
channel->their_shachain.id = 0;
|
||||
|
@ -449,7 +450,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
|||
struct amount_msat htlc_maximum_msat,
|
||||
bool ignore_fee_limits,
|
||||
/* NULL or stolen */
|
||||
struct peer_update *peer_update STEALS)
|
||||
struct peer_update *peer_update STEALS,
|
||||
u64 last_stable_connection)
|
||||
{
|
||||
struct channel *channel = tal(peer->ld, struct channel);
|
||||
struct amount_msat htlc_min, htlc_max;
|
||||
|
@ -600,6 +602,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
|||
channel->close_blockheight = NULL;
|
||||
channel->state_change_cause = reason;
|
||||
channel->ignore_fee_limits = ignore_fee_limits;
|
||||
channel->last_stable_connection = last_stable_connection;
|
||||
/* Populate channel->channel_gossip */
|
||||
channel_gossip_init(channel, take(peer_update));
|
||||
|
||||
|
|
|
@ -310,6 +310,9 @@ struct channel {
|
|||
|
||||
/* Do we allow the peer to set any fee it wants? */
|
||||
bool ignore_fee_limits;
|
||||
|
||||
/* Last time we had a stable connection, if any (0 = none) */
|
||||
u64 last_stable_connection;
|
||||
};
|
||||
|
||||
/* Is channel owned (and should be talking to peer) */
|
||||
|
@ -390,7 +393,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
|||
struct amount_msat htlc_maximum_msat,
|
||||
bool ignore_fee_limits,
|
||||
/* NULL or stolen */
|
||||
struct peer_update *peer_update STEALS);
|
||||
struct peer_update *peer_update STEALS,
|
||||
u64 last_stable_connection);
|
||||
|
||||
/* new_inflight - Create a new channel_inflight for a channel */
|
||||
struct channel_inflight *new_inflight(struct channel *channel,
|
||||
|
|
|
@ -27,6 +27,7 @@ struct closed_channel {
|
|||
const struct channel_type *type;
|
||||
enum state_change state_change_cause;
|
||||
bool leased;
|
||||
u64 last_stable_connection;
|
||||
};
|
||||
|
||||
#endif /* LIGHTNING_LIGHTNINGD_CLOSED_CHANNEL_H */
|
||||
|
|
|
@ -235,7 +235,8 @@ wallet_commit_channel(struct lightningd *ld,
|
|||
ld->config.htlc_minimum_msat,
|
||||
ld->config.htlc_maximum_msat,
|
||||
ld->config.ignore_fee_limits,
|
||||
NULL);
|
||||
NULL,
|
||||
0);
|
||||
|
||||
/* Now we finally put it in the database. */
|
||||
wallet_channel_insert(ld->wallet, channel);
|
||||
|
@ -1504,7 +1505,8 @@ static struct channel *stub_chan(struct command *cmd,
|
|||
ld->config.htlc_minimum_msat,
|
||||
ld->config.htlc_maximum_msat,
|
||||
false,
|
||||
NULL);
|
||||
NULL,
|
||||
0);
|
||||
|
||||
/* We don't want to gossip about this, ever. */
|
||||
channel->channel_gossip = tal_free(channel->channel_gossip);
|
||||
|
|
|
@ -1016,6 +1016,7 @@ static struct migration dbmigrations[] = {
|
|||
{SQL("ALTER TABLE channels ADD remote_cltv_expiry_delta INTEGER DEFAULT NULL;"), NULL},
|
||||
{SQL("ALTER TABLE channels ADD remote_htlc_maximum_msat BIGINT DEFAULT NULL;"), NULL},
|
||||
{SQL("ALTER TABLE channels ADD remote_htlc_minimum_msat BIGINT DEFAULT NULL;"), NULL},
|
||||
{SQL("ALTER TABLE channels ADD last_stable_connection BIGINT DEFAULT 0;"), NULL},
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -184,7 +184,8 @@ struct channel *new_channel(struct peer *peer UNNEEDED, u64 dbid UNNEEDED,
|
|||
struct amount_msat htlc_maximum_msat UNNEEDED,
|
||||
bool ignore_fee_limits UNNEEDED,
|
||||
/* NULL or stolen */
|
||||
struct peer_update *peer_update STEALS UNNEEDED)
|
||||
struct peer_update *peer_update STEALS UNNEEDED,
|
||||
u64 last_stable_connection UNNEEDED)
|
||||
{ fprintf(stderr, "new_channel called!\n"); abort(); }
|
||||
/* Generated stub for new_coin_wallet_deposit */
|
||||
struct chain_coin_mvt *new_coin_wallet_deposit(const tal_t *ctx UNNEEDED,
|
||||
|
|
|
@ -2007,7 +2007,8 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx)
|
|||
AMOUNT_MSAT(0),
|
||||
AMOUNT_MSAT(-1ULL),
|
||||
false,
|
||||
NULL);
|
||||
NULL,
|
||||
0);
|
||||
db_begin_transaction(w->db);
|
||||
CHECK(!wallet_err);
|
||||
wallet_channel_insert(w, chan);
|
||||
|
|
|
@ -1763,7 +1763,8 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
|
|||
htlc_minimum_msat,
|
||||
htlc_maximum_msat,
|
||||
ignore_fee_limits,
|
||||
remote_update);
|
||||
remote_update,
|
||||
db_col_u64(stmt, "last_stable_connection"));
|
||||
|
||||
if (!wallet_channel_load_inflights(w, chan)) {
|
||||
tal_free(chan);
|
||||
|
@ -1800,6 +1801,7 @@ static struct closed_channel *wallet_stmt2closed_channel(const tal_t *ctx,
|
|||
cc->our_msat = db_col_amount_msat(stmt, "msatoshi_local");
|
||||
cc->msat_to_us_min = db_col_amount_msat(stmt, "msatoshi_to_us_min");
|
||||
cc->msat_to_us_max = db_col_amount_msat(stmt, "msatoshi_to_us_max");
|
||||
cc->last_stable_connection = db_col_u64(stmt, "last_stable_connection");
|
||||
/* last_tx is null for stub channels used for recovering funds through
|
||||
* Static channel backups. */
|
||||
if (!db_col_is_null(stmt, "last_tx"))
|
||||
|
@ -1845,6 +1847,7 @@ struct closed_channel **wallet_load_closed_channels(const tal_t *ctx,
|
|||
", channel_type"
|
||||
", state_change_reason"
|
||||
", lease_commit_sig"
|
||||
", last_stable_connection"
|
||||
" FROM channels"
|
||||
" LEFT JOIN peers p ON p.id = peer_id"
|
||||
" WHERE state = ?;"));
|
||||
|
@ -1956,6 +1959,7 @@ static bool wallet_channels_load_active(struct wallet *w)
|
|||
", remote_cltv_expiry_delta"
|
||||
", remote_htlc_minimum_msat"
|
||||
", remote_htlc_maximum_msat"
|
||||
", last_stable_connection"
|
||||
" FROM channels"
|
||||
" WHERE state != ?;")); //? 0
|
||||
db_bind_int(stmt, CLOSED);
|
||||
|
@ -2275,8 +2279,9 @@ void wallet_channel_save(struct wallet *w, struct channel *chan)
|
|||
" remote_feerate_ppm=?," // 48
|
||||
" remote_cltv_expiry_delta=?," // 49
|
||||
" remote_htlc_minimum_msat=?," // 50
|
||||
" remote_htlc_maximum_msat=?" // 51
|
||||
" WHERE id=?")); // 52
|
||||
" remote_htlc_maximum_msat=?,"
|
||||
" last_stable_connection=?"
|
||||
" WHERE id=?"));
|
||||
db_bind_u64(stmt, chan->their_shachain.id);
|
||||
if (chan->scid)
|
||||
db_bind_short_channel_id(stmt, chan->scid);
|
||||
|
@ -2372,6 +2377,7 @@ void wallet_channel_save(struct wallet *w, struct channel *chan)
|
|||
db_bind_null(stmt);
|
||||
db_bind_null(stmt);
|
||||
}
|
||||
db_bind_u64(stmt, chan->last_stable_connection);
|
||||
db_bind_u64(stmt, chan->dbid);
|
||||
db_exec_prepared_v2(take(stmt));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue