Skip to content

Commit

Permalink
feat(starknet_integration_tests): add dummy_recorder binary (#3166)
Browse files Browse the repository at this point in the history
  • Loading branch information
DvirYo-starkware authored Jan 16, 2025
1 parent be32bfa commit b43ae77
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
18 changes: 18 additions & 0 deletions crates/starknet_integration_tests/src/bin/dummy_recorder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::net::SocketAddr;

use starknet_integration_tests::utils::spawn_success_recorder;
use starknet_sequencer_infra::trace_util::configure_tracing;
use tracing::info;

const RECORDER_PORT: u16 = 8080;

#[tokio::main]
async fn main() {
configure_tracing().await;

let socket_address = SocketAddr::from(([0, 0, 0, 0], RECORDER_PORT));
let join_handle = spawn_success_recorder(socket_address);
info!("Spawned the dummy success Recorder successfully!");

join_handle.await.expect("The dummy success Recorder has panicked!!! :(");
}
5 changes: 3 additions & 2 deletions crates/starknet_integration_tests/src/flow_test_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use crate::utils::{
create_mempool_p2p_configs,
create_node_config,
create_state_sync_configs,
spawn_success_recorder,
spawn_local_success_recorder,
};

const SEQUENCER_0: usize = 0;
Expand Down Expand Up @@ -144,7 +144,8 @@ impl FlowSequencerSetup {
) -> Self {
let storage_for_test = StorageTestSetup::new(accounts, &chain_info);

let recorder_url = spawn_success_recorder(available_ports.get_next_port());
let (recorder_url, _join_handle) =
spawn_local_success_recorder(available_ports.get_next_port());
consensus_manager_config.cende_config.recorder_url = recorder_url;

let component_config = ComponentConfig::default();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use tracing::instrument;

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

#[derive(Debug, Copy, Clone)]
pub struct SequencerExecutionId {
Expand Down Expand Up @@ -89,7 +89,8 @@ impl SequencerSetup {
// Creating the storage for the test.
let storage_for_test = StorageTestSetup::new(accounts, &chain_info);

let recorder_url = spawn_success_recorder(available_ports.get_next_port());
let (recorder_url, _join_handle) =
spawn_local_success_recorder(available_ports.get_next_port());
consensus_manager_config.cende_config.recorder_url = recorder_url;

state_sync_config.storage_config = storage_for_test.state_sync_storage_config;
Expand Down
31 changes: 23 additions & 8 deletions crates/starknet_integration_tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ use starknet_sequencer_node::config::config_utils::{
use starknet_sequencer_node::config::node_config::SequencerNodeConfig;
use starknet_state_sync::config::StateSyncConfig;
use starknet_types_core::felt::Felt;
use tokio::task::JoinHandle;
use tracing::{debug, Instrument};
use url::Url;

use crate::integration_test_setup::SequencerExecutionId;
Expand Down Expand Up @@ -146,16 +148,29 @@ pub(crate) fn create_consensus_manager_configs_from_network_configs(
}

// Creates a local recorder server that always returns a success status.
pub fn spawn_success_recorder(port: u16) -> Url {
// [127, 0, 0, 1] is the localhost IP address.
let socket_addr = SocketAddr::from(([127, 0, 0, 1], port));
pub fn spawn_success_recorder(socket_address: SocketAddr) -> JoinHandle<()> {
tokio::spawn(async move {
let router = Router::new()
.route(RECORDER_WRITE_BLOB_PATH, post(move || async { StatusCode::OK.to_string() }));
axum::Server::bind(&socket_addr).serve(router.into_make_service()).await.unwrap();
});
let router = Router::new().route(
RECORDER_WRITE_BLOB_PATH,
post(move || {
async {
debug!("Received a request to write a blob.");
StatusCode::OK.to_string()
}
.instrument(tracing::debug_span!("success recorder write_blob"))
}),
);
axum::Server::bind(&socket_address).serve(router.into_make_service()).await.unwrap();
})
}

Url::parse(&format!("http://{}", socket_addr)).expect("Parsing recorder url fail")
pub fn spawn_local_success_recorder(port: u16) -> (Url, JoinHandle<()>) {
// [127, 0, 0, 1] is the localhost IP address.
let socket_address = SocketAddr::from(([127, 0, 0, 1], port));
// TODO(Tsabary): create a socket-to-url function.
let url = Url::parse(&format!("http://{}", socket_address)).unwrap();
let join_handle = spawn_success_recorder(socket_address);
(url, join_handle)
}

pub fn create_mempool_p2p_configs(chain_id: ChainId, ports: Vec<u16>) -> Vec<MempoolP2pConfig> {
Expand Down

0 comments on commit b43ae77

Please sign in to comment.