add get_channel_ctx to CLI, for testing breaches
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user