Use coins_plm.py as single source of truth for ElectrumX patch
- Remove inline Palladium coin definition from Dockerfile.electrumx and COPY coins_plm.py instead, reducing duplication - Add TX_COUNT/TX_COUNT_HEIGHT/TX_PER_BLOCK to coins_plm.py with real chain data (457478 txs at height 382404) - Update entrypoint.sh to fetch live TX stats from palladiumd at container startup, keeping sync estimates accurate automatically
This commit is contained in:
@@ -53,5 +53,41 @@ echo "RPC Port: ${RPC_PORT}"
|
||||
echo "DAEMON_URL: http://${RPC_USER}:***@palladiumd:${RPC_PORT}/"
|
||||
echo "=========================================="
|
||||
|
||||
# Update TX_COUNT / TX_COUNT_HEIGHT in coins.py from the live node
|
||||
echo "Fetching chain tx stats from palladiumd..."
|
||||
TX_STATS=$(curl -sf --user "${RPC_USER}:${RPC_PASSWORD}" \
|
||||
--data-binary '{"jsonrpc":"1.0","method":"getchaintxstats","params":[]}' \
|
||||
-H 'Content-Type: text/plain;' \
|
||||
"http://palladiumd:${RPC_PORT}/" 2>/dev/null || true)
|
||||
|
||||
if [ -n "$TX_STATS" ]; then
|
||||
TX_COUNT=$(echo "$TX_STATS" | python3 -c "import sys,json; print(json.load(sys.stdin)['result']['txcount'])" 2>/dev/null || true)
|
||||
TX_HEIGHT=$(echo "$TX_STATS" | python3 -c "import sys,json; print(json.load(sys.stdin)['result']['window_final_block_height'])" 2>/dev/null || true)
|
||||
|
||||
if [ -n "$TX_COUNT" ] && [ -n "$TX_HEIGHT" ]; then
|
||||
echo "Patching coins.py: TX_COUNT=${TX_COUNT}, TX_COUNT_HEIGHT=${TX_HEIGHT}"
|
||||
python3 - "$TX_COUNT" "$TX_HEIGHT" <<'TXPATCH'
|
||||
import sys, pathlib, re
|
||||
tx_count, tx_height = sys.argv[1], sys.argv[2]
|
||||
for target in [
|
||||
'/usr/local/lib/python3.13/dist-packages/electrumx/lib/coins.py',
|
||||
'/electrumx/src/electrumx/lib/coins.py',
|
||||
]:
|
||||
p = pathlib.Path(target)
|
||||
if not p.exists():
|
||||
continue
|
||||
s = p.read_text()
|
||||
s = re.sub(r'(class Palladium\(Bitcoin\):.*?TX_COUNT\s*=\s*)\d+', rf'\g<1>{tx_count}', s, count=1, flags=re.DOTALL)
|
||||
s = re.sub(r'(class Palladium\(Bitcoin\):.*?TX_COUNT_HEIGHT\s*=\s*)\d+', rf'\g<1>{tx_height}', s, count=1, flags=re.DOTALL)
|
||||
p.write_text(s)
|
||||
TXPATCH
|
||||
echo ">> TX stats updated from live node"
|
||||
else
|
||||
echo ">> Could not parse tx stats, using defaults from coins_plm.py"
|
||||
fi
|
||||
else
|
||||
echo ">> Node not reachable yet, using defaults from coins_plm.py"
|
||||
fi
|
||||
|
||||
# Execute the original electrumx command
|
||||
exec /usr/local/bin/electrumx_server
|
||||
|
||||
Reference in New Issue
Block a user