Skip to content
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

[WIP] Stream best blocks to the relay instead of pushing them #277

Draft
wants to merge 27 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
712a668
add best block store
SkandaBhat Dec 10, 2024
f949cd7
Merge branch 'develop' of github.com:SkandaBhat/rbuilder into develop
SkandaBhat Dec 10, 2024
d8e7000
Create global best block store with a specified buffer size or default
SkandaBhat Dec 10, 2024
185e13d
add tracker to track and update best blocks
SkandaBhat Dec 10, 2024
33c0e73
update dummy builder to use tracker
SkandaBhat Dec 10, 2024
30b113d
Update builders to use tracker
SkandaBhat Dec 10, 2024
7d6a08d
update bidders with tracker
SkandaBhat Dec 10, 2024
b1bb3e9
update relay submit
SkandaBhat Dec 10, 2024
eb476de
create block storage and initialise in live_builder
SkandaBhat Dec 10, 2024
ab1abb7
support block store in transaction-pool-bundle-ext
SkandaBhat Dec 10, 2024
782023a
cleanup comments
SkandaBhat Dec 10, 2024
cbb1d5e
refactor BlockBuildingSink to RelayCoordinator
SkandaBhat Dec 10, 2024
f5f1b52
refactor tests to avoid duplication
SkandaBhat Dec 10, 2024
b413745
cleanup relay_submit
SkandaBhat Dec 10, 2024
1085840
fmt
SkandaBhat Dec 10, 2024
518d67d
return a future to take_until
SkandaBhat Dec 10, 2024
82f3d82
fmt
SkandaBhat Dec 10, 2024
be9b818
fix: store doesnt store the first block
SkandaBhat Dec 11, 2024
d366faa
init store much later downstream, removing the need for async
SkandaBhat Dec 11, 2024
d49ed90
Further remove async throughout
SkandaBhat Dec 11, 2024
57dd60d
fmt
SkandaBhat Dec 11, 2024
605e3fc
fix try_and_update usage
SkandaBhat Dec 11, 2024
0a1615d
fmt
SkandaBhat Dec 11, 2024
22b912d
cleanup
SkandaBhat Dec 11, 2024
6446e08
Fix tests
SkandaBhat Dec 11, 2024
e4a5ca5
Create scope to make fn atomic
SkandaBhat Dec 13, 2024
a36b84a
Make global best block store specific to bidder, reducing diff
SkandaBhat Dec 13, 2024
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
33 changes: 27 additions & 6 deletions crates/rbuilder/src/bin/dummy-builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
//! This is NOT intended to be run in production so it has no nice configuration, poor error checking and some hardcoded values.
use std::{path::PathBuf, sync::Arc, thread::sleep, time::Duration};

use alloy_primitives::U256;
use jsonrpsee::RpcModule;
use rbuilder::{
beacon_api_client::Client,
building::{
builders::{
best_block_store::BestBlockTracker,
best_block_store::GlobalBestBlockStore,
block_building_helper::{BlockBuildingHelper, BlockBuildingHelperFromProvider},
BlockBuildingAlgorithm, BlockBuildingAlgorithmInput, OrderConsumer,
UnfinishedBlockBuildingSink, UnfinishedBlockBuildingSinkFactory,
Expand Down Expand Up @@ -47,7 +50,7 @@ use tokio::{
sync::{broadcast, mpsc},
};
use tokio_util::sync::CancellationToken;
use tracing::{info, level_filters::LevelFilter};
use tracing::{error, info, level_filters::LevelFilter};

const RETH_DB_PATH: &str = DEFAULT_RETH_DB_PATH;

Expand Down Expand Up @@ -110,7 +113,9 @@ async fn main() -> eyre::Result<()> {
global_cancellation: cancel.clone(),
extra_rpc: RpcModule::new(()),
sink_factory: Box::new(TraceBlockSinkFactory {}),
builders: vec![Arc::new(DummyBuildingAlgorithm::new(10))],
builders: vec![Arc::new(
DummyBuildingAlgorithm::new(10, GlobalBestBlockStore::new()).await,
)],
run_sparse_trie_prefetcher: false,
orderpool_sender,
orderpool_receiver,
Expand Down Expand Up @@ -157,7 +162,6 @@ impl UnfinishedBlockBuildingSink for TracingBlockSink {
false
}
}

////////////////////////////
/// BUILDING ALGORITHM
////////////////////////////
Expand All @@ -168,13 +172,18 @@ impl UnfinishedBlockBuildingSink for TracingBlockSink {
struct DummyBuildingAlgorithm {
/// Amnount of used orders to build a block
orders_to_use: usize,
best_block_tracker: BestBlockTracker,
}

const ORDER_POLLING_PERIOD: Duration = Duration::from_millis(10);
const BUILDER_NAME: &str = "DUMMY";
impl DummyBuildingAlgorithm {
pub fn new(orders_to_use: usize) -> Self {
Self { orders_to_use }
pub async fn new(orders_to_use: usize, best_block_store: GlobalBestBlockStore) -> Self {
let best_block_tracker = BestBlockTracker::new(best_block_store);
Self {
orders_to_use,
best_block_tracker,
}
}

fn wait_for_orders(
Expand Down Expand Up @@ -247,7 +256,19 @@ where
let block = self
.build_block(orders, input.provider, &input.ctx)
.unwrap();
input.sink.new_block(block);

match block.finalize_block(Some(U256::from(0))) {
Ok(res) => {
// block on the async operation
tokio::task::block_in_place(|| {
tokio::runtime::Handle::current()
.block_on(self.best_block_tracker.try_and_update(res.block))
});
}
Err(e) => {
error!("Error on finalize_block on DummyBuildingAlgorithm: {:?}", e);
}
}
}
}
}
Loading