Skip to content

Commit

Permalink
Use single ethereum-types package and cleanup imports_granularity (#2417
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Jouzo authored Sep 6, 2023
1 parent 433267c commit e3c6eaa
Show file tree
Hide file tree
Showing 58 changed files with 258 additions and 267 deletions.
1 change: 1 addition & 0 deletions lib/.rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
unstable_features = true
group_imports = "StdExternalCrate"
imports_granularity = "Crate"
8 changes: 3 additions & 5 deletions lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ jsonrpsee-types = "0.16"
ethereum = "0.14"
ethereum-types = "0.14"
keccak-hash = "0.10"
primitive-types = { version = "0.12", default-features = false, features = ["serde"] }
rlp = "0.5"
ethabi = "18.0.0"

Expand Down
2 changes: 1 addition & 1 deletion lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ clippy:
# cause conflicts across toolchains
.PHONY: fmt-check
fmt-check:
$(CARGO) fmt $(CARGO_MANIFEST_ARG) --all --check 2> >(grep -v -E 'group_imports|unstable_features')
$(CARGO) fmt $(CARGO_MANIFEST_ARG) --all --check 2> >(grep -v -E 'group_imports|unstable_features|imports_granularity')

.PHONY: fmt
fmt:
Expand Down
2 changes: 1 addition & 1 deletion lib/ain-contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
primitive-types.workspace = true
ethereum-types.workspace = true
anyhow.workspace = true
ethereum.workspace = true
serde_json.workspace = true
Expand Down
4 changes: 1 addition & 3 deletions lib/ain-contracts/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::env;
use std::fs;
use std::path::PathBuf;
use std::{env, fs, path::PathBuf};

use anyhow::format_err;
use ethers_solc::{Project, ProjectPathsConfig, Solc};
Expand Down
2 changes: 1 addition & 1 deletion lib/ain-contracts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::str::FromStr;

use anyhow::format_err;
use primitive_types::{H160, H256};
use ethereum_types::{H160, H256};
use sp_core::{Blake2Hasher, Hasher};

pub type Result<T> = std::result::Result<T, anyhow::Error>;
Expand Down
3 changes: 1 addition & 2 deletions lib/ain-cpp-imports/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::env;
use std::path::PathBuf;
use std::{env, path::PathBuf};

use anyhow::{format_err, Result};

Expand Down
1 change: 0 additions & 1 deletion lib/ain-evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ ain-cpp-imports = { path = "../ain-cpp-imports" }
ain-contracts = { path = "../ain-contracts" }

evm = { workspace = true, default-features = false, features = ["with-serde"] }
primitive-types = { workspace = true, default-features = false, features = ["serde"] }
log.workspace = true
rlp.workspace = true
libsecp256k1.workspace = true
Expand Down
10 changes: 4 additions & 6 deletions lib/ain-evm/src/backend.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
use std::error::Error;
use std::sync::Arc;
use std::{error::Error, sync::Arc};

use ethereum::{Account, Log};
use ethereum_types::{H160, H256, U256};
use evm::backend::{Apply, ApplyBackend, Backend, Basic};
use hash_db::Hasher as _;
use log::{debug, trace};
use primitive_types::{H160, H256, U256};
use rlp::{Decodable, Encodable, Rlp};
use sp_core::hexdisplay::AsBytesRef;
use sp_core::Blake2Hasher;
use sp_core::{hexdisplay::AsBytesRef, Blake2Hasher};
use vsdb_trie_db::{MptOnce, MptRo};

use crate::Result;
use crate::{
storage::{traits::BlockStorage, Storage},
traits::BridgeBackend,
transaction::SignedTx,
trie::TrieDBStore,
Result,
};

type Hasher = Blake2Hasher;
Expand Down
14 changes: 9 additions & 5 deletions lib/ain-evm/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
use std::cmp::{max, Ordering};
use std::sync::Arc;
use std::{
cmp::{max, Ordering},
sync::Arc,
};

use anyhow::format_err;
use ethereum::{BlockAny, TransactionAny};
use ethereum_types::U256;
use keccak_hash::H256;
use log::{debug, trace};
use primitive_types::U256;
use statrs::statistics::{Data, OrderStatistics};

use crate::storage::{traits::BlockStorage, Storage};
use crate::Result;
use crate::{
storage::{traits::BlockStorage, Storage},
Result,
};

pub struct BlockService {
storage: Arc<Storage>,
Expand Down
34 changes: 16 additions & 18 deletions lib/ain-evm/src/core.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
use std::path::PathBuf;
use std::sync::Arc;
use std::{path::PathBuf, sync::Arc};

use anyhow::format_err;
use ethereum::{AccessList, Account, Block, Log, PartialHeader, TransactionV2};
use ethereum_types::{Bloom, BloomInput, H160, U256};
use ethereum_types::{Bloom, BloomInput, H160, H256, U256};
use log::debug;
use primitive_types::H256;
use vsdb_core::vsdb_set_base_dir;

use crate::backend::{BackendError, EVMBackend, InsufficientBalance, Vicinity};
use crate::block::INITIAL_BASE_FEE;
use crate::executor::TxResponse;
use crate::fee::calculate_prepay_gas_fee;
use crate::gas::check_tx_intrinsic_gas;
use crate::receipt::ReceiptService;
use crate::storage::traits::BlockStorage;
use crate::storage::Storage;
use crate::transaction::system::{SystemTx, TransferDirection, TransferDomainData};
use crate::trie::TrieDBStore;
use crate::txqueue::{QueueTx, TransactionQueueMap};
use crate::weiamount::WeiAmount;
use crate::{
executor::AinExecutor,
backend::{BackendError, EVMBackend, InsufficientBalance, Vicinity},
block::INITIAL_BASE_FEE,
executor::{AinExecutor, TxResponse},
fee::calculate_prepay_gas_fee,
gas::check_tx_intrinsic_gas,
receipt::ReceiptService,
storage::{traits::BlockStorage, Storage},
traits::{Executor, ExecutorContext},
transaction::SignedTx,
transaction::{
system::{SystemTx, TransferDirection, TransferDomainData},
SignedTx,
},
trie::TrieDBStore,
txqueue::{QueueTx, TransactionQueueMap},
weiamount::WeiAmount,
Result,
};

Expand Down
7 changes: 3 additions & 4 deletions lib/ain-evm/src/ecrecover.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use libsecp256k1::Error;
use libsecp256k1::{PublicKey, RecoveryId, Signature};
use primitive_types::{H160, H256};
use ethereum_types::{H160, H256};
use libsecp256k1::{Error, PublicKey, RecoveryId, Signature};
use sha3::Digest;

pub fn recover_public_key(
Expand Down Expand Up @@ -30,8 +29,8 @@ pub fn public_key_to_address(pubkey: &PublicKey) -> H160 {

#[cfg(test)]
mod tests {
use ethereum_types::*;
use hex_literal::hex;
use primitive_types::*;

use super::{public_key_to_address, recover_public_key};

Expand Down
49 changes: 24 additions & 25 deletions lib/ain-evm/src/evm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::path::PathBuf;
use std::sync::Arc;
use std::{path::PathBuf, sync::Arc};

use ain_contracts::{
get_dst20_contract, get_reserved_contract, get_transferdomain_contract, Contract, FixedContract,
Expand All @@ -9,32 +8,32 @@ use ethereum::{
Block, EIP1559ReceiptData, LegacyTransaction, PartialHeader, ReceiptV3, TransactionAction,
TransactionSignature, TransactionV2,
};
use ethereum_types::{Bloom, H160, H64, U256};
use ethereum_types::{Bloom, H160, H256, H64, U256};
use log::debug;
use primitive_types::H256;

use crate::backend::{EVMBackend, Vicinity};
use crate::block::BlockService;
use crate::contract::{
bridge_dst20, counter_contract, dst20_contract, transfer_domain_contract, DST20BridgeInfo,
DeployContractInfo,
use crate::{
backend::{EVMBackend, Vicinity},
block::BlockService,
contract::{
bridge_dst20, counter_contract, dst20_contract, transfer_domain_contract, DST20BridgeInfo,
DeployContractInfo,
},
core::{EVMCoreService, XHash},
executor::{AinExecutor, TxResponse},
fee::{calculate_gas_fee, calculate_prepay_gas_fee},
filters::FilterService,
log::LogService,
receipt::ReceiptService,
storage::{traits::BlockStorage, Storage},
traits::Executor,
transaction::{
system::{DST20Data, DeployContractData, SystemTx, TransferDirection, TransferDomainData},
SignedTx, LOWER_H256,
},
trie::GENESIS_STATE_ROOT,
txqueue::{BlockData, QueueTx, QueueTxItem},
Result,
};
use crate::core::{EVMCoreService, XHash};
use crate::executor::{AinExecutor, TxResponse};
use crate::fee::{calculate_gas_fee, calculate_prepay_gas_fee};
use crate::filters::FilterService;
use crate::log::LogService;
use crate::receipt::ReceiptService;
use crate::storage::traits::BlockStorage;
use crate::storage::Storage;
use crate::traits::Executor;
use crate::transaction::system::{
DST20Data, DeployContractData, SystemTx, TransferDirection, TransferDomainData,
};
use crate::transaction::{SignedTx, LOWER_H256};
use crate::trie::GENESIS_STATE_ROOT;
use crate::txqueue::{BlockData, QueueTx, QueueTxItem};
use crate::Result;

pub struct EVMServices {
pub core: EVMCoreService,
Expand Down
9 changes: 4 additions & 5 deletions lib/ain-evm/src/executor.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
use ethereum::{EIP658ReceiptData, Log, ReceiptV3};
use ethereum_types::{Bloom, U256};
use ethereum_types::{Bloom, H160, H256, U256};
use evm::{
backend::{ApplyBackend, Backend},
executor::stack::{MemoryStackState, StackExecutor, StackSubstateMetadata},
Config, CreateScheme, ExitReason,
};
use log::trace;
use primitive_types::{H160, H256};

use crate::bytes::Bytes;
use crate::precompiles::MetachainPrecompiles;
use crate::Result;
use crate::{
backend::EVMBackend,
bytes::Bytes,
core::EVMCoreService,
precompiles::MetachainPrecompiles,
traits::{BridgeBackend, Executor, ExecutorContext},
transaction::SignedTx,
Result,
};

pub struct AinExecutor<'backend> {
Expand Down
3 changes: 1 addition & 2 deletions lib/ain-evm/src/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use anyhow::format_err;
use ethereum::TransactionV2;
use ethereum_types::U256;

use crate::transaction::SignedTx;
use crate::Result;
use crate::{transaction::SignedTx, Result};

pub fn calculate_prepay_gas_fee(signed_tx: &SignedTx) -> Result<U256> {
match &signed_tx.transaction {
Expand Down
5 changes: 2 additions & 3 deletions lib/ain-evm/src/filters.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::collections::HashMap;
use std::sync::RwLock;
use std::{collections::HashMap, sync::RwLock};

use ethereum_types::{H160, H256, U256};
use log::debug;
use primitive_types::{H160, H256, U256};

#[derive(Clone, Debug)]
pub enum Filter {
Expand Down
3 changes: 1 addition & 2 deletions lib/ain-evm/src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use evm::{
};
use log::debug;

use crate::transaction::SignedTx;
use crate::Result;
use crate::{transaction::SignedTx, Result};

fn get_tx_cost(signed_tx: &SignedTx) -> TransactionCost {
let access_list = signed_tx
Expand Down
16 changes: 8 additions & 8 deletions lib/ain-evm/src/log.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::collections::HashMap;
use std::sync::Arc;
use std::{collections::HashMap, sync::Arc};

use ethereum::ReceiptV3;
use ethereum_types::{H160, H256, U256};
use log::debug;
use primitive_types::{H160, H256, U256};
use serde::{Deserialize, Serialize};

use crate::filters::LogsFilter;
use crate::receipt::Receipt;
use crate::storage::traits::LogStorage;
use crate::storage::Storage;
use crate::Result;
use crate::{
filters::LogsFilter,
receipt::Receipt,
storage::{traits::LogStorage, Storage},
Result,
};

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct LogIndex {
Expand Down
Loading

0 comments on commit e3c6eaa

Please sign in to comment.