df: persist our setting to disk, read back to dualopend at reinit

It's not likely but possible that the node's settings will shift btw a
start and an RBF; we persist the setting to the database so we don't
lose it.

Right now holding onto it forever is kind of extra but maybe we'll
reuse the setting for splices? idk.

Should this be a channel type??
This commit is contained in:
niftynei 2023-01-12 13:14:47 -06:00 committed by Alex Myers
parent fa80f15f85
commit beec517910
9 changed files with 36 additions and 21 deletions

View file

@ -336,6 +336,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
struct log *log,
const char *transient_billboard TAKES,
u8 channel_flags,
bool req_confirmed_ins_local,
bool req_confirmed_ins_remote,
const struct channel_config *our_config,
u32 minimum_depth,
@ -431,7 +432,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
dbid);
} else
channel->log = tal_steal(channel, log);
channel->req_confirmed_ins = req_confirmed_ins_remote;
channel->req_confirmed_ins[LOCAL] = req_confirmed_ins_local;
channel->req_confirmed_ins[REMOTE] = req_confirmed_ins_remote;
channel->channel_flags = channel_flags;
channel->our_config = *our_config;
channel->minimum_depth = minimum_depth;

View file

@ -120,7 +120,7 @@ struct channel {
struct channel_config our_config;
/* Require confirmed inputs for interactive tx */
bool req_confirmed_ins;
bool req_confirmed_ins[NUM_SIDES];
/* Minimum funding depth (specified by us if they fund). */
u32 minimum_depth;
@ -286,6 +286,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
struct log *log STEALS,
const char *transient_billboard TAKES,
u8 channel_flags,
bool req_confirmed_ins_local,
bool req_confirmed_ins_remote,
const struct channel_config *our_config,
u32 minimum_depth,

View file

@ -185,7 +185,7 @@ struct rbf_channel_payload {
struct amount_sat our_last_funding;
u32 funding_feerate_per_kw;
u32 locktime;
bool req_confirmed_ins;
bool req_confirmed_ins_remote;
/* General info */
u32 feerate_our_max;
@ -230,7 +230,7 @@ static void rbf_channel_hook_serialize(struct rbf_channel_payload *payload,
json_add_amount_sat_msat(stream, "requested_lease_msat",
*payload->requested_lease_amt);
json_add_bool(stream, "require_confirmed_inputs",
payload->req_confirmed_ins);
payload->req_confirmed_ins_remote);
json_object_end(stream);
}
@ -273,7 +273,7 @@ struct openchannel2_payload {
struct amount_sat *requested_lease_amt;
u32 lease_blockheight_start;
u32 node_blockheight;
bool req_confirmed_ins;
bool req_confirmed_ins_remote;
struct amount_sat accepter_funding;
struct wally_psbt *psbt;
@ -324,7 +324,7 @@ static void openchannel2_hook_serialize(struct openchannel2_payload *payload,
payload->node_blockheight);
}
json_add_bool(stream, "require_confirmed_inputs",
payload->req_confirmed_ins);
payload->req_confirmed_ins_remote);
json_object_end(stream);
}
@ -346,7 +346,7 @@ openchannel2_changed_hook_serialize(struct openchannel2_psbt_payload *payload,
type_to_string(tmpctx, struct channel_id,
&payload->channel->cid));
json_add_bool(stream, "require_confirmed_inputs",
payload->channel->req_confirmed_ins);
payload->channel->req_confirmed_ins[REMOTE]);
json_object_end(stream);
}
@ -700,7 +700,8 @@ openchannel2_hook_cb(struct openchannel2_payload *payload STEALS)
channel->cid = payload->channel_id;
channel->opener = REMOTE;
channel->open_attempt = new_channel_open_attempt(channel);
channel->req_confirmed_ins = payload->req_confirmed_ins;
channel->req_confirmed_ins[REMOTE] =
payload->req_confirmed_ins_remote;
msg = towire_dualopend_got_offer_reply(NULL,
payload->accepter_funding,
payload->psbt,
@ -1252,6 +1253,8 @@ wallet_commit_channel(struct lightningd *ld,
channel->push = lease_fee_msat;
channel->msat_to_us_min = our_msat;
channel->msat_to_us_max = our_msat;
channel->req_confirmed_ins[LOCAL] =
ld->config.require_confirmed_inputs;
channel->last_tx = tal_steal(channel, remote_commit);
channel->last_sig = *remote_commit_sig;
@ -1888,7 +1891,8 @@ static void rbf_got_offer(struct subd *dualopend, const u8 *msg)
payload->peer_id = channel->peer->id;
payload->feerate_our_max = feerate_max(dualopend->ld, NULL);
payload->feerate_our_min = feerate_min(dualopend->ld, NULL);
payload->req_confirmed_ins = channel->req_confirmed_ins;
payload->req_confirmed_ins_remote =
channel->req_confirmed_ins[REMOTE];
payload->psbt = NULL;
@ -1944,7 +1948,7 @@ static void accepter_got_offer(struct subd *dualopend,
&payload->shutdown_scriptpubkey,
&payload->requested_lease_amt,
&payload->lease_blockheight_start,
&payload->req_confirmed_ins)) {
&payload->req_confirmed_ins_remote)) {
channel_internal_error(channel, "Bad DUALOPEND_GOT_OFFER: %s",
tal_hex(tmpctx, msg));
return;
@ -2726,7 +2730,7 @@ static struct command_result *json_openchannel_update(struct command *cmd,
pv->success = openchannel_update_valid_psbt;
pv->invalid_input = openchannel_invalid_psbt;
if (channel->req_confirmed_ins) {
if (channel->req_confirmed_ins[REMOTE]) {
/* We might fail/terminate in validate's first call,
* which expects us to be at "command still pending" */
ret = command_still_pending(cmd);
@ -3054,7 +3058,7 @@ static void handle_psbt_changed(struct subd *dualopend,
if (!fromwire_dualopend_psbt_changed(tmpctx, msg,
&cid,
&channel->req_confirmed_ins,
&channel->req_confirmed_ins[REMOTE],
&funding_serial,
&psbt)) {
channel_internal_error(channel,
@ -3083,7 +3087,7 @@ static void handle_psbt_changed(struct subd *dualopend,
json_add_bool(response, "commitments_secured", false);
json_add_u64(response, "funding_serial", funding_serial);
json_add_bool(response, "requires_confirmed_inputs",
channel->req_confirmed_ins);
channel->req_confirmed_ins[REMOTE]);
oa->cmd = NULL;
was_pending(command_success(cmd, response));
@ -3746,7 +3750,8 @@ bool peer_restart_dualopend(struct peer *peer,
amount_sat_zero(inflight->lease_amt) ?
NULL : &inflight->lease_amt,
channel->type,
false); /* FIXME: use persisted state? */
channel->req_confirmed_ins[LOCAL],
channel->req_confirmed_ins[REMOTE]);
subd_send_msg(channel->owner, take(msg));
return true;

View file

@ -178,7 +178,7 @@ wallet_commit_channel(struct lightningd *ld,
uc->log,
take(uc->transient_billboard),
channel_flags,
false,
false, false,
&uc->our_config,
uc->minimum_depth,
1, 1, 0,
@ -1398,7 +1398,7 @@ static struct channel *stub_chan(struct command *cmd,
LOCAL,
NULL,
"restored from static channel backup",
0, false,
0, false, false,
our_config,
0,
1, 1, 1,

View file

@ -4289,7 +4289,8 @@ int main(int argc, char *argv[])
&state->tx_state->lease_chan_max_ppt,
&requested_lease,
&state->channel_type,
&state->require_confirmed_inputs[LOCAL])) {
&state->require_confirmed_inputs[LOCAL],
&state->require_confirmed_inputs[REMOTE])) {
bool ok;

View file

@ -73,6 +73,7 @@ msgdata,dualopend_reinit,lease_chan_max_ppt,u16,
msgdata,dualopend_reinit,requested_lease,?amount_sat,
msgdata,dualopend_reinit,channel_type,channel_type,
msgdata,dualopend_reinit,we_require_confirmed_inputs,bool,
msgdata,dualopend_reinit,they_require_confirmed_inputs,bool,
# dualopend->master: they offered channel, should we continue?
msgtype,dualopend_got_offer,7005

Can't render this file because it has a wrong number of fields in line 16.

View file

@ -947,6 +947,7 @@ static struct migration dbmigrations[] = {
/* FIXME: Remove payments local_offer_id column! */
{SQL("ALTER TABLE channel_funding_inflights ADD COLUMN lease_satoshi BIGINT;"), NULL},
{SQL("ALTER TABLE channels ADD require_confirm_inputs_remote INTEGER DEFAULT 0;"), NULL},
{SQL("ALTER TABLE channels ADD require_confirm_inputs_local INTEGER DEFAULT 0;"), NULL},
};
/**

View file

@ -1655,7 +1655,7 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx)
NULL,
DUALOPEND_AWAITING_LOCKIN,
LOCAL, NULL, "billboard",
8, false, &our_config,
8, false, false, &our_config,
101, 1, 1, 1,
&outpoint,
funding_sats, AMOUNT_MSAT(0),

View file

@ -1492,6 +1492,7 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm
NULL, /* Set up fresh log */
"Loaded from database",
db_col_int(stmt, "channel_flags"),
db_col_int(stmt, "require_confirm_inputs_local") != 0,
db_col_int(stmt, "require_confirm_inputs_remote") != 0,
&our_config,
db_col_int(stmt, "minimum_depth"),
@ -1583,7 +1584,8 @@ static bool wallet_channels_load_active(struct wallet *w)
", state"
", funder"
", channel_flags"
", require_confirm_inputs"
", require_confirm_inputs_local"
", require_confirm_inputs_remote"
", minimum_depth"
", next_index_local"
", next_index_remote"
@ -2213,7 +2215,8 @@ void wallet_channel_insert(struct wallet *w, struct channel *chan)
", delayed_payment_basepoint_local"
", funding_pubkey_local"
", require_confirm_inputs_remote"
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"));
", require_confirm_inputs_local"
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
db_bind_u64(stmt, 0, chan->peer->dbid);
db_bind_int(stmt, 1, chan->first_blocknum);
db_bind_int(stmt, 2, chan->dbid);
@ -2223,7 +2226,8 @@ void wallet_channel_insert(struct wallet *w, struct channel *chan)
db_bind_pubkey(stmt, 5, &chan->local_basepoints.htlc);
db_bind_pubkey(stmt, 6, &chan->local_basepoints.delayed_payment);
db_bind_pubkey(stmt, 7, &chan->local_funding_pubkey);
db_bind_int(stmt, 8, chan->req_confirmed_ins);
db_bind_int(stmt, 8, chan->req_confirmed_ins[REMOTE]);
db_bind_int(stmt, 9, chan->req_confirmed_ins[LOCAL]);
db_exec_prepared_v2(take(stmt));