erigon icon indicating copy to clipboard operation
erigon copied to clipboard

Ephemeral local fork mode

Open banteg opened this issue 4 years ago • 11 comments
trafficstars

Rationale

A very common pattern (1, 2) for testing contract integrations is to run them against a forked mainnet environment using ganache-cli, hardhat or hevm. It would be useful to have this functionality built in the client itself as it would work much faster and would follow consensus rules more precisely.

Implementation

Similarly to rpcdaemon, a process could connect to the existing database, and maintain an ephemeral overlay database on top.

Additionally, it'll need to support ability to control chain state, advance time and unlock arbitrary accounts. Hardhat and ganache-cli use custom RPC methods and hevm uses cheat codes.

banteg avatar Mar 26 '21 17:03 banteg

Maintaining ephemeral database while still staying in sync with the mainnet is going to require opening a long-lived read-transaction, and cause a rapid database bloat. However, such ephemeral database would be possible if turbo-geth stopped being in sync with the mainnet and just "froze" itself. Then, only ephemeral part will grow, until it is discarded, at which point turbo-geth proceeds with catching up again

AlexeyAkhunov avatar Mar 26 '21 19:03 AlexeyAkhunov

@AlexeyAkhunov 1. We don’t need transaction if can use GetAsOf 2. Does this require writable ephemeral overlay?

AskAlexSharov avatar Mar 27 '21 02:03 AskAlexSharov

@AskAlexSharov As far as I understand, the overlay is indeed writable. Yes, I think you are right, we could use GetAsOf to create an appearance of a fork without a long-running read transaction

AlexeyAkhunov avatar Mar 27 '21 06:03 AlexeyAkhunov

Hi @AlexeyAkhunov @banteg @AskAlexSharov , was there any further discussion about supporting mainnet forks in the client? Or is it shelved for now?

kushalbabel avatar Feb 18 '22 08:02 kushalbabel

Would also like to know if this is a planned feature. Existing fork modes are comparatively very slow.

riordant avatar Apr 07 '22 09:04 riordant

@AlexeyAkhunov @banteg

such ephemeral database would be possible if turbo-geth stopped being in sync with the mainnet and just "froze" itself

isn't that how existing forks work? they freeze the DB, sync tx pool and mine on their own.

mandrigin avatar Jul 05 '22 16:07 mandrigin

I agree it could be a very cool feature, if we can piggy-back on our dev network

mandrigin avatar Jul 05 '22 16:07 mandrigin

@mandrigin FYI:

  1. our mining now doesn't use dbRwTransaction, it using only "mutation" object. FunnyGiulio worked on this feature. Maybe 1. can be used for this feature (if don't need store ephemeral fork in db

AskAlexSharov avatar Jul 06 '22 02:07 AskAlexSharov

could be, @banteg do you need this to be persistent across Erigon launches?

mandrigin avatar Jul 06 '22 08:07 mandrigin

+1 this would be helpful.

At least from my limited point of view, stateless ephemeral forks would be a good first step.

mrkshields avatar Aug 05 '22 23:08 mrkshields

+1 this would be helpful.

At least from my limited point of view, stateless ephemeral forks would be a good first step.

This is the only viable method in reality.

sambacha avatar Aug 08 '22 10:08 sambacha

This would be a fantastic feature. Tools like tx2uml require transaction traces like traceTransaction and debug_traceTransaction. For value transfer diagrams, tx2uml uses debug_traceTransaction with a custom EVM tracer. This is not currently supported by Foundry's Anvil, Hardhat or Ganache. Ideally, Erigon could be run in fork mode locally and transaction traces run against the local node.

naddison36 avatar Mar 06 '23 07:03 naddison36

This issue is stale because it has been open for 40 days with no activity. Remove stale label or comment, or this will be closed in 7 days.

github-actions[bot] avatar Sep 11 '23 02:09 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Sep 19 '23 02:09 github-actions[bot]