Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/checkpoints-eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use {
fn main() -> eyre::Result<()> {
// This is the entry point of the payload building API. We construct a
// building context for a given block and attributes.
let (block, provider) = BlockContext::<Ethereum>::mocked();
let block = BlockContext::<Ethereum>::mocked();

// Next we progressively build the payload by creating checkpoints that have
// state mutations applied to them.
Expand All @@ -47,7 +47,8 @@ fn main() -> eyre::Result<()> {
// Checkpoints can be applied on top of each other, creating a progressive
// history of state changes.
let payload = start.apply(tx1)?.apply(bundle)?.apply(tx4)?;
let built_payload = Ethereum::build_payload(payload, &provider)
let built_payload = payload
.build_payload()
.expect("payload should be built successfully");

println!("{built_payload:#?}");
Expand Down
5 changes: 3 additions & 2 deletions examples/checkpoints-op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use {
fn main() -> eyre::Result<()> {
// This is the entry point of the payload building API. We construct a
// building context for a given block and attributes.
let (block, provider) = BlockContext::<Optimism>::mocked();
let block = BlockContext::<Optimism>::mocked();

// Next we progressively build the payload by creating checkpoints that have
// state mutations applied to them.
Expand All @@ -48,7 +48,8 @@ fn main() -> eyre::Result<()> {
// Checkpoints can be applied on top of each other, creating a progressive
// history of state changes.
let payload = start.apply(tx1)?.apply(bundle)?.apply(tx4)?;
let built_payload = Optimism::build_payload(payload, &provider)
let built_payload = payload
.build_payload()
.expect("payload should be built successfully");

println!("{built_payload:#?}");
Expand Down
14 changes: 8 additions & 6 deletions examples/custom-bundle-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use {
ethereum::primitives::SignedTransaction,
optimism::primitives::OpTransactionSigned,
primitives::Recovered,
providers::StateProvider,
revm::db::BundleState,
},
serde::{Deserialize, Serialize},
Expand Down Expand Up @@ -50,21 +51,20 @@ impl Platform for CustomPlatform {
)
}

fn build_payload<P, Provider>(
fn build_payload<P>(
payload: Checkpoint<P>,
provider: &Provider,
provider: &dyn StateProvider,
) -> Result<types::BuiltPayload<Self>, PayloadBuilderError>
where
P: traits::PlatformExecBounds<Self>,
Provider: traits::ProviderBounds<Self>,
{
Optimism::build_payload::<P, Provider>(payload, provider)
Optimism::build_payload::<P>(payload, provider)
}
}

fn main() -> eyre::Result<()> {
// Construct a mock build context for the custom platform.
let (block, provider) = BlockContext::<CustomPlatform>::mocked();
let block = BlockContext::<CustomPlatform>::mocked();

// begin building the payload by creating the first checkpoint for the block.
let start = block.start();
Expand Down Expand Up @@ -97,7 +97,9 @@ fn main() -> eyre::Result<()> {
))
));

let built_payload = CustomPlatform::build_payload(payload, &provider)
// build payload
let built_payload = payload
.build_payload()
.expect("payload should be built successfully");

println!("{built_payload:#?}");
Expand Down
9 changes: 9 additions & 0 deletions src/payload/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ impl<P: Platform> BlockContext<P> {
pub fn start(&self) -> Checkpoint<P> {
Checkpoint::new_at_block(self.clone())
}

/// Given a payload checkpoint, this method builds a new payload on top of
/// this block that is ready to be handed back to the CL client as a response
/// to the `ForkchoiceUpdated` request.
pub fn build_payload(
payload: &Checkpoint<P>,
) -> Result<types::BuiltPayload<P>, PayloadBuilderError> {
payload.build_payload()
}
}

struct BlockContextInner<P: Platform> {
Expand Down
9 changes: 9 additions & 0 deletions src/payload/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ impl<P: Platform> Checkpoint<P> {
pub fn barrier_with_tag(&self, tag: impl Into<Box<str>>) -> Self {
Self::apply_with(self, Mutation::Barrier, Some(tag.into()))
}

/// Given this checkpoint, this method builds a new payload on top of this
/// block base state that is ready to be handed back to the CL client as a
/// response to the `ForkchoiceUpdated` request.
pub fn build_payload(
&self,
) -> Result<types::BuiltPayload<P>, PayloadBuilderError> {
P::build_payload(self.clone(), self.block().base_state())
}
}

/// Internal API
Expand Down
11 changes: 4 additions & 7 deletions src/pipelines/exec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ impl<P: Platform, Provider: traits::ProviderBounds<P>>
// If there is no next step, we are done with the pipeline execution.
// We can finalize the pipeline and return the output as the final
// result of the pipeline run.
return Cursor::Finalizing(self.finalize(
P::build_payload(input, self.service.provider()).map_err(Arc::new),
));
return Cursor::Finalizing(
self.finalize(input.build_payload().map_err(Arc::new)),
);
};

// there is a next step to be executed, create a cursor that will
Expand All @@ -215,10 +215,7 @@ impl<P: Platform, Provider: traits::ProviderBounds<P>>
);

return Cursor::<P>::Finalizing(
self.finalize(
P::build_payload(self.block.start(), self.service.provider())
.map_err(Arc::new),
),
self.finalize(self.block.start().build_payload().map_err(Arc::new)),
);
};

Expand Down
Loading
Loading