Skip to content

Commit

Permalink
only require libsecp256k1 if lightning is enabled
Browse files Browse the repository at this point in the history
related: #5606
  • Loading branch information
SomberNight committed Sep 6, 2019
1 parent e5ff4fc commit 251db63
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 4 additions & 2 deletions electrum/ecc_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@ def verify(self: ecdsa.ecdsa.Public_key, hash: int, signature: ecdsa.ecdsa.Signa

def do_monkey_patching_of_python_ecdsa_internals_with_libsecp256k1():
if not _libsecp256k1:
raise Exception('libsecp256k1 library not available. '
'Verifying Lightning channels is too computationally expensive without libsecp256k1, aborting.')
# FIXME logging 'verbosity' is not yet initialised
_logger.info('libsecp256k1 library not available, falling back to python-ecdsa. '
'This means signing operations will be slower.')
return
if not _patched_functions.prepared_to_patch:
raise Exception("can't patch python-ecdsa without preparations")
ecdsa.ecdsa.Private_key.sign = _patched_functions.fast_sign
Expand Down
2 changes: 2 additions & 0 deletions electrum/lnworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from .lnpeer import Peer, LN_P2P_NETWORK_TIMEOUT
from .lnaddr import lnencode, LnAddr, lndecode
from .ecc import der_sig_from_sig_string
from .ecc_fast import is_using_fast_ecc
from .lnchannel import Channel, ChannelJsonEncoder
from . import lnutil
from .lnutil import (Outpoint, calc_short_channel_id, LNPeerAddr,
Expand Down Expand Up @@ -251,6 +252,7 @@ def __init__(self, network):
self.localfeatures |= LnLocalFeatures.GOSSIP_QUERIES_OPT
self.localfeatures |= LnLocalFeatures.GOSSIP_QUERIES_REQ
self.unknown_ids = set()
assert is_using_fast_ecc(), "verifying LN gossip msgs without libsecp256k1 is hopeless"

def start_network(self, network: 'Network'):
super().start_network(network)
Expand Down
12 changes: 9 additions & 3 deletions run_electrum
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,22 @@ if __name__ == '__main__':
# todo: defer this to gui
config = SimpleConfig(config_options)

cmdname = config.get('cmd')

if config.get('testnet'):
constants.set_testnet()
elif config.get('regtest'):
constants.set_regtest()
elif config.get('simnet'):
constants.set_simnet()
elif config.get('lightning') and not config.get('reckless'):
raise Exception('lightning branch not available on mainnet')
raise Exception('lightning option not available on mainnet')

if config.get('lightning'):
from electrum.ecc_fast import is_using_fast_ecc
if not is_using_fast_ecc():
raise Exception('libsecp256k1 library not available. '
'Verifying Lightning channels is too computationally expensive without libsecp256k1, aborting.')

cmdname = config.get('cmd')

if cmdname == 'daemon' and config.get("detach"):
# fork before creating the asyncio event loop
Expand Down

1 comment on commit 251db63

@Tectract
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lightning should be disabled by default, imho. Bitcoin should not include counterparty trust.

Please sign in to comment.