Repository navigation
test: Fork Hyperliquid behind its latest block in the simulator tests - #1624
Conversation
Three suites fork the public Hyperliquid RPC at its latest block in setUp. Now and then the fork fails with "invalid block height": the RPC is served by more than one node, and the one asked for the latest block had not yet received it. The block rejected on #1623 carries the timestamp of the second the tests ran in. That has failed EVM Tests on unrelated pull requests, twice in one day. Ask for the latest block number and fork ten blocks before it. Blocks come about a second apart, so every node has a block that old. The tests still fail if the RPC is down. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Paul <108695806+pxrl@users.noreply.github.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
droplet-rl
left a comment
There was a problem hiding this comment.
LGTM. The fix matches the failure. When createSelectFork(url) is given no block, it calls eth_blockNumber and then eth_getBlockByNumber, and those two calls can reach different nodes. Pinning the fork ten blocks back closes that gap, and it doesn't add an RPC round-trip: it's still one eth_blockNumber plus one block fetch per setUp.
What I checked:
- Decoding on the pinned Foundry (1.7.1,
.foundry-version).vm.rpctakes the hex string, left-pads odd-length values with0, and returns it as rawbytes. Lengths 20 and 32 becomeAddress/FixedBytesand then go throughconvert_to_bytes, so they come back as raw bytes too. The shift handles every length up to 32. An empty result would underflow and fail loudly, which is fine. - Historical state on the public RPC.
rpc.hyperliquid.xyz/evmreturnedeth_getStorageAtandeth_getBalanceatlatest - 10. A pinned fork needs that, and it works. - RPC disk cache. It doesn't change. In 1.7.1, cheatcode forks cache by the resolved block number whether or not a block is pinned.
- Simulator reads.
PrecompileSimandRealL1Readstilleth_callHyperCore precompiles at"latest", so they now run about 10 s ahead of the forked EVM state. That skew already grew over a test run, and nothing in the simulator depends on wall-clock alignment, so I don't see a problem. - Tests.
forge teston the three suites (HyperCoreFlowExecutor,SponsoredDirectFlow,SponsorredCCTPDstPeriphery) with Foundry 1.7.1: 53 passed, 0 failed. I didn't try to reproduce the original flake. CI'sEVM Testswas still pending when I submitted this.
One optional readability nit is inline.
| // The result is the block number as the bytes of its hex digits: 0x3276a83 comes back as 03276a83. | ||
| bytes memory latest = vm.rpc(hyperliquidRpc, "eth_blockNumber", "[]"); | ||
| uint256 latestBlock = uint256(bytes32(latest)) >> (8 * (32 - latest.length)); |
There was a problem hiding this comment.
Nit, optional: vm.parseUint(vm.toString(latest)) gives the same number, and you could drop the shift and its comment. I compared the two against the live RPC on Foundry 1.7.1 and both returned 52916136.
uint256 latestBlock = vm.parseUint(vm.toString(vm.rpc(hyperliquidRpc, "eth_blockNumber", "[]")));The current code is correct, so this is only about readability.
There was a problem hiding this comment.
Taken in aaf4cdd: the block number is parsed with vm.parseUint(vm.toString(...)), and the shift and its comment are gone.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Paul <108695806+pxrl@users.noreply.github.com>
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
droplet-rl
left a comment
There was a problem hiding this comment.
Re-approving after aaf4cdd. That commit only replaces the byte-shift parse with vm.parseUint(vm.toString(vm.rpc(...))), which addresses my earlier nit. Nothing else changed since my first approval.
I reran the three forked suites on the new head with the pinned Foundry 1.7.1: 53 passed, 0 failed. If the RPC returns an empty or malformed result, the test still fails loudly, either in parseUint or on the - FORK_BLOCKS_BEHIND underflow. Everything else from my first review still holds: vm.rpc decoding, the public RPC serving state at latest - 10, and the precompile "latest" reads.
I haven't checked:
- CI
EVM Testson aaf4cdd, which was still pending when I submitted this. - The original intermittent failure, which I didn't reproduce.
As the description says, this is vendored code, so it will need reapplying if hyper-evm-lib is re-synced from upstream.
Stops a flaky failure in "EVM Tests" that has hit unrelated pull requests twice in one day (#1622 and #1623).
The failure. Three suites (
HyperCoreFlowExecutorTest,CCTPDirectFlowTest,SponsoredCCTPDstPeripheryTest) share asetUpthat forks the public Hyperliquid RPC at its latest block. Now and then the fork fails:The RPC is served by more than one node. A fork asks for the latest block number and then for that block, and the node that got the second request had not yet received it. The block rejected on #1623 carries the timestamp of the second the tests ran in.
The fix.
setUpasks for the latest block number and forks ten blocks before it. Blocks come about a second apart, so every node has a block that old.test/evm/foundry/local/external/hyper-evm-lib/test/BaseSimulatorTest.sol. It is vendored, so this diverges from upstream.🤖 Generated with Claude Code