Skip to content

Commit bccaade

Browse files
Merge branch 'starkware-libs:main' into main
2 parents a06d156 + 7765fdc commit bccaade

File tree

47 files changed

+828
-316
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+828
-316
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ members = [
4949
"crates/apollo_rpc_execution",
5050
"crates/apollo_signature_manager",
5151
"crates/apollo_signature_manager_types",
52+
"crates/apollo_staking",
5253
"crates/apollo_starknet_client",
5354
"crates/apollo_starknet_os_program",
5455
"crates/apollo_state_reader",
@@ -136,6 +137,7 @@ apollo_rpc.path = "crates/apollo_rpc"
136137
apollo_rpc_execution.path = "crates/apollo_rpc_execution"
137138
apollo_signature_manager.path = "crates/apollo_signature_manager"
138139
apollo_signature_manager_types.path = "crates/apollo_signature_manager_types"
140+
apollo_staking.path = "crates/apollo_staking"
139141
apollo_starknet_client.path = "crates/apollo_starknet_client"
140142
apollo_starknet_os_program = { path = "crates/apollo_starknet_os_program", version = "0.0.0" }
141143
apollo_state_reader.path = "crates/apollo_state_reader"

commitlint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const AllowedScopes = ['apollo_batcher',
4141
'apollo_rpc_execution',
4242
'apollo_signature_manager',
4343
'apollo_signature_manager_types',
44+
'apollo_staking',
4445
'apollo_starknet_client',
4546
'apollo_starknet_os_program',
4647
'apollo_state_reader',

crates/apollo_central_sync/src/sources/central_sync_test.rs

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use apollo_storage::header::HeaderStorageReader;
99
use apollo_storage::state::StateStorageReader;
1010
use apollo_storage::test_utils::get_test_storage;
1111
use apollo_storage::{StorageError, StorageReader, StorageWriter};
12+
use apollo_test_utils::{get_rng, GetTestInstance};
1213
use assert_matches::assert_matches;
1314
use async_stream::stream;
1415
use async_trait::async_trait;
@@ -26,10 +27,10 @@ use starknet_api::block::{
2627
BlockNumber,
2728
BlockSignature,
2829
};
29-
use starknet_api::core::{ClassHash, SequencerPublicKey};
30+
use starknet_api::core::{ClassHash, CompiledClassHash, SequencerPublicKey};
3031
use starknet_api::crypto::utils::PublicKey;
3132
use starknet_api::felt;
32-
use starknet_api::state::StateDiff;
33+
use starknet_api::state::{SierraContractClass, StateDiff, StateNumber};
3334
use tokio::sync::{Mutex, RwLock};
3435
use tokio::time::sleep;
3536
use tracing::{debug, error};
@@ -192,6 +193,11 @@ async fn sync_happy_flow() {
192193
const MAX_TIME_TO_SYNC_MS: u64 = 800;
193194
let _ = simple_logger::init_with_env();
194195

196+
let class_hash_1 = ClassHash(felt!("0x1"));
197+
let compiled_class_hash_1 = CompiledClassHash(felt!("0x101"));
198+
let class_hash_2 = ClassHash(felt!("0x2"));
199+
let compiled_class_hash_2 = CompiledClassHash(felt!("0x102"));
200+
195201
// Mock having N_BLOCKS chain in central.
196202
let mut central_mock = MockCentralSourceTrait::new();
197203
central_mock.expect_get_latest_block().returning(|| {
@@ -232,17 +238,70 @@ async fn sync_happy_flow() {
232238
if block_number.0 >= N_BLOCKS {
233239
yield Err(CentralError::BlockNotFound { block_number })
234240
}
241+
242+
// Add declared classes to specific blocks to test compiled class hash mapping
243+
let state_diff = match block_number.0 {
244+
1 => StateDiff {
245+
declared_classes: IndexMap::from([
246+
(class_hash_1, (compiled_class_hash_1, SierraContractClass::default())),
247+
]),
248+
..Default::default()
249+
},
250+
3 => StateDiff {
251+
declared_classes: IndexMap::from([
252+
(class_hash_2, (compiled_class_hash_2, SierraContractClass::default())),
253+
]),
254+
..Default::default()
255+
},
256+
_ => StateDiff::default(),
257+
};
258+
235259
yield Ok((
236260
block_number,
237261
create_block_hash(block_number, false),
238-
StateDiff::default(),
262+
state_diff,
239263
IndexMap::new(),
240264
));
241265
}
242266
}
243267
.boxed();
244268
state_stream
245269
});
270+
271+
// Add compiled classes stream mock
272+
central_mock.expect_stream_compiled_classes().returning(move |initial, up_to| {
273+
let compiled_classes_stream: CompiledClassesStream<'_> = stream! {
274+
for block_number in initial.iter_up_to(up_to) {
275+
if block_number.0 >= N_BLOCKS {
276+
yield Err(CentralError::BlockNotFound { block_number });
277+
}
278+
279+
// Return compiled classes for blocks that declared them
280+
match block_number.0 {
281+
1 => {
282+
let mut rng = get_rng();
283+
yield Ok((
284+
class_hash_1,
285+
compiled_class_hash_1,
286+
CasmContractClass::get_test_instance(&mut rng),
287+
));
288+
},
289+
3 => {
290+
let mut rng = get_rng();
291+
yield Ok((
292+
class_hash_2,
293+
compiled_class_hash_2,
294+
CasmContractClass::get_test_instance(&mut rng),
295+
));
296+
},
297+
_ => {}
298+
}
299+
}
300+
}
301+
.boxed();
302+
compiled_classes_stream
303+
});
304+
246305
central_mock.expect_get_block_hash().returning(|bn| Ok(Some(create_block_hash(bn, false))));
247306

248307
// TODO(dvir): find a better way to do this.
@@ -304,6 +363,31 @@ async fn sync_happy_flow() {
304363
return CheckStoragePredicateResult::Error;
305364
}
306365

366+
// Verify compiled class hash mappings are stored correctly
367+
let txn = reader.begin_ro_txn().unwrap();
368+
let state_reader = txn.get_state_reader().unwrap();
369+
370+
// Check mappings - return InProgress if not ready, otherwise assert equality
371+
let state_number_1 = StateNumber::unchecked_right_after_block(BlockNumber(1));
372+
let state_number_2 = StateNumber::unchecked_right_after_block(BlockNumber(3));
373+
// Arbitrary state number after the last block.
374+
let state_number_final = StateNumber::unchecked_right_after_block(BlockNumber(4));
375+
376+
let hash_1 =
377+
state_reader.get_compiled_class_hash_at(state_number_1, &class_hash_1).unwrap();
378+
let hash_2 =
379+
state_reader.get_compiled_class_hash_at(state_number_2, &class_hash_2).unwrap();
380+
let hash_final =
381+
state_reader.get_compiled_class_hash_at(state_number_final, &class_hash_1).unwrap();
382+
383+
if hash_1.is_none() || hash_2.is_none() || hash_final.is_none() {
384+
return CheckStoragePredicateResult::InProgress;
385+
}
386+
387+
assert_eq!(hash_1, Some(compiled_class_hash_1));
388+
assert_eq!(hash_2, Some(compiled_class_hash_2));
389+
// Ensure class hash 1 remains unchanged after later declarations.
390+
assert_eq!(hash_final, Some(compiled_class_hash_1));
307391
CheckStoragePredicateResult::Passed
308392
});
309393

crates/apollo_consensus_orchestrator/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ pub mod validate_proposal;
1515
#[allow(missing_docs)]
1616
pub mod cende;
1717

18-
#[allow(missing_docs)]
19-
pub mod committee_manager;
20-
2118
/// Fee market logic.
2219
pub mod fee_market;
2320

crates/apollo_consensus_orchestrator/src/utils.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::sync::Arc;
22

3-
use apollo_consensus::types::Round;
43
use apollo_l1_gas_price_types::{
54
EthToStrkOracleClientTrait,
65
L1GasPriceProviderClient,
@@ -18,11 +17,8 @@ use apollo_state_sync_types::errors::StateSyncError;
1817
use blockifier::abi::constants::STORED_BLOCK_HASH_BUFFER;
1918
use futures::channel::mpsc;
2019
use futures::SinkExt;
21-
#[cfg(test)]
22-
use mockall::automock;
2320
use num_rational::Ratio;
2421
use starknet_api::block::{
25-
BlockHash,
2622
BlockHashAndNumber,
2723
BlockNumber,
2824
BlockTimestamp,
@@ -230,29 +226,3 @@ pub(crate) fn truncate_to_executed_txs(
230226

231227
executed_content
232228
}
233-
234-
#[cfg_attr(test, automock)]
235-
pub trait BlockRandomGenerator: Send + Sync {
236-
fn generate(
237-
&self,
238-
height: BlockNumber,
239-
round: Round,
240-
block_hash: Option<BlockHash>,
241-
range: u128,
242-
) -> u128;
243-
}
244-
245-
#[allow(dead_code)]
246-
pub struct BlockPseudorandomGenerator;
247-
248-
impl BlockRandomGenerator for BlockPseudorandomGenerator {
249-
fn generate(
250-
&self,
251-
_height: BlockNumber,
252-
_round: Round,
253-
_block_hash: Option<BlockHash>,
254-
_range: u128,
255-
) -> u128 {
256-
todo!()
257-
}
258-
}

crates/apollo_deployments/resources/deployments/testing/deployment_config_consolidated.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,8 @@
2929
"external_secret": null,
3030
"anti_affinity": false,
3131
"ports": {
32-
"Batcher": 55000,
33-
"ClassManager": 55001,
3432
"ConsensusManager": 53080,
35-
"Gateway": 55002,
36-
"L1EndpointMonitor": 55005,
37-
"L1GasPriceProvider": 55003,
38-
"L1Provider": 55004,
39-
"Mempool": 55006,
4033
"MempoolP2p": 53200,
41-
"SierraCompiler": 55007,
42-
"SignatureManager": 55009,
43-
"StateSync": 55008,
4434
"HttpServer": 8080,
4535
"MonitoringEndpoint": 8082
4636
}

crates/apollo_deployments/resources/deployments/testing/deployment_config_distributed.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,38 @@
270270
"MonitoringEndpoint": 8082
271271
}
272272
},
273+
{
274+
"name": "SignatureManager",
275+
"controller": "StatefulSet",
276+
"config_paths": [
277+
"base_app_config.json",
278+
"deployments/testing/deployment_config_override.json",
279+
"deployments/testing/distributed.json",
280+
"services/distributed/signature_manager.json"
281+
],
282+
"ingress": null,
283+
"k8s_service_config": null,
284+
"autoscale": false,
285+
"replicas": 1,
286+
"storage": null,
287+
"toleration": null,
288+
"resources": {
289+
"requests": {
290+
"cpu": 1,
291+
"memory": 2
292+
},
293+
"limits": {
294+
"cpu": 4,
295+
"memory": 8
296+
}
297+
},
298+
"external_secret": null,
299+
"anti_affinity": false,
300+
"ports": {
301+
"SignatureManager": 55009,
302+
"MonitoringEndpoint": 8082
303+
}
304+
},
273305
{
274306
"name": "StateSync",
275307
"controller": "StatefulSet",

0 commit comments

Comments
 (0)