Skip to content

Commit

Permalink
chore: fix cargo clippy warning
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyr committed Nov 1, 2022
1 parent 5bef332 commit a847135
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 96 deletions.
56 changes: 0 additions & 56 deletions crates/benches/benches/benchmarks/dummy_state.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/benches/benches/benchmarks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod dummy_state;
pub mod fee_queue;
pub mod init_db;
pub mod smt;
Expand Down
13 changes: 6 additions & 7 deletions crates/benches/benches/benchmarks/smt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::Arc;

use criterion::{criterion_group, BenchmarkId, Criterion, Throughput};
use gw_common::{
blake2b::new_blake2b,
Expand All @@ -23,6 +21,7 @@ use gw_store::{
state::{
history::history_state::{HistoryState, RWConfig},
state_db::StateDB,
traits::JournalDB,
MemStateDB,
},
traits::chain_store::ChainStore,
Expand Down Expand Up @@ -257,19 +256,18 @@ impl BenchExecutionEnvironment {
.args(args.as_bytes().pack())
.build();

let run_result = self
.generator
self.generator
.execute_transaction(
&self.chain,
&state,
&mut state,
&block_info,
&raw_tx,
L2TX_MAX_CYCLES,
None,
)
.unwrap();

state.apply_run_result(&run_result.write).unwrap();
state.finalise().unwrap();

from_id += 1;
if from_id > end_account_id {
Expand Down Expand Up @@ -336,6 +334,7 @@ impl BenchExecutionEnvironment {
};

Self::generate_accounts(&mut state, accounts + 1); // Plus block producer
state.finalise().unwrap();

let (genesis, global_state) = {
let prev_state_checkpoint: [u8; 32] =
Expand All @@ -346,7 +345,7 @@ impl BenchExecutionEnvironment {

// calculate post state
let post_account = {
let root = state.finalise_root().unwrap();
let root = state.calculate_root().unwrap();
let count = state.get_account_count().unwrap();
AccountMerkleState::new_builder()
.merkle_root(root.pack())
Expand Down
30 changes: 23 additions & 7 deletions crates/benches/benches/benchmarks/sudt.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
use super::dummy_state::DummyState;
use criterion::*;
use gw_common::{
builtins::ETH_REGISTRY_ACCOUNT_ID, registry_address::RegistryAddress, state::State, H256,
builtins::ETH_REGISTRY_ACCOUNT_ID, registry_address::RegistryAddress, smt::SMT, state::State,
H256,
};
use gw_config::{BackendConfig, BackendSwitchConfig};
use gw_generator::{
account_lock_manage::AccountLockManage, backend_manage::BackendManage,
constants::L2TX_MAX_CYCLES, error::TransactionError, traits::StateExt, Generator,
};
use gw_store::{
smt::smt_store::SMTStateStore,
snapshot::StoreSnapshot,
state::{
overlay::{mem_state::MemStateTree, mem_store::MemStore},
traits::JournalDB,
MemStateDB,
},
Store,
};
use gw_traits::{ChainView, CodeStore};
use gw_types::{
bytes::Bytes,
Expand Down Expand Up @@ -62,6 +72,12 @@ impl ChainView for DummyChainStore {
}
}

fn new_state(store: StoreSnapshot) -> MemStateDB {
let smt = SMT::new(H256::zero(), SMTStateStore::new(MemStore::new(store)));
let inner = MemStateTree::new(smt, 0);
MemStateDB::new(inner)
}

fn new_block_info(block_producer: &RegistryAddress, number: u64, timestamp: u64) -> BlockInfo {
BlockInfo::new_builder()
.block_producer(Bytes::from(block_producer.to_bytes()).pack())
Expand All @@ -70,7 +86,7 @@ fn new_block_info(block_producer: &RegistryAddress, number: u64, timestamp: u64)
.build()
}

fn run_contract_get_result<S: State + CodeStore>(
fn run_contract_get_result<S: State + CodeStore + JournalDB>(
rollup_config: &RollupConfig,
tree: &mut S,
from_id: u32,
Expand Down Expand Up @@ -104,12 +120,11 @@ fn run_contract_get_result<S: State + CodeStore>(
L2TX_MAX_CYCLES,
None,
)?;
tree.apply_run_result(&run_result.write)
.expect("update state");
tree.finalise()?;
Ok(run_result)
}

fn run_contract<S: State + CodeStore>(
fn run_contract<S: State + CodeStore + JournalDB>(
rollup_config: &RollupConfig,
tree: &mut S,
from_id: u32,
Expand All @@ -128,7 +143,8 @@ pub fn bench(c: &mut Criterion) {
group.bench_function("sudt", move |b| {
b.iter_batched(
|| {
let mut tree = DummyState::default();
let db = Store::open_tmp().unwrap();
let mut tree = new_state(db.get_snapshot());

let always_success_lock_hash = [255u8; 32];
let rollup_config = RollupConfig::new_builder()
Expand Down
2 changes: 1 addition & 1 deletion crates/store/src/tests/state_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn test_state_with_version() {
state
.update_raw(H256::from_u32(5), H256::from_u32(25))
.unwrap();
commit_block(&db, build_block(&mut state, 2, prev_txs_state_checkpoint));
commit_block(db, build_block(&mut state, 2, prev_txs_state_checkpoint));
db.set_last_confirmed_block_number_hash(
&NumberHash::new_builder()
.number(2.pack())
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/src/testing_tool/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ pub async fn construct_block_with_timestamp(
reverted_block_root,
block_param,
};
produce_block(&db, generator, param).map(|mut r| {
produce_block(db, generator, param).map(|mut r| {
r.remaining_capacity = remaining_capacity;
r
})
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/src/tests/meta_contract_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async fn test_backward_compatibility() {
.signature(sign.pack())
.build();

mem_pool_state.store_state_db(state.into());
mem_pool_state.store_state_db(state);
{
let mut mem_pool = chain.mem_pool().await;
mem_pool.push_transaction(create_user_tx).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/src/tests/polyjuice_sender_recover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async fn test_eth_account_creator() {
.build_batch_create_tx(&state, recovered_account_scripts)
.unwrap();

mem_pool_state.store_state_db(state.into());
mem_pool_state.store_state_db(state);
{
let mut mem_pool = chain.mem_pool().await;
mem_pool.push_transaction(batch_create_tx).unwrap();
Expand Down
12 changes: 6 additions & 6 deletions crates/tests/src/tests/rpc_server/execute_l2transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async fn test_polyjuice_erc20_tx() {
.build();
let deploy_tx = test_wallet.sign_polyjuice_tx(&state, raw_tx).unwrap();

mem_pool_state.store_state_db(state.into());
mem_pool_state.store_state_db(state);
let run_result = rpc_server.execute_l2transaction(&deploy_tx).await.unwrap();

let logs = run_result.logs.into_iter().map(Into::into);
Expand Down Expand Up @@ -111,7 +111,7 @@ async fn test_polyjuice_tx_from_id_zero() {
let deploy_tx = deployer_wallet.sign_polyjuice_tx(&state, raw_tx).unwrap();
let deploy_tx_hash: H256 = deploy_tx.hash().into();

mem_pool_state.store_state_db(state.into());
mem_pool_state.store_state_db(state);
{
let mut mem_pool = chain.mem_pool().await;
mem_pool.push_transaction(deploy_tx).unwrap();
Expand Down Expand Up @@ -159,7 +159,7 @@ async fn test_polyjuice_tx_from_id_zero() {
.build();
let balance_tx = test_wallet.sign_polyjuice_tx(&state, raw_tx).unwrap();

mem_pool_state.store_state_db(state.into());
mem_pool_state.store_state_db(state);
let run_result = rpc_server.execute_l2transaction(&balance_tx).await.unwrap();

assert_eq!(
Expand Down Expand Up @@ -209,7 +209,7 @@ async fn test_invalid_polyjuice_tx_from_id_zero() {
.unwrap();
let deploy_tx_hash: H256 = deploy_tx.hash().into();

mem_pool_state.store_state_db(state.into());
mem_pool_state.store_state_db(state);
{
let mut mem_pool = chain.mem_pool().await;
mem_pool.push_transaction(deploy_tx).unwrap();
Expand Down Expand Up @@ -300,7 +300,7 @@ async fn test_invalid_polyjuice_tx_from_id_zero() {

let balance = 100u32.into();
test_wallet.mint_ckb_sudt(&mut state, balance).unwrap();
mem_pool_state.store_state_db(state.into());
mem_pool_state.store_state_db(state);

let err = rpc_server
.execute_l2transaction(&balance_tx)
Expand All @@ -316,7 +316,7 @@ async fn test_invalid_polyjuice_tx_from_id_zero() {
state
.mapping_registry_address_to_script_hash(test_wallet.reg_address().to_owned(), H256::one())
.unwrap();
mem_pool_state.store_state_db(state.into());
mem_pool_state.store_state_db(state);

let err = rpc_server
.execute_l2transaction(&balance_tx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async fn test_block_max_cycles_limit() {
.build();
let deploy_tx = test_wallet.sign_polyjuice_tx(&state, raw_tx).unwrap();

mem_pool_state.store_state_db(state.into());
mem_pool_state.store_state_db(state);
let err = rpc_server
.execute_l2transaction(&deploy_tx)
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async fn test_polyjuice_erc20_tx() {
.build();

let reg_addr_bytes = test_wallet.reg_address().to_bytes().into();
mem_pool_state.store_state_db(state.into());
mem_pool_state.store_state_db(state);

let run_result = rpc_server
.execute_raw_l2transaction(&raw_tx, None, Some(reg_addr_bytes))
Expand Down Expand Up @@ -122,7 +122,7 @@ async fn test_polyjuice_tx_from_id_zero() {
let deploy_tx = deployer_wallet.sign_polyjuice_tx(&state, raw_tx).unwrap();
let deploy_tx_hash: H256 = deploy_tx.hash().into();

mem_pool_state.store_state_db(state.into());
mem_pool_state.store_state_db(state);
{
let mut mem_pool = chain.mem_pool().await;
mem_pool.push_transaction(deploy_tx).unwrap();
Expand Down Expand Up @@ -162,7 +162,7 @@ async fn test_polyjuice_tx_from_id_zero() {
.mint_sudt(&mut state, CKB_SUDT_ACCOUNT_ID, test_balance)
.unwrap();

mem_pool_state.store_state_db(state.into());
mem_pool_state.store_state_db(state);
let state = mem_pool_state.load_state_db();

let erc20_contract_account_id = system_log.contract_account_id(&state).unwrap();
Expand Down Expand Up @@ -486,7 +486,7 @@ async fn test_invalid_registry_address() {
let deploy_tx = deployer_wallet.sign_polyjuice_tx(&state, raw_tx).unwrap();
let deploy_tx_hash: H256 = deploy_tx.hash().into();

mem_pool_state.store_state_db(state.into());
mem_pool_state.store_state_db(state);
{
let mut mem_pool = chain.mem_pool().await;
mem_pool.push_transaction(deploy_tx).unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async fn test_block_max_cycles_limit() {
.build();
let reg_addr_bytes = test_wallet.reg_address().to_bytes().into();

mem_pool_state.store_state_db(state.into());
mem_pool_state.store_state_db(state);
let run_result = rpc_server
.execute_raw_l2transaction(&raw_tx, None, Some(reg_addr_bytes))
.await
Expand Down Expand Up @@ -123,7 +123,7 @@ async fn test_block_max_cycles_limit() {
.build();
let reg_addr_bytes = test_wallet.reg_address().to_bytes().into();

mem_pool_state.store_state_db(state.into());
mem_pool_state.store_state_db(state);
let err = rpc_server
.execute_raw_l2transaction(&raw_tx, None, Some(reg_addr_bytes))
.await
Expand Down
Loading

0 comments on commit a847135

Please sign in to comment.