Browse Source

Rename lnchan, lnchannel_verifier, lnbase

Auto-completions are a pain if files share a long prefix
dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
ThomasV 6 years ago
parent
commit
3dce65dc73
  1. 2
      electrum/commands.py
  2. 2
      electrum/gui/qt/channel_details.py
  3. 2
      electrum/gui/qt/channels_list.py
  4. 2
      electrum/lnchannel.py
  5. 2
      electrum/lnpeer.py
  6. 4
      electrum/lnrouter.py
  7. 4
      electrum/lnsweep.py
  8. 4
      electrum/lnutil.py
  9. 1
      electrum/lnverifier.py
  10. 4
      electrum/lnworker.py
  11. 24
      electrum/tests/test_lnchannel.py
  12. 6
      electrum/tests/test_lnpeer.py

2
electrum/commands.py

@ -49,7 +49,7 @@ from .address_synchronizer import TX_HEIGHT_LOCAL
from .import lightning from .import lightning
from .mnemonic import Mnemonic from .mnemonic import Mnemonic
from .lnutil import SENT, RECEIVED from .lnutil import SENT, RECEIVED
from .lnbase import channel_id_from_funding_tx from .lnpeer import channel_id_from_funding_tx
if TYPE_CHECKING: if TYPE_CHECKING:
from .network import Network from .network import Network

2
electrum/gui/qt/channel_details.py

@ -7,7 +7,7 @@ import PyQt5.QtCore as QtCore
from electrum.i18n import _ from electrum.i18n import _
from electrum.util import bh2u, format_time from electrum.util import bh2u, format_time
from electrum.lnutil import format_short_channel_id, LOCAL, REMOTE, UpdateAddHtlc, Direction from electrum.lnutil import format_short_channel_id, LOCAL, REMOTE, UpdateAddHtlc, Direction
from electrum.lnchan import htlcsum from electrum.lnchannel import htlcsum
from electrum.lnaddr import LnAddr, lndecode from electrum.lnaddr import LnAddr, lndecode
from electrum.bitcoin import COIN from electrum.bitcoin import COIN

2
electrum/gui/qt/channels_list.py

@ -6,7 +6,7 @@ from PyQt5.QtWidgets import *
from electrum.util import inv_dict, bh2u, bfh from electrum.util import inv_dict, bh2u, bfh
from electrum.i18n import _ from electrum.i18n import _
from electrum.lnchan import Channel from electrum.lnchannel import Channel
from electrum.lnutil import LOCAL, REMOTE, ConnStringFormatError from electrum.lnutil import LOCAL, REMOTE, ConnStringFormatError
from .util import MyTreeView, WindowModalDialog, Buttons, OkButton, CancelButton, EnterButton, WWLabel from .util import MyTreeView, WindowModalDialog, Buttons, OkButton, CancelButton, EnterButton, WWLabel

2
electrum/lnchan.py → electrum/lnchannel.py

@ -115,7 +115,7 @@ class Channel(PrintError):
if self.name: if self.name:
return str(self.name) return str(self.name)
try: try:
return f"lnchan_{bh2u(self.channel_id[-4:])}" return f"lnchannel_{bh2u(self.channel_id[-4:])}"
except: except:
return super().diagnostic_name() return super().diagnostic_name()

2
electrum/lnbase.py → electrum/lnpeer.py

@ -26,7 +26,7 @@ from .util import PrintError, bh2u, print_error, bfh, log_exceptions, list_enabl
from .transaction import Transaction, TxOutput from .transaction import Transaction, TxOutput
from .lnonion import (new_onion_packet, decode_onion_error, OnionFailureCode, calc_hops_data_for_payment, from .lnonion import (new_onion_packet, decode_onion_error, OnionFailureCode, calc_hops_data_for_payment,
process_onion_packet, OnionPacket, construct_onion_error, OnionRoutingFailureMessage) process_onion_packet, OnionPacket, construct_onion_error, OnionRoutingFailureMessage)
from .lnchan import Channel, RevokeAndAck, htlcsum from .lnchannel import Channel, RevokeAndAck, htlcsum
from .lnutil import (Outpoint, LocalConfig, RECEIVED, UpdateAddHtlc, from .lnutil import (Outpoint, LocalConfig, RECEIVED, UpdateAddHtlc,
RemoteConfig, OnlyPubkeyKeypair, ChannelConstraints, RevocationStore, RemoteConfig, OnlyPubkeyKeypair, ChannelConstraints, RevocationStore,
funding_output_script, get_per_commitment_secret_from_seed, funding_output_script, get_per_commitment_secret_from_seed,

4
electrum/lnrouter.py

@ -36,14 +36,14 @@ import asyncio
from . import constants from . import constants
from .util import PrintError, bh2u, profiler, get_headers_dir, bfh, is_ip_address, list_enabled_bits from .util import PrintError, bh2u, profiler, get_headers_dir, bfh, is_ip_address, list_enabled_bits
from .storage import JsonDB from .storage import JsonDB
from .lnchannelverifier import LNChannelVerifier, verify_sig_for_channel_update from .lnverifier import LNChannelVerifier, verify_sig_for_channel_update
from .crypto import sha256d from .crypto import sha256d
from . import ecc from . import ecc
from .lnutil import (LN_GLOBAL_FEATURES_KNOWN_SET, LNPeerAddr, NUM_MAX_EDGES_IN_PAYMENT_PATH, from .lnutil import (LN_GLOBAL_FEATURES_KNOWN_SET, LNPeerAddr, NUM_MAX_EDGES_IN_PAYMENT_PATH,
NotFoundChanAnnouncementForUpdate) NotFoundChanAnnouncementForUpdate)
if TYPE_CHECKING: if TYPE_CHECKING:
from .lnchan import Channel from .lnchannel import Channel
from .network import Network from .network import Network

4
electrum/lnsweep.py

@ -17,7 +17,7 @@ from .transaction import Transaction, TxOutput, construct_witness
from .simple_config import SimpleConfig, FEERATE_FALLBACK_STATIC_FEE from .simple_config import SimpleConfig, FEERATE_FALLBACK_STATIC_FEE
if TYPE_CHECKING: if TYPE_CHECKING:
from .lnchan import Channel from .lnchannel import Channel
def maybe_create_sweeptx_for_their_ctx_to_remote(ctx: Transaction, sweep_address: str, def maybe_create_sweeptx_for_their_ctx_to_remote(ctx: Transaction, sweep_address: str,
@ -203,7 +203,7 @@ def create_sweeptxs_for_their_latest_ctx(chan: 'Channel', ctx: Transaction,
Regardless of it is a breach or not, construct sweep tx for 'to_remote'. Regardless of it is a breach or not, construct sweep tx for 'to_remote'.
If it is a breach, also construct sweep tx for 'to_local'. If it is a breach, also construct sweep tx for 'to_local'.
Sweep txns for HTLCs are only constructed if it is NOT a breach, as Sweep txns for HTLCs are only constructed if it is NOT a breach, as
lnchan does not store old HTLCs. lnchannel does not store old HTLCs.
""" """
this_conf, other_conf = get_ordered_channel_configs(chan=chan, for_us=False) this_conf, other_conf = get_ordered_channel_configs(chan=chan, for_us=False)
ctn = extract_ctn_from_tx_and_chan(ctx, chan) ctn = extract_ctn_from_tx_and_chan(ctx, chan)

4
electrum/lnutil.py

@ -21,7 +21,7 @@ from .lnaddr import lndecode
from .keystore import BIP32_KeyStore from .keystore import BIP32_KeyStore
if TYPE_CHECKING: if TYPE_CHECKING:
from .lnchan import Channel from .lnchannel import Channel
HTLC_TIMEOUT_WEIGHT = 663 HTLC_TIMEOUT_WEIGHT = 663
@ -114,7 +114,7 @@ MAXIMUM_HTLC_MINIMUM_MSAT_ACCEPTED = 1000
MAXIMUM_REMOTE_TO_SELF_DELAY_ACCEPTED = 2016 MAXIMUM_REMOTE_TO_SELF_DELAY_ACCEPTED = 2016
class RevocationStore: class RevocationStore:
""" Taken from LND, see license in lnchan.py. """ """ Taken from LND, see license in lnchannel.py. """
START_INDEX = 2 ** 48 - 1 START_INDEX = 2 ** 48 - 1

1
electrum/lnchannelverifier.py → electrum/lnverifier.py

@ -29,7 +29,6 @@ from typing import TYPE_CHECKING
import aiorpcx import aiorpcx
from . import lnbase
from . import bitcoin from . import bitcoin
from . import ecc from . import ecc
from . import constants from . import constants

4
electrum/lnworker.py

@ -28,10 +28,10 @@ from .bip32 import bip32_root
from .util import bh2u, bfh, PrintError, InvoiceError, resolve_dns_srv, is_ip_address, log_exceptions from .util import bh2u, bfh, PrintError, InvoiceError, resolve_dns_srv, is_ip_address, log_exceptions
from .util import timestamp_to_datetime from .util import timestamp_to_datetime
from .lntransport import LNTransport, LNResponderTransport from .lntransport import LNTransport, LNResponderTransport
from .lnbase import Peer from .lnpeer import Peer
from .lnaddr import lnencode, LnAddr, lndecode from .lnaddr import lnencode, LnAddr, lndecode
from .ecc import der_sig_from_sig_string from .ecc import der_sig_from_sig_string
from .lnchan import Channel, ChannelJsonEncoder from .lnchannel import Channel, ChannelJsonEncoder
from .lnutil import (Outpoint, calc_short_channel_id, LNPeerAddr, from .lnutil import (Outpoint, calc_short_channel_id, LNPeerAddr,
get_compressed_pubkey_from_bech32, extract_nodeid, get_compressed_pubkey_from_bech32, extract_nodeid,
PaymentFailure, split_host_port, ConnStringFormatError, PaymentFailure, split_host_port, ConnStringFormatError,

24
electrum/tests/test_lnchan.py → electrum/tests/test_lnchannel.py

@ -25,8 +25,8 @@ import binascii
from pprint import pformat from pprint import pformat
from electrum import bitcoin from electrum import bitcoin
from electrum import lnbase from electrum import lnpeer
from electrum import lnchan from electrum import lnchannel
from electrum import lnutil from electrum import lnutil
from electrum import bip32 as bip32_utils from electrum import bip32 as bip32_utils
from electrum.lnutil import SENT, LOCAL, REMOTE, RECEIVED from electrum.lnutil import SENT, LOCAL, REMOTE, RECEIVED
@ -38,14 +38,14 @@ one_bitcoin_in_msat = bitcoin.COIN * 1000
def create_channel_state(funding_txid, funding_index, funding_sat, local_feerate, is_initiator, local_amount, remote_amount, privkeys, other_pubkeys, seed, cur, nex, other_node_id, l_dust, r_dust, l_csv, r_csv): def create_channel_state(funding_txid, funding_index, funding_sat, local_feerate, is_initiator, local_amount, remote_amount, privkeys, other_pubkeys, seed, cur, nex, other_node_id, l_dust, r_dust, l_csv, r_csv):
assert local_amount > 0 assert local_amount > 0
assert remote_amount > 0 assert remote_amount > 0
channel_id, _ = lnbase.channel_id_from_funding_tx(funding_txid, funding_index) channel_id, _ = lnpeer.channel_id_from_funding_tx(funding_txid, funding_index)
their_revocation_store = lnbase.RevocationStore() their_revocation_store = lnpeer.RevocationStore()
return { return {
"channel_id":channel_id, "channel_id":channel_id,
"short_channel_id":channel_id[:8], "short_channel_id":channel_id[:8],
"funding_outpoint":lnbase.Outpoint(funding_txid, funding_index), "funding_outpoint":lnpeer.Outpoint(funding_txid, funding_index),
"remote_config":lnbase.RemoteConfig( "remote_config":lnpeer.RemoteConfig(
payment_basepoint=other_pubkeys[0], payment_basepoint=other_pubkeys[0],
multisig_key=other_pubkeys[1], multisig_key=other_pubkeys[1],
htlc_basepoint=other_pubkeys[2], htlc_basepoint=other_pubkeys[2],
@ -65,7 +65,7 @@ def create_channel_state(funding_txid, funding_index, funding_sat, local_feerate
current_per_commitment_point=cur, current_per_commitment_point=cur,
revocation_store=their_revocation_store, revocation_store=their_revocation_store,
), ),
"local_config":lnbase.LocalConfig( "local_config":lnpeer.LocalConfig(
payment_basepoint=privkeys[0], payment_basepoint=privkeys[0],
multisig_key=privkeys[1], multisig_key=privkeys[1],
htlc_basepoint=privkeys[2], htlc_basepoint=privkeys[2],
@ -87,7 +87,7 @@ def create_channel_state(funding_txid, funding_index, funding_sat, local_feerate
current_htlc_signatures=None, current_htlc_signatures=None,
got_sig_for_next=False, got_sig_for_next=False,
), ),
"constraints":lnbase.ChannelConstraints( "constraints":lnpeer.ChannelConstraints(
capacity=funding_sat, capacity=funding_sat,
is_initiator=is_initiator, is_initiator=is_initiator,
funding_txn_minimum_depth=3, funding_txn_minimum_depth=3,
@ -126,9 +126,9 @@ def create_test_channels(feerate=6000, local=None, remote=None):
bob_first = lnutil.secret_to_pubkey(int.from_bytes(lnutil.get_per_commitment_secret_from_seed(bob_seed, lnutil.RevocationStore.START_INDEX), "big")) bob_first = lnutil.secret_to_pubkey(int.from_bytes(lnutil.get_per_commitment_secret_from_seed(bob_seed, lnutil.RevocationStore.START_INDEX), "big"))
alice, bob = \ alice, bob = \
lnchan.Channel( lnchannel.Channel(
create_channel_state(funding_txid, funding_index, funding_sat, feerate, True, local_amount, remote_amount, alice_privkeys, bob_pubkeys, alice_seed, None, bob_first, b"\x02"*33, l_dust=200, r_dust=1300, l_csv=5, r_csv=4), name="alice"), \ create_channel_state(funding_txid, funding_index, funding_sat, feerate, True, local_amount, remote_amount, alice_privkeys, bob_pubkeys, alice_seed, None, bob_first, b"\x02"*33, l_dust=200, r_dust=1300, l_csv=5, r_csv=4), name="alice"), \
lnchan.Channel( lnchannel.Channel(
create_channel_state(funding_txid, funding_index, funding_sat, feerate, False, remote_amount, local_amount, bob_privkeys, alice_pubkeys, bob_seed, None, alice_first, b"\x01"*33, l_dust=1300, r_dust=200, l_csv=4, r_csv=5), name="bob") create_channel_state(funding_txid, funding_index, funding_sat, feerate, False, remote_amount, local_amount, bob_privkeys, alice_pubkeys, bob_seed, None, alice_first, b"\x01"*33, l_dust=1300, r_dust=200, l_csv=4, r_csv=5), name="bob")
alice.set_state('OPEN') alice.set_state('OPEN')
@ -692,9 +692,9 @@ class TestChanReserve(unittest.TestCase):
force_state_transition(self.alice_channel, self.bob_channel) force_state_transition(self.alice_channel, self.bob_channel)
aliceSelfBalance = self.alice_channel.balance(LOCAL)\ aliceSelfBalance = self.alice_channel.balance(LOCAL)\
- lnchan.htlcsum(self.alice_channel.hm.htlcs_by_direction(LOCAL, SENT)) - lnchannel.htlcsum(self.alice_channel.hm.htlcs_by_direction(LOCAL, SENT))
bobBalance = self.bob_channel.balance(REMOTE)\ bobBalance = self.bob_channel.balance(REMOTE)\
- lnchan.htlcsum(self.alice_channel.hm.htlcs_by_direction(REMOTE, SENT)) - lnchannel.htlcsum(self.alice_channel.hm.htlcs_by_direction(REMOTE, SENT))
self.assertEqual(aliceSelfBalance, one_bitcoin_in_msat*4.5) self.assertEqual(aliceSelfBalance, one_bitcoin_in_msat*4.5)
self.assertEqual(bobBalance, one_bitcoin_in_msat*5) self.assertEqual(bobBalance, one_bitcoin_in_msat*5)
# Now let Bob try to add an HTLC. This should fail, since it will # Now let Bob try to add an HTLC. This should fail, since it will

6
electrum/tests/test_lnbase.py → electrum/tests/test_lnpeer.py

@ -13,7 +13,7 @@ from electrum.lnaddr import lnencode, LnAddr, lndecode
from electrum.bitcoin import COIN, sha256 from electrum.bitcoin import COIN, sha256
from electrum.util import bh2u from electrum.util import bh2u
from electrum.lnbase import Peer from electrum.lnpeer import Peer
from electrum.lnutil import LNPeerAddr, Keypair, privkey_to_pubkey from electrum.lnutil import LNPeerAddr, Keypair, privkey_to_pubkey
from electrum.lnutil import LightningPeerConnectionClosed, RemoteMisbehaving from electrum.lnutil import LightningPeerConnectionClosed, RemoteMisbehaving
from electrum.lnutil import PaymentFailure from electrum.lnutil import PaymentFailure
@ -21,7 +21,7 @@ from electrum.lnrouter import ChannelDB, LNPathFinder
from electrum.lnworker import LNWorker from electrum.lnworker import LNWorker
from electrum.lnmsg import encode_msg, decode_msg from electrum.lnmsg import encode_msg, decode_msg
from .test_lnchan import create_test_channels from .test_lnchannel import create_test_channels
def keypair(): def keypair():
priv = ECPrivkey.generate_random_key().get_secret_bytes() priv = ECPrivkey.generate_random_key().get_secret_bytes()
@ -39,7 +39,7 @@ class MockNetwork:
self.callbacks = defaultdict(list) self.callbacks = defaultdict(list)
self.lnwatcher = None self.lnwatcher = None
user_config = {} user_config = {}
user_dir = tempfile.mkdtemp(prefix="electrum-lnbase-test-") user_dir = tempfile.mkdtemp(prefix="electrum-lnpeer-test-")
self.config = simple_config.SimpleConfig(user_config, read_user_dir_function=lambda: user_dir) self.config = simple_config.SimpleConfig(user_config, read_user_dir_function=lambda: user_dir)
self.asyncio_loop = asyncio.get_event_loop() self.asyncio_loop = asyncio.get_event_loop()
self.channel_db = ChannelDB(self) self.channel_db = ChannelDB(self)
Loading…
Cancel
Save