From 784fc27cb9383c19d3e4e5f8ff7e55b5edbc0312 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Fri, 21 Apr 2023 14:05:21 +0000 Subject: [PATCH] libsecp256k1: add runtime support for 0.3.x this replaces https://github.com/spesmilo/electrum/pull/8320 see https://github.com/bitcoin-core/secp256k1/blob/f6bef03c0a2c826227708dbeaecf1dbc702a2567/CHANGELOG.md I am not yet sure how this will look like going forward, but unless there will be lots of libsecp256k1 releases with ~invisible harmless ABI changes, I think conceptually this is the right approach. --- electrum/ecc_fast.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/electrum/ecc_fast.py b/electrum/ecc_fast.py index fcd13c64d..ba75498f2 100644 --- a/electrum/ecc_fast.py +++ b/electrum/ecc_fast.py @@ -37,16 +37,23 @@ class LibModuleMissing(Exception): pass def load_library(): + # note: for a mapping between bitcoin-core/secp256k1 git tags and .so.V libtool version numbers, + # see https://github.com/bitcoin-core/secp256k1/pull/1055#issuecomment-1227505189 + tested_libversions = [2, 1, 0, ] # try latest version first + libnames = [] if sys.platform == 'darwin': - libnames = ['libsecp256k1.1.dylib', 'libsecp256k1.0.dylib', ] + for v in tested_libversions: + libnames.append(f"libsecp256k1.{v}.dylib") elif sys.platform in ('windows', 'win32'): - libnames = ['libsecp256k1-1.dll', 'libsecp256k1-0.dll', ] + for v in tested_libversions: + libnames.append(f"libsecp256k1-{v}.dll") elif 'ANDROID_DATA' in os.environ: - libnames = ['libsecp256k1.so', ] - elif 'freebsd' in sys.platform: - libnames = ['libsecp256k1.so', ] + libnames = ['libsecp256k1.so', ] # don't care about version number. we built w/e is available. else: # desktop Linux and similar - libnames = ['libsecp256k1.so.1', 'libsecp256k1.so.0', ] + for v in tested_libversions: + libnames.append(f"libsecp256k1.so.{v}") + # maybe we could fall back to trying "any" version? maybe guarded with an env var? + #libnames.append(f"libsecp256k1.so") library_paths = [] for libname in libnames: # try local files in repo dir first library_paths.append(os.path.join(os.path.dirname(__file__), libname))