diff --git a/electrumx/lib/coins.py b/electrumx/lib/coins.py index 1fedce8..a8b3167 100644 --- a/electrumx/lib/coins.py +++ b/electrumx/lib/coins.py @@ -47,8 +47,7 @@ import electrumx.lib.tx_dash as lib_tx_dash import electrumx.server.block_processor as block_proc import electrumx.server.daemon as daemon from electrumx.server.session import (ElectrumX, DashElectrumX, - SmartCashElectrumX, AuxPoWElectrumX, - BitcoinSegwitElectrumX) + SmartCashElectrumX, AuxPoWElectrumX) Block = namedtuple("Block", "raw header transactions") @@ -85,6 +84,7 @@ class Coin(object): # Peer discovery PEER_DEFAULT_PORTS = {'t': '50001', 's': '50002'} PEERS = [] + CRASH_CLIENT_VER = None BLACKLIST_URL = None @classmethod @@ -399,11 +399,11 @@ class BitcoinCash(BitcoinMixin, Coin): class BitcoinSegwit(BitcoinMixin, Coin): NAME = "BitcoinSegwit" DESERIALIZER = lib_tx.DeserializerSegWit - SESSIONCLS = BitcoinSegwitElectrumX MEMPOOL_HISTOGRAM_REFRESH_SECS = 120 TX_COUNT = 318337769 TX_COUNT_HEIGHT = 524213 TX_PER_BLOCK = 1400 + CRASH_CLIENT_VER = (3, 2, 3) BLACKLIST_URL = 'https://electrum.org/blacklist.json' PEERS = [ 'btc.smsys.me s995', @@ -612,7 +612,7 @@ class BitcoinSegwitTestnet(BitcoinTestnetMixin, Coin): '''Bitcoin Testnet for Core bitcoind >= 0.13.1.''' NAME = "BitcoinSegwit" DESERIALIZER = lib_tx.DeserializerSegWit - SESSIONCLS = BitcoinSegwitElectrumX + CRASH_CLIENT_VER = (3, 2, 3) PEERS = [ 'electrum.akinbo.org s t', 'he36kyperp3kbuxu.onion s t', diff --git a/electrumx/server/session.py b/electrumx/server/session.py index d295692..f305da1 100644 --- a/electrumx/server/session.py +++ b/electrumx/server/session.py @@ -1078,7 +1078,9 @@ class ElectrumX(SessionBase): # that protocol version in unsupported. ptuple, client_min = util.protocol_version( protocol_version, self.PROTOCOL_MIN, self.PROTOCOL_MAX) - await self.maybe_attempt_to_crash_old_client(ptuple) + + await self.crash_old_client(ptuple, self.env.coin.CRASH_CLIENT_VER) + if ptuple is None: if client_min > self.PROTOCOL_MIN: self.logger.info(f'client requested future protocol version ' @@ -1090,8 +1092,17 @@ class ElectrumX(SessionBase): return (electrumx.version, self.protocol_version_string()) - async def maybe_attempt_to_crash_old_client(self, proto_ver): - return + async def crash_old_client(self, ptuple, crash_client_ver): + if crash_client_ver: + client_ver = util.protocol_tuple(self.client) + is_old_protocol = ptuple is None or ptuple <= (1, 2) + is_old_client = client_ver != (0,) and client_ver <= crash_client_ver + if is_old_protocol and is_old_client: + self.logger.info(f'attempting to crash old client with version {self.client}') + # this can crash electrum client 2.6 <= v < 3.1.2 + await self.send_notification('blockchain.relayfee', ()) + # this can crash electrum client (v < 2.8.2) UNION (3.0.0 <= v < 3.3.0) + await self.send_notification('blockchain.estimatefee', ()) async def transaction_broadcast(self, raw_tx): '''Broadcast a raw transaction to the network. @@ -1505,17 +1516,3 @@ class AuxPoWElectrumX(ElectrumX): height += 1 return headers.hex() - - -class BitcoinSegwitElectrumX(ElectrumX): - - async def maybe_attempt_to_crash_old_client(self, proto_ver): - client_ver = util.protocol_tuple(self.client) - is_old_protocol = proto_ver is None or proto_ver <= (1, 2) - is_old_client = client_ver != (0,) and client_ver < (3, 2, 4) - if is_old_protocol and is_old_client: - self.logger.info(f'attempting to crash old client with version {self.client}') - # this can crash electrum client 2.6 <= v < 3.1.2 - await self.send_notification('blockchain.relayfee', ()) - # this can crash electrum client (v < 2.8.2) UNION (3.0.0 <= v < 3.3.0) - await self.send_notification('blockchain.estimatefee', ())