commit e7218d798dd1c8556401b1f20d86f9e5474056b6
parent a6983441365d0150eb364d8d289e30ee5ebe6434
Author: ThomasV <thomasv@electrum.org>
Date: Thu, 14 Mar 2019 18:31:41 +0100
add get_channel_ctx to CLI, for testing breaches
Diffstat:
3 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/electrum/commands.py b/electrum/commands.py
@@ -841,6 +841,15 @@ class Commands:
coro = self.lnworker.force_close_channel(chan_id) if force else self.lnworker.close_channel(chan_id)
return self.network.run_from_another_thread(coro)
+ @command('wn')
+ def get_channel_ctx(self, channel_point):
+ """ return the current commitment transaction of a channel """
+ txid, index = channel_point.split(':')
+ chan_id, _ = channel_id_from_funding_tx(txid, int(index))
+ chan = self.lnworker.channels[chan_id]
+ tx = chan.force_close_tx()
+ return tx.as_dict()
+
def eval_bool(x: str) -> bool:
if x == 'false': return False
if x == 'true': return True
diff --git a/electrum/lnchannel.py b/electrum/lnchannel.py
@@ -187,11 +187,6 @@ class Channel(PrintError):
self.local_commitment = ctx
if self.sweep_address is not None:
self.local_sweeptxs = create_sweeptxs_for_our_latest_ctx(self, self.local_commitment, self.sweep_address)
- initial = os.path.join(get_config().electrum_path(), 'initial_commitment_tx')
- tx = self.force_close_tx().serialize_to_network()
- if not os.path.exists(initial):
- with open(initial, 'w') as f:
- f.write(tx)
def set_remote_commitment(self):
self.remote_commitment = self.current_commitment(REMOTE)
diff --git a/electrum/tests/regtest/regtest.sh b/electrum/tests/regtest/regtest.sh
@@ -71,13 +71,14 @@ fi
if [[ $1 == "breach" ]]; then
bob_node=$($bob nodeid)
- $alice open_channel $bob_node 0.15
+ channel=$($alice open_channel $bob_node 0.15)
sleep 3
+ ctx=$($alice get_channel_ctx $channel | jq '.hex' | tr -d '"')
bitcoin-cli generate 6 > /dev/null
sleep 10
request=$($bob addinvoice 0.01 "blah")
$alice lnpay $request
- bitcoin-cli sendrawtransaction $(cat /tmp/alice/regtest/initial_commitment_tx)
+ bitcoin-cli sendrawtransaction $ctx
sleep 12
bitcoin-cli generate 2 > /dev/null
sleep 12