Skip to content

Commit e75b401

Browse files
committed
Merge remote-tracking branch 'origin/main-v0.14.2' into shahak/merge-main-v0.14.1-committer-into-main-v0.14.2-1771144428
2 parents 1dbf9f1 + 11f241e commit e75b401

35 files changed

+416
-139
lines changed

Cargo.lock

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

crates/apollo_deployments/src/scale_policy.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ use serde::{Serialize, Serializer};
33
const IDLE_CONNECTIONS_FOR_AUTO_SCALED_SERVICES: usize = 0;
44
const IDLE_CONNECTIONS_FOR_STATICALLY_SCALED_SERVICES: usize = 10;
55

6+
// Note: we explicitly use a new connection when sending a request to an autoscaled or a
7+
// service allowed to run on a spot instance to ensure each new request goes through the load
8+
// balancer and directed at an available server. This allows us to avoid having to address
9+
// connection termination issues, e.g., when the server is marked for eviction, and should be in
10+
// a graceful shutdown flow, and as such should reject new requests.
11+
612
/// Whether a service is autoscaled or not.
713
#[derive(Clone, Debug, PartialEq)]
814
pub enum ScalePolicy {

crates/apollo_deployments/src/service.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::fmt::Display;
33
use std::fs::File;
44
use std::io::Read;
55
use std::iter::once;
6-
use std::net::{IpAddr, Ipv4Addr};
76
use std::path::{Path, PathBuf};
87

98
use apollo_config::dumping::{prepend_sub_config_name, ser_param, SerializeConfig};
@@ -377,7 +376,6 @@ pub(crate) trait GetComponentConfigs: ServiceNameInner {
377376
fn component_config_for_local_service(&self, port: u16) -> ReactiveComponentExecutionConfig {
378377
ReactiveComponentExecutionConfig::local_with_remote_enabled(
379378
REMOTE_SERVICE_URL_PLACEHOLDER.to_string(),
380-
IpAddr::from(Ipv4Addr::UNSPECIFIED),
381379
port,
382380
)
383381
}
@@ -386,13 +384,9 @@ pub(crate) trait GetComponentConfigs: ServiceNameInner {
386384
fn component_config_for_remote_service(&self, port: u16) -> ReactiveComponentExecutionConfig {
387385
let idle_connections = self.get_scale_policy().idle_connections();
388386
let retries = self.get_retries();
389-
ReactiveComponentExecutionConfig::remote(
390-
REMOTE_SERVICE_URL_PLACEHOLDER.to_string(),
391-
IpAddr::from(Ipv4Addr::UNSPECIFIED),
392-
port,
393-
)
394-
.with_idle_connections(idle_connections)
395-
.with_retries(retries)
387+
ReactiveComponentExecutionConfig::remote(REMOTE_SERVICE_URL_PLACEHOLDER.to_string(), port)
388+
.with_idle_connections(idle_connections)
389+
.with_retries(retries)
396390
}
397391

398392
fn component_config_pair(&self, port: u16) -> ComponentConfigPair {

crates/apollo_node_config/src/component_execution_config.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::collections::BTreeMap;
2-
use std::net::{IpAddr, ToSocketAddrs};
2+
use std::net::ToSocketAddrs;
33

44
use apollo_config::dumping::{ser_optional_sub_config, ser_param, SerializeConfig};
55
use apollo_config::{ParamPath, ParamPrivacyInput, SerializedParam};
@@ -135,8 +135,7 @@ impl ReactiveComponentExecutionConfig {
135135
}
136136
}
137137

138-
// TODO(Tsabary): remove the unused `_ip` arg.
139-
pub fn remote(url: String, _ip: IpAddr, port: u16) -> Self {
138+
pub fn remote(url: String, port: u16) -> Self {
140139
Self {
141140
execution_mode: ReactiveComponentExecutionMode::Remote,
142141
local_server_config: None,
@@ -148,8 +147,7 @@ impl ReactiveComponentExecutionConfig {
148147
}
149148
}
150149

151-
// TODO(Tsabary): remove the unused `_ip` arg.
152-
pub fn local_with_remote_enabled(url: String, _ip: IpAddr, port: u16) -> Self {
150+
pub fn local_with_remote_enabled(url: String, port: u16) -> Self {
153151
Self {
154152
execution_mode: ReactiveComponentExecutionMode::LocalExecutionWithRemoteEnabled,
155153
local_server_config: Some(LocalServerConfig::default()),

crates/apollo_rpc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ pub async fn run_server(
220220
) -> anyhow::Result<(SocketAddr, ServerHandle)> {
221221
debug!("Started get_last_synced_block");
222222
let starting_block = get_last_synced_block(storage_reader.clone())?;
223-
debug!("Starting JSON-RPC.");
224223
let methods = get_methods_from_supported_apis(
225224
&config.chain_id,
226225
config.execution_config,
@@ -246,6 +245,7 @@ pub async fn run_server(
246245
.set_http_middleware(ServiceBuilder::new().filter_async(proxy_rpc_request));
247246

248247
let server_address = SocketAddr::new(config.ip, config.port);
248+
debug!("Starting JSON-RPC at address {server_address}.");
249249

250250
if config.collect_metrics {
251251
let server = server_builder

crates/apollo_storage/src/storage_reader_server.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ pub trait StorageReaderServerHandler<Request, Response> {
130130
) -> Result<Response, StorageError>;
131131
}
132132

133-
// TODO(Nadin): Remove #[allow(dead_code)] once the fields are used in the implementation.
134-
#[allow(dead_code)]
135133
/// A server for handling remote storage reader queries via a configurable request handler.
136134
pub struct StorageReaderServer<RequestHandler, Request, Response>
137135
where

crates/blockifier_reexecution/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use starknet_api::core::ChainId;
1616
use starknet_api::transaction::Transaction;
1717
use state_reader::config::RpcStateReaderConfig;
1818
use state_reader::rpc_state_reader::ConsecutiveRpcStateReaders;
19+
use utils::get_chain_info;
1920

2021
/// Executes a single transaction at the given block number using the RPC state reader.
2122
pub fn execute_single_transaction(
@@ -38,10 +39,11 @@ pub fn execute_single_transaction(
3839
assert!(block_number.0 != 0, "Cannot execute transaction at block 0");
3940
let prev_block_number = BlockNumber(block_number.0 - 1);
4041

42+
let chain_info = get_chain_info(&chain_id, None);
4143
let readers = ConsecutiveRpcStateReaders::new(
4244
prev_block_number,
4345
Some(rpc_state_reader_config),
44-
chain_id,
46+
chain_info,
4547
false,
4648
contract_class_manager,
4749
);

crates/blockifier_reexecution/src/main.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use blockifier_reexecution::state_reader::config::RpcStateReaderConfig;
1414
use blockifier_reexecution::state_reader::offline_state_reader::OfflineConsecutiveStateReaders;
1515
use blockifier_reexecution::state_reader::reexecution_state_reader::ConsecutiveReexecutionStateReaders;
1616
use blockifier_reexecution::state_reader::rpc_state_reader::ConsecutiveRpcStateReaders;
17+
use blockifier_reexecution::utils::get_chain_info;
1718
use clap::Parser;
1819
use google_cloud_storage::client::{Client, ClientConfig};
1920
use google_cloud_storage::http::objects::download::Range;
@@ -68,10 +69,11 @@ async fn main() {
6869
// for details), so should be executed in a blocking thread.
6970
// TODO(Aner): make only the RPC calls blocking, not the whole function.
7071
tokio::task::spawn_blocking(move || {
72+
let chain_info = get_chain_info(&rpc_args.parse_chain_id(), None);
7173
ConsecutiveRpcStateReaders::new(
7274
BlockNumber(block_number - 1),
7375
Some(rpc_state_reader_config),
74-
rpc_args.parse_chain_id(),
76+
chain_info,
7577
false,
7678
contract_class_manager,
7779
)
@@ -98,7 +100,7 @@ async fn main() {
98100
);
99101

100102
let rpc_state_reader_config = RpcStateReaderConfig::from_url(rpc_args.node_url.clone());
101-
let chain_id = rpc_args.parse_chain_id();
103+
let chain_info = get_chain_info(&rpc_args.parse_chain_id(), None);
102104

103105
// RPC calls are "synchronous IO" (see, e.g., https://stackoverflow.com/questions/74547541/when-should-you-use-tokios-spawn_blocking)
104106
// for details), so should be executed in a blocking thread.
@@ -107,7 +109,7 @@ async fn main() {
107109
ConsecutiveRpcStateReaders::new(
108110
BlockNumber(block_number - 1),
109111
Some(rpc_state_reader_config),
110-
chain_id,
112+
chain_info,
111113
false,
112114
contract_class_manager,
113115
)
@@ -129,7 +131,8 @@ async fn main() {
129131
let mut task_set = tokio::task::JoinSet::new();
130132
for block_number in block_numbers {
131133
let full_file_path = block_full_file_path(directory_path.clone(), block_number);
132-
let (node_url, chain_id) = (rpc_args.node_url.clone(), rpc_args.parse_chain_id());
134+
let node_url = rpc_args.node_url.clone();
135+
let chain_info = get_chain_info(&rpc_args.parse_chain_id(), None);
133136
let contract_class_manager = contract_class_manager.clone();
134137

135138
// RPC calls are "synchronous IO" (see, e.g., https://stackoverflow.com/questions/74547541/when-should-you-use-tokios-spawn-blocking)
@@ -142,7 +145,7 @@ async fn main() {
142145
ConsecutiveRpcStateReaders::new(
143146
block_number.prev().expect("Should not run with block 0"),
144147
Some(rpc_state_reader_config),
145-
chain_id,
148+
chain_info,
146149
true,
147150
contract_class_manager,
148151
)

crates/blockifier_reexecution/src/state_reader/rpc_state_reader.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use blockifier::blockifier::transaction_executor::{
1111
};
1212
use blockifier::blockifier_versioned_constants::VersionedConstants;
1313
use blockifier::bouncer::BouncerConfig;
14-
use blockifier::context::BlockContext;
14+
use blockifier::context::{BlockContext, ChainInfo};
1515
use blockifier::execution::contract_class::RunnableCompiledClass;
1616
use blockifier::state::cached_state::{CommitmentStateDiff, StateMaps};
1717
use blockifier::state::contract_class_manager::ContractClassManager;
@@ -119,9 +119,8 @@ pub struct RpcStateReader {
119119
pub config: RpcStateReaderConfig,
120120
pub block_id: BlockId,
121121
pub(crate) retry_config: RetryConfig,
122-
pub chain_id: ChainId,
123-
/// Optional override for the STRK fee token address.
124-
pub strk_fee_token_address: Option<ContractAddress>,
122+
123+
pub chain_info: ChainInfo,
125124
#[allow(dead_code)]
126125
pub(crate) contract_class_mapping_dumper: Arc<Mutex<Option<StarknetContractClassMapping>>>,
127126
}
@@ -133,8 +132,7 @@ impl Default for RpcStateReader {
133132
config,
134133
block_id: BlockId::Latest,
135134
retry_config: RetryConfig::default(),
136-
chain_id: ChainId::Mainnet,
137-
strk_fee_token_address: None,
135+
chain_info: get_chain_info(&ChainId::Mainnet, None),
138136
contract_class_mapping_dumper: Arc::new(Mutex::new(None)),
139137
}
140138
}
@@ -143,7 +141,7 @@ impl Default for RpcStateReader {
143141
impl RpcStateReader {
144142
pub fn new(
145143
config: &RpcStateReaderConfig,
146-
chain_id: ChainId,
144+
chain_info: ChainInfo,
147145
block_number: BlockNumber,
148146
dump_mode: bool,
149147
) -> Self {
@@ -155,34 +153,35 @@ impl RpcStateReader {
155153
config: config.clone(),
156154
block_id: BlockId::Number(block_number),
157155
retry_config: RetryConfig::default(),
158-
chain_id,
159-
strk_fee_token_address: None,
156+
chain_info,
160157
contract_class_mapping_dumper,
161158
}
162159
}
163160

164-
/// Creates an RpcStateReader from a node URL, chain ID, and block ID.
165-
/// Optionally accepts a STRK fee token address override for custom environments.
161+
/// Creates an RpcStateReader from a node URL, chain info, and block ID.
166162
pub fn new_with_config_from_url(
167163
node_url: String,
168-
chain_id: ChainId,
164+
chain_info: ChainInfo,
169165
block_id: BlockId,
170-
strk_fee_token_address: Option<ContractAddress>,
171166
) -> Self {
172167
let config = RpcStateReaderConfig::from_url(node_url);
173168
let contract_class_mapping_dumper = Arc::new(Mutex::new(None));
174169
Self {
175170
config,
176171
block_id,
177172
retry_config: RetryConfig::default(),
178-
chain_id,
179-
strk_fee_token_address,
173+
chain_info,
180174
contract_class_mapping_dumper,
181175
}
182176
}
183177

184178
pub fn new_for_testing(block_number: BlockNumber) -> Self {
185-
RpcStateReader::new(&get_rpc_state_reader_config(), ChainId::Mainnet, block_number, false)
179+
RpcStateReader::new(
180+
&get_rpc_state_reader_config(),
181+
get_chain_info(&ChainId::Mainnet, None),
182+
block_number,
183+
false,
184+
)
186185
}
187186

188187
// Note: This function is blocking though it is sending a request to the rpc server and waiting
@@ -308,7 +307,7 @@ impl RpcStateReader {
308307
pub fn get_block_context(&self) -> ReexecutionResult<BlockContext> {
309308
Ok(BlockContext::new(
310309
self.get_block_info()?,
311-
get_chain_info(&self.chain_id, self.strk_fee_token_address),
310+
self.chain_info.clone(),
312311
self.get_versioned_constants()?,
313312
BouncerConfig::max(),
314313
))
@@ -540,21 +539,21 @@ impl ConsecutiveRpcStateReaders {
540539
pub fn new(
541540
last_constructed_block_number: BlockNumber,
542541
config: Option<RpcStateReaderConfig>,
543-
chain_id: ChainId,
542+
chain_info: ChainInfo,
544543
dump_mode: bool,
545544
contract_class_manager: ContractClassManager,
546545
) -> Self {
547546
let config = config.unwrap_or(get_rpc_state_reader_config());
548547
Self {
549548
last_block_state_reader: RpcStateReader::new(
550549
&config,
551-
chain_id.clone(),
550+
chain_info.clone(),
552551
last_constructed_block_number,
553552
dump_mode,
554553
),
555554
next_block_state_reader: RpcStateReader::new(
556555
&config,
557-
chain_id,
556+
chain_info,
558557
last_constructed_block_number.next().expect("Overflow in block number"),
559558
dump_mode,
560559
),
@@ -603,8 +602,8 @@ impl ConsecutiveRpcStateReaders {
603602
self,
604603
tx: Transaction,
605604
) -> ReexecutionResult<(TransactionExecutionOutput, StateMaps, BlockContext)> {
606-
let chain_id = self.next_block_state_reader.chain_id.clone();
607-
let transaction_hash = tx.calculate_transaction_hash(&chain_id)?;
605+
let chain_id = &self.next_block_state_reader.chain_info.chain_id;
606+
let transaction_hash = tx.calculate_transaction_hash(chain_id)?;
608607

609608
let blockifier_txs = self
610609
.next_block_state_reader
@@ -640,11 +639,11 @@ impl ConsecutiveRpcStateReaders {
640639
let json_content = read_to_string(&tx_path).unwrap_or_else(|_| {
641640
panic!("Failed to read transaction JSON file: {}.", tx_path)
642641
});
643-
let chain_id = self.next_block_state_reader.chain_id.clone();
642+
let chain_id = &self.next_block_state_reader.chain_info.chain_id;
644643

645644
let json_value: Value = serde_json::from_str(&json_content)?;
646645
let transaction = deserialize_transaction_json_to_starknet_api_tx(json_value)?;
647-
let transaction_hash = transaction.calculate_transaction_hash(&chain_id)?;
646+
let transaction_hash = transaction.calculate_transaction_hash(chain_id)?;
648647

649648
(transaction, transaction_hash)
650649
}
@@ -659,7 +658,7 @@ impl ConsecutiveRpcStateReaders {
659658

660659
/// Writes the reexecution data required to reexecute a block to a JSON file.
661660
pub fn write_block_reexecution_data_to_file(self, full_file_path: &str) {
662-
let chain_id = self.next_block_state_reader.chain_id.clone();
661+
let chain_id = self.next_block_state_reader.chain_info.chain_id.clone();
663662
let block_number = self.next_block_state_reader.get_block_info().unwrap().block_number;
664663

665664
let serializable_data_next_block = self.get_serializable_data_next_block().unwrap();

crates/blockifier_reexecution/src/state_reader/rpc_state_reader_basic_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ use crate::state_reader::rpc_objects::{
1616
RpcSuccessResponse,
1717
};
1818
use crate::state_reader::rpc_state_reader::{RetryConfig, RpcStateReader};
19+
use crate::utils::get_chain_info;
1920

2021
fn rpc_state_reader_from_latest(config: &RpcStateReaderConfig) -> RpcStateReader {
2122
RpcStateReader {
2223
config: config.clone(),
2324
block_id: BlockId::Latest,
2425
retry_config: RetryConfig::default(),
25-
chain_id: ChainId::Mainnet,
26-
strk_fee_token_address: None,
26+
chain_info: get_chain_info(&ChainId::Mainnet, None),
2727
contract_class_mapping_dumper: Arc::new(Mutex::new(None)),
2828
}
2929
}

0 commit comments

Comments
 (0)