From b054a69d8565e825b5829bc1fe95c77505aaabff Mon Sep 17 00:00:00 2001 From: tomg10 Date: Fri, 13 Sep 2024 16:31:56 +0200 Subject: [PATCH] removed old protocol upgrades processor Signed-off-by: tomg10 --- ...5550_add_eth_watcher_progress_table.up.sql | 2 +- core/lib/dal/src/eth_watcher_dal.rs | 9 +- core/node/eth_watch/src/client.rs | 73 ++------- .../decentralized_upgrades.rs | 142 ------------------ .../eth_watch/src/event_processors/mod.rs | 2 - core/node/eth_watch/src/lib.rs | 9 +- core/node/eth_watch/src/tests.rs | 11 +- .../src/implementations/layers/eth_watch.rs | 3 +- 8 files changed, 19 insertions(+), 232 deletions(-) delete mode 100644 core/node/eth_watch/src/event_processors/decentralized_upgrades.rs diff --git a/core/lib/dal/migrations/20240912085550_add_eth_watcher_progress_table.up.sql b/core/lib/dal/migrations/20240912085550_add_eth_watcher_progress_table.up.sql index f8cdd573c069..91605a017e56 100644 --- a/core/lib/dal/migrations/20240912085550_add_eth_watcher_progress_table.up.sql +++ b/core/lib/dal/migrations/20240912085550_add_eth_watcher_progress_table.up.sql @@ -1,4 +1,4 @@ -CREATE TYPE event_type AS ENUM ('ProtocolUpgrades', 'PriorityTransactions', 'GovernanceUpgrades'); +CREATE TYPE event_type AS ENUM ('PriorityTransactions', 'GovernanceUpgrades'); CREATE TABLE processed_events ( diff --git a/core/lib/dal/src/eth_watcher_dal.rs b/core/lib/dal/src/eth_watcher_dal.rs index 87fc4b778138..ba8ad8bff4d7 100644 --- a/core/lib/dal/src/eth_watcher_dal.rs +++ b/core/lib/dal/src/eth_watcher_dal.rs @@ -10,7 +10,6 @@ pub struct ProcessedEventsDal<'a, 'c> { #[derive(Debug, Copy, Clone, sqlx::Type)] #[sqlx(type_name = "event_type")] pub enum EventType { - ProtocolUpgrades, PriorityTransactions, GovernanceUpgrades, } @@ -108,9 +107,9 @@ mod tests { let mut conn = pool.connection().await.unwrap(); let mut dal = conn.processed_events_dal(); - // Test with ProtocolUpgrades + // Test with GovernanceUpgrades let next_block = dal - .get_or_set_next_block_to_process(EventType::ProtocolUpgrades, SLChainId(1), 100) + .get_or_set_next_block_to_process(EventType::GovernanceUpgrades, SLChainId(1), 100) .await .expect("Failed to get or set next block to process"); assert_eq!(next_block, 100); @@ -129,9 +128,9 @@ mod tests { .expect("Failed to get or set next block to process"); assert_eq!(next_block, 300); - // Verify that the initial block is not updated for ProtocolUpgrades + // Verify that the initial block is not updated for GovernanceUpgrades let next_block = dal - .get_or_set_next_block_to_process(EventType::ProtocolUpgrades, SLChainId(1), 150) + .get_or_set_next_block_to_process(EventType::GovernanceUpgrades, SLChainId(1), 150) .await .expect("Failed to get or set next block to process"); assert_eq!(next_block, 100); diff --git a/core/node/eth_watch/src/client.rs b/core/node/eth_watch/src/client.rs index 5c7262017ec6..d1e559a9fbb5 100644 --- a/core/node/eth_watch/src/client.rs +++ b/core/node/eth_watch/src/client.rs @@ -1,7 +1,6 @@ use std::fmt; -use anyhow::Context; -use zksync_contracts::{getters_contract, state_transition_manager_contract, verifier_contract}; +use zksync_contracts::{getters_contract, verifier_contract}; use zksync_eth_client::{ clients::{DynClient, L1}, CallFunctionArgs, ClientError, ContractCallError, EnrichedClientError, EnrichedClientResult, @@ -21,8 +20,7 @@ pub trait EthClient: 'static + fmt::Debug + Send + Sync { &self, from: BlockNumber, to: BlockNumber, - topic1: H256, - topic2: Option, + topic: H256, retries_left: usize, ) -> EnrichedClientResult>; /// Returns finalized L1 block number. @@ -32,11 +30,6 @@ pub trait EthClient: 'static + fmt::Debug + Send + Sync { /// Returns scheduler verification key hash by verifier address. async fn scheduler_vk_hash(&self, verifier_address: Address) -> Result; - /// Returns upgrade diamond cut by packed protocol version. - async fn diamond_cut_by_version( - &self, - packed_version: H256, - ) -> EnrichedClientResult>>; async fn chain_id(&self) -> EnrichedClientResult; } @@ -52,7 +45,6 @@ pub struct EthHttpQueryClient { client: Box>, diamond_proxy_addr: Address, governance_address: Address, - new_upgrade_cut_data_signature: H256, // Only present for post-shared bridge chains. state_transition_manager_address: Option
, chain_admin_address: Option
, @@ -81,11 +73,6 @@ impl EthHttpQueryClient { state_transition_manager_address, chain_admin_address, governance_address, - new_upgrade_cut_data_signature: state_transition_manager_contract() - .event("NewUpgradeCutData") - .context("NewUpgradeCutData event is missing in ABI") - .unwrap() - .signature(), verifier_contract_abi: verifier_contract(), getters_contract_abi: getters_contract(), confirmations_for_eth_event, @@ -108,16 +95,15 @@ impl EthHttpQueryClient { &self, from: BlockNumber, to: BlockNumber, - topics1: H256, - topic2: Option, - addresses: &Vec
, + topic: H256, + addresses: &[Address], retries_left: usize, ) -> EnrichedClientResult> { let filter = FilterBuilder::default() .from_block(from) .to_block(to) - .topics(Some(vec![topics1]), topic2.map(|x| vec![x]), None, None) - .address(addresses.clone()) + .topics(Some(vec![topic]), None, None, None) + .address(addresses.to_vec()) .build(); let mut result = self.client.logs(&filter).await; @@ -172,25 +158,17 @@ impl EthHttpQueryClient { tracing::warn!("Splitting block range in half: {from:?} - {mid:?} - {to:?}"); let mut first_half = self - .get_events(from, BlockNumber::Number(mid), topics1, topic2, RETRY_LIMIT) + .get_events(from, BlockNumber::Number(mid), topic, RETRY_LIMIT) .await?; let mut second_half = self - .get_events( - BlockNumber::Number(mid + 1u64), - to, - topics1, - topic2, - RETRY_LIMIT, - ) + .get_events(BlockNumber::Number(mid + 1u64), to, topic, RETRY_LIMIT) .await?; first_half.append(&mut second_half); result = Ok(first_half); } else if should_retry(err_code, err_message) && retries_left > 0 { tracing::warn!("Retrying. Retries left: {retries_left}"); - result = self - .get_events(from, to, topics1, topic2, retries_left - 1) - .await; + result = self.get_events(from, to, topic, retries_left - 1).await; } } @@ -211,46 +189,17 @@ impl EthClient for EthHttpQueryClient { .await } - async fn diamond_cut_by_version( - &self, - packed_version: H256, - ) -> EnrichedClientResult>> { - const LOOK_BACK_BLOCK_RANGE: u64 = 1_000_000; - - let Some(state_transition_manager_address) = self.state_transition_manager_address else { - return Ok(None); - }; - - let to_block = self.client.block_number().await?; - let from_block = to_block.saturating_sub((LOOK_BACK_BLOCK_RANGE - 1).into()); - - let logs = self - .get_events_inner( - from_block.into(), - to_block.into(), - self.new_upgrade_cut_data_signature, - Some(packed_version), - &vec![state_transition_manager_address], - RETRY_LIMIT, - ) - .await?; - - Ok(logs.into_iter().next().map(|log| log.data.0)) - } - async fn get_events( &self, from: BlockNumber, to: BlockNumber, - topic1: H256, - topic2: Option, + topic: H256, retries_left: usize, ) -> EnrichedClientResult> { self.get_events_inner( from, to, - topic1, - topic2, + topic, &self.get_default_address_list(), retries_left, ) diff --git a/core/node/eth_watch/src/event_processors/decentralized_upgrades.rs b/core/node/eth_watch/src/event_processors/decentralized_upgrades.rs deleted file mode 100644 index aa43e7239f88..000000000000 --- a/core/node/eth_watch/src/event_processors/decentralized_upgrades.rs +++ /dev/null @@ -1,142 +0,0 @@ -use anyhow::Context as _; -use zksync_dal::{eth_watcher_dal::EventType, Connection, Core, CoreDal, DalError}; -use zksync_types::{ - ethabi::Contract, protocol_version::ProtocolSemanticVersion, web3::Log, ProtocolUpgrade, H256, - U256, -}; - -use crate::{ - client::EthClient, - event_processors::{EventProcessor, EventProcessorError, EventsSource}, - metrics::{PollStage, METRICS}, -}; - -/// Listens to scheduling events coming from the chain admin contract and saves new protocol upgrade proposals to the database. -#[derive(Debug)] -pub struct DecentralizedUpgradesEventProcessor { - /// Last protocol version seen. Used to skip events for already known upgrade proposals. - last_seen_protocol_version: ProtocolSemanticVersion, - update_upgrade_timestamp_signature: H256, -} - -impl DecentralizedUpgradesEventProcessor { - pub fn new( - last_seen_protocol_version: ProtocolSemanticVersion, - chain_admin_contract: &Contract, - ) -> Self { - Self { - last_seen_protocol_version, - update_upgrade_timestamp_signature: chain_admin_contract - .event("UpdateUpgradeTimestamp") - .context("UpdateUpgradeTimestamp event is missing in ABI") - .unwrap() - .signature(), - } - } -} - -#[async_trait::async_trait] -impl EventProcessor for DecentralizedUpgradesEventProcessor { - async fn process_events( - &mut self, - storage: &mut Connection<'_, Core>, - sl_client: &dyn EthClient, - events: Vec, - ) -> Result { - let mut upgrades = Vec::new(); - for event in &events { - let version = event.topics.get(1).copied().context("missing topic 1")?; - let timestamp: u64 = U256::from_big_endian(&event.data.0) - .try_into() - .ok() - .context("upgrade timestamp is too big")?; - - let diamond_cut = sl_client - .diamond_cut_by_version(version) - .await? - .context("missing upgrade data on STM")?; - - let upgrade = ProtocolUpgrade { - timestamp, - ..ProtocolUpgrade::try_from_diamond_cut(&diamond_cut)? - }; - // Scheduler VK is not present in proposal event. It is hard coded in verifier contract. - let scheduler_vk_hash = if let Some(address) = upgrade.verifier_address { - Some(sl_client.scheduler_vk_hash(address).await?) - } else { - None - }; - upgrades.push((upgrade, scheduler_vk_hash)); - } - - let new_upgrades: Vec<_> = upgrades - .into_iter() - .skip_while(|(v, _)| v.version <= self.last_seen_protocol_version) - .collect(); - - let Some((last_upgrade, _)) = new_upgrades.last() else { - return Ok(events.len()); - }; - let versions: Vec<_> = new_upgrades - .iter() - .map(|(u, _)| u.version.to_string()) - .collect(); - tracing::debug!("Received upgrades with versions: {versions:?}"); - - let last_version = last_upgrade.version; - let stage_latency = METRICS.poll_eth_node[&PollStage::PersistUpgrades].start(); - for (upgrade, scheduler_vk_hash) in new_upgrades { - let latest_semantic_version = storage - .protocol_versions_dal() - .latest_semantic_version() - .await - .map_err(DalError::generalize)? - .context("expected some version to be present in DB")?; - - if upgrade.version > latest_semantic_version { - let latest_version = storage - .protocol_versions_dal() - .get_protocol_version_with_latest_patch(latest_semantic_version.minor) - .await - .map_err(DalError::generalize)? - .with_context(|| { - format!( - "expected minor version {} to be present in DB", - latest_semantic_version.minor as u16 - ) - })?; - - let new_version = latest_version.apply_upgrade(upgrade, scheduler_vk_hash); - if new_version.version.minor == latest_semantic_version.minor { - // Only verification parameters may change if only patch is bumped. - assert_eq!( - new_version.base_system_contracts_hashes, - latest_version.base_system_contracts_hashes - ); - assert!(new_version.tx.is_none()); - } - storage - .protocol_versions_dal() - .save_protocol_version_with_tx(&new_version) - .await - .map_err(DalError::generalize)?; - } - } - stage_latency.observe(); - - self.last_seen_protocol_version = last_version; - Ok(events.len()) - } - - fn relevant_topic(&self) -> H256 { - self.update_upgrade_timestamp_signature - } - - fn event_source(&self) -> EventsSource { - EventsSource::SL - } - - fn event_type(&self) -> EventType { - EventType::ProtocolUpgrades - } -} diff --git a/core/node/eth_watch/src/event_processors/mod.rs b/core/node/eth_watch/src/event_processors/mod.rs index 5ded825cce4a..7a81e79d0f35 100644 --- a/core/node/eth_watch/src/event_processors/mod.rs +++ b/core/node/eth_watch/src/event_processors/mod.rs @@ -5,12 +5,10 @@ use zksync_eth_client::{ContractCallError, EnrichedClientError}; use zksync_types::{web3::Log, H256}; pub(crate) use self::{ - decentralized_upgrades::DecentralizedUpgradesEventProcessor, governance_upgrades::GovernanceUpgradesEventProcessor, priority_ops::PriorityOpsEventProcessor, }; use crate::client::EthClient; -mod decentralized_upgrades; mod governance_upgrades; pub mod priority_ops; diff --git a/core/node/eth_watch/src/lib.rs b/core/node/eth_watch/src/lib.rs index 3d283f250326..392a164e47be 100644 --- a/core/node/eth_watch/src/lib.rs +++ b/core/node/eth_watch/src/lib.rs @@ -22,7 +22,7 @@ use self::{ }, metrics::METRICS, }; -use crate::event_processors::{DecentralizedUpgradesEventProcessor, EventsSource}; +use crate::event_processors::EventsSource; mod client; mod event_processors; @@ -51,7 +51,6 @@ impl EthWatch { pub async fn new( sl_diamond_proxy_addr: Address, governance_contract: &Contract, - chain_admin_contract: &Contract, l1_client: Box, sl_client: Box, pool: ConnectionPool, @@ -69,14 +68,9 @@ impl EthWatch { state.last_seen_protocol_version, governance_contract, ); - let decentralized_upgrades_processor = DecentralizedUpgradesEventProcessor::new( - state.last_seen_protocol_version, - chain_admin_contract, - ); let event_processors: Vec> = vec![ Box::new(priority_ops_processor), Box::new(governance_upgrades_processor), - Box::new(decentralized_upgrades_processor), ]; Ok(Self { @@ -166,7 +160,6 @@ impl EthWatch { Web3BlockNumber::Number(from_block.into()), Web3BlockNumber::Number(finalized_block.into()), processor.relevant_topic(), - None, RETRY_LIMIT, ) .await?; diff --git a/core/node/eth_watch/src/tests.rs b/core/node/eth_watch/src/tests.rs index 8ac30c0f0ded..4d3202ad345d 100644 --- a/core/node/eth_watch/src/tests.rs +++ b/core/node/eth_watch/src/tests.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, convert::TryInto, sync::Arc}; use tokio::sync::RwLock; -use zksync_contracts::{chain_admin_contract, governance_contract, hyperchain_contract}; +use zksync_contracts::{governance_contract, hyperchain_contract}; use zksync_dal::{Connection, ConnectionPool, Core, CoreDal}; use zksync_eth_client::{ContractCallError, EnrichedClientResult}; use zksync_types::{ @@ -154,13 +154,6 @@ impl EthClient for MockEthClient { Ok(self.inner.read().await.last_finalized_block_number) } - async fn diamond_cut_by_version( - &self, - _packed_version: H256, - ) -> EnrichedClientResult>> { - unimplemented!() - } - async fn get_total_priority_txs(&self) -> Result { Ok(self .inner @@ -246,7 +239,6 @@ async fn create_test_watcher( let watcher = EthWatch::new( Address::default(), &governance_contract(), - &chain_admin_contract(), Box::new(l1_client.clone()), Box::new(sl_client.clone()), connection_pool, @@ -353,7 +345,6 @@ async fn test_normal_operation_governance_upgrades() { let mut watcher = EthWatch::new( Address::default(), &governance_contract(), - &chain_admin_contract(), Box::new(client.clone()), Box::new(client.clone()), connection_pool.clone(), diff --git a/core/node/node_framework/src/implementations/layers/eth_watch.rs b/core/node/node_framework/src/implementations/layers/eth_watch.rs index 15798ffebacf..4fb1b1e5f968 100644 --- a/core/node/node_framework/src/implementations/layers/eth_watch.rs +++ b/core/node/node_framework/src/implementations/layers/eth_watch.rs @@ -1,5 +1,5 @@ use zksync_config::{ContractsConfig, EthWatchConfig}; -use zksync_contracts::{chain_admin_contract, governance_contract}; +use zksync_contracts::governance_contract; use zksync_eth_watch::{EthHttpQueryClient, EthWatch}; use crate::{ @@ -73,7 +73,6 @@ impl WiringLayer for EthWatchLayer { let eth_watch = EthWatch::new( self.contracts_config.diamond_proxy_addr, &governance_contract(), - &chain_admin_contract(), Box::new(eth_client.clone()), Box::new(eth_client), main_pool,