Remove dead code left by the other coins

GENESIS_ACTIVATION and is_unspendable_genesis (always legacy for Palladium),
script matching helpers and ScriptPubKey.TO_*_OPS, Deserializer._read_be_uint16,
the unused Coin.CHUNK_SIZE and ENCODE_CHECK, the name-index fallback of the
local RPC 'query' command, and stale comments about other coins.

Block processing and the db format are unchanged: a fresh sync gives the same
history as before. STATIC_BLOCK_HEADERS and the dynamic header code in db.py
are left, being generic functionality that would need wider changes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
davideandClaude Sonnet 5.5 committed 2026-10-22 16:25:58 +02:00
1 parent 3d05c37feb
commit f1e6ad29ab
6 files changed
+13 -63

No files matched your search

+1 -6
View File
@@ -63,7 +63,6 @@ class Coin:
# Not sure if these are coin-specific
RPC_URL_REGEX = re.compile('.+@(\\[[0-9a-fA-F:]+\\]|[^:]+)(:[0-9]+)?')
VALUE_PER_COIN = 100000000
CHUNK_SIZE = 2016
BASIC_HEADER_SIZE = 80
STATIC_BLOCK_HEADERS = True
SESSIONCLS = ElectrumX
@@ -72,11 +71,9 @@ class Coin:
BLOCK_PROCESSOR = block_proc.BlockProcessor
P2PKH_VERBYTE = bytes.fromhex("00")
P2SH_VERBYTES = (bytes.fromhex("05"),)
ENCODE_CHECK = Base58.encode_check
DECODE_CHECK = Base58.decode_check
GENESIS_HASH = ('000000000019d6689c085ae165831e93'
'4ff763ae46a2a6c172b3f1b60a8ce26f') # 'hum' byte-order
GENESIS_ACTIVATION = 100_000_000
# max byte-size of single jsonrpc message
# note: we should probably be able to serve a client asking for the largest consensus-valid tx.
@@ -188,9 +185,7 @@ class Coin:
'''Return a pubkey script that pays to a pubkey hash.
Pass the address (either P2PKH or P2SH) in base58 form.
note(ghost43): looks mainly needed for serving the altcoin Dash(Coin)'s "masternode.list" RPC.
Barring that, we could rip out the whole base58 encoder/decoder.
Only used for the local RPC 'query' command (bech32 addresses are not supported).
'''
raw = cls.DECODE_CHECK(address)
-23
View File
@@ -77,34 +77,11 @@ def is_unspendable_legacy(script):
return script[:2] == b'\x00\x6a' or (script and script[0] == 0x6a)
def is_unspendable_genesis(script):
# OP_FALSE OP_RETURN
return script[:2] == b'\x00\x6a'
def _match_ops(ops, pattern):
if len(ops) != len(pattern):
return False
for op, pop in zip(ops, pattern):
if pop != op:
# -1 means 'data push', whose op is an (op, data) tuple
if pop == -1 and isinstance(op, tuple):
continue
return False
return True
class ScriptPubKey:
'''A class for handling a tx output script that gives conditions
necessary for spending.
'''
TO_ADDRESS_OPS = (OpCodes.OP_DUP, OpCodes.OP_HASH160, -1,
OpCodes.OP_EQUALVERIFY, OpCodes.OP_CHECKSIG)
TO_P2SH_OPS = (OpCodes.OP_HASH160, -1, OpCodes.OP_EQUAL)
TO_PUBKEY_OPS = (-1, OpCodes.OP_CHECKSIG)
@classmethod
def P2SH_script(cls, hash160):
return (bytes((OpCodes.OP_HASH160,))
-6
View File
@@ -33,7 +33,6 @@ from typing import Sequence, Optional, Tuple
from electrumx.lib.hash import double_sha256, hash_to_hex_str
from electrumx.lib.util import (
unpack_le_int32_from, unpack_le_int64_from, unpack_le_uint16_from,
unpack_be_uint16_from,
unpack_le_uint32_from, unpack_le_uint64_from, pack_le_int32, pack_varint,
pack_le_uint32, pack_le_int64, pack_varbytes,
)
@@ -237,11 +236,6 @@ class Deserializer:
self.cursor += 2
return result
def _read_be_uint16(self):
result, = unpack_be_uint16_from(self.binary, self.cursor)
self.cursor += 2
return result
def _read_le_uint32(self):
result, = unpack_le_uint32_from(self.binary, self.cursor)
self.cursor += 4
+3 -9
View File
@@ -22,7 +22,7 @@ from aiorpcx import run_in_thread, CancelledError, ignore_after
import electrumx
from electrumx.server.daemon import DaemonError, Daemon
from electrumx.lib.hash import hash_to_hex_str, HASHX_LEN
from electrumx.lib.script import is_unspendable_legacy, is_unspendable_genesis
from electrumx.lib.script import is_unspendable_legacy
from electrumx.lib.util import (
chunks, class_logger, OldTaskGroup,
)
@@ -526,9 +526,7 @@ class BlockProcessor:
"""This method must be thread-safe. (runs on bp.pool_executor)"""
tx_num_start = self.db.tx_counts[height - 1] if height > 0 else 0
is_unspendable = (
is_unspendable_genesis if height >= self.coin.GENESIS_ACTIVATION
else is_unspendable_legacy)
is_unspendable = is_unspendable_legacy
# Use local vars for speed in the loops
script_hashX = self.coin.hashX_from_script
@@ -643,8 +641,6 @@ class BlockProcessor:
assert self.state_lock.locked()
self.db.assert_flushed(self.flush_data())
assert self.height >= len(raw_blocks)
genesis_activation = self.coin.GENESIS_ACTIVATION
coin = self.coin
for raw_block in raw_blocks:
# Check and update self.tip
@@ -656,9 +652,7 @@ class BlockProcessor:
f'{hash_to_hex_str(self.tip)} at height {self.height:,d}'
)
self.tip = coin.header_prevhash_rev(block.header)
is_unspendable = (is_unspendable_genesis if self.height >= genesis_activation
else is_unspendable_legacy)
self.backup_txs(block.transactions, is_unspendable)
self.backup_txs(block.transactions, is_unspendable_legacy)
self._bhash_to_bheight[header_hash] = self.height
self.height -= 1
self.db.tx_counts.pop()
+2 -10
View File
@@ -584,7 +584,7 @@ class SessionManager:
async def rpc_add_peer(self, real_name: str) -> str:
'''Add a peer.
real_name: "bch.electrumx.cash t50001 s50002" for example
real_name: "electrum.example.com t50001 s50002" for example
'''
await self.peer_mgr.add_localRPC_peer(real_name)
return f"peer '{real_name}' added"
@@ -697,7 +697,7 @@ class SessionManager:
return self.peer_mgr.rpc_data()
async def rpc_query(self, items, limit):
'''Returns data about a script, address or name.'''
'''Returns data about a script or address.'''
coin = self.env.coin
db = self.db
lines = []
@@ -717,14 +717,6 @@ class SessionManager:
except Base58Error:
pass
try:
script = coin.build_name_index_script(arg.encode("ascii"))
hashX = coin.name_hashX_from_script(script)
lines.append(f'Name: {arg}')
return hashX
except (AttributeError, UnicodeEncodeError):
pass
return None
for arg in items:
+7 -9
View File
@@ -1,17 +1,16 @@
import pytest
from electrumx.lib.script import OpCodes, is_unspendable_legacy, is_unspendable_genesis
from electrumx.lib.script import OpCodes, is_unspendable_legacy
@pytest.mark.parametrize("script, iug", (
(bytes([OpCodes.OP_RETURN]), False),
(bytes([OpCodes.OP_RETURN]) + bytes([2, 28, 50]), False),
(bytes([OpCodes.OP_0, OpCodes.OP_RETURN]), True),
(bytes([OpCodes.OP_0, OpCodes.OP_RETURN]) + bytes([2, 28, 50]), True)
@pytest.mark.parametrize("script", (
bytes([OpCodes.OP_RETURN]),
bytes([OpCodes.OP_RETURN]) + bytes([2, 28, 50]),
bytes([OpCodes.OP_0, OpCodes.OP_RETURN]),
bytes([OpCodes.OP_0, OpCodes.OP_RETURN]) + bytes([2, 28, 50]),
))
def test_op_return_legacy(script, iug):
def test_op_return(script):
assert is_unspendable_legacy(script)
assert is_unspendable_genesis(script) is iug
@pytest.mark.parametrize("script", (
@@ -23,4 +22,3 @@ def test_op_return_legacy(script, iug):
))
def test_not_op_return(script):
assert not is_unspendable_legacy(script)
assert not is_unspendable_genesis(script)