From 81982c729f4bb8f702b6c73f4685463c97cb6e4a Mon Sep 17 00:00:00 2001 From: Kristaps Kaupe Date: Fri, 11 Dec 2020 07:24:20 +0200 Subject: [PATCH] Drop support for pre-0.17 Bitcoin Core --- docs/INSTALL.md | 4 +- docs/PAYJOIN.md | 2 +- docs/TESTING.md | 2 +- jmclient/jmclient/blockchaininterface.py | 61 ++++++++---------------- 4 files changed, 24 insertions(+), 45 deletions(-) diff --git a/docs/INSTALL.md b/docs/INSTALL.md index bc0965f..c9cf87e 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -117,9 +117,11 @@ Before starting, note you need either (a) Bitcoin Core installed on Windows or ( If (a), then note the following two points: ##### Installing Bitcoin Core -If you haven't done so yet, install Bitcoin Core as described [here](https://bitcoin.org/en/full-node#windows-10). After starting it for the first time, it will start the Initial Block Download. JoinMarket cannot be used until this is finished. More information on that can be found [here](https://bitcoin.org/en/full-node#initial-block-downloadibd). + +If you haven't done so yet, install Bitcoin Core, version 0.18 or newer, as described [here](https://bitcoin.org/en/full-node#windows-10). After starting it for the first time, it will start the Initial Block Download. JoinMarket cannot be used until this is finished. More information on that can be found [here](https://bitcoin.org/en/full-node#initial-block-downloadibd). ##### Configuring Bitcoin Core + Bitcoin Core needs to be configured to allow JoinMarket to connect to it. From the `Settings` menu choose `Options` and click `Open Configuration File`. Add `server=1`, save and close the file. After that restart Bitcoin Core. There are currently two choices for installing on Windows; one, directly installing on Windows, requiring the manual addition of a libsodium dependency, or, two, using Ubuntu via the WSL mechanism (which may require additional setup to make the Qt GUI work). diff --git a/docs/PAYJOIN.md b/docs/PAYJOIN.md index 05ba820..4119bd4 100644 --- a/docs/PAYJOIN.md +++ b/docs/PAYJOIN.md @@ -39,7 +39,7 @@ So just skip those sections if you already know it. ### Preparatory step: configuring for Bitcoin Core. -Joinmarket currently requires a Bitcoin Core full node, although it can be pruned. +Joinmarket currently requires a Bitcoin Core full node, version 0.18 or newer, although it can be pruned. First thing to do: in `scripts/`, run: diff --git a/docs/TESTING.md b/docs/TESTING.md index d3de1e8..5596c40 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -1,6 +1,6 @@ ### Test instructions (for developers): -Work in your `jmvenv` virtualenv as for all Joinmarket work. Make sure to have [bitcoind](https://bitcoin.org/en/full-node) 0.17 or newer installed. Also need miniircd installed to the root (i.e. in your `joinmarket-clientserver` directory): +Work in your `jmvenv` virtualenv as for all Joinmarket work. Make sure to have [bitcoind](https://bitcoin.org/en/full-node) 0.18 or newer installed. Also need miniircd installed to the root (i.e. in your `joinmarket-clientserver` directory): (jmvenv)$ cd /path/to/joinmarket-clientserver (jmvenv)$ git clone https://github.com/Joinmarket-Org/miniircd diff --git a/jmclient/jmclient/blockchaininterface.py b/jmclient/jmclient/blockchaininterface.py index 9a85da1..42e5758 100644 --- a/jmclient/jmclient/blockchaininterface.py +++ b/jmclient/jmclient/blockchaininterface.py @@ -184,10 +184,7 @@ class BitcoinCoreInterface(BlockchainInterface): raise Exception('wrong network configured') def is_address_imported(self, addr): - try: - return self._rpc('getaccount', [addr]) != '' - except JsonRpcError: - return len(self._rpc('getaddressinfo', [addr])['labels']) > 0 + return len(self._rpc('getaddressinfo', [addr])['labels']) > 0 def get_block(self, blockheight): """Returns full serialized block at a given height. @@ -232,11 +229,7 @@ class BitcoinCoreInterface(BlockchainInterface): return res def is_address_labeled(self, utxo, walletname): - # Bitcoin Core before 0.17 used accounts, new versions has labels - return ( - ("label" in utxo and utxo["label"] == walletname) or - ("account" in utxo and utxo["account"] == walletname) - ) + return ("label" in utxo and utxo["label"] == walletname) def import_addresses(self, addr_list, wallet_name, restart_cb=None): """Imports addresses in a batch during initial sync. @@ -275,15 +268,11 @@ class BitcoinCoreInterface(BlockchainInterface): sys.exit(EXIT_FAILURE) def import_addresses_if_needed(self, addresses, wallet_name): - try: - imported_addresses = set(self._rpc('getaddressesbyaccount', - [wallet_name])) - except JsonRpcError: - if wallet_name in self._rpc('listlabels', []): - imported_addresses = set(self._rpc('getaddressesbylabel', - [wallet_name]).keys()) - else: - imported_addresses = set() + if wallet_name in self._rpc('listlabels', []): + imported_addresses = set(self._rpc('getaddressesbylabel', + [wallet_name]).keys()) + else: + imported_addresses = set() import_needed = not addresses.issubset(imported_addresses) if import_needed: self.import_addresses(addresses - imported_addresses, wallet_name) @@ -327,25 +316,21 @@ class BitcoinCoreInterface(BlockchainInterface): watch-only wallets. """ htxid = bintohex(txid) - #changed syntax in 0.14.0; allow both syntaxes try: res = self._rpc("gettransaction", [htxid, True]) + except JsonRpcError as e: + #This should never happen (gettransaction is a wallet rpc). + log.warn("Failed gettransaction call; JsonRpcError: " + repr(e)) + return None except Exception as e: - try: - res = self._rpc("gettransaction", [htxid, 1]) - except JsonRpcError as e: - #This should never happen (gettransaction is a wallet rpc). - log.warn("Failed gettransaction call; JsonRpcError: " + repr(e)) - return None - except Exception as e: - log.warn("Failed gettransaction call; unexpected error:") - log.warn(str(e)) - return None + log.warn("Failed gettransaction call; unexpected error:") + log.warn(str(e)) + return None if res is None: # happens in case of rpc connection failure: return None if "confirmations" not in res: - log.warning("Malformed gettx result: " + str(res)) + log.warning("Malformed gettransaction result: " + str(res)) return None return res @@ -479,11 +464,7 @@ class BitcoinCoreInterface(BlockchainInterface): return self._rpc('getblockchaininfo', [])['mediantime'] def _get_block_header_data(self, blockhash, key): - try: - # works with pruning enabled, but only after v0.12 - return self._rpc('getblockheader', [blockhash])[key] - except JsonRpcError: - return self._rpc('getblock', [blockhash])[key] + return self._rpc('getblockheader', [blockhash])[key] def get_block_height(self, blockhash): return self._get_block_header_data(blockhash, 'height') @@ -594,13 +575,9 @@ class BitcoinCoreNoHistoryInterface(BitcoinCoreInterface, RegtestBitcoinCoreMixi addr_list = ["addr(" + a + ")" for a in addresses] log.debug("Starting scan of UTXO set") st = time.time() - try: - self._rpc("scantxoutset", ["abort", []]) - self.scan_result = self._rpc("scantxoutset", ["start", - addr_list]) - except JsonRpcError as e: - raise RuntimeError("Bitcoin Core 0.17.0 or higher required " - + "for no-history sync (" + repr(e) + ")") + self._rpc("scantxoutset", ["abort", []]) + self.scan_result = self._rpc("scantxoutset", ["start", + addr_list]) et = time.time() log.debug("UTXO set scan took " + str(et - st) + "sec") elif self.import_addresses_call_count > 4: