wallet: Detect close transactions and track their outputs in DB

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2017-12-16 21:04:16 +01:00
parent 2a3c9e96f0
commit 85eb743e02
2 changed files with 20 additions and 1 deletions

View File

@ -1699,6 +1699,8 @@ static void peer_got_shutdown(struct peer *peer, const u8 *msg)
return;
}
txfilter_add_scriptpubkey(peer->ld->owned_txfilter, scriptpubkey);
/* BOLT #2:
*
* A receiving node MUST reply to a `shutdown` message with a
@ -2688,6 +2690,8 @@ static void json_close(struct command *cmd,
peer_set_condition(peer, CHANNELD_NORMAL, CHANNELD_SHUTTING_DOWN);
txfilter_add_scriptpubkey(peer->ld->owned_txfilter, shutdown_scriptpubkey);
if (peer->owner)
subd_send_msg(peer->owner,
take(towire_channel_send_shutdown(peer,

View File

@ -756,7 +756,7 @@ class LightningDTests(BaseLightningDTests):
l1,l2 = self.connect()
self.fund_channel(l1, l2, 10**6)
self.pay(l1,l2,200000000)
self.pay(l1, l2, 200000000)
assert l1.bitcoin.rpc.getmempoolinfo()['size'] == 0
@ -771,8 +771,23 @@ class LightningDTests(BaseLightningDTests):
# And should put closing into mempool.
l1.daemon.wait_for_log('sendrawtx exit 0')
l2.daemon.wait_for_log('sendrawtx exit 0')
assert l1.bitcoin.rpc.getmempoolinfo()['size'] == 1
# Now grab the close transaction
closetxid = l1.bitcoin.rpc.getrawmempool(False)[0]
l1.bitcoin.rpc.generate(10)
l1.daemon.wait_for_log(r'Owning output .* txid %s' % closetxid)
l2.daemon.wait_for_log(r'Owning output .* txid %s' % closetxid)
print(l1.rpc.listfunds())
# Make sure both nodes have grabbed their close tx funds
assert closetxid in set([o['txid'] for o in l1.rpc.listfunds()['outputs']])
assert closetxid in set([o['txid'] for o in l2.rpc.listfunds()['outputs']])
@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")
def test_permfail(self):
l1,l2 = self.connect()