Skip to content

Commit

Permalink
removed old protocol upgrades processor
Browse files Browse the repository at this point in the history
Signed-off-by: tomg10 <[email protected]>
  • Loading branch information
tomg10 committed Sep 13, 2024
1 parent 8cec8ed commit b054a69
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 232 deletions.
Original file line number Diff line number Diff line change
@@ -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
(
Expand Down
9 changes: 4 additions & 5 deletions core/lib/dal/src/eth_watcher_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
73 changes: 11 additions & 62 deletions core/node/eth_watch/src/client.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -21,8 +20,7 @@ pub trait EthClient: 'static + fmt::Debug + Send + Sync {
&self,
from: BlockNumber,
to: BlockNumber,
topic1: H256,
topic2: Option<H256>,
topic: H256,
retries_left: usize,
) -> EnrichedClientResult<Vec<Log>>;
/// Returns finalized L1 block number.
Expand All @@ -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<H256, ContractCallError>;
/// Returns upgrade diamond cut by packed protocol version.
async fn diamond_cut_by_version(
&self,
packed_version: H256,
) -> EnrichedClientResult<Option<Vec<u8>>>;

async fn chain_id(&self) -> EnrichedClientResult<SLChainId>;
}
Expand All @@ -52,7 +45,6 @@ pub struct EthHttpQueryClient {
client: Box<DynClient<L1>>,
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<Address>,
chain_admin_address: Option<Address>,
Expand Down Expand Up @@ -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,
Expand All @@ -108,16 +95,15 @@ impl EthHttpQueryClient {
&self,
from: BlockNumber,
to: BlockNumber,
topics1: H256,
topic2: Option<H256>,
addresses: &Vec<Address>,
topic: H256,
addresses: &[Address],
retries_left: usize,
) -> EnrichedClientResult<Vec<Log>> {
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;

Expand Down Expand Up @@ -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;
}
}

Expand All @@ -211,46 +189,17 @@ impl EthClient for EthHttpQueryClient {
.await
}

async fn diamond_cut_by_version(
&self,
packed_version: H256,
) -> EnrichedClientResult<Option<Vec<u8>>> {
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<H256>,
topic: H256,
retries_left: usize,
) -> EnrichedClientResult<Vec<Log>> {
self.get_events_inner(
from,
to,
topic1,
topic2,
topic,
&self.get_default_address_list(),
retries_left,
)
Expand Down
142 changes: 0 additions & 142 deletions core/node/eth_watch/src/event_processors/decentralized_upgrades.rs

This file was deleted.

2 changes: 0 additions & 2 deletions core/node/eth_watch/src/event_processors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 1 addition & 8 deletions core/node/eth_watch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use self::{
},
metrics::METRICS,
};
use crate::event_processors::{DecentralizedUpgradesEventProcessor, EventsSource};
use crate::event_processors::EventsSource;

mod client;
mod event_processors;
Expand Down Expand Up @@ -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<dyn EthClient>,
sl_client: Box<dyn EthClient>,
pool: ConnectionPool<Core>,
Expand All @@ -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<Box<dyn EventProcessor>> = vec![
Box::new(priority_ops_processor),
Box::new(governance_upgrades_processor),
Box::new(decentralized_upgrades_processor),
];

Ok(Self {
Expand Down Expand Up @@ -166,7 +160,6 @@ impl EthWatch {
Web3BlockNumber::Number(from_block.into()),
Web3BlockNumber::Number(finalized_block.into()),
processor.relevant_topic(),
None,
RETRY_LIMIT,
)
.await?;
Expand Down
Loading

0 comments on commit b054a69

Please sign in to comment.