From a8cc933351c238e2d261d8741eb79b1e8ae45270 Mon Sep 17 00:00:00 2001 From: lisa neigut Date: Wed, 10 Apr 2019 14:58:01 -0700 Subject: [PATCH] closing: add message to billboard when closing txn is broadcast make it a bit easier to track mutual channel closures by adding broadcast txid to the listpeers billboard. since lightningd manages the 'identity' of the closing tx we need to send it back to closingd so it can update the billboard appropriately. --- closingd/closing_wire.csv | 1 + closingd/closingd.c | 23 ++++++++++++++--------- lightningd/closing_control.c | 6 +++++- tests/test_closing.py | 8 +++++--- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/closingd/closing_wire.csv b/closingd/closing_wire.csv index 6ffcc5d90..c92cb8b45 100644 --- a/closingd/closing_wire.csv +++ b/closingd/closing_wire.csv @@ -35,6 +35,7 @@ closing_received_signature,,signature,struct bitcoin_signature closing_received_signature,,tx,struct bitcoin_tx closing_received_signature_reply,2102 +closing_received_signature_reply,,closing_txid,struct bitcoin_txid # Negotiations complete, we're exiting. closing_complete,2004 diff --git a/closingd/closingd.c b/closingd/closingd.c index 25bdb3691..8f1b13d3a 100644 --- a/closingd/closingd.c +++ b/closingd/closingd.c @@ -268,7 +268,8 @@ static void send_offer(struct crypto_state *cs, } static void tell_master_their_offer(const struct bitcoin_signature *their_sig, - const struct bitcoin_tx *tx) + const struct bitcoin_tx *tx, + struct bitcoin_txid *tx_id) { u8 *msg = towire_closing_received_signature(NULL, their_sig, tx); if (!wire_sync_write(REQ_FD, take(msg))) @@ -278,7 +279,7 @@ static void tell_master_their_offer(const struct bitcoin_signature *their_sig, /* Wait for master to ack, to make sure it's in db. */ msg = wire_sync_read(NULL, REQ_FD); - if (!fromwire_closing_received_signature_reply(msg)) + if (!fromwire_closing_received_signature_reply(msg, tx_id)) master_badmsg(WIRE_CLOSING_RECEIVED_SIGNATURE_REPLY, msg); tal_free(msg); } @@ -296,7 +297,8 @@ receive_offer(struct crypto_state *cs, const struct amount_sat out[NUM_SIDES], enum side funder, struct amount_sat our_dust_limit, - struct amount_sat min_fee_to_accept) + struct amount_sat min_fee_to_accept, + struct bitcoin_txid *closing_txid) { u8 *msg; struct channel_id their_channel_id; @@ -399,7 +401,7 @@ receive_offer(struct crypto_state *cs, /* Master sorts out what is best offer, we just tell it any above min */ if (amount_sat_greater_eq(received_fee, min_fee_to_accept)) { status_trace("...offer is reasonable"); - tell_master_their_offer(&their_sig, tx); + tell_master_their_offer(&their_sig, tx, closing_txid); } return received_fee; @@ -535,7 +537,7 @@ int main(int argc, char *argv[]) const tal_t *ctx = tal(NULL, char); u8 *msg; struct pubkey funding_pubkey[NUM_SIDES]; - struct bitcoin_txid funding_txid; + struct bitcoin_txid funding_txid, closing_txid; u16 funding_txout; struct amount_sat funding, out[NUM_SIDES]; struct amount_sat our_dust_limit; @@ -643,7 +645,8 @@ int main(int argc, char *argv[]) funding_txout, funding, out, funder, our_dust_limit, - min_fee_to_accept); + min_fee_to_accept, + &closing_txid); } } @@ -684,14 +687,16 @@ int main(int argc, char *argv[]) funding_txout, funding, out, funder, our_dust_limit, - min_fee_to_accept); + min_fee_to_accept, + &closing_txid); } whose_turn = !whose_turn; } - peer_billboard(true, "We agreed on a closing fee of %"PRIu64" satoshi", - offer[LOCAL]); + peer_billboard(true, "We agreed on a closing fee of %"PRIu64" satoshi for tx:%s", + offer[LOCAL], + type_to_string(tmpctx, struct bitcoin_txid, &closing_txid)); #if DEVELOPER /* We don't listen for master commands, so always check memleak here */ diff --git a/lightningd/closing_control.c b/lightningd/closing_control.c index f3365dd64..a3efe0cd7 100644 --- a/lightningd/closing_control.c +++ b/lightningd/closing_control.c @@ -83,6 +83,7 @@ static void peer_received_closing_signature(struct channel *channel, { struct bitcoin_signature sig; struct bitcoin_tx *tx; + struct bitcoin_txid tx_id; struct lightningd *ld = channel->peer->ld; if (!fromwire_closing_received_signature(msg, msg, &sig, &tx)) { @@ -98,9 +99,12 @@ static void peer_received_closing_signature(struct channel *channel, wallet_channel_save(ld->wallet, channel); } + + // Send back the txid so we can update the billboard on selection. + bitcoin_txid(channel->last_tx, &tx_id); /* OK, you can continue now. */ subd_send_msg(channel->owner, - take(towire_closing_received_signature_reply(channel))); + take(towire_closing_received_signature_reply(channel, &tx_id))); } static void peer_closing_complete(struct channel *channel, const u8 *msg) diff --git a/tests/test_closing.py b/tests/test_closing.py index fd76bd42d..f00e66c80 100644 --- a/tests/test_closing.py +++ b/tests/test_closing.py @@ -61,7 +61,9 @@ def test_closing(node_factory, bitcoind): closetxid = only_one(bitcoind.rpc.getrawmempool(False)) billboard = only_one(l1.rpc.listpeers(l2.info['id'])['peers'][0]['channels'])['status'] - assert billboard == ['CLOSINGD_SIGEXCHANGE:We agreed on a closing fee of 5430 satoshi'] + assert billboard == [ + 'CLOSINGD_SIGEXCHANGE:We agreed on a closing fee of 5430 satoshi for tx:{}'.format(closetxid), + ] bitcoind.generate_block(1) l1.daemon.wait_for_log(r'Owning output .* txid %s' % closetxid) @@ -72,14 +74,14 @@ def test_closing(node_factory, bitcoind): assert closetxid in set([o['txid'] for o in l2.rpc.listfunds()['outputs']]) wait_for(lambda: only_one(l1.rpc.listpeers(l2.info['id'])['peers'][0]['channels'])['status'] == [ - 'CLOSINGD_SIGEXCHANGE:We agreed on a closing fee of 5430 satoshi', + 'CLOSINGD_SIGEXCHANGE:We agreed on a closing fee of 5430 satoshi for tx:{}'.format(closetxid), 'ONCHAIN:Tracking mutual close transaction', 'ONCHAIN:All outputs resolved: waiting 99 more blocks before forgetting channel' ]) bitcoind.generate_block(9) wait_for(lambda: only_one(l1.rpc.listpeers(l2.info['id'])['peers'][0]['channels'])['status'] == [ - 'CLOSINGD_SIGEXCHANGE:We agreed on a closing fee of 5430 satoshi', + 'CLOSINGD_SIGEXCHANGE:We agreed on a closing fee of 5430 satoshi for tx:{}'.format(closetxid), 'ONCHAIN:Tracking mutual close transaction', 'ONCHAIN:All outputs resolved: waiting 90 more blocks before forgetting channel' ])