mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-23 15:00:34 +01:00
bkpr: fetch originating account, if exists, and make sure is populated
It's possible we'll get an "external" event for an account/channel and then try to do close checks on it and it'll bomb out because we didn't go look up the originating account to make sure that that had open info Now, we make sure and do that when we hear about an originating account
This commit is contained in:
parent
55e15c5f10
commit
2d22bab879
1 changed files with 22 additions and 7 deletions
|
@ -1159,7 +1159,7 @@ parse_and_log_chain_move(struct command *cmd,
|
||||||
struct sha256 *payment_hash = tal(cmd, struct sha256);
|
struct sha256 *payment_hash = tal(cmd, struct sha256);
|
||||||
struct bitcoin_txid *spending_txid = tal(cmd, struct bitcoin_txid);
|
struct bitcoin_txid *spending_txid = tal(cmd, struct bitcoin_txid);
|
||||||
struct node_id *peer_id;
|
struct node_id *peer_id;
|
||||||
struct account *acct;
|
struct account *acct, *orig_acct;
|
||||||
u32 closed_count;
|
u32 closed_count;
|
||||||
const char *err;
|
const char *err;
|
||||||
|
|
||||||
|
@ -1265,6 +1265,18 @@ parse_and_log_chain_move(struct command *cmd,
|
||||||
account_add(db, acct);
|
account_add(db, acct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e->origin_acct) {
|
||||||
|
orig_acct = find_account(cmd, db, e->origin_acct);
|
||||||
|
/* Go fetch the originating account
|
||||||
|
* (we might not have it) */
|
||||||
|
if (!orig_acct) {
|
||||||
|
orig_acct = new_account(cmd, e->origin_acct, NULL);
|
||||||
|
account_add(db, orig_acct);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
orig_acct = NULL;
|
||||||
|
|
||||||
|
|
||||||
if (!log_chain_event(db, acct, e)) {
|
if (!log_chain_event(db, acct, e)) {
|
||||||
db_commit_transaction(db);
|
db_commit_transaction(db);
|
||||||
/* This is not a new event, do nothing */
|
/* This is not a new event, do nothing */
|
||||||
|
@ -1301,24 +1313,27 @@ parse_and_log_chain_move(struct command *cmd,
|
||||||
db_commit_transaction(db);
|
db_commit_transaction(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If this is an account close event, it's possible
|
/* If this is a channel account event, it's possible
|
||||||
* that we *never* got the open event. (This happens
|
* that we *never* got the open event. (This happens
|
||||||
* if you add the plugin *after* you've closed the channel) */
|
* if you add the plugin *after* you've closed the channel) */
|
||||||
if (!acct->open_event_db_id
|
if ((!acct->open_event_db_id && is_channel_account(acct))
|
||||||
&& acct->closed_event_db_id
|
|| (orig_acct && is_channel_account(orig_acct)
|
||||||
&& *acct->closed_event_db_id == e->db_id) {
|
&& !orig_acct->open_event_db_id)) {
|
||||||
/* Find the channel open info for this peer */
|
/* Find the channel open info for this peer */
|
||||||
struct out_req *req;
|
struct out_req *req;
|
||||||
struct event_info *info;
|
struct event_info *info;
|
||||||
|
|
||||||
plugin_log(cmd->plugin, LOG_DBG,
|
plugin_log(cmd->plugin, LOG_DBG,
|
||||||
"`channel_close` but no open for channel %s."
|
"channel event received but no open for channel %s."
|
||||||
" Calling `listpeers` to fetch missing info",
|
" Calling `listpeers` to fetch missing info",
|
||||||
acct->name);
|
acct->name);
|
||||||
|
|
||||||
info = tal(NULL, struct event_info);
|
info = tal(NULL, struct event_info);
|
||||||
info->ev = tal_steal(info, e);
|
info->ev = tal_steal(info, e);
|
||||||
info->acct = tal_steal(info, acct);
|
info->acct = tal_steal(info,
|
||||||
|
is_channel_account(acct) ?
|
||||||
|
acct : orig_acct);
|
||||||
|
|
||||||
req = jsonrpc_request_start(cmd->plugin, cmd,
|
req = jsonrpc_request_start(cmd->plugin, cmd,
|
||||||
"listpeers",
|
"listpeers",
|
||||||
listpeers_done,
|
listpeers_done,
|
||||||
|
|
Loading…
Add table
Reference in a new issue