-
Notifications
You must be signed in to change notification settings - Fork 20.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
miner: support custom block collation strategies #23421
Conversation
miner/default_collator.go
Outdated
headerView := bs.Header() | ||
for { | ||
// If we don't have enough gas for any further transactions then we're done | ||
available := headerView.GasLimit() - headerView.GasUsed() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's wrong to me. Since header is immutable, the GasUsed
should be modified at all and this check is meaningless.
miner/collator.go
Outdated
} | ||
|
||
// TODO can this error also be returned by commitTransaction below? | ||
_, err := tx.EffectiveGasTip(bs.env.header.BaseFee) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be checked by commitTransaction
, isn't it? https://github.com/ethereum/go-ethereum/blob/master/core/state_transition.go#L250
The goal with these shared contextual values for the given work cycle was to give the following properties:
But as I think about it, the implementation seems really hacky:
These are just my high-level thoughts about making the changes more intuitive. I started a refactor to make the changes in this PR more intuitive... but it's touching/changing so much of the miner worker that I really think I need to halt until we can do a review call for this. |
4f04a20
to
092b35a
Compare
4b28f32
to
721e2de
Compare
721e2de
to
403c31b
Compare
…with reverts (reverting first tx in the block panics)
09102df
to
0af653b
Compare
…. make the work-cycle become stale when the miner etherbase is set
…turning an rpc service
miner/default_collator.go
Outdated
|
||
// If mining is running resubmit a new work cycle periodically to pull in | ||
// higher priced transactions. Disable this overhead for pending blocks. | ||
if c.miner.IsRunning() && (chainConfig.Clique == nil || chainConfig.Clique.Period > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I expose this minerState
which exposes the chain config and a flag to see if the miner is running to the collator implementation. But I'm thinking for the sake of making the API clean, to remove the MinerState
and always do the recommit (eating the added overhead if the miner is not running).
Originally was thinking about the case of 0-period clique where you don't want to commit if there aren't any txs. But this detail should be abstracted away from the collator implementation.
… miner is running and what the consensus engine is
This was a good project, but ultimately did not gain the traction we had hoped -- having it be the base used for MEV so that MEV would not have to fork geth, but instead only build plugins. |
Yep |
depends on #23256.
This PR changes Geth's miner to allow for implementation of custom block collation strategies as Go plugins. A block collator receives empty pending blocks from the miner which it can fill with transactions from the pool (or another source), and commit to be the current sealing/pending block. Plugins can also register custom RPC methods.
Usage
./geth --miner.collator /path/to/plugin --miner.collatorconfig /path/to/custom/config.toml
See https://github.com/jwasinger/geth-mev-plugin for an example which re-implements https://github.com/flashbots/mev-geth miner changes as a plugin.
Collator Plugins
Collator plugins are Go plugins. Geth expects a plugin to export a plugin constructor method:
config
represents an optional custom plugin toml configuration file. ACollator
implements custom block-filling strategies:CollateBlocks
is a function that should run for the lifetime of the client (until it sees thatexitCh
is closed). It is invoked in its own go-routine. Every time a new empty pending block is created, it will appear for the collator to read fromblockCh
. TheBlockCollatorWork
object read fromblockCh
has an emptyBlockState
for constructing and committing new blocks for sealing as well as aContext
that the client will use to communicate when that block is stale due to the arrival of a new canonical chain head block. A block is constructed by adding transactions from the pool (or another custom source) to aBlockState
object and callingCommit
(which sets the block as a the currently-sealing block).CollateBlock
is the hook for post-merge proposal of a single block. The final call toCommit
on the passedBlockState
instance (or one of its copies) during the invocation ofCollateBlock
chooses the block that will be proposed. Post-merge,CollateBlocks
is used as a hook for receiving empty pending blocks. Post-merge, callingCommit
on theBlockState
instances passed to it is a no-op.The
BlockState
API allows for adding transactions to a block, inspecting the state between transactions, deep-copying, and aCommit
method.Custom Plugin RPC Methods
The plugin constructor can choose to register custom rpc methods using the given
node.Node
object'sRegisterAPIs
method.