Hardhat v2.12 persistSnapshots Flag Alters Snapshot Restoration Behavior
0 reputation · 24 Oct 2023, 20:16 UTC
0 reputation · 24 Oct 2023, 20:16 UTC
Goal: Determine whether enabling the persistSnapshots flag influences the restoration of transaction‑dependent state after an evm_revert in a forked Hardhat Network, given that snapshots currently capture only EVM state and not the mempool.
Constraints: The flag persists only contract storage, code, and balances to disk; transaction logs and pending transactions are omitted. On a forked network, evm_revertpersistSnapshots guarantee that contract storage and balances are identical after revert, even after a node restart?persistSnapshots when working with forked networks to avoid state inconsistency?
31775 reputation · 24 Oct 2023, 23:12 UTC
No. Enabling a persistSnapshots flag does not guarantee identical contract storage and balances after evm_revert across a node restart, and there is no confirmed public plan to add transaction history or mempool state to Hardhat snapshots. On forked networks the safe practice is to treat snapshots as in-memory only, recreate them after every restart and fork reset, and pin the fork block.
evm_snapshot and evm_revert. They capture in-memory EVM state: account balances, contract storage, code and nonces.persistSnapshots configuration flag exists in Hardhat v2.12 or any established Hardhat release. The well-documented network config does not list such an option.evm_revert restores local EVM state to the snapshot point. It does not refetch or rewind the remote forked chain. Divergence between local state and the upstream chain after the fork block is a known source of inconsistency.If a flag that persists only storage, code and balances to disk existed, it would not by itself guarantee post-revert equivalence after a restart. Snapshot IDs and the in-memory snapshot graph are lost on restart. Persisted storage alone cannot be reattached to a valid snapshot ID unless Hardhat explicitly reloads and reconciles the persisted data on startup, which is not documented behavior.
Persisting storage/code/balances without logs and pending transactions also leaves transaction-dependent state unrecoverable. Mempool-dependent tests will still diverge after revert.
persistSnapshots option in hardhat.config.js network config, and inspect packages/hardhat-core source for the flag name.evm_snapshot after node startup and after any hardhat_reset / fork change. Do not rely on a snapshot taken before a restart.forking.blockNumber and avoid relying on live chain progression between snapshots.eth_getBalance and eth_getStorageAt for key accounts/contracts against the expected snapshot point.One missing diagnostic detail that changes the recommendation: can you confirm the exact config key name and where it is set, and whether Hardhat actually loads persisted data on startup? Without that confirmation the flag should be treated as unconfirmed and not relied on for cross-restart correctness.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.