Skip to content

Commit

Permalink
fix(sync): inject a state object instead of using a global state
Browse files Browse the repository at this point in the history
RPC and sync code now gets an explicit state object that is used to store
and query sync state.

This avoids issues with tests, too: previously running
`rpc::tests::syncing::{syncing,not_syncing}` in parallel would lead to
test failures.
  • Loading branch information
kkovaacs committed Mar 4, 2022
1 parent 4d1a9b1 commit 95d67d5
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 79 deletions.
7 changes: 5 additions & 2 deletions crates/pathfinder/src/bin/pathfinder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use pathfinder_lib::{
ethereum, rpc, sequencer, state,
storage::Storage,
};
use std::sync::Arc;
use tracing::info;
use web3::{transports::Http, Web3};

Expand Down Expand Up @@ -38,12 +39,14 @@ async fn main() -> anyhow::Result<()> {

let storage = Storage::migrate(database_path.into()).unwrap();
let sequencer = sequencer::Client::new(network_chain).unwrap();
let sync_state = Arc::new(state::SyncState::new());

let _sync_handle = tokio::spawn(state::sync(
storage.clone(),
eth_transport,
network_chain,
sequencer.clone(),
sync_state.clone(),
));

// TODO: the error could be recovered, but currently it's required for startup. There should
Expand All @@ -56,8 +59,8 @@ async fn main() -> anyhow::Result<()> {
.await
.context("Creating python process for call handling. Have you setup and activate the python `VIRTUAL_ENV` in the `py` directory?")?;

let api =
rpc::api::RpcApi::new(storage, sequencer, network_chain).with_call_handling(call_handle);
let api = rpc::api::RpcApi::new(storage, sequencer, network_chain, sync_state)
.with_call_handling(call_handle);

let (_rpc_handle, local_addr) =
rpc::run_server(config.http_rpc_addr, api).context("Starting the RPC server")?;
Expand Down
Loading

0 comments on commit 95d67d5

Please sign in to comment.