Browse Source

add get_channel_ctx to CLI, for testing breaches

regtest_lnd
ThomasV 6 years ago
committed by SomberNight
parent
commit
bff1724e67
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 9
      electrum/commands.py
  2. 5
      electrum/lnchannel.py
  3. 5
      electrum/tests/regtest/regtest.sh

9
electrum/commands.py

@ -845,6 +845,15 @@ class Commands:
coro = self.lnworker.force_close_channel(chan_id) if force else self.lnworker.close_channel(chan_id) 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) 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: def eval_bool(x: str) -> bool:
if x == 'false': return False if x == 'false': return False
if x == 'true': return True if x == 'true': return True

5
electrum/lnchannel.py

@ -187,11 +187,6 @@ class Channel(PrintError):
self.local_commitment = ctx self.local_commitment = ctx
if self.sweep_address is not None: if self.sweep_address is not None:
self.local_sweeptxs = create_sweeptxs_for_our_latest_ctx(self, self.local_commitment, self.sweep_address) 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): def set_remote_commitment(self):
self.remote_commitment = self.current_commitment(REMOTE) self.remote_commitment = self.current_commitment(REMOTE)

5
electrum/tests/regtest/regtest.sh

@ -71,13 +71,14 @@ fi
if [[ $1 == "breach" ]]; then if [[ $1 == "breach" ]]; then
bob_node=$($bob nodeid) bob_node=$($bob nodeid)
$alice open_channel $bob_node 0.15 channel=$($alice open_channel $bob_node 0.15)
sleep 3 sleep 3
ctx=$($alice get_channel_ctx $channel | jq '.hex' | tr -d '"')
bitcoin-cli generate 6 > /dev/null bitcoin-cli generate 6 > /dev/null
sleep 10 sleep 10
request=$($bob addinvoice 0.01 "blah") request=$($bob addinvoice 0.01 "blah")
$alice lnpay $request $alice lnpay $request
bitcoin-cli sendrawtransaction $(cat /tmp/alice/regtest/initial_commitment_tx) bitcoin-cli sendrawtransaction $ctx
sleep 12 sleep 12
bitcoin-cli generate 2 > /dev/null bitcoin-cli generate 2 > /dev/null
sleep 12 sleep 12

Loading…
Cancel
Save