diff --git a/Cargo.lock b/Cargo.lock index 082abf63b5..e09908ba9e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2187,18 +2187,6 @@ dependencies = [ "ahash 0.4.7", ] -[[package]] -name = "hashes_migration" -version = "1.0.0" -dependencies = [ - "anyhow", - "async-trait", - "tokio 0.2.22", - "vlog", - "zksync_storage", - "zksync_types", -] - [[package]] name = "hashlink" version = "0.6.0" @@ -4090,27 +4078,6 @@ version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" -[[package]] -name = "regen-root-hash" -version = "1.0.0" -dependencies = [ - "anyhow", - "bigdecimal", - "ethabi", - "hex", - "num", - "once_cell", - "serde", - "serde_json", - "structopt", - "tokio 0.2.22", - "zksync_circuit", - "zksync_crypto", - "zksync_storage", - "zksync_types", - "zksync_utils", -] - [[package]] name = "regex" version = "1.4.1" diff --git a/core/bin/zksync_core/src/lib.rs b/core/bin/zksync_core/src/lib.rs index 63c9f3d589..fb41118aa8 100644 --- a/core/bin/zksync_core/src/lib.rs +++ b/core/bin/zksync_core/src/lib.rs @@ -135,7 +135,6 @@ pub async fn run_core( config.chain.state_keeper.block_chunk_sizes.clone(), config.chain.state_keeper.miniblock_iterations as usize, config.chain.state_keeper.fast_block_miniblock_iterations as usize, - config.chain.state_keeper.last_tx_signer_data(), ); let state_keeper_task = start_state_keeper(state_keeper, pending_block); diff --git a/core/bin/zksync_core/src/state_keeper/mod.rs b/core/bin/zksync_core/src/state_keeper/mod.rs index a7a0d31142..e45241cad2 100644 --- a/core/bin/zksync_core/src/state_keeper/mod.rs +++ b/core/bin/zksync_core/src/state_keeper/mod.rs @@ -10,13 +10,8 @@ use itertools::Itertools; use tokio::task::JoinHandle; // Workspace uses use zksync_crypto::{ - convert::FeConvert, ff::{self, PrimeField, PrimeFieldRepr}, - params::{ - ETH_TOKEN_ID, MIN_NFT_TOKEN_ID, NFT_STORAGE_ACCOUNT_ADDRESS, NFT_STORAGE_ACCOUNT_ID, - NFT_TOKEN_ID, - }, - PrivateKey, + params::{MIN_NFT_TOKEN_ID, NFT_STORAGE_ACCOUNT_ADDRESS, NFT_STORAGE_ACCOUNT_ID, NFT_TOKEN_ID}, }; use zksync_state::state::{CollectedFee, OpSuccess, ZkSyncState}; use zksync_storage::ConnectionPool; @@ -26,11 +21,10 @@ use zksync_types::{ PendingBlock as SendablePendingBlock, }, gas_counter::GasCounter, - helpers::reverse_updates, mempool::SignedTxVariant, tx::{TxHash, ZkSyncTx}, Account, AccountId, AccountTree, AccountUpdate, AccountUpdates, Address, BlockNumber, - PriorityOp, SignedZkSyncTx, Token, TokenId, Transfer, TransferOp, H256, NFT, + PriorityOp, SignedZkSyncTx, Token, TokenId, H256, NFT, }; // Local uses use crate::{ @@ -82,16 +76,12 @@ impl PendingBlock { available_chunks_sizes: &[usize], previous_block_root_hash: H256, timestamp: u64, - should_include_last_transfer: bool, ) -> Self { // TransferOp chunks are subtracted to reserve space for last transfer. - let mut chunks_left = *available_chunks_sizes + let chunks_left = *available_chunks_sizes .iter() .max() .expect("Expected at least one block chunks size"); - if should_include_last_transfer { - chunks_left -= TransferOp::CHUNKS; - } Self { success_operations: Vec::new(), failed_txs: Vec::new(), @@ -140,9 +130,6 @@ pub struct ZkSyncStateKeeper { success_txs_pending_len: usize, /// Amount of failed transactions in the pending block at the last pending block synchronization step. failed_txs_pending_len: usize, - - /// ZK sync account that is used to create last transfer before sealing block (e.g. to change block hash) - tx_signer: Option<(Address, PrivateKey)>, } #[derive(Debug, Clone)] @@ -413,7 +400,6 @@ impl ZkSyncStateKeeper { available_block_chunk_sizes: Vec, max_miniblock_iterations: usize, fast_miniblock_iterations: usize, - tx_signer: Option<(Address, PrivateKey)>, ) -> Self { assert!(!available_block_chunk_sizes.is_empty()); @@ -453,7 +439,6 @@ impl ZkSyncStateKeeper { &available_block_chunk_sizes, previous_root_hash, system_time_timestamp(), - tx_signer.is_some(), ), available_block_chunk_sizes, max_miniblock_iterations, @@ -461,7 +446,6 @@ impl ZkSyncStateKeeper { success_txs_pending_len: 0, failed_txs_pending_len: 0, - tx_signer, }; let root = keeper.state.root_hash(); @@ -1053,10 +1037,6 @@ impl ZkSyncStateKeeper { .account_updates .extend(fee_updates.into_iter()); - // This last tx does not pay any fee - if let Err(e) = self.execute_transfer_to_change_block_hash() { - vlog::error!("Failed to execute transfer to change block hash: {}", e); - } let mut pending_block = std::mem::replace( &mut self.pending_block, PendingBlock::new( @@ -1064,7 +1044,6 @@ impl ZkSyncStateKeeper { &self.available_block_chunk_sizes, H256::default(), system_time_timestamp(), - self.tx_signer.is_some(), ), ); // Once block is sealed, we refresh the counters for the next block. @@ -1203,102 +1182,7 @@ impl ZkSyncStateKeeper { unprocessed_priority_op: self.current_unprocessed_priority_op, } } - - /// Should be applied after fee is collected when block is being sealed. - fn execute_transfer_to_change_block_hash(&mut self) -> anyhow::Result<()> { - let (signer_id, signer_account, signer_pk) = { - let (address, pk) = if let Some((address, pk)) = self.tx_signer.as_ref() { - (address, pk) - } else { - return Ok(()); - }; - let (id, account) = self.state.get_account_by_address(&address).ok_or_else(|| { - anyhow::format_err!("Signer account is not in the tree: {:?}", address) - })?; - (id, account, pk) - }; - let (target_id, target_account) = { - ( - self.fee_account_id, - self.state - .get_account(self.fee_account_id) - .expect("Fee account must be present in the tree"), - ) - }; - - let mut tx_value = 0u32; - let mut first_byte = self.state.root_hash().to_bytes()[0]; - while first_byte > 0x1F { - tx_value += 1; - anyhow::ensure!( - signer_account.get_balance(ETH_TOKEN_ID) > tx_value.into(), - "Not enough balance on signer account" - ); - - let expected_updates = vec![ - ( - signer_id, - AccountUpdate::UpdateBalance { - old_nonce: signer_account.nonce, - new_nonce: signer_account.nonce + 1, - balance_update: ( - ETH_TOKEN_ID, - signer_account.get_balance(ETH_TOKEN_ID), - signer_account.get_balance(ETH_TOKEN_ID) - tx_value, - ), - }, - ), - ( - target_id, - AccountUpdate::UpdateBalance { - old_nonce: target_account.nonce, - new_nonce: target_account.nonce, - balance_update: ( - ETH_TOKEN_ID, - target_account.get_balance(ETH_TOKEN_ID), - target_account.get_balance(ETH_TOKEN_ID) + tx_value, - ), - }, - ), - ]; - self.state.apply_account_updates(expected_updates.clone()); - - first_byte = self.state.root_hash().to_bytes()[0]; - - let reverse_updates = { - let mut rev_updates = expected_updates; - reverse_updates(&mut rev_updates); - rev_updates - }; - self.state.apply_account_updates(reverse_updates); - } - - if tx_value == 0 { - return Ok(()); - } - - let transfer = Transfer::new_signed( - signer_id, - signer_account.address, - target_account.address, - ETH_TOKEN_ID, - tx_value.into(), - 0u32.into(), - signer_account.nonce, - Default::default(), - &signer_pk, - )?; - - self.apply_tx(&SignedZkSyncTx { - tx: transfer.into(), - eth_sign_data: None, - }) - .map_err(|_| anyhow::format_err!("Transaction execution failed"))?; - - Ok(()) - } } - #[must_use] pub fn start_state_keeper( sk: ZkSyncStateKeeper, diff --git a/core/bin/zksync_core/src/state_keeper/tests.rs b/core/bin/zksync_core/src/state_keeper/tests.rs index 7c3fc6fb6e..6b925ea50d 100644 --- a/core/bin/zksync_core/src/state_keeper/tests.rs +++ b/core/bin/zksync_core/src/state_keeper/tests.rs @@ -37,7 +37,6 @@ impl StateKeeperTester { vec![available_chunk_size], max_iterations, fast_iterations, - None, ); Self { @@ -254,7 +253,6 @@ fn test_create_incorrect_state_keeper() { vec![1, 2, 2], // `available_block_chunk_sizes` must be strictly increasing. MAX_ITERATIONS, FAST_ITERATIONS, - None, ); } diff --git a/core/lib/config/src/configs/chain.rs b/core/lib/config/src/configs/chain.rs index e677d0c55e..c05e030c18 100644 --- a/core/lib/config/src/configs/chain.rs +++ b/core/lib/config/src/configs/chain.rs @@ -3,7 +3,6 @@ use serde::Deserialize; /// Built-in uses use std::time::Duration; // Local uses -use zksync_crypto::{convert::FeConvert, priv_key_from_fs, Fs, PrivateKey}; use zksync_types::network::Network; use zksync_types::Address; @@ -89,9 +88,6 @@ pub struct StateKeeper { pub block_prove_deadline: u64, pub block_execute_deadline: u64, pub max_aggregated_tx_gas: usize, - pub last_tx_signer_used: bool, - pub last_tx_signer_address: Address, - pub last_tx_signer_private_key: String, } impl StateKeeper { @@ -111,17 +107,6 @@ impl StateKeeper { pub fn block_execute_deadline(&self) -> Duration { Duration::from_secs(self.block_execute_deadline) } - - pub fn last_tx_signer_data(&self) -> Option<(Address, PrivateKey)> { - if self.last_tx_signer_used { - let fs = Fs::from_hex(&self.last_tx_signer_private_key) - .expect("failed to parse private key"); - let pk = priv_key_from_fs(fs); - Some((self.last_tx_signer_address, pk)) - } else { - None - } - } } #[cfg(test)] @@ -156,9 +141,6 @@ mod tests { block_prove_deadline: 3_000, block_execute_deadline: 4_000, max_aggregated_tx_gas: 4_000_000, - last_tx_signer_used: false, - last_tx_signer_private_key: "0xaabbeecc".into(), - last_tx_signer_address: addr("da03a0b5963f75f1c8485b355ff6d30f3093bde7"), }, } } @@ -187,9 +169,6 @@ CHAIN_STATE_KEEPER_BLOCK_COMMIT_DEADLINE="300" CHAIN_STATE_KEEPER_BLOCK_PROVE_DEADLINE="3000" CHAIN_STATE_KEEPER_BLOCK_EXECUTE_DEADLINE="4000" CHAIN_STATE_KEEPER_MAX_AGGREGATED_TX_GAS="4000000" -CHAIN_STATE_KEEPER_LAST_TX_SIGNER_USED="false" -CHAIN_STATE_KEEPER_LAST_TX_SIGNER_ADDRESS="0xda03a0b5963f75f1c8485b355ff6d30f3093bde7" -CHAIN_STATE_KEEPER_LAST_TX_SIGNER_PRIVATE_KEY="0xaabbeecc" "#; set_env(config); diff --git a/core/tests/testkit/src/state_keeper_utils.rs b/core/tests/testkit/src/state_keeper_utils.rs index 66baafa980..62c6177409 100644 --- a/core/tests/testkit/src/state_keeper_utils.rs +++ b/core/tests/testkit/src/state_keeper_utils.rs @@ -63,7 +63,6 @@ pub fn spawn_state_keeper( block_chunks_sizes, max_miniblock_iterations, max_miniblock_iterations, - None, ); let (stop_state_keeper_sender, stop_state_keeper_receiver) = oneshot::channel::<()>();