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.
This commit is contained in:
lisa neigut 2019-04-10 14:58:01 -07:00 committed by Rusty Russell
parent 9c373fecb6
commit a8cc933351
4 changed files with 25 additions and 13 deletions

View File

@ -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

1 #include <common/cryptomsg.h>
35 closing_received_signature_reply,2102
36 # Negotiations complete, we're exiting. closing_received_signature_reply,,closing_txid,struct bitcoin_txid
37 closing_complete,2004 # Negotiations complete, we're exiting.
38 closing_complete,2004
39
40
41

View File

@ -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 */

View File

@ -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)

View File

@ -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'
])