From a15cd2cd6f717c3b0a092f0f29b5eff0534536c1 Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Thu, 1 Feb 2024 17:02:53 -0300 Subject: [PATCH 01/49] [WIP] Gas oracle to convert native token price --- Cargo.lock | 17 ++ Cargo.toml | 2 + core/bin/erc20_fetcher/Cargo.toml | 21 ++ core/bin/erc20_fetcher/src/lib.rs | 59 ++++ core/bin/erc20_fetcher/src/main.rs | 45 +++ core/bin/erc20_fetcher/src/rpc.rs | 20 ++ core/bin/zksync_server/src/main.rs | 2 + core/lib/config/src/configs/mod.rs | 1 + .../src/configs/native_erc20_fetcher.rs | 9 + core/lib/env_config/src/lib.rs | 1 + .../env_config/src/native_erc20_fetcher.rs | 8 + .../lib/zksync_core/src/consensus/testonly.rs | 1 + core/lib/zksync_core/src/lib.rs | 46 +++ .../src/native_erc20_fetcher/mod.rs | 112 ++++++++ .../zksync_core/src/state_keeper/keeper.rs | 10 +- core/lib/zksync_core/src/state_keeper/mod.rs | 7 +- .../src/state_keeper/tests/tester.rs | 1 + core/lib/zksync_core/src/sync_layer/tests.rs | 1 + core/lib/zksync_core/src/temp_config_store.rs | 2 + etc/env/l1-inits/.init.env | 28 +- yarn.lock | 269 +++++++++++------- 21 files changed, 563 insertions(+), 99 deletions(-) create mode 100644 core/bin/erc20_fetcher/Cargo.toml create mode 100644 core/bin/erc20_fetcher/src/lib.rs create mode 100644 core/bin/erc20_fetcher/src/main.rs create mode 100644 core/bin/erc20_fetcher/src/rpc.rs create mode 100644 core/lib/config/src/configs/native_erc20_fetcher.rs create mode 100644 core/lib/env_config/src/native_erc20_fetcher.rs create mode 100644 core/lib/zksync_core/src/native_erc20_fetcher/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 6aae513b69a..8a89d5954a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2265,6 +2265,23 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "erc20_fetcher" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap 4.4.6", + "futures 0.3.28", + "jsonrpsee", + "reqwest", + "serde", + "serde_json", + "thiserror", + "tokio", + "tracing", + "tracing-subscriber", +] + [[package]] name = "errno" version = "0.3.5" diff --git a/Cargo.toml b/Cargo.toml index cd823972a01..f8735631aea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,8 @@ members = [ "core/bin/system-constants-generator", "core/bin/verified_sources_fetcher", "core/bin/zksync_server", + # For native ERC20 support + "core/bin/erc20_fetcher", # Libraries "core/lib/zksync_core", "core/lib/basic_types", diff --git a/core/bin/erc20_fetcher/Cargo.toml b/core/bin/erc20_fetcher/Cargo.toml new file mode 100644 index 00000000000..2a9933f291e --- /dev/null +++ b/core/bin/erc20_fetcher/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "erc20_fetcher" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +jsonrpsee = { version = "0.21.0", features = [ + "macros", "server", "http-client" +] } +serde = "1.0" +serde_json = "1.0" +thiserror = "1.0" +anyhow = "1.0" +clap = { version = "4.2.4", features = ["derive"] } +tokio = { version = "1", features = ["full"] } +tracing = "0.1" +tracing-subscriber = "0.3" +futures = "0.3" +reqwest = { version = "0.11", features = ["json", "blocking"] } diff --git a/core/bin/erc20_fetcher/src/lib.rs b/core/bin/erc20_fetcher/src/lib.rs new file mode 100644 index 00000000000..c28a606d096 --- /dev/null +++ b/core/bin/erc20_fetcher/src/lib.rs @@ -0,0 +1,59 @@ +use jsonrpsee::core::{async_trait, RpcResult}; +pub use rpc::RpcApiServer; +use serde::{Deserialize, Serialize}; +mod rpc; + +pub struct RpcApiBackend { + erc20_symbol: String, + erc20_name: String, +} + +impl RpcApiBackend { + pub fn new(erc20_symbol: String, erc20_name: String) -> Self { + Self { + erc20_symbol, + erc20_name, + } + } +} + +#[derive(Deserialize, Serialize, Debug)] +struct EthValue { + eth: serde_json::value::Number, +} +#[derive(Deserialize, Serialize, Debug)] +struct Request { + dai: EthValue, +} + +#[async_trait] +impl RpcApiServer for RpcApiBackend { + async fn conversion_rate(&self) -> RpcResult { + let url = + "https://api.coingecko.com/api/v3/simple/price?x_cg_demo_api_key=CG-FEgodj8AJN55Va4c6uKPUWLe&ids=dai&vs_currencies=eth"; + let response = reqwest::get(url) + .await + .expect("Failed request for ERC-20") + .json::() + .await + .unwrap(); + RpcResult::Ok(response.dai.eth.to_string()) + } + fn token_symbol(&self) -> RpcResult { + RpcResult::Ok(self.erc20_symbol.clone()) + } + fn token_name(&self) -> RpcResult { + RpcResult::Ok(self.erc20_name.clone()) + } + // async fn price(&self) -> RpcResult { + // let url = + // "https://api.coingecko.com/api/v3/simple/price?x_cg_demo_api_key=CG-FEgodj8AJN55Va4c6uKPUWLe&ids=dai&vs_currencies=usd"; + // let response = reqwest::get(url) + // .await + // .expect("Failed request for ERC-20") + // .json::() + // .await + // .unwrap(); + // RpcResult::Ok(response.dai.eth.to_string()) + // } +} diff --git a/core/bin/erc20_fetcher/src/main.rs b/core/bin/erc20_fetcher/src/main.rs new file mode 100644 index 00000000000..bef6d43dda0 --- /dev/null +++ b/core/bin/erc20_fetcher/src/main.rs @@ -0,0 +1,45 @@ +use clap::Parser; +use erc20_fetcher::{RpcApiBackend, RpcApiServer}; +use jsonrpsee::{ + server::{ServerBuilder, ServerHandle}, + RpcModule, +}; +use tokio::net::ToSocketAddrs; +use tracing::{error, info}; + +#[derive(Parser)] +struct Cli { + #[arg(long, help = "the port where the fetcher will run.")] + port: u16, + #[arg(long, help = "the name of the ERC20 token.")] + name: String, + #[arg(long, help = "the symbol of the ERC20 token.")] + symbol: String, +} + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + tracing_subscriber::fmt::init(); + let opt = Cli::parse(); + let addr = format!("127.0.0.1:{}", opt.port); + let rpc_module = RpcApiBackend::new(opt.symbol, opt.name).into_rpc(); + + let handle = start_server(addr, rpc_module).await; + match handle { + Ok(handle) => { + info!("Server started and listening on port: {}", opt.port); + handle.stopped().await; + } + Err(e) => error!("An error has occurred while starting the server: {}", e), + } + Ok(()) +} + +async fn start_server( + addr: impl ToSocketAddrs, + module: RpcModule, +) -> Result { + let server = ServerBuilder::default().build(addr).await?; + let server_handle = server.start(module); + Ok(server_handle) +} diff --git a/core/bin/erc20_fetcher/src/rpc.rs b/core/bin/erc20_fetcher/src/rpc.rs new file mode 100644 index 00000000000..2d2c543853d --- /dev/null +++ b/core/bin/erc20_fetcher/src/rpc.rs @@ -0,0 +1,20 @@ +use jsonrpsee::{core::RpcResult, proc_macros::rpc}; + +#[rpc(server, client, namespace = "fetcher")] +pub trait RpcApi { + /// Returns the NativeERC20/ETH conversion rate. + #[method(name = "conversionRate")] + async fn conversion_rate(&self) -> RpcResult; + + // /// Returns the ERC20 token price in USD. + // #[method(name = "tokenPrice")] + // async fn price(&self) -> RpcResult; + + /// returns the symbol of the ERC20. + #[method(name = "tokenSymbol")] + fn token_symbol(&self) -> RpcResult; + + /// returns the name of the ERC20. + #[method(name = "tokenName")] + fn token_name(&self) -> RpcResult; +} diff --git a/core/bin/zksync_server/src/main.rs b/core/bin/zksync_server/src/main.rs index ffaa08ea090..068d1190218 100644 --- a/core/bin/zksync_server/src/main.rs +++ b/core/bin/zksync_server/src/main.rs @@ -11,6 +11,7 @@ use zksync_config::{ }, fri_prover_group::FriProverGroupConfig, house_keeper::HouseKeeperConfig, + native_erc20_fetcher::NativeErc20FetcherConfig, FriProofCompressorConfig, FriProverConfig, FriWitnessGeneratorConfig, PrometheusConfig, ProofDataHandlerConfig, WitnessGeneratorConfig, }, @@ -119,6 +120,7 @@ async fn main() -> anyhow::Result<()> { eth_watch_config: ETHWatchConfig::from_env().ok(), gas_adjuster_config: GasAdjusterConfig::from_env().ok(), object_store_config: ObjectStoreConfig::from_env().ok(), + native_erc20_fetcher_config: NativeErc20FetcherConfig::from_env().ok(), }; let postgres_config = configs.postgres_config.clone().context("PostgresConfig")?; diff --git a/core/lib/config/src/configs/mod.rs b/core/lib/config/src/configs/mod.rs index fc0e7eb6d4d..93dc0e787fb 100644 --- a/core/lib/config/src/configs/mod.rs +++ b/core/lib/config/src/configs/mod.rs @@ -36,6 +36,7 @@ pub mod fri_prover_group; pub mod fri_witness_generator; pub mod fri_witness_vector_generator; pub mod house_keeper; +pub mod native_erc20_fetcher; pub mod object_store; pub mod proof_data_handler; pub mod snapshots_creator; diff --git a/core/lib/config/src/configs/native_erc20_fetcher.rs b/core/lib/config/src/configs/native_erc20_fetcher.rs new file mode 100644 index 00000000000..19c7c97beec --- /dev/null +++ b/core/lib/config/src/configs/native_erc20_fetcher.rs @@ -0,0 +1,9 @@ +use serde::Deserialize; + +#[derive(Debug, Clone, Deserialize, PartialEq)] +pub struct NativeErc20FetcherConfig { + pub poll_interval: u64, + pub host: String, + pub name: String, + pub symbol: String, +} diff --git a/core/lib/env_config/src/lib.rs b/core/lib/env_config/src/lib.rs index fa2bb237191..911426cf90d 100644 --- a/core/lib/env_config/src/lib.rs +++ b/core/lib/env_config/src/lib.rs @@ -17,6 +17,7 @@ mod fri_prover_group; mod fri_witness_generator; mod fri_witness_vector_generator; mod house_keeper; +pub mod native_erc20_fetcher; pub mod object_store; mod proof_data_handler; mod snapshots_creator; diff --git a/core/lib/env_config/src/native_erc20_fetcher.rs b/core/lib/env_config/src/native_erc20_fetcher.rs new file mode 100644 index 00000000000..e1d64519e05 --- /dev/null +++ b/core/lib/env_config/src/native_erc20_fetcher.rs @@ -0,0 +1,8 @@ +use crate::{envy_load, FromEnv}; +use zksync_config::configs::native_erc20_fetcher::NativeErc20FetcherConfig; + +impl FromEnv for NativeErc20FetcherConfig { + fn from_env() -> anyhow::Result { + envy_load("native_erc20_fetcher", "NATIVE_TOKEN_FETCHER_") + } +} diff --git a/core/lib/zksync_core/src/consensus/testonly.rs b/core/lib/zksync_core/src/consensus/testonly.rs index ebbd43ee920..c141071de77 100644 --- a/core/lib/zksync_core/src/consensus/testonly.rs +++ b/core/lib/zksync_core/src/consensus/testonly.rs @@ -375,6 +375,7 @@ impl StateKeeperRunner { Box::new(io), Box::new(MockBatchExecutorBuilder), Box::new(NoopSealer), + Box::new(None), ) .run(), ); diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index e45bf6b6712..a81c404f51d 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -5,6 +5,7 @@ use std::{net::Ipv4Addr, str::FromStr, sync::Arc, time::Instant}; use anyhow::Context as _; use fee_model::MainNodeFeeInputProvider; use futures::channel::oneshot; +use native_erc20_fetcher::Erc20Fetcher; use prometheus_exporter::PrometheusExporterConfig; use temp_config_store::TempConfigStore; use tokio::{sync::watch, task::JoinHandle}; @@ -69,6 +70,7 @@ use crate::{ l1_gas_price::{GasAdjusterSingleton, L1GasPriceProvider}, metadata_calculator::{MetadataCalculator, MetadataCalculatorConfig}, metrics::{InitStage, APP_METRICS}, + native_erc20_fetcher::{NativeErc20Fetcher, NativeErc20FetcherSingleton}, state_keeper::{ create_state_keeper, MempoolFetcher, MempoolGuard, MiniblockSealer, SequencerSealer, }, @@ -88,6 +90,7 @@ pub mod house_keeper; pub mod l1_gas_price; pub mod metadata_calculator; mod metrics; +pub mod native_erc20_fetcher; pub mod proof_data_handler; pub mod reorg_detector; pub mod state_keeper; @@ -230,6 +233,8 @@ pub enum Component { Housekeeper, /// Component for exposing APIs to prover for providing proof generation data and accepting proofs. ProofDataHandler, + /// Native ERC20 fetcher + NativeERC20Fetcher, } #[derive(Debug)] @@ -264,6 +269,7 @@ impl FromStr for Components { "eth_tx_aggregator" => Ok(Components(vec![Component::EthTxAggregator])), "eth_tx_manager" => Ok(Components(vec![Component::EthTxManager])), "proof_data_handler" => Ok(Components(vec![Component::ProofDataHandler])), + "native_erc20_fetcher" => Ok(Components(vec![Component::NativeERC20Fetcher])), other => Err(format!("{} is not a valid component name", other)), } } @@ -325,6 +331,19 @@ pub async fn initialize_components( let mut gas_adjuster = GasAdjusterSingleton::new(eth_client_config.web3_url.clone(), gas_adjuster_config); + // spawn the native ERC20 fetcher if it is enabled + let mut fetcher_component = if components.contains(&Component::NativeERC20Fetcher) { + let fetcher = NativeErc20FetcherSingleton::new( + configs + .native_erc20_fetcher_config + .clone() + .context("native_erc20_fetcher_config")?, + ); + + Some(fetcher) + } else { + None + }; let (stop_sender, stop_receiver) = watch::channel(false); let (cb_sender, cb_receiver) = oneshot::channel(); @@ -482,6 +501,21 @@ pub async fn initialize_components( .get_or_init() .await .context("gas_adjuster.get_or_init()")?; + + let native_erc20_fetcher = if let Some(ref mut fetcher_singleton) = fetcher_component { + let fetcher = fetcher_singleton + .get_or_init() + .await + .context("fetcher.get_or_init()")?; + Some(fetcher) + } else { + None + }; + + let erc20_fetcher_dyn: Option> = native_erc20_fetcher + .as_ref() + .map(|fetcher| fetcher.clone() as Arc); + add_state_keeper_to_task_futures( &mut task_futures, &postgres_config, @@ -495,6 +529,7 @@ pub async fn initialize_components( &configs.mempool_config.clone().context("mempool_config")?, bounded_gas_adjuster, store_factory.create_store().await, + erc20_fetcher_dyn, stop_receiver.clone(), ) .await @@ -671,6 +706,15 @@ pub async fn initialize_components( if let Some(task) = gas_adjuster.run_if_initialized(stop_receiver.clone()) { task_futures.push(task); } + + // check if the native ERC20 fetcher is enabled and run it if it is + fetcher_component + .and_then(|c| c.run_if_initialized(stop_receiver.clone())) + .into_iter() + .for_each(|handle| { + task_futures.push(handle); + }); + Ok((task_futures, stop_sender, cb_receiver, health_check_handle)) } @@ -685,6 +729,7 @@ async fn add_state_keeper_to_task_futures, object_store: Arc, + native_erc20_fetcher: Option>, stop_receiver: watch::Receiver, ) -> anyhow::Result<()> { let pool_builder = ConnectionPool::singleton(postgres_config.master_url()?); @@ -728,6 +773,7 @@ async fn add_state_keeper_to_task_futures); + +impl From for Error { + fn from(err: anyhow::Error) -> Self { + Self(Arc::new(err)) + } +} + +#[async_trait] +pub trait Erc20Fetcher: 'static + std::fmt::Debug + Send + Sync { + async fn conversion_rate(&self) -> anyhow::Result; + async fn token_price(&self) -> anyhow::Result; +} + +pub(crate) struct NativeErc20FetcherSingleton { + native_erc20_fetcher_config: NativeErc20FetcherConfig, + singleton: OnceCell, Error>>, +} + +impl NativeErc20FetcherSingleton { + pub fn new(native_erc20_fetcher_config: NativeErc20FetcherConfig) -> Self { + Self { + native_erc20_fetcher_config, + singleton: OnceCell::new(), + } + } + + pub async fn get_or_init(&mut self) -> Result, Error> { + let adjuster = self + .singleton + .get_or_init(|| async { + let fetcher = NativeErc20Fetcher::new(self.native_erc20_fetcher_config.clone()); + Ok(Arc::new(fetcher)) + }) + .await; + adjuster.clone() + } + + pub fn run_if_initialized( + self, + stop_signal: watch::Receiver, + ) -> Option>> { + let fetcher = self.singleton.get()?.clone(); + Some(tokio::spawn(async move { fetcher?.run(stop_signal).await })) + } +} + +#[derive(Debug)] +pub(crate) struct NativeErc20Fetcher { + // TODO: we probably need to add a http client here + // to avoid creating a new one for each request + pub config: NativeErc20FetcherConfig, + pub latest_to_eth_conversion_rate: Arc>, + pub latest_token_price: Arc>, +} + +impl NativeErc20Fetcher { + pub(crate) fn new(config: NativeErc20FetcherConfig) -> Self { + Self { + config, + latest_to_eth_conversion_rate: Arc::new(Mutex::new(0.0)), + latest_token_price: Arc::new(Mutex::new(0.0)), + } + } + + pub(crate) async fn run(&self, stop_receiver: watch::Receiver) -> anyhow::Result<()> { + loop { + if *stop_receiver.borrow() { + tracing::info!("Stop signal received, eth_tx_manager is shutting down"); + break; + } + // TODO: update: + // - latest_to_eth_conversion_rate + // - latest_token_price + } + + Ok(()) + } + + // TODO: implement the actual fetch logic + pub(crate) async fn fetch_conversion_rate(&self) -> anyhow::Result { + todo!() + } + + pub(crate) async fn fetch_token_price(&self) -> anyhow::Result { + todo!() + } +} + +#[async_trait] +impl Erc20Fetcher for NativeErc20Fetcher { + async fn conversion_rate(&self) -> anyhow::Result { + anyhow::Ok(self.latest_to_eth_conversion_rate.lock().await.clone()) + } + + async fn token_price(&self) -> anyhow::Result { + anyhow::Ok(self.latest_token_price.lock().await.clone()) + } +} diff --git a/core/lib/zksync_core/src/state_keeper/keeper.rs b/core/lib/zksync_core/src/state_keeper/keeper.rs index 35aaf77cb5a..33f09cf595a 100644 --- a/core/lib/zksync_core/src/state_keeper/keeper.rs +++ b/core/lib/zksync_core/src/state_keeper/keeper.rs @@ -1,11 +1,13 @@ use std::{ convert::Infallible, + sync::Arc, time::{Duration, Instant}, }; use anyhow::Context as _; use multivm::interface::{Halt, L1BatchEnv, SystemEnv}; use tokio::sync::watch; +use zksync_config::configs::native_erc20_fetcher; use zksync_types::{ block::MiniblockExecutionData, l2::TransactionType, protocol_version::ProtocolUpgradeTx, storage_writes_deduplicator::StorageWritesDeduplicator, L1BatchNumber, Transaction, @@ -20,7 +22,10 @@ use super::{ types::ExecutionMetricsForCriteria, updates::UpdatesManager, }; -use crate::gas_tracker::gas_count_from_writes; +use crate::{ + gas_tracker::gas_count_from_writes, + native_erc20_fetcher::{Erc20Fetcher, NativeErc20Fetcher}, +}; /// Amount of time to block on waiting for some resource. The exact value is not really important, /// we only need it to not block on waiting indefinitely and be able to process cancellation requests. @@ -59,6 +64,7 @@ pub struct ZkSyncStateKeeper { io: Box, batch_executor_base: Box, sealer: Box, + native_erc20_fetcher: Box>>, } impl ZkSyncStateKeeper { @@ -67,12 +73,14 @@ impl ZkSyncStateKeeper { io: Box, batch_executor_base: Box, sealer: Box, + native_erc20_fetcher: Box>>, ) -> Self { Self { stop_receiver, io, batch_executor_base, sealer, + native_erc20_fetcher, } } diff --git a/core/lib/zksync_core/src/state_keeper/mod.rs b/core/lib/zksync_core/src/state_keeper/mod.rs index b1534d9612f..5f7ed623bdb 100644 --- a/core/lib/zksync_core/src/state_keeper/mod.rs +++ b/core/lib/zksync_core/src/state_keeper/mod.rs @@ -17,7 +17,10 @@ pub use self::{ pub(crate) use self::{ mempool_actor::MempoolFetcher, seal_criteria::SequencerSealer, types::MempoolGuard, }; -use crate::fee_model::BatchFeeModelInputProvider; +use crate::{ + fee_model::BatchFeeModelInputProvider, + native_erc20_fetcher::{Erc20Fetcher, NativeErc20Fetcher}, +}; mod batch_executor; pub(crate) mod extractors; @@ -43,6 +46,7 @@ pub(crate) async fn create_state_keeper( batch_fee_input_provider: Arc, miniblock_sealer_handle: MiniblockSealerHandle, object_store: Arc, + native_erc20_fetcher: Option>, stop_receiver: watch::Receiver, ) -> ZkSyncStateKeeper { let batch_executor_base = MainBatchExecutorBuilder::new( @@ -75,5 +79,6 @@ pub(crate) async fn create_state_keeper( Box::new(io), Box::new(batch_executor_base), Box::new(sealer), + Box::new(native_erc20_fetcher), ) } diff --git a/core/lib/zksync_core/src/state_keeper/tests/tester.rs b/core/lib/zksync_core/src/state_keeper/tests/tester.rs index 9ac886270d3..6459205e90b 100644 --- a/core/lib/zksync_core/src/state_keeper/tests/tester.rs +++ b/core/lib/zksync_core/src/state_keeper/tests/tester.rs @@ -201,6 +201,7 @@ impl TestScenario { Box::new(io), Box::new(batch_executor_base), Box::new(sealer), + Box::new(None), ); let sk_thread = tokio::spawn(sk.run()); diff --git a/core/lib/zksync_core/src/sync_layer/tests.rs b/core/lib/zksync_core/src/sync_layer/tests.rs index 3e508accefc..1142e47abea 100644 --- a/core/lib/zksync_core/src/sync_layer/tests.rs +++ b/core/lib/zksync_core/src/sync_layer/tests.rs @@ -85,6 +85,7 @@ impl StateKeeperHandles { Box::new(io), Box::new(batch_executor_base), Box::new(NoopSealer), + Box::new(None), ); Self { stop_sender, diff --git a/core/lib/zksync_core/src/temp_config_store.rs b/core/lib/zksync_core/src/temp_config_store.rs index cfa9ceed379..98fd6c3b33e 100644 --- a/core/lib/zksync_core/src/temp_config_store.rs +++ b/core/lib/zksync_core/src/temp_config_store.rs @@ -7,6 +7,7 @@ use zksync_config::{ }, fri_prover_group::FriProverGroupConfig, house_keeper::HouseKeeperConfig, + native_erc20_fetcher::NativeErc20FetcherConfig, FriProofCompressorConfig, FriProverConfig, FriWitnessGeneratorConfig, PrometheusConfig, ProofDataHandlerConfig, WitnessGeneratorConfig, }, @@ -44,4 +45,5 @@ pub struct TempConfigStore { pub eth_watch_config: Option, pub gas_adjuster_config: Option, pub object_store_config: Option, + pub native_erc20_fetcher_config: Option, } diff --git a/etc/env/l1-inits/.init.env b/etc/env/l1-inits/.init.env index c582a2e6d17..5a8307e01d5 100644 --- a/etc/env/l1-inits/.init.env +++ b/etc/env/l1-inits/.init.env @@ -1,6 +1,30 @@ -CONTRACTS_LATEST_PROTOCOL_VERSION=23 +CONTRACTS_LATEST_PROTOCOL_VERSION=22 +CONTRACTS_CREATE2_FACTORY_ADDR=0x3c4CE2E9D8b03BbCd568E47465A483EE86893c49 +CONTRACTS_VERIFIER_ADDR=0x42758Ee9dd7eaB0c8462443fDe050b583eA7321e +CONTRACTS_L1_MULTICALL3_ADDR=0xF673f2EAcc34A298a6a40AeE4dab90fdDeD83Bae CONTRACTS_GENESIS_ROOT=0xa783f96aedee88117bc4e3a006f6e3c4d89199db4fa66fe01cd009f4c92ea029 CHAIN_STATE_KEEPER_BOOTLOADER_HASH=0x010007ed0e328b940e241f7666a6303b7ffd4e3fd7e8c154d6e7556befe6cd6d CHAIN_STATE_KEEPER_DEFAULT_AA_HASH=0x0100055b7a8be90522251be8be1a186464d056462973502ac8a0437c85e4d2a9 CONTRACTS_GENESIS_BATCH_COMMITMENT=0xda81b5c95796a0a7afbe3c11637617364a5bf0e2947ad89a32d1535f9929eda5 -CONTRACTS_GENESIS_ROLLUP_LEAF_INDEX=25 \ No newline at end of file +CONTRACTS_GENESIS_ROLLUP_LEAF_INDEX=25 +CONTRACTS_L1_WETH_TOKEN_ADDR=0x4A470422bFf67C34a3A565106118023059fa4E34 +CONTRACTS_BRIDGEHUB_PROXY_ADDR=0x7a7C7c73927B7ccA796a340851F639B3511F2D04 +CONTRACTS_BRIDGEHUB_IMPL_ADDR=0x7F35af739d185a4EaC39f78E4Bbe8F1Af7B10C02 +CONTRACTS_STATE_TRANSITION_PROXY_ADDR=0x43eaca081D9c9511Cc1F5007C219E3fBaCbe2c2C +CONTRACTS_STATE_TRANSITION_IMPL_ADDR=0x3c7A51295cf1C877F21bbFaa70cd38B71fD62409 +CONTRACTS_ADMIN_FACET_ADDR=0x31773CfF68fe6248275430b9AfD8AbB292D29804 +CONTRACTS_DIAMOND_UPGRADE_INIT_ADDR=0x39FD4D26A2eb7e38d0607d6C36581FCBF40D53ED +CONTRACTS_DIAMOND_INIT_ADDR=0x6F7B294f0da192ffcBE519bFFF167a92226eB787 +CONTRACTS_DEFAULT_UPGRADE_ADDR=0x226238E3Fd7bd1C3BBB2De75e151796611f467F6 +CONTRACTS_GENESIS_UPGRADE_ADDR=0x9703D7eb1561FC6f49C95487323a0Ebd2E3E0F91 +CONTRACTS_GOVERNANCE_ADDR=0x2ee9094257c9Dfac3A173D3875D9307758d4563C +CONTRACTS_MAILBOX_FACET_ADDR=0x84124338Dc6370847802F7Ee7afB992D29788c0f +CONTRACTS_EXECUTOR_FACET_ADDR=0xE29343E58f154aB62e0DdDE3D5a929d2ef6118ac +CONTRACTS_GETTERS_FACET_ADDR=0x599f2f39715D6dDCaE249692aaBE1b8598D14349 +CONTRACTS_VALIDATOR_TIMELOCK_ADDR=0x58e9DC2122715322cA983859d1B8A2Df8384e2e5 +CONTRACTS_TRANSPARENT_PROXY_ADMIN_ADDR=0x20410058241d1c4C5f7C04753BD4713B04f19423 +CONTRACTS_L1_ERC20_BRIDGE_PROXY_ADDR=0x648892bCeF482B2B98A7434066680FFFA6Bc2523 +CONTRACTS_L1_ERC20_BRIDGE_IMPL_ADDR=0xB7Ee5eF6a5375499873655f6b892CF3FAa9B6A2b +CONTRACTS_L1_ERC20_BRIDGE_MESSAGE_PARSING_ADDR=0xD0C33116B8dF6Ce35f211685886e7565e20f297D +CONTRACTS_L1_WETH_BRIDGE_IMPL_ADDR=0x92F85F130457371168663D95e7fF422b152f3f71 +CONTRACTS_L1_WETH_BRIDGE_PROXY_ADDR=0xA51b095F78Ad6e158563a58b6D33f0a16D849ab4 \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index f50b97b0ed2..36b24ffdc63 100644 --- a/yarn.lock +++ b/yarn.lock @@ -22,7 +22,7 @@ dependencies: "@babel/highlight" "^7.10.4" -"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.22.13", "@babel/code-frame@^7.23.5": +"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.23.5": version "7.23.5" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.23.5.tgz#9009b69a8c602293476ad598ff53e4562e15c244" integrity sha512-CgH3s1a96LipHCmSUmYFPwY7MNx8C3avkq7i4Wl3cfa662ldtUe4VM1TPXX70pfmrlWTb6jLqTYrZyT2ZTJBgA== @@ -36,20 +36,20 @@ integrity sha512-uU27kfDRlhfKl+w1U6vp16IuvSLtjAxdArVXPa9BvLkrr7CYIsxH5adpHObeAGY/41+syctUWOZ140a2Rvkgjw== "@babel/core@^7.11.6", "@babel/core@^7.12.3": - version "7.23.7" - resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.23.7.tgz#4d8016e06a14b5f92530a13ed0561730b5c6483f" - integrity sha512-+UpDgowcmqe36d4NwqvKsyPMlOLNGMsfMmQ5WGCu+siCe3t3dfe9njrzGfdN4qq+bcNUt0+Vw6haRxBOycs4dw== + version "7.23.9" + resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.23.9.tgz#b028820718000f267870822fec434820e9b1e4d1" + integrity sha512-5q0175NOjddqpvvzU+kDiSOAk4PfdO6FvwCWoQ6RO7rTzEe8vlo+4HVfcnAREhD4npMs0e9uZypjTwzZPCf/cw== dependencies: "@ampproject/remapping" "^2.2.0" "@babel/code-frame" "^7.23.5" "@babel/generator" "^7.23.6" "@babel/helper-compilation-targets" "^7.23.6" "@babel/helper-module-transforms" "^7.23.3" - "@babel/helpers" "^7.23.7" - "@babel/parser" "^7.23.6" - "@babel/template" "^7.22.15" - "@babel/traverse" "^7.23.7" - "@babel/types" "^7.23.6" + "@babel/helpers" "^7.23.9" + "@babel/parser" "^7.23.9" + "@babel/template" "^7.23.9" + "@babel/traverse" "^7.23.9" + "@babel/types" "^7.23.9" convert-source-map "^2.0.0" debug "^4.1.0" gensync "^1.0.0-beta.2" @@ -149,14 +149,14 @@ resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.23.5.tgz#907a3fbd4523426285365d1206c423c4c5520307" integrity sha512-85ttAOMLsr53VgXkTbkx8oA6YTfT4q7/HzXSLEYmjcSTJPMPQtvq1BD79Byep5xMUYbGRzEpDsjUf3dyp54IKw== -"@babel/helpers@^7.23.7": - version "7.23.8" - resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.23.8.tgz#fc6b2d65b16847fd50adddbd4232c76378959e34" - integrity sha512-KDqYz4PiOWvDFrdHLPhKtCThtIcKVy6avWD2oG4GEvyQ+XDZwHD4YQd+H2vNMnq2rkdxsDkU82T+Vk8U/WXHRQ== +"@babel/helpers@^7.23.9": + version "7.23.9" + resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.23.9.tgz#c3e20bbe7f7a7e10cb9b178384b4affdf5995c7d" + integrity sha512-87ICKgU5t5SzOT7sBMfCOZQ2rHjRU+Pcb9BoILMYz600W6DkVRLFBPwQ18gwUVvggqXivaUakpnxWQGbpywbBQ== dependencies: - "@babel/template" "^7.22.15" - "@babel/traverse" "^7.23.7" - "@babel/types" "^7.23.6" + "@babel/template" "^7.23.9" + "@babel/traverse" "^7.23.9" + "@babel/types" "^7.23.9" "@babel/highlight@^7.10.4", "@babel/highlight@^7.23.4": version "7.23.4" @@ -167,10 +167,10 @@ chalk "^2.4.2" js-tokens "^4.0.0" -"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.22.15", "@babel/parser@^7.23.6", "@babel/parser@^7.7.0": - version "7.23.6" - resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.23.6.tgz#ba1c9e512bda72a47e285ae42aff9d2a635a9e3b" - integrity sha512-Z2uID7YJ7oNvAI20O9X0bblw7Qqs8Q2hFy0R9tAfnfLkp5MW0UH9eUvnDSnFwKZ0AvgS1ucqR4KzvVHgnke1VQ== +"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.23.9", "@babel/parser@^7.7.0": + version "7.23.9" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.23.9.tgz#7b903b6149b0f8fa7ad564af646c4c38a77fc44b" + integrity sha512-9tcKgqKbs3xGJ+NtKF2ndOBBLVwPjl1SHxPQkd36r3Dlirw3xWUeGaTbqr7uGZcTaxkVNwc+03SVP7aCdWrTlA== "@babel/plugin-syntax-async-generators@^7.8.4": version "7.8.4" @@ -270,19 +270,19 @@ dependencies: "@babel/helper-plugin-utils" "^7.22.5" -"@babel/template@^7.22.15", "@babel/template@^7.3.3": - version "7.22.15" - resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.22.15.tgz#09576efc3830f0430f4548ef971dde1350ef2f38" - integrity sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w== +"@babel/template@^7.22.15", "@babel/template@^7.23.9", "@babel/template@^7.3.3": + version "7.23.9" + resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.23.9.tgz#f881d0487cba2828d3259dcb9ef5005a9731011a" + integrity sha512-+xrD2BWLpvHKNmX2QbpdpsBaWnRxahMwJjO+KZk2JOElj5nSmKezyS1B4u+QbHMTX69t4ukm6hh9lsYQ7GHCKA== dependencies: - "@babel/code-frame" "^7.22.13" - "@babel/parser" "^7.22.15" - "@babel/types" "^7.22.15" + "@babel/code-frame" "^7.23.5" + "@babel/parser" "^7.23.9" + "@babel/types" "^7.23.9" -"@babel/traverse@^7.23.7", "@babel/traverse@^7.7.0": - version "7.23.7" - resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.23.7.tgz#9a7bf285c928cb99b5ead19c3b1ce5b310c9c305" - integrity sha512-tY3mM8rH9jM0YHFGyfC0/xf+SB5eKUu7HPj7/k3fpi9dAlsMc5YbQvDi0Sh2QTPXqMhyaAtzAr807TIyfQrmyg== +"@babel/traverse@^7.23.9", "@babel/traverse@^7.7.0": + version "7.23.9" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.23.9.tgz#2f9d6aead6b564669394c5ce0f9302bb65b9d950" + integrity sha512-I/4UJ9vs90OkBtY6iiiTORVMyIhJ4kAVmsKo9KFc8UOxMeUfi2hvtIBsET5u9GizXE6/GFSuKCTNfgCswuEjRg== dependencies: "@babel/code-frame" "^7.23.5" "@babel/generator" "^7.23.6" @@ -290,15 +290,15 @@ "@babel/helper-function-name" "^7.23.0" "@babel/helper-hoist-variables" "^7.22.5" "@babel/helper-split-export-declaration" "^7.22.6" - "@babel/parser" "^7.23.6" - "@babel/types" "^7.23.6" + "@babel/parser" "^7.23.9" + "@babel/types" "^7.23.9" debug "^4.3.1" globals "^11.1.0" -"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.22.15", "@babel/types@^7.22.5", "@babel/types@^7.23.0", "@babel/types@^7.23.6", "@babel/types@^7.3.3", "@babel/types@^7.7.0": - version "7.23.6" - resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.23.6.tgz#be33fdb151e1f5a56877d704492c240fc71c7ccd" - integrity sha512-+uarb83brBzPKN38NX1MkB6vb6+mwvR6amUulqAE7ccQw1pEl+bCia9TbdG1lsnFP7lZySvUn37CHyXQdfTwzg== +"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.22.15", "@babel/types@^7.22.5", "@babel/types@^7.23.0", "@babel/types@^7.23.6", "@babel/types@^7.23.9", "@babel/types@^7.3.3", "@babel/types@^7.7.0": + version "7.23.9" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.23.9.tgz#1dd7b59a9a2b5c87f8b41e52770b5ecbf492e002" + integrity sha512-dQjSq/7HaSjRM43FFGnv5keM2HsxpmyV1PfaSVm0nzzjwwTmjOe6J4bC8e3+pTEIgHaHj+1ZlLThRJ2auc/w1Q== dependencies: "@babel/helper-string-parser" "^7.23.4" "@babel/helper-validator-identifier" "^7.22.20" @@ -2014,9 +2014,9 @@ dockerode "^3.3.4" "@matterlabs/hardhat-zksync-solc@^1.0.5", "@matterlabs/hardhat-zksync-solc@^1.0.6": - version "1.1.0" - resolved "https://registry.yarnpkg.com/@matterlabs/hardhat-zksync-solc/-/hardhat-zksync-solc-1.1.0.tgz#14e05b4365392fe7a473a636e132883687dcf69a" - integrity sha512-DbknnOFsRNVqYMkxIrVofUk0cXA6uRIqSqyuVvhktg53KTHWubYlj6zEqCC+Q+wtONXijXQoN1BTIQ5FqDmAIQ== + version "1.1.2" + resolved "https://registry.yarnpkg.com/@matterlabs/hardhat-zksync-solc/-/hardhat-zksync-solc-1.1.2.tgz#d5c371acb8b745f018f0559403fe590e8c1dd8b4" + integrity sha512-4qyt9T3OevP+IGJqGd6cS/BKwJnne6XfYCq4gES2nnXoyIWOihmuaL9+KDsbvwVI4mBfB4bz84+SP68W5Bxuig== dependencies: "@nomiclabs/hardhat-docker" "^2.0.0" chai "^4.3.6" @@ -2042,9 +2042,9 @@ dockerode "^3.3.4" "@matterlabs/hardhat-zksync-vyper@^1.0.0": - version "1.0.6" - resolved "https://registry.yarnpkg.com/@matterlabs/hardhat-zksync-vyper/-/hardhat-zksync-vyper-1.0.6.tgz#c674a5a446dd7298814d5d78f40dfe5808bd09b1" - integrity sha512-OBStKayxJo9zKqZz0lRhKbv/33/IJO9suU4FSysYvdOcx6PJDHqO30+4TL+G2kE9o8j8Y8X7Ev2nJ6pCUcelrQ== + version "1.0.7" + resolved "https://registry.yarnpkg.com/@matterlabs/hardhat-zksync-vyper/-/hardhat-zksync-vyper-1.0.7.tgz#58603c8f41ae1e473011f37d314b054e859b24ea" + integrity sha512-s15DxL6S0LyAH88u8B+E9aLMa9pCwPhbSOpqXqm2tQkbqaNcGOR02s7OAzw8/fKo4Wf01vFp4w/RNW4Nr02Wpw== dependencies: "@nomiclabs/hardhat-docker" "^2.0.0" chai "^4.3.6" @@ -2843,6 +2843,11 @@ resolved "https://registry.yarnpkg.com/@solidity-parser/parser/-/parser-0.17.0.tgz#52a2fcc97ff609f72011014e4c5b485ec52243ef" integrity sha512-Nko8R0/kUo391jsEHHxrGM07QFdnPGvlmox4rmH0kNiNAashItAilhy4Mv4pK5gQmW5f4sXAF58fwJbmlkGcVw== +"@solidity-parser/parser@^0.18.0": + version "0.18.0" + resolved "https://registry.yarnpkg.com/@solidity-parser/parser/-/parser-0.18.0.tgz#8e77a02a09ecce957255a2f48c9a7178ec191908" + integrity sha512-yfORGUIPgLck41qyN7nbwJRAx17/jAIXCTanHOJZhB6PJ1iAk/84b/xlsVKFSyNyLXIj0dhppoE0+CRws7wlzA== + "@trufflesuite/bigint-buffer@1.1.10": version "1.1.10" resolved "https://registry.yarnpkg.com/@trufflesuite/bigint-buffer/-/bigint-buffer-1.1.10.tgz#a1d9ca22d3cad1a138b78baaf15543637a3e1692" @@ -3104,9 +3109,9 @@ form-data "^4.0.0" "@types/node@*", "@types/node@>=13.7.0": - version "20.11.6" - resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.6.tgz#6adf4241460e28be53836529c033a41985f85b6e" - integrity sha512-+EOokTnksGVgip2PbYbr3xnR7kZigh4LbybAfBAw5BpnQ+FqBYUsvCEjYd70IXKlbohQ64mzEYmMtlWUY8q//Q== + version "20.11.7" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.7.tgz#cb49aedd758c978c30806d0c38b520ed2a3df6e0" + integrity sha512-GPmeN1C3XAyV5uybAf4cMLWT9fDWcmQhZVtMFu7OR32WjrqGG+Wnk2V1d0bmtUyE/Zy1QJ9BxyiTih9z8Oks8A== dependencies: undici-types "~5.26.4" @@ -3143,9 +3148,9 @@ "@types/node" "*" "@types/pg@^8.10.3": - version "8.10.9" - resolved "https://registry.yarnpkg.com/@types/pg/-/pg-8.10.9.tgz#d20bb948c6268c5bd847e2bf968f1194c5a2355a" - integrity sha512-UksbANNE/f8w0wOMxVKKIrLCbEMV+oM1uKejmwXr39olg4xqcfBDbXxObJAt6XxHbDa4XTKOlUEcEltXDX+XLQ== + version "8.11.0" + resolved "https://registry.yarnpkg.com/@types/pg/-/pg-8.11.0.tgz#355a07531d467f2e4fabaa78be087ce2d99fd862" + integrity sha512-sDAlRiBNthGjNFfvt0k6mtotoVYVQ63pA8R4EMWka7crawSR60waVYR0HAgmPRs/e2YaeJTD/43OoZ3PFw80pw== dependencies: "@types/node" "*" pg-protocol "*" @@ -3245,14 +3250,14 @@ debug "^4.3.1" "@typescript-eslint/parser@^6.7.4": - version "6.19.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-6.19.1.tgz#68a87bb21afaf0b1689e9cdce0e6e75bc91ada78" - integrity sha512-WEfX22ziAh6pRE9jnbkkLGp/4RhTpffr2ZK5bJ18M8mIfA8A+k97U9ZyaXCEJRlmMHh7R9MJZWXp/r73DzINVQ== - dependencies: - "@typescript-eslint/scope-manager" "6.19.1" - "@typescript-eslint/types" "6.19.1" - "@typescript-eslint/typescript-estree" "6.19.1" - "@typescript-eslint/visitor-keys" "6.19.1" + version "6.20.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-6.20.0.tgz#17e314177304bdf498527e3c4b112e41287b7416" + integrity sha512-bYerPDF/H5v6V76MdMYhjwmwgMA+jlPVqjSDq2cRqMi8bP5sR3Z+RLOiOMad3nsnmDVmn2gAFCyNgh/dIrfP/w== + dependencies: + "@typescript-eslint/scope-manager" "6.20.0" + "@typescript-eslint/types" "6.20.0" + "@typescript-eslint/typescript-estree" "6.20.0" + "@typescript-eslint/visitor-keys" "6.20.0" debug "^4.3.4" "@typescript-eslint/scope-manager@4.33.0": @@ -3271,6 +3276,14 @@ "@typescript-eslint/types" "6.19.1" "@typescript-eslint/visitor-keys" "6.19.1" +"@typescript-eslint/scope-manager@6.20.0": + version "6.20.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.20.0.tgz#8a926e60f6c47feb5bab878246dc2ae465730151" + integrity sha512-p4rvHQRDTI1tGGMDFQm+GtxP1ZHyAh64WANVoyEcNMpaTFn3ox/3CcgtIlELnRfKzSs/DwYlDccJEtr3O6qBvA== + dependencies: + "@typescript-eslint/types" "6.20.0" + "@typescript-eslint/visitor-keys" "6.20.0" + "@typescript-eslint/type-utils@6.19.1": version "6.19.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-6.19.1.tgz#6a130e3afe605a4898e043fa9f72e96309b54935" @@ -3291,6 +3304,11 @@ resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.19.1.tgz#2d4c9d492a63ede15e7ba7d129bdf7714b77f771" integrity sha512-6+bk6FEtBhvfYvpHsDgAL3uo4BfvnTnoge5LrrCj2eJN8g3IJdLTD4B/jK3Q6vo4Ql/Hoip9I8aB6fF+6RfDqg== +"@typescript-eslint/types@6.20.0": + version "6.20.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.20.0.tgz#5ccd74c29011ae7714ae6973e4ec0c634708b448" + integrity sha512-MM9mfZMAhiN4cOEcUOEx+0HmuaW3WBfukBZPCfwSqFnQy0grXYtngKCqpQN339X3RrwtzspWJrpbrupKYUSBXQ== + "@typescript-eslint/typescript-estree@4.33.0": version "4.33.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.33.0.tgz#0dfb51c2908f68c5c08d82aefeaf166a17c24609" @@ -3318,6 +3336,20 @@ semver "^7.5.4" ts-api-utils "^1.0.1" +"@typescript-eslint/typescript-estree@6.20.0": + version "6.20.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.20.0.tgz#5b2d0975949e6bdd8d45ee1471461ef5fadc5542" + integrity sha512-RnRya9q5m6YYSpBN7IzKu9FmLcYtErkDkc8/dKv81I9QiLLtVBHrjz+Ev/crAqgMNW2FCsoZF4g2QUylMnJz+g== + dependencies: + "@typescript-eslint/types" "6.20.0" + "@typescript-eslint/visitor-keys" "6.20.0" + debug "^4.3.4" + globby "^11.1.0" + is-glob "^4.0.3" + minimatch "9.0.3" + semver "^7.5.4" + ts-api-utils "^1.0.1" + "@typescript-eslint/utils@6.19.1": version "6.19.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-6.19.1.tgz#df93497f9cfddde2bcc2a591da80536e68acd151" @@ -3347,6 +3379,14 @@ "@typescript-eslint/types" "6.19.1" eslint-visitor-keys "^3.4.1" +"@typescript-eslint/visitor-keys@6.20.0": + version "6.20.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.20.0.tgz#f7ada27f2803de89df0edd9fd7be22c05ce6a498" + integrity sha512-E8Cp98kRe4gKHjJD4NExXKz/zOJ1A2hhZc+IMVD6i7w4yjIvh6VyuRI0gRtxAsXtoC35uGMaQ9rjI2zJaXDEAw== + dependencies: + "@typescript-eslint/types" "6.20.0" + eslint-visitor-keys "^3.4.1" + "@ungap/promise-all-settled@1.1.2": version "1.1.2" resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44" @@ -3504,6 +3544,13 @@ amdefine@>=0.0.4: resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5" integrity sha512-S2Hw0TtNkMJhIabBwIojKL9YHO5T0n5eNqWJ7Lrlel/zDbftQpxpapi8tZs3X1HWa+u+QeydGmzzNU0m09+Rcg== +ansi-align@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-3.0.1.tgz#0cdf12e111ace773a86e9a1fad1225c43cb19a59" + integrity sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w== + dependencies: + string-width "^4.1.0" + ansi-colors@4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348" @@ -3801,9 +3848,9 @@ axios@^0.21.1: follow-redirects "^1.14.0" axios@^1.4.0, axios@^1.5.1: - version "1.6.5" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.5.tgz#2c090da14aeeab3770ad30c3a1461bc970fb0cd8" - integrity sha512-Ii012v05KEVuUoFWmMW/UQv9aRIc3ZwkWDcM+h5Il8izZCtRVpDUfwpoFf7eOtajT3QiGR4yDUx7lPqHJULgbg== + version "1.6.7" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.7.tgz#7b48c2e27c96f9c68a2f8f31e2ab19f59b06b0a7" + integrity sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA== dependencies: follow-redirects "^1.15.4" form-data "^4.0.0" @@ -3993,6 +4040,20 @@ boolbase@^1.0.0: resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e" integrity sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww== +boxen@^5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/boxen/-/boxen-5.1.2.tgz#788cb686fc83c1f486dfa8a40c68fc2b831d2b50" + integrity sha512-9gYgQKXx+1nP8mP7CzFyaUARhg7D3n1dF/FnErWmu9l6JvGpNUN278h0aSb+QjoiKSWG+iZ3uHrcqk0qrY9RQQ== + dependencies: + ansi-align "^3.0.0" + camelcase "^6.2.0" + chalk "^4.1.0" + cli-boxes "^2.2.1" + string-width "^4.2.2" + type-fest "^0.20.2" + widest-line "^3.1.0" + wrap-ansi "^7.0.0" + brace-expansion@^1.1.7: version "1.1.11" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" @@ -4195,9 +4256,9 @@ camelcase@^6.0.0, camelcase@^6.2.0: integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== caniuse-lite@^1.0.30001565: - version "1.0.30001579" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001579.tgz#45c065216110f46d6274311a4b3fcf6278e0852a" - integrity sha512-u5AUVkixruKHJjw/pj9wISlcMpgFWzSrczLZbrqBSxukQixmg0SJ5sZTpvaFvxU0HoQKd4yoyAogyrAz9pzJnA== + version "1.0.30001580" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001580.tgz#e3c76bc6fe020d9007647044278954ff8cd17d1e" + integrity sha512-mtj5ur2FFPZcCEpXFy8ADXbDACuNFXg6mxVDqp7tqooX6l3zwm+d8EPoeOSIFRDvHs8qu7/SLFOGniULkcH2iA== case@^1.6.3: version "1.6.3" @@ -4384,6 +4445,11 @@ clear-module@^4.1.2: parent-module "^2.0.0" resolve-from "^5.0.0" +cli-boxes@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-2.2.1.tgz#ddd5035d25094fce220e9cab40a45840a440318f" + integrity sha512-y4coMcylgSCdVinjiDBuR8PCC2bLjyGTwEmPb9NHR/QaNU6EUOXcTY/s6VjGMD6ENSEaeQYHCY0GNGS5jfMwPw== + cli-cursor@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5" @@ -5145,9 +5211,9 @@ dot-prop@^6.0.1: is-obj "^2.0.0" dotenv@^16.0.3: - version "16.4.0" - resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.0.tgz#ac21c3fcaad2e7832a1cd0c0e4e8e52225ecda0e" - integrity sha512-WvImr5kpN5NGNn7KaDjJnLTh5rDVLZiDf/YLA8T1ZEZEBZNEDOE+mnkS0PVjPax8ZxBP5zC5SLMB3/9VV5de9g== + version "16.4.1" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.1.tgz#1d9931f1d3e5d2959350d1250efab299561f7f11" + integrity sha512-CjA3y+Dr3FyFDOAMnxZEGtnW9KBR2M0JvvUtXNW+dYJL5ROWxP9DUHCwgFqpMk0OXCc0ljhaNTr2w/kutYIcHQ== dotenv@^8.2.0: version "8.6.0" @@ -5175,9 +5241,9 @@ ecdsa-sig-formatter@1.0.11: safe-buffer "^5.0.1" electron-to-chromium@^1.4.601: - version "1.4.643" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.643.tgz#081a20c5534db91e66ef094f68624960f674768f" - integrity sha512-QHscvvS7gt155PtoRC0dR2ilhL8E9LHhfTQEq1uD5AL0524rBLAwpAREFH06f87/e45B9XkR6Ki5dbhbCsVEIg== + version "1.4.647" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.647.tgz#3c8d4815e5ed2fbdd37f4ab7333cd9f8fc56d53a" + integrity sha512-Z/fTNGwc45WrYQhPaEcz5tAJuZZ8G7S/DBnhS6Kgp4BxnS40Z/HqlJ0hHg3Z79IGVzuVartIlTcjw/cQbPLgOw== elliptic@6.5.4, elliptic@^6.5.2, elliptic@^6.5.4: version "6.5.4" @@ -6653,9 +6719,9 @@ hardhat-contract-sizer@^2.0.2: strip-ansi "^6.0.0" hardhat-gas-reporter@^1.0.9: - version "1.0.9" - resolved "https://registry.yarnpkg.com/hardhat-gas-reporter/-/hardhat-gas-reporter-1.0.9.tgz#9a2afb354bc3b6346aab55b1c02ca556d0e16450" - integrity sha512-INN26G3EW43adGKBNzYWOlI3+rlLnasXTwW79YNnUhXPDa+yHESgt639dJEs37gCjhkbNKcRRJnomXEuMFBXJg== + version "1.0.10" + resolved "https://registry.yarnpkg.com/hardhat-gas-reporter/-/hardhat-gas-reporter-1.0.10.tgz#ebe5bda5334b5def312747580cd923c2b09aef1b" + integrity sha512-02N4+So/fZrzJ88ci54GqwVA3Zrf0C9duuTyGt0CFRIh/CdNwbnTgkXkRfojOMLBQ+6t+lBIkgbsOtqMvNwikA== dependencies: array-uniq "1.0.3" eth-gas-reporter "^0.2.25" @@ -6722,9 +6788,9 @@ hardhat@=2.16.0: ws "^7.4.6" hardhat@^2.18.3: - version "2.19.4" - resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.19.4.tgz#5112c30295d8be2e18e55d847373c50483ed1902" - integrity sha512-fTQJpqSt3Xo9Mn/WrdblNGAfcANM6XC3tAEi6YogB4s02DmTf93A8QsGb8uR0KR8TFcpcS8lgiW4ugAIYpnbrQ== + version "2.19.5" + resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.19.5.tgz#6017c35ae2844b669e9bcc84c3d05346d4ef031c" + integrity sha512-vx8R7zWCYVgM56vA6o0Wqx2bIIptkN4TMs9QwDqZVNGRhMzBfzqUeEYbp+69gxWp1neg2V2nYQUaaUv7aom1kw== dependencies: "@ethersproject/abi" "^5.1.2" "@metamask/eth-sig-util" "^4.0.0" @@ -6745,6 +6811,7 @@ hardhat@^2.18.3: adm-zip "^0.4.16" aggregate-error "^3.0.0" ansi-escapes "^4.3.0" + boxen "^5.1.2" chalk "^2.4.2" chokidar "^3.4.0" ci-info "^2.0.0" @@ -6968,7 +7035,12 @@ ignore@^4.0.6: resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc" integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg== -ignore@^5.1.1, ignore@^5.2.0, ignore@^5.2.4: +ignore@^5.1.1: + version "5.3.1" + resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.3.1.tgz#5073e554cd42c5b33b394375f538b8593e34d4ef" + integrity sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw== + +ignore@^5.2.0, ignore@^5.2.4: version "5.3.0" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.3.0.tgz#67418ae40d34d6999c95ff56016759c718c82f78" integrity sha512-g7dmpshy+gD7mh88OC9NwSGTKoc3kyLAZQRU1mt53Aw/vnvfXnbC+F/7F7QoYVKbV+KNvJx8wArewKy1vXMtlg== @@ -6994,9 +7066,9 @@ immediate@~3.2.3: integrity sha512-RrGCXRm/fRVqMIhqXrGEX9rRADavPiDFSoMb/k64i9XMk8uH4r/Omi5Ctierj6XzNecwDbO4WuFbDD1zmpl3Tg== immutable@^4.0.0-rc.12: - version "4.3.4" - resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.3.4.tgz#2e07b33837b4bb7662f288c244d1ced1ef65a78f" - integrity sha512-fsXeu4J4i6WNWSikpI88v/PcVflZz+6kMhUfIwc5SY+poQRPnaf5V7qds6SUyUN3cVxEzuCab7QIoLOQ+DQ1wA== + version "4.3.5" + resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.3.5.tgz#f8b436e66d59f99760dc577f5c99a4fd2a5cc5a0" + integrity sha512-8eabxkth9gZatlwl5TBuJnCsoTADlL6ftEr7A4qgdaTsPyreilDSnUk57SO+jfKcNtxPa22U5KK6DSeAYhpBJw== import-fresh@^3.0.0, import-fresh@^3.2.1, import-fresh@^3.3.0: version "3.3.0" @@ -8342,9 +8414,9 @@ lru-cache@^6.0.0: yallist "^4.0.0" "lru-cache@^9.1.1 || ^10.0.0": - version "10.1.0" - resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.1.0.tgz#2098d41c2dc56500e6c88584aa656c84de7d0484" - integrity sha512-/1clY/ui8CzjKFyjdvwPWJUYKiFVXG2I2cY0ssG7h4+hwk+XOIX7ZSG9Q7TW8TW3Kp3BUSqgFWBLgL4PJ+Blag== + version "10.2.0" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.2.0.tgz#0bd445ca57363465900f4d1f9bd8db343a4d95c3" + integrity sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q== lru_map@^0.3.3: version "0.3.3" @@ -8707,7 +8779,7 @@ mocha-steps@^1.3.0: resolved "https://registry.yarnpkg.com/mocha-steps/-/mocha-steps-1.3.0.tgz#2449231ec45ec56810f65502cb22e2571862957f" integrity sha512-KZvpMJTqzLZw3mOb+EEuYi4YZS41C9iTnb7skVFRxHjUd1OYbl64tCMSmpdIRM9LnwIrSOaRfPtNpF5msgv6Eg== -mocha@10.2.0, mocha@^10.0.0, mocha@^10.2.0: +mocha@^10.0.0, mocha@^10.2.0: version "10.2.0" resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.2.0.tgz#1fd4a7c32ba5ac372e03a17eef435bd00e5c68b8" integrity sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg== @@ -8873,9 +8945,9 @@ nise@^4.0.4: path-to-regexp "^1.7.0" nise@^5.1.4: - version "5.1.7" - resolved "https://registry.yarnpkg.com/nise/-/nise-5.1.7.tgz#03ca96539efb306612eb60a8c5d6beeb208e27e5" - integrity sha512-wWtNUhkT7k58uvWTB/Gy26eA/EJKtPZFVAhEilN5UYVmmGRYOURbejRUyKm0Uu9XVEW7K5nBOZfR8VMB4QR2RQ== + version "5.1.9" + resolved "https://registry.yarnpkg.com/nise/-/nise-5.1.9.tgz#0cb73b5e4499d738231a473cd89bd8afbb618139" + integrity sha512-qOnoujW4SV6e40dYxJOb3uvuoPHtmLzIk4TFo+j0jPJoC+5Z9xja5qH5JZobEPsa8+YYphMrOSwnrshEhG2qww== dependencies: "@sinonjs/commons" "^3.0.0" "@sinonjs/fake-timers" "^11.2.2" @@ -10395,12 +10467,12 @@ solidity-comments-extractor@^0.0.8: integrity sha512-htM7Vn6LhHreR+EglVMd2s+sZhcXAirB1Zlyrv5zBuTxieCvjfnRpd7iZk75m/u6NOlEyQ94C6TWbBn2cY7w8g== solidity-coverage@^0.8.5: - version "0.8.5" - resolved "https://registry.yarnpkg.com/solidity-coverage/-/solidity-coverage-0.8.5.tgz#64071c3a0c06a0cecf9a7776c35f49edc961e875" - integrity sha512-6C6N6OV2O8FQA0FWA95FdzVH+L16HU94iFgg5wAFZ29UpLFkgNI/DRR2HotG1bC0F4gAc/OMs2BJI44Q/DYlKQ== + version "0.8.6" + resolved "https://registry.yarnpkg.com/solidity-coverage/-/solidity-coverage-0.8.6.tgz#c7b18dc9edfeba11064726c37d96265f689c9478" + integrity sha512-vV03mA/0nNMskOdVwNarUcqk0N/aYdelxAbf6RZ5l84FcYHbqDTr2JXyeYMp4bT48qHtAQjnKrygW1FrECyWNw== dependencies: "@ethersproject/abi" "^5.0.9" - "@solidity-parser/parser" "^0.16.0" + "@solidity-parser/parser" "^0.18.0" chalk "^2.4.2" death "^1.1.0" detect-port "^1.3.0" @@ -10411,7 +10483,7 @@ solidity-coverage@^0.8.5: globby "^10.0.1" jsonschema "^1.2.4" lodash "^4.17.15" - mocha "10.2.0" + mocha "^10.2.0" node-emoji "^1.10.0" pify "^4.0.1" recursive-readdir "^2.2.2" @@ -10472,9 +10544,9 @@ spdx-correct@^3.0.0: spdx-license-ids "^3.0.0" spdx-exceptions@^2.1.0: - version "2.3.0" - resolved "https://registry.yarnpkg.com/spdx-exceptions/-/spdx-exceptions-2.3.0.tgz#3f28ce1a77a00372683eade4a433183527a2163d" - integrity sha512-/tTrYOC7PPI1nUAgx34hUpqXuyJG+DTHJTnIULG4rDygi4xu/tfgmq1e1cIRwRzwZgo4NLySi+ricLkZkw4i5A== + version "2.4.0" + resolved "https://registry.yarnpkg.com/spdx-exceptions/-/spdx-exceptions-2.4.0.tgz#c07a4ede25b16e4f78e6707bbd84b15a45c19c1b" + integrity sha512-hcjppoJ68fhxA/cjbN4T8N6uCUejN8yFw69ttpqtBeCbF3u13n7mb31NB9jKwGTTWWnt9IbRA/mf1FprYS8wfw== spdx-expression-parse@^3.0.0: version "3.0.1" @@ -10571,7 +10643,7 @@ string-length@^4.0.1: char-regex "^1.0.2" strip-ansi "^6.0.0" -"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -11499,6 +11571,13 @@ which@^1.1.1, which@^1.2.9, which@^1.3.1: dependencies: isexe "^2.0.0" +widest-line@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/widest-line/-/widest-line-3.1.0.tgz#8292333bbf66cb45ff0de1603b136b7ae1496eca" + integrity sha512-NsmoXalsWVDMGupxZ5R08ka9flZjjiLvHVAWYOKtiKM8ujtZWr9cRffak+uSE48+Ob8ObalXpwyeUiyDD6QFgg== + dependencies: + string-width "^4.0.0" + word-wrap@~1.2.3: version "1.2.5" resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34" From dcd272103abbf8a2ef00104d768969d7aeab14b5 Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Thu, 1 Feb 2024 17:03:27 -0300 Subject: [PATCH 02/49] zk fmt --- core/lib/env_config/src/native_erc20_fetcher.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/lib/env_config/src/native_erc20_fetcher.rs b/core/lib/env_config/src/native_erc20_fetcher.rs index e1d64519e05..a4a1130725b 100644 --- a/core/lib/env_config/src/native_erc20_fetcher.rs +++ b/core/lib/env_config/src/native_erc20_fetcher.rs @@ -1,6 +1,7 @@ -use crate::{envy_load, FromEnv}; use zksync_config::configs::native_erc20_fetcher::NativeErc20FetcherConfig; +use crate::{envy_load, FromEnv}; + impl FromEnv for NativeErc20FetcherConfig { fn from_env() -> anyhow::Result { envy_load("native_erc20_fetcher", "NATIVE_TOKEN_FETCHER_") From c8626a7545b5ca235ccd94a870294d7780d38c03 Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Thu, 1 Feb 2024 19:21:11 -0300 Subject: [PATCH 03/49] Connect with fetcher with config data to get the host and poll interval --- Cargo.lock | 17 ------ Cargo.toml | 2 - core/bin/erc20_fetcher/Cargo.toml | 21 ------- core/bin/erc20_fetcher/src/lib.rs | 59 ------------------- core/bin/erc20_fetcher/src/main.rs | 45 -------------- core/bin/erc20_fetcher/src/rpc.rs | 20 ------- .../src/native_erc20_fetcher/mod.rs | 47 ++++++++------- erc20_example.py | 8 +++ etc/env/base/erc20_fetcher.toml | 4 ++ etc/env/l1-inits/.init.env | 42 ++++++------- 10 files changed, 58 insertions(+), 207 deletions(-) delete mode 100644 core/bin/erc20_fetcher/Cargo.toml delete mode 100644 core/bin/erc20_fetcher/src/lib.rs delete mode 100644 core/bin/erc20_fetcher/src/main.rs delete mode 100644 core/bin/erc20_fetcher/src/rpc.rs create mode 100644 erc20_example.py create mode 100644 etc/env/base/erc20_fetcher.toml diff --git a/Cargo.lock b/Cargo.lock index 8a89d5954a9..6aae513b69a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2265,23 +2265,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "erc20_fetcher" -version = "0.1.0" -dependencies = [ - "anyhow", - "clap 4.4.6", - "futures 0.3.28", - "jsonrpsee", - "reqwest", - "serde", - "serde_json", - "thiserror", - "tokio", - "tracing", - "tracing-subscriber", -] - [[package]] name = "errno" version = "0.3.5" diff --git a/Cargo.toml b/Cargo.toml index f8735631aea..cd823972a01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,6 @@ members = [ "core/bin/system-constants-generator", "core/bin/verified_sources_fetcher", "core/bin/zksync_server", - # For native ERC20 support - "core/bin/erc20_fetcher", # Libraries "core/lib/zksync_core", "core/lib/basic_types", diff --git a/core/bin/erc20_fetcher/Cargo.toml b/core/bin/erc20_fetcher/Cargo.toml deleted file mode 100644 index 2a9933f291e..00000000000 --- a/core/bin/erc20_fetcher/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "erc20_fetcher" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -jsonrpsee = { version = "0.21.0", features = [ - "macros", "server", "http-client" -] } -serde = "1.0" -serde_json = "1.0" -thiserror = "1.0" -anyhow = "1.0" -clap = { version = "4.2.4", features = ["derive"] } -tokio = { version = "1", features = ["full"] } -tracing = "0.1" -tracing-subscriber = "0.3" -futures = "0.3" -reqwest = { version = "0.11", features = ["json", "blocking"] } diff --git a/core/bin/erc20_fetcher/src/lib.rs b/core/bin/erc20_fetcher/src/lib.rs deleted file mode 100644 index c28a606d096..00000000000 --- a/core/bin/erc20_fetcher/src/lib.rs +++ /dev/null @@ -1,59 +0,0 @@ -use jsonrpsee::core::{async_trait, RpcResult}; -pub use rpc::RpcApiServer; -use serde::{Deserialize, Serialize}; -mod rpc; - -pub struct RpcApiBackend { - erc20_symbol: String, - erc20_name: String, -} - -impl RpcApiBackend { - pub fn new(erc20_symbol: String, erc20_name: String) -> Self { - Self { - erc20_symbol, - erc20_name, - } - } -} - -#[derive(Deserialize, Serialize, Debug)] -struct EthValue { - eth: serde_json::value::Number, -} -#[derive(Deserialize, Serialize, Debug)] -struct Request { - dai: EthValue, -} - -#[async_trait] -impl RpcApiServer for RpcApiBackend { - async fn conversion_rate(&self) -> RpcResult { - let url = - "https://api.coingecko.com/api/v3/simple/price?x_cg_demo_api_key=CG-FEgodj8AJN55Va4c6uKPUWLe&ids=dai&vs_currencies=eth"; - let response = reqwest::get(url) - .await - .expect("Failed request for ERC-20") - .json::() - .await - .unwrap(); - RpcResult::Ok(response.dai.eth.to_string()) - } - fn token_symbol(&self) -> RpcResult { - RpcResult::Ok(self.erc20_symbol.clone()) - } - fn token_name(&self) -> RpcResult { - RpcResult::Ok(self.erc20_name.clone()) - } - // async fn price(&self) -> RpcResult { - // let url = - // "https://api.coingecko.com/api/v3/simple/price?x_cg_demo_api_key=CG-FEgodj8AJN55Va4c6uKPUWLe&ids=dai&vs_currencies=usd"; - // let response = reqwest::get(url) - // .await - // .expect("Failed request for ERC-20") - // .json::() - // .await - // .unwrap(); - // RpcResult::Ok(response.dai.eth.to_string()) - // } -} diff --git a/core/bin/erc20_fetcher/src/main.rs b/core/bin/erc20_fetcher/src/main.rs deleted file mode 100644 index bef6d43dda0..00000000000 --- a/core/bin/erc20_fetcher/src/main.rs +++ /dev/null @@ -1,45 +0,0 @@ -use clap::Parser; -use erc20_fetcher::{RpcApiBackend, RpcApiServer}; -use jsonrpsee::{ - server::{ServerBuilder, ServerHandle}, - RpcModule, -}; -use tokio::net::ToSocketAddrs; -use tracing::{error, info}; - -#[derive(Parser)] -struct Cli { - #[arg(long, help = "the port where the fetcher will run.")] - port: u16, - #[arg(long, help = "the name of the ERC20 token.")] - name: String, - #[arg(long, help = "the symbol of the ERC20 token.")] - symbol: String, -} - -#[tokio::main] -async fn main() -> anyhow::Result<()> { - tracing_subscriber::fmt::init(); - let opt = Cli::parse(); - let addr = format!("127.0.0.1:{}", opt.port); - let rpc_module = RpcApiBackend::new(opt.symbol, opt.name).into_rpc(); - - let handle = start_server(addr, rpc_module).await; - match handle { - Ok(handle) => { - info!("Server started and listening on port: {}", opt.port); - handle.stopped().await; - } - Err(e) => error!("An error has occurred while starting the server: {}", e), - } - Ok(()) -} - -async fn start_server( - addr: impl ToSocketAddrs, - module: RpcModule, -) -> Result { - let server = ServerBuilder::default().build(addr).await?; - let server_handle = server.start(module); - Ok(server_handle) -} diff --git a/core/bin/erc20_fetcher/src/rpc.rs b/core/bin/erc20_fetcher/src/rpc.rs deleted file mode 100644 index 2d2c543853d..00000000000 --- a/core/bin/erc20_fetcher/src/rpc.rs +++ /dev/null @@ -1,20 +0,0 @@ -use jsonrpsee::{core::RpcResult, proc_macros::rpc}; - -#[rpc(server, client, namespace = "fetcher")] -pub trait RpcApi { - /// Returns the NativeERC20/ETH conversion rate. - #[method(name = "conversionRate")] - async fn conversion_rate(&self) -> RpcResult; - - // /// Returns the ERC20 token price in USD. - // #[method(name = "tokenPrice")] - // async fn price(&self) -> RpcResult; - - /// returns the symbol of the ERC20. - #[method(name = "tokenSymbol")] - fn token_symbol(&self) -> RpcResult; - - /// returns the name of the ERC20. - #[method(name = "tokenName")] - fn token_name(&self) -> RpcResult; -} diff --git a/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs b/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs index cfab7b23a02..3646c197c47 100644 --- a/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs @@ -1,6 +1,7 @@ -use std::sync::Arc; +use std::{borrow::BorrowMut, collections::HashMap, sync::Arc, time::Duration}; use async_trait::async_trait; +use metrics::atomics::AtomicU64; use tokio::{ sync::{watch, Mutex, OnceCell}, task::JoinHandle, @@ -21,8 +22,7 @@ impl From for Error { #[async_trait] pub trait Erc20Fetcher: 'static + std::fmt::Debug + Send + Sync { - async fn conversion_rate(&self) -> anyhow::Result; - async fn token_price(&self) -> anyhow::Result; + async fn conversion_rate(&self) -> anyhow::Result; } pub(crate) struct NativeErc20FetcherSingleton { @@ -63,16 +63,14 @@ pub(crate) struct NativeErc20Fetcher { // TODO: we probably need to add a http client here // to avoid creating a new one for each request pub config: NativeErc20FetcherConfig, - pub latest_to_eth_conversion_rate: Arc>, - pub latest_token_price: Arc>, + pub latest_to_eth_conversion_rate: AtomicU64, } impl NativeErc20Fetcher { pub(crate) fn new(config: NativeErc20FetcherConfig) -> Self { Self { config, - latest_to_eth_conversion_rate: Arc::new(Mutex::new(0.0)), - latest_token_price: Arc::new(Mutex::new(0.0)), + latest_to_eth_conversion_rate: AtomicU64::new(0), } } @@ -82,31 +80,36 @@ impl NativeErc20Fetcher { tracing::info!("Stop signal received, eth_tx_manager is shutting down"); break; } - // TODO: update: - // - latest_to_eth_conversion_rate - // - latest_token_price + + let conversion_rate = reqwest::get(format!("{}/conversion_rate", &self.config.host)) + .await? + .json::() + .await + .unwrap(); + + self.latest_to_eth_conversion_rate + .store(conversion_rate, std::sync::atomic::Ordering::Relaxed); + + tokio::time::sleep(Duration::from_secs(self.config.poll_interval)).await; } Ok(()) } // TODO: implement the actual fetch logic - pub(crate) async fn fetch_conversion_rate(&self) -> anyhow::Result { - todo!() - } - - pub(crate) async fn fetch_token_price(&self) -> anyhow::Result { - todo!() + pub(crate) async fn fetch_conversion_rate(&self) -> anyhow::Result { + Ok(self + .latest_to_eth_conversion_rate + .load(std::sync::atomic::Ordering::Relaxed)) } } #[async_trait] impl Erc20Fetcher for NativeErc20Fetcher { - async fn conversion_rate(&self) -> anyhow::Result { - anyhow::Ok(self.latest_to_eth_conversion_rate.lock().await.clone()) - } - - async fn token_price(&self) -> anyhow::Result { - anyhow::Ok(self.latest_token_price.lock().await.clone()) + async fn conversion_rate(&self) -> anyhow::Result { + anyhow::Ok( + self.latest_to_eth_conversion_rate + .load(std::sync::atomic::Ordering::Relaxed), + ) } } diff --git a/erc20_example.py b/erc20_example.py new file mode 100644 index 00000000000..79b0a1c4882 --- /dev/null +++ b/erc20_example.py @@ -0,0 +1,8 @@ +from flask import Flask +from random import randint + +app = Flask(__name__) + +@app.route("/conversion_rate") +def conversion_rate(): + return str(randint(1, 100)) diff --git a/etc/env/base/erc20_fetcher.toml b/etc/env/base/erc20_fetcher.toml new file mode 100644 index 00000000000..939fb27b460 --- /dev/null +++ b/etc/env/base/erc20_fetcher.toml @@ -0,0 +1,4 @@ +[native_erc20_fetcher] +host="http://127.0.0.1:5000" +# Poll interval is in seconds +poll_interval=10 diff --git a/etc/env/l1-inits/.init.env b/etc/env/l1-inits/.init.env index 5a8307e01d5..784c3ad43a2 100644 --- a/etc/env/l1-inits/.init.env +++ b/etc/env/l1-inits/.init.env @@ -1,30 +1,30 @@ CONTRACTS_LATEST_PROTOCOL_VERSION=22 CONTRACTS_CREATE2_FACTORY_ADDR=0x3c4CE2E9D8b03BbCd568E47465A483EE86893c49 -CONTRACTS_VERIFIER_ADDR=0x42758Ee9dd7eaB0c8462443fDe050b583eA7321e -CONTRACTS_L1_MULTICALL3_ADDR=0xF673f2EAcc34A298a6a40AeE4dab90fdDeD83Bae +CONTRACTS_VERIFIER_ADDR=0x849924715a04035Ada2d2695Dbd0822A34686D70 +CONTRACTS_L1_MULTICALL3_ADDR=0x5497399bCd1b6f7B2DbF8C1a3fB19FaD1568b08d CONTRACTS_GENESIS_ROOT=0xa783f96aedee88117bc4e3a006f6e3c4d89199db4fa66fe01cd009f4c92ea029 CHAIN_STATE_KEEPER_BOOTLOADER_HASH=0x010007ed0e328b940e241f7666a6303b7ffd4e3fd7e8c154d6e7556befe6cd6d CHAIN_STATE_KEEPER_DEFAULT_AA_HASH=0x0100055b7a8be90522251be8be1a186464d056462973502ac8a0437c85e4d2a9 CONTRACTS_GENESIS_BATCH_COMMITMENT=0xda81b5c95796a0a7afbe3c11637617364a5bf0e2947ad89a32d1535f9929eda5 CONTRACTS_GENESIS_ROLLUP_LEAF_INDEX=25 CONTRACTS_L1_WETH_TOKEN_ADDR=0x4A470422bFf67C34a3A565106118023059fa4E34 -CONTRACTS_BRIDGEHUB_PROXY_ADDR=0x7a7C7c73927B7ccA796a340851F639B3511F2D04 -CONTRACTS_BRIDGEHUB_IMPL_ADDR=0x7F35af739d185a4EaC39f78E4Bbe8F1Af7B10C02 -CONTRACTS_STATE_TRANSITION_PROXY_ADDR=0x43eaca081D9c9511Cc1F5007C219E3fBaCbe2c2C -CONTRACTS_STATE_TRANSITION_IMPL_ADDR=0x3c7A51295cf1C877F21bbFaa70cd38B71fD62409 -CONTRACTS_ADMIN_FACET_ADDR=0x31773CfF68fe6248275430b9AfD8AbB292D29804 -CONTRACTS_DIAMOND_UPGRADE_INIT_ADDR=0x39FD4D26A2eb7e38d0607d6C36581FCBF40D53ED -CONTRACTS_DIAMOND_INIT_ADDR=0x6F7B294f0da192ffcBE519bFFF167a92226eB787 -CONTRACTS_DEFAULT_UPGRADE_ADDR=0x226238E3Fd7bd1C3BBB2De75e151796611f467F6 -CONTRACTS_GENESIS_UPGRADE_ADDR=0x9703D7eb1561FC6f49C95487323a0Ebd2E3E0F91 -CONTRACTS_GOVERNANCE_ADDR=0x2ee9094257c9Dfac3A173D3875D9307758d4563C -CONTRACTS_MAILBOX_FACET_ADDR=0x84124338Dc6370847802F7Ee7afB992D29788c0f -CONTRACTS_EXECUTOR_FACET_ADDR=0xE29343E58f154aB62e0DdDE3D5a929d2ef6118ac -CONTRACTS_GETTERS_FACET_ADDR=0x599f2f39715D6dDCaE249692aaBE1b8598D14349 -CONTRACTS_VALIDATOR_TIMELOCK_ADDR=0x58e9DC2122715322cA983859d1B8A2Df8384e2e5 +CONTRACTS_BRIDGEHUB_PROXY_ADDR=0xc151A5dB14941B4D680e8585620Dc79d133D5E5D +CONTRACTS_BRIDGEHUB_IMPL_ADDR=0x345d99eD9311fd048E08e1C72Cc82Cf54D1e23Fe +CONTRACTS_STATE_TRANSITION_PROXY_ADDR=0x0d316Ef1880A6a789364166EB481C2d51F5Bd947 +CONTRACTS_STATE_TRANSITION_IMPL_ADDR=0xE215B844F28c1C78118b346Da0dAcEc95f75D180 +CONTRACTS_ADMIN_FACET_ADDR=0xb41D9B0B23Ea1C3905E6c51686d73E9Ea8776B85 +CONTRACTS_DIAMOND_UPGRADE_INIT_ADDR=0xBA2b13a022E3c5C5E3737b8f604DeB2Ca25A1c87 +CONTRACTS_DIAMOND_INIT_ADDR=0xC73e162211E59Df591EF2a61ea2BA330Aa4e29a0 +CONTRACTS_DEFAULT_UPGRADE_ADDR=0x26b934C51D8Cb8Bf2805243c68E7e1B58075046e +CONTRACTS_GENESIS_UPGRADE_ADDR=0xe25684528AA1fCf3b502D9F85A0D8386ab3978D7 +CONTRACTS_GOVERNANCE_ADDR=0x4Dc927bb5DA050d694bcD5E0970b02E9E53402f3 +CONTRACTS_MAILBOX_FACET_ADDR=0x0bFFc1d19EeEA52b3375B7fD170A2493afCF4a04 +CONTRACTS_EXECUTOR_FACET_ADDR=0x4f9b081F9fae5b013d83A1635cB6B396EC192a67 +CONTRACTS_GETTERS_FACET_ADDR=0x5aeAC41e0FBA073c35e201e7AF87416852710713 +CONTRACTS_VALIDATOR_TIMELOCK_ADDR=0x8Ea2c7b9B891FD316e6268eF44f75dF13E17Ef41 CONTRACTS_TRANSPARENT_PROXY_ADMIN_ADDR=0x20410058241d1c4C5f7C04753BD4713B04f19423 -CONTRACTS_L1_ERC20_BRIDGE_PROXY_ADDR=0x648892bCeF482B2B98A7434066680FFFA6Bc2523 -CONTRACTS_L1_ERC20_BRIDGE_IMPL_ADDR=0xB7Ee5eF6a5375499873655f6b892CF3FAa9B6A2b -CONTRACTS_L1_ERC20_BRIDGE_MESSAGE_PARSING_ADDR=0xD0C33116B8dF6Ce35f211685886e7565e20f297D -CONTRACTS_L1_WETH_BRIDGE_IMPL_ADDR=0x92F85F130457371168663D95e7fF422b152f3f71 -CONTRACTS_L1_WETH_BRIDGE_PROXY_ADDR=0xA51b095F78Ad6e158563a58b6D33f0a16D849ab4 \ No newline at end of file +CONTRACTS_L1_ERC20_BRIDGE_PROXY_ADDR=0xBae7E00c5B250Af2933d2c18c184FD3Cd602357E +CONTRACTS_L1_ERC20_BRIDGE_IMPL_ADDR=0x96b2758B11E88F5c411cAE8b560D91Baaa39e552 +CONTRACTS_L1_ERC20_BRIDGE_MESSAGE_PARSING_ADDR=0xAe04Bf1D7FFa3D83750670D9e96791DE240cC4E1 +CONTRACTS_L1_WETH_BRIDGE_IMPL_ADDR=0x6122E9F4dfAD2b0c83a1E8977c1179167ab1a36D +CONTRACTS_L1_WETH_BRIDGE_PROXY_ADDR=0x4D1282D5865D67E515742183082C71CCa4412e7E \ No newline at end of file From 06ec84d645082a9d108a258e09b536e4ece35329 Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Thu, 1 Feb 2024 19:22:32 -0300 Subject: [PATCH 04/49] Remove unused fields --- core/lib/config/src/configs/native_erc20_fetcher.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/lib/config/src/configs/native_erc20_fetcher.rs b/core/lib/config/src/configs/native_erc20_fetcher.rs index 19c7c97beec..758347e9b28 100644 --- a/core/lib/config/src/configs/native_erc20_fetcher.rs +++ b/core/lib/config/src/configs/native_erc20_fetcher.rs @@ -4,6 +4,4 @@ use serde::Deserialize; pub struct NativeErc20FetcherConfig { pub poll_interval: u64, pub host: String, - pub name: String, - pub symbol: String, } From 5c6b6476d16832f571d94730dcec0940a6b1647e Mon Sep 17 00:00:00 2001 From: jmunoz Date: Thu, 8 Feb 2024 10:24:20 -0300 Subject: [PATCH 05/49] add erc20 fetcher to gas adjuster --- .../src/l1_gas_price/gas_adjuster/mod.rs | 18 ++++++++++-- .../zksync_core/src/l1_gas_price/singleton.rs | 20 +++++++++---- core/lib/zksync_core/src/lib.rs | 29 +++++++++++++++---- .../src/native_erc20_fetcher/mod.rs | 5 ++-- 4 files changed, 55 insertions(+), 17 deletions(-) diff --git a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs index ac5d0413438..8e9023bcfdc 100644 --- a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs +++ b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs @@ -12,7 +12,7 @@ use zksync_system_constants::L1_GAS_PER_PUBDATA_BYTE; use self::metrics::METRICS; use super::{L1GasPriceProvider, L1TxParamsProvider}; -use crate::state_keeper::metrics::KEEPER_METRICS; +use crate::{native_erc20_fetcher::Erc20Fetcher, state_keeper::metrics::KEEPER_METRICS}; mod metrics; #[cfg(test)] @@ -25,10 +25,15 @@ pub struct GasAdjuster { pub(super) statistics: GasStatistics, pub(super) config: GasAdjusterConfig, eth_client: E, + erc20_fetcher_dyn: Option>, } impl GasAdjuster { - pub async fn new(eth_client: E, config: GasAdjusterConfig) -> Result { + pub async fn new( + eth_client: E, + config: GasAdjusterConfig, + erc20_fetcher_dyn: Option>, + ) -> Result { // Subtracting 1 from the "latest" block number to prevent errors in case // the info about the latest block is not yet present on the node. // This sometimes happens on Infura. @@ -44,6 +49,7 @@ impl GasAdjuster { statistics: GasStatistics::new(config.max_base_fee_samples, current_block, &history), eth_client, config, + erc20_fetcher_dyn, }) } @@ -125,7 +131,13 @@ impl L1GasPriceProvider for GasAdjuster { (self.config.internal_l1_pricing_multiplier * effective_gas_price as f64) as u64; // Bound the price if it's too high. - self.bound_gas_price(calculated_price) + let conversion_rate = match self.erc20_fetcher_dyn.as_ref() { + Some(fetcher) => fetcher.conversion_rate().unwrap_or(1) as u64, + None => 1, + }; + // let conversion_rate = 100_000_000_000_000; + + self.bound_gas_price(calculated_price) * conversion_rate } fn estimate_effective_pubdata_price(&self) -> u64 { diff --git a/core/lib/zksync_core/src/l1_gas_price/singleton.rs b/core/lib/zksync_core/src/l1_gas_price/singleton.rs index 639f00c52b9..f72483ee316 100644 --- a/core/lib/zksync_core/src/l1_gas_price/singleton.rs +++ b/core/lib/zksync_core/src/l1_gas_price/singleton.rs @@ -8,7 +8,7 @@ use tokio::{ use zksync_config::GasAdjusterConfig; use zksync_eth_client::clients::QueryClient; -use crate::l1_gas_price::GasAdjuster; +use crate::{l1_gas_price::GasAdjuster, native_erc20_fetcher::Erc20Fetcher}; /// Special struct for creating a singleton of `GasAdjuster`. /// This is needed only for running the server. @@ -17,6 +17,7 @@ pub struct GasAdjusterSingleton { web3_url: String, gas_adjuster_config: GasAdjusterConfig, singleton: OnceCell>, Error>>, + erc20_fetcher_dyn: Option>, } #[derive(thiserror::Error, Debug, Clone)] @@ -30,11 +31,16 @@ impl From for Error { } impl GasAdjusterSingleton { - pub fn new(web3_url: String, gas_adjuster_config: GasAdjusterConfig) -> Self { + pub fn new( + web3_url: String, + gas_adjuster_config: GasAdjusterConfig, + erc20_fetcher_dyn: Option>, + ) -> Self { Self { web3_url, gas_adjuster_config, singleton: OnceCell::new(), + erc20_fetcher_dyn, } } @@ -44,9 +50,13 @@ impl GasAdjusterSingleton { .get_or_init(|| async { let query_client = QueryClient::new(&self.web3_url).context("QueryClient::new()")?; - let adjuster = GasAdjuster::new(query_client.clone(), self.gas_adjuster_config) - .await - .context("GasAdjuster::new()")?; + let adjuster = GasAdjuster::new( + query_client.clone(), + self.gas_adjuster_config, + self.erc20_fetcher_dyn.clone(), + ) + .await + .context("GasAdjuster::new()")?; Ok(Arc::new(adjuster)) }) .await; diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index a81c404f51d..df9a27c02d9 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -70,7 +70,7 @@ use crate::{ l1_gas_price::{GasAdjusterSingleton, L1GasPriceProvider}, metadata_calculator::{MetadataCalculator, MetadataCalculatorConfig}, metrics::{InitStage, APP_METRICS}, - native_erc20_fetcher::{NativeErc20Fetcher, NativeErc20FetcherSingleton}, + native_erc20_fetcher::NativeErc20FetcherSingleton, state_keeper::{ create_state_keeper, MempoolFetcher, MempoolGuard, MiniblockSealer, SequencerSealer, }, @@ -326,11 +326,6 @@ pub async fn initialize_components( panic!("Circuit breaker triggered: {}", err); }); - let query_client = QueryClient::new(ð_client_config.web3_url).unwrap(); - let gas_adjuster_config = configs.gas_adjuster_config.context("gas_adjuster_config")?; - let mut gas_adjuster = - GasAdjusterSingleton::new(eth_client_config.web3_url.clone(), gas_adjuster_config); - // spawn the native ERC20 fetcher if it is enabled let mut fetcher_component = if components.contains(&Component::NativeERC20Fetcher) { let fetcher = NativeErc20FetcherSingleton::new( @@ -347,6 +342,28 @@ pub async fn initialize_components( let (stop_sender, stop_receiver) = watch::channel(false); let (cb_sender, cb_receiver) = oneshot::channel(); + let native_erc20_fetcher = if let Some(ref mut fetcher_singleton) = fetcher_component { + let fetcher = fetcher_singleton + .get_or_init() + .await + .context("fetcher.get_or_init()")?; + Some(fetcher) + } else { + None + }; + + let erc20_fetcher_dyn: Option> = native_erc20_fetcher + .as_ref() + .map(|fetcher| fetcher.clone() as Arc); + + let query_client = QueryClient::new(ð_client_config.web3_url).unwrap(); + let gas_adjuster_config = configs.gas_adjuster_config.context("gas_adjuster_config")?; + let mut gas_adjuster = GasAdjusterSingleton::new( + eth_client_config.web3_url.clone(), + gas_adjuster_config, + erc20_fetcher_dyn, + ); + // Prometheus exporter and circuit breaker checker should run for every component configuration. let prom_config = configs .prometheus_config diff --git a/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs b/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs index 3646c197c47..f17fe5c523c 100644 --- a/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs @@ -20,9 +20,8 @@ impl From for Error { } } -#[async_trait] pub trait Erc20Fetcher: 'static + std::fmt::Debug + Send + Sync { - async fn conversion_rate(&self) -> anyhow::Result; + fn conversion_rate(&self) -> anyhow::Result; } pub(crate) struct NativeErc20FetcherSingleton { @@ -106,7 +105,7 @@ impl NativeErc20Fetcher { #[async_trait] impl Erc20Fetcher for NativeErc20Fetcher { - async fn conversion_rate(&self) -> anyhow::Result { + fn conversion_rate(&self) -> anyhow::Result { anyhow::Ok( self.latest_to_eth_conversion_rate .load(std::sync::atomic::Ordering::Relaxed), From 9a055f2f8b9b11c51a356c19d1a451f552d0e8ab Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Fri, 16 Feb 2024 15:14:31 +0100 Subject: [PATCH 06/49] fix env vars names, remove unused variable --- core/lib/env_config/src/native_erc20_fetcher.rs | 2 +- core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/core/lib/env_config/src/native_erc20_fetcher.rs b/core/lib/env_config/src/native_erc20_fetcher.rs index a4a1130725b..c041156171b 100644 --- a/core/lib/env_config/src/native_erc20_fetcher.rs +++ b/core/lib/env_config/src/native_erc20_fetcher.rs @@ -4,6 +4,6 @@ use crate::{envy_load, FromEnv}; impl FromEnv for NativeErc20FetcherConfig { fn from_env() -> anyhow::Result { - envy_load("native_erc20_fetcher", "NATIVE_TOKEN_FETCHER_") + envy_load("native_erc20_fetcher", "NATIVE_ERC20_FETCHER_") } } diff --git a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs index 8e9023bcfdc..c82895afd1c 100644 --- a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs +++ b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs @@ -135,7 +135,6 @@ impl L1GasPriceProvider for GasAdjuster { Some(fetcher) => fetcher.conversion_rate().unwrap_or(1) as u64, None => 1, }; - // let conversion_rate = 100_000_000_000_000; self.bound_gas_price(calculated_price) * conversion_rate } From a16252bc9c4284df16567746cd14b1b20da8e39f Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Fri, 16 Feb 2024 15:56:34 +0100 Subject: [PATCH 07/49] remove cast to u64 --- core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs index c82895afd1c..574b9c93c1b 100644 --- a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs +++ b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs @@ -132,7 +132,7 @@ impl L1GasPriceProvider for GasAdjuster { // Bound the price if it's too high. let conversion_rate = match self.erc20_fetcher_dyn.as_ref() { - Some(fetcher) => fetcher.conversion_rate().unwrap_or(1) as u64, + Some(fetcher) => fetcher.conversion_rate().unwrap_or(1), None => 1, }; From 4fe5b7a6973fac20790b27bfd90cc3706cb57931 Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Fri, 16 Feb 2024 15:57:12 +0100 Subject: [PATCH 08/49] remove unused field from ZkSyncStateKeeper --- core/lib/zksync_core/src/lib.rs | 17 ----------------- .../zksync_core/src/native_erc20_fetcher/mod.rs | 11 ++--------- core/lib/zksync_core/src/state_keeper/keeper.rs | 10 +--------- core/lib/zksync_core/src/state_keeper/mod.rs | 7 +------ 4 files changed, 4 insertions(+), 41 deletions(-) diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index df9a27c02d9..5b24b2a663d 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -519,20 +519,6 @@ pub async fn initialize_components( .await .context("gas_adjuster.get_or_init()")?; - let native_erc20_fetcher = if let Some(ref mut fetcher_singleton) = fetcher_component { - let fetcher = fetcher_singleton - .get_or_init() - .await - .context("fetcher.get_or_init()")?; - Some(fetcher) - } else { - None - }; - - let erc20_fetcher_dyn: Option> = native_erc20_fetcher - .as_ref() - .map(|fetcher| fetcher.clone() as Arc); - add_state_keeper_to_task_futures( &mut task_futures, &postgres_config, @@ -546,7 +532,6 @@ pub async fn initialize_components( &configs.mempool_config.clone().context("mempool_config")?, bounded_gas_adjuster, store_factory.create_store().await, - erc20_fetcher_dyn, stop_receiver.clone(), ) .await @@ -746,7 +731,6 @@ async fn add_state_keeper_to_task_futures, object_store: Arc, - native_erc20_fetcher: Option>, stop_receiver: watch::Receiver, ) -> anyhow::Result<()> { let pool_builder = ConnectionPool::singleton(postgres_config.master_url()?); @@ -790,7 +774,6 @@ async fn add_state_keeper_to_task_futures anyhow::Result { - Ok(self - .latest_to_eth_conversion_rate - .load(std::sync::atomic::Ordering::Relaxed)) - } } #[async_trait] diff --git a/core/lib/zksync_core/src/state_keeper/keeper.rs b/core/lib/zksync_core/src/state_keeper/keeper.rs index 33f09cf595a..35aaf77cb5a 100644 --- a/core/lib/zksync_core/src/state_keeper/keeper.rs +++ b/core/lib/zksync_core/src/state_keeper/keeper.rs @@ -1,13 +1,11 @@ use std::{ convert::Infallible, - sync::Arc, time::{Duration, Instant}, }; use anyhow::Context as _; use multivm::interface::{Halt, L1BatchEnv, SystemEnv}; use tokio::sync::watch; -use zksync_config::configs::native_erc20_fetcher; use zksync_types::{ block::MiniblockExecutionData, l2::TransactionType, protocol_version::ProtocolUpgradeTx, storage_writes_deduplicator::StorageWritesDeduplicator, L1BatchNumber, Transaction, @@ -22,10 +20,7 @@ use super::{ types::ExecutionMetricsForCriteria, updates::UpdatesManager, }; -use crate::{ - gas_tracker::gas_count_from_writes, - native_erc20_fetcher::{Erc20Fetcher, NativeErc20Fetcher}, -}; +use crate::gas_tracker::gas_count_from_writes; /// Amount of time to block on waiting for some resource. The exact value is not really important, /// we only need it to not block on waiting indefinitely and be able to process cancellation requests. @@ -64,7 +59,6 @@ pub struct ZkSyncStateKeeper { io: Box, batch_executor_base: Box, sealer: Box, - native_erc20_fetcher: Box>>, } impl ZkSyncStateKeeper { @@ -73,14 +67,12 @@ impl ZkSyncStateKeeper { io: Box, batch_executor_base: Box, sealer: Box, - native_erc20_fetcher: Box>>, ) -> Self { Self { stop_receiver, io, batch_executor_base, sealer, - native_erc20_fetcher, } } diff --git a/core/lib/zksync_core/src/state_keeper/mod.rs b/core/lib/zksync_core/src/state_keeper/mod.rs index 5f7ed623bdb..b1534d9612f 100644 --- a/core/lib/zksync_core/src/state_keeper/mod.rs +++ b/core/lib/zksync_core/src/state_keeper/mod.rs @@ -17,10 +17,7 @@ pub use self::{ pub(crate) use self::{ mempool_actor::MempoolFetcher, seal_criteria::SequencerSealer, types::MempoolGuard, }; -use crate::{ - fee_model::BatchFeeModelInputProvider, - native_erc20_fetcher::{Erc20Fetcher, NativeErc20Fetcher}, -}; +use crate::fee_model::BatchFeeModelInputProvider; mod batch_executor; pub(crate) mod extractors; @@ -46,7 +43,6 @@ pub(crate) async fn create_state_keeper( batch_fee_input_provider: Arc, miniblock_sealer_handle: MiniblockSealerHandle, object_store: Arc, - native_erc20_fetcher: Option>, stop_receiver: watch::Receiver, ) -> ZkSyncStateKeeper { let batch_executor_base = MainBatchExecutorBuilder::new( @@ -79,6 +75,5 @@ pub(crate) async fn create_state_keeper( Box::new(io), Box::new(batch_executor_base), Box::new(sealer), - Box::new(native_erc20_fetcher), ) } From 5de1233bb87285d0e32c5c04ba795f8a84c36832 Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Mon, 26 Feb 2024 10:58:48 -0300 Subject: [PATCH 09/49] Use = &mut instead of ref mut --- core/lib/zksync_core/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index 5b24b2a663d..bae153720ab 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -342,7 +342,7 @@ pub async fn initialize_components( let (stop_sender, stop_receiver) = watch::channel(false); let (cb_sender, cb_receiver) = oneshot::channel(); - let native_erc20_fetcher = if let Some(ref mut fetcher_singleton) = fetcher_component { + let native_erc20_fetcher = if let Some(fetcher_singleton) = &mut fetcher_component { let fetcher = fetcher_singleton .get_or_init() .await From 773ff7a2b1977b30cfd192e13073b615ca00522e Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Mon, 26 Feb 2024 19:46:57 -0300 Subject: [PATCH 10/49] Fetch the conversion rate on Fetcher initialization to avoid incorrect values on server startup --- .../zksync_core/src/native_erc20_fetcher/mod.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs b/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs index 9720e7a09be..77a0b30e4bb 100644 --- a/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs @@ -41,7 +41,8 @@ impl NativeErc20FetcherSingleton { let adjuster = self .singleton .get_or_init(|| async { - let fetcher = NativeErc20Fetcher::new(self.native_erc20_fetcher_config.clone()); + let fetcher = + NativeErc20Fetcher::new(self.native_erc20_fetcher_config.clone()).await; Ok(Arc::new(fetcher)) }) .await; @@ -66,10 +67,17 @@ pub(crate) struct NativeErc20Fetcher { } impl NativeErc20Fetcher { - pub(crate) fn new(config: NativeErc20FetcherConfig) -> Self { + pub(crate) async fn new(config: NativeErc20FetcherConfig) -> Self { + let conversion_rate = reqwest::get(format!("{}/conversion_rate", config.host)) + .await + .unwrap() + .json::() + .await + .unwrap(); + Self { config, - latest_to_eth_conversion_rate: AtomicU64::new(0), + latest_to_eth_conversion_rate: AtomicU64::new(conversion_rate), } } From fd3e7d2840006c9299098dc1aff731f549a589b5 Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Tue, 27 Feb 2024 12:19:55 -0300 Subject: [PATCH 11/49] Add http client as a field to the native erc20 fetcher --- .../lib/zksync_core/src/native_erc20_fetcher/mod.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs b/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs index 77a0b30e4bb..9bea43090de 100644 --- a/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs @@ -60,10 +60,9 @@ impl NativeErc20FetcherSingleton { #[derive(Debug)] pub(crate) struct NativeErc20Fetcher { - // TODO: we probably need to add a http client here - // to avoid creating a new one for each request pub config: NativeErc20FetcherConfig, pub latest_to_eth_conversion_rate: AtomicU64, + http_client: reqwest::Client, } impl NativeErc20Fetcher { @@ -75,20 +74,26 @@ impl NativeErc20Fetcher { .await .unwrap(); + let http_client = reqwest::Client::new(); + Self { config, latest_to_eth_conversion_rate: AtomicU64::new(conversion_rate), + http_client: http_client, } } pub(crate) async fn run(&self, stop_receiver: watch::Receiver) -> anyhow::Result<()> { loop { if *stop_receiver.borrow() { - tracing::info!("Stop signal received, eth_tx_manager is shutting down"); + tracing::info!("Stop signal received, native_erc20_fetcher is shutting down"); break; } - let conversion_rate = reqwest::get(format!("{}/conversion_rate", &self.config.host)) + let conversion_rate = self + .http_client + .get(format!("{}/conversion_rate", &self.config.host)) + .send() .await? .json::() .await From 6838588290160de7db1b09d7bcaf168a28366b70 Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Tue, 27 Feb 2024 17:00:21 -0300 Subject: [PATCH 12/49] Rename NativeErc20 stuff to be NativeToken instead --- core/bin/zksync_server/src/main.rs | 4 +- core/lib/config/src/configs/mod.rs | 2 +- ...c20_fetcher.rs => native_token_fetcher.rs} | 2 +- core/lib/env_config/src/lib.rs | 2 +- .../env_config/src/native_erc20_fetcher.rs | 9 ----- .../env_config/src/native_token_fetcher.rs | 9 +++++ .../src/l1_gas_price/gas_adjuster/mod.rs | 10 ++--- .../zksync_core/src/l1_gas_price/singleton.rs | 6 +-- core/lib/zksync_core/src/lib.rs | 28 ++++++------- .../mod.rs | 38 +++++++++--------- core/lib/zksync_core/src/temp_config_store.rs | 4 +- ...fetcher.toml => native_token_fetcher.toml} | 2 +- etc/env/l1-inits/.init.env | 40 +++++++++---------- 13 files changed, 78 insertions(+), 78 deletions(-) rename core/lib/config/src/configs/{native_erc20_fetcher.rs => native_token_fetcher.rs} (76%) delete mode 100644 core/lib/env_config/src/native_erc20_fetcher.rs create mode 100644 core/lib/env_config/src/native_token_fetcher.rs rename core/lib/zksync_core/src/{native_erc20_fetcher => native_token_fetcher}/mod.rs (67%) rename etc/env/base/{erc20_fetcher.toml => native_token_fetcher.toml} (76%) diff --git a/core/bin/zksync_server/src/main.rs b/core/bin/zksync_server/src/main.rs index 068d1190218..fcf1bed8dd6 100644 --- a/core/bin/zksync_server/src/main.rs +++ b/core/bin/zksync_server/src/main.rs @@ -11,7 +11,7 @@ use zksync_config::{ }, fri_prover_group::FriProverGroupConfig, house_keeper::HouseKeeperConfig, - native_erc20_fetcher::NativeErc20FetcherConfig, + native_token_fetcher::NativeTokenFetcherConfig, FriProofCompressorConfig, FriProverConfig, FriWitnessGeneratorConfig, PrometheusConfig, ProofDataHandlerConfig, WitnessGeneratorConfig, }, @@ -120,7 +120,7 @@ async fn main() -> anyhow::Result<()> { eth_watch_config: ETHWatchConfig::from_env().ok(), gas_adjuster_config: GasAdjusterConfig::from_env().ok(), object_store_config: ObjectStoreConfig::from_env().ok(), - native_erc20_fetcher_config: NativeErc20FetcherConfig::from_env().ok(), + native_token_fetcher_config: NativeTokenFetcherConfig::from_env().ok(), }; let postgres_config = configs.postgres_config.clone().context("PostgresConfig")?; diff --git a/core/lib/config/src/configs/mod.rs b/core/lib/config/src/configs/mod.rs index 93dc0e787fb..4caf528d866 100644 --- a/core/lib/config/src/configs/mod.rs +++ b/core/lib/config/src/configs/mod.rs @@ -36,7 +36,7 @@ pub mod fri_prover_group; pub mod fri_witness_generator; pub mod fri_witness_vector_generator; pub mod house_keeper; -pub mod native_erc20_fetcher; +pub mod native_token_fetcher; pub mod object_store; pub mod proof_data_handler; pub mod snapshots_creator; diff --git a/core/lib/config/src/configs/native_erc20_fetcher.rs b/core/lib/config/src/configs/native_token_fetcher.rs similarity index 76% rename from core/lib/config/src/configs/native_erc20_fetcher.rs rename to core/lib/config/src/configs/native_token_fetcher.rs index 758347e9b28..38debd1a843 100644 --- a/core/lib/config/src/configs/native_erc20_fetcher.rs +++ b/core/lib/config/src/configs/native_token_fetcher.rs @@ -1,7 +1,7 @@ use serde::Deserialize; #[derive(Debug, Clone, Deserialize, PartialEq)] -pub struct NativeErc20FetcherConfig { +pub struct NativeTokenFetcherConfig { pub poll_interval: u64, pub host: String, } diff --git a/core/lib/env_config/src/lib.rs b/core/lib/env_config/src/lib.rs index 911426cf90d..1b00618ab25 100644 --- a/core/lib/env_config/src/lib.rs +++ b/core/lib/env_config/src/lib.rs @@ -17,7 +17,7 @@ mod fri_prover_group; mod fri_witness_generator; mod fri_witness_vector_generator; mod house_keeper; -pub mod native_erc20_fetcher; +pub mod native_token_fetcher; pub mod object_store; mod proof_data_handler; mod snapshots_creator; diff --git a/core/lib/env_config/src/native_erc20_fetcher.rs b/core/lib/env_config/src/native_erc20_fetcher.rs deleted file mode 100644 index c041156171b..00000000000 --- a/core/lib/env_config/src/native_erc20_fetcher.rs +++ /dev/null @@ -1,9 +0,0 @@ -use zksync_config::configs::native_erc20_fetcher::NativeErc20FetcherConfig; - -use crate::{envy_load, FromEnv}; - -impl FromEnv for NativeErc20FetcherConfig { - fn from_env() -> anyhow::Result { - envy_load("native_erc20_fetcher", "NATIVE_ERC20_FETCHER_") - } -} diff --git a/core/lib/env_config/src/native_token_fetcher.rs b/core/lib/env_config/src/native_token_fetcher.rs new file mode 100644 index 00000000000..dde0e086907 --- /dev/null +++ b/core/lib/env_config/src/native_token_fetcher.rs @@ -0,0 +1,9 @@ +use zksync_config::configs::native_token_fetcher::NativeTokenFetcherConfig; + +use crate::{envy_load, FromEnv}; + +impl FromEnv for NativeTokenFetcherConfig { + fn from_env() -> anyhow::Result { + envy_load("native_token_fetcher", "NATIVE_TOKEN_FETCHER_") + } +} diff --git a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs index 574b9c93c1b..5fa771ae25d 100644 --- a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs +++ b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs @@ -12,7 +12,7 @@ use zksync_system_constants::L1_GAS_PER_PUBDATA_BYTE; use self::metrics::METRICS; use super::{L1GasPriceProvider, L1TxParamsProvider}; -use crate::{native_erc20_fetcher::Erc20Fetcher, state_keeper::metrics::KEEPER_METRICS}; +use crate::{native_token_fetcher::ConversionRateFetcher, state_keeper::metrics::KEEPER_METRICS}; mod metrics; #[cfg(test)] @@ -25,14 +25,14 @@ pub struct GasAdjuster { pub(super) statistics: GasStatistics, pub(super) config: GasAdjusterConfig, eth_client: E, - erc20_fetcher_dyn: Option>, + native_token_fetcher_dyn: Option>, } impl GasAdjuster { pub async fn new( eth_client: E, config: GasAdjusterConfig, - erc20_fetcher_dyn: Option>, + native_token_fetcher_dyn: Option>, ) -> Result { // Subtracting 1 from the "latest" block number to prevent errors in case // the info about the latest block is not yet present on the node. @@ -49,7 +49,7 @@ impl GasAdjuster { statistics: GasStatistics::new(config.max_base_fee_samples, current_block, &history), eth_client, config, - erc20_fetcher_dyn, + native_token_fetcher_dyn, }) } @@ -131,7 +131,7 @@ impl L1GasPriceProvider for GasAdjuster { (self.config.internal_l1_pricing_multiplier * effective_gas_price as f64) as u64; // Bound the price if it's too high. - let conversion_rate = match self.erc20_fetcher_dyn.as_ref() { + let conversion_rate = match self.native_token_fetcher_dyn.as_ref() { Some(fetcher) => fetcher.conversion_rate().unwrap_or(1), None => 1, }; diff --git a/core/lib/zksync_core/src/l1_gas_price/singleton.rs b/core/lib/zksync_core/src/l1_gas_price/singleton.rs index f72483ee316..21fc9a5e7ee 100644 --- a/core/lib/zksync_core/src/l1_gas_price/singleton.rs +++ b/core/lib/zksync_core/src/l1_gas_price/singleton.rs @@ -8,7 +8,7 @@ use tokio::{ use zksync_config::GasAdjusterConfig; use zksync_eth_client::clients::QueryClient; -use crate::{l1_gas_price::GasAdjuster, native_erc20_fetcher::Erc20Fetcher}; +use crate::{l1_gas_price::GasAdjuster, native_token_fetcher::ConversionRateFetcher}; /// Special struct for creating a singleton of `GasAdjuster`. /// This is needed only for running the server. @@ -17,7 +17,7 @@ pub struct GasAdjusterSingleton { web3_url: String, gas_adjuster_config: GasAdjusterConfig, singleton: OnceCell>, Error>>, - erc20_fetcher_dyn: Option>, + erc20_fetcher_dyn: Option>, } #[derive(thiserror::Error, Debug, Clone)] @@ -34,7 +34,7 @@ impl GasAdjusterSingleton { pub fn new( web3_url: String, gas_adjuster_config: GasAdjusterConfig, - erc20_fetcher_dyn: Option>, + erc20_fetcher_dyn: Option>, ) -> Self { Self { web3_url, diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index bae153720ab..dad2a497b86 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -5,7 +5,6 @@ use std::{net::Ipv4Addr, str::FromStr, sync::Arc, time::Instant}; use anyhow::Context as _; use fee_model::MainNodeFeeInputProvider; use futures::channel::oneshot; -use native_erc20_fetcher::Erc20Fetcher; use prometheus_exporter::PrometheusExporterConfig; use temp_config_store::TempConfigStore; use tokio::{sync::watch, task::JoinHandle}; @@ -49,8 +48,7 @@ use crate::{ execution_sandbox::{VmConcurrencyBarrier, VmConcurrencyLimiter}, healthcheck::HealthCheckHandle, tx_sender::{ApiContracts, TxSender, TxSenderBuilder, TxSenderConfig}, - web3, - web3::{state::InternalApiConfig, ApiServerHandles, Namespace}, + web3::{self, state::InternalApiConfig, ApiServerHandles, Namespace}, }, basic_witness_input_producer::BasicWitnessInputProducer, eth_sender::{Aggregator, EthTxAggregator, EthTxManager}, @@ -70,7 +68,7 @@ use crate::{ l1_gas_price::{GasAdjusterSingleton, L1GasPriceProvider}, metadata_calculator::{MetadataCalculator, MetadataCalculatorConfig}, metrics::{InitStage, APP_METRICS}, - native_erc20_fetcher::NativeErc20FetcherSingleton, + native_token_fetcher::{ConversionRateFetcher, NativeTokenFetcherSingleton}, state_keeper::{ create_state_keeper, MempoolFetcher, MempoolGuard, MiniblockSealer, SequencerSealer, }, @@ -90,7 +88,7 @@ pub mod house_keeper; pub mod l1_gas_price; pub mod metadata_calculator; mod metrics; -pub mod native_erc20_fetcher; +pub mod native_token_fetcher; pub mod proof_data_handler; pub mod reorg_detector; pub mod state_keeper; @@ -233,8 +231,8 @@ pub enum Component { Housekeeper, /// Component for exposing APIs to prover for providing proof generation data and accepting proofs. ProofDataHandler, - /// Native ERC20 fetcher - NativeERC20Fetcher, + /// Native Token fetcher + NativeTokenFetcher, } #[derive(Debug)] @@ -269,7 +267,7 @@ impl FromStr for Components { "eth_tx_aggregator" => Ok(Components(vec![Component::EthTxAggregator])), "eth_tx_manager" => Ok(Components(vec![Component::EthTxManager])), "proof_data_handler" => Ok(Components(vec![Component::ProofDataHandler])), - "native_erc20_fetcher" => Ok(Components(vec![Component::NativeERC20Fetcher])), + "native_token_fetcher" => Ok(Components(vec![Component::NativeTokenFetcher])), other => Err(format!("{} is not a valid component name", other)), } } @@ -327,12 +325,12 @@ pub async fn initialize_components( }); // spawn the native ERC20 fetcher if it is enabled - let mut fetcher_component = if components.contains(&Component::NativeERC20Fetcher) { - let fetcher = NativeErc20FetcherSingleton::new( + let mut fetcher_component = if components.contains(&Component::NativeTokenFetcher) { + let fetcher = NativeTokenFetcherSingleton::new( configs - .native_erc20_fetcher_config + .native_token_fetcher_config .clone() - .context("native_erc20_fetcher_config")?, + .context("native_token_fetcher_config")?, ); Some(fetcher) @@ -342,7 +340,7 @@ pub async fn initialize_components( let (stop_sender, stop_receiver) = watch::channel(false); let (cb_sender, cb_receiver) = oneshot::channel(); - let native_erc20_fetcher = if let Some(fetcher_singleton) = &mut fetcher_component { + let native_token_fetcher = if let Some(fetcher_singleton) = &mut fetcher_component { let fetcher = fetcher_singleton .get_or_init() .await @@ -352,9 +350,9 @@ pub async fn initialize_components( None }; - let erc20_fetcher_dyn: Option> = native_erc20_fetcher + let erc20_fetcher_dyn: Option> = native_token_fetcher .as_ref() - .map(|fetcher| fetcher.clone() as Arc); + .map(|fetcher| fetcher.clone() as Arc); let query_client = QueryClient::new(ð_client_config.web3_url).unwrap(); let gas_adjuster_config = configs.gas_adjuster_config.context("gas_adjuster_config")?; diff --git a/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs similarity index 67% rename from core/lib/zksync_core/src/native_erc20_fetcher/mod.rs rename to core/lib/zksync_core/src/native_token_fetcher/mod.rs index 77a0b30e4bb..82c81d124bb 100644 --- a/core/lib/zksync_core/src/native_erc20_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -6,7 +6,7 @@ use tokio::{ sync::{watch, OnceCell}, task::JoinHandle, }; -use zksync_config::configs::native_erc20_fetcher::NativeErc20FetcherConfig; +use zksync_config::configs::native_token_fetcher::NativeTokenFetcherConfig; // TODO: this error type is also defined by the gasAdjuster module, // we should consider moving it to a common place @@ -20,29 +20,31 @@ impl From for Error { } } -pub trait Erc20Fetcher: 'static + std::fmt::Debug + Send + Sync { +/// Trait used to query the stack's native token conversion rate. Used to properly +/// determine gas prices, as they partially depend on L1 gas prices, denominated in `eth`. +pub trait ConversionRateFetcher: 'static + std::fmt::Debug + Send + Sync { fn conversion_rate(&self) -> anyhow::Result; } -pub(crate) struct NativeErc20FetcherSingleton { - native_erc20_fetcher_config: NativeErc20FetcherConfig, - singleton: OnceCell, Error>>, +pub(crate) struct NativeTokenFetcherSingleton { + native_token_fetcher_config: NativeTokenFetcherConfig, + singleton: OnceCell, Error>>, } -impl NativeErc20FetcherSingleton { - pub fn new(native_erc20_fetcher_config: NativeErc20FetcherConfig) -> Self { +impl NativeTokenFetcherSingleton { + pub fn new(native_token_fetcher_config: NativeTokenFetcherConfig) -> Self { Self { - native_erc20_fetcher_config, + native_token_fetcher_config, singleton: OnceCell::new(), } } - pub async fn get_or_init(&mut self) -> Result, Error> { + pub async fn get_or_init(&mut self) -> Result, Error> { let adjuster = self .singleton .get_or_init(|| async { let fetcher = - NativeErc20Fetcher::new(self.native_erc20_fetcher_config.clone()).await; + NativeTokenFetcher::new(self.native_token_fetcher_config.clone()).await; Ok(Arc::new(fetcher)) }) .await; @@ -58,16 +60,16 @@ impl NativeErc20FetcherSingleton { } } +/// Struct in charge of periodically querying and caching the native token's conversion rate +/// to `eth`. #[derive(Debug)] -pub(crate) struct NativeErc20Fetcher { - // TODO: we probably need to add a http client here - // to avoid creating a new one for each request - pub config: NativeErc20FetcherConfig, +pub(crate) struct NativeTokenFetcher { + pub config: NativeTokenFetcherConfig, pub latest_to_eth_conversion_rate: AtomicU64, } -impl NativeErc20Fetcher { - pub(crate) async fn new(config: NativeErc20FetcherConfig) -> Self { +impl NativeTokenFetcher { + pub(crate) async fn new(config: NativeTokenFetcherConfig) -> Self { let conversion_rate = reqwest::get(format!("{}/conversion_rate", config.host)) .await .unwrap() @@ -84,7 +86,7 @@ impl NativeErc20Fetcher { pub(crate) async fn run(&self, stop_receiver: watch::Receiver) -> anyhow::Result<()> { loop { if *stop_receiver.borrow() { - tracing::info!("Stop signal received, eth_tx_manager is shutting down"); + tracing::info!("Stop signal received, native_token_fetcher is shutting down"); break; } @@ -105,7 +107,7 @@ impl NativeErc20Fetcher { } #[async_trait] -impl Erc20Fetcher for NativeErc20Fetcher { +impl ConversionRateFetcher for NativeTokenFetcher { fn conversion_rate(&self) -> anyhow::Result { anyhow::Ok( self.latest_to_eth_conversion_rate diff --git a/core/lib/zksync_core/src/temp_config_store.rs b/core/lib/zksync_core/src/temp_config_store.rs index 98fd6c3b33e..8c7fb2c1fb5 100644 --- a/core/lib/zksync_core/src/temp_config_store.rs +++ b/core/lib/zksync_core/src/temp_config_store.rs @@ -7,7 +7,7 @@ use zksync_config::{ }, fri_prover_group::FriProverGroupConfig, house_keeper::HouseKeeperConfig, - native_erc20_fetcher::NativeErc20FetcherConfig, + native_token_fetcher::NativeTokenFetcherConfig, FriProofCompressorConfig, FriProverConfig, FriWitnessGeneratorConfig, PrometheusConfig, ProofDataHandlerConfig, WitnessGeneratorConfig, }, @@ -45,5 +45,5 @@ pub struct TempConfigStore { pub eth_watch_config: Option, pub gas_adjuster_config: Option, pub object_store_config: Option, - pub native_erc20_fetcher_config: Option, + pub native_token_fetcher_config: Option, } diff --git a/etc/env/base/erc20_fetcher.toml b/etc/env/base/native_token_fetcher.toml similarity index 76% rename from etc/env/base/erc20_fetcher.toml rename to etc/env/base/native_token_fetcher.toml index 939fb27b460..aaf42d42ab4 100644 --- a/etc/env/base/erc20_fetcher.toml +++ b/etc/env/base/native_token_fetcher.toml @@ -1,4 +1,4 @@ -[native_erc20_fetcher] +[native_token_fetcher] host="http://127.0.0.1:5000" # Poll interval is in seconds poll_interval=10 diff --git a/etc/env/l1-inits/.init.env b/etc/env/l1-inits/.init.env index bc59563d842..efb1742d996 100644 --- a/etc/env/l1-inits/.init.env +++ b/etc/env/l1-inits/.init.env @@ -1,29 +1,29 @@ CONTRACTS_LATEST_PROTOCOL_VERSION=22 CONTRACTS_CREATE2_FACTORY_ADDR=0x3c4CE2E9D8b03BbCd568E47465A483EE86893c49 -CONTRACTS_VERIFIER_ADDR=0x5c30A64f323c341497258D9a3eC55D1A1aD5b3f3 -CONTRACTS_L1_MULTICALL3_ADDR=0x1A70f23b21a983C7b8c2B60f3964973CE0F46a37 +CONTRACTS_VERIFIER_ADDR=0xCf42AEFfB17dED8de2d4116D33716354F53e51e6 +CONTRACTS_L1_MULTICALL3_ADDR=0x69D85c64032337E58064A35020d6F45Dab350883 CONTRACTS_GENESIS_ROOT=0x300ac58a9fa3b6283791831f5d62b1b525b81e6ec4f4793bea5fb14ebea730c7 CHAIN_STATE_KEEPER_BOOTLOADER_HASH=0x010007ed36aa249ae63fa088c251736a3170cd179a03d8d6f0fe6a6f47b23705 CHAIN_STATE_KEEPER_DEFAULT_AA_HASH=0x0100055bbad08b38b8e0b22b57703bb1f440b8789a3ba809a4ca4830c497e1d4 CONTRACTS_GENESIS_BATCH_COMMITMENT=0x921bdf66c72d3f84c1f7520050c4980721d32b6c95c76ab32aaa556a6430d24c CONTRACTS_GENESIS_ROLLUP_LEAF_INDEX=25 CONTRACTS_L1_WETH_TOKEN_ADDR=0x4A470422bFf67C34a3A565106118023059fa4E34 -CONTRACTS_BRIDGEHUB_PROXY_ADDR=0x463151A0713aD71b6182073965693f088909f88C -CONTRACTS_BRIDGEHUB_IMPL_ADDR=0xD3ADb5a413510e0f9eF1C1F4F27e10a9985c9401 -CONTRACTS_STATE_TRANSITION_PROXY_ADDR=0x0Cf3E2a556b0cF22bb727fA1E441C014EE405686 -CONTRACTS_STATE_TRANSITION_IMPL_ADDR=0x585380F7144B533f963D8b138602730C15d438d8 -CONTRACTS_ADMIN_FACET_ADDR=0x4660Fd112Ebc269C19f08508Ba5820B4115703B5 -CONTRACTS_DIAMOND_UPGRADE_INIT_ADDR=0xD81AA805FCc7350fE58234bAE019A97736d4155E -CONTRACTS_DIAMOND_INIT_ADDR=0xd34a475F8eC8767bB8485c7e1512281446Be4760 -CONTRACTS_DEFAULT_UPGRADE_ADDR=0x2be7dD65605C1DDFc995fb9CDB90bC94B257614a -CONTRACTS_GENESIS_UPGRADE_ADDR=0xCbb9F33327afE40ab612cec3585B950D1Fe35B49 -CONTRACTS_GOVERNANCE_ADDR=0x5aBbB05B314d20839De8b45dfbB67295030bcD5F -CONTRACTS_MAILBOX_FACET_ADDR=0xb228e268d4095C8d44981cdb9a5E71fb715c947B -CONTRACTS_EXECUTOR_FACET_ADDR=0x9405ff27d4c71CdedCdad53C20157f416823ccc6 -CONTRACTS_GETTERS_FACET_ADDR=0x5c747E49a38799e9E1cbDD1ab6ebE57cf812E887 -CONTRACTS_VALIDATOR_TIMELOCK_ADDR=0x0fa9a7cB2Ea1658d7be4C7d7830b9de7Dcd701b0 +CONTRACTS_BRIDGEHUB_PROXY_ADDR=0xb81673bCE7AAd30D8C18A3e118fc5018B8E1b304 +CONTRACTS_BRIDGEHUB_IMPL_ADDR=0x8F78c7272727e3cf99d631cA2Ee04A7F866F7D0A +CONTRACTS_STATE_TRANSITION_PROXY_ADDR=0x71470A85Afc4dE5241ae84c5b382c245e36E2e2E +CONTRACTS_STATE_TRANSITION_IMPL_ADDR=0x5C542Cc2886E6B8172D1E87637b5f681df6cE6b4 +CONTRACTS_ADMIN_FACET_ADDR=0xB178e8fECEa2521aC351f4179eF53014EF66deA4 +CONTRACTS_DIAMOND_UPGRADE_INIT_ADDR=0x01e88D723515404ea24136D2b2209D80597c60EE +CONTRACTS_DIAMOND_INIT_ADDR=0x1440EbE06A353bca88cAD588d5AC55513ACC9d31 +CONTRACTS_DEFAULT_UPGRADE_ADDR=0xD14F5CF299EF63a9aD5DcF35D7c43b07c48192Ff +CONTRACTS_GENESIS_UPGRADE_ADDR=0x223350ebdb7bB5EE851C1e089D51cc1900D84CC6 +CONTRACTS_GOVERNANCE_ADDR=0x410a4b3a5A7F2c52B1bCdeFBA05091a932A75c82 +CONTRACTS_MAILBOX_FACET_ADDR=0xb73B7e1cA6ef3F9d036466004433FB9E2f3eB3ce +CONTRACTS_EXECUTOR_FACET_ADDR=0x9F630Aa2999ff37736a5a64FA4Edd396A5d0Cafc +CONTRACTS_GETTERS_FACET_ADDR=0x27197A55F385AA3bA572618928845f591f677AD7 +CONTRACTS_VALIDATOR_TIMELOCK_ADDR=0x43e5978b9BCF261e3b3d93bfc76b36db513A7C42 CONTRACTS_TRANSPARENT_PROXY_ADMIN_ADDR=0x20410058241d1c4C5f7C04753BD4713B04f19423 -CONTRACTS_L1_SHARED_BRIDGE_PROXY_ADDR=0x9D5b8B500657902135932161BD9aaDc39b466376 -CONTRACTS_L1_SHARED_BRIDGE_IMPL_ADDR=0xc95D922550ac40660789d8F95F3311311E8E4E69 -CONTRACTS_L1_ERC20_BRIDGE_PROXY_ADDR=0x9d4E2808968f2Bdb081C6f3C59bDD3C2096FB375 -CONTRACTS_L1_ERC20_BRIDGE_IMPL_ADDR=0x2DF7728e71Ccc114490270BD538B3594e1D1796d +CONTRACTS_L1_SHARED_BRIDGE_PROXY_ADDR=0x3C95EE1e5dade52f008b71d09fE0ba178603AFC3 +CONTRACTS_L1_SHARED_BRIDGE_IMPL_ADDR=0x3D3805B1B87A9a69232B4082955A3982049d1EA2 +CONTRACTS_L1_ERC20_BRIDGE_PROXY_ADDR=0x910123E3Fe7a35a5A76735cbA6D4f25A0F1eE459 +CONTRACTS_L1_ERC20_BRIDGE_IMPL_ADDR=0x025d71862C01c20Ccb858d98BBB01078c3690B2d From 67286bca2a89cea695043c91e64facf33cb9f102 Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Wed, 28 Feb 2024 09:59:32 -0300 Subject: [PATCH 13/49] initial commit --- .../src/l1_gas_price/gas_adjuster/mod.rs | 13 +++++---- .../zksync_core/src/l1_gas_price/singleton.rs | 4 +-- core/lib/zksync_core/src/lib.rs | 28 ++++++++++--------- .../src/native_token_fetcher/mod.rs | 16 +++++++++++ 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs index 5fa771ae25d..43851f150ff 100644 --- a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs +++ b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs @@ -25,14 +25,14 @@ pub struct GasAdjuster { pub(super) statistics: GasStatistics, pub(super) config: GasAdjusterConfig, eth_client: E, - native_token_fetcher_dyn: Option>, + native_token_fetcher_dyn: Arc, } impl GasAdjuster { pub async fn new( eth_client: E, config: GasAdjusterConfig, - native_token_fetcher_dyn: Option>, + native_token_fetcher_dyn: Arc, ) -> Result { // Subtracting 1 from the "latest" block number to prevent errors in case // the info about the latest block is not yet present on the node. @@ -131,10 +131,11 @@ impl L1GasPriceProvider for GasAdjuster { (self.config.internal_l1_pricing_multiplier * effective_gas_price as f64) as u64; // Bound the price if it's too high. - let conversion_rate = match self.native_token_fetcher_dyn.as_ref() { - Some(fetcher) => fetcher.conversion_rate().unwrap_or(1), - None => 1, - }; + // let conversion_rate = match self.native_token_fetcher_dyn.as_ref() { + // Some(fetcher) => fetcher.conversion_rate().unwrap_or(1), + // None => 1, + // }; + let conversion_rate = self.native_token_fetcher_dyn.conversion_rate().unwrap_or(1); self.bound_gas_price(calculated_price) * conversion_rate } diff --git a/core/lib/zksync_core/src/l1_gas_price/singleton.rs b/core/lib/zksync_core/src/l1_gas_price/singleton.rs index 21fc9a5e7ee..8d2204b943f 100644 --- a/core/lib/zksync_core/src/l1_gas_price/singleton.rs +++ b/core/lib/zksync_core/src/l1_gas_price/singleton.rs @@ -17,7 +17,7 @@ pub struct GasAdjusterSingleton { web3_url: String, gas_adjuster_config: GasAdjusterConfig, singleton: OnceCell>, Error>>, - erc20_fetcher_dyn: Option>, + erc20_fetcher_dyn: Arc, } #[derive(thiserror::Error, Debug, Clone)] @@ -34,7 +34,7 @@ impl GasAdjusterSingleton { pub fn new( web3_url: String, gas_adjuster_config: GasAdjusterConfig, - erc20_fetcher_dyn: Option>, + erc20_fetcher_dyn: Arc, ) -> Self { Self { web3_url, diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index dad2a497b86..56a8accb4bf 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -68,7 +68,9 @@ use crate::{ l1_gas_price::{GasAdjusterSingleton, L1GasPriceProvider}, metadata_calculator::{MetadataCalculator, MetadataCalculatorConfig}, metrics::{InitStage, APP_METRICS}, - native_token_fetcher::{ConversionRateFetcher, NativeTokenFetcherSingleton}, + native_token_fetcher::{ + ConversionRateFetcher, NativeTokenFetcherSingleton, NoOpConversionRateFetcher, + }, state_keeper::{ create_state_keeper, MempoolFetcher, MempoolGuard, MiniblockSealer, SequencerSealer, }, @@ -340,19 +342,19 @@ pub async fn initialize_components( let (stop_sender, stop_receiver) = watch::channel(false); let (cb_sender, cb_receiver) = oneshot::channel(); - let native_token_fetcher = if let Some(fetcher_singleton) = &mut fetcher_component { - let fetcher = fetcher_singleton - .get_or_init() - .await - .context("fetcher.get_or_init()")?; - Some(fetcher) - } else { - None - }; + let native_token_fetcher: Arc = + if let Some(fetcher_singleton) = &mut fetcher_component { + let fetcher = fetcher_singleton + .get_or_init() + .await + .context("fetcher.get_or_init()")?; + fetcher + } else { + // create no-op fetcher if the native token fetcher is not enabled + Arc::new(NoOpConversionRateFetcher::new()) + }; - let erc20_fetcher_dyn: Option> = native_token_fetcher - .as_ref() - .map(|fetcher| fetcher.clone() as Arc); + let erc20_fetcher_dyn: Arc = native_token_fetcher.clone(); let query_client = QueryClient::new(ð_client_config.web3_url).unwrap(); let gas_adjuster_config = configs.gas_adjuster_config.context("gas_adjuster_config")?; diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index 82c81d124bb..eda45879c93 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -26,6 +26,22 @@ pub trait ConversionRateFetcher: 'static + std::fmt::Debug + Send + Sync { fn conversion_rate(&self) -> anyhow::Result; } +#[derive(Debug)] +pub(crate) struct NoOpConversionRateFetcher; + +impl NoOpConversionRateFetcher { + pub fn new() -> Self { + Self + } +} + +#[async_trait] +impl ConversionRateFetcher for NoOpConversionRateFetcher { + fn conversion_rate(&self) -> anyhow::Result { + Ok(1) + } +} + pub(crate) struct NativeTokenFetcherSingleton { native_token_fetcher_config: NativeTokenFetcherConfig, singleton: OnceCell, Error>>, From 08e8b5a3d920e95be2775ae41804e96f2320150e Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Wed, 28 Feb 2024 10:41:17 -0300 Subject: [PATCH 14/49] remove comment --- core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs index 43851f150ff..902681789d9 100644 --- a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs +++ b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs @@ -130,11 +130,6 @@ impl L1GasPriceProvider for GasAdjuster { let calculated_price = (self.config.internal_l1_pricing_multiplier * effective_gas_price as f64) as u64; - // Bound the price if it's too high. - // let conversion_rate = match self.native_token_fetcher_dyn.as_ref() { - // Some(fetcher) => fetcher.conversion_rate().unwrap_or(1), - // None => 1, - // }; let conversion_rate = self.native_token_fetcher_dyn.conversion_rate().unwrap_or(1); self.bound_gas_price(calculated_price) * conversion_rate From 7ca95b8222a332b9e9f852474c2835f4f8dfe117 Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Wed, 28 Feb 2024 10:54:48 -0300 Subject: [PATCH 15/49] remove needless variable --- core/lib/zksync_core/src/lib.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index 56a8accb4bf..5f1c885f6b4 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -342,7 +342,7 @@ pub async fn initialize_components( let (stop_sender, stop_receiver) = watch::channel(false); let (cb_sender, cb_receiver) = oneshot::channel(); - let native_token_fetcher: Arc = + let conversion_rate_fetcher: Arc = if let Some(fetcher_singleton) = &mut fetcher_component { let fetcher = fetcher_singleton .get_or_init() @@ -354,14 +354,12 @@ pub async fn initialize_components( Arc::new(NoOpConversionRateFetcher::new()) }; - let erc20_fetcher_dyn: Arc = native_token_fetcher.clone(); - let query_client = QueryClient::new(ð_client_config.web3_url).unwrap(); let gas_adjuster_config = configs.gas_adjuster_config.context("gas_adjuster_config")?; let mut gas_adjuster = GasAdjusterSingleton::new( eth_client_config.web3_url.clone(), gas_adjuster_config, - erc20_fetcher_dyn, + conversion_rate_fetcher, ); // Prometheus exporter and circuit breaker checker should run for every component configuration. From 0315e46b46f8831f2d9774e4bb980ac9f0b28d60 Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Wed, 28 Feb 2024 15:15:08 -0300 Subject: [PATCH 16/49] initial commit --- .../zksync_core/src/l1_gas_price/singleton.rs | 30 +++++++--------- .../src/native_token_fetcher/mod.rs | 34 ++++++++----------- 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/core/lib/zksync_core/src/l1_gas_price/singleton.rs b/core/lib/zksync_core/src/l1_gas_price/singleton.rs index 21fc9a5e7ee..24d27ad9bd2 100644 --- a/core/lib/zksync_core/src/l1_gas_price/singleton.rs +++ b/core/lib/zksync_core/src/l1_gas_price/singleton.rs @@ -16,20 +16,10 @@ use crate::{l1_gas_price::GasAdjuster, native_token_fetcher::ConversionRateFetch pub struct GasAdjusterSingleton { web3_url: String, gas_adjuster_config: GasAdjusterConfig, - singleton: OnceCell>, Error>>, + singleton: OnceCell>>>, erc20_fetcher_dyn: Option>, } -#[derive(thiserror::Error, Debug, Clone)] -#[error(transparent)] -pub struct Error(Arc); - -impl From for Error { - fn from(err: anyhow::Error) -> Self { - Self(Arc::new(err)) - } -} - impl GasAdjusterSingleton { pub fn new( web3_url: String, @@ -44,8 +34,8 @@ impl GasAdjusterSingleton { } } - pub async fn get_or_init(&mut self) -> Result>, Error> { - let adjuster = self + pub async fn get_or_init(&mut self) -> anyhow::Result>> { + match self .singleton .get_or_init(|| async { let query_client = @@ -59,17 +49,23 @@ impl GasAdjusterSingleton { .context("GasAdjuster::new()")?; Ok(Arc::new(adjuster)) }) - .await; - adjuster.clone() + .await + { + Ok(adjuster) => Ok(adjuster.clone()), + Err(_e) => Err(anyhow::anyhow!("Failed to get or initialize GasAdjuster")), + } } pub fn run_if_initialized( self, stop_signal: watch::Receiver, ) -> Option>> { - let gas_adjuster = self.singleton.get()?.clone(); + let gas_adjuster = match self.singleton.get()? { + Ok(gas_adjuster) => gas_adjuster.clone(), + Err(_e) => return None, + }; Some(tokio::spawn( - async move { gas_adjuster?.run(stop_signal).await }, + async move { gas_adjuster.run(stop_signal).await }, )) } } diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index 82c81d124bb..d7577fd1e87 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -8,18 +8,6 @@ use tokio::{ }; use zksync_config::configs::native_token_fetcher::NativeTokenFetcherConfig; -// TODO: this error type is also defined by the gasAdjuster module, -// we should consider moving it to a common place -#[derive(thiserror::Error, Debug, Clone)] -#[error(transparent)] -pub struct Error(Arc); - -impl From for Error { - fn from(err: anyhow::Error) -> Self { - Self(Arc::new(err)) - } -} - /// Trait used to query the stack's native token conversion rate. Used to properly /// determine gas prices, as they partially depend on L1 gas prices, denominated in `eth`. pub trait ConversionRateFetcher: 'static + std::fmt::Debug + Send + Sync { @@ -28,7 +16,7 @@ pub trait ConversionRateFetcher: 'static + std::fmt::Debug + Send + Sync { pub(crate) struct NativeTokenFetcherSingleton { native_token_fetcher_config: NativeTokenFetcherConfig, - singleton: OnceCell, Error>>, + singleton: OnceCell>>, } impl NativeTokenFetcherSingleton { @@ -39,24 +27,32 @@ impl NativeTokenFetcherSingleton { } } - pub async fn get_or_init(&mut self) -> Result, Error> { - let adjuster = self + pub async fn get_or_init(&mut self) -> anyhow::Result> { + match self .singleton .get_or_init(|| async { let fetcher = NativeTokenFetcher::new(self.native_token_fetcher_config.clone()).await; Ok(Arc::new(fetcher)) }) - .await; - adjuster.clone() + .await + { + Ok(fetcher) => Ok(fetcher.clone()), + Err(_e) => Err(anyhow::anyhow!( + "Failed to get or initialize NativeTokenFetcher" + )), + } } pub fn run_if_initialized( self, stop_signal: watch::Receiver, ) -> Option>> { - let fetcher = self.singleton.get()?.clone(); - Some(tokio::spawn(async move { fetcher?.run(stop_signal).await })) + let fetcher = match self.singleton.get()? { + Ok(fetcher) => fetcher.clone(), + Err(_e) => return None, + }; + Some(tokio::spawn(async move { fetcher.run(stop_signal).await })) } } From c79dccbb08291f503fbee8278f07e793c6fec635 Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Wed, 28 Feb 2024 17:02:45 -0300 Subject: [PATCH 17/49] initial commit --- .../src/native_token_fetcher/mod.rs | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index 82c81d124bb..15174b8eee0 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -8,6 +8,8 @@ use tokio::{ }; use zksync_config::configs::native_token_fetcher::NativeTokenFetcherConfig; +const MAX_CONSECUTIVE_NETWORK_ERRORS: u8 = 10; + // TODO: this error type is also defined by the gasAdjuster module, // we should consider moving it to a common place #[derive(thiserror::Error, Debug, Clone)] @@ -75,7 +77,7 @@ impl NativeTokenFetcher { .unwrap() .json::() .await - .unwrap(); + .unwrap_or(1); // Prevent program from crashing altogether if the first request fails Self { config, @@ -84,17 +86,40 @@ impl NativeTokenFetcher { } pub(crate) async fn run(&self, stop_receiver: watch::Receiver) -> anyhow::Result<()> { + let mut network_consecutive_errors = 0; loop { if *stop_receiver.borrow() { tracing::info!("Stop signal received, native_token_fetcher is shutting down"); break; } - let conversion_rate = reqwest::get(format!("{}/conversion_rate", &self.config.host)) - .await? - .json::() - .await - .unwrap(); + let conversion_rate = + match reqwest::get(format!("{}/conversion_rate", &self.config.host)) + .await? + .json::() + .await + { + Ok(rate) => { + network_consecutive_errors = 0; + rate + } + Err(err) => { + network_consecutive_errors += 1; + + tracing::error!( + "Failed to fetch native token conversion rate from the server: {err}" + ); + + if network_consecutive_errors >= MAX_CONSECUTIVE_NETWORK_ERRORS { + vlog::capture_message(&err.to_string(), vlog::AlertLevel::Warning); + + // reset the error counter to prevent sending multiple sentry errors consecutively + network_consecutive_errors = 0; + } + + continue; + } + }; self.latest_to_eth_conversion_rate .store(conversion_rate, std::sync::atomic::Ordering::Relaxed); From b6367ad1d2533d657ba93c72536b7b0978095320 Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Wed, 28 Feb 2024 17:30:25 -0300 Subject: [PATCH 18/49] rmv unwrap --- .../zksync_core/src/native_token_fetcher/mod.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index 15174b8eee0..616e7df929d 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -72,12 +72,15 @@ pub(crate) struct NativeTokenFetcher { impl NativeTokenFetcher { pub(crate) async fn new(config: NativeTokenFetcherConfig) -> Self { - let conversion_rate = reqwest::get(format!("{}/conversion_rate", config.host)) - .await - .unwrap() - .json::() - .await - .unwrap_or(1); // Prevent program from crashing altogether if the first request fails + let conversion_rate = match reqwest::get(format!("{}/conversion_rate", config.host)).await { + Ok(response) => response.json::().await.unwrap_or(1), // Prevent program from crashing altogether if the first request fails + Err(err) => { + tracing::error!( + "Failed to fetch native token conversion rate from the server: {err}" + ); + 1 + } + }; Self { config, From 252312ae27ad16a32d0af121d8a8980eb79c92fe Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Wed, 28 Feb 2024 17:58:18 -0300 Subject: [PATCH 19/49] improve err handling --- .../src/native_token_fetcher/mod.rs | 48 ++++++++----------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index 616e7df929d..b053a0e7524 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -96,36 +96,28 @@ impl NativeTokenFetcher { break; } - let conversion_rate = - match reqwest::get(format!("{}/conversion_rate", &self.config.host)) - .await? - .json::() - .await - { - Ok(rate) => { + match reqwest::get(format!("{}/conversion_rate", &self.config.host)).await { + Ok(response) => { + let conversion_rate = response.json::().await?; + self.latest_to_eth_conversion_rate + .store(conversion_rate, std::sync::atomic::Ordering::Relaxed); + network_consecutive_errors = 0; + } + Err(err) => { + network_consecutive_errors += 1; + + tracing::error!( + "Failed to fetch native token conversion rate from the server: {err}" + ); + + if network_consecutive_errors >= MAX_CONSECUTIVE_NETWORK_ERRORS { + vlog::capture_message(&err.to_string(), vlog::AlertLevel::Warning); + + // reset the error counter to prevent sending multiple sentry errors consecutively network_consecutive_errors = 0; - rate } - Err(err) => { - network_consecutive_errors += 1; - - tracing::error!( - "Failed to fetch native token conversion rate from the server: {err}" - ); - - if network_consecutive_errors >= MAX_CONSECUTIVE_NETWORK_ERRORS { - vlog::capture_message(&err.to_string(), vlog::AlertLevel::Warning); - - // reset the error counter to prevent sending multiple sentry errors consecutively - network_consecutive_errors = 0; - } - - continue; - } - }; - - self.latest_to_eth_conversion_rate - .store(conversion_rate, std::sync::atomic::Ordering::Relaxed); + } + } tokio::time::sleep(Duration::from_secs(self.config.poll_interval)).await; } From 7b339343036a6b12304a1135239464820adc3a01 Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Thu, 29 Feb 2024 18:28:31 +0100 Subject: [PATCH 20/49] store native token address in fetcher config, use it in the conversion rate endpoint subdir --- .../src/configs/native_token_fetcher.rs | 1 + .../src/native_token_fetcher/mod.rs | 20 ++++++++++++------- erc20_example.py | 5 +++-- etc/env/base/native_token_fetcher.toml | 1 + 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/core/lib/config/src/configs/native_token_fetcher.rs b/core/lib/config/src/configs/native_token_fetcher.rs index 38debd1a843..e1aace2b2a4 100644 --- a/core/lib/config/src/configs/native_token_fetcher.rs +++ b/core/lib/config/src/configs/native_token_fetcher.rs @@ -4,4 +4,5 @@ use serde::Deserialize; pub struct NativeTokenFetcherConfig { pub poll_interval: u64, pub host: String, + pub token_address: String, } diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index 684dc5bb722..4245da785bf 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -87,12 +87,15 @@ pub(crate) struct NativeTokenFetcher { impl NativeTokenFetcher { pub(crate) async fn new(config: NativeTokenFetcherConfig) -> Self { - let conversion_rate = reqwest::get(format!("{}/conversion_rate", config.host)) - .await - .unwrap() - .json::() - .await - .unwrap(); + let conversion_rate = reqwest::get(format!( + "{}/conversion_rate/{}", + config.host, config.token_address + )) + .await + .unwrap() + .json::() + .await + .unwrap(); let http_client = reqwest::Client::new(); @@ -112,7 +115,10 @@ impl NativeTokenFetcher { let conversion_rate = self .http_client - .get(format!("{}/conversion_rate", &self.config.host)) + .get(format!( + "{}/conversion_rate/{}", + &self.config.host, &self.config.token_address + )) .send() .await? .json::() diff --git a/erc20_example.py b/erc20_example.py index 79b0a1c4882..9d59f6b7403 100644 --- a/erc20_example.py +++ b/erc20_example.py @@ -3,6 +3,7 @@ app = Flask(__name__) -@app.route("/conversion_rate") -def conversion_rate(): +@app.route("/conversion_rate/") +def conversion_rate(token_address): + print("Token address: ", token_address) return str(randint(1, 100)) diff --git a/etc/env/base/native_token_fetcher.toml b/etc/env/base/native_token_fetcher.toml index aaf42d42ab4..dd425675a34 100644 --- a/etc/env/base/native_token_fetcher.toml +++ b/etc/env/base/native_token_fetcher.toml @@ -2,3 +2,4 @@ host="http://127.0.0.1:5000" # Poll interval is in seconds poll_interval=10 +token_address="0xdF2Ff03eAAfae59fA7fd30D4f91ab045B3d5D95D" \ No newline at end of file From e4fb1c43e989d379de6cc59b690668755e160514 Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Thu, 29 Feb 2024 18:29:35 +0100 Subject: [PATCH 21/49] add mission EOF --- etc/env/base/native_token_fetcher.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/env/base/native_token_fetcher.toml b/etc/env/base/native_token_fetcher.toml index dd425675a34..0f8d23f4399 100644 --- a/etc/env/base/native_token_fetcher.toml +++ b/etc/env/base/native_token_fetcher.toml @@ -2,4 +2,4 @@ host="http://127.0.0.1:5000" # Poll interval is in seconds poll_interval=10 -token_address="0xdF2Ff03eAAfae59fA7fd30D4f91ab045B3d5D95D" \ No newline at end of file +token_address="0xdF2Ff03eAAfae59fA7fd30D4f91ab045B3d5D95D" From 6d114f34f3e4fdf9a6872a737ac1c9c32e1095c9 Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Thu, 29 Feb 2024 18:30:13 +0100 Subject: [PATCH 22/49] remove print --- erc20_example.py | 1 - 1 file changed, 1 deletion(-) diff --git a/erc20_example.py b/erc20_example.py index 9d59f6b7403..70828545b1f 100644 --- a/erc20_example.py +++ b/erc20_example.py @@ -5,5 +5,4 @@ @app.route("/conversion_rate/") def conversion_rate(token_address): - print("Token address: ", token_address) return str(randint(1, 100)) From 5eb92bcc4fab37de71d0066161a7d00a6533c506 Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Thu, 29 Feb 2024 17:42:51 -0300 Subject: [PATCH 23/49] impl ErrorReporter --- .../src/native_token_fetcher/mod.rs | 83 +++++++++++-------- 1 file changed, 48 insertions(+), 35 deletions(-) diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index d0a9ad77bd6..df95bbdfec3 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -1,4 +1,4 @@ -use std::{sync::Arc, time::Duration}; +use std::{cmp::min, sync::Arc, time::Duration}; use async_trait::async_trait; use metrics::atomics::AtomicU64; @@ -8,7 +8,36 @@ use tokio::{ }; use zksync_config::configs::native_token_fetcher::NativeTokenFetcherConfig; -const MAX_CONSECUTIVE_NETWORK_ERRORS: u8 = 10; +#[derive(Debug)] +struct ErrorReporter { + current_try: u8, + alert_spawned: bool, +} + +impl ErrorReporter { + const MAX_CONSECUTIVE_NETWORK_ERRORS: u8 = 10; + + fn new() -> Self { + Self { + current_try: 0, + alert_spawned: false, + } + } + + fn reset(&mut self) { + self.current_try = 0; + self.alert_spawned = false; + } + + fn process(&mut self, err: anyhow::Error) { + self.current_try = min(self.current_try + 1, Self::MAX_CONSECUTIVE_NETWORK_ERRORS); + tracing::error!("Failed to fetch native token conversion rate from the server: {err}"); + if self.current_try >= Self::MAX_CONSECUTIVE_NETWORK_ERRORS && !self.alert_spawned { + vlog::capture_message(&err.to_string(), vlog::AlertLevel::Warning); + self.alert_spawned = true; + } + } +} /// Trait used to query the stack's native token conversion rate. Used to properly /// determine gas prices, as they partially depend on L1 gas prices, denominated in `eth`. @@ -49,9 +78,9 @@ impl NativeTokenFetcherSingleton { match self .singleton .get_or_init(|| async { - let fetcher = - NativeTokenFetcher::new(self.native_token_fetcher_config.clone()).await; - Ok(Arc::new(fetcher)) + Ok(Arc::new( + NativeTokenFetcher::new(self.native_token_fetcher_config.clone()).await?, + )) }) .await { @@ -84,28 +113,25 @@ pub(crate) struct NativeTokenFetcher { } impl NativeTokenFetcher { - pub(crate) async fn new(config: NativeTokenFetcherConfig) -> Self { - let conversion_rate = match reqwest::get(format!("{}/conversion_rate", config.host)).await { - Ok(response) => response.json::().await.unwrap_or(1), // Prevent program from crashing altogether if the first request fails - Err(err) => { - tracing::error!( - "Failed to fetch native token conversion rate from the server: {err}" - ); - 1 - } - }; - + pub(crate) async fn new(config: NativeTokenFetcherConfig) -> anyhow::Result { let http_client = reqwest::Client::new(); - Self { + let conversion_rate = http_client + .get(format!("{}/conversion_rate", config.host)) + .send() + .await? + .json::() + .await?; + + Ok(Self { config, latest_to_eth_conversion_rate: AtomicU64::new(conversion_rate), - http_client: http_client, - } + http_client, + }) } pub(crate) async fn run(&self, stop_receiver: watch::Receiver) -> anyhow::Result<()> { - let mut network_consecutive_errors = 0; + let mut error_reporter = ErrorReporter::new(); loop { if *stop_receiver.borrow() { tracing::info!("Stop signal received, native_token_fetcher is shutting down"); @@ -122,22 +148,9 @@ impl NativeTokenFetcher { let conversion_rate = response.json::().await?; self.latest_to_eth_conversion_rate .store(conversion_rate, std::sync::atomic::Ordering::Relaxed); - network_consecutive_errors = 0; - } - Err(err) => { - network_consecutive_errors += 1; - - tracing::error!( - "Failed to fetch native token conversion rate from the server: {err}" - ); - - if network_consecutive_errors >= MAX_CONSECUTIVE_NETWORK_ERRORS { - vlog::capture_message(&err.to_string(), vlog::AlertLevel::Warning); - - // reset the error counter to prevent sending multiple sentry errors consecutively - network_consecutive_errors = 0; - } + error_reporter.reset(); } + Err(err) => error_reporter.process(anyhow::anyhow!(err)), } tokio::time::sleep(Duration::from_secs(self.config.poll_interval)).await; From 13b84d0219d5cd78bbfd6855997d2d546053dc8a Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Fri, 1 Mar 2024 11:47:48 +0100 Subject: [PATCH 24/49] use Address struct for token address --- core/lib/config/src/configs/native_token_fetcher.rs | 3 ++- core/lib/zksync_core/src/native_token_fetcher/mod.rs | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/lib/config/src/configs/native_token_fetcher.rs b/core/lib/config/src/configs/native_token_fetcher.rs index e1aace2b2a4..4afc40acc69 100644 --- a/core/lib/config/src/configs/native_token_fetcher.rs +++ b/core/lib/config/src/configs/native_token_fetcher.rs @@ -1,8 +1,9 @@ use serde::Deserialize; +use zksync_basic_types::Address; #[derive(Debug, Clone, Deserialize, PartialEq)] pub struct NativeTokenFetcherConfig { pub poll_interval: u64, pub host: String, - pub token_address: String, + pub token_address: Address, } diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index 4245da785bf..e927a1445a1 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -1,6 +1,7 @@ use std::{sync::Arc, time::Duration}; use async_trait::async_trait; +use hex::ToHex; use metrics::atomics::AtomicU64; use tokio::{ sync::{watch, OnceCell}, @@ -88,8 +89,9 @@ pub(crate) struct NativeTokenFetcher { impl NativeTokenFetcher { pub(crate) async fn new(config: NativeTokenFetcherConfig) -> Self { let conversion_rate = reqwest::get(format!( - "{}/conversion_rate/{}", - config.host, config.token_address + "{}/conversion_rate/0x{}", + config.host, + config.token_address.encode_hex::() )) .await .unwrap() @@ -116,8 +118,9 @@ impl NativeTokenFetcher { let conversion_rate = self .http_client .get(format!( - "{}/conversion_rate/{}", - &self.config.host, &self.config.token_address + "{}/conversion_rate/0x{}", + &self.config.host, + &self.config.token_address.encode_hex::() )) .send() .await? From 7f61a38210d29328f881ddf2f47c6746f2ef87dd Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Fri, 1 Mar 2024 10:37:47 -0300 Subject: [PATCH 25/49] move struct & add context to err --- .../src/native_token_fetcher/mod.rs | 67 ++++++++++--------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index df95bbdfec3..2b9d4e0062e 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -1,5 +1,6 @@ use std::{cmp::min, sync::Arc, time::Duration}; +use anyhow::Context; use async_trait::async_trait; use metrics::atomics::AtomicU64; use tokio::{ @@ -8,37 +9,6 @@ use tokio::{ }; use zksync_config::configs::native_token_fetcher::NativeTokenFetcherConfig; -#[derive(Debug)] -struct ErrorReporter { - current_try: u8, - alert_spawned: bool, -} - -impl ErrorReporter { - const MAX_CONSECUTIVE_NETWORK_ERRORS: u8 = 10; - - fn new() -> Self { - Self { - current_try: 0, - alert_spawned: false, - } - } - - fn reset(&mut self) { - self.current_try = 0; - self.alert_spawned = false; - } - - fn process(&mut self, err: anyhow::Error) { - self.current_try = min(self.current_try + 1, Self::MAX_CONSECUTIVE_NETWORK_ERRORS); - tracing::error!("Failed to fetch native token conversion rate from the server: {err}"); - if self.current_try >= Self::MAX_CONSECUTIVE_NETWORK_ERRORS && !self.alert_spawned { - vlog::capture_message(&err.to_string(), vlog::AlertLevel::Warning); - self.alert_spawned = true; - } - } -} - /// Trait used to query the stack's native token conversion rate. Used to properly /// determine gas prices, as they partially depend on L1 gas prices, denominated in `eth`. pub trait ConversionRateFetcher: 'static + std::fmt::Debug + Send + Sync { @@ -145,7 +115,9 @@ impl NativeTokenFetcher { .await { Ok(response) => { - let conversion_rate = response.json::().await?; + let conversion_rate = response.json::().await.context( + "Unable to parse the response of the native token conversion rate server", + )?; self.latest_to_eth_conversion_rate .store(conversion_rate, std::sync::atomic::Ordering::Relaxed); error_reporter.reset(); @@ -169,3 +141,34 @@ impl ConversionRateFetcher for NativeTokenFetcher { ) } } + +#[derive(Debug)] +struct ErrorReporter { + current_try: u8, + alert_spawned: bool, +} + +impl ErrorReporter { + const MAX_CONSECUTIVE_NETWORK_ERRORS: u8 = 10; + + fn new() -> Self { + Self { + current_try: 0, + alert_spawned: false, + } + } + + fn reset(&mut self) { + self.current_try = 0; + self.alert_spawned = false; + } + + fn process(&mut self, err: anyhow::Error) { + self.current_try = min(self.current_try + 1, Self::MAX_CONSECUTIVE_NETWORK_ERRORS); + tracing::error!("Failed to fetch native token conversion rate from the server: {err}"); + if self.current_try >= Self::MAX_CONSECUTIVE_NETWORK_ERRORS && !self.alert_spawned { + vlog::capture_message(&err.to_string(), vlog::AlertLevel::Warning); + self.alert_spawned = true; + } + } +} From a98a0b7bfcde4922ade6d126839f5ae55f8fefaa Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Fri, 1 Mar 2024 11:23:08 -0300 Subject: [PATCH 26/49] add context to init --- core/lib/zksync_core/src/native_token_fetcher/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index 2b9d4e0062e..d2a06d0894a 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -91,7 +91,8 @@ impl NativeTokenFetcher { .send() .await? .json::() - .await?; + .await + .context("Unable to parse the response of the native token conversion rate server")?; Ok(Self { config, From e182381142ebbd235f07f3aa00ed7400fe226391 Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Fri, 1 Mar 2024 18:03:59 +0100 Subject: [PATCH 27/49] add conversion rate component --- .../src/api_conversion_rate/mod.rs | 37 +++++++++++++++++++ core/lib/zksync_core/src/lib.rs | 24 ++++++++++++ .../src/native_token_fetcher/mod.rs | 23 +++++++++--- 3 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 core/lib/zksync_core/src/api_conversion_rate/mod.rs diff --git a/core/lib/zksync_core/src/api_conversion_rate/mod.rs b/core/lib/zksync_core/src/api_conversion_rate/mod.rs new file mode 100644 index 00000000000..aacf5af1a07 --- /dev/null +++ b/core/lib/zksync_core/src/api_conversion_rate/mod.rs @@ -0,0 +1,37 @@ +use axum::extract::Json; +use axum::{extract, routing::get, Router}; +use rand::Rng; +use tokio::sync::watch; +use zksync_config::configs::native_token_fetcher::NativeTokenFetcherConfig; + +pub(crate) async fn run_server( + mut stop_receiver: watch::Receiver, + server_configs: &NativeTokenFetcherConfig, +) { + let app = Router::new().route("/conversion_rate/:token_address", get(get_conversion_rate)); + + let bind_address = if server_configs.host.starts_with("http://") { + &server_configs.host[7..] // If it starts with "http://", strip the prefix + } else { + &server_configs.host // Otherwise, return the original string + }; + + axum::Server::bind(&bind_address.parse().expect("Unable to parse socket address")) + .serve(app.into_make_service()) + .with_graceful_shutdown(async move { + if stop_receiver.changed().await.is_err() { + tracing::warn!("Stop signal sender for conversion rate API server was dropped without sending a signal"); + } + tracing::info!("Stop signal received, conversion rate server is shutting down"); + }) + .await + .expect("Conversion rate server failed"); + tracing::info!("Conversion rate server shut down"); +} + +// basic handler that responds with a static string +async fn get_conversion_rate(extract::Path(_token_address): extract::Path) -> Json { + let mut rng = rand::thread_rng(); + let random_number: u64 = rng.gen_range(1..=100); + Json(random_number) +} diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index 5f1c885f6b4..310934179d7 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -76,6 +76,7 @@ use crate::{ }, }; +pub mod api_conversion_rate; pub mod api_server; pub mod basic_witness_input_producer; pub mod block_reverter; @@ -235,6 +236,8 @@ pub enum Component { ProofDataHandler, /// Native Token fetcher NativeTokenFetcher, + /// Conversion rate API, for local development. + ConversionRateApi, } #[derive(Debug)] @@ -270,6 +273,7 @@ impl FromStr for Components { "eth_tx_manager" => Ok(Components(vec![Component::EthTxManager])), "proof_data_handler" => Ok(Components(vec![Component::ProofDataHandler])), "native_token_fetcher" => Ok(Components(vec![Component::NativeTokenFetcher])), + "conversion_rate_api" => Ok(Components(vec![Component::ConversionRateApi])), other => Err(format!("{} is not a valid component name", other)), } } @@ -326,6 +330,25 @@ pub async fn initialize_components( panic!("Circuit breaker triggered: {}", err); }); + // spawn the conversion rate API if it is enabled + if components.contains(&Component::ConversionRateApi) { + let (_stop_sender, stop_receiver) = watch::channel(false); + + let native_token_fetcher_config = configs + .native_token_fetcher_config + .clone() + .context("native_token_fetcher_config") + .unwrap(); // Assuming unwrap is safe here, handle the error appropriately + + tokio::spawn(async move { + api_conversion_rate::run_server(stop_receiver, &native_token_fetcher_config).await; + }); + + use std::thread; + use std::time::Duration; + thread::sleep(Duration::from_secs(2)); + }; + // spawn the native ERC20 fetcher if it is enabled let mut fetcher_component = if components.contains(&Component::NativeTokenFetcher) { let fetcher = NativeTokenFetcherSingleton::new( @@ -339,6 +362,7 @@ pub async fn initialize_components( } else { None }; + let (stop_sender, stop_receiver) = watch::channel(false); let (cb_sender, cb_receiver) = oneshot::channel(); diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index 684dc5bb722..ea1a0dc4b1d 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -6,6 +6,7 @@ use tokio::{ sync::{watch, OnceCell}, task::JoinHandle, }; +use tracing::field::debug; use zksync_config::configs::native_token_fetcher::NativeTokenFetcherConfig; // TODO: this error type is also defined by the gasAdjuster module, @@ -87,12 +88,22 @@ pub(crate) struct NativeTokenFetcher { impl NativeTokenFetcher { pub(crate) async fn new(config: NativeTokenFetcherConfig) -> Self { - let conversion_rate = reqwest::get(format!("{}/conversion_rate", config.host)) - .await - .unwrap() - .json::() - .await - .unwrap(); + let conversion_rate = reqwest::get(format!( + "{}/conversion_rate/0x{}", + config.host, + config.token_address.encode_hex::() + )) + .await + .unwrap(); + + dbg!(&conversion_rate); + dbg!(format!( + "{}/conversion_rate/0x{}", + config.host, + config.token_address.encode_hex::() + )); + + let conversion_rate = conversion_rate.json::().await.unwrap(); let http_client = reqwest::Client::new(); From 6bb64ef6c290f93e80d3406a7b3fc8a81bae6584 Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Fri, 1 Mar 2024 18:05:02 +0100 Subject: [PATCH 28/49] apply zk fmt --- core/lib/zksync_core/src/api_conversion_rate/mod.rs | 3 +-- core/lib/zksync_core/src/lib.rs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/core/lib/zksync_core/src/api_conversion_rate/mod.rs b/core/lib/zksync_core/src/api_conversion_rate/mod.rs index aacf5af1a07..e819707ef0a 100644 --- a/core/lib/zksync_core/src/api_conversion_rate/mod.rs +++ b/core/lib/zksync_core/src/api_conversion_rate/mod.rs @@ -1,5 +1,4 @@ -use axum::extract::Json; -use axum::{extract, routing::get, Router}; +use axum::{extract, extract::Json, routing::get, Router}; use rand::Rng; use tokio::sync::watch; use zksync_config::configs::native_token_fetcher::NativeTokenFetcherConfig; diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index 310934179d7..b37f79bbdce 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -344,8 +344,7 @@ pub async fn initialize_components( api_conversion_rate::run_server(stop_receiver, &native_token_fetcher_config).await; }); - use std::thread; - use std::time::Duration; + use std::{thread, time::Duration}; thread::sleep(Duration::from_secs(2)); }; From e7241fcefd6d82951e4dc6e578786f52f5c4e775 Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Fri, 1 Mar 2024 18:06:01 +0100 Subject: [PATCH 29/49] add token address to config --- core/lib/config/src/configs/native_token_fetcher.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/lib/config/src/configs/native_token_fetcher.rs b/core/lib/config/src/configs/native_token_fetcher.rs index 38debd1a843..4afc40acc69 100644 --- a/core/lib/config/src/configs/native_token_fetcher.rs +++ b/core/lib/config/src/configs/native_token_fetcher.rs @@ -1,7 +1,9 @@ use serde::Deserialize; +use zksync_basic_types::Address; #[derive(Debug, Clone, Deserialize, PartialEq)] pub struct NativeTokenFetcherConfig { pub poll_interval: u64, pub host: String, + pub token_address: Address, } From bfae1c61d680180c632d57c3f5a3ccfec1671338 Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Fri, 1 Mar 2024 18:06:32 +0100 Subject: [PATCH 30/49] Add missing trait --- core/lib/zksync_core/src/native_token_fetcher/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index ea1a0dc4b1d..8e3dcd902ea 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -1,6 +1,7 @@ use std::{sync::Arc, time::Duration}; use async_trait::async_trait; +use hex::ToHex; use metrics::atomics::AtomicU64; use tokio::{ sync::{watch, OnceCell}, From 7077b405312bce00901492f83fc6275ae20cc434 Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Fri, 1 Mar 2024 18:07:36 +0100 Subject: [PATCH 31/49] add token address to config --- etc/env/base/native_token_fetcher.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/etc/env/base/native_token_fetcher.toml b/etc/env/base/native_token_fetcher.toml index aaf42d42ab4..5fdf5c638c8 100644 --- a/etc/env/base/native_token_fetcher.toml +++ b/etc/env/base/native_token_fetcher.toml @@ -2,3 +2,4 @@ host="http://127.0.0.1:5000" # Poll interval is in seconds poll_interval=10 +token_address=0xdF2Ff03eAAfae59fA7fd30D4f91ab045B3d5D95D \ No newline at end of file From dd11e4a55b62b9399f2c66dce1cfe69bbf9e9d9e Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Mon, 4 Mar 2024 15:25:01 -0300 Subject: [PATCH 32/49] fix up code --- .../zksync_core/src/api_conversion_rate/mod.rs | 3 ++- core/lib/zksync_core/src/lib.rs | 17 ++++++++--------- .../zksync_core/src/native_token_fetcher/mod.rs | 1 - 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/core/lib/zksync_core/src/api_conversion_rate/mod.rs b/core/lib/zksync_core/src/api_conversion_rate/mod.rs index e819707ef0a..17440aeaa4a 100644 --- a/core/lib/zksync_core/src/api_conversion_rate/mod.rs +++ b/core/lib/zksync_core/src/api_conversion_rate/mod.rs @@ -6,7 +6,7 @@ use zksync_config::configs::native_token_fetcher::NativeTokenFetcherConfig; pub(crate) async fn run_server( mut stop_receiver: watch::Receiver, server_configs: &NativeTokenFetcherConfig, -) { +) -> anyhow::Result<()> { let app = Router::new().route("/conversion_rate/:token_address", get(get_conversion_rate)); let bind_address = if server_configs.host.starts_with("http://") { @@ -26,6 +26,7 @@ pub(crate) async fn run_server( .await .expect("Conversion rate server failed"); tracing::info!("Conversion rate server shut down"); + Ok(()) } // basic handler that responds with a static string diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index b37f79bbdce..5abea8c0ef0 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -330,6 +330,8 @@ pub async fn initialize_components( panic!("Circuit breaker triggered: {}", err); }); + let mut task_futures: Vec>> = Vec::new(); + // spawn the conversion rate API if it is enabled if components.contains(&Component::ConversionRateApi) { let (_stop_sender, stop_receiver) = watch::channel(false); @@ -337,15 +339,12 @@ pub async fn initialize_components( let native_token_fetcher_config = configs .native_token_fetcher_config .clone() - .context("native_token_fetcher_config") - .unwrap(); // Assuming unwrap is safe here, handle the error appropriately + .context("native_token_fetcher_config")?; - tokio::spawn(async move { - api_conversion_rate::run_server(stop_receiver, &native_token_fetcher_config).await; + let conversion_rate_task = tokio::spawn(async move { + api_conversion_rate::run_server(stop_receiver, &native_token_fetcher_config).await }); - - use std::{thread, time::Duration}; - thread::sleep(Duration::from_secs(2)); + task_futures.push(conversion_rate_task); }; // spawn the native ERC20 fetcher if it is enabled @@ -403,10 +402,10 @@ pub async fn initialize_components( res }); - let mut task_futures: Vec>> = vec![ + task_futures.extend(vec![ prometheus_task, tokio::spawn(circuit_breaker_checker.run(cb_sender, stop_receiver.clone())), - ]; + ]); if components.contains(&Component::WsApi) || components.contains(&Component::HttpApi) diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index 3b660f3120d..5b07d740307 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -8,7 +8,6 @@ use tokio::{ sync::{watch, OnceCell}, task::JoinHandle, }; -use tracing::field::debug; use zksync_config::configs::native_token_fetcher::NativeTokenFetcherConfig; /// Trait used to query the stack's native token conversion rate. Used to properly From 1a20f2aa38e3f978612ff59cc3107b899734e093 Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Tue, 5 Mar 2024 13:05:03 -0300 Subject: [PATCH 33/49] [WIP] Remove native token fetcher singleton --- .../src/l1_gas_price/gas_adjuster/mod.rs | 9 ++++ core/lib/zksync_core/src/lib.rs | 39 +++----------- .../src/native_token_fetcher/mod.rs | 54 ++++++------------- 3 files changed, 32 insertions(+), 70 deletions(-) diff --git a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs index 5fa771ae25d..bb5e4b03f56 100644 --- a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs +++ b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs @@ -111,6 +111,15 @@ impl GasAdjuster { tracing::warn!("Cannot add the base fee to gas statistics: {}", err); } + if let Some(native_erc20_fetcher) = &self.native_token_fetcher_dyn { + if let Err(err) = native_erc20_fetcher.update().await { + tracing::warn!( + "Error when trying to fetch the native erc20 conversion rate: {}", + err + ); + } + } + tokio::time::sleep(self.config.poll_period()).await; } Ok(()) diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index dad2a497b86..33de1d5844c 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -68,7 +68,7 @@ use crate::{ l1_gas_price::{GasAdjusterSingleton, L1GasPriceProvider}, metadata_calculator::{MetadataCalculator, MetadataCalculatorConfig}, metrics::{InitStage, APP_METRICS}, - native_token_fetcher::{ConversionRateFetcher, NativeTokenFetcherSingleton}, + native_token_fetcher::{ConversionRateFetcher, NativeTokenFetcher}, state_keeper::{ create_state_keeper, MempoolFetcher, MempoolGuard, MiniblockSealer, SequencerSealer, }, @@ -323,43 +323,26 @@ pub async fn initialize_components( circuit_breaker_checker.check().await.unwrap_or_else(|err| { panic!("Circuit breaker triggered: {}", err); }); + let (stop_sender, stop_receiver) = watch::channel(false); + let (cb_sender, cb_receiver) = oneshot::channel(); - // spawn the native ERC20 fetcher if it is enabled - let mut fetcher_component = if components.contains(&Component::NativeTokenFetcher) { - let fetcher = NativeTokenFetcherSingleton::new( + let native_token_fetcher = if components.contains(&Component::NativeTokenFetcher) { + Some(Arc::new(NativeTokenFetcher::new( configs .native_token_fetcher_config .clone() .context("native_token_fetcher_config")?, - ); - - Some(fetcher) - } else { - None - }; - let (stop_sender, stop_receiver) = watch::channel(false); - let (cb_sender, cb_receiver) = oneshot::channel(); - - let native_token_fetcher = if let Some(fetcher_singleton) = &mut fetcher_component { - let fetcher = fetcher_singleton - .get_or_init() - .await - .context("fetcher.get_or_init()")?; - Some(fetcher) + ))) } else { None }; - let erc20_fetcher_dyn: Option> = native_token_fetcher - .as_ref() - .map(|fetcher| fetcher.clone() as Arc); - let query_client = QueryClient::new(ð_client_config.web3_url).unwrap(); let gas_adjuster_config = configs.gas_adjuster_config.context("gas_adjuster_config")?; let mut gas_adjuster = GasAdjusterSingleton::new( eth_client_config.web3_url.clone(), gas_adjuster_config, - erc20_fetcher_dyn, + native_token_fetcher, ); // Prometheus exporter and circuit breaker checker should run for every component configuration. @@ -707,14 +690,6 @@ pub async fn initialize_components( task_futures.push(task); } - // check if the native ERC20 fetcher is enabled and run it if it is - fetcher_component - .and_then(|c| c.run_if_initialized(stop_receiver.clone())) - .into_iter() - .for_each(|handle| { - task_futures.push(handle); - }); - Ok((task_futures, stop_sender, cb_receiver, health_check_handle)) } diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index 82c81d124bb..08f47b89144 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -2,10 +2,7 @@ use std::{sync::Arc, time::Duration}; use async_trait::async_trait; use metrics::atomics::AtomicU64; -use tokio::{ - sync::{watch, OnceCell}, - task::JoinHandle, -}; +use tokio::sync::watch; use zksync_config::configs::native_token_fetcher::NativeTokenFetcherConfig; // TODO: this error type is also defined by the gasAdjuster module, @@ -22,42 +19,10 @@ impl From for Error { /// Trait used to query the stack's native token conversion rate. Used to properly /// determine gas prices, as they partially depend on L1 gas prices, denominated in `eth`. +#[async_trait::async_trait] pub trait ConversionRateFetcher: 'static + std::fmt::Debug + Send + Sync { fn conversion_rate(&self) -> anyhow::Result; -} - -pub(crate) struct NativeTokenFetcherSingleton { - native_token_fetcher_config: NativeTokenFetcherConfig, - singleton: OnceCell, Error>>, -} - -impl NativeTokenFetcherSingleton { - pub fn new(native_token_fetcher_config: NativeTokenFetcherConfig) -> Self { - Self { - native_token_fetcher_config, - singleton: OnceCell::new(), - } - } - - pub async fn get_or_init(&mut self) -> Result, Error> { - let adjuster = self - .singleton - .get_or_init(|| async { - let fetcher = - NativeTokenFetcher::new(self.native_token_fetcher_config.clone()).await; - Ok(Arc::new(fetcher)) - }) - .await; - adjuster.clone() - } - - pub fn run_if_initialized( - self, - stop_signal: watch::Receiver, - ) -> Option>> { - let fetcher = self.singleton.get()?.clone(); - Some(tokio::spawn(async move { fetcher?.run(stop_signal).await })) - } + async fn update(&self) -> anyhow::Result<()>; } /// Struct in charge of periodically querying and caching the native token's conversion rate @@ -114,4 +79,17 @@ impl ConversionRateFetcher for NativeTokenFetcher { .load(std::sync::atomic::Ordering::Relaxed), ) } + + async fn update(&self) -> anyhow::Result<()> { + let conversion_rate = reqwest::get(format!("{}/conversion_rate", &self.config.host)) + .await? + .json::() + .await + .unwrap(); + + self.latest_to_eth_conversion_rate + .store(conversion_rate, std::sync::atomic::Ordering::Relaxed); + + Ok(()) + } } From 3103dcad797331137f9b4d51ac757d8502f3dcdf Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Tue, 5 Mar 2024 14:50:08 -0300 Subject: [PATCH 34/49] Fix compilation (add missing await) --- core/lib/zksync_core/src/lib.rs | 15 +- .../src/native_token_fetcher/mod.rs | 2 +- etc/env/l1-inits/.init.env | 40 +-- yarn.lock | 298 +++++++----------- 4 files changed, 143 insertions(+), 212 deletions(-) diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index 33de1d5844c..1575013f38a 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -327,12 +327,15 @@ pub async fn initialize_components( let (cb_sender, cb_receiver) = oneshot::channel(); let native_token_fetcher = if components.contains(&Component::NativeTokenFetcher) { - Some(Arc::new(NativeTokenFetcher::new( - configs - .native_token_fetcher_config - .clone() - .context("native_token_fetcher_config")?, - ))) + Some(Arc::new( + NativeTokenFetcher::new( + configs + .native_token_fetcher_config + .clone() + .context("native_token_fetcher_config")?, + ) + .await, + ) as Arc) } else { None }; diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index 08f47b89144..00dfb28c123 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -19,7 +19,7 @@ impl From for Error { /// Trait used to query the stack's native token conversion rate. Used to properly /// determine gas prices, as they partially depend on L1 gas prices, denominated in `eth`. -#[async_trait::async_trait] +#[async_trait] pub trait ConversionRateFetcher: 'static + std::fmt::Debug + Send + Sync { fn conversion_rate(&self) -> anyhow::Result; async fn update(&self) -> anyhow::Result<()>; diff --git a/etc/env/l1-inits/.init.env b/etc/env/l1-inits/.init.env index efb1742d996..86af566478a 100644 --- a/etc/env/l1-inits/.init.env +++ b/etc/env/l1-inits/.init.env @@ -1,29 +1,29 @@ CONTRACTS_LATEST_PROTOCOL_VERSION=22 CONTRACTS_CREATE2_FACTORY_ADDR=0x3c4CE2E9D8b03BbCd568E47465A483EE86893c49 -CONTRACTS_VERIFIER_ADDR=0xCf42AEFfB17dED8de2d4116D33716354F53e51e6 -CONTRACTS_L1_MULTICALL3_ADDR=0x69D85c64032337E58064A35020d6F45Dab350883 +CONTRACTS_VERIFIER_ADDR=0x6aF2E29f6a3c4c64748066e1322308D33555B705 +CONTRACTS_L1_MULTICALL3_ADDR=0x149ED651660b8B857FE57241Ea5737e70bb9a494 CONTRACTS_GENESIS_ROOT=0x300ac58a9fa3b6283791831f5d62b1b525b81e6ec4f4793bea5fb14ebea730c7 CHAIN_STATE_KEEPER_BOOTLOADER_HASH=0x010007ed36aa249ae63fa088c251736a3170cd179a03d8d6f0fe6a6f47b23705 CHAIN_STATE_KEEPER_DEFAULT_AA_HASH=0x0100055bbad08b38b8e0b22b57703bb1f440b8789a3ba809a4ca4830c497e1d4 CONTRACTS_GENESIS_BATCH_COMMITMENT=0x921bdf66c72d3f84c1f7520050c4980721d32b6c95c76ab32aaa556a6430d24c CONTRACTS_GENESIS_ROLLUP_LEAF_INDEX=25 CONTRACTS_L1_WETH_TOKEN_ADDR=0x4A470422bFf67C34a3A565106118023059fa4E34 -CONTRACTS_BRIDGEHUB_PROXY_ADDR=0xb81673bCE7AAd30D8C18A3e118fc5018B8E1b304 -CONTRACTS_BRIDGEHUB_IMPL_ADDR=0x8F78c7272727e3cf99d631cA2Ee04A7F866F7D0A -CONTRACTS_STATE_TRANSITION_PROXY_ADDR=0x71470A85Afc4dE5241ae84c5b382c245e36E2e2E -CONTRACTS_STATE_TRANSITION_IMPL_ADDR=0x5C542Cc2886E6B8172D1E87637b5f681df6cE6b4 -CONTRACTS_ADMIN_FACET_ADDR=0xB178e8fECEa2521aC351f4179eF53014EF66deA4 -CONTRACTS_DIAMOND_UPGRADE_INIT_ADDR=0x01e88D723515404ea24136D2b2209D80597c60EE -CONTRACTS_DIAMOND_INIT_ADDR=0x1440EbE06A353bca88cAD588d5AC55513ACC9d31 -CONTRACTS_DEFAULT_UPGRADE_ADDR=0xD14F5CF299EF63a9aD5DcF35D7c43b07c48192Ff -CONTRACTS_GENESIS_UPGRADE_ADDR=0x223350ebdb7bB5EE851C1e089D51cc1900D84CC6 -CONTRACTS_GOVERNANCE_ADDR=0x410a4b3a5A7F2c52B1bCdeFBA05091a932A75c82 -CONTRACTS_MAILBOX_FACET_ADDR=0xb73B7e1cA6ef3F9d036466004433FB9E2f3eB3ce -CONTRACTS_EXECUTOR_FACET_ADDR=0x9F630Aa2999ff37736a5a64FA4Edd396A5d0Cafc -CONTRACTS_GETTERS_FACET_ADDR=0x27197A55F385AA3bA572618928845f591f677AD7 -CONTRACTS_VALIDATOR_TIMELOCK_ADDR=0x43e5978b9BCF261e3b3d93bfc76b36db513A7C42 +CONTRACTS_BRIDGEHUB_PROXY_ADDR=0x5CaDc7256EBb15E74380948D927dDBeB17050342 +CONTRACTS_BRIDGEHUB_IMPL_ADDR=0x6aC201691c7Fd4621B48E95a3e41eA87D2668c8b +CONTRACTS_STATE_TRANSITION_PROXY_ADDR=0x826373Bf58236f9b2c4991dB73763b9e119463B0 +CONTRACTS_STATE_TRANSITION_IMPL_ADDR=0x83Ac1F8e1386C5935AB8E392f1b806eEf307eF82 +CONTRACTS_ADMIN_FACET_ADDR=0x80f2c21Dbf1404A88BaD1FFA8e4bC7767cd63FA0 +CONTRACTS_DIAMOND_UPGRADE_INIT_ADDR=0xaCF43f8cC9d69a2A1A5FCe6CbBDa30659916AAc4 +CONTRACTS_DIAMOND_INIT_ADDR=0x6Cc3d11A82b22D0B11D168B69C29F2DcBEB7193B +CONTRACTS_DEFAULT_UPGRADE_ADDR=0x421B8FceaCFBec683632EFCCEC04ce3EF48A9A8b +CONTRACTS_GENESIS_UPGRADE_ADDR=0xeb2aDF0Bf99E712272D4037f0FfE24A945991227 +CONTRACTS_GOVERNANCE_ADDR=0xe9a45757133903dE0B6eA7e8f8AF8676Ef72ED57 +CONTRACTS_MAILBOX_FACET_ADDR=0xB0A311C86b6dC27DE11Ab49f11058c1dBF4e1554 +CONTRACTS_EXECUTOR_FACET_ADDR=0x0071BA8127fa4C6b0293DF1E4cbd2ef63AeC50b5 +CONTRACTS_GETTERS_FACET_ADDR=0x1afC9fF70FB0Aec49697AdCaFC19fBA6A35B699D +CONTRACTS_VALIDATOR_TIMELOCK_ADDR=0x3003A236F0B2eF0Cbe140f76e39139E16165a19A CONTRACTS_TRANSPARENT_PROXY_ADMIN_ADDR=0x20410058241d1c4C5f7C04753BD4713B04f19423 -CONTRACTS_L1_SHARED_BRIDGE_PROXY_ADDR=0x3C95EE1e5dade52f008b71d09fE0ba178603AFC3 -CONTRACTS_L1_SHARED_BRIDGE_IMPL_ADDR=0x3D3805B1B87A9a69232B4082955A3982049d1EA2 -CONTRACTS_L1_ERC20_BRIDGE_PROXY_ADDR=0x910123E3Fe7a35a5A76735cbA6D4f25A0F1eE459 -CONTRACTS_L1_ERC20_BRIDGE_IMPL_ADDR=0x025d71862C01c20Ccb858d98BBB01078c3690B2d +CONTRACTS_L1_SHARED_BRIDGE_PROXY_ADDR=0xf878a0bab7F63d58a006d9789C37201c51798218 +CONTRACTS_L1_SHARED_BRIDGE_IMPL_ADDR=0x75654a9B121A1B4a9F82eA417f530d50d22Ae379 +CONTRACTS_L1_ERC20_BRIDGE_PROXY_ADDR=0x6F26224F8e82CE5A9fDCdbd79b26CFF6477e4412 +CONTRACTS_L1_ERC20_BRIDGE_IMPL_ADDR=0x99a202636B53d615DCa47B718793A3d7B2De7050 diff --git a/yarn.lock b/yarn.lock index e8bc79d0395..3b534178ba1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -759,10 +759,10 @@ minimatch "^3.1.2" strip-json-comments "^3.1.1" -"@eslint/js@8.56.0": - version "8.56.0" - resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.56.0.tgz#ef20350fec605a7f7035a01764731b2de0f3782b" - integrity sha512-gMsVel9D7f2HLkBma9VbtzZRehRogVRfbr++f06nL2vnCGCNlzOD+/MUov/F4p8myyAHspEhVobgjpX64q5m6A== +"@eslint/js@8.57.0": + version "8.57.0" + resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.0.tgz#a5417ae8427873f1dd08b70b3574b453e67b5f7f" + integrity sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g== "@ethereum-waffle/chai@4.0.10": version "4.0.10" @@ -1654,7 +1654,7 @@ optionalDependencies: "@trufflesuite/bigint-buffer" "1.1.9" -"@humanwhocodes/config-array@^0.11.13": +"@humanwhocodes/config-array@^0.11.14": version "0.11.14" resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.14.tgz#d78e481a039f7566ecc9660b4ea7fe6b1fec442b" integrity sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg== @@ -2014,19 +2014,19 @@ dockerode "^3.3.4" "@matterlabs/hardhat-zksync-solc@^1.0.5", "@matterlabs/hardhat-zksync-solc@^1.0.6": - version "1.1.2" - resolved "https://registry.yarnpkg.com/@matterlabs/hardhat-zksync-solc/-/hardhat-zksync-solc-1.1.2.tgz#d5c371acb8b745f018f0559403fe590e8c1dd8b4" - integrity sha512-4qyt9T3OevP+IGJqGd6cS/BKwJnne6XfYCq4gES2nnXoyIWOihmuaL9+KDsbvwVI4mBfB4bz84+SP68W5Bxuig== + version "1.1.4" + resolved "https://registry.yarnpkg.com/@matterlabs/hardhat-zksync-solc/-/hardhat-zksync-solc-1.1.4.tgz#04a2fad6fb6b6944c64ad969080ee65b9af3f617" + integrity sha512-4/usbogh9neewR2/v8Dn2OzqVblZMUuT/iH2MyPZgPRZYQlL4SlZtMvokU9UQjZT6iSoaKCbbdWESHDHSzfUjA== dependencies: "@nomiclabs/hardhat-docker" "^2.0.0" chai "^4.3.6" chalk "4.1.2" debug "^4.3.4" - dockerode "^4.0.0" + dockerode "^4.0.2" fs-extra "^11.1.1" proper-lockfile "^4.1.2" semver "^7.5.1" - sinon "^16.0.0" + sinon "^17.0.1" sinon-chai "^3.7.0" undici "^5.14.0" @@ -2115,6 +2115,66 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" +"@nomicfoundation/edr-darwin-arm64@0.2.1": + version "0.2.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-arm64/-/edr-darwin-arm64-0.2.1.tgz#10c1a07add192583ce8b2d4cc93439f52b390a41" + integrity sha512-aMYaRaZVQ/TmyNJIoXf1bU4k0zfinaL9Sy1day4yGlL6eiQPFfRGj9W6TZaZIoYG0XTx/mQWD7dkXJ7LdrleJA== + +"@nomicfoundation/edr-darwin-x64@0.2.1": + version "0.2.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-x64/-/edr-darwin-x64-0.2.1.tgz#eaa29d2ba9f91ddb5f59b872c5a54f94a6fe3095" + integrity sha512-ma0SLcjHm5L3nPHcKFJB0jv/gKGSKaxr5Z65rurX/eaYUQJ7YGMsb8er9bSCo9rjzOtxf4FoPj3grL3zGpOj8A== + +"@nomicfoundation/edr-linux-arm64-gnu@0.2.1": + version "0.2.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-gnu/-/edr-linux-arm64-gnu-0.2.1.tgz#8149db0d742157405effe82d485ea9bfefddc795" + integrity sha512-NX3G4pBhRitWrjSGY3HTyCq3wKSm5YqrKVOCNQGl9/jcjSovqxlgzFMiTx4YZCzGntfJ/1om9AI84OWxYJjoDw== + +"@nomicfoundation/edr-linux-arm64-musl@0.2.1": + version "0.2.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-musl/-/edr-linux-arm64-musl-0.2.1.tgz#7d53afe5607eb406d199a199d00209a6304ff07b" + integrity sha512-gdQ3QHkt9XRkdtOGQ8fMwS11MXdjLeZgLrqoial4V4qtMaamIMMhVczK+VEvUhD8p7G4BVmp6kmkvcsthmndmw== + +"@nomicfoundation/edr-linux-x64-gnu@0.2.1": + version "0.2.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-gnu/-/edr-linux-x64-gnu-0.2.1.tgz#b762c95368fcb88bbbabba4d8be5380f38967413" + integrity sha512-OqabFY37vji6mYbLD9CvG28lja68czeVw58oWByIhFV3BpBu/cyP1oAbhzk3LieylujabS3Ekpvjw2Tkf0A9RQ== + +"@nomicfoundation/edr-linux-x64-musl@0.2.1": + version "0.2.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-musl/-/edr-linux-x64-musl-0.2.1.tgz#522448c42bff7d2abd52ddcf11ae6ca3dfdd6db4" + integrity sha512-vHfFFK2EPISuQUQge+bdjXamb0EUjfl8srYSog1qfiwyLwLeuSbpyyFzDeITAgPpkkFuedTfJW553K0Hipspyg== + +"@nomicfoundation/edr-win32-arm64-msvc@0.2.1": + version "0.2.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-win32-arm64-msvc/-/edr-win32-arm64-msvc-0.2.1.tgz#ccfa443c274e49de93016a1060be810096dc6f1d" + integrity sha512-K/mui67RCKxghbSyvhvW3rvyVN1pa9M1Q9APUx1PtWjSSdXDFpqEY1NYsv2syb47Ca8ObJwVMF+LvnB6GvhUOQ== + +"@nomicfoundation/edr-win32-ia32-msvc@0.2.1": + version "0.2.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-win32-ia32-msvc/-/edr-win32-ia32-msvc-0.2.1.tgz#822b19d3e67d6dcfa5394cb6a4d55d8bab1b2f26" + integrity sha512-HHK0mXEtjvfjJrJlqcYgQCy3lZIXS1KNl2GaP8bwEIuEwx++XxXs/ThLjPepM1nhCGICij8IGy7p3KrkzRelsw== + +"@nomicfoundation/edr-win32-x64-msvc@0.2.1": + version "0.2.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-win32-x64-msvc/-/edr-win32-x64-msvc-0.2.1.tgz#7b56ff742b2724779cc9f3385815b394f76de8df" + integrity sha512-FY4eQJdj1/y8ST0RyQycx63yr+lvdYNnUkzgWf4X+vPH1lOhXae+L2NDcNCQlTDAfQcD6yz0bkBUkLrlJ8pTww== + +"@nomicfoundation/edr@^0.2.0": + version "0.2.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/edr/-/edr-0.2.1.tgz#a3d2a542dcd5dc5a8d757116d52baea05f370531" + integrity sha512-Dleau3ItHJh2n85G2J6AIPBoLgu/mOWkmrh26z3VsJE2tp/e00hUk/dqz85ncsVcBYEc6/YOn/DomWu0wSF9tQ== + optionalDependencies: + "@nomicfoundation/edr-darwin-arm64" "0.2.1" + "@nomicfoundation/edr-darwin-x64" "0.2.1" + "@nomicfoundation/edr-linux-arm64-gnu" "0.2.1" + "@nomicfoundation/edr-linux-arm64-musl" "0.2.1" + "@nomicfoundation/edr-linux-x64-gnu" "0.2.1" + "@nomicfoundation/edr-linux-x64-musl" "0.2.1" + "@nomicfoundation/edr-win32-arm64-msvc" "0.2.1" + "@nomicfoundation/edr-win32-ia32-msvc" "0.2.1" + "@nomicfoundation/edr-win32-x64-msvc" "0.2.1" + "@nomicfoundation/ethereumjs-block@5.0.1": version "5.0.1" resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-block/-/ethereumjs-block-5.0.1.tgz#6f89664f55febbd723195b6d0974773d29ee133d" @@ -2128,18 +2188,6 @@ ethereum-cryptography "0.1.3" ethers "^5.7.1" -"@nomicfoundation/ethereumjs-block@5.0.4": - version "5.0.4" - resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-block/-/ethereumjs-block-5.0.4.tgz#ff2acb98a86b9290e35e315a6abfb9aebb9cf39e" - integrity sha512-AcyacJ9eX/uPEvqsPiB+WO1ymE+kyH48qGGiGV+YTojdtas8itUTW5dehDSOXEEItWGbbzEJ4PRqnQZlWaPvDw== - dependencies: - "@nomicfoundation/ethereumjs-common" "4.0.4" - "@nomicfoundation/ethereumjs-rlp" "5.0.4" - "@nomicfoundation/ethereumjs-trie" "6.0.4" - "@nomicfoundation/ethereumjs-tx" "5.0.4" - "@nomicfoundation/ethereumjs-util" "9.0.4" - ethereum-cryptography "0.1.3" - "@nomicfoundation/ethereumjs-blockchain@7.0.1": version "7.0.1" resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-blockchain/-/ethereumjs-blockchain-7.0.1.tgz#80e0bd3535bfeb9baa29836b6f25123dab06a726" @@ -2159,22 +2207,6 @@ lru-cache "^5.1.1" memory-level "^1.0.0" -"@nomicfoundation/ethereumjs-blockchain@7.0.4": - version "7.0.4" - resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-blockchain/-/ethereumjs-blockchain-7.0.4.tgz#b77511b389290b186c8d999e70f4b15c27ef44ea" - integrity sha512-jYsd/kwzbmpnxx86tXsYV8wZ5xGvFL+7/P0c6OlzpClHsbFzeF41KrYA9scON8Rg6bZu3ZTv6JOAgj3t7USUfg== - dependencies: - "@nomicfoundation/ethereumjs-block" "5.0.4" - "@nomicfoundation/ethereumjs-common" "4.0.4" - "@nomicfoundation/ethereumjs-ethash" "3.0.4" - "@nomicfoundation/ethereumjs-rlp" "5.0.4" - "@nomicfoundation/ethereumjs-trie" "6.0.4" - "@nomicfoundation/ethereumjs-tx" "5.0.4" - "@nomicfoundation/ethereumjs-util" "9.0.4" - debug "^4.3.3" - ethereum-cryptography "0.1.3" - lru-cache "^10.0.0" - "@nomicfoundation/ethereumjs-common@4.0.1": version "4.0.1" resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-common/-/ethereumjs-common-4.0.1.tgz#4702d82df35b07b5407583b54a45bf728e46a2f0" @@ -2202,17 +2234,6 @@ bigint-crypto-utils "^3.0.23" ethereum-cryptography "0.1.3" -"@nomicfoundation/ethereumjs-ethash@3.0.4": - version "3.0.4" - resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-ethash/-/ethereumjs-ethash-3.0.4.tgz#06cb2502b3012fb6c11cffd44af08aecf71310da" - integrity sha512-xvIrwIMl9sSaiYKRem68+O7vYdj7Q2XWv5P7JXiIkn83918QzWHvqbswTRsH7+r6X1UEvdsURRnZbvZszEjAaQ== - dependencies: - "@nomicfoundation/ethereumjs-block" "5.0.4" - "@nomicfoundation/ethereumjs-rlp" "5.0.4" - "@nomicfoundation/ethereumjs-util" "9.0.4" - bigint-crypto-utils "^3.2.2" - ethereum-cryptography "0.1.3" - "@nomicfoundation/ethereumjs-evm@2.0.1": version "2.0.1" resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-evm/-/ethereumjs-evm-2.0.1.tgz#f35681e203363f69ce2b3d3bf9f44d4e883ca1f1" @@ -2227,20 +2248,6 @@ mcl-wasm "^0.7.1" rustbn.js "~0.2.0" -"@nomicfoundation/ethereumjs-evm@2.0.4": - version "2.0.4" - resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-evm/-/ethereumjs-evm-2.0.4.tgz#c9c761767283ac53946185474362230b169f8f63" - integrity sha512-lTyZZi1KpeMHzaO6cSVisR2tjiTTedjo7PcmhI/+GNFo9BmyY6QYzGeSti0sFttmjbEMioHgXxl5yrLNRg6+1w== - dependencies: - "@nomicfoundation/ethereumjs-common" "4.0.4" - "@nomicfoundation/ethereumjs-statemanager" "2.0.4" - "@nomicfoundation/ethereumjs-tx" "5.0.4" - "@nomicfoundation/ethereumjs-util" "9.0.4" - "@types/debug" "^4.1.9" - debug "^4.3.3" - ethereum-cryptography "0.1.3" - rustbn-wasm "^0.2.0" - "@nomicfoundation/ethereumjs-rlp@5.0.1": version "5.0.1" resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-rlp/-/ethereumjs-rlp-5.0.1.tgz#0b30c1cf77d125d390408e391c4bb5291ef43c28" @@ -2263,20 +2270,6 @@ ethers "^5.7.1" js-sdsl "^4.1.4" -"@nomicfoundation/ethereumjs-statemanager@2.0.4": - version "2.0.4" - resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-statemanager/-/ethereumjs-statemanager-2.0.4.tgz#bf14415e1f31b5ea8b98a0c027c547d0555059b6" - integrity sha512-HPDjeFrxw6llEi+BzqXkZ+KkvFnTOPczuHBtk21hRlDiuKuZz32dPzlhpRsDBGV1b5JTmRDUVqCS1lp3Gghw4Q== - dependencies: - "@nomicfoundation/ethereumjs-common" "4.0.4" - "@nomicfoundation/ethereumjs-rlp" "5.0.4" - "@nomicfoundation/ethereumjs-trie" "6.0.4" - "@nomicfoundation/ethereumjs-util" "9.0.4" - debug "^4.3.3" - ethereum-cryptography "0.1.3" - js-sdsl "^4.1.4" - lru-cache "^10.0.0" - "@nomicfoundation/ethereumjs-trie@6.0.1": version "6.0.1" resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-trie/-/ethereumjs-trie-6.0.1.tgz#662c55f6b50659fd4b22ea9f806a7401cafb7717" @@ -2288,18 +2281,6 @@ ethereum-cryptography "0.1.3" readable-stream "^3.6.0" -"@nomicfoundation/ethereumjs-trie@6.0.4": - version "6.0.4" - resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-trie/-/ethereumjs-trie-6.0.4.tgz#688a3f76646c209365ee6d959c3d7330ede5e609" - integrity sha512-3nSwQiFMvr2VFe/aZUyinuohYvtytUqZCUCvIWcPJ/BwJH6oQdZRB42aNFBJ/8nAh2s3OcroWpBLskzW01mFKA== - dependencies: - "@nomicfoundation/ethereumjs-rlp" "5.0.4" - "@nomicfoundation/ethereumjs-util" "9.0.4" - "@types/readable-stream" "^2.3.13" - ethereum-cryptography "0.1.3" - lru-cache "^10.0.0" - readable-stream "^3.6.0" - "@nomicfoundation/ethereumjs-tx@5.0.1": version "5.0.1" resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-tx/-/ethereumjs-tx-5.0.1.tgz#7629dc2036b4a33c34e9f0a592b43227ef4f0c7d" @@ -2339,16 +2320,6 @@ "@nomicfoundation/ethereumjs-rlp" "5.0.4" ethereum-cryptography "0.1.3" -"@nomicfoundation/ethereumjs-verkle@0.0.2": - version "0.0.2" - resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-verkle/-/ethereumjs-verkle-0.0.2.tgz#7686689edec775b2efea5a71548f417c18f7dea4" - integrity sha512-bjnfZElpYGK/XuuVRmLS3yDvr+cDs85D9oonZ0YUa5A3lgFgokWMp76zXrxX2jVQ0BfHaw12y860n1+iOi6yFQ== - dependencies: - "@nomicfoundation/ethereumjs-rlp" "5.0.4" - "@nomicfoundation/ethereumjs-util" "9.0.4" - lru-cache "^10.0.0" - rust-verkle-wasm "^0.0.1" - "@nomicfoundation/ethereumjs-vm@7.0.1": version "7.0.1" resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-vm/-/ethereumjs-vm-7.0.1.tgz#7d035e0993bcad10716c8b36e61dfb87fa3ca05f" @@ -2368,23 +2339,6 @@ mcl-wasm "^0.7.1" rustbn.js "~0.2.0" -"@nomicfoundation/ethereumjs-vm@7.0.4": - version "7.0.4" - resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-vm/-/ethereumjs-vm-7.0.4.tgz#e5a6eec4877dc62dda93003c6d7afd1fe4b9625b" - integrity sha512-gsA4IhmtWHI4BofKy3kio9W+dqZQs5Ji5mLjLYxHCkat+JQBUt5szjRKra2F9nGDJ2XcI/wWb0YWUFNgln4zRQ== - dependencies: - "@nomicfoundation/ethereumjs-block" "5.0.4" - "@nomicfoundation/ethereumjs-blockchain" "7.0.4" - "@nomicfoundation/ethereumjs-common" "4.0.4" - "@nomicfoundation/ethereumjs-evm" "2.0.4" - "@nomicfoundation/ethereumjs-rlp" "5.0.4" - "@nomicfoundation/ethereumjs-statemanager" "2.0.4" - "@nomicfoundation/ethereumjs-trie" "6.0.4" - "@nomicfoundation/ethereumjs-tx" "5.0.4" - "@nomicfoundation/ethereumjs-util" "9.0.4" - debug "^4.3.3" - ethereum-cryptography "0.1.3" - "@nomicfoundation/hardhat-chai-matchers@^1.0.3", "@nomicfoundation/hardhat-chai-matchers@^1.0.6": version "1.0.6" resolved "https://registry.yarnpkg.com/@nomicfoundation/hardhat-chai-matchers/-/hardhat-chai-matchers-1.0.6.tgz#72a2e312e1504ee5dd73fe302932736432ba96bc" @@ -2649,7 +2603,7 @@ path-browserify "^1.0.0" url "^0.11.0" -"@scure/base@^1.1.1", "@scure/base@~1.1.0", "@scure/base@~1.1.4": +"@scure/base@~1.1.0", "@scure/base@~1.1.4": version "1.1.5" resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.5.tgz#1d85d17269fe97694b9c592552dd9e5e33552157" integrity sha512-Brj9FiG2W1MRQSTB212YVPRrcbjkv48FoZi/u4l/zds/ieRrqsh7aUf6CLwkAq61oKXr/ZlTzlY66gLIj3TFTQ== @@ -2782,7 +2736,7 @@ dependencies: type-detect "4.0.8" -"@sinonjs/fake-timers@^10.0.2", "@sinonjs/fake-timers@^10.3.0": +"@sinonjs/fake-timers@^10.0.2": version "10.3.0" resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-10.3.0.tgz#55fdff1ecab9f354019129daf4df0dd4d923ea66" integrity sha512-V4BG07kuYSUkTCSBHG8G8TNhM+F19jXFWnQtzj+we8DrkpSBCee9Z3Ms8yiGer/dlmhe35/Xdgyo3/0rQKg7YA== @@ -2973,7 +2927,12 @@ dependencies: "@types/chai" "*" -"@types/chai@*", "@types/chai@^4.2.21": +"@types/chai@*": + version "4.3.12" + resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.12.tgz#b192fe1c553b54f45d20543adc2ab88455a07d5e" + integrity sha512-zNKDHG/1yxm8Il6uCCVsm+dRdEsJlFoDu73X17y09bId6UwoYww+vFBsAcRzl8knM1sab3Dp1VRikFQwDOtDDw== + +"@types/chai@^4.2.21": version "4.3.11" resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.11.tgz#e95050bf79a932cb7305dd130254ccdf9bde671c" integrity sha512-qQR1dr2rGIHYlJulmr8Ioq3De0Le9E4MJ5AiaeAETJJpndT1uUNHsGFK3L/UIu+rbkQSdj8J/w2bCsBZc/Y5fQ== @@ -2985,13 +2944,6 @@ dependencies: "@types/node" "*" -"@types/debug@^4.1.9": - version "4.1.12" - resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.12.tgz#a155f21690871953410df4b6b6f53187f0500917" - integrity sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ== - dependencies: - "@types/ms" "*" - "@types/deep-extend@^0.4.31": version "0.4.32" resolved "https://registry.yarnpkg.com/@types/deep-extend/-/deep-extend-0.4.32.tgz#0af51fffde55cb168e8d68f8236908c2cdfe7419" @@ -3109,11 +3061,6 @@ resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-8.2.3.tgz#bbeb55fbc73f28ea6de601fbfa4613f58d785323" integrity sha512-ekGvFhFgrc2zYQoX4JeZPmVzZxw6Dtllga7iGHzfbYIYkAMUx/sAFP2GdFpLff+vdHXu5fl7WX9AT+TtqYcsyw== -"@types/ms@*": - version "0.7.34" - resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.34.tgz#10964ba0dee6ac4cd462e2795b6bebd407303433" - integrity sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g== - "@types/node-fetch@^2.5.7", "@types/node-fetch@^2.6.1": version "2.6.11" resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.11.tgz#9b39b78665dae0e82a08f02f4967d62c66f95d24" @@ -3176,9 +3123,9 @@ integrity sha512-+68kP9yzs4LMp7VNh8gdzMSPZFL44MLGqiHWvttYJe+6qnuVr4Ek9wSBQoveqY/r+LwjCcU29kNVkidwim+kYA== "@types/qs@^6.2.31": - version "6.9.11" - resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.11.tgz#208d8a30bc507bd82e03ada29e4732ea46a6bbda" - integrity sha512-oGk0gmhnEJK4Yyk+oI7EfXsLayXatCWPHary1MtcmbAifkobT9cM9yutG/hZKIseOU0MqbIwQ/u2nn/Gb+ltuQ== + version "6.9.12" + resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.12.tgz#afa96b383a3a6fdc859453a1892d41b607fc7756" + integrity sha512-bZcOkJ6uWrL0Qb2NAWKa7TBU+mJHPzhx9jjLL1KHF+XpzEcR7EXHvjbHlGtR/IsP1vyPrehuS6XqkmaePy//mg== "@types/readable-stream@^2.3.13": version "2.3.15" @@ -3953,7 +3900,7 @@ bech32@1.1.4: resolved "https://registry.yarnpkg.com/bech32/-/bech32-1.1.4.tgz#e38c9f37bf179b8eb16ae3a772b40c356d4832e9" integrity sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ== -bigint-crypto-utils@^3.0.23, bigint-crypto-utils@^3.2.2: +bigint-crypto-utils@^3.0.23: version "3.3.0" resolved "https://registry.yarnpkg.com/bigint-crypto-utils/-/bigint-crypto-utils-3.3.0.tgz#72ad00ae91062cf07f2b1def9594006c279c1d77" integrity sha512-jOTSb+drvEDxEq6OuUybOAv/xxoh3cuYRUIPyu8sSHQNKM303UQ2R1DAo45o1AkcIXw6fzbaFI1+xGGdaXs2lg== @@ -5147,7 +5094,7 @@ dockerode@^3.3.4: docker-modem "^3.0.0" tar-fs "~2.0.1" -dockerode@^4.0.0: +dockerode@^4.0.0, dockerode@^4.0.2: version "4.0.2" resolved "https://registry.yarnpkg.com/dockerode/-/dockerode-4.0.2.tgz#dedc8529a1db3ac46d186f5912389899bc309f7d" integrity sha512-9wM1BVpVMFr2Pw3eJNXrYYt6DT9k0xMcsSCjtPvyQ+xa1iPg/Mo3T/gUcwI0B2cczqCeCYRPF8yFYDwtFXT0+w== @@ -5298,9 +5245,9 @@ end-of-stream@^1.0.0, end-of-stream@^1.1.0, end-of-stream@^1.4.1: once "^1.4.0" enhanced-resolve@^5.12.0: - version "5.15.0" - resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz#1af946c7d93603eb88e9896cee4904dc012e9c35" - integrity sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg== + version "5.15.1" + resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.15.1.tgz#384391e025f099e67b4b00bfd7f0906a408214e1" + integrity sha512-3d3JRbwsCLJsYgvb6NuWEG44jjPSOMuS73L/6+7BZuoKm3W+qXnSoIYVHi8dG7Qcg4inAY4jbzkZ7MnskePeDg== dependencies: graceful-fs "^4.2.4" tapable "^2.2.0" @@ -5501,9 +5448,9 @@ eslint-import-resolver-typescript@^3.6.1: is-glob "^4.0.3" eslint-module-utils@^2.7.4, eslint-module-utils@^2.8.0: - version "2.8.0" - resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.8.0.tgz#e439fee65fc33f6bba630ff621efc38ec0375c49" - integrity sha512-aWajIYfsqCKRDgUfjEXNN/JlrzauMuSEy5sbd7WXbtW3EH6A6MpwEh42c7qD+MqQo9QMJ6fWLAeIJynx0g6OAw== + version "2.8.1" + resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.8.1.tgz#52f2404300c3bd33deece9d7372fb337cc1d7c34" + integrity sha512-rXDXR3h7cs7dy9RNpUlQf80nX31XWJEyGq1tRMo+6GsO5VmTe4UTwtmonAD4ZkAsrfMVDA2wlGJ3790Ys+D49Q== dependencies: debug "^3.2.7" @@ -5623,15 +5570,15 @@ eslint@^7.16.0: v8-compile-cache "^2.0.3" eslint@^8.51.0: - version "8.56.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.56.0.tgz#4957ce8da409dc0809f99ab07a1b94832ab74b15" - integrity sha512-Go19xM6T9puCOWntie1/P997aXxFsOi37JIHRWI514Hc6ZnaHGKY9xFhrU65RT6CcBEzZoGG1e6Nq+DT04ZtZQ== + version "8.57.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.57.0.tgz#c786a6fd0e0b68941aaf624596fb987089195668" + integrity sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ== dependencies: "@eslint-community/eslint-utils" "^4.2.0" "@eslint-community/regexpp" "^4.6.1" "@eslint/eslintrc" "^2.1.4" - "@eslint/js" "8.56.0" - "@humanwhocodes/config-array" "^0.11.13" + "@eslint/js" "8.57.0" + "@humanwhocodes/config-array" "^0.11.14" "@humanwhocodes/module-importer" "^1.0.1" "@nodelib/fs.walk" "^1.2.8" "@ungap/structured-clone" "^1.2.0" @@ -6806,23 +6753,16 @@ hardhat@=2.16.0: ws "^7.4.6" hardhat@^2.18.3: - version "2.20.1" - resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.20.1.tgz#3ad8f2b003a96c9ce80a55fec3575580ff2ddcd4" - integrity sha512-q75xDQiQtCZcTMBwjTovrXEU5ECr49baxr4/OBkIu/ULTPzlB20yk1dRWNmD2IFbAeAeXggaWvQAdpiScaHtPw== + version "2.21.0" + resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.21.0.tgz#2e23126310a6c77cd7e149e6af1dd67626b7a74f" + integrity sha512-8DlJAVJDEVHaV1sh9FLuKLLgCFv9EAJ+M+8IbjSIPgoeNo3ss5L1HgGBMfnI88c7OzMEZkdcuyGoobFeK3Orqw== dependencies: "@ethersproject/abi" "^5.1.2" "@metamask/eth-sig-util" "^4.0.0" - "@nomicfoundation/ethereumjs-block" "5.0.4" - "@nomicfoundation/ethereumjs-blockchain" "7.0.4" + "@nomicfoundation/edr" "^0.2.0" "@nomicfoundation/ethereumjs-common" "4.0.4" - "@nomicfoundation/ethereumjs-evm" "2.0.4" - "@nomicfoundation/ethereumjs-rlp" "5.0.4" - "@nomicfoundation/ethereumjs-statemanager" "2.0.4" - "@nomicfoundation/ethereumjs-trie" "6.0.4" "@nomicfoundation/ethereumjs-tx" "5.0.4" "@nomicfoundation/ethereumjs-util" "9.0.4" - "@nomicfoundation/ethereumjs-verkle" "0.0.2" - "@nomicfoundation/ethereumjs-vm" "7.0.4" "@nomicfoundation/solidity-analyzer" "^0.1.0" "@sentry/node" "^5.18.1" "@types/bn.js" "^5.1.0" @@ -8413,11 +8353,6 @@ loupe@^2.3.6: dependencies: get-func-name "^2.0.1" -lru-cache@^10.0.0, "lru-cache@^9.1.1 || ^10.0.0": - version "10.2.0" - resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.2.0.tgz#0bd445ca57363465900f4d1f9bd8db343a4d95c3" - integrity sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q== - lru-cache@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920" @@ -8432,6 +8367,11 @@ lru-cache@^6.0.0: dependencies: yallist "^4.0.0" +"lru-cache@^9.1.1 || ^10.0.0": + version "10.2.0" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.2.0.tgz#0bd445ca57363465900f4d1f9bd8db343a4d95c3" + integrity sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q== + lru_map@^0.3.3: version "0.3.3" resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd" @@ -8952,7 +8892,7 @@ nise@^4.0.4: just-extend "^4.0.2" path-to-regexp "^1.7.0" -nise@^5.1.4: +nise@^5.1.5: version "5.1.9" resolved "https://registry.yarnpkg.com/nise/-/nise-5.1.9.tgz#0cb73b5e4499d738231a473cd89bd8afbb618139" integrity sha512-qOnoujW4SV6e40dYxJOb3uvuoPHtmLzIk4TFo+j0jPJoC+5Z9xja5qH5JZobEPsa8+YYphMrOSwnrshEhG2qww== @@ -10123,18 +10063,6 @@ run-parallel@^1.1.9: dependencies: queue-microtask "^1.2.2" -rust-verkle-wasm@^0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/rust-verkle-wasm/-/rust-verkle-wasm-0.0.1.tgz#fd8396a7060d8ee8ea10da50ab6e862948095a74" - integrity sha512-BN6fiTsxcd2dCECz/cHtGTt9cdLJR925nh7iAuRcj8ymKw7OOaPmCneQZ7JePOJ/ia27TjEL91VdOi88Yf+mcA== - -rustbn-wasm@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/rustbn-wasm/-/rustbn-wasm-0.2.0.tgz#0407521fb55ae69eeb4968d01885d63efd1c4ff9" - integrity sha512-FThvYFNTqrEKGqXuseeg0zR7yROh/6U1617mCHF68OVqrN1tNKRN7Tdwy4WayPVsCmmK+eMxtIZX1qL6JxTkMg== - dependencies: - "@scure/base" "^1.1.1" - rustbn.js@~0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/rustbn.js/-/rustbn.js-0.2.0.tgz#8082cb886e707155fd1cb6f23bd591ab8d55d0ca" @@ -10370,16 +10298,16 @@ sinon-chai@^3.7.0: resolved "https://registry.yarnpkg.com/sinon-chai/-/sinon-chai-3.7.0.tgz#cfb7dec1c50990ed18c153f1840721cf13139783" integrity sha512-mf5NURdUaSdnatJx3uhoBOrY9dtL19fiOtAdT1Azxg3+lNJFiuN0uzaU3xX1LeAfL17kHQhTAJgpsfhbMJMY2g== -sinon@^16.0.0: - version "16.1.3" - resolved "https://registry.yarnpkg.com/sinon/-/sinon-16.1.3.tgz#b760ddafe785356e2847502657b4a0da5501fba8" - integrity sha512-mjnWWeyxcAf9nC0bXcPmiDut+oE8HYridTNzBbF98AYVLmWwGRp2ISEpyhYflG1ifILT+eNn3BmKUJPxjXUPlA== +sinon@^17.0.1: + version "17.0.1" + resolved "https://registry.yarnpkg.com/sinon/-/sinon-17.0.1.tgz#26b8ef719261bf8df43f925924cccc96748e407a" + integrity sha512-wmwE19Lie0MLT+ZYNpDymasPHUKTaZHUH/pKEubRXIzySv9Atnlw+BUMGCzWgV7b7wO+Hw6f1TEOr0IUnmU8/g== dependencies: "@sinonjs/commons" "^3.0.0" - "@sinonjs/fake-timers" "^10.3.0" + "@sinonjs/fake-timers" "^11.2.2" "@sinonjs/samsam" "^8.0.0" diff "^5.1.0" - nise "^5.1.4" + nise "^5.1.5" supports-color "^7.2.0" sinon@^9.0.0: @@ -10497,9 +10425,9 @@ solidity-comments-extractor@^0.0.8: integrity sha512-htM7Vn6LhHreR+EglVMd2s+sZhcXAirB1Zlyrv5zBuTxieCvjfnRpd7iZk75m/u6NOlEyQ94C6TWbBn2cY7w8g== solidity-coverage@^0.8.5: - version "0.8.7" - resolved "https://registry.yarnpkg.com/solidity-coverage/-/solidity-coverage-0.8.7.tgz#fa8809fdd3321c357609fd20f6888878efc0f0fc" - integrity sha512-RzcPuNsIqVGq5F8rjQZPdI2EVdsRU7w2f1Uk1UY567n9eNcg5LSEQ3Q1WFoy9bi/2AD5SYbYK9SS/Nwh2oYbNw== + version "0.8.10" + resolved "https://registry.yarnpkg.com/solidity-coverage/-/solidity-coverage-0.8.10.tgz#8985f9f80a34432daf397fc13d994e689f3df92d" + integrity sha512-6nvlWLnCjBIVnCgTZiIo2XBI62O3YJuU83xj+bklnH/B+dXGTjuQB7SccZfysUC3LFkjtZO/KjzUJ/hiSlkXWw== dependencies: "@ethersproject/abi" "^5.0.9" "@solidity-parser/parser" "^0.18.0" From cf5f2ffdaf8036afdb12e1a5762c82b81576337c Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Wed, 6 Mar 2024 11:06:16 -0300 Subject: [PATCH 35/49] fix stop handle for converstion rate api --- core/lib/zksync_core/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index 5abea8c0ef0..31ba81e3293 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -331,16 +331,16 @@ pub async fn initialize_components( }); let mut task_futures: Vec>> = Vec::new(); + let (stop_sender, stop_receiver) = watch::channel(false); // spawn the conversion rate API if it is enabled if components.contains(&Component::ConversionRateApi) { - let (_stop_sender, stop_receiver) = watch::channel(false); - let native_token_fetcher_config = configs .native_token_fetcher_config .clone() .context("native_token_fetcher_config")?; + let stop_receiver = stop_receiver.clone(); let conversion_rate_task = tokio::spawn(async move { api_conversion_rate::run_server(stop_receiver, &native_token_fetcher_config).await }); @@ -361,7 +361,6 @@ pub async fn initialize_components( None }; - let (stop_sender, stop_receiver) = watch::channel(false); let (cb_sender, cb_receiver) = oneshot::channel(); let conversion_rate_fetcher: Arc = From 46b6ef40d2b89e3efa0cd0ab7b3f661ac07e6bdf Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Wed, 6 Mar 2024 11:13:13 -0300 Subject: [PATCH 36/49] add logging for conversion rate --- core/lib/zksync_core/src/api_conversion_rate/mod.rs | 1 + core/lib/zksync_core/src/native_token_fetcher/mod.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/core/lib/zksync_core/src/api_conversion_rate/mod.rs b/core/lib/zksync_core/src/api_conversion_rate/mod.rs index 17440aeaa4a..fead76e3c4f 100644 --- a/core/lib/zksync_core/src/api_conversion_rate/mod.rs +++ b/core/lib/zksync_core/src/api_conversion_rate/mod.rs @@ -31,6 +31,7 @@ pub(crate) async fn run_server( // basic handler that responds with a static string async fn get_conversion_rate(extract::Path(_token_address): extract::Path) -> Json { + tracing::info!("Received request for conversion rate"); let mut rng = rand::thread_rng(); let random_number: u64 = rng.gen_range(1..=100); Json(random_number) diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index 5b07d740307..76367c20b51 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -128,6 +128,7 @@ impl NativeTokenFetcher { let conversion_rate = response.json::().await.context( "Unable to parse the response of the native token conversion rate server", )?; + tracing::info!("Fetched native token conversion rate: {}", conversion_rate); self.latest_to_eth_conversion_rate .store(conversion_rate, std::sync::atomic::Ordering::Relaxed); error_reporter.reset(); From 6e0c81294b7f78d85d8768356ba0cd3815c82de2 Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Thu, 7 Mar 2024 14:10:14 -0300 Subject: [PATCH 37/49] Remove unnecessary alert_spawned boolean --- .../src/native_token_fetcher/mod.rs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index 99f740d6e46..4c769ce9081 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -1,7 +1,4 @@ -use std::{ - cmp::min, - sync::atomic::{AtomicBool, AtomicU8}, -}; +use std::{cmp::min, sync::atomic::AtomicU8}; use anyhow::Context; use async_trait::async_trait; @@ -112,7 +109,6 @@ impl ConversionRateFetcher for NativeTokenFetcher { #[derive(Debug)] struct ErrorReporter { current_try: AtomicU8, - alert_spawned: AtomicBool, } impl ErrorReporter { @@ -121,32 +117,24 @@ impl ErrorReporter { fn new() -> Self { Self { current_try: AtomicU8::new(0), - alert_spawned: AtomicBool::new(false), } } fn reset(&self) { self.current_try .store(0, std::sync::atomic::Ordering::Relaxed); - self.alert_spawned - .store(false, std::sync::atomic::Ordering::Relaxed); } fn process(&self, err: anyhow::Error) { let current_try = self.current_try.load(std::sync::atomic::Ordering::Relaxed); - let new_value = min(current_try + 1, Self::MAX_CONSECUTIVE_NETWORK_ERRORS); + let new_value = current_try + 1; self.current_try .store(new_value, std::sync::atomic::Ordering::Relaxed); tracing::error!("Failed to fetch native token conversion rate from the server: {err}"); - let alert_spawned = self - .alert_spawned - .load(std::sync::atomic::Ordering::Relaxed); - if new_value >= Self::MAX_CONSECUTIVE_NETWORK_ERRORS && !alert_spawned { + if new_value == Self::MAX_CONSECUTIVE_NETWORK_ERRORS { vlog::capture_message(&err.to_string(), vlog::AlertLevel::Warning); - self.alert_spawned - .store(true, std::sync::atomic::Ordering::Relaxed); } } } From 13cf3431a7f634040359debebb616630bafe1216 Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Fri, 8 Mar 2024 17:20:55 -0300 Subject: [PATCH 38/49] Revert "Remove unnecessary alert_spawned boolean" This reverts commit 6e0c81294b7f78d85d8768356ba0cd3815c82de2. --- .../src/native_token_fetcher/mod.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index 4c769ce9081..99f740d6e46 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -1,4 +1,7 @@ -use std::{cmp::min, sync::atomic::AtomicU8}; +use std::{ + cmp::min, + sync::atomic::{AtomicBool, AtomicU8}, +}; use anyhow::Context; use async_trait::async_trait; @@ -109,6 +112,7 @@ impl ConversionRateFetcher for NativeTokenFetcher { #[derive(Debug)] struct ErrorReporter { current_try: AtomicU8, + alert_spawned: AtomicBool, } impl ErrorReporter { @@ -117,24 +121,32 @@ impl ErrorReporter { fn new() -> Self { Self { current_try: AtomicU8::new(0), + alert_spawned: AtomicBool::new(false), } } fn reset(&self) { self.current_try .store(0, std::sync::atomic::Ordering::Relaxed); + self.alert_spawned + .store(false, std::sync::atomic::Ordering::Relaxed); } fn process(&self, err: anyhow::Error) { let current_try = self.current_try.load(std::sync::atomic::Ordering::Relaxed); - let new_value = current_try + 1; + let new_value = min(current_try + 1, Self::MAX_CONSECUTIVE_NETWORK_ERRORS); self.current_try .store(new_value, std::sync::atomic::Ordering::Relaxed); tracing::error!("Failed to fetch native token conversion rate from the server: {err}"); - if new_value == Self::MAX_CONSECUTIVE_NETWORK_ERRORS { + let alert_spawned = self + .alert_spawned + .load(std::sync::atomic::Ordering::Relaxed); + if new_value >= Self::MAX_CONSECUTIVE_NETWORK_ERRORS && !alert_spawned { vlog::capture_message(&err.to_string(), vlog::AlertLevel::Warning); + self.alert_spawned + .store(true, std::sync::atomic::Ordering::Relaxed); } } } From fbf66b15e11767592b05a5f4fecd82aca26edd21 Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Fri, 8 Mar 2024 17:40:24 -0300 Subject: [PATCH 39/49] Use a mutex for the errorreporter --- .../src/native_token_fetcher/mod.rs | 49 ++++++++----------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/native_token_fetcher/mod.rs index 99f740d6e46..f606ff085f8 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/native_token_fetcher/mod.rs @@ -1,12 +1,10 @@ -use std::{ - cmp::min, - sync::atomic::{AtomicBool, AtomicU8}, -}; +use std::{cmp::min, sync::Arc}; use anyhow::Context; use async_trait::async_trait; use hex::ToHex; use metrics::atomics::AtomicU64; +use tokio::sync::Mutex; use zksync_config::configs::native_token_fetcher::NativeTokenFetcherConfig; /// Trait used to query the stack's native token conversion rate. Used to properly @@ -44,7 +42,7 @@ pub(crate) struct NativeTokenFetcher { pub config: NativeTokenFetcherConfig, pub latest_to_eth_conversion_rate: AtomicU64, http_client: reqwest::Client, - error_reporter: ErrorReporter, + error_reporter: Arc>, } impl NativeTokenFetcher { @@ -63,7 +61,7 @@ impl NativeTokenFetcher { .await .context("Unable to parse the response of the native token conversion rate server")?; - let error_reporter = ErrorReporter::new(); + let error_reporter = Arc::new(Mutex::new(ErrorReporter::new())); Ok(Self { config, @@ -100,9 +98,13 @@ impl ConversionRateFetcher for NativeTokenFetcher { )?; self.latest_to_eth_conversion_rate .store(conversion_rate, std::sync::atomic::Ordering::Relaxed); - self.error_reporter.reset(); + self.error_reporter.lock().await.reset(); } - Err(err) => self.error_reporter.process(anyhow::anyhow!(err)), + Err(err) => self + .error_reporter + .lock() + .await + .process(anyhow::anyhow!(err)), } Ok(()) @@ -111,8 +113,8 @@ impl ConversionRateFetcher for NativeTokenFetcher { #[derive(Debug)] struct ErrorReporter { - current_try: AtomicU8, - alert_spawned: AtomicBool, + current_try: u8, + alert_spawned: bool, } impl ErrorReporter { @@ -120,33 +122,24 @@ impl ErrorReporter { fn new() -> Self { Self { - current_try: AtomicU8::new(0), - alert_spawned: AtomicBool::new(false), + current_try: 0, + alert_spawned: false, } } - fn reset(&self) { - self.current_try - .store(0, std::sync::atomic::Ordering::Relaxed); - self.alert_spawned - .store(false, std::sync::atomic::Ordering::Relaxed); + fn reset(&mut self) { + self.current_try = 0; + self.alert_spawned = false; } - fn process(&self, err: anyhow::Error) { - let current_try = self.current_try.load(std::sync::atomic::Ordering::Relaxed); - let new_value = min(current_try + 1, Self::MAX_CONSECUTIVE_NETWORK_ERRORS); - self.current_try - .store(new_value, std::sync::atomic::Ordering::Relaxed); + fn process(&mut self, err: anyhow::Error) { + self.current_try = min(self.current_try + 1, Self::MAX_CONSECUTIVE_NETWORK_ERRORS); tracing::error!("Failed to fetch native token conversion rate from the server: {err}"); - let alert_spawned = self - .alert_spawned - .load(std::sync::atomic::Ordering::Relaxed); - if new_value >= Self::MAX_CONSECUTIVE_NETWORK_ERRORS && !alert_spawned { + if self.current_try >= Self::MAX_CONSECUTIVE_NETWORK_ERRORS && !self.alert_spawned { vlog::capture_message(&err.to_string(), vlog::AlertLevel::Warning); - self.alert_spawned - .store(true, std::sync::atomic::Ordering::Relaxed); + self.alert_spawned = true; } } } From a19be607ea8b287339c040d78bc13d2ba8c8f18d Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Fri, 8 Mar 2024 17:41:35 -0300 Subject: [PATCH 40/49] Revert changes to .init.env --- etc/env/l1-inits/.init.env | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/etc/env/l1-inits/.init.env b/etc/env/l1-inits/.init.env index b771d3c0518..efb1742d996 100644 --- a/etc/env/l1-inits/.init.env +++ b/etc/env/l1-inits/.init.env @@ -1,29 +1,29 @@ CONTRACTS_LATEST_PROTOCOL_VERSION=22 CONTRACTS_CREATE2_FACTORY_ADDR=0x3c4CE2E9D8b03BbCd568E47465A483EE86893c49 -CONTRACTS_VERIFIER_ADDR=0xF025a57cfda291db967Cbd88120fb8997232bC5E -CONTRACTS_L1_MULTICALL3_ADDR=0x905C13b7CD5dDCbAc889ab375b1171F1b73abB0a +CONTRACTS_VERIFIER_ADDR=0xCf42AEFfB17dED8de2d4116D33716354F53e51e6 +CONTRACTS_L1_MULTICALL3_ADDR=0x69D85c64032337E58064A35020d6F45Dab350883 CONTRACTS_GENESIS_ROOT=0x300ac58a9fa3b6283791831f5d62b1b525b81e6ec4f4793bea5fb14ebea730c7 CHAIN_STATE_KEEPER_BOOTLOADER_HASH=0x010007ed36aa249ae63fa088c251736a3170cd179a03d8d6f0fe6a6f47b23705 CHAIN_STATE_KEEPER_DEFAULT_AA_HASH=0x0100055bbad08b38b8e0b22b57703bb1f440b8789a3ba809a4ca4830c497e1d4 CONTRACTS_GENESIS_BATCH_COMMITMENT=0x921bdf66c72d3f84c1f7520050c4980721d32b6c95c76ab32aaa556a6430d24c CONTRACTS_GENESIS_ROLLUP_LEAF_INDEX=25 CONTRACTS_L1_WETH_TOKEN_ADDR=0x4A470422bFf67C34a3A565106118023059fa4E34 -CONTRACTS_BRIDGEHUB_PROXY_ADDR=0x1f849CcAEDc8f1e2b134398429b83079C3312838 -CONTRACTS_BRIDGEHUB_IMPL_ADDR=0xE04e74e7005eD8EB352e7c7f861Cdf20C854211A -CONTRACTS_STATE_TRANSITION_PROXY_ADDR=0xdec77cB44245c13a3D04E1388CbaF0a9AC5CE030 -CONTRACTS_STATE_TRANSITION_IMPL_ADDR=0xB73F0239979523B5C2739a4Da1d5939d93Cb7F28 -CONTRACTS_ADMIN_FACET_ADDR=0x237ea7fF712b43A8c8AF12aE9fe1609f7be30d0c -CONTRACTS_DIAMOND_UPGRADE_INIT_ADDR=0xDf3aE6Ed38547e28436359b5F41F2d6384172d9d -CONTRACTS_DIAMOND_INIT_ADDR=0xCEbc1cdB0028571f0Fdc6C36555a079A65c013ed -CONTRACTS_DEFAULT_UPGRADE_ADDR=0xff264541e1617Ff59531387F568CD2B3Bb2a9f9F -CONTRACTS_GENESIS_UPGRADE_ADDR=0x5E7a81741129A0dACE27906163b4878cf22A1Adf -CONTRACTS_GOVERNANCE_ADDR=0xFeD6891Aa811b36BFF738eDFC4E80A6C3afcfeeE -CONTRACTS_MAILBOX_FACET_ADDR=0x91839132a58bF1d492cd4E3494b811aE70BC1704 -CONTRACTS_EXECUTOR_FACET_ADDR=0x30417aCA2281d7e0f513ff2827050391c12133f7 -CONTRACTS_GETTERS_FACET_ADDR=0xf516C23364e86F0495a8cFc602E0f00A90c8B682 -CONTRACTS_VALIDATOR_TIMELOCK_ADDR=0x605e085451F8E3057e2B07669Ef41D23264842B1 +CONTRACTS_BRIDGEHUB_PROXY_ADDR=0xb81673bCE7AAd30D8C18A3e118fc5018B8E1b304 +CONTRACTS_BRIDGEHUB_IMPL_ADDR=0x8F78c7272727e3cf99d631cA2Ee04A7F866F7D0A +CONTRACTS_STATE_TRANSITION_PROXY_ADDR=0x71470A85Afc4dE5241ae84c5b382c245e36E2e2E +CONTRACTS_STATE_TRANSITION_IMPL_ADDR=0x5C542Cc2886E6B8172D1E87637b5f681df6cE6b4 +CONTRACTS_ADMIN_FACET_ADDR=0xB178e8fECEa2521aC351f4179eF53014EF66deA4 +CONTRACTS_DIAMOND_UPGRADE_INIT_ADDR=0x01e88D723515404ea24136D2b2209D80597c60EE +CONTRACTS_DIAMOND_INIT_ADDR=0x1440EbE06A353bca88cAD588d5AC55513ACC9d31 +CONTRACTS_DEFAULT_UPGRADE_ADDR=0xD14F5CF299EF63a9aD5DcF35D7c43b07c48192Ff +CONTRACTS_GENESIS_UPGRADE_ADDR=0x223350ebdb7bB5EE851C1e089D51cc1900D84CC6 +CONTRACTS_GOVERNANCE_ADDR=0x410a4b3a5A7F2c52B1bCdeFBA05091a932A75c82 +CONTRACTS_MAILBOX_FACET_ADDR=0xb73B7e1cA6ef3F9d036466004433FB9E2f3eB3ce +CONTRACTS_EXECUTOR_FACET_ADDR=0x9F630Aa2999ff37736a5a64FA4Edd396A5d0Cafc +CONTRACTS_GETTERS_FACET_ADDR=0x27197A55F385AA3bA572618928845f591f677AD7 +CONTRACTS_VALIDATOR_TIMELOCK_ADDR=0x43e5978b9BCF261e3b3d93bfc76b36db513A7C42 CONTRACTS_TRANSPARENT_PROXY_ADMIN_ADDR=0x20410058241d1c4C5f7C04753BD4713B04f19423 -CONTRACTS_L1_SHARED_BRIDGE_PROXY_ADDR=0xf7e17A2B474Fb364229cdA5591B6CA6bD23849BE -CONTRACTS_L1_SHARED_BRIDGE_IMPL_ADDR=0xF01055b018b42508f54434c12A93a472545ae8db -CONTRACTS_L1_ERC20_BRIDGE_PROXY_ADDR=0x03352137199A03c3EfaB9525213a52C8f3AF2311 -CONTRACTS_L1_ERC20_BRIDGE_IMPL_ADDR=0xd0bd759411EB29Ff013cD0665dBdE3eFA1F4Fa4a +CONTRACTS_L1_SHARED_BRIDGE_PROXY_ADDR=0x3C95EE1e5dade52f008b71d09fE0ba178603AFC3 +CONTRACTS_L1_SHARED_BRIDGE_IMPL_ADDR=0x3D3805B1B87A9a69232B4082955A3982049d1EA2 +CONTRACTS_L1_ERC20_BRIDGE_PROXY_ADDR=0x910123E3Fe7a35a5A76735cbA6D4f25A0F1eE459 +CONTRACTS_L1_ERC20_BRIDGE_IMPL_ADDR=0x025d71862C01c20Ccb858d98BBB01078c3690B2d From d99e9bf6106d6b2705d73e03e67fd1b067895a24 Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Mon, 11 Mar 2024 13:10:21 -0300 Subject: [PATCH 41/49] rmv flask app, rename component & refactor func --- core/lib/zksync_core/src/api_conversion_rate/mod.rs | 5 +---- core/lib/zksync_core/src/lib.rs | 6 +++--- erc20_example.py | 8 -------- 3 files changed, 4 insertions(+), 15 deletions(-) delete mode 100644 erc20_example.py diff --git a/core/lib/zksync_core/src/api_conversion_rate/mod.rs b/core/lib/zksync_core/src/api_conversion_rate/mod.rs index fead76e3c4f..e095c97fe62 100644 --- a/core/lib/zksync_core/src/api_conversion_rate/mod.rs +++ b/core/lib/zksync_core/src/api_conversion_rate/mod.rs @@ -1,5 +1,4 @@ use axum::{extract, extract::Json, routing::get, Router}; -use rand::Rng; use tokio::sync::watch; use zksync_config::configs::native_token_fetcher::NativeTokenFetcherConfig; @@ -32,7 +31,5 @@ pub(crate) async fn run_server( // basic handler that responds with a static string async fn get_conversion_rate(extract::Path(_token_address): extract::Path) -> Json { tracing::info!("Received request for conversion rate"); - let mut rng = rand::thread_rng(); - let random_number: u64 = rng.gen_range(1..=100); - Json(random_number) + Json(42) } diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index 31ba81e3293..5a9e7def963 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -237,7 +237,7 @@ pub enum Component { /// Native Token fetcher NativeTokenFetcher, /// Conversion rate API, for local development. - ConversionRateApi, + DevConversionRateApi, } #[derive(Debug)] @@ -273,7 +273,7 @@ impl FromStr for Components { "eth_tx_manager" => Ok(Components(vec![Component::EthTxManager])), "proof_data_handler" => Ok(Components(vec![Component::ProofDataHandler])), "native_token_fetcher" => Ok(Components(vec![Component::NativeTokenFetcher])), - "conversion_rate_api" => Ok(Components(vec![Component::ConversionRateApi])), + "conversion_rate_api" => Ok(Components(vec![Component::DevConversionRateApi])), other => Err(format!("{} is not a valid component name", other)), } } @@ -334,7 +334,7 @@ pub async fn initialize_components( let (stop_sender, stop_receiver) = watch::channel(false); // spawn the conversion rate API if it is enabled - if components.contains(&Component::ConversionRateApi) { + if components.contains(&Component::DevConversionRateApi) { let native_token_fetcher_config = configs .native_token_fetcher_config .clone() diff --git a/erc20_example.py b/erc20_example.py deleted file mode 100644 index 70828545b1f..00000000000 --- a/erc20_example.py +++ /dev/null @@ -1,8 +0,0 @@ -from flask import Flask -from random import randint - -app = Flask(__name__) - -@app.route("/conversion_rate/") -def conversion_rate(token_address): - return str(randint(1, 100)) From 8d379245966248028a4684bc24d2f14c8fe2d63d Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Mon, 11 Mar 2024 14:00:05 -0300 Subject: [PATCH 42/49] rename module --- .../{api_conversion_rate => dev_api_conversion_rate}/mod.rs | 0 core/lib/zksync_core/src/lib.rs | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) rename core/lib/zksync_core/src/{api_conversion_rate => dev_api_conversion_rate}/mod.rs (100%) diff --git a/core/lib/zksync_core/src/api_conversion_rate/mod.rs b/core/lib/zksync_core/src/dev_api_conversion_rate/mod.rs similarity index 100% rename from core/lib/zksync_core/src/api_conversion_rate/mod.rs rename to core/lib/zksync_core/src/dev_api_conversion_rate/mod.rs diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index 5a9e7def963..035f63a8674 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -76,12 +76,12 @@ use crate::{ }, }; -pub mod api_conversion_rate; pub mod api_server; pub mod basic_witness_input_producer; pub mod block_reverter; pub mod consensus; pub mod consistency_checker; +pub mod dev_api_conversion_rate; pub mod eth_sender; pub mod eth_watch; mod fee_model; @@ -273,7 +273,7 @@ impl FromStr for Components { "eth_tx_manager" => Ok(Components(vec![Component::EthTxManager])), "proof_data_handler" => Ok(Components(vec![Component::ProofDataHandler])), "native_token_fetcher" => Ok(Components(vec![Component::NativeTokenFetcher])), - "conversion_rate_api" => Ok(Components(vec![Component::DevConversionRateApi])), + "dev_conversion_rate_api" => Ok(Components(vec![Component::DevConversionRateApi])), other => Err(format!("{} is not a valid component name", other)), } } @@ -342,7 +342,7 @@ pub async fn initialize_components( let stop_receiver = stop_receiver.clone(); let conversion_rate_task = tokio::spawn(async move { - api_conversion_rate::run_server(stop_receiver, &native_token_fetcher_config).await + dev_api_conversion_rate::run_server(stop_receiver, &native_token_fetcher_config).await }); task_futures.push(conversion_rate_task); }; From 5680df8f4ecd3de69071564f17eb122797ab50d9 Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Tue, 19 Mar 2024 16:20:01 -0300 Subject: [PATCH 43/49] zk fmt --- core/lib/dal/src/blocks_dal.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/lib/dal/src/blocks_dal.rs b/core/lib/dal/src/blocks_dal.rs index 79dc66c26c8..a15ea716f1f 100644 --- a/core/lib/dal/src/blocks_dal.rs +++ b/core/lib/dal/src/blocks_dal.rs @@ -2216,7 +2216,7 @@ impl BlocksDal<'_, '_> { ) WHERE l1_batch_number IS NULL - AND fee_account_address = '\x0000000000000000000000000000000000000000'::bytea + AND fee_account_address = 'x0000000000000000000000000000000000000000'::bytea "# ) .execute(self.storage.conn()) @@ -2256,7 +2256,7 @@ impl BlocksDal<'_, '_> { WHERE l1_batches.number = miniblocks.l1_batch_number AND miniblocks.number BETWEEN $1 AND $2 - AND miniblocks.fee_account_address = '\x0000000000000000000000000000000000000000'::bytea + AND miniblocks.fee_account_address = 'x0000000000000000000000000000000000000000'::bytea "#, numbers.start().0 as i64, numbers.end().0 as i64 From b520744f0605f64728738e31ba422fe01d39d19a Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Mon, 25 Mar 2024 13:11:11 -0300 Subject: [PATCH 44/49] rename native token to base token --- core/bin/zksync_server/src/main.rs | 4 +-- ...token_fetcher.rs => base_token_fetcher.rs} | 2 +- core/lib/config/src/configs/mod.rs | 4 +-- core/lib/env_config/src/base_token_fetcher.rs | 9 ++++++ core/lib/env_config/src/lib.rs | 2 +- .../env_config/src/native_token_fetcher.rs | 9 ------ ...token_fetcher.rs => base_token_fetcher.rs} | 6 ++-- core/lib/protobuf_config/src/lib.rs | 2 +- ...fetcher.proto => base_token_fetcher.proto} | 4 +-- .../mod.rs | 12 ++++---- .../src/dev_api_conversion_rate/mod.rs | 4 +-- .../src/l1_gas_price/gas_adjuster/mod.rs | 12 ++++---- .../zksync_core/src/l1_gas_price/singleton.rs | 10 +++---- core/lib/zksync_core/src/lib.rs | 28 +++++++++---------- core/lib/zksync_core/src/proto/mod.proto | 4 +-- .../zksync_core/src/temp_config_store/mod.rs | 12 ++++---- ...n_fetcher.toml => base_token_fetcher.toml} | 2 +- etc/env/configs/dev.toml | 1 + 18 files changed, 64 insertions(+), 63 deletions(-) rename core/lib/config/src/configs/{native_token_fetcher.rs => base_token_fetcher.rs} (83%) create mode 100644 core/lib/env_config/src/base_token_fetcher.rs delete mode 100644 core/lib/env_config/src/native_token_fetcher.rs rename core/lib/protobuf_config/src/{native_token_fetcher.rs => base_token_fetcher.rs} (82%) rename core/lib/protobuf_config/src/proto/{native_token_fetcher.proto => base_token_fetcher.proto} (64%) rename core/lib/zksync_core/src/{native_token_fetcher => base_token_fetcher}/mod.rs (92%) rename etc/env/base/{native_token_fetcher.toml => base_token_fetcher.toml} (85%) diff --git a/core/bin/zksync_server/src/main.rs b/core/bin/zksync_server/src/main.rs index 5a40db33fd1..7b72004cc8d 100644 --- a/core/bin/zksync_server/src/main.rs +++ b/core/bin/zksync_server/src/main.rs @@ -5,13 +5,13 @@ use clap::Parser; use zksync_config::{ configs::{ api::{HealthCheckConfig, MerkleTreeApiConfig, Web3JsonRpcConfig}, + base_token_fetcher::BaseTokenFetcherConfig, chain::{ CircuitBreakerConfig, MempoolConfig, NetworkConfig, OperationsManagerConfig, StateKeeperConfig, }, fri_prover_group::FriProverGroupConfig, house_keeper::HouseKeeperConfig, - native_token_fetcher::NativeTokenFetcherConfig, FriProofCompressorConfig, FriProverConfig, FriWitnessGeneratorConfig, ObservabilityConfig, PrometheusConfig, ProofDataHandlerConfig, WitnessGeneratorConfig, }, @@ -140,7 +140,7 @@ async fn main() -> anyhow::Result<()> { eth_watch_config: ETHWatchConfig::from_env().ok(), gas_adjuster_config: GasAdjusterConfig::from_env().ok(), object_store_config: ObjectStoreConfig::from_env().ok(), - native_token_fetcher_config: NativeTokenFetcherConfig::from_env().ok(), + base_token_fetcher_config: BaseTokenFetcherConfig::from_env().ok(), consensus_config: config::read_consensus_config().context("read_consensus_config()")?, }, }; diff --git a/core/lib/config/src/configs/native_token_fetcher.rs b/core/lib/config/src/configs/base_token_fetcher.rs similarity index 83% rename from core/lib/config/src/configs/native_token_fetcher.rs rename to core/lib/config/src/configs/base_token_fetcher.rs index 4afc40acc69..5a74aec3438 100644 --- a/core/lib/config/src/configs/native_token_fetcher.rs +++ b/core/lib/config/src/configs/base_token_fetcher.rs @@ -2,7 +2,7 @@ use serde::Deserialize; use zksync_basic_types::Address; #[derive(Debug, Clone, Deserialize, PartialEq)] -pub struct NativeTokenFetcherConfig { +pub struct BaseTokenFetcherConfig { pub poll_interval: u64, pub host: String, pub token_address: Address, diff --git a/core/lib/config/src/configs/mod.rs b/core/lib/config/src/configs/mod.rs index f5ecb1fcdc6..0d8c52da023 100644 --- a/core/lib/config/src/configs/mod.rs +++ b/core/lib/config/src/configs/mod.rs @@ -2,6 +2,7 @@ pub use self::{ alerts::AlertsConfig, api::ApiConfig, + base_token_fetcher::BaseTokenFetcherConfig, contract_verifier::ContractVerifierConfig, contracts::ContractsConfig, database::{DBConfig, PostgresConfig}, @@ -13,7 +14,6 @@ pub use self::{ fri_prover_gateway::FriProverGatewayConfig, fri_witness_generator::FriWitnessGeneratorConfig, fri_witness_vector_generator::FriWitnessVectorGeneratorConfig, - native_token_fetcher::NativeTokenFetcherConfig, object_store::ObjectStoreConfig, observability::ObservabilityConfig, proof_data_handler::ProofDataHandlerConfig, @@ -24,6 +24,7 @@ pub use self::{ pub mod alerts; pub mod api; +pub mod base_token_fetcher; pub mod chain; pub mod contract_verifier; pub mod contracts; @@ -38,7 +39,6 @@ pub mod fri_prover_group; pub mod fri_witness_generator; pub mod fri_witness_vector_generator; pub mod house_keeper; -pub mod native_token_fetcher; pub mod object_store; pub mod observability; pub mod proof_data_handler; diff --git a/core/lib/env_config/src/base_token_fetcher.rs b/core/lib/env_config/src/base_token_fetcher.rs new file mode 100644 index 00000000000..9e0aed1c59a --- /dev/null +++ b/core/lib/env_config/src/base_token_fetcher.rs @@ -0,0 +1,9 @@ +use zksync_config::configs::base_token_fetcher::BaseTokenFetcherConfig; + +use crate::{envy_load, FromEnv}; + +impl FromEnv for BaseTokenFetcherConfig { + fn from_env() -> anyhow::Result { + envy_load("base_token_fetcher", "base_token_fetcher_") + } +} diff --git a/core/lib/env_config/src/lib.rs b/core/lib/env_config/src/lib.rs index 53a325fa338..9452555a3cd 100644 --- a/core/lib/env_config/src/lib.rs +++ b/core/lib/env_config/src/lib.rs @@ -3,6 +3,7 @@ use serde::de::DeserializeOwned; mod alerts; mod api; +pub mod base_token_fetcher; mod chain; mod contract_verifier; mod contracts; @@ -17,7 +18,6 @@ mod fri_prover_group; mod fri_witness_generator; mod fri_witness_vector_generator; mod house_keeper; -pub mod native_token_fetcher; pub mod object_store; mod observability; mod proof_data_handler; diff --git a/core/lib/env_config/src/native_token_fetcher.rs b/core/lib/env_config/src/native_token_fetcher.rs deleted file mode 100644 index dde0e086907..00000000000 --- a/core/lib/env_config/src/native_token_fetcher.rs +++ /dev/null @@ -1,9 +0,0 @@ -use zksync_config::configs::native_token_fetcher::NativeTokenFetcherConfig; - -use crate::{envy_load, FromEnv}; - -impl FromEnv for NativeTokenFetcherConfig { - fn from_env() -> anyhow::Result { - envy_load("native_token_fetcher", "NATIVE_TOKEN_FETCHER_") - } -} diff --git a/core/lib/protobuf_config/src/native_token_fetcher.rs b/core/lib/protobuf_config/src/base_token_fetcher.rs similarity index 82% rename from core/lib/protobuf_config/src/native_token_fetcher.rs rename to core/lib/protobuf_config/src/base_token_fetcher.rs index fbff1ea8632..930e764eab9 100644 --- a/core/lib/protobuf_config/src/native_token_fetcher.rs +++ b/core/lib/protobuf_config/src/base_token_fetcher.rs @@ -2,10 +2,10 @@ use anyhow::{Context as _, Ok}; use zksync_config::configs; use zksync_protobuf::{repr::ProtoRepr, required}; -use crate::{parse_h160, proto::native_token_fetcher as proto}; +use crate::{parse_h160, proto::base_token_fetcher as proto}; -impl ProtoRepr for proto::NativeTokenFetcher { - type Type = configs::NativeTokenFetcherConfig; +impl ProtoRepr for proto::BaseTokenFetcher { + type Type = configs::BaseTokenFetcherConfig; fn read(&self) -> anyhow::Result { Ok(Self::Type { poll_interval: *required(&self.poll_interval).context("poll_interval")?, diff --git a/core/lib/protobuf_config/src/lib.rs b/core/lib/protobuf_config/src/lib.rs index f16109cf861..f6c7eb7a4d8 100644 --- a/core/lib/protobuf_config/src/lib.rs +++ b/core/lib/protobuf_config/src/lib.rs @@ -6,6 +6,7 @@ mod alerts; mod api; +mod base_token_fetcher; mod chain; mod contract_verifier; mod contracts; @@ -20,7 +21,6 @@ mod fri_prover_group; mod fri_witness_generator; mod fri_witness_vector_generator; mod house_keeper; -mod native_token_fetcher; mod object_store; mod observability; mod proof_data_handler; diff --git a/core/lib/protobuf_config/src/proto/native_token_fetcher.proto b/core/lib/protobuf_config/src/proto/base_token_fetcher.proto similarity index 64% rename from core/lib/protobuf_config/src/proto/native_token_fetcher.proto rename to core/lib/protobuf_config/src/proto/base_token_fetcher.proto index b9dd1801821..c0e447e0a43 100644 --- a/core/lib/protobuf_config/src/proto/native_token_fetcher.proto +++ b/core/lib/protobuf_config/src/proto/base_token_fetcher.proto @@ -1,8 +1,8 @@ syntax = "proto3"; -package zksync.config.native_token_fetcher; +package zksync.config.base_token_fetcher; -message NativeTokenFetcher { +message BaseTokenFetcher { optional uint64 poll_interval = 1; optional string host = 2; optional bytes token_address = 3; diff --git a/core/lib/zksync_core/src/native_token_fetcher/mod.rs b/core/lib/zksync_core/src/base_token_fetcher/mod.rs similarity index 92% rename from core/lib/zksync_core/src/native_token_fetcher/mod.rs rename to core/lib/zksync_core/src/base_token_fetcher/mod.rs index f606ff085f8..c6c060cd0e1 100644 --- a/core/lib/zksync_core/src/native_token_fetcher/mod.rs +++ b/core/lib/zksync_core/src/base_token_fetcher/mod.rs @@ -5,7 +5,7 @@ use async_trait::async_trait; use hex::ToHex; use metrics::atomics::AtomicU64; use tokio::sync::Mutex; -use zksync_config::configs::native_token_fetcher::NativeTokenFetcherConfig; +use zksync_config::configs::base_token_fetcher::BaseTokenFetcherConfig; /// Trait used to query the stack's native token conversion rate. Used to properly /// determine gas prices, as they partially depend on L1 gas prices, denominated in `eth`. @@ -38,15 +38,15 @@ impl ConversionRateFetcher for NoOpConversionRateFetcher { /// Struct in charge of periodically querying and caching the native token's conversion rate /// to `eth`. #[derive(Debug)] -pub(crate) struct NativeTokenFetcher { - pub config: NativeTokenFetcherConfig, +pub(crate) struct BaseTokenFetcher { + pub config: BaseTokenFetcherConfig, pub latest_to_eth_conversion_rate: AtomicU64, http_client: reqwest::Client, error_reporter: Arc>, } -impl NativeTokenFetcher { - pub(crate) async fn new(config: NativeTokenFetcherConfig) -> anyhow::Result { +impl BaseTokenFetcher { + pub(crate) async fn new(config: BaseTokenFetcherConfig) -> anyhow::Result { let http_client = reqwest::Client::new(); let conversion_rate = http_client @@ -73,7 +73,7 @@ impl NativeTokenFetcher { } #[async_trait] -impl ConversionRateFetcher for NativeTokenFetcher { +impl ConversionRateFetcher for BaseTokenFetcher { fn conversion_rate(&self) -> anyhow::Result { anyhow::Ok( self.latest_to_eth_conversion_rate diff --git a/core/lib/zksync_core/src/dev_api_conversion_rate/mod.rs b/core/lib/zksync_core/src/dev_api_conversion_rate/mod.rs index e095c97fe62..5f565cb4835 100644 --- a/core/lib/zksync_core/src/dev_api_conversion_rate/mod.rs +++ b/core/lib/zksync_core/src/dev_api_conversion_rate/mod.rs @@ -1,10 +1,10 @@ use axum::{extract, extract::Json, routing::get, Router}; use tokio::sync::watch; -use zksync_config::configs::native_token_fetcher::NativeTokenFetcherConfig; +use zksync_config::configs::base_token_fetcher::BaseTokenFetcherConfig; pub(crate) async fn run_server( mut stop_receiver: watch::Receiver, - server_configs: &NativeTokenFetcherConfig, + server_configs: &BaseTokenFetcherConfig, ) -> anyhow::Result<()> { let app = Router::new().route("/conversion_rate/:token_address", get(get_conversion_rate)); diff --git a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs index 90d8891e884..fc4faaa0e21 100644 --- a/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs +++ b/core/lib/zksync_core/src/l1_gas_price/gas_adjuster/mod.rs @@ -14,7 +14,7 @@ use zksync_types::{U256, U64}; use self::metrics::METRICS; use super::L1TxParamsProvider; -use crate::{native_token_fetcher::ConversionRateFetcher, state_keeper::metrics::KEEPER_METRICS}; +use crate::{base_token_fetcher::ConversionRateFetcher, state_keeper::metrics::KEEPER_METRICS}; mod metrics; #[cfg(test)] @@ -33,7 +33,7 @@ pub struct GasAdjuster { pub(super) config: GasAdjusterConfig, pubdata_sending_mode: PubdataSendingMode, eth_client: Arc, - native_token_fetcher: Arc, + base_token_fetcher: Arc, } impl GasAdjuster { @@ -41,7 +41,7 @@ impl GasAdjuster { eth_client: Arc, config: GasAdjusterConfig, pubdata_sending_mode: PubdataSendingMode, - native_token_fetcher: Arc, + base_token_fetcher: Arc, ) -> Result { // Subtracting 1 from the "latest" block number to prevent errors in case // the info about the latest block is not yet present on the node. @@ -72,7 +72,7 @@ impl GasAdjuster { &last_block_blob_base_fee, ), config, - native_token_fetcher, + base_token_fetcher, pubdata_sending_mode, eth_client, }) @@ -160,7 +160,7 @@ impl GasAdjuster { tracing::warn!("Cannot add the base fee to gas statistics: {}", err); } - if let Err(err) = self.native_token_fetcher.update().await { + if let Err(err) = self.base_token_fetcher.update().await { tracing::warn!( "Error when trying to fetch the native erc20 conversion rate: {}", err @@ -184,7 +184,7 @@ impl GasAdjuster { let calculated_price = (self.config.internal_l1_pricing_multiplier * effective_gas_price as f64) as u64; - let conversion_rate = self.native_token_fetcher.conversion_rate().unwrap_or(1); + let conversion_rate = self.base_token_fetcher.conversion_rate().unwrap_or(1); self.bound_gas_price(calculated_price) * conversion_rate } diff --git a/core/lib/zksync_core/src/l1_gas_price/singleton.rs b/core/lib/zksync_core/src/l1_gas_price/singleton.rs index c5398762b3d..802156f0707 100644 --- a/core/lib/zksync_core/src/l1_gas_price/singleton.rs +++ b/core/lib/zksync_core/src/l1_gas_price/singleton.rs @@ -8,7 +8,7 @@ use tokio::{ use zksync_config::{configs::eth_sender::PubdataSendingMode, GasAdjusterConfig}; use zksync_eth_client::clients::QueryClient; -use crate::{l1_gas_price::GasAdjuster, native_token_fetcher::ConversionRateFetcher}; +use crate::{base_token_fetcher::ConversionRateFetcher, l1_gas_price::GasAdjuster}; /// Special struct for creating a singleton of `GasAdjuster`. /// This is needed only for running the server. @@ -18,7 +18,7 @@ pub struct GasAdjusterSingleton { gas_adjuster_config: GasAdjusterConfig, pubdata_sending_mode: PubdataSendingMode, singleton: OnceCell, Error>>, - native_token_fetcher: Arc, + base_token_fetcher: Arc, } #[derive(thiserror::Error, Debug, Clone)] @@ -36,14 +36,14 @@ impl GasAdjusterSingleton { web3_url: String, gas_adjuster_config: GasAdjusterConfig, pubdata_sending_mode: PubdataSendingMode, - native_token_fetcher: Arc, + base_token_fetcher: Arc, ) -> Self { Self { web3_url, gas_adjuster_config, pubdata_sending_mode, singleton: OnceCell::new(), - native_token_fetcher, + base_token_fetcher, } } @@ -57,7 +57,7 @@ impl GasAdjusterSingleton { Arc::new(query_client.clone()), self.gas_adjuster_config, self.pubdata_sending_mode, - self.native_token_fetcher.clone(), + self.base_token_fetcher.clone(), ) .await .context("GasAdjuster::new()")?; diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index 841cd0f5e3f..ffe6272668c 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -58,6 +58,7 @@ use crate::{ tx_sender::{ApiContracts, TxSender, TxSenderBuilder, TxSenderConfig}, web3::{self, state::InternalApiConfig, Namespace}, }, + base_token_fetcher::{BaseTokenFetcher, ConversionRateFetcher, NoOpConversionRateFetcher}, basic_witness_input_producer::BasicWitnessInputProducer, commitment_generator::CommitmentGenerator, eth_sender::{Aggregator, EthTxAggregator, EthTxManager}, @@ -77,13 +78,13 @@ use crate::{ l1_gas_price::GasAdjusterSingleton, metadata_calculator::{MetadataCalculator, MetadataCalculatorConfig}, metrics::{InitStage, APP_METRICS}, - native_token_fetcher::{ConversionRateFetcher, NativeTokenFetcher, NoOpConversionRateFetcher}, state_keeper::{ create_state_keeper, MempoolFetcher, MempoolGuard, MiniblockSealer, SequencerSealer, }, }; pub mod api_server; +pub mod base_token_fetcher; pub mod basic_witness_input_producer; pub mod block_reverter; pub mod commitment_generator; @@ -99,7 +100,6 @@ pub mod house_keeper; pub mod l1_gas_price; pub mod metadata_calculator; mod metrics; -pub mod native_token_fetcher; pub mod proof_data_handler; pub mod proto; pub mod reorg_detector; @@ -258,8 +258,8 @@ pub enum Component { Housekeeper, /// Component for exposing APIs to prover for providing proof generation data and accepting proofs. ProofDataHandler, - /// Native Token fetcher - NativeTokenFetcher, + /// Base Token fetcher + BaseTokenFetcher, /// Conversion rate API, for local development. DevConversionRateApi, /// Component generating BFT consensus certificates for miniblocks. @@ -300,7 +300,7 @@ impl FromStr for Components { "eth_tx_aggregator" => Ok(Components(vec![Component::EthTxAggregator])), "eth_tx_manager" => Ok(Components(vec![Component::EthTxManager])), "proof_data_handler" => Ok(Components(vec![Component::ProofDataHandler])), - "native_token_fetcher" => Ok(Components(vec![Component::NativeTokenFetcher])), + "base_token_fetcher" => Ok(Components(vec![Component::BaseTokenFetcher])), "dev_conversion_rate_api" => Ok(Components(vec![Component::DevConversionRateApi])), "consensus" => Ok(Components(vec![Component::Consensus])), "commitment_generator" => Ok(Components(vec![Component::CommitmentGenerator])), @@ -382,25 +382,25 @@ pub async fn initialize_components( // spawn the conversion rate API if it is enabled if components.contains(&Component::DevConversionRateApi) { - let native_token_fetcher_config = configs - .native_token_fetcher_config + let base_token_fetcher_config = configs + .base_token_fetcher_config .clone() - .context("native_token_fetcher_config")?; + .context("base_token_fetcher_config")?; let stop_receiver = stop_receiver.clone(); let conversion_rate_task = tokio::spawn(async move { - dev_api_conversion_rate::run_server(stop_receiver, &native_token_fetcher_config).await + dev_api_conversion_rate::run_server(stop_receiver, &base_token_fetcher_config).await }); task_futures.push(conversion_rate_task); }; - let native_token_fetcher = if components.contains(&Component::NativeTokenFetcher) { + let base_token_fetcher = if components.contains(&Component::BaseTokenFetcher) { Arc::new( - NativeTokenFetcher::new( + BaseTokenFetcher::new( configs - .native_token_fetcher_config + .base_token_fetcher_config .clone() - .context("native_token_fetcher_config")?, + .context("base_token_fetcher_config")?, ) .await?, ) as Arc @@ -419,7 +419,7 @@ pub async fn initialize_components( eth_client_config.web3_url.clone(), gas_adjuster_config, eth_sender_config.sender.pubdata_sending_mode, - native_token_fetcher, + base_token_fetcher, ); let (cb_sender, cb_receiver) = oneshot::channel(); diff --git a/core/lib/zksync_core/src/proto/mod.proto b/core/lib/zksync_core/src/proto/mod.proto index bef9cc74f3a..75c7af531f5 100644 --- a/core/lib/zksync_core/src/proto/mod.proto +++ b/core/lib/zksync_core/src/proto/mod.proto @@ -25,7 +25,7 @@ import "zksync/config/snapshots_creator.proto"; import "zksync/config/utils.proto"; import "zksync/config/witness_generator.proto"; import "zksync/core/consensus.proto"; -import "zksync/config/native_token_fetcher.proto"; +import "zksync/config/base_token_fetcher.proto"; message TempConfigStore { optional config.database.Postgres postgres = 1; @@ -54,7 +54,7 @@ message TempConfigStore { optional config.eth_sender.GasAdjuster gas_adjuster = 24; optional config.object_store.ObjectStore object_store = 25; optional consensus.Config consensus = 26; - optional config.native_token_fetcher.NativeTokenFetcher native_token_fetcher = 27; + optional config.base_token_fetcher.BaseTokenFetcher base_token_fetcher = 27; } message Secrets { diff --git a/core/lib/zksync_core/src/temp_config_store/mod.rs b/core/lib/zksync_core/src/temp_config_store/mod.rs index ae9e5f2ea26..19657ef1aed 100644 --- a/core/lib/zksync_core/src/temp_config_store/mod.rs +++ b/core/lib/zksync_core/src/temp_config_store/mod.rs @@ -2,13 +2,13 @@ use anyhow::Context as _; use zksync_config::{ configs::{ api::{HealthCheckConfig, MerkleTreeApiConfig, Web3JsonRpcConfig}, + base_token_fetcher::BaseTokenFetcherConfig, chain::{ CircuitBreakerConfig, MempoolConfig, NetworkConfig, OperationsManagerConfig, StateKeeperConfig, }, fri_prover_group::FriProverGroupConfig, house_keeper::HouseKeeperConfig, - native_token_fetcher::NativeTokenFetcherConfig, FriProofCompressorConfig, FriProverConfig, FriWitnessGeneratorConfig, PrometheusConfig, ProofDataHandlerConfig, WitnessGeneratorConfig, }, @@ -73,7 +73,7 @@ pub struct TempConfigStore { pub gas_adjuster_config: Option, pub object_store_config: Option, pub consensus_config: Option, - pub native_token_fetcher_config: Option, + pub base_token_fetcher_config: Option, } impl ProtoFmt for TempConfigStore { @@ -114,8 +114,8 @@ impl ProtoFmt for TempConfigStore { gas_adjuster_config: read_optional_repr(&r.gas_adjuster).context("gas_adjuster")?, object_store_config: read_optional_repr(&r.object_store).context("object_store")?, consensus_config: read_optional(&r.consensus).context("consensus")?, - native_token_fetcher_config: read_optional_repr(&r.native_token_fetcher) - .context("native_token_fetcher")?, + base_token_fetcher_config: read_optional_repr(&r.base_token_fetcher) + .context("base_token_fetcher")?, }) } @@ -159,8 +159,8 @@ impl ProtoFmt for TempConfigStore { gas_adjuster: self.gas_adjuster_config.as_ref().map(ProtoRepr::build), object_store: self.object_store_config.as_ref().map(ProtoRepr::build), consensus: self.consensus_config.as_ref().map(ProtoFmt::build), - native_token_fetcher: self - .native_token_fetcher_config + base_token_fetcher: self + .base_token_fetcher_config .as_ref() .map(ProtoRepr::build), } diff --git a/etc/env/base/native_token_fetcher.toml b/etc/env/base/base_token_fetcher.toml similarity index 85% rename from etc/env/base/native_token_fetcher.toml rename to etc/env/base/base_token_fetcher.toml index 0f8d23f4399..4910110b7c7 100644 --- a/etc/env/base/native_token_fetcher.toml +++ b/etc/env/base/base_token_fetcher.toml @@ -1,4 +1,4 @@ -[native_token_fetcher] +[base_token_fetcher] host="http://127.0.0.1:5000" # Poll interval is in seconds poll_interval=10 diff --git a/etc/env/configs/dev.toml b/etc/env/configs/dev.toml index a1e819b2fb9..a420015e091 100644 --- a/etc/env/configs/dev.toml +++ b/etc/env/configs/dev.toml @@ -1,2 +1,3 @@ __imports__ = [ "base", "l1-inits/.init.env", "l2-inits/dev.init.env" ] +ETH_SENDER_SENDER_PUBDATA_SENDING_MODE = "Calldata" # ZKSYNC_DEBUG_LOGS=true From 29289c9a0af4a31d029f21fc5c5fdcf723f954ac Mon Sep 17 00:00:00 2001 From: Jmunoz Date: Mon, 25 Mar 2024 14:52:04 -0300 Subject: [PATCH 45/49] fix env load --- core/lib/env_config/src/base_token_fetcher.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/env_config/src/base_token_fetcher.rs b/core/lib/env_config/src/base_token_fetcher.rs index 9e0aed1c59a..78d559bda90 100644 --- a/core/lib/env_config/src/base_token_fetcher.rs +++ b/core/lib/env_config/src/base_token_fetcher.rs @@ -4,6 +4,6 @@ use crate::{envy_load, FromEnv}; impl FromEnv for BaseTokenFetcherConfig { fn from_env() -> anyhow::Result { - envy_load("base_token_fetcher", "base_token_fetcher_") + envy_load("base_token_fetcher", "BASE_TOKEN_FETCHER_") } } From 7c8ec4523560d964e53229c509d38df40da59114 Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Wed, 27 Mar 2024 14:23:40 -0300 Subject: [PATCH 46/49] add gas oracle documentation --- docs/guides/launch.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/guides/launch.md b/docs/guides/launch.md index 2889216dbbe..73dbdf472c4 100644 --- a/docs/guides/launch.md +++ b/docs/guides/launch.md @@ -94,6 +94,33 @@ template. Make sure you have environment variables set right, you can check it by running: `zk env`. You should see `* dev` in output. +## Gas Price Oracle + +As prices in a custom base token setting need to be in the native currency of the chain. These prices are partially determined by l1 gas prices in L1, which are in eth, so a conversion is required. + +### Conversion rate API + +To use a conversion rate oracle, you will need to add the component to the command: +``` +zk server --components "api,tree,eth,state_keeper,housekeeper,commitment_generator,base_token_fetcher" +``` + +In order to run the server with the conversion rate, you will need to configure the variables in the `etc/env/base/base_token_fetcher.toml` file, or you can export the variables in the environment: +``` +export BASE_TOKEN_FETCHER_HOST= +# Poll interval is in seconds +export BASE_TOKEN_FETCHER_POLL_INTERVAL= +export BASE_TOKEN_FETCHER_TOKEN_ADDRESS= +``` + +Additionally, you can run the server with the `dev_conversion_rate_api` component to enable the development conversion rate API, this component is only meant for development purposes and should not be used in production and will provide a fixed conversion rate for all tokens: + +``` +zk server --components "api,tree,eth,state_keeper,housekeeper,commitment_generator,base_token_fetcher,dev_conversion_rate_api" +``` + +This server will use the host setted in the environment variable previously mentioned. + ## Running server using Google cloud storage object store instead of default In memory store Get the service_account.json file containing the GCP credentials from kubernetes secret for relevant environment(stage2/ From 2a7761ddfdc9729a6f7c9b8cf211d17b4f4b882f Mon Sep 17 00:00:00 2001 From: Santiago Pittella Date: Wed, 27 Mar 2024 14:24:35 -0300 Subject: [PATCH 47/49] fmt --- docs/guides/launch.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/guides/launch.md b/docs/guides/launch.md index 73dbdf472c4..1c5496fa051 100644 --- a/docs/guides/launch.md +++ b/docs/guides/launch.md @@ -96,16 +96,20 @@ output. ## Gas Price Oracle -As prices in a custom base token setting need to be in the native currency of the chain. These prices are partially determined by l1 gas prices in L1, which are in eth, so a conversion is required. +As prices in a custom base token setting need to be in the native currency of the chain. These prices are partially +determined by l1 gas prices in L1, which are in eth, so a conversion is required. ### Conversion rate API To use a conversion rate oracle, you will need to add the component to the command: + ``` zk server --components "api,tree,eth,state_keeper,housekeeper,commitment_generator,base_token_fetcher" ``` -In order to run the server with the conversion rate, you will need to configure the variables in the `etc/env/base/base_token_fetcher.toml` file, or you can export the variables in the environment: +In order to run the server with the conversion rate, you will need to configure the variables in the +`etc/env/base/base_token_fetcher.toml` file, or you can export the variables in the environment: + ``` export BASE_TOKEN_FETCHER_HOST= # Poll interval is in seconds @@ -113,7 +117,9 @@ export BASE_TOKEN_FETCHER_POLL_INTERVAL= export BASE_TOKEN_FETCHER_TOKEN_ADDRESS= ``` -Additionally, you can run the server with the `dev_conversion_rate_api` component to enable the development conversion rate API, this component is only meant for development purposes and should not be used in production and will provide a fixed conversion rate for all tokens: +Additionally, you can run the server with the `dev_conversion_rate_api` component to enable the development conversion +rate API, this component is only meant for development purposes and should not be used in production and will provide a +fixed conversion rate for all tokens: ``` zk server --components "api,tree,eth,state_keeper,housekeeper,commitment_generator,base_token_fetcher,dev_conversion_rate_api" From cd2e52b1065e996b20121787244e3c1bb9627f41 Mon Sep 17 00:00:00 2001 From: Francisco Krause Arnim Date: Mon, 8 Apr 2024 19:21:52 -0300 Subject: [PATCH 48/49] chore(fmt): zk fmt --- core/lib/config/src/configs/general.rs | 3 +-- core/tests/ts-integration/src/context-owner.ts | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/lib/config/src/configs/general.rs b/core/lib/config/src/configs/general.rs index 7541db786bf..cf150e01adc 100644 --- a/core/lib/config/src/configs/general.rs +++ b/core/lib/config/src/configs/general.rs @@ -1,3 +1,4 @@ +use super::BaseTokenFetcherConfig; use crate::{ configs::{ chain::{CircuitBreakerConfig, MempoolConfig, OperationsManagerConfig, StateKeeperConfig}, @@ -10,8 +11,6 @@ use crate::{ ApiConfig, ContractVerifierConfig, DBConfig, ETHConfig, PostgresConfig, SnapshotsCreatorConfig, }; -use super::BaseTokenFetcherConfig; - #[derive(Debug, PartialEq)] pub struct GeneralConfig { pub postgres_config: Option, diff --git a/core/tests/ts-integration/src/context-owner.ts b/core/tests/ts-integration/src/context-owner.ts index 1f1f21fecf1..82cfdbbfa9a 100644 --- a/core/tests/ts-integration/src/context-owner.ts +++ b/core/tests/ts-integration/src/context-owner.ts @@ -368,7 +368,8 @@ export class TestContextOwner { nonce: nonce + (ethIsBaseToken ? 0 : 1), // if eth is base token the approve tx does not happen gasPrice } - }).then((op) => op.waitL1Commit()); + }) + .then((op) => op.waitL1Commit()); nonce = nonce + 1 + (ethIsBaseToken ? 0 : 1); this.reporter.debug( `Nonce changed by ${1 + (ethIsBaseToken ? 0 : 1)} for ETH deposit, new nonce: ${nonce}` From e25b33eec4acbd2fc5391daafde7d565b37e8692 Mon Sep 17 00:00:00 2001 From: fborello-lambda Date: Mon, 8 Apr 2024 16:59:49 -0300 Subject: [PATCH 49/49] feat: add resources/conversion_rate_fetcher.rs Implements a way to get the resource from the context Used at core/node/node_framework/src/implementations/layers/fee_input.rs --- .../src/implementations/layers/l1_gas.rs | 17 ++++++++--------- .../resources/conversion_rate_fetcher.rs | 14 ++++++++++++++ .../src/implementations/resources/mod.rs | 1 + 3 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 core/node/node_framework/src/implementations/resources/conversion_rate_fetcher.rs diff --git a/core/node/node_framework/src/implementations/layers/l1_gas.rs b/core/node/node_framework/src/implementations/layers/l1_gas.rs index 5d956a306da..2d8cae84a2a 100644 --- a/core/node/node_framework/src/implementations/layers/l1_gas.rs +++ b/core/node/node_framework/src/implementations/layers/l1_gas.rs @@ -16,7 +16,7 @@ use zksync_types::fee_model::FeeModelConfig; use crate::{ implementations::resources::{ - eth_interface::EthInterfaceResource, fee_input::FeeInputResource, + eth_interface::EthInterfaceResource, fee_input::FeeInputResource, conversion_rate_fetcher::ConversionRateFetcherResource, l1_tx_params::L1TxParamsResource, }, service::{ServiceContext, StopReceiver}, @@ -48,6 +48,8 @@ impl SequencerL1GasLayer { } } + + #[async_trait::async_trait] impl WiringLayer for SequencerL1GasLayer { fn layer_name(&self) -> &'static str { @@ -61,14 +63,11 @@ impl WiringLayer for SequencerL1GasLayer { L1BatchCommitDataGeneratorMode::Validium => Arc::new(ValidiumPubdataPricing {}), }; let client = context.get_resource::().await?.0; - let adjuster = GasAdjuster::new( - client, - self.gas_adjuster_config, - self.pubdata_sending_mode, - pubdata_pricing, - ) - .await - .context("GasAdjuster::new()")?; + let conversion_fetcher = context.get_resource::().await?.0; + let adjuster = + GasAdjuster::new(client, self.gas_adjuster_config, self.pubdata_sending_mode, conversion_fetcher, pubdata_pricing) + .await + .context("GasAdjuster::new()")?; let gas_adjuster = Arc::new(adjuster); let batch_fee_input_provider = Arc::new(MainNodeFeeInputProvider::new( diff --git a/core/node/node_framework/src/implementations/resources/conversion_rate_fetcher.rs b/core/node/node_framework/src/implementations/resources/conversion_rate_fetcher.rs new file mode 100644 index 00000000000..b9fabb4f8cc --- /dev/null +++ b/core/node/node_framework/src/implementations/resources/conversion_rate_fetcher.rs @@ -0,0 +1,14 @@ +use std::sync::Arc; + +use zksync_core::base_token_fetcher::ConversionRateFetcher; + +use crate::resource::Resource; + +#[derive(Debug, Clone)] +pub struct ConversionRateFetcherResource(pub Arc); + +impl Resource for ConversionRateFetcherResource { + fn name() -> String { + "common/conversion_rate_fetcher".into() + } +} diff --git a/core/node/node_framework/src/implementations/resources/mod.rs b/core/node/node_framework/src/implementations/resources/mod.rs index 2225fcd2f4c..f842b5b015a 100644 --- a/core/node/node_framework/src/implementations/resources/mod.rs +++ b/core/node/node_framework/src/implementations/resources/mod.rs @@ -11,3 +11,4 @@ pub mod pools; pub mod state_keeper; pub mod sync_state; pub mod web3_api; +pub mod conversion_rate_fetcher;