Repository navigation
feat(firehose): add a post-block hook for state changes outside the EVM - #98
Closed
valvecitydev wants to merge 1 commit into
Closed
valvecitydev wants to merge 1 commit into
valvecitydev wants to merge 1 commit into
Conversation
Some chains change state in the block executor's finish, outside the EVM, where the Firehose inspector cannot see it. PostTxExtras gains capture_post_block, which runs before the inner finish and returns a PostBlockChanges. The wrapper emits it after the inner finish, after the withdrawal balance changes. The default captures nothing, so Ethereum output does not change. FirehoseEvmConfig<F> now uses F's hooks instead of the no-op ones: on the engine path through FirehoseLiveHooks, and on the pipeline path through a new LiveChainHooks for its batch executor. Before, a chain that wrapped its EVM configuration in FirehoseEvmConfig lost its hooks.
Author
|
Thanks @maoueh for carrying this forward in #108 with the block context follow-up. Closing in favour of it. I have added you and @UlysseCorbeil as collaborators on valvecitydev/reth, so you can push to our PR branches directly next time. |
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.
Some chains change state in the block executor's
finish, outside the EVM. The Firehose inspector cannot see those writes.FirehoseWrappedExecutoralready hasPreTxAdjustandPostTxExtrasfor gaps around each transaction. This PR adds the same kind of hook at the block level, and makesFirehoseEvmConfig<F>keep the hooks of the configuration it wraps.The hook
PostTxExtrasgainscapture_post_block(&self, evm, block_number, chain_id) -> Option<Box<dyn PostBlockChanges>>. The wrapper calls it before the inner finish, soevmreads the state after the block's last transaction. The wrapper then callsPostBlockChanges::emit(tracer, state)after the inner finish and after the withdrawal balance changes, with the finalBundleState. The default returnsNone, so Ethereum output does not change.BlockFeesnow carries the block number for this call.We need this hook for PulseChain's PrimordialPulse fork block, which credits balances and replaces a contract in
finish. With the hook, that code lives in our PulseChain crate, andreth-firehosekeeps no chain-specific code.Hooks of the wrapped configuration
Before this PR,
FirehoseEvmConfig<F>always usedNoPreTxAdjustandNoPostTxExtras, on both paths. A chain that wrapped its EVM configuration inFirehoseEvmConfigtherefore lost its hooks without an error. Now:FirehoseLiveHooks for FirehoseEvmConfig<F>usesF::PreTxAdjustandF::PostTxExtras(engine path).FirehoseEvmConfig::batch_executoruses a newLiveChainHooks, aChainHooksthat installs the hooksFselects throughFirehoseLiveHooks(pipeline path).ConfigureEvm for FirehoseEvmConfig<F>now requiresF: FirehoseLiveHooks.EthEvmConfig,NoopEvmConfigand thereth-bbconfiguration already implement it.Tests
crates/firehose-tests/tests/post_block_hook.rs(new test binary, process-wide tracer) defines a test EVM configuration with its own hooks. ItsPostTxExtrasmarks each transaction with a balance change, and itscapture_post_blockrecords an account's balance before finish and reports that account's change across finish. The test runs thenop_transferblock with one added withdrawal to that account throughFirehoseEvmConfig::batch_executorandexecute_and_trace_one. It checks that:FirehoseEvmConfig<TestEvmConfig>selects the test configuration'sPostTxExtrastype for the engine path.Fail before, pass after. On
release/reth-2.xthe test does not compile (nocapture_post_block, noPostBlockChanges). With only the hook parts of the test removed, it fails onrelease/reth-2.xat the type check (left: TypeId(..) right: TypeId(..)). With the type check also removed, it fails with "the post-transaction hook did not run". With this PR, it passes. Allreth-firehoseandreth-firehose-teststests pass.cargo checkpasses forreth-engine-tree --tests,reth-node-ethereum --testsandreth --no-default-features.Notes
cargo clippy -p reth-firehose -p reth-firehose-tests --all-targets -- -D warningsfails onrelease/reth-2.xalready, on lines this PR does not touch (doc_markdown,missing_const_for_fn,use_self,if_then_some_else_none,clone_on_copy,double_ended_iterator_last,ptr_arg). With those lints allowed, clippy is clean.This PR and the pre-Merge reward PR both change the two
finish_*methods ofFirehoseWrappedExecutorand addBlockFees::block_number. Whichever lands second needs a small rebase. The intended order of block-level changes is withdrawals, then pre-Merge rewards, then the chain's post-block changes.A design question for you: the hook returns a boxed trait object, so a chain can capture any shape of state without a new associated type on
PostTxExtras. If you prefer an associated type, I can change it.