Skip to content

Commit

Permalink
Remove some dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc committed Mar 3, 2022
1 parent 8a06713 commit 999f1a3
Show file tree
Hide file tree
Showing 21 changed files with 83 additions and 257 deletions.
5 changes: 1 addition & 4 deletions core/bin/zksync_core/src/state_keeper/init_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,7 @@ impl ZkSyncStateInitParams {
.await
.expect("Unable to load committed NFT tokens")
.into_iter()
.map(|nft| {
let token: NFT = nft.into();
(token.id, token)
})
.map(|nft| (nft.id, nft))
.collect()
}

Expand Down
1 change: 0 additions & 1 deletion core/bin/zksync_prometheus_exporter/src/main.rs

This file was deleted.

23 changes: 13 additions & 10 deletions core/lib/storage/src/chain/account/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use sqlx::{types::BigDecimal, FromRow};
use zksync_types::{AccountId, Address, PubKeyHash, TokenId, H256, NFT};

#[derive(Debug, FromRow)]
pub struct StorageAccount {
pub(crate) struct StorageAccount {
pub id: i64,
pub last_block: i64,
pub nonce: i64,
Expand All @@ -14,7 +14,7 @@ pub struct StorageAccount {
}

#[derive(Debug, FromRow)]
pub struct StorageAccountCreation {
pub(crate) struct StorageAccountCreation {
pub account_id: i64,
pub is_create: bool,
pub block_number: i64,
Expand All @@ -24,7 +24,8 @@ pub struct StorageAccountCreation {
}

#[derive(Debug, FromRow)]
pub struct StorageAccountUpdate {
pub(crate) struct StorageAccountUpdate {
#[allow(dead_code)]
pub balance_update_id: i32,
pub account_id: i64,
pub block_number: i64,
Expand All @@ -37,7 +38,7 @@ pub struct StorageAccountUpdate {
}

#[derive(Debug, FromRow)]
pub struct StorageMintNFTUpdate {
pub(crate) struct StorageMintNFTUpdate {
pub token_id: i32,
pub serial_id: i32,
pub creator_account_id: i32,
Expand Down Expand Up @@ -65,7 +66,8 @@ impl From<StorageMintNFTUpdate> for NFT {
}

#[derive(Debug, FromRow)]
pub struct StorageAccountPubkeyUpdate {
pub(crate) struct StorageAccountPubkeyUpdate {
#[allow(dead_code)]
pub pubkey_update_id: i32,
pub update_order_id: i32,
pub account_id: i64,
Expand All @@ -77,21 +79,22 @@ pub struct StorageAccountPubkeyUpdate {
}

#[derive(Debug, FromRow, Clone)]
pub struct StorageBalance {
pub(crate) struct StorageBalance {
pub account_id: i64,
pub coin_id: i32,
pub balance: BigDecimal,
}

#[derive(Debug, Clone, Copy, sqlx::Type)]
#[sqlx(type_name = "eth_account_type")]
pub enum DbAccountType {
pub(crate) enum DbAccountType {
Owned,
CREATE2,
No2FA,
}

pub struct StorageAccountType {
pub(crate) struct StorageAccountType {
#[allow(dead_code)]
pub account_id: i64,
pub account_type: DbAccountType,
}
Expand All @@ -114,15 +117,15 @@ impl From<EthAccountType> for ApiEthAccountType {
}

impl EthAccountType {
pub fn from_db(account_type: DbAccountType, pub_key_hash: Option<PubKeyHash>) -> Self {
pub(crate) fn from_db(account_type: DbAccountType, pub_key_hash: Option<PubKeyHash>) -> Self {
match account_type {
DbAccountType::Owned => EthAccountType::Owned,
DbAccountType::CREATE2 => EthAccountType::CREATE2,
DbAccountType::No2FA => EthAccountType::No2FA(pub_key_hash),
}
}

pub fn into_db_types(self) -> (DbAccountType, Option<PubKeyHash>) {
pub(crate) fn into_db_types(self) -> (DbAccountType, Option<PubKeyHash>) {
match self {
EthAccountType::Owned => (DbAccountType::Owned, None),
EthAccountType::CREATE2 => (DbAccountType::CREATE2, None),
Expand Down
2 changes: 1 addition & 1 deletion core/lib/storage/src/chain/account/restore_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use zksync_types::{Account, AccountId, Address, Nonce, PubKeyHash, TokenId};
// Local imports
use super::records::*;

pub fn restore_account(
pub(crate) fn restore_account(
stored_account: &StorageAccount,
stored_balances: Vec<StorageBalance>,
) -> (AccountId, Account) {
Expand Down
48 changes: 12 additions & 36 deletions core/lib/storage/src/chain/block/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,24 @@ use zksync_types::{
aggregated_operations::AggregatedOperation,
block::{ExecutedPriorityOp, ExecutedTx},
tx::TxHash,
Action, ActionType, BlockNumber, Operation, PriorityOp, SignedZkSyncTx, ZkSyncOp, ZkSyncTx,
H256,
BlockNumber, PriorityOp, SignedZkSyncTx, ZkSyncOp, ZkSyncTx, H256,
};
// Local imports
use crate::chain::operations::records::StoredAggregatedOperation;
use crate::utils::affected_accounts;
use crate::{
chain::{
block::{records::TransactionItem, BlockSchema},
block::records::TransactionItem,
operations::records::{
NewExecutedPriorityOperation, NewExecutedTransaction, StoredExecutedPriorityOperation,
StoredExecutedTransaction, StoredOperation,
StoredExecutedTransaction,
},
},
prover::ProverSchema,
QueryResult, StorageActionType, StorageProcessor,
QueryResult, StorageProcessor,
};

impl StoredOperation {
pub async fn into_op(self, conn: &mut StorageProcessor<'_>) -> QueryResult<Operation> {
let block_number = BlockNumber(self.block_number as u32);
let id = Some(self.id);

let action = if self.action_type == StorageActionType::from(ActionType::COMMIT) {
Action::Commit
} else if self.action_type == StorageActionType::from(ActionType::VERIFY) {
let proof = Box::new(ProverSchema(conn).load_proof(block_number).await?);
Action::Verify {
proof: proof.expect("No proof for verify action").into(),
}
} else {
unreachable!("Incorrect action type in db");
};

let block = BlockSchema(conn)
.get_block(block_number)
.await?
.expect("Block for action does not exist");

Ok(Operation { id, action, block })
}
}

impl StoredExecutedTransaction {
pub fn into_executed_tx(self) -> ExecutedTx {
pub(crate) fn into_executed_tx(self) -> ExecutedTx {
let tx: ZkSyncTx = serde_json::from_value(self.tx).expect("Unparsable ZkSyncTx in db");
let franklin_op: Option<ZkSyncOp> =
serde_json::from_value(self.operation).expect("Unparsable ZkSyncOp in db");
Expand Down Expand Up @@ -105,7 +78,7 @@ impl StoredExecutedPriorityOperation {
}

impl NewExecutedPriorityOperation {
pub fn prepare_stored_priority_op(
pub(crate) fn prepare_stored_priority_op(
exec_prior_op: ExecutedPriorityOp,
block: BlockNumber,
) -> Self {
Expand Down Expand Up @@ -156,7 +129,7 @@ impl NewExecutedPriorityOperation {
}

impl NewExecutedTransaction {
pub async fn prepare_stored_tx(
pub(crate) async fn prepare_stored_tx(
exec_tx: ExecutedTx,
block: BlockNumber,
storage: &mut StorageProcessor<'_>,
Expand Down Expand Up @@ -244,7 +217,7 @@ impl NewExecutedTransaction {
}

impl StoredAggregatedOperation {
pub fn into_aggregated_op(self) -> (i64, AggregatedOperation) {
pub(crate) fn into_aggregated_op(self) -> (i64, AggregatedOperation) {
(
self.id,
serde_json::from_value(self.arguments)
Expand All @@ -254,7 +227,10 @@ impl StoredAggregatedOperation {
}

impl TransactionItem {
pub fn transaction_from_item(item: TransactionItem, is_block_finalized: bool) -> Transaction {
pub(crate) fn transaction_from_item(
item: TransactionItem,
is_block_finalized: bool,
) -> Transaction {
let tx_hash = TxHash::from_slice(&item.tx_hash).unwrap();
let block_number = Some(BlockNumber(item.block_number as u32));
let status = if item.success {
Expand Down
11 changes: 6 additions & 5 deletions core/lib/storage/src/chain/block/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct StorageBlock {
}

#[derive(Debug, FromRow)]
pub struct StorageIncompleteBlock {
pub(crate) struct StorageIncompleteBlock {
pub number: i64,
pub fee_account_id: i64,
pub unprocessed_prior_op_before: i64,
Expand All @@ -35,12 +35,12 @@ pub struct StorageIncompleteBlock {
}

#[derive(Debug, FromRow)]
pub struct StorageRootHash {
pub(crate) struct StorageRootHash {
pub root_hash: Vec<u8>,
}

#[derive(Debug, FromRow)]
pub struct StoragePendingBlock {
pub(crate) struct StoragePendingBlock {
pub number: i64,
pub chunks_left: i64,
pub unprocessed_priority_op_before: i64,
Expand Down Expand Up @@ -87,7 +87,7 @@ pub struct BlockTransactionItem {
}

#[derive(Debug, Serialize, Deserialize, FromRow, PartialEq)]
pub struct TransactionItem {
pub(crate) struct TransactionItem {
// Number from a sequence consisting of priority operations and transactions
pub sequence_number: Option<i64>,
pub tx_hash: Vec<u8>,
Expand Down Expand Up @@ -133,7 +133,8 @@ impl From<StorageBlockDetails> for BlockDetails {
}

#[derive(Debug, FromRow)]
pub struct StorageBlockMetadata {
pub(crate) struct StorageBlockMetadata {
#[allow(dead_code)]
pub block_number: i64,
pub fast_processing: bool,
}
2 changes: 1 addition & 1 deletion core/lib/storage/src/chain/mempool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl<'a, 'c> MempoolSchema<'a, 'c> {
}

/// Returns mempool transaction as it is stored in the database.
pub async fn get_mempool_tx(&mut self, tx_hash: &[u8]) -> QueryResult<Option<MempoolTx>> {
async fn get_mempool_tx(&mut self, tx_hash: &[u8]) -> QueryResult<Option<MempoolTx>> {
let start = Instant::now();

let tx_hash = hex::encode(tx_hash);
Expand Down
14 changes: 10 additions & 4 deletions core/lib/storage/src/chain/mempool/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use zksync_types::{PriorityOp, SignedZkSyncTx, H256};
// Local imports

#[derive(Debug, FromRow)]
pub struct RevertedBlock {
pub(crate) struct RevertedBlock {
pub number: i64,
// These values should not change after re-applying the reverted block.
pub unprocessed_priority_op_before: i64,
Expand All @@ -20,14 +20,17 @@ pub struct RevertedBlock {
}

#[derive(Debug, FromRow)]
pub struct MempoolTx {
pub(crate) struct MempoolTx {
#[allow(dead_code)]
pub id: i64,
#[allow(dead_code)]
pub tx_hash: String,
pub tx: serde_json::Value,
pub created_at: DateTime<Utc>,
pub eth_sign_data: Option<serde_json::Value>,
pub batch_id: i64,
pub next_priority_op_serial_id: Option<i64>,
#[allow(dead_code)]
pub reverted: bool,
}

Expand All @@ -47,16 +50,19 @@ impl TryFrom<MempoolTx> for SignedZkSyncTx {
}

#[derive(Debug, FromRow, PartialEq)]
pub struct QueuedBatchTx {
pub(crate) struct QueuedBatchTx {
pub tx_hash: String,
pub created_at: DateTime<Utc>,
}

#[derive(Debug, FromRow)]
pub struct MempoolPriorityOp {
pub(crate) struct MempoolPriorityOp {
pub serial_id: i64,
#[allow(dead_code)]
pub tx_hash: String,
pub eth_hash: Vec<u8>,
pub data: serde_json::Value,
#[allow(dead_code)]
pub created_at: DateTime<Utc>,
pub eth_block: i64,
pub eth_block_index: Option<i32>,
Expand Down
2 changes: 1 addition & 1 deletion core/lib/storage/src/chain/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'a, 'c> OperationsSchema<'a, 'c> {
}

/// Retrieves transaction from the database given its hash.
pub async fn get_executed_operation(
pub(crate) async fn get_executed_operation(
&mut self,
op_hash: &[u8],
) -> QueryResult<Option<StoredExecutedTransaction>> {
Expand Down
Loading

0 comments on commit 999f1a3

Please sign in to comment.