Skip to content

Upgrade to ElectrumX 2.0.0 and port the Doichain coin classes - #10

Closed
NiKrause wants to merge 483 commits into
masterfrom
feat/electrumx-2.0
Closed

NiKrause wants to merge 483 commits into
masterfrom
feat/electrumx-2.0

Conversation

@NiKrause

Copy link
Copy Markdown
Contributor

Upgrades this fork from ElectrumX 1.15.0 (2020) to upstream 2.0.0 (3 July 2026) and ports the Doichain coin classes onto it. 482 upstream commits plus one of ours; the merge base with master is upstream tag 1.15.0 (835aa49), so this is the whole jump in one branch, including the releases 1.16 through 1.20 that we skipped.

Why

  • 1.15.0 pins aiorpcX < 0.19 and runs on Python versions that are past end of life (3.7 on the servers, 3.9 in the container image), so it receives no upstream fixes.
  • RPC_PORT in the coin class was 8338. Since Doichain Core 31 that is the P2P port — RPC is 8339 — so a DAEMON_URL without an explicit port connected to the wrong socket and ElectrumX never got an answer.
  • 2.0.0 ends the periodic "DB::flush_count overflow" and the manual history compaction that came with it.

What the port had to handle

Upstream did not keep the shape our classes were written against:

1.15.0 2.0.0
base classes NameIndexMixin, AuxPowMixin, Coin NameIndexAuxPoWMixin, Coin (carries SESSIONCLS)
P2SH_VERBYTES, NAME_OPERATIONS lists tuples
name expiry — NAME_EXPIRATION (new)
XPUB_VERBYTES, XPRV_VERBYTES, WIF_BYTE present removed upstream, no remaining use
testnet / regtest full copies inherit from the mainnet class

Values are taken from the chain and the consensus rules rather than carried over:

  • RPC_PORT 8339 / 18339 / 18332
  • TX_COUNT 2,742,220 at height 431,763 (getchaintxstats), TX_PER_BLOCK 2 (4,937 transactions in the last 4,320 blocks)
  • NAME_EXPIRATION 36,000, regtest 30 — Consensus::MainNetConsensus::NameExpirationDepth, which returns 36,000 above height 48,000

Verification

With the package installed, ElectrumX resolves all three classes itself:

  • SESSIONCLS NameIndexAuxPoWElectrumX, DESERIALIZER DeserializerAuxPowSegWit, BLOCK_PROCESSOR NameIndexBlockProcessor
  • four name operations including name_doi (OP_10), as a tuple
  • REQUIRED_DAEMON_INDEXES empty — 2.0.0 requires txospenderindex only on class Bitcoin, so no additional index is needed on doichaind
  • tests/lib/test_coins.py: 16 passed

tests/lib/test_merkle.py and four test_addresses.py cases (SmartCash among them) fail on the pristine 2.0.0 tag as well, verified by stashing this change — they are a missing pytest-asyncio and a missing optional hash module, not a regression.

For operators, when this is deployed

  • The database schema changed and there is no migration path: every server reindexes from genesis. On this chain, node and index were complete about 25 minutes from empty volumes.
  • DB_ENGINE is now mandatory (leveldb or rocksdb; RocksDB syncs roughly 25 % faster on SSD).
  • Python ≥ 3.10, aiorpcX ≥ 0.25.
  • Electrum wallets are unaffected: 2.0.0 still serves PROTOCOL_MIN = (1, 4).

Not in this PR

The container recipe and the compose service live in Doichain/doichain-install and follow separately.

🤖 Generated with Claude Code

SomberNight and others added 30 commits June 13, 2025 23:22
docs: fix lib/coins.py link in environment.rst
to help distinguish logs from kyuupichan/electrumx

ref spesmilo/electrumx#306
This prevents the DoS attack vector caused by hitting the max number of sessions.
Prior to this change if the max number of sessions was reached, the server would stop listening for new connections until ALL existing connections were closed.
Now, the listening port is closed, the existing connections remain live and when the lower threshold is reached, the listening socket is reopened.
…implementation

fix: prevent incorrect session limit DoS attack vector
Adds the `mempool.get_info` rpc to fetch mempoolminfee, minrelaytxfee
and incrementalrelayfee from the daemons getmempoolinfo rpc for protocol
version 1.6.
Updates the relayfee comments as the fee returned by
`blockchain.relayfee` doesn't guarantee to get into the mempool as
previously stated in the docstrings.
The parsing of the version number returned from 'getnetworkinfo' was not
adapted to the changed bitcoin core version number scheme since core went
from beta to stable. The banner incorrectly showed 0.29.0 instead of
29.0.0.
Checks the daemon version on startup against a minimum allowed daemon
version hardcoded in the corresponding `Coin`. This allows ensure that
the connected daemon is running a version that supports all the rpc
calls electrumx requires.
Guards the new `blockchain.transaction.broadcast_package` and
`mempool.get_info` methods of protocol 1.6 behind this versions ptuple
in `set_request_handlers` so they are only exposed in protocol versions
>= 1.6. Also stops exposing the `blockchain.relayfee` endpoint for
version >= 1.6 as it got removed in 1.6.
implements mempool.get_info and clarifies comments of relayfee
check daemon version on startup, fix version in banner
Removes the incorrect and unnecessary txid calculation in
`ElectrumX.package_broadcast()`, the daemon will complain anyways if the
transactions are invalid.
Make mode uppercase if passed as neither the protocol nor core do
specify any requirement here.
session: estimatefee: normalize mode arg
session: broadcast_package: followup #288
session.py: sanitize inputs for tx broadcast RPCs
was just sending back a response with value 1, instead of a jsonrpc error

ref spesmilo/electrumx@860ff53
session: fix ReplyAndDisconnect. was broken for PaddedRSTransport
Adds a 1024 (unpadded) byte sending budget to the PaddedRSTransport below which
messages are instantly flushed down the socket before the transport will
beginn waiting for the buffer to reach MIN_PACKET_SIZE (1024).
This allows to get the first couple of messages sent quickly when
a wallet connects to improve its ux.
add warmup budget to PaddedRSTransport
We already enforce that server.version must be the first received message
in a session, but we also need to ensure that the server finishes processing
that message and sets up the correct protocol version before starting to
process further messages.
protocol 1.6: "server.version" must be first msg, must tolerate unknown args
Note that this is a soft fork: the server can apply it even for past
protocol versions.

Previously, with the order being undefined, if an address had multiple
mempool transactions touching it, switching between different servers
could result in a change in address status simply as a result of these
servers ordering mempool txs differently. This would result in the client
re-requesting the whole history of the address.

-----

D/i | interface.[electrum.blockstream.info:60002] | <-- ('blockchain.scripthash.subscribe', ['660b44502503064f9d5feee48726287c0973e25bc531b4b8a072f57f143d5cd0']) {} (id: 12)
D/i | interface.[electrum.blockstream.info:60002] | --> 9da27f9df91e3f860212f65b736fa20a539ba6e3d509f6370367ee7f10a4d5b0 (id: 12)
D/i | interface.[electrum.blockstream.info:60002] | <-- ('blockchain.scripthash.get_history', ['660b44502503064f9d5feee48726287c0973e25bc531b4b8a072f57f143d5cd0']) {} (id: 13)
D/i | interface.[electrum.blockstream.info:60002] | --> [
{'fee': 200, 'height': 0, 'tx_hash': '3ee6d6e26291ce360127fe039b816470fce6eeea19b5c9d10829a1e4efc2d0c7'},
{'fee': 239, 'height': 0, 'tx_hash': '9e050f09b676b9b0ee26aa02ccee623fae585a85d6a5e24ecedd6f8d6d2d3b1d'},
{'fee': 178, 'height': 0, 'tx_hash': 'fb80adbf8274190418cb3fb0385d82fe9d47a844d9913684fa5fb3d48094b35a'},
{'fee': 200, 'height': 0, 'tx_hash': '713933c50b7c43f606dad5749ea46e3bc6622657e9b13ace9d639697da266e8b'}
] (id: 13)

D/i | interface.[testnet.hsmiths.com:53012] | <-- ('blockchain.scripthash.subscribe', ['660b44502503064f9d5feee48726287c0973e25bc531b4b8a072f57f143d5cd0']) {} (id: 12)
D/i | interface.[testnet.hsmiths.com:53012] | --> f7ef7237d2d62a3280acae05616200b96ad9dd85fd0473c29152a4a41e05686c (id: 12)
D/i | interface.[testnet.hsmiths.com:53012] | <-- ('blockchain.scripthash.get_history', ['660b44502503064f9d5feee48726287c0973e25bc531b4b8a072f57f143d5cd0']) {} (id: 13)
D/i | interface.[testnet.hsmiths.com:53012] | --> [
{'tx_hash': '9e050f09b676b9b0ee26aa02ccee623fae585a85d6a5e24ecedd6f8d6d2d3b1d', 'height': 0, 'fee': 239},
{'tx_hash': 'fb80adbf8274190418cb3fb0385d82fe9d47a844d9913684fa5fb3d48094b35a', 'height': 0, 'fee': 178},
{'tx_hash': '3ee6d6e26291ce360127fe039b816470fce6eeea19b5c9d10829a1e4efc2d0c7', 'height': 0, 'fee': 200},
{'tx_hash': '713933c50b7c43f606dad5749ea46e3bc6622657e9b13ace9d639697da266e8b', 'height': 0, 'fee': 200}
] (id: 13)
SomberNight and others added 25 commits June 29, 2026 14:13
utxo db: incrementally clear excess undo infos as we go
reverts parts of
e1ccd4b
ead66dd

self.txs and self.hashXs and self.txo_to_spender are accessed
from the external interface, on the asyncio thread, and they are
assumed to be consistent with each other.
mempool: partially revert threading _process_mempool
protocol 1.7: revert adding chaintip to responses
also,
- don't pin python patch version
- use default env var values
- "docker stop" seems cleaner, more intuitive, than kill
dockerfile: switch to rocksdb, and show how to build free-threaded python
Our fleet runs ElectrumX 1.15.0 (2020). Upstream 2.0.0 moved the tree to
src/, merged the name and AuxPoW mixins into NameIndexAuxPoWMixin (which
carries SESSIONCLS), turned P2SH_VERBYTES and NAME_OPERATIONS into tuples,
added NAME_EXPIRATION, and dropped XPUB/XPRV/WIF entirely -- they have no
remaining use anywhere in the tree.

Values come from the chain and the consensus rules rather than being carried
over unchanged:

  RPC_PORT 8339 / 18339       8338 is the P2P port since Core 31, so the old
                              value pointed ElectrumX at the wrong socket
  TX_COUNT 2,742,220          getchaintxstats at height 431,763
  NAME_EXPIRATION 36,000 / 30 Consensus::MainNetConsensus::NameExpirationDepth
                              (36,000 above height 48,000; regtest 30)

Testnet and regtest inherit from Doichain now instead of repeating every
declaration, matching how upstream keeps the Namecoin classes.

Verified with the package installed: ElectrumX resolves all three classes,
with SESSIONCLS NameIndexAuxPoWElectrumX, DESERIALIZER DeserializerAuxPowSegWit,
BLOCK_PROCESSOR NameIndexBlockProcessor, four name operations including
name_doi, and REQUIRED_DAEMON_INDEXES empty -- so no extra daemon index is
required. tests/lib/test_coins.py: 16 passed.

Co-Authored-By: Claude Opus 5 <[email protected]>
@NiKrause

Copy link
Copy Markdown
Contributor Author

Superseded by the branch feat/electrumx-2.0-r2, which is the same upgrade with master merged in and the conflicts resolved, so it is mergeable as it stands.

One of the conflicts did not announce itself: git treated electrumx/lib/coins.py → src/electrumx/lib/coins.py as a rename and merged master's 121 lines of Doichain classes into the already-ported file without a conflict marker, leaving every class defined twice. In Python the second definition wins, so resolving only the two reported conflicts would have shipped the old classes — no name RPC, RPC port 8338, no NAME_EXPIRATION — with a diff that looks fine.

Please close this PR in favour of the replacement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants