mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
channel: Add struct scb_chan in channel and making last tx optional.
This commit is contained in:
parent
e42ba8366b
commit
eca844eb36
4 changed files with 45 additions and 5 deletions
|
@ -212,6 +212,7 @@ struct channel *new_unsaved_channel(struct peer *peer,
|
||||||
channel->openchannel_signed_cmd = NULL;
|
channel->openchannel_signed_cmd = NULL;
|
||||||
channel->state = DUALOPEND_OPEN_INIT;
|
channel->state = DUALOPEND_OPEN_INIT;
|
||||||
channel->owner = NULL;
|
channel->owner = NULL;
|
||||||
|
channel->scb = NULL;
|
||||||
memset(&channel->billboard, 0, sizeof(channel->billboard));
|
memset(&channel->billboard, 0, sizeof(channel->billboard));
|
||||||
channel->billboard.transient = tal_fmt(channel, "%s",
|
channel->billboard.transient = tal_fmt(channel, "%s",
|
||||||
"Empty channel init'd");
|
"Empty channel init'd");
|
||||||
|
@ -419,6 +420,14 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
||||||
channel->owner = NULL;
|
channel->owner = NULL;
|
||||||
memset(&channel->billboard, 0, sizeof(channel->billboard));
|
memset(&channel->billboard, 0, sizeof(channel->billboard));
|
||||||
channel->billboard.transient = tal_strdup(channel, transient_billboard);
|
channel->billboard.transient = tal_strdup(channel, transient_billboard);
|
||||||
|
channel->scb = tal(channel, struct scb_chan);
|
||||||
|
channel->scb->id = dbid;
|
||||||
|
channel->scb->addr = peer->addr;
|
||||||
|
channel->scb->node_id = peer->id;
|
||||||
|
channel->scb->funding = *funding;
|
||||||
|
channel->scb->cid = *cid;
|
||||||
|
channel->scb->funding_sats = funding_sats;
|
||||||
|
channel->scb->type = channel_type_dup(channel->scb, type);
|
||||||
|
|
||||||
if (!log) {
|
if (!log) {
|
||||||
channel->log = new_log(channel,
|
channel->log = new_log(channel,
|
||||||
|
@ -447,9 +456,11 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
|
||||||
channel->our_msat = our_msat;
|
channel->our_msat = our_msat;
|
||||||
channel->msat_to_us_min = msat_to_us_min;
|
channel->msat_to_us_min = msat_to_us_min;
|
||||||
channel->msat_to_us_max = msat_to_us_max;
|
channel->msat_to_us_max = msat_to_us_max;
|
||||||
channel->last_tx = tal_steal(channel, last_tx);
|
channel->last_tx = tal_steal(channel, last_tx);
|
||||||
channel->last_tx->chainparams = chainparams;
|
if (channel->last_tx) {
|
||||||
channel->last_tx_type = TX_UNKNOWN;
|
channel->last_tx->chainparams = chainparams;
|
||||||
|
channel->last_tx_type = TX_UNKNOWN;
|
||||||
|
}
|
||||||
channel->last_sig = *last_sig;
|
channel->last_sig = *last_sig;
|
||||||
channel->last_htlc_sigs = tal_steal(channel, last_htlc_sigs);
|
channel->last_htlc_sigs = tal_steal(channel, last_htlc_sigs);
|
||||||
channel->channel_info = *channel_info;
|
channel->channel_info = *channel_info;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <common/channel_id.h>
|
#include <common/channel_id.h>
|
||||||
#include <common/channel_type.h>
|
#include <common/channel_type.h>
|
||||||
|
#include <common/scb_wiregen.h>
|
||||||
#include <common/tx_roles.h>
|
#include <common/tx_roles.h>
|
||||||
#include <common/utils.h>
|
#include <common/utils.h>
|
||||||
#include <lightningd/channel_state.h>
|
#include <lightningd/channel_state.h>
|
||||||
|
@ -260,6 +261,10 @@ struct channel {
|
||||||
|
|
||||||
/* Latest channel_update, for use in error messages. */
|
/* Latest channel_update, for use in error messages. */
|
||||||
u8 *channel_update;
|
u8 *channel_update;
|
||||||
|
|
||||||
|
/* `Channel-shell` of this channel
|
||||||
|
* (Minimum information required to backup this channel). */
|
||||||
|
struct scb_chan *scb;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* For v2 opens, a channel that has not yet been committed/saved to disk */
|
/* For v2 opens, a channel that has not yet been committed/saved to disk */
|
||||||
|
|
|
@ -1228,6 +1228,14 @@ wallet_commit_channel(struct lightningd *ld,
|
||||||
&commitment_feerate);
|
&commitment_feerate);
|
||||||
channel->min_possible_feerate = commitment_feerate;
|
channel->min_possible_feerate = commitment_feerate;
|
||||||
channel->max_possible_feerate = commitment_feerate;
|
channel->max_possible_feerate = commitment_feerate;
|
||||||
|
channel->scb = tal(channel, struct scb_chan);
|
||||||
|
channel->scb->id = channel->dbid;
|
||||||
|
channel->scb->addr = channel->peer->addr;
|
||||||
|
channel->scb->node_id = channel->peer->id;
|
||||||
|
channel->scb->funding = *funding;
|
||||||
|
channel->scb->cid = channel->cid;
|
||||||
|
channel->scb->funding_sats = total_funding;
|
||||||
|
channel->scb->type = channel_type_dup(channel->scb, channel->type);
|
||||||
|
|
||||||
/* We are connected */
|
/* We are connected */
|
||||||
channel->connected = true;
|
channel->connected = true;
|
||||||
|
|
|
@ -1114,6 +1114,7 @@ wallet_stmt2inflight(struct wallet *w, struct db_stmt *stmt,
|
||||||
struct amount_msat lease_fee;
|
struct amount_msat lease_fee;
|
||||||
struct bitcoin_outpoint funding;
|
struct bitcoin_outpoint funding;
|
||||||
struct bitcoin_signature last_sig;
|
struct bitcoin_signature last_sig;
|
||||||
|
struct bitcoin_tx *last_tx;
|
||||||
struct channel_inflight *inflight;
|
struct channel_inflight *inflight;
|
||||||
|
|
||||||
secp256k1_ecdsa_signature *lease_commit_sig;
|
secp256k1_ecdsa_signature *lease_commit_sig;
|
||||||
|
@ -1149,12 +1150,19 @@ wallet_stmt2inflight(struct wallet *w, struct db_stmt *stmt,
|
||||||
db_col_ignore(stmt, "lease_fee");
|
db_col_ignore(stmt, "lease_fee");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* last_tx is null for stub channels used for recovering funds through
|
||||||
|
* Static channel backups. */
|
||||||
|
if (!db_col_is_null(stmt, "last_tx"))
|
||||||
|
last_tx = db_col_psbt_to_tx(tmpctx, stmt, "last_tx");
|
||||||
|
else
|
||||||
|
last_tx = NULL;
|
||||||
|
|
||||||
inflight = new_inflight(chan, &funding,
|
inflight = new_inflight(chan, &funding,
|
||||||
db_col_int(stmt, "funding_feerate"),
|
db_col_int(stmt, "funding_feerate"),
|
||||||
funding_sat,
|
funding_sat,
|
||||||
our_funding_sat,
|
our_funding_sat,
|
||||||
db_col_psbt(tmpctx, stmt, "funding_psbt"),
|
db_col_psbt(tmpctx, stmt, "funding_psbt"),
|
||||||
db_col_psbt_to_tx(tmpctx, stmt, "last_tx"),
|
last_tx,
|
||||||
last_sig,
|
last_sig,
|
||||||
db_col_int(stmt, "lease_expiry"),
|
db_col_int(stmt, "lease_expiry"),
|
||||||
lease_commit_sig,
|
lease_commit_sig,
|
||||||
|
@ -1260,6 +1268,7 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
|
||||||
struct bitcoin_outpoint funding;
|
struct bitcoin_outpoint funding;
|
||||||
struct bitcoin_outpoint *shutdown_wrong_funding;
|
struct bitcoin_outpoint *shutdown_wrong_funding;
|
||||||
struct bitcoin_signature last_sig;
|
struct bitcoin_signature last_sig;
|
||||||
|
struct bitcoin_tx *last_tx;
|
||||||
u8 *remote_shutdown_scriptpubkey;
|
u8 *remote_shutdown_scriptpubkey;
|
||||||
u8 *local_shutdown_scriptpubkey;
|
u8 *local_shutdown_scriptpubkey;
|
||||||
struct changed_htlc *last_sent_commit;
|
struct changed_htlc *last_sent_commit;
|
||||||
|
@ -1445,6 +1454,13 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
|
||||||
else
|
else
|
||||||
type = channel_type_none(NULL);
|
type = channel_type_none(NULL);
|
||||||
|
|
||||||
|
/* last_tx is null for stub channels used for recovering funds through
|
||||||
|
* Static channel backups. */
|
||||||
|
if (!db_col_is_null(stmt, "last_tx"))
|
||||||
|
last_tx = db_col_psbt_to_tx(tmpctx, stmt, "last_tx");
|
||||||
|
else
|
||||||
|
last_tx = NULL;
|
||||||
|
|
||||||
chan = new_channel(peer, db_col_u64(stmt, "id"),
|
chan = new_channel(peer, db_col_u64(stmt, "id"),
|
||||||
&wshachain,
|
&wshachain,
|
||||||
db_col_int(stmt, "state"),
|
db_col_int(stmt, "state"),
|
||||||
|
@ -1469,7 +1485,7 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
|
||||||
our_msat,
|
our_msat,
|
||||||
msat_to_us_min, /* msatoshi_to_us_min */
|
msat_to_us_min, /* msatoshi_to_us_min */
|
||||||
msat_to_us_max, /* msatoshi_to_us_max */
|
msat_to_us_max, /* msatoshi_to_us_max */
|
||||||
db_col_psbt_to_tx(tmpctx, stmt, "last_tx"),
|
last_tx,
|
||||||
&last_sig,
|
&last_sig,
|
||||||
wallet_htlc_sigs_load(tmpctx, w,
|
wallet_htlc_sigs_load(tmpctx, w,
|
||||||
db_col_u64(stmt, "id"),
|
db_col_u64(stmt, "id"),
|
||||||
|
|
Loading…
Add table
Reference in a new issue