feat(evm): bind Monad's journal state to ContextTr::Journal - #16262
Merged
Conversation
Introduces ContextUpdateFor<F>, a type alias that resolves to ContextUpdate<F::ChainContext> under the monad feature and to PhantomData<F> otherwise, so DatabaseExt's fork-switching methods keep one signature while the ContextUpdate enum, its construction sites, and the block-position helpers that exclusively serve it become dead code eliminated at compile time for non-Monad builds. Consumption is centralized in a small apply_context_update helper local to evm/fork.rs, co-located with its two callers, instead of duplicating the Unchanged/Replace/Rebase match at each call site.
FoundryEvmFactory/NestedEvm carried a bespoke ChainContext associated type plus capture/apply methods that only Monad ever implemented meaningfully. revm already exposes an unconstrained Chain slot on ContextTr with free chain()/chain_mut() accessors, and monad-revm already plugs MonadChainContext directly into it. Add FoundryChain, a marker trait bound on ContextTr::Chain (mirroring FoundryBlock/FoundryTransaction), and a refresh_chain_dependent_state hook on FoundryContextExt, default no-op, overridden only in Monad's existing concrete FoundryContextExt impl to rebase its reserve-balance tracker. Every call site now reads/writes the chain field directly and calls the hook unconditionally instead of going through a monad cfg gate from every one of those call sites. Rename FoundryEvmFactory::ChainContext and NestedEvm::ChainContext to Chain, and the ChainContextFor<FEN> alias to ChainFor<FEN>, matching revm's own naming. FoundryChain only needs Clone + Debug + Default + Send + Sync; 'static is not required by anything in the workspace. Optimism's revm context already uses ContextTr::Chain for L1BlockInfo, unrelated to Foundry's abstraction; OpEvmFactory::Chain is updated to match reality instead of claiming ().
Introduce FoundryJournal, mirroring FoundryChain, so the reserve-balance tracker Monad needs is reached through revm's native journal() / journal_mut() accessors instead of bespoke capture/restore methods on FoundryEvmFactory and NestedEvm. The tracker methods are concrete (ReserveBalanceTracker) and individually feature-gated, so no Monad-only associated type or method remains on those generic traits.
mablr
requested review from
0xrusowsky,
DaniPopes,
figtracer,
grandizzy,
mattsse and
stevencartavia
as code owners
August 19, 2026 17:58
Contributor
✅ Changelog foundThe deterministic check will validate the changed entry. |
stevencartavia
previously approved these changes
Aug 19, 2026
mablr
dismissed stale reviews from stevencartavia and mattsse
August 19, 2026 19:18
The base branch was changed.
stevencartavia
approved these changes
Aug 19, 2026
ContextTr::Journal
figtracer
approved these changes
Aug 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #16257.
FoundryEvmFactory/NestedEvmstill carried aTransactionStateassociated type pluscapture_transaction_state,restore_transaction_state,preserve_transaction_state_on_next_transactionmethods that only Monad implements meaningfully, the same shape of leak #16257 already fixed for chain context.monad-revm'sMonadJournal<DB>already wraps revm'sJournal<DB>and exposes its reserve-balance tracker throughMonadJournalTr, so this state doesn't need a bespoke side-channel: it's reachable through revm's nativeContextTr::journal/journal_mut.This adds
FoundryJournal, reached the same wayFoundryChainreaches chain context. Unlike chain context, the reserve-balance tracker only exists on Monad's journal type, so its methods are concrete (ReserveBalanceTracker) and individually#[cfg(feature = "monad")]-gated rather than generic over an associated type.NestedEvmgains a
Journal: FoundryJournalassociated type and ajournal_mut()accessor, and arefresh_chain_dependent_state()hook (mirroring the one already onFoundryContextExt) to preserve the rebase-on-restore behavior the old bundledrestore_transaction_stateprovided.
BlockContext<FEN>/NEEDS_BLOCK_CONTEXTare unaffected and remain a separate, later scoping effort.PR implementation was assisted by AI.