-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from worldcoin/world-chain-builder
feat(wc-builder): Implement initial `WorldChainBuilder` logic
- Loading branch information
Showing
6 changed files
with
230 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use reth_basic_payload_builder::{ | ||
BuildArguments, BuildOutcome, MissingPayloadBehaviour, PayloadBuilder, PayloadConfig, | ||
}; | ||
use reth_evm::ConfigureEvm; | ||
use reth_node_optimism::{OptimismBuiltPayload, OptimismPayloadBuilderAttributes}; | ||
use reth_payload_builder::error::PayloadBuilderError; | ||
use reth_provider::StateProviderFactory; | ||
use reth_transaction_pool::TransactionPool; | ||
|
||
/// Priority blockspace for humans builder | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct PBHBuilder<EvmConfig> { | ||
// NOTE: do we need this? | ||
// compute_pending_block: bool, | ||
evm_config: EvmConfig, | ||
} | ||
|
||
impl<EvmConfig> PBHBuilder<EvmConfig> { | ||
/// `OptimismPayloadBuilder` constructor. | ||
pub const fn new(evm_config: EvmConfig) -> Self { | ||
Self { evm_config } | ||
} | ||
} | ||
|
||
/// Implementation of the [`PayloadBuilder`] trait for [`PBHBuilder`]. | ||
impl<Pool, Client, EvmConfig> PayloadBuilder<Pool, Client> for PBHBuilder<EvmConfig> | ||
where | ||
Client: StateProviderFactory, | ||
Pool: TransactionPool, | ||
EvmConfig: ConfigureEvm, | ||
{ | ||
type Attributes = OptimismPayloadBuilderAttributes; | ||
type BuiltPayload = OptimismBuiltPayload; | ||
|
||
fn try_build( | ||
&self, | ||
args: BuildArguments<Pool, Client, OptimismPayloadBuilderAttributes, OptimismBuiltPayload>, | ||
) -> Result<BuildOutcome<OptimismBuiltPayload>, PayloadBuilderError> { | ||
todo!() | ||
} | ||
|
||
fn on_missing_payload( | ||
&self, | ||
_args: BuildArguments<Pool, Client, OptimismPayloadBuilderAttributes, OptimismBuiltPayload>, | ||
) -> MissingPayloadBehaviour<Self::BuiltPayload> { | ||
MissingPayloadBehaviour::AwaitInProgress | ||
} | ||
|
||
fn build_empty_payload( | ||
&self, | ||
client: &Client, | ||
config: PayloadConfig<Self::Attributes>, | ||
) -> Result<OptimismBuiltPayload, PayloadBuilderError> { | ||
todo!() | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod builder; | ||
pub mod node; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,152 @@ | ||
use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig}; | ||
use reth_chainspec::ChainSpec; | ||
use reth_evm::ConfigureEvm; | ||
use reth_node_builder::{ | ||
components::{ComponentsBuilder, PayloadServiceBuilder}, | ||
BuilderContext, FullNodeTypes, Node, NodeTypes, NodeTypesWithEngine, PayloadBuilderConfig, | ||
}; | ||
use reth_node_optimism::{ | ||
args::RollupArgs, | ||
node::{ | ||
OptimismAddOns, OptimismConsensusBuilder, OptimismExecutorBuilder, OptimismNetworkBuilder, | ||
OptimismPoolBuilder, | ||
}, | ||
OptimismEngineTypes, OptimismEvmConfig, | ||
}; | ||
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService}; | ||
use reth_provider::CanonStateSubscriptions; | ||
use reth_transaction_pool::TransactionPool; | ||
|
||
use crate::builder::PBHBuilder; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct WorldChainBuilder { | ||
/// Additional Optimism args | ||
pub args: RollupArgs, | ||
} | ||
|
||
impl WorldChainBuilder { | ||
pub const fn new(args: RollupArgs) -> Self { | ||
Self { args } | ||
} | ||
|
||
/// Returns the components for the given [`RollupArgs`]. | ||
pub fn components<Node>( | ||
args: RollupArgs, | ||
) -> ComponentsBuilder< | ||
Node, | ||
OptimismPoolBuilder, | ||
WorldChainPayloadBuilder, | ||
OptimismNetworkBuilder, | ||
OptimismExecutorBuilder, | ||
OptimismConsensusBuilder, | ||
> | ||
where | ||
Node: FullNodeTypes< | ||
Types: NodeTypesWithEngine<Engine = OptimismEngineTypes, ChainSpec = ChainSpec>, | ||
>, | ||
{ | ||
let RollupArgs { | ||
disable_txpool_gossip, | ||
compute_pending_block, | ||
discovery_v4, | ||
.. | ||
} = args; | ||
ComponentsBuilder::default() | ||
.node_types::<Node>() | ||
.pool(OptimismPoolBuilder::default()) | ||
.payload(WorldChainPayloadBuilder::new(OptimismEvmConfig::default())) | ||
.network(OptimismNetworkBuilder { | ||
disable_txpool_gossip, | ||
disable_discovery_v4: !discovery_v4, | ||
}) | ||
.executor(OptimismExecutorBuilder::default()) | ||
.consensus(OptimismConsensusBuilder::default()) | ||
} | ||
} | ||
|
||
impl<N> Node<N> for WorldChainBuilder | ||
where | ||
N: FullNodeTypes< | ||
Types: NodeTypesWithEngine<Engine = OptimismEngineTypes, ChainSpec = ChainSpec>, | ||
>, | ||
{ | ||
type ComponentsBuilder = ComponentsBuilder< | ||
N, | ||
OptimismPoolBuilder, | ||
WorldChainPayloadBuilder, | ||
OptimismNetworkBuilder, | ||
OptimismExecutorBuilder, | ||
OptimismConsensusBuilder, | ||
>; | ||
|
||
type AddOns = OptimismAddOns; | ||
|
||
fn components_builder(&self) -> Self::ComponentsBuilder { | ||
let Self { args } = self; | ||
Self::components(args.clone()) | ||
} | ||
} | ||
|
||
impl NodeTypes for WorldChainBuilder { | ||
type Primitives = (); | ||
type ChainSpec = ChainSpec; | ||
} | ||
|
||
impl NodeTypesWithEngine for WorldChainBuilder { | ||
type Engine = OptimismEngineTypes; | ||
} | ||
|
||
#[derive(Debug, Default, Clone)] | ||
pub struct WorldChainPayloadBuilder {} | ||
pub struct WorldChainPayloadBuilder<EVM = OptimismEvmConfig> { | ||
/// The EVM configuration to use for the payload builder. | ||
pub evm_config: EVM, | ||
} | ||
|
||
impl<EVM> WorldChainPayloadBuilder<EVM> { | ||
pub const fn new(evm_config: EVM) -> Self { | ||
Self { evm_config } | ||
} | ||
} | ||
|
||
impl<Node, EVM, Pool> PayloadServiceBuilder<Node, Pool> for WorldChainPayloadBuilder<EVM> | ||
where | ||
Node: FullNodeTypes< | ||
Types: NodeTypesWithEngine<Engine = OptimismEngineTypes, ChainSpec = ChainSpec>, | ||
>, | ||
Pool: TransactionPool + Unpin + 'static, | ||
EVM: ConfigureEvm, | ||
{ | ||
async fn spawn_payload_service( | ||
self, | ||
ctx: &BuilderContext<Node>, | ||
pool: Pool, | ||
) -> eyre::Result<PayloadBuilderHandle<OptimismEngineTypes>> { | ||
let payload_builder = PBHBuilder::new(self.evm_config); | ||
|
||
let conf = ctx.payload_builder_config(); | ||
|
||
let payload_job_config = BasicPayloadJobGeneratorConfig::default() | ||
.interval(conf.interval()) | ||
.deadline(conf.deadline()) | ||
.max_payload_tasks(conf.max_payload_tasks()) | ||
// no extradata for OP | ||
.extradata(Default::default()); | ||
|
||
let payload_generator = BasicPayloadJobGenerator::with_builder( | ||
ctx.provider().clone(), | ||
pool, | ||
ctx.task_executor().clone(), | ||
payload_job_config, | ||
ctx.chain_spec(), | ||
payload_builder, | ||
); | ||
let (payload_service, payload_builder) = | ||
PayloadBuilderService::new(payload_generator, ctx.provider().canonical_state_stream()); | ||
|
||
ctx.task_executor() | ||
.spawn_critical("payload builder service", Box::pin(payload_service)); | ||
|
||
Ok(payload_builder) | ||
} | ||
} |