Skip to content

Commit e7218d7

Browse files
committed
add get_channel_ctx to CLI, for testing breaches
1 parent a698344 commit e7218d7

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

electrum/commands.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,15 @@ def close_channel(self, channel_point, force=False):
841841
coro = self.lnworker.force_close_channel(chan_id) if force else self.lnworker.close_channel(chan_id)
842842
return self.network.run_from_another_thread(coro)
843843

844+
@command('wn')
845+
def get_channel_ctx(self, channel_point):
846+
""" return the current commitment transaction of a channel """
847+
txid, index = channel_point.split(':')
848+
chan_id, _ = channel_id_from_funding_tx(txid, int(index))
849+
chan = self.lnworker.channels[chan_id]
850+
tx = chan.force_close_tx()
851+
return tx.as_dict()
852+
844853
def eval_bool(x: str) -> bool:
845854
if x == 'false': return False
846855
if x == 'true': return True

electrum/lnchannel.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,6 @@ def set_local_commitment(self, ctx):
187187
self.local_commitment = ctx
188188
if self.sweep_address is not None:
189189
self.local_sweeptxs = create_sweeptxs_for_our_latest_ctx(self, self.local_commitment, self.sweep_address)
190-
initial = os.path.join(get_config().electrum_path(), 'initial_commitment_tx')
191-
tx = self.force_close_tx().serialize_to_network()
192-
if not os.path.exists(initial):
193-
with open(initial, 'w') as f:
194-
f.write(tx)
195190

196191
def set_remote_commitment(self):
197192
self.remote_commitment = self.current_commitment(REMOTE)

electrum/tests/regtest/regtest.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,14 @@ fi
7171

7272
if [[ $1 == "breach" ]]; then
7373
bob_node=$($bob nodeid)
74-
$alice open_channel $bob_node 0.15
74+
channel=$($alice open_channel $bob_node 0.15)
7575
sleep 3
76+
ctx=$($alice get_channel_ctx $channel | jq '.hex' | tr -d '"')
7677
bitcoin-cli generate 6 > /dev/null
7778
sleep 10
7879
request=$($bob addinvoice 0.01 "blah")
7980
$alice lnpay $request
80-
bitcoin-cli sendrawtransaction $(cat /tmp/alice/regtest/initial_commitment_tx)
81+
bitcoin-cli sendrawtransaction $ctx
8182
sleep 12
8283
bitcoin-cli generate 2 > /dev/null
8384
sleep 12

0 commit comments

Comments
 (0)