dual-open-rbf: remember the requested lease amount btw restarts
Don't forget the requested lease across restarts.
This commit is contained in:
parent
314c021e2c
commit
4c46750001
|
@ -135,7 +135,8 @@ new_inflight(struct channel *channel,
|
|||
const secp256k1_ecdsa_signature *lease_commit_sig,
|
||||
const u32 lease_chan_max_msat, const u16 lease_chan_max_ppt,
|
||||
const u32 lease_blockheight_start,
|
||||
const struct amount_msat lease_fee)
|
||||
const struct amount_msat lease_fee,
|
||||
const struct amount_sat lease_amt)
|
||||
{
|
||||
struct wally_psbt *last_tx_psbt_clone;
|
||||
struct channel_inflight *inflight
|
||||
|
@ -169,6 +170,7 @@ new_inflight(struct channel *channel,
|
|||
inflight->lease_chan_max_msat = lease_chan_max_msat;
|
||||
inflight->lease_chan_max_ppt = lease_chan_max_ppt;
|
||||
inflight->lease_fee = lease_fee;
|
||||
inflight->lease_amt = lease_amt;
|
||||
|
||||
list_add_tail(&channel->inflights, &inflight->list);
|
||||
tal_add_destructor(inflight, destroy_inflight);
|
||||
|
|
|
@ -54,6 +54,9 @@ struct channel_inflight {
|
|||
/* We save this data so we can do nice accounting;
|
||||
* on the channel we slot it into the 'push' field */
|
||||
struct amount_msat lease_fee;
|
||||
|
||||
/* Amount requested to lease for this open */
|
||||
struct amount_sat lease_amt;
|
||||
};
|
||||
|
||||
struct open_attempt {
|
||||
|
@ -351,7 +354,8 @@ new_inflight(struct channel *channel,
|
|||
const u32 lease_chan_max_msat,
|
||||
const u16 lease_chan_max_ppt,
|
||||
const u32 lease_blockheight_start,
|
||||
const struct amount_msat lease_fee);
|
||||
const struct amount_msat lease_fee,
|
||||
const struct amount_sat lease_amt);
|
||||
|
||||
/* Given a txid, find an inflight channel stub. Returns NULL if none found */
|
||||
struct channel_inflight *channel_inflight_find(struct channel *channel,
|
||||
|
|
|
@ -1113,7 +1113,8 @@ wallet_update_channel(struct lightningd *ld,
|
|||
secp256k1_ecdsa_signature *lease_commit_sig STEALS,
|
||||
const u32 lease_chan_max_msat,
|
||||
const u16 lease_chan_max_ppt,
|
||||
const u32 lease_blockheight_start)
|
||||
const u32 lease_blockheight_start,
|
||||
struct amount_sat lease_amt)
|
||||
{
|
||||
struct amount_msat our_msat, lease_fee_msat;
|
||||
struct channel_inflight *inflight;
|
||||
|
@ -1173,7 +1174,8 @@ wallet_update_channel(struct lightningd *ld,
|
|||
channel->lease_chan_max_msat,
|
||||
channel->lease_chan_max_ppt,
|
||||
lease_blockheight_start,
|
||||
channel->push);
|
||||
channel->push,
|
||||
lease_amt);
|
||||
wallet_inflight_add(ld->wallet, inflight);
|
||||
|
||||
return inflight;
|
||||
|
@ -1194,6 +1196,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 struct amount_sat lease_amt,
|
||||
const u32 lease_blockheight_start,
|
||||
const u32 lease_expiry,
|
||||
const struct amount_sat lease_fee,
|
||||
|
@ -1316,7 +1319,8 @@ wallet_commit_channel(struct lightningd *ld,
|
|||
channel->lease_chan_max_msat,
|
||||
channel->lease_chan_max_ppt,
|
||||
lease_blockheight_start,
|
||||
channel->push);
|
||||
channel->push,
|
||||
lease_amt);
|
||||
wallet_inflight_add(ld->wallet, inflight);
|
||||
|
||||
/* We might have disconnected and decided we didn't need to
|
||||
|
@ -2909,7 +2913,7 @@ static void handle_commit_received(struct subd *dualopend,
|
|||
u16 lease_chan_max_ppt;
|
||||
u32 feerate_funding, feerate_commitment, lease_expiry,
|
||||
lease_chan_max_msat, lease_blockheight_start;
|
||||
struct amount_sat total_funding, funding_ours, lease_fee;
|
||||
struct amount_sat total_funding, funding_ours, lease_fee, lease_amt;
|
||||
u8 *remote_upfront_shutdown_script,
|
||||
*local_upfront_shutdown_script;
|
||||
struct penalty_base *pbase;
|
||||
|
@ -2941,6 +2945,7 @@ static void handle_commit_received(struct subd *dualopend,
|
|||
&feerate_commitment,
|
||||
&local_upfront_shutdown_script,
|
||||
&remote_upfront_shutdown_script,
|
||||
&lease_amt,
|
||||
&lease_blockheight_start,
|
||||
&lease_expiry,
|
||||
&lease_fee,
|
||||
|
@ -2976,6 +2981,7 @@ static void handle_commit_received(struct subd *dualopend,
|
|||
local_upfront_shutdown_script,
|
||||
remote_upfront_shutdown_script,
|
||||
psbt,
|
||||
lease_amt,
|
||||
lease_blockheight_start,
|
||||
lease_expiry,
|
||||
lease_fee,
|
||||
|
@ -3016,7 +3022,8 @@ static void handle_commit_received(struct subd *dualopend,
|
|||
lease_commit_sig,
|
||||
lease_chan_max_msat,
|
||||
lease_chan_max_ppt,
|
||||
lease_blockheight_start))) {
|
||||
lease_blockheight_start,
|
||||
lease_amt))) {
|
||||
channel_internal_error(channel,
|
||||
"wallet_update_channel failed"
|
||||
" (chan %s)",
|
||||
|
@ -3529,8 +3536,8 @@ bool peer_restart_dualopend(struct peer *peer,
|
|||
inflight->lease_commit_sig,
|
||||
inflight->lease_chan_max_msat,
|
||||
inflight->lease_chan_max_ppt,
|
||||
/* FIXME: requested lease? */
|
||||
NULL,
|
||||
amount_sat_zero(inflight->lease_amt) ?
|
||||
NULL : &inflight->lease_amt,
|
||||
channel->type);
|
||||
|
||||
subd_send_msg(channel->owner, take(msg));
|
||||
|
|
|
@ -1950,6 +1950,9 @@ static u8 *accepter_commits(struct state *state,
|
|||
state->feerate_per_kw_commitment,
|
||||
state->upfront_shutdown_script[LOCAL],
|
||||
state->upfront_shutdown_script[REMOTE],
|
||||
state->requested_lease ?
|
||||
*state->requested_lease :
|
||||
AMOUNT_SAT(0),
|
||||
tx_state->blockheight,
|
||||
tx_state->lease_expiry,
|
||||
tx_state->lease_fee,
|
||||
|
@ -2681,6 +2684,9 @@ static u8 *opener_commits(struct state *state,
|
|||
state->feerate_per_kw_commitment,
|
||||
state->upfront_shutdown_script[LOCAL],
|
||||
state->upfront_shutdown_script[REMOTE],
|
||||
state->requested_lease ?
|
||||
*state->requested_lease :
|
||||
AMOUNT_SAT(0),
|
||||
tx_state->blockheight,
|
||||
tx_state->lease_expiry,
|
||||
tx_state->lease_fee,
|
||||
|
|
|
@ -151,6 +151,7 @@ msgdata,dualopend_commit_rcvd,local_shutdown_len,u16,
|
|||
msgdata,dualopend_commit_rcvd,local_shutdown_scriptpubkey,u8,local_shutdown_len
|
||||
msgdata,dualopend_commit_rcvd,remote_shutdown_len,u16,
|
||||
msgdata,dualopend_commit_rcvd,remote_shutdown_scriptpubkey,u8,remote_shutdown_len
|
||||
msgdata,dualopend_commit_rcvd,lease_amt,amount_sat,
|
||||
msgdata,dualopend_commit_rcvd,lease_start_blockheight,u32,
|
||||
msgdata,dualopend_commit_rcvd,lease_expiry,u32,
|
||||
msgdata,dualopend_commit_rcvd,lease_fee,amount_sat,
|
||||
|
|
Can't render this file because it has a wrong number of fields in line 15.
|
|
@ -347,7 +347,6 @@ def test_v2_rbf_single(node_factory, bitcoind, chainparams):
|
|||
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
|
||||
@pytest.mark.openchannel('v2')
|
||||
@pytest.mark.developer("requres 'dev-force-features'")
|
||||
@pytest.mark.xfail
|
||||
def test_v2_rbf_liquidity_ad(node_factory, bitcoind, chainparams):
|
||||
|
||||
opts = {'funder-policy': 'match', 'funder-policy-mod': 100,
|
||||
|
|
|
@ -945,6 +945,7 @@ static struct migration dbmigrations[] = {
|
|||
/* A reference into our own invoicerequests table, if it was made from one */
|
||||
{SQL("ALTER TABLE payments ADD COLUMN local_invreq_id BLOB DEFAULT NULL REFERENCES invoicerequests(invreq_id);"), NULL},
|
||||
/* FIXME: Remove payments local_offer_id column! */
|
||||
{SQL("ALTER TABLE channel_funding_inflights ADD COLUMN lease_satoshi BIGINT;"), NULL},
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -1252,6 +1252,7 @@ static bool channel_inflightseq(struct channel_inflight *i1,
|
|||
&i2->last_sig, sizeof(i2->last_sig)));
|
||||
CHECK(bitcoin_tx_eq(i1->last_tx, i2->last_tx));
|
||||
|
||||
CHECK(amount_sat_eq(i1->lease_amt, i2->lease_amt));
|
||||
CHECK(!i1->lease_commit_sig == !i2->lease_commit_sig);
|
||||
if (i1->lease_commit_sig)
|
||||
CHECK(memeq(i1->lease_commit_sig, sizeof(*i1->lease_commit_sig),
|
||||
|
@ -1674,7 +1675,8 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx)
|
|||
last_tx,
|
||||
sig,
|
||||
1, lease_commit_sig, 2, 4, 22,
|
||||
AMOUNT_MSAT(10));
|
||||
AMOUNT_MSAT(10),
|
||||
AMOUNT_SAT(1111));
|
||||
|
||||
/* do inflights get correctly added to the channel? */
|
||||
wallet_inflight_add(w, inflight);
|
||||
|
@ -1697,7 +1699,8 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx)
|
|||
last_tx,
|
||||
sig,
|
||||
0, NULL, 0, 0, 0,
|
||||
AMOUNT_MSAT(0));
|
||||
AMOUNT_MSAT(0),
|
||||
AMOUNT_SAT(0));
|
||||
wallet_inflight_add(w, inflight);
|
||||
CHECK_MSG(c2 = wallet_channel_load(w, chan->dbid),
|
||||
tal_fmt(w, "Load from DB"));
|
||||
|
|
|
@ -1041,8 +1041,9 @@ void wallet_inflight_add(struct wallet *w, struct channel_inflight *inflight)
|
|||
", lease_expiry"
|
||||
", lease_blockheight_start"
|
||||
", lease_fee"
|
||||
", lease_satoshi"
|
||||
") VALUES ("
|
||||
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
|
||||
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
|
||||
|
||||
db_bind_u64(stmt, 0, inflight->channel->dbid);
|
||||
db_bind_txid(stmt, 1, &inflight->funding->outpoint.txid);
|
||||
|
@ -1062,6 +1063,7 @@ void wallet_inflight_add(struct wallet *w, struct channel_inflight *inflight)
|
|||
db_bind_int(stmt, 13, inflight->lease_expiry);
|
||||
db_bind_int(stmt, 14, inflight->lease_blockheight_start);
|
||||
db_bind_amount_msat(stmt, 15, &inflight->lease_fee);
|
||||
db_bind_amount_sat(stmt, 16, &inflight->lease_amt);
|
||||
} else {
|
||||
db_bind_null(stmt, 10);
|
||||
db_bind_null(stmt, 11);
|
||||
|
@ -1069,6 +1071,7 @@ void wallet_inflight_add(struct wallet *w, struct channel_inflight *inflight)
|
|||
db_bind_int(stmt, 13, 0);
|
||||
db_bind_null(stmt, 14);
|
||||
db_bind_null(stmt, 15);
|
||||
db_bind_int(stmt, 16, 0);
|
||||
}
|
||||
|
||||
db_exec_prepared_v2(stmt);
|
||||
|
@ -1134,6 +1137,7 @@ wallet_stmt2inflight(struct wallet *w, struct db_stmt *stmt,
|
|||
u32 lease_blockheight_start;
|
||||
u64 lease_chan_max_msat;
|
||||
u16 lease_chan_max_ppt;
|
||||
struct amount_sat lease_amt;
|
||||
|
||||
db_col_txid(stmt, "funding_tx_id", &funding.txid);
|
||||
funding.n = db_col_int(stmt, "funding_tx_outnum"),
|
||||
|
@ -1151,17 +1155,20 @@ wallet_stmt2inflight(struct wallet *w, struct db_stmt *stmt,
|
|||
lease_chan_max_ppt = db_col_int(stmt, "lease_chan_max_ppt");
|
||||
lease_blockheight_start = db_col_int(stmt, "lease_blockheight_start");
|
||||
db_col_amount_msat(stmt, "lease_fee", &lease_fee);
|
||||
db_col_amount_sat(stmt, "lease_satoshi", &lease_amt);
|
||||
} else {
|
||||
lease_commit_sig = NULL;
|
||||
lease_chan_max_msat = 0;
|
||||
lease_chan_max_ppt = 0;
|
||||
lease_blockheight_start = 0;
|
||||
lease_fee = AMOUNT_MSAT(0);
|
||||
lease_amt = AMOUNT_SAT(0);
|
||||
|
||||
db_col_ignore(stmt, "lease_chan_max_msat");
|
||||
db_col_ignore(stmt, "lease_chan_max_ppt");
|
||||
db_col_ignore(stmt, "lease_blockheight_start");
|
||||
db_col_ignore(stmt, "lease_fee");
|
||||
db_col_ignore(stmt, "lease_satoshi");
|
||||
}
|
||||
|
||||
/* last_tx is null for stub channels used for recovering funds through
|
||||
|
@ -1183,7 +1190,8 @@ wallet_stmt2inflight(struct wallet *w, struct db_stmt *stmt,
|
|||
lease_chan_max_msat,
|
||||
lease_chan_max_ppt,
|
||||
lease_blockheight_start,
|
||||
lease_fee);
|
||||
lease_fee,
|
||||
lease_amt);
|
||||
|
||||
/* Pull out the serialized tx-sigs-received-ness */
|
||||
inflight->remote_tx_sigs = db_col_int(stmt, "funding_tx_remote_sigs_received");
|
||||
|
@ -1212,6 +1220,7 @@ static bool wallet_channel_load_inflights(struct wallet *w,
|
|||
", lease_chan_max_ppt"
|
||||
", lease_blockheight_start"
|
||||
", lease_fee"
|
||||
", lease_satoshi"
|
||||
" FROM channel_funding_inflights"
|
||||
" WHERE channel_id = ?"
|
||||
" ORDER BY funding_feerate"));
|
||||
|
|
Loading…
Reference in New Issue