Skip to content

Commit

Permalink
feat: add cache size to batcher config (#1493)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware authored Oct 23, 2024
1 parent 687e278 commit 361a915
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions config/mempool/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@
"privacy": "Public",
"value": 1000000
},
"batcher_config.global_contract_cache_size": {
"description": "Cache size for the global_class_hash_to_class. Initialized with this size on creation.",
"privacy": "Public",
"value": 400
},
"batcher_config.outstream_content_buffer_size": {
"description": "Maximum items to add to the outstream buffer before blocking further filling of the stream.",
"privacy": "Public",
Expand Down
5 changes: 1 addition & 4 deletions crates/batcher/src/batcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,10 @@ pub fn create_batcher(config: BatcherConfig, mempool_client: SharedMempoolClient
let (storage_reader, storage_writer) = papyrus_storage::open_storage(config.storage.clone())
.expect("Failed to open batcher's storage");

// TODO(Yael 15/10/2024): Add cache_size to the config.
let cache_size = 100;

let block_builder_factory = Arc::new(BlockBuilderFactory {
block_builder_config: config.block_builder_config.clone(),
storage_reader: storage_reader.clone(),
global_class_hash_to_class: GlobalContractCache::new(cache_size),
global_class_hash_to_class: GlobalContractCache::new(config.global_contract_cache_size),
});
let storage_reader = Arc::new(storage_reader);
let storage_writer = Box::new(storage_writer);
Expand Down
9 changes: 9 additions & 0 deletions crates/batcher/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct BatcherConfig {
pub proposal_manager: ProposalManagerConfig,
pub outstream_content_buffer_size: usize,
pub block_builder_config: BlockBuilderConfig,
pub global_contract_cache_size: usize,
}

impl SerializeConfig for BatcherConfig {
Expand All @@ -28,6 +29,13 @@ impl SerializeConfig for BatcherConfig {
stream.",
ParamPrivacyInput::Public,
)]));
dump.append(&mut BTreeMap::from([ser_param(
"global_contract_cache_size",
&self.global_contract_cache_size,
"Cache size for the global_class_hash_to_class. Initialized with this size on \
creation.",
ParamPrivacyInput::Public,
)]));
dump.append(&mut append_sub_config_name(self.storage.dump(), "storage"));
dump.append(&mut append_sub_config_name(
self.block_builder_config.dump(),
Expand All @@ -54,6 +62,7 @@ impl Default for BatcherConfig {
// TODO: set a more reasonable default value.
outstream_content_buffer_size: 100,
block_builder_config: BlockBuilderConfig::default(),
global_contract_cache_size: 400,
}
}
}

0 comments on commit 361a915

Please sign in to comment.