Skip to content

Commit

Permalink
wallet: Detect close transactions and track their outputs in DB
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Decker <[email protected]>
  • Loading branch information
cdecker committed Jan 8, 2018
1 parent 2a3c9e9 commit 85eb743
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 16 additions & 1 deletion tests/test_lightningd.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ def test_closing(self):
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

Expand All @@ -771,8 +771,23 @@ def test_closing(self):
# 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()
Expand Down

0 comments on commit 85eb743

Please sign in to comment.