coin_mvt: log channel_open for channels that close before they're locked
We don't push out a coin_move for a channel open until it's locked in, but this causes problems for channels that close before they're locked. So if we go the "close before locked in" route, we push out a channel open event. These will get a blockheight of 0, if we haven't seen the funding transaction in a block yet.
This commit is contained in:
parent
91ebddeb78
commit
d87bdeeace
|
@ -127,16 +127,13 @@ void notify_feerate_change(struct lightningd *ld)
|
|||
* peer. We *could* do so, however. */
|
||||
}
|
||||
|
||||
void channel_record_open(struct channel *channel)
|
||||
void channel_record_open(struct channel *channel, u32 blockheight)
|
||||
{
|
||||
struct chain_coin_mvt *mvt;
|
||||
u32 blockheight;
|
||||
struct amount_msat start_balance;
|
||||
bool is_pushed = !amount_msat_zero(channel->push);
|
||||
bool is_leased = channel->lease_expiry > 0;
|
||||
|
||||
blockheight = short_channel_id_blocknum(channel->scid);
|
||||
|
||||
/* If funds were pushed, add/sub them from the starting balance */
|
||||
if (channel->opener == LOCAL) {
|
||||
if (!amount_msat_add(&start_balance,
|
||||
|
@ -210,7 +207,8 @@ static void lockin_complete(struct channel *channel)
|
|||
|
||||
/* Only record this once we get a real confirmation. */
|
||||
if (channel->scid)
|
||||
channel_record_open(channel);
|
||||
channel_record_open(channel,
|
||||
short_channel_id_blocknum(channel->scid));
|
||||
}
|
||||
|
||||
bool channel_on_funding_locked(struct channel *channel,
|
||||
|
@ -869,7 +867,8 @@ bool channel_tell_depth(struct lightningd *ld,
|
|||
get_block_height(channel->peer->ld->topology));
|
||||
|
||||
/* Only record this once we get a real confirmation. */
|
||||
channel_record_open(channel);
|
||||
channel_record_open(channel,
|
||||
short_channel_id_blocknum(channel->scid));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ bool channel_on_funding_locked(struct channel *channel,
|
|||
struct pubkey *next_per_commitment_point);
|
||||
|
||||
/* Record channel open (coin movement notifications) */
|
||||
void channel_record_open(struct channel *channel);
|
||||
void channel_record_open(struct channel *channel, u32 blockheight);
|
||||
|
||||
/* A channel has unrecoverably fallen behind */
|
||||
void channel_fallen_behind(struct channel *channel, const u8 *msg);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
* saves and funding tx watching for a channel open */
|
||||
|
||||
#include "config.h"
|
||||
#include <bitcoin/short_channel_id.h>
|
||||
#include <ccan/array_size/array_size.h>
|
||||
#include <ccan/cast/cast.h>
|
||||
#include <ccan/mem/mem.h>
|
||||
|
@ -1748,7 +1749,8 @@ static void handle_channel_locked(struct subd *dualopend,
|
|||
CHANNELD_NORMAL,
|
||||
REASON_UNKNOWN,
|
||||
"Lockin complete");
|
||||
channel_record_open(channel);
|
||||
channel_record_open(channel,
|
||||
short_channel_id_blocknum(channel->scid));
|
||||
|
||||
/* Empty out the inflights */
|
||||
wallet_channel_clear_inflights(dualopend->ld->wallet, channel);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <inttypes.h>
|
||||
#include <lightningd/chaintopology.h>
|
||||
#include <lightningd/channel.h>
|
||||
#include <lightningd/channel_control.h>
|
||||
#include <lightningd/coin_mvts.h>
|
||||
#include <lightningd/hsm_control.h>
|
||||
#include <lightningd/onchain_control.h>
|
||||
|
@ -622,6 +623,17 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
|
|||
|
||||
channel_fail_permanent(channel, reason, "Funding transaction spent");
|
||||
|
||||
/* If we haven't posted the open event yet, post an open */
|
||||
if (!channel->scid || !channel->remote_funding_locked) {
|
||||
u32 blkh;
|
||||
/* Note that blockheight will be zero if it's not in chain
|
||||
* yet */
|
||||
blkh = wallet_transaction_height(channel->peer->ld->wallet,
|
||||
&channel->funding.txid);
|
||||
channel_record_open(channel, blkh);
|
||||
}
|
||||
|
||||
|
||||
/* We could come from almost any state. */
|
||||
/* NOTE(mschmoock) above comment is wrong, since we failed above! */
|
||||
channel_set_state(channel,
|
||||
|
|
Loading…
Reference in New Issue