Skip to content

[feat] adds simulation to block loop #71

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

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open

Conversation

dylanlott
Copy link
Contributor

@dylanlott dylanlott commented Apr 15, 2025

[feat] adds simulation to block loop

This PR adds simulation to the block builder loop.

  • Updates the builder to use a SlotCalculator for managing slot timings.
  • Removes the tx and bundle poller from the block builder and instead leans into the actor model and feeds them in via channels to the simulation process.
  • This PR relies on the signet-sdk Sim Crate PR

Configuration

Deploying this PR will require additional environment variables to be set

  • CONCURRENCY_LIMIT to limit how many concurrent simulations the block builder runs.
  • START_TIMESTAMP to set the starting timestamp of the chain for anchoring slot calculation.

Testing

This code is still being tested before final merge.

The current test plan is to

  • Build a Docker image of the builder with this branch
  • Update environment variables to include the above values
  • Deploy the test image to Pecorino
  • Add a bundle to the cache and see if it is picked up
  • See what, if any, errors spring up
  • Land blocks and see that the block building rate is not decreased with new timing updates

dylanlott and others added 15 commits April 3, 2025 09:45
- shifts the tx-poller to a more actor oriented approach by streaming transactions out of the cache.
- transaction deduplication and validation is intended to be carried out by the simulator.
- improves poll interval handling
- removes arcs
- updates comments
- adds file level comment
* fix: break loop on closure and improve tracing

* refactor: break out the task future
- improves poll interval handling
- cleans up and updates comments
- removes arc usage
- adds init4 metrics
- updates provider types to account for alloy changes
- align to alloy @ 0.12.6
- transfer off of zenith-rs and use signet-sdk instead
@dylanlott dylanlott self-assigned this Apr 15, 2025
Copy link
Contributor Author

dylanlott commented Apr 15, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@dylanlott dylanlott marked this pull request as ready for review April 24, 2025 17:48
}

/// polls the tx-pool for unique transactions and evicts expired transactions.
/// unique transactions that haven't been seen before are sent into the builder pipeline.
/// Polls the transaction cache for transactions.
pub async fn check_tx_cache(&mut self) -> Result<Vec<TxEnvelope>, Error> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this PR pulls this functionality into the SDK - but no need to block on it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will address in a follow-up PR 👍

Copy link
Member

@prestwich prestwich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are going places 😎


let port = config.builder_port;
let server = serve_builder_with_span(([0, 0, 0, 0], port), span);

select! {
_ = tx_poller_jh => {
tracing::info!("tx_poller finished");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i miss is cooked :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is cooked got cooked

pub config: BuilderConfig,
/// Reqwest client for fetching transactions from the tx-pool
/// Reqwest Client for fetching transactions from the cache.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can replace this with TxCache after init4tech/signet-sdk#39

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will address in a follow up PR 👍

- adds newlines after arguments and returns sections in comments
- pulls several functions out into methods
- refactors the rollup provider type from a FillProvider to a RootProvider
- defines the alloy database provider type around this
- updates relevant connection functions to use the new RuProvider type
- renames Provider to HostProvider
- renames WalletlessProvider to RuProvider
@dylanlott dylanlott requested a review from prestwich April 28, 2025 22:00
src/consts.rs Outdated
@@ -0,0 +1,4 @@
//! Constants used in the builder.
Copy link
Member

@Evalir Evalir Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mega nit: let's just call this file constants.rs since that's the usual name elsewhere

EDIT: well just saw on the prev review that this was the suggestion. feel free to ignore

src/config.rs Outdated
Comment on lines 256 to 273
address!("0x4E8cC181805aFC307C83298242271142b8e2f249"),
address!("0xd553C4CA4792Af71F4B61231409eaB321c1Dd2Ce"),
address!("0x1af3A16857C28917Ab2C4c78Be099fF251669200"),
PredeployTokens::new(
address!("0x885F8DB528dC8a38aA3DDad9D3F619746B4a6A81"),
address!("0x7970D259D4a96764Fa9B23FF0715A35f06f52D1A"),
address!("0x7970D259D4a96764Fa9B23FF0715A35f06f52D1A"),
),
);
let rollup = RollupConfig::new(
self.ru_chain_id,
address!("0x4E8cC181805aFC307C83298242271142b8e2f249"),
address!("0xd553C4CA4792Af71F4B61231409eaB321c1Dd2Ce"),
address!("0xe0eDA3701D44511ce419344A4CeD30B52c9Ba231"),
PredeployTokens::new(
address!("0x0B8BC5e60EE10957E0d1A0d95598fA63E65605e2"),
address!("0xF34326d3521F1b07d1aa63729cB14A372f8A737C"),
address!("0xE3d7066115f7d6b65F88Dff86288dB4756a7D733"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should all be constants in constants.rs


let port = config.builder_port;
let server = serve_builder_with_span(([0, 0, 0, 0], port), span);

select! {
_ = tx_poller_jh => {
tracing::info!("tx_poller finished");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is cooked got cooked

Comment on lines +127 to +129
/// Error checking available system concurrency
#[error("failed to determine system concurrency: {0}")]
Io(#[from] std::io::Error),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, i think the error thrown when checking concurrency will add the specific info; therefore, we can keep this general as an "I/O error" instead of using Io to describe the specific concurrency check error.

@@ -278,5 +309,18 @@ pub fn load_url(key: &str) -> Result<Cow<'static, str>, ConfigError> {
/// Load an address from an environment variable.
pub fn load_address(key: &str) -> Result<Address, ConfigError> {
let address = load_string(key)?;
Address::from_str(&address).map_err(Into::into)
Address::from_str(&address)
.map_err(|_| ConfigError::Var(format!("Invalid address format for {}", key)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's include the actual error source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants