From bf984a7b24ba115bf8ac0645d99de9d2507a7399 Mon Sep 17 00:00:00 2001 From: Ayelet Zilber Date: Sun, 13 Oct 2024 17:09:57 +0300 Subject: [PATCH] chore(batcher): impl SerializeConfig for BlockBuilderConfig and related structs --- crates/batcher/src/block_builder.rs | 35 ++++++ crates/blockifier/src/blockifier/config.rs | 35 ++++++ crates/blockifier/src/bouncer.rs | 114 ++++++++++++++++++- crates/blockifier/src/versioned_constants.rs | 29 ++++- 4 files changed, 211 insertions(+), 2 deletions(-) diff --git a/crates/batcher/src/block_builder.rs b/crates/batcher/src/block_builder.rs index f72aeb066c..22232276a6 100644 --- a/crates/batcher/src/block_builder.rs +++ b/crates/batcher/src/block_builder.rs @@ -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; @@ -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}; @@ -94,6 +98,37 @@ impl Default for BlockBuilderConfig { } } +impl SerializeConfig for BlockBuilderConfig { + fn dump(&self) -> BTreeMap { + 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( diff --git a/crates/blockifier/src/blockifier/config.rs b/crates/blockifier/src/blockifier/config.rs index 25781aaa42..3252394a45 100644 --- a/crates/blockifier/src/blockifier/config.rs +++ b/crates/blockifier/src/blockifier/config.rs @@ -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)] @@ -11,6 +15,12 @@ impl TransactionExecutorConfig { } } +impl SerializeConfig for TransactionExecutorConfig { + fn dump(&self) -> BTreeMap { + append_sub_config_name(self.concurrency_config.dump(), "concurrency_config") + } +} + #[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)] pub struct ConcurrencyConfig { pub enabled: bool, @@ -26,3 +36,28 @@ impl ConcurrencyConfig { Self { enabled: false, n_workers: 0, chunk_size: 0 } } } + +impl SerializeConfig for ConcurrencyConfig { + fn dump(&self) -> BTreeMap { + 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, + ), + ]) + } +} diff --git a/crates/blockifier/src/bouncer.rs b/crates/blockifier/src/bouncer.rs index 22d8539316..414fff93a9 100644 --- a/crates/blockifier/src/bouncer.rs +++ b/crates/blockifier/src/bouncer.rs @@ -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; @@ -71,6 +73,12 @@ impl BouncerConfig { } } +impl SerializeConfig for BouncerConfig { + fn dump(&self) -> BTreeMap { + append_sub_config_name(self.block_max_capacity.dump(), "block_max_capacity") + } +} + #[derive( Clone, Copy, @@ -143,6 +151,43 @@ impl Default for BouncerWeights { } } +impl SerializeConfig for BouncerWeights { + fn dump(&self) -> BTreeMap { + 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!( @@ -307,6 +352,73 @@ impl Default for BuiltinCount { } } +impl SerializeConfig for BuiltinCount { + fn dump(&self) -> BTreeMap { + 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 { diff --git a/crates/blockifier/src/versioned_constants.rs b/crates/blockifier/src/versioned_constants.rs index 506a6282d5..1a179bd184 100644 --- a/crates/blockifier/src/versioned_constants.rs +++ b/crates/blockifier/src/versioned_constants.rs @@ -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}; @@ -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; @@ -869,3 +871,28 @@ impl Default for VersionedConstantsOverrides { } } } + +impl SerializeConfig for VersionedConstantsOverrides { + fn dump(&self) -> BTreeMap { + 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, + ), + ]) + } +}