feat: add BuilderTransactions abstraction for end of block builder txs - #935
Open
MavenRain wants to merge 1 commit into
Open
feat: add BuilderTransactions abstraction for end of block builder txs#935MavenRain wants to merge 1 commit into
MavenRain wants to merge 1 commit into
Conversation
Adds a trait for the transactions the builder appends at the end of the block, with a validation and block space reservation hook that runs before building and a hook returning the txs at finalization. Implementations are registered per block with BlockBuildingContext::with_builder_transactions and are committed after the accumulated refunds and before the proposer payout tx, which stays the last tx of the block. The space they reserve is held back for the whole build and is included in the true block value deduction, so the bid ceiling accounts for the gas those txs burn. Closes flashbots#343 Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
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.
Summary
Closes #343. Adds
BuilderTransactions, a trait for the transactions the builder itself appends at the end of the block, with the two phases the issue asks for: validation plus block space reservation before building, and the list of txs to include after building.Problem
Everything the builder adds for itself is hardcoded today.
create_payout_txhas exactly three production call sites (the combined refunds, the proposer payout, the per-bundle kickback) and the space for them is reserved in one place inBlockBuildingHelperFromProvider::new_with_execution_tracer. There is no way for a builder to add a block signature, an attestation or any other tx of its own without editing the finalization path, and no way to make sure the block keeps room for it.Fix
crates/rbuilder/src/building/builder_tx.rsadds:BuilderTransactions:validateandreserve_block_spacerun once before building, on the state of the parent block;transactionsruns at finalization and returns the signed txs to append.BuilderTransactionError, named after the equivalent type in op-rbuilder'sbuilder_tx.rsso the two builders read the same way.reserve_builder_txs_block_space, which validates every registered source and folds their reservations, passing the running total so a source can fit itself into the remaining budget.Sources are registered per block with
BlockBuildingContext::with_builder_transactions. Carrying them on the context rather than onBlockBuildingHelperfollows the existingArc<dyn RootHasher>precedent and leaves the helper trait, both of its test doubles and everydyn BlockBuildingHelpercall site untouched.Two behaviors are worth calling out:
BuilderTransactions. It has to stay the last tx of the block (PartialBlock::finalizeexpects it there,ReceiptsData::pre_payment_logs_bloomis defined as the bloom of everything before it, bid adjustments indexlen - 1, and backtests infer the fee recipient from the last tx) and its value is only known once the bid is chosen. Builder txs are inserted before it.!adjust_finalized_block, so a finalization adjustment re-executes only the payout tx and leaves them untouched. Letting a builder tx depend on the payout value would mean generalizingFinalizeRevertStateCurrentIterationto an N-tx tail and teaching the receipts and tx-root caches about it; that is a much larger change and is not attempted here.The reserved gas also widens the
true_block_valuededuction, because the bid ceiling is read before finalization and the builder pays for its own txs. With no sources registered,end_of_block_gas == payout_tx_gasand the whole path is a no-op.Testing
cargo test -p rbuilder --lib builder_tx, covering: only the payout tx lands when nothing is registered; builder txs land before the payout tx with consecutive nonces and the payout stays last; a reseal reverts and rebuilds only the payout tx while the builder txs survive; a tx that cannot fit fails the block; space and value reservations are summed and chained; a failed validation aborts before any reservation. The payout test harness now funds the builder signer and can build an EOA fee recipient, which is what makes committing real end-of-block txs in a unit test possible.Note for reviewers
Where the validation hook should be used first is #296 / #929 (checking the coinbase can cover the payout before building). I did not move that check in here to keep this PR to the abstraction itself; happy to fold it in as a
BuilderTransactionsimpl in a follow-up, or to rebase this on top of that PR if it lands first.