Skip to content

Commit ca98a6a

Browse files
blockifier: set state reader and contract manager metrics as optional (#10469)
1 parent 2b5ed03 commit ca98a6a

File tree

7 files changed

+20
-54
lines changed

7 files changed

+20
-54
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/apollo_batcher/src/block_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ impl BlockBuilderFactory {
728728
let state_reader = StateReaderAndContractManager::new(
729729
apollo_reader,
730730
self.contract_class_manager.clone(),
731-
BATCHER_CLASS_CACHE_METRICS,
731+
Some(BATCHER_CLASS_CACHE_METRICS),
732732
);
733733

734734
let executor = ConcurrentTransactionExecutor::start_block(

crates/apollo_gateway/src/stateful_transaction_validator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl StatefulTransactionValidatorFactoryTrait for StatefulTransactionValidatorFa
8585
let state_reader_and_contract_manager = StateReaderAndContractManager::new(
8686
state_reader,
8787
self.contract_class_manager.clone(),
88-
GATEWAY_CLASS_CACHE_METRICS,
88+
Some(GATEWAY_CLASS_CACHE_METRICS),
8989
);
9090

9191
let state = CachedState::new(state_reader_and_contract_manager);

crates/blockifier/src/state/state_reader_and_contract_manager.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ pub trait FetchCompiledClasses: StateReader {
2222
pub struct StateReaderAndContractManager<S: FetchCompiledClasses> {
2323
pub state_reader: S,
2424
contract_class_manager: ContractClassManager,
25-
class_cache_metrics: CacheMetrics,
25+
class_cache_metrics: Option<CacheMetrics>,
2626
}
2727

2828
impl<S: FetchCompiledClasses> StateReaderAndContractManager<S> {
2929
pub fn new(
3030
state_reader: S,
3131
contract_class_manager: ContractClassManager,
32-
class_cache_metrics: CacheMetrics,
32+
class_cache_metrics: Option<CacheMetrics>,
3333
) -> Self {
3434
Self { state_reader, contract_class_manager, class_cache_metrics }
3535
}
@@ -52,11 +52,11 @@ impl<S: FetchCompiledClasses> StateReaderAndContractManager<S> {
5252
}
5353
}
5454
}
55-
self.class_cache_metrics.increment_hit();
55+
self.increment_cache_hit_metric();
5656
self.update_native_metrics(&runnable_class);
5757
return Ok(runnable_class);
5858
}
59-
self.class_cache_metrics.increment_miss();
59+
self.increment_cache_miss_metric();
6060

6161
let compiled_class = self.state_reader.get_compiled_classes(class_hash)?;
6262
self.contract_class_manager.set_and_compile(class_hash, compiled_class.clone());
@@ -72,6 +72,18 @@ impl<S: FetchCompiledClasses> StateReaderAndContractManager<S> {
7272
Ok(runnable_class)
7373
}
7474

75+
fn increment_cache_hit_metric(&self) {
76+
if let Some(ref class_cache_metrics) = self.class_cache_metrics {
77+
class_cache_metrics.increment_hit();
78+
}
79+
}
80+
81+
fn increment_cache_miss_metric(&self) {
82+
if let Some(ref class_cache_metrics) = self.class_cache_metrics {
83+
class_cache_metrics.increment_miss();
84+
}
85+
}
86+
7587
fn update_native_metrics(&self, _runnable_class: &RunnableCompiledClass) {
7688
#[cfg(feature = "cairo_native")]
7789
{

crates/blockifier/src/test_utils/initial_test_state.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use apollo_metrics::metrics::{MetricCounter, MetricScope};
21
use blockifier_test_utils::cairo_versions::CairoVersion;
32
use blockifier_test_utils::contracts::FeatureContract;
43
use starknet_api::abi::abi_utils::get_fee_token_var_address;
@@ -11,7 +10,6 @@ use strum::IntoEnumIterator;
1110

1211
use crate::blockifier::config::ContractClassManagerConfig;
1312
use crate::context::ChainInfo;
14-
use crate::metrics::CacheMetrics;
1513
use crate::state::cached_state::CachedState;
1614
use crate::state::contract_class_manager::ContractClassManager;
1715
use crate::state::state_reader_and_contract_manager::{
@@ -21,22 +19,6 @@ use crate::state::state_reader_and_contract_manager::{
2119
use crate::test_utils::contracts::FeatureContractData;
2220
use crate::test_utils::dict_state_reader::DictStateReader;
2321

24-
/// Placeholder class cache metrics. The metrics are not tested in the blockifier's context.
25-
const BLOCKIFIER_CLASS_CACHE_METRICS: CacheMetrics = CacheMetrics::new(
26-
MetricCounter::new(
27-
MetricScope::Blockifier,
28-
"Class Cache Misses in Blockifier",
29-
"Counter of the number of times that the class cache was missed",
30-
0,
31-
),
32-
MetricCounter::new(
33-
MetricScope::Blockifier,
34-
"Class Cache Misses in Blockifier",
35-
"Counter of the number of times that the class cache was hit",
36-
0,
37-
),
38-
);
39-
4022
/// Utility to fund an account.
4123
pub fn fund_account(
4224
chain_info: &ChainInfo,
@@ -203,9 +185,5 @@ pub fn state_reader_and_contract_manager_for_testing<Reader: FetchCompiledClasse
203185
state_reader: Reader,
204186
contract_class_manager: ContractClassManager,
205187
) -> StateReaderAndContractManager<Reader> {
206-
StateReaderAndContractManager::new(
207-
state_reader,
208-
contract_class_manager,
209-
BLOCKIFIER_CLASS_CACHE_METRICS,
210-
)
188+
StateReaderAndContractManager::new(state_reader, contract_class_manager, None)
211189
}

crates/native_blockifier/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ crate-type = ["cdylib"]
2828

2929
[dependencies]
3030
apollo_compile_to_native_types.workspace = true
31-
apollo_metrics.workspace = true
3231
apollo_state_reader.workspace = true
3332
apollo_storage.workspace = true
3433
blockifier = { workspace = true, features = ["native_blockifier"] }

crates/native_blockifier/src/py_block_executor.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use std::str::FromStr;
44

5-
use apollo_metrics::metrics::{MetricCounter, MetricScope};
65
use apollo_state_reader::apollo_state::ApolloReader;
76
use blockifier::blockifier::config::{ContractClassManagerConfig, TransactionExecutorConfig};
87
use blockifier::blockifier::transaction_executor::{
@@ -13,7 +12,6 @@ use blockifier::blockifier::transaction_executor::{
1312
use blockifier::blockifier_versioned_constants::VersionedConstants;
1413
use blockifier::bouncer::BouncerConfig;
1514
use blockifier::context::{BlockContext, ChainInfo, FeeTokenAddresses};
16-
use blockifier::metrics::CacheMetrics;
1715
use blockifier::state::contract_class_manager::ContractClassManager;
1816
use blockifier::state::state_reader_and_contract_manager::StateReaderAndContractManager;
1917
use blockifier::transaction::account_transaction::AccountTransaction;
@@ -55,22 +53,6 @@ pub(crate) type RawTransactionExecutionResult = Vec<u8>;
5553
pub type ApolloStateReaderAndContractManager = StateReaderAndContractManager<ApolloReader>;
5654
const RESULT_SERIALIZE_ERR: &str = "Failed serializing execution info.";
5755

58-
/// Placeholder class cache metrics. There are not metrics on the native blockifier.
59-
const NATIVE_BLOCKIFIER_CLASS_CACHE_METRICS: CacheMetrics = CacheMetrics::new(
60-
MetricCounter::new(
61-
MetricScope::Blockifier,
62-
"Class Cache Misses in Native Blockifier",
63-
"Counter of the number of times that the class cache was missed",
64-
0,
65-
),
66-
MetricCounter::new(
67-
MetricScope::Blockifier,
68-
"Class Cache Misses in Native Blockifier",
69-
"Counter of the number of times that the class cache was hit",
70-
0,
71-
),
72-
);
73-
7456
/// Return type for the finalize method containing state diffs, bouncer weights, and CASM hash
7557
/// computation data.
7658
type FinalizeResult = (
@@ -429,11 +411,7 @@ impl PyBlockExecutor {
429411
self.storage.validate_aligned(next_block_number.0);
430412
let apollo_reader = ApolloReader::new(self.storage.reader().clone(), next_block_number);
431413

432-
StateReaderAndContractManager::new(
433-
apollo_reader,
434-
self.contract_class_manager.clone(),
435-
NATIVE_BLOCKIFIER_CLASS_CACHE_METRICS,
436-
)
414+
StateReaderAndContractManager::new(apollo_reader, self.contract_class_manager.clone(), None)
437415
}
438416

439417
pub fn create_for_testing_with_storage(storage: impl Storage + Send + 'static) -> Self {

0 commit comments

Comments
 (0)