diff --git a/electrum/gui/qt/channels_list.py b/electrum/gui/qt/channels_list.py index d243bad64..59763c319 100644 --- a/electrum/gui/qt/channels_list.py +++ b/electrum/gui/qt/channels_list.py @@ -5,7 +5,7 @@ from PyQt5.QtWidgets import * from electrum.util import inv_dict, bh2u, bfh from electrum.i18n import _ -from electrum.lnhtlc import HTLCStateMachine +from electrum.lnchan import Channel from electrum.lnutil import LOCAL, REMOTE, ConnStringFormatError from .util import MyTreeWidget, SortableTreeWidgetItem, WindowModalDialog, Buttons, OkButton, CancelButton @@ -13,7 +13,7 @@ from .amountedit import BTCAmountEdit class ChannelsList(MyTreeWidget): update_rows = QtCore.pyqtSignal() - update_single_row = QtCore.pyqtSignal(HTLCStateMachine) + update_single_row = QtCore.pyqtSignal(Channel) def __init__(self, parent): MyTreeWidget.__init__(self, parent, self.create_menu, [_('Node ID'), _('Balance'), _('Remote'), _('Status')], 0) @@ -43,7 +43,7 @@ class ChannelsList(MyTreeWidget): menu.addAction(_("Force-close channel"), close) menu.exec_(self.viewport().mapToGlobal(position)) - @QtCore.pyqtSlot(HTLCStateMachine) + @QtCore.pyqtSlot(Channel) def do_update_single_row(self, chan): for i in range(self.topLevelItemCount()): item = self.topLevelItem(i) diff --git a/electrum/lnbase.py b/electrum/lnbase.py index 6f0f586ee..b1e7fffaf 100644 --- a/electrum/lnbase.py +++ b/electrum/lnbase.py @@ -27,7 +27,7 @@ from .util import PrintError, bh2u, print_error, bfh, log_exceptions from .transaction import Transaction, TxOutput from .lnonion import new_onion_packet, OnionHopsDataSingle, OnionPerHop, decode_onion_error, OnionFailureCode from .lnaddr import lndecode -from .lnhtlc import HTLCStateMachine, RevokeAndAck, htlcsum +from .lnchan import Channel, RevokeAndAck, htlcsum from .lnutil import (Outpoint, LocalConfig, ChannelConfig, RemoteConfig, OnlyPubkeyKeypair, ChannelConstraints, RevocationStore, funding_output_script, get_ecdh, get_per_commitment_secret_from_seed, @@ -641,7 +641,7 @@ class Peer(PrintError): "constraints": ChannelConstraints(capacity=funding_sat, is_initiator=True, funding_txn_minimum_depth=funding_txn_minimum_depth, feerate=feerate), "remote_commitment_to_be_revoked": None, } - m = HTLCStateMachine(chan) + m = Channel(chan) m.lnwatcher = self.lnwatcher m.sweep_address = self.lnworker.sweep_address sig_64, _ = m.sign_next_commitment() @@ -737,7 +737,7 @@ class Peer(PrintError): "constraints": ChannelConstraints(capacity=funding_sat, is_initiator=False, funding_txn_minimum_depth=min_depth, feerate=feerate), "remote_commitment_to_be_revoked": None, } - m = HTLCStateMachine(chan) + m = Channel(chan) m.lnwatcher = self.lnwatcher m.sweep_address = self.lnworker.sweep_address remote_sig = funding_created['signature'] diff --git a/electrum/lnhtlc.py b/electrum/lnchan.py similarity index 99% rename from electrum/lnhtlc.py rename to electrum/lnchan.py index a726e8291..d453e70d6 100644 --- a/electrum/lnhtlc.py +++ b/electrum/lnchan.py @@ -83,7 +83,7 @@ def decodeAll(d, local): def htlcsum(htlcs): return sum([x.amount_msat for x in htlcs]) -class HTLCStateMachine(PrintError): +class Channel(PrintError): def diagnostic_name(self): return str(self.name) @@ -589,7 +589,7 @@ class HTLCStateMachine(PrintError): return super(MyJsonEncoder, self) dumped = MyJsonEncoder().encode(serialized_channel) roundtripped = json.loads(dumped) - reconstructed = HTLCStateMachine(roundtripped) + reconstructed = Channel(roundtripped) if reconstructed.to_save() != self.to_save(): from pprint import pformat try: diff --git a/electrum/lnworker.py b/electrum/lnworker.py index 454231f39..7597339b1 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -19,7 +19,7 @@ from .util import bh2u, bfh, PrintError, InvoiceError, resolve_dns_srv, is_ip_ad from .lnbase import Peer, aiosafe from .lnaddr import lnencode, LnAddr, lndecode from .ecc import der_sig_from_sig_string -from .lnhtlc import HTLCStateMachine +from .lnchan import Channel from .lnutil import (Outpoint, calc_short_channel_id, LNPeerAddr, get_compressed_pubkey_from_bech32, extract_nodeid, PaymentFailure, split_host_port, ConnStringFormatError, @@ -50,7 +50,7 @@ class LNWorker(PrintError): self.node_keypair = generate_keypair(self.ln_keystore, LnKeyFamily.NODE_KEY, 0) self.config = network.config self.peers = {} # type: Dict[bytes, Peer] # pubkey -> Peer - self.channels = {x.channel_id: x for x in map(HTLCStateMachine, wallet.storage.get("channels", []))} # type: Dict[bytes, HTLCStateMachine] + self.channels = {x.channel_id: x for x in map(Channel, wallet.storage.get("channels", []))} # type: Dict[bytes, HTLCStateMachine] for c in self.channels.values(): c.lnwatcher = network.lnwatcher c.sweep_address = self.sweep_address @@ -115,7 +115,7 @@ class LNWorker(PrintError): return peer def save_channel(self, openchannel): - assert type(openchannel) is HTLCStateMachine + assert type(openchannel) is Channel if openchannel.config[REMOTE].next_per_commitment_point == openchannel.config[REMOTE].current_per_commitment_point: raise Exception("Tried to save channel with next_point == current_point, this should not happen") with self.lock: diff --git a/electrum/tests/test_lnhtlc.py b/electrum/tests/test_lnchan.py similarity index 98% rename from electrum/tests/test_lnhtlc.py rename to electrum/tests/test_lnchan.py index e2ed183d3..c8c478eea 100644 --- a/electrum/tests/test_lnhtlc.py +++ b/electrum/tests/test_lnchan.py @@ -3,7 +3,7 @@ import unittest import electrum.bitcoin as bitcoin import electrum.lnbase as lnbase -import electrum.lnhtlc as lnhtlc +import electrum.lnchan as lnchan import electrum.lnutil as lnutil import electrum.util as util import os @@ -102,9 +102,9 @@ def create_test_channels(feerate=6000, local=None, remote=None): bob_next = lnutil.secret_to_pubkey(int.from_bytes(lnutil.get_per_commitment_secret_from_seed(bob_seed, lnutil.RevocationStore.START_INDEX - 1), "big")) return \ - lnhtlc.HTLCStateMachine( + lnchan.Channel( create_channel_state(funding_txid, funding_index, funding_sat, feerate, True, local_amount, remote_amount, alice_privkeys, bob_pubkeys, alice_seed, bob_cur, bob_next, b"\x02"*33, l_dust=200, r_dust=1300, l_csv=5, r_csv=4), "alice"), \ - lnhtlc.HTLCStateMachine( + lnchan.Channel( create_channel_state(funding_txid, funding_index, funding_sat, feerate, False, remote_amount, local_amount, bob_privkeys, alice_pubkeys, bob_seed, alice_cur, alice_next, b"\x01"*33, l_dust=1300, r_dust=200, l_csv=4, r_csv=5), "bob") one_bitcoin_in_msat = bitcoin.COIN * 1000 @@ -118,7 +118,7 @@ class TestFee(unittest.TestCase): alice_channel, bob_channel = create_test_channels(253, 10000000000, 5000000000) self.assertIn(9999817, [x[2] for x in alice_channel.local_commitment.outputs()]) -class TestLNBaseHTLCStateMachine(unittest.TestCase): +class TestChannel(unittest.TestCase): def assertOutputExistsByValue(self, tx, amt_sat): for typ, scr, val in tx.outputs(): if val == amt_sat: @@ -320,8 +320,8 @@ class TestLNBaseHTLCStateMachine(unittest.TestCase): -class TestLNHTLCDust(unittest.TestCase): - def test_HTLCDustLimit(self): +class TestDust(unittest.TestCase): + def test_DustLimit(self): alice_channel, bob_channel = create_test_channels() paymentPreimage = b"\x01" * 32 diff --git a/electrum/tests/test_lnutil.py b/electrum/tests/test_lnutil.py index 86745a52b..8ce21d7f1 100644 --- a/electrum/tests/test_lnutil.py +++ b/electrum/tests/test_lnutil.py @@ -7,7 +7,7 @@ from electrum.lnutil import (RevocationStore, get_per_commitment_secret_from_see derive_pubkey, make_htlc_tx, extract_ctn_from_tx, UnableToDeriveSecret, get_compressed_pubkey_from_bech32, split_host_port, ConnStringFormatError, ScriptHtlc, extract_nodeid) -from electrum import lnhtlc +from electrum import lnchan from electrum.util import bh2u, bfh from electrum.transaction import Transaction @@ -496,7 +496,7 @@ class TestLNUtil(unittest.TestCase): (1, 2000 * 1000), (3, 3000 * 1000), (4, 4000 * 1000)]: - htlc_obj[num] = lnhtlc.UpdateAddHtlc(amount_msat=msat, payment_hash=bitcoin.sha256(htlc_payment_preimage[num]), cltv_expiry=None, htlc_id=None) + htlc_obj[num] = lnchan.UpdateAddHtlc(amount_msat=msat, payment_hash=bitcoin.sha256(htlc_payment_preimage[num]), cltv_expiry=None, htlc_id=None) htlcs = [ScriptHtlc(htlc[x], htlc_obj[x]) for x in range(5)] our_commit_tx = make_commitment(