Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(starknet_integration_tests): add update revert config #4074

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 2 additions & 41 deletions crates/starknet_integration_tests/src/config_utils.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,8 @@
use std::path::PathBuf;

use papyrus_config::dumping::{combine_config_map_and_pointers, SerializeConfig};
use serde_json::Value;
use starknet_sequencer_node::config::config_utils::{
config_to_preset,
dump_json_data,
RequiredParams,
};
use starknet_sequencer_node::config::node_config::{
SequencerNodeConfig,
CONFIG_NON_POINTERS_WHITELIST,
CONFIG_POINTERS,
};

// TODO(Tsabary): Move here all config-related functions from "integration_test_utils.rs".

const NODE_CONFIG_CHANGES_FILE_PATH: &str = "node_integration_test_config_changes.json";

/// Creates a config file for the sequencer node for an integration test.
pub(crate) fn dump_config_file_changes(
config: &SequencerNodeConfig,
required_params: RequiredParams,
dir: PathBuf,
) -> PathBuf {
// Create the entire mapping of the config and the pointers, without the required params.
let config_as_map = combine_config_map_and_pointers(
config.dump(),
&CONFIG_POINTERS,
&CONFIG_NON_POINTERS_WHITELIST,
)
.unwrap();

// Extract only the required fields from the config map.
let mut preset = config_to_preset(&config_as_map);

// Add the required params to the preset.
add_required_params_to_preset(&mut preset, required_params.as_json());

// Dump the preset to a file, return its path.
let node_config_path = dump_json_data(preset, NODE_CONFIG_CHANGES_FILE_PATH, dir);
assert!(node_config_path.exists(), "File does not exist: {:?}", node_config_path);
node_config_path
}
pub const NODE_CONFIG_CHANGES_FILE_PATH: &str = "node_integration_test_config_changes.json";

/// Merges required parameters into an existing preset JSON object.
///
Expand All @@ -62,7 +23,7 @@ pub(crate) fn dump_config_file_changes(
/// # Panics
/// This function panics if either `preset` or `required_params` is not a JSON dictionary object, or
/// if the `preset` already contains a key from the `required_params`.
fn add_required_params_to_preset(preset: &mut Value, required_params: Value) {
pub fn add_required_params_to_preset(preset: &mut Value, required_params: Value) {
if let (Value::Object(preset_map), Value::Object(required_params_map)) =
(preset, required_params)
{
Expand Down
96 changes: 89 additions & 7 deletions crates/starknet_integration_tests/src/integration_test_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use std::path::{Path, PathBuf};

use blockifier::context::ChainInfo;
use mempool_test_utils::starknet_api_test_utils::AccountTransactionGenerator;
use papyrus_config::dumping::{combine_config_map_and_pointers, SerializeConfig};
use papyrus_storage::StorageConfig;
use starknet_api::block::BlockNumber;
use starknet_api::rpc_transaction::RpcTransaction;
use starknet_api::transaction::TransactionHash;
use starknet_class_manager::test_utils::FileHandles;
Expand All @@ -15,13 +17,23 @@ use starknet_mempool_p2p::config::MempoolP2pConfig;
use starknet_monitoring_endpoint::config::MonitoringEndpointConfig;
use starknet_monitoring_endpoint::test_utils::MonitoringClient;
use starknet_sequencer_node::config::component_config::ComponentConfig;
use starknet_sequencer_node::config::config_utils::{
config_to_preset,
dump_json_data,
RequiredParams,
};
use starknet_sequencer_node::config::node_config::{
SequencerNodeConfig,
CONFIG_NON_POINTERS_WHITELIST,
CONFIG_POINTERS,
};
use starknet_sequencer_node::test_utils::node_runner::NodeRunner;
use starknet_state_sync::config::StateSyncConfig;
use tempfile::{tempdir, TempDir};
use tokio::fs::create_dir_all;
use tracing::instrument;

use crate::config_utils::dump_config_file_changes;
use crate::config_utils::{add_required_params_to_preset, NODE_CONFIG_CHANGES_FILE_PATH};
use crate::state_reader::StorageTestSetup;
use crate::utils::{create_node_config, spawn_local_success_recorder};

Expand Down Expand Up @@ -84,6 +96,10 @@ pub struct ExecutableSetup {
state_sync_storage_handle: Option<TempDir>,
#[allow(dead_code)]
class_manager_storage_handles: Option<FileHandles>,
// The content of the configuration file.
config: SequencerNodeConfig,
// The required params of the configuration file.
required_params: RequiredParams,
}

// TODO(Tsabary/ Nadin): reduce number of args.
Expand Down Expand Up @@ -139,7 +155,7 @@ impl ExecutableSetup {
component_config,
);

let (node_config_dir, node_config_dir_handle) = match config_path_dir {
let (mut node_config_path, node_config_dir_handle) = match config_path_dir {
Some(config_path_dir) => {
create_dir_all(&config_path_dir).await.unwrap();
(config_path_dir, None)
Expand All @@ -149,7 +165,7 @@ impl ExecutableSetup {
(node_config_dir_handle.path().to_path_buf(), Some(node_config_dir_handle))
}
};
let node_config_path = dump_config_file_changes(&config, required_params, node_config_dir);
node_config_path.push(NODE_CONFIG_CHANGES_FILE_PATH);

// Wait for the node to start.
let MonitoringEndpointConfig { ip, port, .. } = config.monitoring_endpoint_config;
Expand All @@ -158,21 +174,87 @@ impl ExecutableSetup {
let HttpServerConfig { ip, port } = config.http_server_config;
let add_tx_http_client = HttpTestClient::new(SocketAddr::from((ip, port)));

Self {
let result = Self {
node_execution_id,
add_tx_http_client,
monitoring_client,
batcher_storage_handle,
batcher_storage_config: config.batcher_config.storage,
batcher_storage_config: config.batcher_config.storage.clone(),
node_config_dir_handle,
node_config_path,
state_sync_storage_handle,
state_sync_storage_config: config.state_sync_config.storage_config,
state_sync_storage_config: config.state_sync_config.storage_config.clone(),
class_manager_storage_handles,
}
config,
required_params,
};
result.update_config_file();
result
}

pub async fn assert_add_tx_success(&self, tx: RpcTransaction) -> TransactionHash {
self.add_tx_http_client.assert_add_tx_success(tx).await
}

// TODO(noamsp): Change this into change_config once we need to change other values in the
// config.
pub fn update_revert_config(&mut self, value: Option<BlockNumber>) {
match value {
Some(value) => {
self.config.state_sync_config.revert_config.revert_up_to_and_including = value;
self.config.consensus_manager_config.revert_config.revert_up_to_and_including =
value;
self.config.state_sync_config.revert_config.should_revert = true;
self.config.consensus_manager_config.revert_config.should_revert = true;
}
// If should revert is false, the revert_up_to_and_including value is irrelevant.
None => {
self.config.state_sync_config.revert_config.should_revert = false;
self.config.consensus_manager_config.revert_config.should_revert = false;
}
}
self.update_config_file();
}

fn update_config_file(&self) {
// Create the entire mapping of the config and the pointers, without the required params.
let config_as_map = combine_config_map_and_pointers(
self.config.dump(),
&CONFIG_POINTERS,
&CONFIG_NON_POINTERS_WHITELIST,
)
.unwrap();

// Extract only the required fields from the config map.
let mut preset = config_to_preset(&config_as_map);

// Add the required params to the preset.
add_required_params_to_preset(&mut preset, self.required_params.as_json());

// Dump the preset to a file, return its path.
let node_config_path = dump_json_data(
preset,
// TODO(Itay): Change dump_json_data to receive the path.
self.node_config_path
.as_path()
.file_name()
.unwrap_or_else(|| {
panic!("Config path {:?} has no file name", self.node_config_path)
})
.to_str()
.unwrap_or_else(|| {
panic!(
"Failed converting {:?} to a string",
self.node_config_path.as_path().file_name(),
)
}),
self.node_config_path
.parent()
.unwrap_or_else(|| panic!("Config path {:?} has no parent.", self.node_config_path))
.to_path_buf(),
);
assert!(node_config_path.exists(), "File does not exist: {:?}", node_config_path);
// TODO(Itay): Change dump_json_data to receive the path and remove this assertion.
assert_eq!(node_config_path, self.node_config_path);
}
}
9 changes: 9 additions & 0 deletions crates/starknet_integration_tests/src/sequencer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ impl IntegrationTestManager {
self.await_alive(5000, 50).await;
}

pub fn update_revert_config_to_all_idle_nodes(&mut self, value: Option<BlockNumber>) {
info!("Updating revert config to all idle nodes.");
self.idle_nodes.values_mut().for_each(|idle_node| {
idle_node.executables.iter_mut().for_each(|executable| {
executable.update_revert_config(value);
});
});
}

pub fn get_node_indices(&self) -> HashSet<usize> {
self.node_indices.clone()
}
Expand Down
Loading