Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query optimize #948

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/components/config/src/abci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ pub struct CheckPointConfig {

#[serde(default = "def_validator_whitelist_v3")]
pub validator_whitelist_v3: Vec<String>,

pub storage_query_optimize: u64,
}

fn def_fix_check_replay() -> u64 {
Expand Down Expand Up @@ -246,6 +248,7 @@ lazy_static! {
validator_whitelist_v2: vec![],
validator_whitelist_v3_height: 0,
validator_whitelist_v3: vec![],
storage_query_optimize: 0,
};
}

Expand Down Expand Up @@ -577,6 +580,7 @@ lazy_static! {
"37D3228A650F591522698BECDF42DCE5D1113D88".to_string(),
"577F8548D8F834D39D26350D2A3A928F478AF5FD".to_string(),
],
storage_query_optimize: 100000000,
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/contracts/baseapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
4 changes: 2 additions & 2 deletions src/components/contracts/modules/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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" }
10 changes: 5 additions & 5 deletions src/components/contracts/modules/account/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ 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};
use ruc::*;

impl<C: Config> AccountAsset<Address> for App<C> {
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(
Expand All @@ -20,9 +20,9 @@ impl<C: Config> AccountAsset<Address> for App<C> {
) -> Option<SmartAccount> {
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)
}
}

Expand Down Expand Up @@ -207,7 +207,7 @@ impl<C: Config> AccountAsset<Address> for App<C> {
}

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(
Expand Down
6 changes: 3 additions & 3 deletions src/components/contracts/modules/account/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/contracts/modules/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
18 changes: 9 additions & 9 deletions src/components/contracts/modules/ethereum/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -472,13 +472,13 @@ impl<C: Config> App<C> {
id: Option<BlockId>,
) -> Option<Vec<TransactionStatus>> {
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<BlockId>) -> Option<Block> {
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.
Expand All @@ -488,12 +488,12 @@ impl<C: Config> App<C> {
id: Option<BlockId>,
) -> Option<Vec<ethereum::ReceiptV0>> {
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<H256> {
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
Expand All @@ -502,7 +502,7 @@ impl<C: Config> App<C> {

/// Get current block number
pub fn current_block_number(ctx: &Context) -> Option<U256> {
CurrentBlockNumber::get(ctx.db.read().borrow())
CurrentBlockNumber::get(&ctx.db.read())
}

/// Get header hash of given block id.
Expand All @@ -519,7 +519,7 @@ impl<C: Config> App<C> {

/// 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<ethereum::Log>, bloom: &mut Bloom) {
Expand All @@ -532,7 +532,7 @@ impl<C: Config> App<C> {
}

fn get_hash(ctx: &Context, number: U256) -> Option<H256> {
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
Expand All @@ -541,7 +541,7 @@ impl<C: Config> App<C> {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/contracts/modules/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
13 changes: 6 additions & 7 deletions src/components/contracts/modules/evm/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -16,8 +16,7 @@ impl<C: Config> App<C> {
/// 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
}
Expand Down Expand Up @@ -48,9 +47,9 @@ impl<C: Config> App<C> {

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)
}
}

Expand All @@ -63,9 +62,9 @@ impl<C: Config> App<C> {
) -> Option<H256> {
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)
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/components/contracts/modules/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -280,7 +279,7 @@ impl<C: Config> AppModule for App<C> {
match path[0] {
"contract-number" => {
let contracts: Vec<(HA160, Vec<u8>)> =
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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
));
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/contracts/modules/template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,7 +56,7 @@ impl<C: Config> AppModule for App<C> {
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 = <ValueStoreInstance as StatelessStore>::get_obj(
// ctx.store.read().deref(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Expand Down
15 changes: 7 additions & 8 deletions src/components/contracts/modules/xhub/src/impls.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -52,13 +52,12 @@ impl<C: Config> App<C> {
ctx: &Context,
mut outputs: Vec<NonConfidentialOutput>,
) -> 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)
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/contracts/primitives/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/components/contracts/primitives/core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RwLock<ChainState<FinDB>>>,
Expand Down
Loading