Commit 2d007f2
committed
S3-E.3: hedera dual-protocol adapter (Mirror REST + JSON-RPC Relay)
Hedera 是天然双协议链 — Mirror REST 提供账户/balance/transaction 查询,
JSON-RPC Relay (Hashio) 提供 EVM-compat eth_* 方法。原 `rest` family adapter
不支持单 chain 内 per-method 协议路由,所以 mixed mode 跑 eth_getBalance/
eth_call 时会 ValueError(method not in _meta.rest_paths)。
## 改动
(1) 新建 `tools/chain_adapters/hedera_dual.py` — 第 7 个 adapter family。
- per-method 路由:eth_*/net_*/web3_*/debug_*/trace_* → JSON-RPC POST
到 _meta.json_rpc_url;其他 path-style key → REST GET/POST
- delegate to RestAdapter + JsonRpcAdapter,不重复 logic
- health_check 复用 REST 侧;parse_block_height 两侧 best-effort
(2) `tools/chain_adapters/base.py` — import chain 加 hedera_dual
(3) `config/chains/hedera.json`:
- adapter_family: rest → hedera_dual(留 adapter_family_upgraded_at 审计)
- 加 _meta.json_rpc_url = https://mainnet.hashio.io/api
- 保留全 5 mixed method(3 Mirror REST + eth_getBalance + eth_call)
(4) `tests/test_chain_adapters.py`:
- test_factory_registers_six → seven_families;expected set 含 hedera_dual
- KNOWN_BROKEN_CLI 移除 hedera 条目,assert len 14 → 13
- _sample_address_for 加 hedera_dual → "0.0.2"(原生 3-part ID)
## 验证
L1:python3 tests/test_chain_adapters.py → 10/10 PASS
- healthy 22 → 23(hedera 进集合)
- broken 14 → 13
- 7 families registered
L3 替代:bash tools/target_generator.sh BLOCKCHAIN_NODE=hedera RPC_MODE=mixed
- 4 个 account × 5 method 全成功,exit=0
- 实际生成 vegeta target:
* Mirror REST GET → mainnet-public.mirrornode.hedera.com/api/v1/accounts/0.0.2
* Mirror REST GET → mainnet-public.mirrornode.hedera.com/api/v1/balances?account.id=0.0.98
* Mirror REST GET → mainnet-public.mirrornode.hedera.com/api/v1/transactions/0.0.800
* JSON-RPC POST → mainnet.hashio.io/api body={"method":"eth_getBalance","params":["0.0.801"]}
- 真双协议路由生效
L3 single mode:4 account × 1 method (GET /api/v1/accounts/{addr}) 全成功
## 自审 E1-E5
E1 (调研先行):基于 docs/zh/chains/14-hedera.md 调研(E1-E15 实测过 Mirror + Hashio),
endpoint URL 现场 curl HTTP 200 复验。
E2 (无降级/未 defer):5 method 全保留,不砍 mixed,无 KNOWN_BROKEN_MIXED ledger。
E3 (实证):L1 10/10 + L3 真路径 vegeta target 文件生成 + body base64 decode 验证。
E4 (parallel-entry-trap):无新平行入口,新 adapter 用 composition (RestAdapter +
JsonRpcAdapter delegation),不复制 logic。
E5 (broken set 单调递减):14 → 13,hedera 进 audit healthy 集合。
## 显式 defer(非降级,新 wave 处理)
(a) cli.py L40 读 `params` 字段应该是 `param_formats` — 全链 bug,影响所有
JSON-RPC chain 的 param shape(eth_getBalance 应为 [addr, "latest"]
现 [addr])。本 PR scope = hedera_dual adapter,不污染 commit。
(b) hedera eth_* 实际生产需把 3-part ID (0.0.N) 转 EVM 地址 (0x...0N),
fetch_active_accounts 端处理,留 S4。
ledger: KNOWN_BROKEN_CLI baseline 16 → S3-E.1 aptos -1 → S3-E.2 algorand -1
→ S3-E.3 hedera -1 → 13 剩1 parent 2e05837 commit 2d007f2
4 files changed
Lines changed: 145 additions & 11 deletions
File tree
- config/chains
- tests
- tools/chain_adapters
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
| 20 | + | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
59 | 70 | | |
60 | 71 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
343 | 343 | | |
344 | 344 | | |
345 | 345 | | |
346 | | - | |
347 | 346 | | |
348 | 347 | | |
349 | 348 | | |
| |||
368 | 367 | | |
369 | 368 | | |
370 | 369 | | |
371 | | - | |
| 370 | + | |
372 | 371 | | |
373 | 372 | | |
374 | 373 | | |
| |||
385 | 384 | | |
386 | 385 | | |
387 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
388 | 392 | | |
389 | 393 | | |
390 | 394 | | |
| |||
478 | 482 | | |
479 | 483 | | |
480 | 484 | | |
481 | | - | |
| 485 | + | |
482 | 486 | | |
483 | 487 | | |
484 | 488 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
0 commit comments