foundry icon indicating copy to clipboard operation
foundry copied to clipboard

forge script: "Could not instantiate forked environment with fork url" --rpc-url to local anvil chain

Open Tenari opened this issue 1 year ago • 2 comments

Component

Forge

Have you ensured that all of these are up to date?

  • [X] Foundry
  • [X] Foundryup

What version of Foundry are you on?

forge 0.2.0 (54d8510 2024-05-20T00:19:01.949744889Z)

What command(s) is the bug in?

forge script

Operating System

Windows

Describe the bug

fresh install on new(to me) setup. using WSL ubuntu. do foundryup, everything is good. start an anvil local chain, it spins up nicely.

Genesis Timestamp
==================

1716225685

Listening on 127.0.0.1:8545
eth_blockNumber
Anvil is ready on port 8545.

then I go to run my deploy script with forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545

get strange error I have never seen before when running this same script against local anvil on a different computer I have.

[⠊] Compiling...
[⠔] Compiling 35 files with Solc 0.8.25
[⠒] Solc 0.8.25 finished in 1.37s
Compiler run successful!
2024-05-20T17:21:29.426517Z ERROR foundry_evm_core::fork::init: It looks like you're trying to fork from an older block with a non-archive node which is not supported. Please try to change your RPC url to an archive node if the issue persists.
Error:
Could not instantiate forked environment with fork url: http://localhost:8545

Context:
- Failed to get block for block number: 12
latest block number: 12

I am not sure what an "archive node" is, and didn't see any mention of it on https://book.getfoundry.sh/reference/anvil/ tried explicitly passing various --fork-block-number, which didn't really change much. tried googling, and looked through the issues here. I see nothing. tried installing an earlier commit of foundry with foundryup -C 63fff3510408b552f11efb8196f48cfe6c1da664 and got same results. tried logging within my Deploy.s.sol, but none of the logs were ever hit, which leads me to believe it is happening at some earlier layer of code I didn't write. perhaps something in here?

import { Script } from "forge-std/Script.sol";

I'm happy to provide more information if needed.

Tenari avatar May 20 '24 17:05 Tenari

more digging seems to show that it's from anvil being started with --load-state option which seems to fail on the particular serialized state I'm using

Tenari avatar May 20 '24 19:05 Tenari

bump, I think related to this: https://github.com/foundry-rs/foundry/issues/7502

barraguda avatar May 20 '24 19:05 barraguda

Marking as resolved by #7502, unrelated to forge.

Feel free to re-open if you run into this again.

zerosnacks avatar Jun 27 '24 11:06 zerosnacks

Met the same error using anvil 0.2.0 (7f0f5b4 2024-08-08T00:19:27.666925503Z).

2024-08-21T09:12:38.474298Z ERROR foundry_evm_core::fork::init: It looks like you're trying to fork from an older block with a non-archive node which is not supported. Please try to change your RPC url to an archive node if the issue persists.

yiweichi avatar Aug 21 '24 09:08 yiweichi