Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update emergency.recover after every 'commitment_revocation' so that user can sweep funds by penalty transaction. #7772

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
54 changes: 45 additions & 9 deletions lightningd/opening_control.c
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for commit 53b16a0, it looks like a keyword got omitted from the commit message

Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,11 @@ static struct channel *stub_chan(struct command *cmd,
struct bitcoin_outpoint funding,
struct wireaddr addr,
struct amount_sat funding_sats,
struct channel_type *type)
struct channel_type *type,
struct shachain shachain,
struct basepoints their_basepoint,
enum side opener,
u16 remote_to_self_delay)
{
struct basepoints basepoints;
struct bitcoin_signature *sig;
Expand All @@ -1465,9 +1469,13 @@ static struct channel *stub_chan(struct command *cmd,
struct pubkey localFundingPubkey;
struct pubkey pk;
struct short_channel_id *scid;
u32 blockht;
u32 blockht = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why set this here? it doesn't look like it got used again in this commit

u32 feerate;
struct channel_stats zero_channel_stats;
struct wallet_shachain *their_shachain = tal(cmd, struct wallet_shachain);
their_shachain->chain = shachain;
their_shachain->id = 0;

u8 *dummy_sig = tal_hexdata(cmd,
"30450221009b2e0eef267b94c3899fb0dc73750"
"12e2cee4c10348a068fe78d1b82b4b1403602207"
Expand Down Expand Up @@ -1528,8 +1536,11 @@ static struct channel *stub_chan(struct command *cmd,
/* FIXME: Makeake these a pointer, so they could be NULL */
memset(our_config, 0, sizeof(struct channel_config));
memset(their_config, 0, sizeof(struct channel_config));
memset(channel_info, 0, sizeof(struct channel_info));

our_config->to_self_delay = remote_to_self_delay;
channel_info->their_config = *their_config;
channel_info->theirbase = basepoints;
channel_info->theirbase = their_basepoint;
channel_info->remote_fundingkey = pk;
channel_info->remote_per_commit = pk;
channel_info->old_remote_per_commit = pk;
Expand All @@ -1545,9 +1556,9 @@ static struct channel *stub_chan(struct command *cmd,

/* Channel Shell with Dummy data(mostly) */
channel = new_channel(peer, id,
NULL, /* No shachain yet */
their_shachain,
CHANNELD_NORMAL,
LOCAL,
opener,
NULL,
"restored from static channel backup",
0, false, false,
Expand All @@ -1574,15 +1585,15 @@ static struct channel *stub_chan(struct command *cmd,
sig,
NULL, /* No HTLC sigs */
channel_info,
new_fee_states(cmd, LOCAL, &feerate),
new_fee_states(cmd, opener, &feerate),
NULL, /* No shutdown_scriptpubkey[REMOTE] */
NULL,
1, false,
NULL, /* No commit sent */
/* If we're fundee, could be a little before this
* in theory, but it's only used for timing out. */
get_network_blockheight(ld->topology),
FEERATE_FLOOR,
feerate,
funding_sats.satoshis / MINIMUM_TX_WEIGHT * 1000 /* Raw: convert to feerate */,
&basepoints,
&localFundingPubkey,
Expand All @@ -1596,7 +1607,7 @@ static struct channel *stub_chan(struct command *cmd,
0, /* no close_attempt_height */
REASON_REMOTE,
NULL,
take(new_height_states(ld->wallet, LOCAL,
take(new_height_states(ld->wallet, opener,
&blockht)),
0, NULL, 0, 0, /* No leases on v1s */
ld->config.htlc_minimum_msat,
Expand Down Expand Up @@ -1636,6 +1647,8 @@ static struct command_result *json_recoverchannel(struct command *cmd,
char *token = json_strdup(tmpctx, buffer, t);
const u8 *scb_arr = tal_hexdata(cmd, token, strlen(token));
size_t scblen = tal_count(scb_arr);
struct shachain chain;
struct basepoints basepoints;

scb_chan = fromwire_scb_chan(cmd ,&scb_arr, &scblen);

Expand All @@ -1644,6 +1657,25 @@ static struct command_result *json_recoverchannel(struct command *cmd,
continue;
}

if (scb_chan->tlvs->shachain == NULL) {
shachain_init(&chain);
} else {
log_debug(cmd->ld->log, "shachain is not null yayyy");
chain = *scb_chan->tlvs->shachain;
}

if (scb_chan->tlvs->basepoints == NULL) {
struct pubkey _localfundingpubkey;
get_channel_basepoints(cmd->ld,
&scb_chan->node_id,
scb_chan->id,
&basepoints,
&_localfundingpubkey);
} else {
log_debug(cmd->ld->log, "basepoints is not null yayyy");
basepoints = *scb_chan->tlvs->basepoints;
}

struct lightningd *ld = cmd->ld;
struct channel *channel= stub_chan(cmd,
scb_chan->id,
Expand All @@ -1652,7 +1684,11 @@ static struct command_result *json_recoverchannel(struct command *cmd,
scb_chan->funding,
scb_chan->addr,
scb_chan->funding_sats,
scb_chan->type);
scb_chan->type,
chain,
basepoints,
scb_chan->tlvs->opener == NULL ? LOCAL : *scb_chan->tlvs->opener,
scb_chan->tlvs->remote_to_self_delay == NULL ? 0 : *scb_chan->tlvs->remote_to_self_delay);

/* Returns NULL only when channel already exists, so we skip over it. */
if (channel == NULL)
Expand Down