Skip to content

Commit

Permalink
chore(batcher): impl SerializeConfig for BlockBuilderConfig and relat…
Browse files Browse the repository at this point in the history
…ed structs
  • Loading branch information
ayeletstarkware committed Oct 15, 2024
1 parent 57a15a3 commit bf984a7
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 2 deletions.
35 changes: 35 additions & 0 deletions crates/batcher/src/block_builder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::BTreeMap;

use async_trait::async_trait;
use blockifier::blockifier::block::{BlockInfo, BlockNumberHashPair, GasPrices};
use blockifier::blockifier::config::TransactionExecutorConfig;
Expand All @@ -21,6 +23,8 @@ use blockifier::versioned_constants::{VersionedConstants, VersionedConstantsOver
use indexmap::IndexMap;
#[cfg(test)]
use mockall::automock;
use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig};
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam};
use papyrus_storage::StorageReader;
use serde::{Deserialize, Serialize};
use starknet_api::block::{BlockNumber, BlockTimestamp, NonzeroGasPrice};
Expand Down Expand Up @@ -94,6 +98,37 @@ impl Default for BlockBuilderConfig {
}
}

impl SerializeConfig for BlockBuilderConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
let mut dump = append_sub_config_name(self.chain_info.dump(), "chain_info");
dump.append(&mut append_sub_config_name(self.execute_config.dump(), "execute_config"));
dump.append(&mut append_sub_config_name(self.bouncer_config.dump(), "bouncer_config"));
dump.append(&mut BTreeMap::from([ser_param(
"sequencer_address",
&self.sequencer_address,
"The address of the sequencer.",
ParamPrivacyInput::Public,
)]));
dump.append(&mut BTreeMap::from([ser_param(
"use_kzg_da",
&self.use_kzg_da,
"Indicates whether the kzg mechanism is used for data availability.",
ParamPrivacyInput::Public,
)]));
dump.append(&mut BTreeMap::from([ser_param(
"tx_chunk_size",
&self.tx_chunk_size,
"The size of the transaction chunk.",
ParamPrivacyInput::Public,
)]));
dump.append(&mut append_sub_config_name(
self.versioned_constants_overrides.dump(),
"versioned_constants_overrides",
));
dump
}
}

#[async_trait]
impl BlockBuilderTrait for BlockBuilder {
async fn build_block(
Expand Down
35 changes: 35 additions & 0 deletions crates/blockifier/src/blockifier/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use std::collections::BTreeMap;

use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig};
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
Expand All @@ -11,6 +15,12 @@ impl TransactionExecutorConfig {
}
}

impl SerializeConfig for TransactionExecutorConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
append_sub_config_name(self.concurrency_config.dump(), "concurrency_config")
}
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct ConcurrencyConfig {
pub enabled: bool,
Expand All @@ -26,3 +36,28 @@ impl ConcurrencyConfig {
Self { enabled: false, n_workers: 0, chunk_size: 0 }
}
}

impl SerializeConfig for ConcurrencyConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
BTreeMap::from_iter([
ser_param(
"enabled",
&self.enabled,
"Enables concurrency of transaction execution.",
ParamPrivacyInput::Public,
),
ser_param(
"n_workers",
&self.n_workers,
"Number of parallel transaction execution workers.",
ParamPrivacyInput::Public,
),
ser_param(
"chunk_size",
&self.chunk_size,
"The size of the transaction chunk executed in parallel.",
ParamPrivacyInput::Public,
),
])
}
}
114 changes: 113 additions & 1 deletion crates/blockifier/src/bouncer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::collections::{HashMap, HashSet};
use std::collections::{BTreeMap, HashMap, HashSet};

use cairo_vm::types::builtin_name::BuiltinName;
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig};
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam};
use serde::{Deserialize, Serialize};
use starknet_api::core::ClassHash;

Expand Down Expand Up @@ -71,6 +73,12 @@ impl BouncerConfig {
}
}

impl SerializeConfig for BouncerConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
append_sub_config_name(self.block_max_capacity.dump(), "block_max_capacity")
}
}

#[derive(
Clone,
Copy,
Expand Down Expand Up @@ -143,6 +151,43 @@ impl Default for BouncerWeights {
}
}

impl SerializeConfig for BouncerWeights {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
let mut dump = append_sub_config_name(self.builtin_count.dump(), "builtin_count");
dump.append(&mut BTreeMap::from([ser_param(
"gas",
&self.gas,
"An upper bound on the total gas used in a block.",
ParamPrivacyInput::Public,
)]));
dump.append(&mut BTreeMap::from([ser_param(
"message_segment_length",
&self.message_segment_length,
"An upper bound on the message segment length in a block.",
ParamPrivacyInput::Public,
)]));
dump.append(&mut BTreeMap::from([ser_param(
"n_events",
&self.n_events,
"An upper bound on the total number of events generated in a block.",
ParamPrivacyInput::Public,
)]));
dump.append(&mut BTreeMap::from([ser_param(
"n_steps",
&self.n_steps,
"An upper bound on the total number of steps in a block.",
ParamPrivacyInput::Public,
)]));
dump.append(&mut BTreeMap::from([ser_param(
"state_diff_size",
&self.state_diff_size,
"An upper bound on the total state diff size in a block.",
ParamPrivacyInput::Public,
)]));
dump
}
}

impl std::fmt::Display for BouncerWeights {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
Expand Down Expand Up @@ -307,6 +352,73 @@ impl Default for BuiltinCount {
}
}

impl SerializeConfig for BuiltinCount {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
BTreeMap::from_iter([
ser_param(
"add_mod",
&self.add_mod,
"Max number of add mod builtin usage in a block.",
ParamPrivacyInput::Public,
),
ser_param(
"bitwise",
&self.bitwise,
"Max number of bitwise builtin usage in a block.",
ParamPrivacyInput::Public,
),
ser_param(
"ecdsa",
&self.ecdsa,
"Max number of ECDSA builtin usage in a block.",
ParamPrivacyInput::Public,
),
ser_param(
"ec_op",
&self.ec_op,
"Max number of EC operation builtin usage in a block.",
ParamPrivacyInput::Public,
),
ser_param(
"keccak",
&self.keccak,
"Max number of keccak builtin usage in a block.",
ParamPrivacyInput::Public,
),
ser_param(
"mul_mod",
&self.mul_mod,
"Max number of mul mod builtin usage in a block.",
ParamPrivacyInput::Public,
),
ser_param(
"pedersen",
&self.pedersen,
"Max number of pedersen builtin usage in a block.",
ParamPrivacyInput::Public,
),
ser_param(
"poseidon",
&self.poseidon,
"Max number of poseidon builtin usage in a block.",
ParamPrivacyInput::Public,
),
ser_param(
"range_check",
&self.range_check,
"Max number of range check builtin usage in a block.",
ParamPrivacyInput::Public,
),
ser_param(
"range_check96",
&self.range_check96,
"Max number of range check 96 builtin usage in a block.",
ParamPrivacyInput::Public,
),
])
}
}

#[derive(Debug, PartialEq)]
#[cfg_attr(test, derive(Clone))]
pub struct Bouncer {
Expand Down
29 changes: 28 additions & 1 deletion crates/blockifier/src/versioned_constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashMap, HashSet};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::path::{Path, PathBuf};
use std::sync::{Arc, LazyLock};
use std::{fs, io};
Expand All @@ -8,6 +8,8 @@ use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use indexmap::{IndexMap, IndexSet};
use num_rational::Ratio;
use num_traits::Inv;
use papyrus_config::dumping::{ser_param, SerializeConfig};
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam};
use paste::paste;
use semver::Version;
use serde::de::Error as DeserializationError;
Expand Down Expand Up @@ -869,3 +871,28 @@ impl Default for VersionedConstantsOverrides {
}
}
}

impl SerializeConfig for VersionedConstantsOverrides {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
BTreeMap::from_iter([
ser_param(
"validate_max_n_steps",
&self.validate_max_n_steps,
"Maximum number of steps the validation function is allowed to run.",
ParamPrivacyInput::Public,
),
ser_param(
"max_recursion_depth",
&self.max_recursion_depth,
"Maximum recursion depth for nested calls during blockifier validation.",
ParamPrivacyInput::Public,
),
ser_param(
"invoke_tx_max_n_steps",
&self.invoke_tx_max_n_steps,
"Maximum number of steps the invoke function is allowed to run.",
ParamPrivacyInput::Public,
),
])
}
}

0 comments on commit bf984a7

Please sign in to comment.