From db3e7ce3c8e53e6f1623ba16a187cd3dcfea5da9 Mon Sep 17 00:00:00 2001 From: harry Date: Mon, 19 Jun 2023 12:14:01 +0800 Subject: [PATCH 1/3] query state optimize --- src/components/contracts/baseapp/Cargo.toml | 4 ++-- src/components/contracts/modules/account/Cargo.toml | 4 ++-- src/components/contracts/modules/ethereum/Cargo.toml | 4 ++-- src/components/contracts/modules/evm/Cargo.toml | 4 ++-- src/components/contracts/primitives/core/Cargo.toml | 4 ++-- src/components/contracts/primitives/core/src/context.rs | 6 ++++++ src/components/contracts/primitives/storage/Cargo.toml | 4 ++-- src/components/contracts/rpc/src/eth.rs | 2 ++ 8 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/components/contracts/baseapp/Cargo.toml b/src/components/contracts/baseapp/Cargo.toml index 9336d2b42..ad8d32477 100644 --- a/src/components/contracts/baseapp/Cargo.toml +++ b/src/components/contracts/baseapp/Cargo.toml @@ -22,8 +22,8 @@ protobuf = "2.16" ruc = "1.0" serde = {version = "1.0.124", features = ["derive"]} serde_json = "1.0.40" -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } -fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.6" } +fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.6" } sha3 = "0.8" config = { path = "../../config"} diff --git a/src/components/contracts/modules/account/Cargo.toml b/src/components/contracts/modules/account/Cargo.toml index 5fedd1cad..7fa712ab0 100644 --- a/src/components/contracts/modules/account/Cargo.toml +++ b/src/components/contracts/modules/account/Cargo.toml @@ -15,7 +15,7 @@ primitive-types = { version = "0.11.1", default-features = false, features = ["r ruc = "1.0" serde = { version = "1.0.124", features = ["derive"] } serde_json = "1.0.64" -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.6" } # primitives, don't depend on any modules fp-core = { path = "../../primitives/core" } @@ -29,4 +29,4 @@ config = { path = "../../../config"} rand_chacha = "0.2" parking_lot = "0.12" zei = { git = "https://github.com/FindoraNetwork/zei", branch = "stable-main" } -fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } +fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.6" } diff --git a/src/components/contracts/modules/ethereum/Cargo.toml b/src/components/contracts/modules/ethereum/Cargo.toml index c40e523aa..a4b4e2424 100644 --- a/src/components/contracts/modules/ethereum/Cargo.toml +++ b/src/components/contracts/modules/ethereum/Cargo.toml @@ -37,8 +37,8 @@ enterprise-web3 = { path = "../../primitives/enterprise-web3" } baseapp = { path = "../../baseapp" } fp-mocks = { path = "../../primitives/mocks" } module-account = { path = "../account" } -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } -fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.6" } +fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.6" } [features] default = [] diff --git a/src/components/contracts/modules/evm/Cargo.toml b/src/components/contracts/modules/evm/Cargo.toml index 2762fcc0f..8e53ebfad 100644 --- a/src/components/contracts/modules/evm/Cargo.toml +++ b/src/components/contracts/modules/evm/Cargo.toml @@ -34,8 +34,8 @@ fp-traits = { path = "../../primitives/traits" } fp-types = { path = "../../primitives/types" } fp-utils = { path = "../../primitives/utils" } config = { path = "../../../config"} -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } -fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.6" } +fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.6" } ledger = { path = "../../../../ledger" } enterprise-web3 = { path = "../../primitives/enterprise-web3" } diff --git a/src/components/contracts/primitives/core/Cargo.toml b/src/components/contracts/primitives/core/Cargo.toml index e265036a7..b177ab792 100644 --- a/src/components/contracts/primitives/core/Cargo.toml +++ b/src/components/contracts/primitives/core/Cargo.toml @@ -16,8 +16,8 @@ parking_lot = "0.12" primitive-types = { version = "0.11.1", default-features = false, features = ["rlp", "byteorder", "serde"] } ruc = "1.0" serde = { version = "1.0.124", features = ["derive"] } -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5", optional = true } -fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5", optional = true } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.6", optional = true } +fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.6", optional = true } serde_with = { version = "1.9.4"} # primitives diff --git a/src/components/contracts/primitives/core/src/context.rs b/src/components/contracts/primitives/core/src/context.rs index d1d34c8df..6825b60e1 100644 --- a/src/components/contracts/primitives/core/src/context.rs +++ b/src/components/contracts/primitives/core/src/context.rs @@ -38,6 +38,12 @@ pub struct Context { pub eth_cache: EthereumCache, } +impl Drop for Context { + fn drop(&mut self) { + self.state.write().clear_query_cache(); + } +} + impl Context { pub fn new( state_merkle: Arc>>, diff --git a/src/components/contracts/primitives/storage/Cargo.toml b/src/components/contracts/primitives/storage/Cargo.toml index bab9bfc4c..52d824e86 100644 --- a/src/components/contracts/primitives/storage/Cargo.toml +++ b/src/components/contracts/primitives/storage/Cargo.toml @@ -15,11 +15,11 @@ ruc = "1.0" serde = { version = "1.0.124", features = ["derive"] } serde_json = "1.0" sha2 = "0.9.5" -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.6" } # primitives fp-core = { path = "../core" } config = { path = "../../../config"} [dev-dependencies] -temp_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.5" } +temp_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.6" } diff --git a/src/components/contracts/rpc/src/eth.rs b/src/components/contracts/rpc/src/eth.rs index 7a4ffff85..26f461b72 100644 --- a/src/components/contracts/rpc/src/eth.rs +++ b/src/components/contracts/rpc/src/eth.rs @@ -359,6 +359,8 @@ impl EthApi for EthApiImpl { .create_context_at(block.header.number.as_u64()) .ok_or_else(|| internal_err("failed to create context"))?; + ctx.state.write().create_query_cache(); + ctx.header .mut_time() .set_seconds(block.header.timestamp as i64); From 282f76f0714360ac33affe62320a4c66cf62416b Mon Sep 17 00:00:00 2001 From: harry Date: Sun, 16 Jul 2023 04:37:12 +0800 Subject: [PATCH 2/3] update query optimize --- src/components/config/src/abci/mod.rs | 4 ++++ src/components/contracts/rpc/src/eth.rs | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/config/src/abci/mod.rs b/src/components/config/src/abci/mod.rs index 6d3f3460a..3c1e05900 100644 --- a/src/components/config/src/abci/mod.rs +++ b/src/components/config/src/abci/mod.rs @@ -141,6 +141,8 @@ pub struct CheckPointConfig { #[serde(default = "def_validator_whitelist_v3")] pub validator_whitelist_v3: Vec, + + pub storage_query_optimize: u64, } fn def_fix_check_replay() -> u64 { @@ -246,6 +248,7 @@ lazy_static! { validator_whitelist_v2: vec![], validator_whitelist_v3_height: 0, validator_whitelist_v3: vec![], + storage_query_optimize: 0, }; } @@ -577,6 +580,7 @@ lazy_static! { "37D3228A650F591522698BECDF42DCE5D1113D88".to_string(), "577F8548D8F834D39D26350D2A3A928F478AF5FD".to_string(), ], + storage_query_optimize: 100000000, }; } diff --git a/src/components/contracts/rpc/src/eth.rs b/src/components/contracts/rpc/src/eth.rs index 26f461b72..2931de45c 100644 --- a/src/components/contracts/rpc/src/eth.rs +++ b/src/components/contracts/rpc/src/eth.rs @@ -359,7 +359,10 @@ impl EthApi for EthApiImpl { .create_context_at(block.header.number.as_u64()) .ok_or_else(|| internal_err("failed to create context"))?; - ctx.state.write().create_query_cache(); + let curr_height = account_base_app.read().current_block_number().unwrap(); + if curr_height > U256::from(CFG.checkpoint.storage_query_optimize) { + ctx.state.write().create_query_cache(); + } ctx.header .mut_time() From 5df80c0b7034d6a1d1e5984a72d43d541b16b480 Mon Sep 17 00:00:00 2001 From: harry Date: Sun, 16 Jul 2023 04:51:44 +0800 Subject: [PATCH 3/3] fix compile error --- .../contracts/modules/account/src/impls.rs | 10 ++-- .../contracts/modules/account/src/tests.rs | 6 +-- .../contracts/modules/ethereum/src/impls.rs | 18 +++---- .../modules/ethereum/tests/ethereum_db.rs | 5 +- .../contracts/modules/evm/src/impls.rs | 13 +++-- .../contracts/modules/evm/src/lib.rs | 3 +- .../modules/evm/tests/evm_integration.rs | 3 +- .../contracts/modules/template/src/lib.rs | 4 +- .../template/tests/template_integration.rs | 2 +- .../contracts/modules/xhub/src/impls.rs | 15 +++--- .../contracts/primitives/storage/src/tests.rs | 50 +++++++------------ src/ledger/src/staking/mod.rs | 4 +- src/ledger/src/store/mod.rs | 1 + 13 files changed, 59 insertions(+), 75 deletions(-) diff --git a/src/components/contracts/modules/account/src/impls.rs b/src/components/contracts/modules/account/src/impls.rs index 808aed138..94352bd80 100644 --- a/src/components/contracts/modules/account/src/impls.rs +++ b/src/components/contracts/modules/account/src/impls.rs @@ -2,7 +2,7 @@ use crate::{storage::*, App, Config}; use config::abci::global_cfg::CFG; use enterprise_web3::{BALANCE_MAP, WEB3_SERVICE_START_HEIGHT}; use fp_core::{account::SmartAccount, context::Context}; -use fp_storage::{Borrow, BorrowMut}; +use fp_storage::BorrowMut; use fp_traits::account::AccountAsset; use fp_types::crypto::Address; use primitive_types::{H160, U256}; @@ -10,7 +10,7 @@ use ruc::*; impl AccountAsset
for App { fn total_issuance(ctx: &Context) -> U256 { - TotalIssuance::get(ctx.state.read().borrow()).unwrap_or_default() + TotalIssuance::get(&ctx.state.read()).unwrap_or_default() } fn account_of( @@ -20,9 +20,9 @@ impl AccountAsset
for App { ) -> Option { let version = height.unwrap_or(0); if version == 0 { - AccountStore::get(ctx.state.read().borrow(), who) + AccountStore::get(&ctx.state.read(), who) } else { - AccountStore::get_ver(ctx.state.read().borrow(), who, version) + AccountStore::get_ver(&ctx.state.read(), who, version) } } @@ -207,7 +207,7 @@ impl AccountAsset
for App { } fn allowance(ctx: &Context, owner: &Address, spender: &Address) -> U256 { - Allowances::get(ctx.state.read().borrow(), owner, spender).unwrap_or_default() + Allowances::get(&ctx.state.read(), owner, spender).unwrap_or_default() } fn approve( diff --git a/src/components/contracts/modules/account/src/tests.rs b/src/components/contracts/modules/account/src/tests.rs index aa07f72f4..8fd0fbb9a 100644 --- a/src/components/contracts/modules/account/src/tests.rs +++ b/src/components/contracts/modules/account/src/tests.rs @@ -2,7 +2,7 @@ use crate::storage::*; use crate::App; use fin_db::{FinDB, RocksDB}; use fp_core::{account::SmartAccount, context::Context}; -use fp_storage::{Borrow, BorrowMut}; +use fp_storage::BorrowMut; use fp_traits::account::AccountAsset; use fp_types::crypto::Address; use fp_types::U256; @@ -63,12 +63,12 @@ fn test_accounts_set_get() { ); assert_eq!( account, - AccountStore::get(ctx.state.read().borrow(), &address).unwrap() + AccountStore::get(&ctx.state.read(), &address).unwrap() ); assert!(ctx.state.write().commit(1).is_ok()); assert_eq!( account, - AccountStore::get(ctx.state.read().borrow(), &address).unwrap() + AccountStore::get(&ctx.state.read(), &address).unwrap() ); } diff --git a/src/components/contracts/modules/ethereum/src/impls.rs b/src/components/contracts/modules/ethereum/src/impls.rs index 7884c44da..f28cde195 100644 --- a/src/components/contracts/modules/ethereum/src/impls.rs +++ b/src/components/contracts/modules/ethereum/src/impls.rs @@ -16,7 +16,7 @@ use fp_core::{ }; use fp_events::Event; use fp_evm::{BlockId, CallOrCreateInfo, Runner, TransactionStatus}; -use fp_storage::{Borrow, BorrowMut}; +use fp_storage::BorrowMut; use fp_types::crypto::Address; use fp_types::{ actions::evm as EvmAction, @@ -472,13 +472,13 @@ impl App { id: Option, ) -> Option> { let hash = HA256::new(Self::block_hash(ctx, id).unwrap_or_default()); - CurrentTransactionStatuses::get(ctx.db.read().borrow(), &hash) + CurrentTransactionStatuses::get(&ctx.db.read(), &hash) } /// Get the block with given block id. pub fn current_block(&self, ctx: &Context, id: Option) -> Option { let hash = HA256::new(Self::block_hash(ctx, id).unwrap_or_default()); - CurrentBlock::get(ctx.db.read().borrow(), &hash) + CurrentBlock::get(&ctx.db.read(), &hash) } /// Get receipts with given block id. @@ -488,12 +488,12 @@ impl App { id: Option, ) -> Option> { let hash = HA256::new(Self::block_hash(ctx, id).unwrap_or_default()); - CurrentReceipts::get(ctx.db.read().borrow(), &hash) + CurrentReceipts::get(&ctx.db.read(), &hash) } /// Get current block hash pub fn current_block_hash(ctx: &Context) -> Option { - if let Some(number) = CurrentBlockNumber::get(ctx.db.read().borrow()) { + if let Some(number) = CurrentBlockNumber::get(&ctx.db.read()) { Self::get_hash(ctx, number) } else { None @@ -502,7 +502,7 @@ impl App { /// Get current block number pub fn current_block_number(ctx: &Context) -> Option { - CurrentBlockNumber::get(ctx.db.read().borrow()) + CurrentBlockNumber::get(&ctx.db.read()) } /// Get header hash of given block id. @@ -519,7 +519,7 @@ impl App { /// The index of the transaction in the block pub fn transaction_index(ctx: &Context, hash: H256) -> Option<(U256, u32)> { - TransactionIndex::get(ctx.db.read().borrow(), &HA256::new(hash)) + TransactionIndex::get(&ctx.db.read(), &HA256::new(hash)) } fn logs_bloom(logs: Vec, bloom: &mut Bloom) { @@ -532,7 +532,7 @@ impl App { } fn get_hash(ctx: &Context, number: U256) -> Option { - if let Some(hash) = BlockHash::get(ctx.db.read().borrow(), &number) { + if let Some(hash) = BlockHash::get(&ctx.db.read(), &number) { return Some(hash.h256()); } None @@ -541,7 +541,7 @@ impl App { pub fn migrate(ctx: &mut Context) -> Result<()> { //Migrate existing transaction indices from chain-state to rocksdb. let txn_idxs: Vec<(HA256, (U256, u32))> = - TransactionIndex::iterate(ctx.state.read().borrow()); + TransactionIndex::iterate(&ctx.state.read()); let txn_idxs_cnt = txn_idxs.len(); for idx in txn_idxs { diff --git a/src/components/contracts/modules/ethereum/tests/ethereum_db.rs b/src/components/contracts/modules/ethereum/tests/ethereum_db.rs index 75cd17f48..56b3d4ad0 100644 --- a/src/components/contracts/modules/ethereum/tests/ethereum_db.rs +++ b/src/components/contracts/modules/ethereum/tests/ethereum_db.rs @@ -2,7 +2,7 @@ use baseapp::BaseApp; use ethereum::{TransactionAction, TransactionSignature, TransactionV0}; use fin_db::{FinDB, RocksDB}; use fp_core::context::Context; -use fp_storage::{Borrow, BorrowMut, RwLock}; +use fp_storage::{BorrowMut, RwLock}; use fp_types::crypto::HA256; use fp_types::{H256, U256}; use module_ethereum::storage::TransactionIndex; @@ -72,8 +72,7 @@ fn test_eth_db_migrate_txn_index() { //Confirm transaction index values were migrated to rocksdb instance from the context. for txn in txns { - let value: Option<(U256, u32)> = - TransactionIndex::get(ctx.db.read().borrow(), &txn.0); + let value: Option<(U256, u32)> = TransactionIndex::get(&ctx.db.read(), &txn.0); assert!(value.is_some()); assert_eq!(value.unwrap(), txn.1); } diff --git a/src/components/contracts/modules/evm/src/impls.rs b/src/components/contracts/modules/evm/src/impls.rs index bf405846c..3e8175c91 100644 --- a/src/components/contracts/modules/evm/src/impls.rs +++ b/src/components/contracts/modules/evm/src/impls.rs @@ -3,7 +3,7 @@ use crate::{App, Config}; use ethereum_types::{H160, H256, U256}; use fp_core::context::Context; use fp_evm::Account; -use fp_storage::{Borrow, BorrowMut}; +use fp_storage::BorrowMut; use fp_traits::{ account::AccountAsset, evm::{AddressMapping, OnChargeEVMTransaction}, @@ -16,8 +16,7 @@ impl App { /// Check whether an account is empty. pub fn is_account_empty(ctx: &Context, address: &HA160) -> bool { let account = Self::account_basic(ctx, address); - let code_len = - AccountCodes::decode_len(ctx.state.read().borrow(), address).unwrap_or(0); + let code_len = AccountCodes::decode_len(&ctx.state.read(), address).unwrap_or(0); account.nonce == U256::zero() && account.balance == U256::zero() && code_len == 0 } @@ -48,9 +47,9 @@ impl App { let version = height.unwrap_or(0); if version == 0 { - AccountCodes::get_bytes(ctx.state.read().borrow(), address) + AccountCodes::get_bytes(&ctx.state.read(), address) } else { - AccountCodes::get_ver_bytes(ctx.state.read().borrow(), address, version) + AccountCodes::get_ver_bytes(&ctx.state.read(), address, version) } } @@ -63,9 +62,9 @@ impl App { ) -> Option { let version = height.unwrap_or(0); if version == 0 { - AccountStorages::get(ctx.state.read().borrow(), address, index) + AccountStorages::get(&ctx.state.read(), address, index) } else { - AccountStorages::get_ver(ctx.state.read().borrow(), address, index, version) + AccountStorages::get_ver(&ctx.state.read(), address, index, version) } } diff --git a/src/components/contracts/modules/evm/src/lib.rs b/src/components/contracts/modules/evm/src/lib.rs index 979ac39b1..47c0ae882 100644 --- a/src/components/contracts/modules/evm/src/lib.rs +++ b/src/components/contracts/modules/evm/src/lib.rs @@ -26,7 +26,6 @@ use fp_core::{ transaction::{ActionResult, Executable}, }; use fp_evm::TransactionStatus; -use fp_storage::Borrow; use fp_traits::{ account::AccountAsset, evm::{AddressMapping, BlockHashMapping, DecimalsMapping, FeeCalculator}, @@ -280,7 +279,7 @@ impl AppModule for App { match path[0] { "contract-number" => { let contracts: Vec<(HA160, Vec)> = - storage::AccountCodes::iterate(ctx.state.read().borrow()); + storage::AccountCodes::iterate(&ctx.state.read()); resp.value = serde_json::to_vec(&contracts.len()).unwrap_or_default(); resp } diff --git a/src/components/contracts/modules/evm/tests/evm_integration.rs b/src/components/contracts/modules/evm/tests/evm_integration.rs index 46eed3595..1c158ef4d 100644 --- a/src/components/contracts/modules/evm/tests/evm_integration.rs +++ b/src/components/contracts/modules/evm/tests/evm_integration.rs @@ -7,7 +7,6 @@ use baseapp::{BaseApp, ChainId}; use ethereum_types::{H160, H256, U256}; use fp_evm::{CallOrCreateInfo, Runner}; use fp_mocks::*; -use fp_storage::Borrow; use fp_types::{ actions::ethereum::Action as EthereumAction, actions::evm::Call, actions::Action, assemble::UncheckedTransaction, @@ -157,7 +156,7 @@ fn test_deploy_commit(contract_address: H160) { .create_query_context(Some(0), false) .unwrap(); assert!(AccountCodes::contains_key( - ctx.state.read().borrow(), + &ctx.state.read(), &contract_address.into() )); } diff --git a/src/components/contracts/modules/template/src/lib.rs b/src/components/contracts/modules/template/src/lib.rs index 9c528595e..59e8bc87d 100644 --- a/src/components/contracts/modules/template/src/lib.rs +++ b/src/components/contracts/modules/template/src/lib.rs @@ -11,7 +11,7 @@ use fp_core::{ }; // use fp_storage::{hash::StoragePrefixKey, Deref, StatelessStore}; use abci::{RequestQuery, ResponseQuery}; -use fp_storage::{Borrow, BorrowMut}; +use fp_storage::BorrowMut; use fp_types::{actions::template::Action, crypto::Address}; use ruc::Result; use std::marker::PhantomData; @@ -56,7 +56,7 @@ impl AppModule for App { return resp; } - let value = ValueStore::get(ctx.state.read().borrow()).unwrap_or_default(); + let value = ValueStore::get(&ctx.state.read()).unwrap_or_default(); // let value: u64 = ::get_obj( // ctx.store.read().deref(), diff --git a/src/components/contracts/modules/template/tests/template_integration.rs b/src/components/contracts/modules/template/tests/template_integration.rs index 481f22b98..389b9afec 100644 --- a/src/components/contracts/modules/template/tests/template_integration.rs +++ b/src/components/contracts/modules/template/tests/template_integration.rs @@ -119,7 +119,7 @@ fn test_abci_deliver_tx() { assert_eq!(u64::from_be_bytes(resp.data.try_into().unwrap()), 10); assert_eq!( - ValueStore::get(BASE_APP.lock().unwrap().deliver_state.state.read().borrow()), + ValueStore::get(&BASE_APP.lock().unwrap().deliver_state.state.read()), Some(10) ); } diff --git a/src/components/contracts/modules/xhub/src/impls.rs b/src/components/contracts/modules/xhub/src/impls.rs index 0b4887b5a..5b402ce3c 100644 --- a/src/components/contracts/modules/xhub/src/impls.rs +++ b/src/components/contracts/modules/xhub/src/impls.rs @@ -1,7 +1,7 @@ use crate::storage::*; use crate::{App, Config}; use fp_core::{context::Context, ensure, transaction::ActionResult}; -use fp_storage::{Borrow, BorrowMut}; +use fp_storage::BorrowMut; use fp_traits::{account::AccountAsset, evm::DecimalsMapping}; use fp_types::actions::xhub::NonConfidentialTransfer; use fp_types::{actions::xhub::NonConfidentialOutput, crypto::Address}; @@ -52,13 +52,12 @@ impl App { ctx: &Context, mut outputs: Vec, ) -> Result<()> { - let ops = - if let Some(mut ori_outputs) = PendingUTXOs::get(ctx.db.read().borrow()) { - ori_outputs.append(&mut outputs); - ori_outputs - } else { - outputs - }; + let ops = if let Some(mut ori_outputs) = PendingUTXOs::get(&ctx.db.read()) { + ori_outputs.append(&mut outputs); + ori_outputs + } else { + outputs + }; PendingUTXOs::put(ctx.db.write().borrow_mut(), &ops) } diff --git a/src/components/contracts/primitives/storage/src/tests.rs b/src/components/contracts/primitives/storage/src/tests.rs index f8d306079..792176b91 100644 --- a/src/components/contracts/primitives/storage/src/tests.rs +++ b/src/components/contracts/primitives/storage/src/tests.rs @@ -44,11 +44,11 @@ fn storage_value_works() { assert!(Number::put(state.write().borrow_mut(), &10).is_ok()); - assert_eq!(Number::get(state.read().borrow()), Some(10)); - assert!(Number::exists(state.read().borrow())); + assert_eq!(Number::get(&state.read()), Some(10)); + assert!(Number::exists(&state.read())); Number::delete(state.write().borrow_mut()); - assert_eq!(Number::get(state.read().borrow()), None); - assert!(!Number::exists(state.read().borrow())); + assert_eq!(Number::get(&state.read()), None); + assert!(!Number::exists(&state.read())); } #[test] @@ -65,33 +65,21 @@ fn storage_map_test() { assert!(Account::insert(state.write().borrow_mut(), &"b".to_string(), &20).is_ok()); assert!(Account::insert(state.write().borrow_mut(), &"c".to_string(), &30).is_ok()); + assert_eq!(Account::get(&state.read(), &"abc".to_string()), Some(10)); assert_eq!( - Account::get(state.read().borrow(), &"abc".to_string()), - Some(10) - ); - assert_eq!( - Account::get_unique_prefix(state.read().borrow(), &"ab".to_string()), + Account::get_unique_prefix(&state.read(), &"ab".to_string()), Some(("abc".to_string(), 10)) ); - assert!(Account::contains_key( - state.read().borrow(), - &"abc".to_string() - )); + assert!(Account::contains_key(&state.read(), &"abc".to_string())); Account::remove(state.write().borrow_mut(), &"abc".to_string()); - assert_eq!( - Account::get(state.read().borrow(), &"abc".to_string()), - None - ); - assert!(!Account::contains_key( - state.read().borrow(), - &"abc".to_string() - ),); + assert_eq!(Account::get(&state.read(), &"abc".to_string()), None); + assert!(!Account::contains_key(&state.read(), &"abc".to_string()),); - let kvs = Account::iterate(state.read().borrow()); + let kvs = Account::iterate(&state.read()); assert_eq!(kvs, vec![("b".to_string(), 20), ("c".to_string(), 30)]); state.write().commit(1).unwrap(); - let kvs = Account::iterate(state.read().borrow()); + let kvs = Account::iterate(&state.read()); assert_eq!(kvs, vec![("b".to_string(), 20), ("c".to_string(), 30)]); } @@ -108,23 +96,23 @@ fn storage_double_map_test() { assert!(Data::insert(state.write().borrow_mut(), &2, &3, &30).is_ok()); assert!(Data::insert(state.write().borrow_mut(), &2, &4, &40).is_ok()); - assert_eq!(Data::get(state.read().borrow(), &1, &2), Some(10)); - assert!(Data::contains_key(state.read().borrow(), &1, &2)); + assert_eq!(Data::get(&state.read(), &1, &2), Some(10)); + assert!(Data::contains_key(&state.read(), &1, &2)); Data::remove(state.write().borrow_mut(), &1, &2); - assert_eq!(Data::get(state.read().borrow(), &1, &2), None); - assert!(!Data::contains_key(state.read().borrow(), &1, &2)); + assert_eq!(Data::get(&state.read(), &1, &2), None); + assert!(!Data::contains_key(&state.read(), &1, &2)); - let kvs = Data::iterate_prefix(state.read().borrow(), &1); + let kvs = Data::iterate_prefix(&state.read(), &1); assert_eq!(kvs, vec![(3, 20)]); - let kvs = Data::iterate_prefix(state.read().borrow(), &2); + let kvs = Data::iterate_prefix(&state.read(), &2); assert_eq!(kvs, vec![(3, 30), (4, 40)]); Data::remove_prefix(state.write().borrow_mut(), &2); - let kvs = Data::iterate_prefix(state.read().borrow(), &2); + let kvs = Data::iterate_prefix(&state.read(), &2); assert_eq!(kvs, vec![]); state.write().commit(1).unwrap(); - let kvs = Data::iterate_prefix(state.read().borrow(), &1); + let kvs = Data::iterate_prefix(&state.read(), &1); assert_eq!(kvs, vec![(3, 20)]); } diff --git a/src/ledger/src/staking/mod.rs b/src/ledger/src/staking/mod.rs index 91b51d827..42af6a1ad 100644 --- a/src/ledger/src/staking/mod.rs +++ b/src/ledger/src/staking/mod.rs @@ -366,7 +366,7 @@ impl Staking { self.validator_info .range(0..=h) .rev() - .next() + .next_back() .map(|(_, v)| v) } @@ -391,7 +391,7 @@ impl Staking { self.validator_info .range_mut(0..=h) .rev() - .next() + .next_back() .map(|(_, v)| v) } diff --git a/src/ledger/src/store/mod.rs b/src/ledger/src/store/mod.rs index 1975d7d59..aef5501c6 100644 --- a/src/ledger/src/store/mod.rs +++ b/src/ledger/src/store/mod.rs @@ -1369,6 +1369,7 @@ impl LedgerStatus { // Apply memo updates for (code, memo) in block.memo_updates.drain() { + #[allow(unused_mut)] let mut asset = self.asset_types.get_mut(&code).unwrap(); asset.properties.memo = memo; }