mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 22:31:48 +01:00
coin_mvt: report mutual close outputs also
It's better to report every single utxo on close so we know when to mark a channel account as definitively closed.
This commit is contained in:
parent
d246e9c1a2
commit
ecb19ba6f2
2 changed files with 31 additions and 4 deletions
|
@ -247,6 +247,31 @@ static void record_external_deposit(const struct tracked_output *out,
|
|||
record_external_output(&out->outpoint, out->sat, blockheight, tag);
|
||||
}
|
||||
|
||||
static void record_mutual_close(const struct tx_parts *tx,
|
||||
const u8 *remote_scriptpubkey,
|
||||
u32 blockheight)
|
||||
{
|
||||
/* FIXME: if we ever change how closes happen, this will
|
||||
* need to be updated as there's no longer 1 output
|
||||
* per peer */
|
||||
for (size_t i = 0; i < tal_count(tx->outputs); i++) {
|
||||
struct bitcoin_outpoint out;
|
||||
|
||||
if (!wally_tx_output_scripteq(tx->outputs[i],
|
||||
remote_scriptpubkey))
|
||||
continue;
|
||||
|
||||
out.n = i;
|
||||
out.txid = tx->txid;
|
||||
record_external_output(&out,
|
||||
amount_sat(tx->outputs[i]->satoshi),
|
||||
blockheight,
|
||||
TO_THEM);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void record_channel_deposit(struct tracked_output *out,
|
||||
u32 blockheight, enum mvt_tag tag)
|
||||
{
|
||||
|
@ -3882,9 +3907,11 @@ int main(int argc, char *argv[])
|
|||
* without any pending payments) and publish it on the blockchain (see
|
||||
* [BOLT #2: Channel Close](02-peer-protocol.md#channel-close)).
|
||||
*/
|
||||
if (is_mutual_close(tx, scriptpubkey[LOCAL], scriptpubkey[REMOTE]))
|
||||
if (is_mutual_close(tx, scriptpubkey[LOCAL], scriptpubkey[REMOTE])) {
|
||||
record_mutual_close(tx, scriptpubkey[REMOTE],
|
||||
tx_blockheight);
|
||||
handle_mutual_close(outs, tx);
|
||||
else {
|
||||
} else {
|
||||
/* BOLT #5:
|
||||
*
|
||||
* 2. The bad way (*unilateral close*): something goes wrong,
|
||||
|
|
|
@ -108,12 +108,12 @@ def test_closing_simple(node_factory, bitcoind, chainparams):
|
|||
expected_1 = {
|
||||
'0': [('wallet', ['deposit'], ['withdrawal'], 'A')],
|
||||
'A': [('wallet', ['deposit'], None, None), ('cid1', ['channel_open', 'opener'], ['channel_close'], 'B')],
|
||||
'B': [('wallet', ['deposit'], None, None)],
|
||||
'B': [('wallet', ['deposit'], None, None), ('external', ['to_them'], None, None)],
|
||||
}
|
||||
|
||||
expected_2 = {
|
||||
'A': [('cid1', ['channel_open'], ['channel_close'], 'B')],
|
||||
'B': [('wallet', ['deposit'], None, None)],
|
||||
'B': [('wallet', ['deposit'], None, None), ('external', ['to_them'], None, None)],
|
||||
}
|
||||
tags = check_utxos_channel(l1, [channel_id], expected_1)
|
||||
check_utxos_channel(l2, [channel_id], expected_2, tags)
|
||||
|
|
Loading…
Add table
Reference in a new issue