From fbc19ba431387dbcc4b3e0376c5078b3e803151a Mon Sep 17 00:00:00 2001 From: Abdul Basit Date: Wed, 21 Aug 2024 14:03:13 +0500 Subject: [PATCH] rename ver to apiver --- hotshot-state-prover/src/service.rs | 33 +++++++++-------- marketplace-solver/src/api.rs | 4 +- node-metrics/src/api/node_validator/v0/mod.rs | 4 +- sequencer/src/api/endpoints.rs | 37 +++++++++++-------- sequencer/src/api/options.rs | 6 +-- sequencer/src/bin/commitment-task.rs | 6 +-- sequencer/src/bin/espresso-dev-node.rs | 10 ++--- sequencer/src/bin/submit-transactions.rs | 8 ++-- sequencer/src/bin/verify-headers.rs | 11 ++++-- sequencer/src/catchup.rs | 16 ++++---- sequencer/src/hotshot_commitment.rs | 12 +++--- sequencer/src/state_signature.rs | 6 +-- sequencer/src/state_signature/relay_server.rs | 16 ++++---- 13 files changed, 89 insertions(+), 80 deletions(-) diff --git a/hotshot-state-prover/src/service.rs b/hotshot-state-prover/src/service.rs index b0c5d549e..f869e0df5 100644 --- a/hotshot-state-prover/src/service.rs +++ b/hotshot-state-prover/src/service.rs @@ -235,8 +235,8 @@ pub fn load_proving_key(stake_table_capacity: usize) -> ProvingKey { pk } -pub async fn fetch_latest_state( - client: &Client, +pub async fn fetch_latest_state( + client: &Client, ) -> Result { tracing::info!("Fetching the latest state signatures bundle from relay server."); client @@ -307,10 +307,10 @@ pub async fn submit_state_and_proof( Ok(()) } -pub async fn sync_state( +pub async fn sync_state( st: &StakeTable, proving_key: Arc, - relay_server_client: &Client, + relay_server_client: &Client, config: &StateProverConfig, ) -> Result<(), ProverError> { let light_client_address = config.light_client_address; @@ -393,16 +393,16 @@ pub async fn sync_state( Ok(()) } -fn start_http_server( +fn start_http_server( port: u16, light_client_address: Address, - bind_version: Ver, + bind_version: ApiVer, ) -> io::Result<()> { let mut app = tide_disco::App::<_, ServerError>::with_state(()); let toml = toml::from_str::(include_str!("../api/prover-service.toml")) .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; - let mut api = Api::<_, ServerError, Ver>::new(toml) + let mut api = Api::<_, ServerError, ApiVer>::new(toml) .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; api.get("getlightclientcontract", move |_, _| { @@ -416,9 +416,9 @@ fn start_http_server( Ok(()) } -pub async fn run_prover_service( +pub async fn run_prover_service( config: StateProverConfig, - bind_version: Ver, + bind_version: ApiVer, ) -> Result<()> { let stake_table_capacity = config.stake_table_capacity; tracing::info!("Stake table capacity: {}", stake_table_capacity); @@ -431,15 +431,16 @@ pub async fn run_prover_service( run_prover_service_with_stake_table(config, bind_version, st).await } -pub async fn run_prover_service_with_stake_table( +pub async fn run_prover_service_with_stake_table( config: StateProverConfig, - bind_version: Ver, + bind_version: ApiVer, st: Arc>, ) -> Result<()> { tracing::info!("Light client address: {:?}", config.light_client_address); - let relay_server_client = - Arc::new(Client::::new(config.relay_server.clone())); + let relay_server_client = Arc::new(Client::::new( + config.relay_server.clone(), + )); // Start the HTTP server to get a functioning healthcheck before any heavy computations. if let Some(port) = config.port { @@ -466,9 +467,9 @@ pub async fn run_prover_service_with_stake_table( +pub async fn run_prover_once( config: StateProverConfig, - _: Ver, + _: ApiVer, ) -> Result<()> { let st = init_stake_table_from_sequencer(&config.sequencer_url, config.stake_table_capacity) .await @@ -476,7 +477,7 @@ pub async fn run_prover_once( let stake_table_capacity = config.stake_table_capacity; let proving_key = spawn_blocking(move || Arc::new(load_proving_key(stake_table_capacity))).await; - let relay_server_client = Client::::new(config.relay_server.clone()); + let relay_server_client = Client::::new(config.relay_server.clone()); sync_state(&st, proving_key, &relay_server_client, &config) .await diff --git a/marketplace-solver/src/api.rs b/marketplace-solver/src/api.rs index 337dfad62..f8596d6df 100644 --- a/marketplace-solver/src/api.rs +++ b/marketplace-solver/src/api.rs @@ -141,11 +141,11 @@ where Ok(api) } -pub(crate) fn load_api( +pub(crate) fn load_api( path: Option>, default: &str, extensions: impl IntoIterator, -) -> Result, ApiError> { +) -> Result, ApiError> { let mut toml = match path { Some(path) => load_toml(path.as_ref())?, None => toml::from_str(default).map_err(|err| ApiError::CannotReadToml { diff --git a/node-metrics/src/api/node_validator/v0/mod.rs b/node-metrics/src/api/node_validator/v0/mod.rs index 0cae3c51c..490a11cee 100644 --- a/node-metrics/src/api/node_validator/v0/mod.rs +++ b/node-metrics/src/api/node_validator/v0/mod.rs @@ -100,9 +100,9 @@ impl From for LoadApiError { } } -pub(crate) fn load_api( +pub(crate) fn load_api( default: &str, -) -> Result, LoadApiError> { +) -> Result, LoadApiError> { let toml: toml::Value = toml::from_str(default)?; Ok(Api::new(toml)?) } diff --git a/sequencer/src/api/endpoints.rs b/sequencer/src/api/endpoints.rs index 277177b5e..d75473a55 100644 --- a/sequencer/src/api/endpoints.rs +++ b/sequencer/src/api/endpoints.rs @@ -50,9 +50,9 @@ pub struct NamespaceProofQueryData { pub transactions: Vec, } -pub(super) type AvailState = Arc>>; +pub(super) type AvailState = Arc>>; -type AvailabilityApi = Api, availability::Error, Ver>; +type AvailabilityApi = Api, availability::Error, ApiVer>; // TODO (abdul): replace snafu with `this_error` in hotshot query service // Snafu has been replaced by `this_error` everywhere. @@ -127,7 +127,7 @@ where Ok(api) } -type ExplorerApi = Api, explorer::Error, Ver>; +type ExplorerApi = Api, explorer::Error, ApiVer>; pub(super) fn explorer( ) -> Result> @@ -142,7 +142,7 @@ where Ok(api) } -type NodeApi = Api, node::Error, Ver>; +type NodeApi = Api, node::Error, ApiVer>; pub(super) fn node() -> Result> where @@ -156,7 +156,7 @@ where )?; Ok(api) } -pub(super) fn submit() -> Result> +pub(super) fn submit() -> Result> where N: ConnectedNetwork, S: 'static + Send + Sync + WriteState, @@ -164,12 +164,12 @@ where S::State: Send + Sync + SubmitDataSource, { let toml = toml::from_str::(include_str!("../../api/submit.toml"))?; - let mut api = Api::::new(toml)?; + let mut api = Api::::new(toml)?; api.at("submit", |req, state| { async move { let tx = req - .body_auto::(Ver::instance()) + .body_auto::(ApiVer::instance()) .map_err(Error::from_request_error)?; let hash = tx.commit(); @@ -185,16 +185,16 @@ where Ok(api) } -pub(super) fn state_signature( - _: Ver, -) -> Result> +pub(super) fn state_signature( + _: ApiVer, +) -> Result> where N: ConnectedNetwork, S: 'static + Send + Sync + ReadState, S::State: Send + Sync + StateSignatureDataSource, { let toml = toml::from_str::(include_str!("../../api/state_signature.toml"))?; - let mut api = Api::::new(toml)?; + let mut api = Api::::new(toml)?; api.get("get_state_signature", |req, state| { async move { @@ -215,13 +215,15 @@ where Ok(api) } -pub(super) fn catchup(_: Ver) -> Result> +pub(super) fn catchup( + _: ApiVer, +) -> Result> where S: 'static + Send + Sync + ReadState, S::State: Send + Sync + CatchupDataSource, { let toml = toml::from_str::(include_str!("../../api/catchup.toml"))?; - let mut api = Api::::new(toml)?; + let mut api = Api::::new(toml)?; api.get("account", |req, state| { async move { @@ -281,7 +283,8 @@ where Ok(api) } -type MerklizedStateApi = Api, merklized_state::Error, Ver>; +type MerklizedStateApi = + Api, merklized_state::Error, ApiVer>; pub(super) fn merklized_state( ) -> Result> where @@ -305,13 +308,15 @@ where Ok(api) } -pub(super) fn config(_: Ver) -> Result> +pub(super) fn config( + _: ApiVer, +) -> Result> where S: 'static + Send + Sync + ReadState, S::State: Send + Sync + HotShotConfigDataSource, { let toml = toml::from_str::(include_str!("../../api/config.toml"))?; - let mut api = Api::::new(toml)?; + let mut api = Api::::new(toml)?; let env_variables = get_public_env_vars() .map_err(|err| Error::catch_all(StatusCode::INTERNAL_SERVER_ERROR, format!("{err:#}")))?; diff --git a/sequencer/src/api/options.rs b/sequencer/src/api/options.rs index 290b48832..d800e56f1 100644 --- a/sequencer/src/api/options.rs +++ b/sequencer/src/api/options.rs @@ -466,16 +466,16 @@ impl Options { Ok(()) } - fn listen( + fn listen( &self, port: u16, app: App, - bind_version: Ver, + bind_version: ApiVer, ) -> impl Future> where S: Send + Sync + 'static, E: Send + Sync + tide_disco::Error, - Ver: StaticVersionType + 'static, + ApiVer: StaticVersionType + 'static, { let max_connections = self.http.max_connections; diff --git a/sequencer/src/bin/commitment-task.rs b/sequencer/src/bin/commitment-task.rs index 061deb93f..eaaf5a02a 100644 --- a/sequencer/src/bin/commitment-task.rs +++ b/sequencer/src/bin/commitment-task.rs @@ -85,16 +85,16 @@ async fn main() { run_hotshot_commitment_task::(&hotshot_contract_options).await; } -fn start_http_server( +fn start_http_server( port: u16, hotshot_address: Address, - bind_version: Ver, + bind_version: ApiVer, ) -> io::Result<()> { let mut app = tide_disco::App::<(), ServerError>::with_state(()); let toml = toml::from_str::(include_str!("../../api/commitment_task.toml")) .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; - let mut api = Api::<(), ServerError, Ver>::new(toml) + let mut api = Api::<(), ServerError, ApiVer>::new(toml) .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; api.get("gethotshotcontract", move |_, _| { diff --git a/sequencer/src/bin/espresso-dev-node.rs b/sequencer/src/bin/espresso-dev-node.rs index 631097085..7462b1f0d 100644 --- a/sequencer/src/bin/espresso-dev-node.rs +++ b/sequencer/src/bin/espresso-dev-node.rs @@ -367,18 +367,18 @@ impl ReadState for ApiState { } } -async fn run_dev_node_server( +async fn run_dev_node_server( port: u16, contracts: BTreeMap, S>>>, dev_info: DevInfo, - bind_version: Ver, + bind_version: ApiVer, ) -> anyhow::Result<()> { let mut app = tide_disco::App::<_, ServerError>::with_state(ApiState(contracts)); let toml = toml::from_str::(include_str!("../../api/espresso_dev_node.toml")) .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; - let mut api = Api::<_, ServerError, Ver>::new(toml) + let mut api = Api::<_, ServerError, ApiVer>::new(toml) .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; api.get("devinfo", move |_, _| { let info = dev_info.clone(); @@ -388,7 +388,7 @@ async fn run_dev_node_server| { async move { let body = req - .body_auto::(Ver::instance()) + .body_auto::(ApiVer::instance()) .map_err(ServerError::from_request_error)?; // if chain id is not provided, primary L1 light client is used @@ -423,7 +423,7 @@ async fn run_dev_node_server, Ver>(Ver::instance()) + .body_auto::, ApiVer>(ApiVer::instance()) .map_err(ServerError::from_request_error)? .map(|b| b.chain_id); diff --git a/sequencer/src/bin/submit-transactions.rs b/sequencer/src/bin/submit-transactions.rs index c5c325f2f..5001a2763 100644 --- a/sequencer/src/bin/submit-transactions.rs +++ b/sequencer/src/bin/submit-transactions.rs @@ -381,15 +381,15 @@ struct SubmittedTransaction { submitted_at: Instant, } -async fn submit_transactions( +async fn submit_transactions( opt: Options, mut sender: Sender, mut rng: ChaChaRng, - _: Ver, + _: ApiVer, ) { let url = opt.submit_url(); tracing::info!(%url, "starting load generator task"); - let client = Client::::new(url); + let client = Client::::new(url); // Create an exponential distribution for sampling delay times. The distribution should have // mean `opt.delay`, or parameter `\lambda = 1 / opt.delay`. @@ -455,7 +455,7 @@ async fn submit_transactions( } } -async fn server(port: u16, bind_version: Ver) { +async fn server(port: u16, bind_version: ApiVer) { if let Err(err) = App::<(), ServerError>::with_state(()) .serve(format!("0.0.0.0:{port}"), bind_version) .await diff --git a/sequencer/src/bin/verify-headers.rs b/sequencer/src/bin/verify-headers.rs index a1ba2b3ea..9ef794578 100644 --- a/sequencer/src/bin/verify-headers.rs +++ b/sequencer/src/bin/verify-headers.rs @@ -54,11 +54,11 @@ struct Options { logging: logging::Config, } -type SequencerClient = surf_disco::Client; +type SequencerClient = surf_disco::Client; -async fn verify_header( +async fn verify_header( opt: &Options, - seq: &SequencerClient, + seq: &SequencerClient, l1: Option<&Provider>, parent: Option
, height: usize, @@ -117,7 +117,10 @@ async fn verify_header( (header, ok) } -async fn get_header(seq: &SequencerClient, height: usize) -> Header { +async fn get_header( + seq: &SequencerClient, + height: usize, +) -> Header { loop { match seq .get(&format!("availability/header/{height}")) diff --git a/sequencer/src/catchup.rs b/sequencer/src/catchup.rs index 035b1809f..5950a6bdf 100644 --- a/sequencer/src/catchup.rs +++ b/sequencer/src/catchup.rs @@ -32,12 +32,12 @@ use crate::{ // This newtype is probably not worth having. It's only used to be able to log // URLs before doing requests. #[derive(Debug, Clone)] -struct Client { - inner: surf_disco::Client, +struct Client { + inner: surf_disco::Client, url: Url, } -impl Client { +impl Client { pub fn new(url: Url) -> Self { Self { inner: surf_disco::Client::new(url.clone()), @@ -45,7 +45,7 @@ impl Client { } } - pub fn get(&self, route: &str) -> Request { + pub fn get(&self, route: &str) -> Request { self.inner.get(route) } } @@ -66,12 +66,12 @@ pub(crate) async fn local_and_remote( } #[derive(Debug, Clone, Default)] -pub struct StatePeers { - clients: Vec>, +pub struct StatePeers { + clients: Vec>, backoff: BackoffParams, } -impl StatePeers { +impl StatePeers { pub fn from_urls(urls: Vec, backoff: BackoffParams) -> Self { if urls.is_empty() { panic!("Cannot create StatePeers with no peers"); @@ -116,7 +116,7 @@ impl StatePeers { } #[async_trait] -impl StateCatchup for StatePeers { +impl StateCatchup for StatePeers { #[tracing::instrument(skip(self))] async fn try_fetch_account( &self, diff --git a/sequencer/src/hotshot_commitment.rs b/sequencer/src/hotshot_commitment.rs index 3b220e02a..ba9f291ac 100644 --- a/sequencer/src/hotshot_commitment.rs +++ b/sequencer/src/hotshot_commitment.rs @@ -22,7 +22,7 @@ use crate::SeqTypes; const RETRY_DELAY: Duration = Duration::from_secs(1); -type HotShotClient = surf_disco::Client; +type HotShotClient = surf_disco::Client; #[derive(Clone, Debug)] pub struct CommitmentTaskOptions { @@ -62,9 +62,9 @@ pub struct CommitmentTaskOptions { } /// main logic for the commitment task, which sync the latest blocks from HotShot to L1 contracts -pub async fn run_hotshot_commitment_task(opt: &CommitmentTaskOptions) { +pub async fn run_hotshot_commitment_task(opt: &CommitmentTaskOptions) { // init a client connecting to HotShot query service - let hotshot = HotShotClient::::builder( + let hotshot = HotShotClient::::builder( opt.query_service_url .clone() .expect("query service URL must be specified"), @@ -87,8 +87,8 @@ pub async fn run_hotshot_commitment_task(opt: &Commitmen sequence(hotshot, contract, opt.delay).await; } -async fn sequence( - hotshot: HotShotClient, +async fn sequence( + hotshot: HotShotClient, contract: HotShot, delay: Option, ) { @@ -147,7 +147,7 @@ trait HotShotDataSource { } #[async_trait] -impl HotShotDataSource for HotShotClient { +impl HotShotDataSource for HotShotClient { type Error = hotshot_query_service::Error; async fn block_height(&self) -> Result { diff --git a/sequencer/src/state_signature.rs b/sequencer/src/state_signature.rs index 8488bdddc..cf4e7e041 100644 --- a/sequencer/src/state_signature.rs +++ b/sequencer/src/state_signature.rs @@ -38,7 +38,7 @@ pub mod relay_server; const SIGNATURE_STORAGE_CAPACITY: usize = 100; #[derive(Debug)] -pub struct StateSigner { +pub struct StateSigner { /// Key pair for signing a new light client state key_pair: StateKeyPair, @@ -49,10 +49,10 @@ pub struct StateSigner { stake_table_comm: StakeTableCommitmentType, /// The state relay server url - relay_server_client: Option>, + relay_server_client: Option>, } -impl StateSigner { +impl StateSigner { pub fn new(key_pair: StateKeyPair, stake_table_comm: StakeTableCommitmentType) -> Self { Self { key_pair, diff --git a/sequencer/src/state_signature/relay_server.rs b/sequencer/src/state_signature/relay_server.rs index 082482cc9..de61ba92d 100644 --- a/sequencer/src/state_signature/relay_server.rs +++ b/sequencer/src/state_signature/relay_server.rs @@ -183,16 +183,16 @@ pub struct Options { } /// Set up APIs for relay server -fn define_api( +fn define_api( options: &Options, - _: Ver, -) -> Result, ApiError> + _: ApiVer, +) -> Result, ApiError> where State: 'static + Send + Sync + ReadState + WriteState, ::State: Send + Sync + StateRelayServerDataSource, { let mut api = match &options.api_path { - Some(path) => Api::::from_file(path)?, + Some(path) => Api::::from_file(path)?, None => { let toml: toml::Value = toml::from_str(include_str!( "../../api/state_relay_server.toml" @@ -200,7 +200,7 @@ where .map_err(|err| ApiError::CannotReadToml { reason: err.to_string(), })?; - Api::::new(toml)? + Api::::new(toml)? } }; @@ -214,7 +214,7 @@ where state: lcstate, signature, } = req - .body_auto::(Ver::instance()) + .body_auto::(ApiVer::instance()) .map_err(Error::from_request_error)?; state.post_signature(key, lcstate, signature) } @@ -224,11 +224,11 @@ where Ok(api) } -pub async fn run_relay_server( +pub async fn run_relay_server( shutdown_listener: Option>, threshold: U256, url: Url, - bind_version: Ver, + bind_version: ApiVer, ) -> std::io::Result<()> { let options = Options::default();