From 84f9e70fa9b3f7dbb9226ba40079ce764abb40de Mon Sep 17 00:00:00 2001 From: shaorongqiang Date: Mon, 9 Jan 2023 10:02:33 +0800 Subject: [PATCH 1/6] add wasm new_keypair_old (#789) Co-authored-by: shaorongqiang --- src/components/wasm/src/wasm.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/wasm/src/wasm.rs b/src/components/wasm/src/wasm.rs index 9b7e965721..edb62015f5 100644 --- a/src/components/wasm/src/wasm.rs +++ b/src/components/wasm/src/wasm.rs @@ -1596,6 +1596,11 @@ pub fn new_keypair() -> XfrKeyPair { gen_random_keypair() } +#[wasm_bindgen] +/// Creates a new transfer key pair. +pub fn new_keypair_old() -> XfrKeyPair { + XfrKeyPair::generate_ed25519(&mut ChaChaRng::from_entropy()) +} #[wasm_bindgen] /// Generates a new keypair deterministically from a seed string and an optional name. pub fn new_keypair_from_seed(seed_str: String, name: Option) -> XfrKeyPair { From 996f59aaa88d0e22fbb843dfd6295e21dd9cec59 Mon Sep 17 00:00:00 2001 From: liyue201 Date: Wed, 18 Jan 2023 10:58:31 +0800 Subject: [PATCH 2/6] Upgrade prism (#791) * Mint FRA for test address * upgrade prism * make fmt * make test * fix make test * fix withdraw_fra and parse_deposit_asset --- src/components/abciapp/Cargo.toml | 5 +- .../abciapp/src/abci/server/callback/mod.rs | 108 +++++-- .../abciapp/src/abci/staking/mod.rs | 137 +++------ src/components/config/src/abci/mod.rs | 7 +- src/components/contracts/baseapp/Cargo.toml | 3 +- src/components/contracts/baseapp/src/lib.rs | 36 +-- .../contracts/baseapp/src/modules.rs | 17 ++ .../evm/contracts/PrismXXBridge.abi.json | 266 ++++-------------- .../contracts/modules/evm/src/lib.rs | 62 +--- .../modules/evm/src/system_contracts.rs | 29 +- .../contracts/modules/evm/src/utils.rs | 197 ++++++------- 11 files changed, 293 insertions(+), 574 deletions(-) diff --git a/src/components/abciapp/Cargo.toml b/src/components/abciapp/Cargo.toml index aa1499ebea..f2a4e393cf 100644 --- a/src/components/abciapp/Cargo.toml +++ b/src/components/abciapp/Cargo.toml @@ -58,7 +58,8 @@ tempfile = "3.1.0" baseapp = { path = "../contracts/baseapp" } fc-rpc = { path = "../contracts/rpc" } fp-storage = { path = "../contracts/primitives/storage" } -fp-utils = { path = "../contracts/primitives/utils" } +fp-types = {path = "../contracts/primitives/types"} +fp-utils = {path = "../contracts/primitives/utils" } enterprise-web3 = { path = "../contracts/primitives/enterprise-web3", optional = true } @@ -75,5 +76,5 @@ vergen = "=3.1.0" [features] default = ["diskcache"] diskcache = ["ledger/diskcache"] -debug_env = ["ledger/debug_env", "config/debug_env"] +debug_env = ["ledger/debug_env", "config/debug_env", "baseapp/debug_env"] web3_service = ["enterprise-web3", "baseapp/web3_service"] \ No newline at end of file diff --git a/src/components/abciapp/src/abci/server/callback/mod.rs b/src/components/abciapp/src/abci/server/callback/mod.rs index 3d32493c2a..fec71386e2 100644 --- a/src/components/abciapp/src/abci/server/callback/mod.rs +++ b/src/components/abciapp/src/abci/server/callback/mod.rs @@ -29,6 +29,7 @@ use { staking::KEEP_HIST, store::api_cache, }, + module_evm::utils::{deposit_asset_event_topic_str, parse_deposit_asset_event}, parking_lot::{Mutex, RwLock}, protobuf::RepeatedField, ruc::*, @@ -374,30 +375,85 @@ pub fn deliver_tx( } let mut resp = s.account_base_app.write().deliver_tx(req); - if td_height > CFG.checkpoint.fix_prism_mint_pay && 0 == resp.code { - let mut la = s.la.write(); - let mut laa = la.get_committed_state().write(); - if let Some(tx) = staking::system_prism_mint_pay( - &mut laa, - &mut s.account_base_app.write(), - ) { - drop(laa); - if la.cache_transaction(tx).is_ok() { - return resp; + if td_height > CFG.checkpoint.prismxx_inital_height && 0 == resp.code { + let deposit_asset_topic = deposit_asset_event_topic_str(); + + for evt in resp.events.iter() { + if evt.field_type == *"ethereum_ContractLog" { + let mut bridge_contract_found = false; + let mut deposit_asset_foud = false; + + for pair in evt.attributes.iter() { + let key = String::from_utf8(pair.key.clone()) + .unwrap_or_default(); + if key == *"address" { + let addr = String::from_utf8(pair.value.clone()) + .unwrap_or_default(); + if addr + == CFG + .checkpoint + .prism_bridge_address + .to_lowercase() + { + bridge_contract_found = true + } + } + if key == *"topics" { + let topic = String::from_utf8(pair.value.clone()) + .unwrap_or_default(); + if topic == deposit_asset_topic { + deposit_asset_foud = true + } + } + if key == *"data" + && bridge_contract_found + && deposit_asset_foud + { + let data = String::from_utf8(pair.value.clone()) + .unwrap_or_default(); + + let data_vec = serde_json::from_str(&data).unwrap(); + + let deposit_asset = + parse_deposit_asset_event(data_vec); + + match deposit_asset { + Ok(deposit) => { + let mut la = s.la.write(); + let mut laa = + la.get_committed_state().write(); + if let Some(tx) = + staking::system_prism_mint_pay( + &mut laa, deposit, + ) + { + drop(laa); + if la.cache_transaction(tx).is_ok() { + return resp; + } + resp.code = 1; + s.account_base_app + .read() + .deliver_state + .state + .write() + .discard_session(); + s.account_base_app + .read() + .deliver_state + .db + .write() + .discard_session(); + } + } + Err(e) => { + resp.code = 1; + resp.log = e.to_string(); + } + } + } + } } - resp.code = 1; - s.account_base_app - .read() - .deliver_state - .state - .write() - .discard_session(); - s.account_base_app - .read() - .deliver_state - .db - .write() - .discard_session(); } } resp @@ -434,11 +490,7 @@ pub fn end_block( // mint coinbase, cache system transactions to ledger { let mut laa = la.get_committed_state().write(); - if let Some(tx) = staking::system_mint_pay( - td_height, - &mut laa, - &mut s.account_base_app.write(), - ) { + if let Some(tx) = staking::system_mint_pay(td_height, &mut laa) { drop(laa); // this unwrap should be safe la.cache_transaction(tx).unwrap(); diff --git a/src/components/abciapp/src/abci/staking/mod.rs b/src/components/abciapp/src/abci/staking/mod.rs index 929f7c37d9..532e0e2b3e 100644 --- a/src/components/abciapp/src/abci/staking/mod.rs +++ b/src/components/abciapp/src/abci/staking/mod.rs @@ -12,8 +12,8 @@ mod test; use { crate::abci::server::callback::TENDERMINT_BLOCK_HEIGHT, abci::{Evidence, Header, LastCommitInfo, PubKey, ValidatorUpdate}, - baseapp::BaseApp as AccountBaseApp, config::abci::global_cfg::CFG, + fp_types::actions::xhub::NonConfidentialOutput, lazy_static::lazy_static, ledger::{ data_model::{ @@ -285,120 +285,57 @@ fn system_governance(staking: &mut Staking, bz: &ByzantineInfo) -> Result<()> { /// Pay for freed 'Delegations' and 'FraDistributions'. pub fn system_prism_mint_pay( la: &mut LedgerState, - account_base_app: &mut AccountBaseApp, + mint: NonConfidentialOutput, ) -> Option { let mut mints = Vec::new(); - if let Some(account_mint) = account_base_app.consume_mint() { - for mint in account_mint { - if mint.asset != ASSET_TYPE_FRA { - let atc = AssetTypeCode { val: mint.asset }; - let at = if let Some(mut at) = la.get_asset_type(&atc) { - at.properties.issuer = IssuerPublicKey { - key: *BLACK_HOLE_PUBKEY_STAKING, - }; - if mint.max_supply != 0 { - at.properties.asset_rules.max_units = Some(mint.max_supply); - } - at.properties.asset_rules.decimals = mint.decimal; - at - } else { - let mut at = AssetType::default(); - at.properties.issuer = IssuerPublicKey { - key: *BLACK_HOLE_PUBKEY_STAKING, - }; + if mint.asset != ASSET_TYPE_FRA { + let atc = AssetTypeCode { val: mint.asset }; + let at = if let Some(mut at) = la.get_asset_type(&atc) { + at.properties.issuer = IssuerPublicKey { + key: *BLACK_HOLE_PUBKEY_STAKING, + }; + if mint.max_supply != 0 { + at.properties.asset_rules.max_units = Some(mint.max_supply); + } + at.properties.asset_rules.decimals = mint.decimal; + at + } else { + let mut at = AssetType::default(); + at.properties.issuer = IssuerPublicKey { + key: *BLACK_HOLE_PUBKEY_STAKING, + }; - if mint.max_supply != 0 { - at.properties.asset_rules.max_units = Some(mint.max_supply); - } - at.properties.asset_rules.decimals = mint.decimal; + if mint.max_supply != 0 { + at.properties.asset_rules.max_units = Some(mint.max_supply); + } + at.properties.asset_rules.decimals = mint.decimal; - at.properties.code = AssetTypeCode { val: mint.asset }; + at.properties.code = AssetTypeCode { val: mint.asset }; - at - }; + at + }; - la.insert_asset_type(atc, at); - } + la.insert_asset_type(atc, at); + } - let mint_entry = MintEntry::new( - MintKind::Other, - mint.target, - None, - mint.amount, - mint.asset, - ); + let mint_entry = + MintEntry::new(MintKind::Other, mint.target, None, mint.amount, mint.asset); - mints.push(mint_entry); - } - } + mints.push(mint_entry); - if mints.is_empty() { - None - } else { - let mint_ops = - Operation::MintFra(MintFraOps::new(la.get_staking().cur_height(), mints)); - Some(Transaction::from_operation_coinbase_mint( - mint_ops, - la.get_state_commitment().1, - )) - } + let mint_ops = + Operation::MintFra(MintFraOps::new(la.get_staking().cur_height(), mints)); + Some(Transaction::from_operation_coinbase_mint( + mint_ops, + la.get_state_commitment().1, + )) } /// Pay for freed 'Delegations' and 'FraDistributions'. -pub fn system_mint_pay( - td_height: i64, - la: &mut LedgerState, - account_base_app: &mut AccountBaseApp, -) -> Option { +pub fn system_mint_pay(td_height: i64, la: &mut LedgerState) -> Option { let mut mints = Vec::new(); - if td_height <= CFG.checkpoint.fix_prism_mint_pay { - if let Some(account_mint) = account_base_app.consume_mint() { - for mint in account_mint { - if mint.asset != ASSET_TYPE_FRA { - let atc = AssetTypeCode { val: mint.asset }; - let at = if let Some(mut at) = la.get_asset_type(&atc) { - at.properties.issuer = IssuerPublicKey { - key: *BLACK_HOLE_PUBKEY_STAKING, - }; - - if mint.max_supply != 0 { - at.properties.asset_rules.max_units = Some(mint.max_supply); - } - - at - } else { - let mut at = AssetType::default(); - at.properties.issuer = IssuerPublicKey { - key: *BLACK_HOLE_PUBKEY_STAKING, - }; - - if mint.max_supply != 0 { - at.properties.asset_rules.max_units = Some(mint.max_supply); - } - - at.properties.code = AssetTypeCode { val: mint.asset }; - - at - }; - - la.insert_asset_type(atc, at); - } - - let mint_entry = MintEntry::new( - MintKind::Other, - mint.target, - None, - mint.amount, - mint.asset, - ); - - mints.push(mint_entry); - } - } - } - let staking = la.get_staking(); let mut limit = staking.coinbase_balance() as i128; diff --git a/src/components/config/src/abci/mod.rs b/src/components/config/src/abci/mod.rs index b97a41c6b7..12428ea4a6 100644 --- a/src/components/config/src/abci/mod.rs +++ b/src/components/config/src/abci/mod.rs @@ -61,7 +61,6 @@ pub struct CheckPointConfig { pub unbond_block_cnt: u64, pub prismxx_inital_height: i64, pub enable_triple_masking_height: i64, - pub fix_prism_mint_pay: i64, pub fix_exec_code: i64, // https://github.com/FindoraNetwork/platform/pull/307 @@ -117,13 +116,14 @@ impl CheckPointConfig { enable_triple_masking_height: 0, fix_unpaid_delegation_height: 0, fix_undelegation_missing_reward_height: 0, - fix_prism_mint_pay: 0, fix_exec_code: 0, evm_checktx_nonce: 0, utxo_checktx_height: 0, utxo_asset_prefix_height: 0, nonce_bug_fix_height: 0, - prism_bridge_address: String::new(), + prism_bridge_address: + "0xfcfe4ff1006a7721cee870b56ee2b5c250aec13b" + .to_owned(), proper_gas_set_height: 0, fix_delegators_am_height: 0, validators_limit_v2_height: 0, @@ -145,7 +145,6 @@ impl CheckPointConfig { prismxx_inital_height: 30000000, enable_triple_masking_height: 30000000, fix_unpaid_delegation_height: 2261885, - fix_prism_mint_pay: 30000000, fix_exec_code: 30000000, evm_checktx_nonce: 30000000, utxo_checktx_height: 30000000, diff --git a/src/components/contracts/baseapp/Cargo.toml b/src/components/contracts/baseapp/Cargo.toml index cbc641ceba..74bc31e815 100644 --- a/src/components/contracts/baseapp/Cargo.toml +++ b/src/components/contracts/baseapp/Cargo.toml @@ -56,4 +56,5 @@ evm-precompile = {path = "../modules/evm/precompile"} [features] abci_mock = [] -web3_service = ["enterprise-web3", "module-account/web3_service", "module-ethereum/web3_service", "module-evm/web3_service"] \ No newline at end of file +web3_service = ["enterprise-web3", "module-account/web3_service", "module-ethereum/web3_service", "module-evm/web3_service"] +debug_env = [] diff --git a/src/components/contracts/baseapp/src/lib.rs b/src/components/contracts/baseapp/src/lib.rs index 02de696a16..05d003679d 100644 --- a/src/components/contracts/baseapp/src/lib.rs +++ b/src/components/contracts/baseapp/src/lib.rs @@ -27,11 +27,11 @@ use fp_evm::BlockId; use fp_traits::{ account::{AccountAsset, FeeCalculator}, base::BaseProvider, - evm::{DecimalsMapping, EthereumAddressMapping, EthereumDecimalsMapping}, + evm::{EthereumAddressMapping, EthereumDecimalsMapping}, }; -use fp_types::{actions::xhub::NonConfidentialOutput, actions::Action, crypto::Address}; +use fp_types::{actions::Action, crypto::Address}; use lazy_static::lazy_static; -use ledger::data_model::{Transaction as FindoraTransaction, ASSET_TYPE_FRA}; +use ledger::data_model::Transaction as FindoraTransaction; use notify::*; use parking_lot::RwLock; use primitive_types::{H160, H256, U256}; @@ -350,36 +350,6 @@ impl BaseApp { self.modules .process_findora_tx(&self.deliver_state, tx, H256::from_slice(hash)) } - - pub fn consume_mint(&self) -> Option> { - let mut outputs = self.modules.evm_module.consume_mint(&self.deliver_state); - - for output in &outputs { - if output.asset == ASSET_TYPE_FRA { - let address = - Address::from(self.modules.evm_module.contracts.bridge_address); - if let Some(amount) = - EthereumDecimalsMapping::from_native_token(U256::from(output.amount)) - { - if let Err(e) = module_account::App::::burn( - &self.deliver_state, - &address, - amount, - ) { - tracing::error!("Error when burn account: {:?}", e); - } - } - } - } - - let outputs2 = module_xhub::App::::consume_mint(&self.deliver_state); - - if let Some(mut e) = outputs2 { - outputs.append(&mut e); - } - - Some(outputs) - } } impl BaseProvider for BaseApp { diff --git a/src/components/contracts/baseapp/src/modules.rs b/src/components/contracts/baseapp/src/modules.rs index c84a219259..f4982471cc 100644 --- a/src/components/contracts/baseapp/src/modules.rs +++ b/src/components/contracts/baseapp/src/modules.rs @@ -22,6 +22,9 @@ use module_ethereum::storage::{TransactionIndex, DELIVER_PENDING_TRANSACTIONS}; use ruc::*; use serde::Serialize; +#[cfg(feature = "debug_env")] +use std::str::FromStr; + #[derive(Default, Clone)] pub struct ModuleManager { // Ordered module list @@ -72,6 +75,20 @@ impl ModuleManager { self.evm_module.begin_block(ctx, req); self.xhub_module.begin_block(ctx, req); self.template_module.begin_block(ctx, req); + + #[cfg(feature = "debug_env")] + if ctx.header.height == 1 { + //private key: 4d05b965f821ea900ddd995dfa1b6caa834eaaa1ebe100a9760baf9331aae567 + let test_address = + H160::from_str("0x72488bAa718F52B76118C79168E55c209056A2E6").unwrap(); + + // mint 1000 FRA + pnk!(module_account::App::::mint( + ctx, + &Address::from(test_address), + U256::from(1_0000_0000_0000_0000_u64).saturating_mul(1000_00.into()) + )); + } } pub fn end_block( diff --git a/src/components/contracts/modules/evm/contracts/PrismXXBridge.abi.json b/src/components/contracts/modules/evm/contracts/PrismXXBridge.abi.json index 3defb48dbb..3909b80430 100644 --- a/src/components/contracts/modules/evm/contracts/PrismXXBridge.abi.json +++ b/src/components/contracts/modules/evm/contracts/PrismXXBridge.abi.json @@ -1,14 +1,40 @@ [ { + "anonymous": false, "inputs": [ { - "internalType": "address", - "name": "_proxy_contract", - "type": "address" + "indexed": false, + "internalType": "bytes32", + "name": "asset", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "receiver", + "type": "bytes" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "decimal", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "max_supply", + "type": "uint256" } ], - "stateMutability": "nonpayable", - "type": "constructor" + "name": "DepositAsset", + "type": "event" }, { "anonymous": false, @@ -134,6 +160,19 @@ "name": "DepositFRC721", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "version", + "type": "uint8" + } + ], + "name": "Initialized", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -277,115 +316,6 @@ "name": "WithdrawFRC721", "type": "event" }, - { - "inputs": [], - "name": "__self", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "_consumeMint", - "outputs": [ - { - "components": [ - { - "internalType": "bytes32", - "name": "asset", - "type": "bytes32" - }, - { - "internalType": "bytes", - "name": "receiver", - "type": "bytes" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "uint8", - "name": "decimal", - "type": "uint8" - }, - { - "internalType": "uint256", - "name": "max_supply", - "type": "uint256" - } - ], - "internalType": "struct PrismXXBridge.MintOp[]", - "name": "", - "type": "tuple[]" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "_asset", - "type": "bytes32" - }, - { - "internalType": "bytes", - "name": "_from", - "type": "bytes" - }, - { - "internalType": "address", - "name": "_to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_value", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "_data", - "type": "bytes" - } - ], - "name": "_withdrawAsset", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address payable", - "name": "_to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_value", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "_data", - "type": "bytes" - } - ], - "name": "_withdrawFRA", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [ { @@ -468,46 +398,6 @@ "stateMutability": "pure", "type": "function" }, - { - "inputs": [], - "name": "consumeMint", - "outputs": [ - { - "components": [ - { - "internalType": "bytes32", - "name": "asset", - "type": "bytes32" - }, - { - "internalType": "bytes", - "name": "receiver", - "type": "bytes" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "uint8", - "name": "decimal", - "type": "uint8" - }, - { - "internalType": "uint256", - "name": "max_supply", - "type": "uint256" - } - ], - "internalType": "struct PrismXXBridge.MintOp[]", - "name": "", - "type": "tuple[]" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [ { @@ -597,59 +487,14 @@ }, { "inputs": [], - "name": "ledger_contract", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "ops", - "outputs": [ - { - "internalType": "bytes32", - "name": "asset", - "type": "bytes32" - }, - { - "internalType": "bytes", - "name": "receiver", - "type": "bytes" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "uint8", - "name": "decimal", - "type": "uint8" - }, - { - "internalType": "uint256", - "name": "max_supply", - "type": "uint256" - } - ], - "stateMutability": "view", + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], - "name": "owner", + "name": "ledger_contract", "outputs": [ { "internalType": "address", @@ -662,7 +507,7 @@ }, { "inputs": [], - "name": "proxy_contract", + "name": "owner", "outputs": [ { "internalType": "address", @@ -728,24 +573,19 @@ }, { "inputs": [ - { - "internalType": "bytes", - "name": "_from", - "type": "bytes" - }, { "internalType": "address payable", - "name": "_to", + "name": "to", "type": "address" }, { "internalType": "uint256", - "name": "_value", + "name": "value", "type": "uint256" }, { "internalType": "bytes", - "name": "_data", + "name": "data", "type": "bytes" } ], @@ -758,4 +598,4 @@ "stateMutability": "payable", "type": "receive" } -] +] \ No newline at end of file diff --git a/src/components/contracts/modules/evm/src/lib.rs b/src/components/contracts/modules/evm/src/lib.rs index 3839482c32..45e9d916fe 100644 --- a/src/components/contracts/modules/evm/src/lib.rs +++ b/src/components/contracts/modules/evm/src/lib.rs @@ -12,7 +12,6 @@ pub mod system_contracts; pub mod utils; use abci::{RequestQuery, ResponseQuery}; -use config::abci::global_cfg::CFG; use ethabi::Token; use ethereum_types::{Bloom, BloomInput, H160, H256, U256}; use fp_core::{ @@ -37,7 +36,7 @@ use ethereum::{ }; use fp_types::{ - actions::{evm::Action, xhub::NonConfidentialOutput}, + actions::evm::Action, crypto::{Address, HA160}, }; use noah::xfr::sig::XfrPublicKey; @@ -46,7 +45,8 @@ use precompile::PrecompileSet; use ruc::*; use runtime::runner::ActionRunner; use std::marker::PhantomData; -use system_contracts::SystemContracts; +use std::str::FromStr; +use system_contracts::{SystemContracts, SYSTEM_ADDR}; pub use runtime::*; @@ -127,7 +127,7 @@ impl App { .encode_input(&[asset, from, to, value, lowlevel]) .c(d!())?; - let from = H160::zero(); + let from = H160::from_str(SYSTEM_ADDR).unwrap(); let gas_limit = 9999999; let value = U256::zero(); @@ -161,7 +161,7 @@ impl App { pub fn withdraw_fra( &self, ctx: &Context, - from: &XfrPublicKey, + _from: &XfrPublicKey, to: &H160, _value: U256, _lowlevel: Vec, @@ -170,23 +170,19 @@ impl App { ) -> Result<(TransactionV0, TransactionStatus, Receipt)> { let function = self.contracts.bridge.function("withdrawFRA").c(d!())?; - let from = Token::Bytes(from.noah_to_bytes()); - // let to = Token::Address(H160::from_slice(&bytes[4..24])); let to = Token::Address(*to); let value = Token::Uint(_value); let lowlevel = Token::Bytes(_lowlevel); - // println!("{:?}, {:?}, {:?}, {:?}", from, to, value, lowlevel); + //println!("{:?}, {:?}, {:?}, {:?}", from, to, value, lowlevel); - let input = function - .encode_input(&[from, to, value, lowlevel]) - .c(d!())?; + let input = function.encode_input(&[to, value, lowlevel]).c(d!())?; let gas_limit = 9999999; let value = U256::zero(); let gas_price = U256::one(); - let from = H160::zero(); + let from = H160::from_str(SYSTEM_ADDR).unwrap(); let (_, logs, used_gas) = ActionRunner::::execute_systemc_contract( ctx, @@ -214,22 +210,6 @@ impl App { )) } - pub fn consume_mint(&self, ctx: &Context) -> Vec { - let height = CFG.checkpoint.prismxx_inital_height; - - let mut pending_outputs = Vec::new(); - - if height < ctx.header.height { - if let Err(e) = - utils::fetch_mint::(ctx, &self.contracts, &mut pending_outputs) - { - tracing::error!("Collect mint ops error: {:?}", e); - } - } - - pending_outputs - } - fn logs_bloom(logs: &[ethereum::Log], bloom: &mut Bloom) { for log in logs { bloom.accrue(BloomInput::Raw(&log.address[..])); @@ -316,31 +296,7 @@ impl AppModule for App { } } - fn begin_block(&mut self, ctx: &mut Context, _req: &abci::RequestBeginBlock) { - let height = CFG.checkpoint.prismxx_inital_height; - - if ctx.header.height == height { - let bytecode_str = include_str!("../contracts/PrismXXProxy.bytecode"); - - if let Err(e) = - utils::deploy_contract::(ctx, &self.contracts, bytecode_str) - { - pd!(e); - return; - } - println!( - "Bridge contract address: {:?}", - self.contracts.bridge_address - ); - - if !ctx.state.write().cache_mut().good2_commit() { - ctx.state.write().discard_session(); - pd!(eg!("ctx state commit no good")); - } else { - ctx.state.write().commit_session(); - } - } - } + fn begin_block(&mut self, _ctx: &mut Context, _req: &abci::RequestBeginBlock) {} } impl Executable for App { diff --git a/src/components/contracts/modules/evm/src/system_contracts.rs b/src/components/contracts/modules/evm/src/system_contracts.rs index b910d3083a..57c39cd99a 100644 --- a/src/components/contracts/modules/evm/src/system_contracts.rs +++ b/src/components/contracts/modules/evm/src/system_contracts.rs @@ -2,49 +2,28 @@ use std::str::FromStr; use config::abci::global_cfg::CFG; use ethabi::Contract; -use ethereum_types::{H160, H256}; -use fp_utils::hashing::keccak_256; +use ethereum_types::H160; use ruc::*; use serde::{Deserialize, Serialize}; -use crate::utils; +pub static SYSTEM_ADDR: &str = "0x0000000000000000000000000000000000002000"; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct SystemContracts { pub bridge: Contract, pub bridge_address: H160, - pub owner: H160, - pub salt: H256, } impl SystemContracts { pub fn new() -> Result { let abi_str = include_str!("../contracts/PrismXXBridge.abi.json"); let bridge = Contract::load(abi_str.as_bytes()).c(d!())?; - - let owner = - H160::from_str("0x72488bAa718F52B76118C79168E55c209056A2E6").c(d!())?; - - let salt = H256::zero(); - - let bridge_address = if CFG.checkpoint.prism_bridge_address.is_empty() { - // Driect use this bytecode, beacuse we will remove on mainnet - let bytecode_str = include_str!("../contracts/PrismXXProxy.bytecode"); - - let bytecode = hex::decode(bytecode_str[2..].trim()).c(d!())?; - - let code_hash = keccak_256(&bytecode); - - utils::compute_create2(owner, salt, H256::from_slice(&code_hash)) - } else { - H160::from_str(&CFG.checkpoint.prism_bridge_address).c(d!())? - }; + let bridge_address = + H160::from_str(&CFG.checkpoint.prism_bridge_address).unwrap_or_default(); Ok(Self { bridge, bridge_address, - owner, - salt, }) } } diff --git a/src/components/contracts/modules/evm/src/utils.rs b/src/components/contracts/modules/evm/src/utils.rs index 526fde4a00..386826560b 100644 --- a/src/components/contracts/modules/evm/src/utils.rs +++ b/src/components/contracts/modules/evm/src/utils.rs @@ -1,137 +1,104 @@ -use ethabi::Token; -use ethereum_types::{H160, H256, U256}; -use fp_core::context::Context; +use ethabi::{Event, EventParam, ParamType, RawLog}; use fp_traits::evm::{DecimalsMapping, EthereumDecimalsMapping}; use fp_types::actions::xhub::NonConfidentialOutput; use ledger::data_model::ASSET_TYPE_FRA; +use noah::xfr::structs::ASSET_TYPE_LENGTH; use noah::xfr::{sig::XfrPublicKey, structs::AssetType}; use noah_algebra::serialization::NoahFromToBytes; use ruc::*; -use sha3::{Digest, Keccak256}; -use crate::{runner::ActionRunner, system_contracts::SystemContracts, Config}; - -pub fn deploy_contract( - ctx: &Context, - contracts: &SystemContracts, - bytecode_str: &str, -) -> Result<()> { - // Deploy Bridge here. - let bytecode = hex::decode(bytecode_str[2..].trim()).c(d!())?; - - ActionRunner::::inital_system_contract( - ctx, - bytecode, - 9999999999, - contracts.owner, - contracts.salt, - )?; - - Ok(()) -} - -pub fn fetch_mint( - ctx: &Context, - contracts: &SystemContracts, - outputs: &mut Vec, -) -> Result<()> { - let function = contracts.bridge.function("consumeMint").c(d!())?; - let input = function.encode_input(&[]).c(d!())?; - - let source = H160::zero(); - let target = contracts.bridge_address; - - let (ret, _, _) = ActionRunner::::execute_systemc_contract( - ctx, - input, - source, - 99999999, - target, - U256::zero(), - ) - .c(d!())?; - - let result = function.decode_output(&ret).c(d!())?; - - for v1 in result { - if let Token::Array(tokens) = v1 { - for token in tokens { - if let Token::Tuple(tuple) = token { - let output = parse_truple_result(tuple)?; - - tracing::info!("Got issue output: {:?}", output); - - outputs.push(output); - } - } - } +pub fn deposit_asset_event() -> Event { + Event { + name: "DepositAsset".to_owned(), + inputs: vec![ + EventParam { + name: "asset".to_owned(), + kind: ParamType::FixedBytes(32), + indexed: false, + }, + EventParam { + name: "receiver".to_owned(), + kind: ParamType::Bytes, + indexed: false, + }, + EventParam { + name: "amount".to_owned(), + kind: ParamType::Uint(256), + indexed: false, + }, + EventParam { + name: "decimal".to_owned(), + kind: ParamType::Uint(8), + indexed: false, + }, + EventParam { + name: "max_supply".to_owned(), + kind: ParamType::Uint(256), + indexed: false, + }, + ], + anonymous: false, } - - Ok(()) } -fn parse_truple_result(tuple: Vec) -> Result { - let asset = if let Token::FixedBytes(bytes) = - tuple.get(0).ok_or(eg!("Asset Must be FixedBytes"))? - { - let mut inner = [0u8; 32]; - - inner.copy_from_slice(bytes); - - AssetType(inner) - } else { - return Err(eg!("Asset Must be FixedBytes")); - }; +pub fn deposit_asset_event_topic_str() -> String { + let topic = deposit_asset_event().signature(); + let temp = hex::encode(topic.as_bytes()); + "[0x".to_owned() + &*temp + &*"]".to_owned() +} - let target = if let Token::Bytes(bytes) = - tuple.get(1).ok_or(eg!("Target must be FixedBytes"))? - { - XfrPublicKey::noah_from_bytes(bytes)? - } else { - return Err(eg!("Asset Must be FixedBytes")); +pub fn parse_deposit_asset_event(data: Vec) -> Result { + let event = deposit_asset_event(); + let log = RawLog { + topics: vec![event.signature()], + data, }; - - let amount = - if let Token::Uint(i) = tuple.get(2).ok_or(eg!("No asset in index 2"))? { - i - } else { - return Err(eg!("Amount must be uint")); - }; - - let amount = if asset == ASSET_TYPE_FRA { - EthereumDecimalsMapping::convert_to_native_token(*amount).as_u64() + let result = event.parse_log(log).c(d!())?; + + let asset = result.params[0] + .value + .clone() + .into_fixed_bytes() + .unwrap_or_default(); + let mut temp = [0u8; ASSET_TYPE_LENGTH]; + temp.copy_from_slice(asset.as_slice()); + let asset_type = AssetType(temp); + + let receiver = result.params[1] + .value + .clone() + .into_bytes() + .unwrap_or_default(); + let target = XfrPublicKey::noah_from_bytes(receiver.as_slice()).unwrap_or_default(); + + let amount = result.params[2] + .value + .clone() + .into_uint() + .unwrap_or_default(); + + let amount = if asset_type == ASSET_TYPE_FRA { + EthereumDecimalsMapping::convert_to_native_token(amount).as_u64() } else { amount.as_u64() }; - let decimal = - if let Token::Uint(decimal) = tuple.get(3).ok_or(eg!("No asset in index 3"))? { - decimal.as_u64() as u8 - } else { - return Err(eg!("Decimal must be uint")); - }; - - let max_supply = - if let Token::Uint(num) = tuple.get(4).ok_or(eg!("No asset in index 4"))? { - num.as_u64() - } else { - return Err(eg!("Max supply must be uint")); - }; + let decimal = result.params[3] + .value + .clone() + .into_uint() + .unwrap_or_default(); + let max_supply = result.params[4] + .value + .clone() + .into_uint() + .unwrap_or_default(); Ok(NonConfidentialOutput { - asset, + asset: asset_type, amount, target, - decimal, - max_supply, + decimal: decimal.as_u64() as u8, + max_supply: max_supply.as_u64(), }) } - -pub fn compute_create2(caller: H160, salt: H256, code_hash: H256) -> H160 { - let mut hasher = Keccak256::new(); - hasher.update([0xff]); - hasher.update(&caller[..]); - hasher.update(&salt[..]); - hasher.update(&code_hash[..]); - H256::from_slice(hasher.finalize().as_slice()).into() -} From c3fa3fcd63f7b6893e095f64347d25f0b885414a Mon Sep 17 00:00:00 2001 From: HarryLiIsMe <42673017+HarryLiIsMe@users.noreply.github.com> Date: Mon, 30 Jan 2023 14:15:42 +0800 Subject: [PATCH 3/6] prism bridge asdress update (#798) Co-authored-by: harry --- src/components/config/src/abci/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/config/src/abci/mod.rs b/src/components/config/src/abci/mod.rs index 12428ea4a6..669233601a 100644 --- a/src/components/config/src/abci/mod.rs +++ b/src/components/config/src/abci/mod.rs @@ -122,7 +122,7 @@ impl CheckPointConfig { utxo_asset_prefix_height: 0, nonce_bug_fix_height: 0, prism_bridge_address: - "0xfcfe4ff1006a7721cee870b56ee2b5c250aec13b" + "0x5f9552fEd754F20B636C996DaDB32806554Bb995" .to_owned(), proper_gas_set_height: 0, fix_delegators_am_height: 0, From faebb770a0d353435e76a827beaa3a617db1f4e0 Mon Sep 17 00:00:00 2001 From: HarryLiIsMe <42673017+HarryLiIsMe@users.noreply.github.com> Date: Tue, 31 Jan 2023 10:16:04 +0800 Subject: [PATCH 4/6] fix lint error (#800) Co-authored-by: harry --- .../abciapp/src/abci/server/callback/mod.rs | 4 +- .../abciapp/src/abci/server/tx_sender.rs | 2 +- .../src/api/query_server/query_api/mod.rs | 2 +- .../api/submission_server/submission_api.rs | 2 +- src/components/abciapp/src/bins/findorad.rs | 6 +- src/components/config/src/abci/mod.rs | 10 +- src/components/contracts/baseapp/src/app.rs | 18 +- src/components/contracts/baseapp/src/lib.rs | 6 +- .../contracts/baseapp/src/modules.rs | 2 +- .../contracts/modules/account/src/impls.rs | 2 +- .../contracts/modules/account/src/tests.rs | 4 +- .../contracts/modules/ethereum/src/impls.rs | 4 +- .../contracts/modules/ethereum/src/lib.rs | 3 +- .../modules/ethereum/tests/ethereum_db.rs | 4 +- .../ethereum/tests/ethereum_integration.rs | 2 +- .../modules/evm/precompile/frc20/src/lib.rs | 8 +- .../evm/precompile/sha3fips/src/lib.rs | 8 +- .../modules/evm/precompile/utils/src/tests.rs | 2 +- .../contracts/modules/evm/src/precompile.rs | 8 +- .../modules/evm/tests/evm_integration.rs | 14 +- .../modules/evm/tests/utils/solidity.rs | 4 +- .../contracts/primitives/evm/src/lib.rs | 2 +- .../contracts/primitives/mocks/src/lib.rs | 2 +- .../rpc-core/src/types/block_number.rs | 11 +- .../primitives/rpc-core/src/types/bytes.rs | 2 +- .../primitives/rpc-core/src/types/filter.rs | 2 +- .../primitives/rpc-core/src/types/index.rs | 4 +- .../primitives/rpc-core/src/types/pubsub.rs | 2 +- .../contracts/primitives/storage/src/tests.rs | 2 +- .../contracts/primitives/utils/src/ecdsa.rs | 11 +- .../contracts/primitives/wasm/src/wasm.rs | 8 +- src/components/contracts/rpc/src/eth.rs | 31 ++-- .../contracts/rpc/src/eth_filter.rs | 12 +- src/components/contracts/rpc/src/lib.rs | 6 +- src/components/contracts/rpc/src/utils.rs | 4 +- .../finutils/src/bins/cfg_generator.rs | 3 +- src/components/finutils/src/bins/fn.rs | 10 +- .../finutils/src/bins/stt/init/i_testing.rs | 2 +- .../finutils/src/bins/stt/init/mod.rs | 2 +- src/components/finutils/src/bins/stt/stt.rs | 8 +- .../finutils/src/common/ddev/init.rs | 6 +- .../finutils/src/common/ddev/mod.rs | 2 +- src/components/finutils/src/common/dev/mod.rs | 2 +- src/components/finutils/src/common/mod.rs | 33 ++-- src/components/finutils/src/common/utils.rs | 2 +- .../finutils/src/txn_builder/mod.rs | 7 +- src/ledger/src/data_model/mod.rs | 7 +- src/ledger/src/data_model/test.rs | 2 +- src/ledger/src/staking/cosig.rs | 2 +- src/ledger/src/staking/mod.rs | 5 +- src/ledger/src/store/api_cache.rs | 54 +++--- src/ledger/src/store/helpers.rs | 2 +- src/ledger/src/store/mod.rs | 9 +- src/libs/bitmap/src/lib.rs | 13 +- src/libs/bitmap/src/test.rs | 20 +-- src/libs/globutils/src/lib.rs | 4 +- src/libs/globutils/src/logging.rs | 6 +- src/libs/merkle_tree/src/lib.rs | 159 ++++++++---------- src/libs/sliding_set/src/lib.rs | 5 +- src/libs/sparse_merkle_tree/src/lib.rs | 4 +- 60 files changed, 271 insertions(+), 312 deletions(-) diff --git a/src/components/abciapp/src/abci/server/callback/mod.rs b/src/components/abciapp/src/abci/server/callback/mod.rs index fec71386e2..dd5244bdf7 100644 --- a/src/components/abciapp/src/abci/server/callback/mod.rs +++ b/src/components/abciapp/src/abci/server/callback/mod.rs @@ -278,11 +278,11 @@ pub fn deliver_tx( if let Err(err) = s.account_base_app.write().deliver_findora_tx(&txn, &hash.0) { - tracing::error!(target: "abciapp", "deliver convert account tx failed: {:?}", err); + tracing::error!(target: "abciapp", "deliver convert account tx failed: {err:?}", ); resp.code = 1; resp.log = - format!("deliver convert account tx failed: {:?}", err); + format!("deliver convert account tx failed: {err:?}",); return resp; } diff --git a/src/components/abciapp/src/abci/server/tx_sender.rs b/src/components/abciapp/src/abci/server/tx_sender.rs index 13dbb354a7..0382234e67 100644 --- a/src/components/abciapp/src/abci/server/tx_sender.rs +++ b/src/components/abciapp/src/abci/server/tx_sender.rs @@ -50,7 +50,7 @@ pub fn forward_txn_with_mode( ) }; - let tendermint_reply = format!("http://{}", url); + let tendermint_reply = format!("http://{url}",); if 2000 > TX_PENDING_CNT.fetch_add(1, Ordering::Relaxed) { POOL.spawn_ok(async move { ruc::info_omit!(attohttpc::post(&tendermint_reply) diff --git a/src/components/abciapp/src/api/query_server/query_api/mod.rs b/src/components/abciapp/src/api/query_server/query_api/mod.rs index e799d2cb90..617f4d2475 100644 --- a/src/components/abciapp/src/api/query_server/query_api/mod.rs +++ b/src/components/abciapp/src/api/query_server/query_api/mod.rs @@ -803,7 +803,7 @@ impl QueryApi { }); for (host, port) in addrs.iter() { - hdr = hdr.bind(&format!("{}:{}", host, port)).c(d!())? + hdr = hdr.bind(&format!("{host}:{port}")).c(d!())? } hdr.run(); diff --git a/src/components/abciapp/src/api/submission_server/submission_api.rs b/src/components/abciapp/src/api/submission_server/submission_api.rs index bc8b690f22..4c67684b3f 100644 --- a/src/components/abciapp/src/api/submission_server/submission_api.rs +++ b/src/components/abciapp/src/api/submission_server/submission_api.rs @@ -130,7 +130,7 @@ impl SubmissionApi { web::get().to(txn_status::), ) }) - .bind(&format!("{}:{}", host, port)) + .bind(&format!("{host}:{port}",)) .c(d!())? .run(); diff --git a/src/components/abciapp/src/bins/findorad.rs b/src/components/abciapp/src/bins/findorad.rs index a9eaee0ab8..cf450af88c 100644 --- a/src/components/abciapp/src/bins/findorad.rs +++ b/src/components/abciapp/src/bins/findorad.rs @@ -123,10 +123,10 @@ fn node_command() -> Result<()> { ctrlc::set_handler(move || { //info_omit!(kill(Pid::from_raw(0), Signal::SIGINT)); pnk!(abcid_child.kill().c(d!())); - pnk!(abcid_child.wait().c(d!()).map(|s| println!("{}", s))); + pnk!(abcid_child.wait().c(d!()).map(|s| println!("{s}",))); pnk!(tendermint_child.kill()); - pnk!(tendermint_child.wait().c(d!()).map(|s| println!("{}", s))); + pnk!(tendermint_child.wait().c(d!()).map(|s| println!("{s}",))); pnk!(send.send(())); }) @@ -163,7 +163,7 @@ fn init_command() -> Result<()> { fn pack() -> Result<()> { let bin_path_orig = get_bin_path().c(d!())?; let bin_name = bin_path_orig.file_name().c(d!())?.to_str().c(d!())?; - let bin_path = format!("/tmp/{}", bin_name); + let bin_path = format!("/tmp/{bin_name}",); fs::copy(bin_path_orig, &bin_path).c(d!())?; let mut f = OpenOptions::new().append(true).open(bin_path).c(d!())?; diff --git a/src/components/config/src/abci/mod.rs b/src/components/config/src/abci/mod.rs index 669233601a..e4a94faee7 100644 --- a/src/components/config/src/abci/mod.rs +++ b/src/components/config/src/abci/mod.rs @@ -161,11 +161,11 @@ impl CheckPointConfig { return Some(config); } Err(error) => { - panic!("failed to create file: {:?}", error) + panic!("failed to create file: {error:?}",) } }; } else { - panic!("failed to open file: {:?}", error) + panic!("failed to open file: {error:?}",) } } }; @@ -451,7 +451,7 @@ pub mod global_cfg { .value_of("checkpoint-file") .map(|v| v.to_owned()) .unwrap_or_else(|| String::from("./checkpoint.toml")); - println!("{}", checkpoint_path); + println!("{checkpoint_path}",); let res = Config { abci_host: ah, @@ -558,7 +558,7 @@ pub mod global_cfg { .into_iter() .rev() .for_each(|h| { - println!(" {}", h); + println!(" {h}",); }); exit(0); } @@ -576,7 +576,7 @@ pub mod global_cfg { || m.is_present("snapshot-rollback-to") || m.is_present("snapshot-rollback-to-exact") { - println!("\x1b[31;01m\n{}\x1b[00m", HINTS); + println!("\x1b[31;01m\n{HINTS}\x1b[00m",); let (h, strict) = m .value_of("snapshot-rollback-to-exact") diff --git a/src/components/contracts/baseapp/src/app.rs b/src/components/contracts/baseapp/src/app.rs index 2211728ce7..5928bddbe4 100644 --- a/src/components/contracts/baseapp/src/app.rs +++ b/src/components/contracts/baseapp/src/app.rs @@ -50,7 +50,7 @@ impl crate::BaseApp { let ctx = self.create_query_context(Some(req.height as u64), req.prove); if let Err(e) = ctx { - return err_resp(format!("Cannot create query context with err: {}!", e)); + return err_resp(format!("Cannot create query context with err: {e}!",)); } match path.remove(0) { @@ -144,14 +144,14 @@ impl crate::BaseApp { } resp.code = ar.code; if ar.code != 0 { - info!(target: "baseapp", "Transaction check error, action result {:?}", ar); + info!(target: "baseapp", "Transaction check error, action result {ar:?}", ); resp.log = ar.log; } } Err(e) => { - info!(target: "baseapp", "Transaction check error: {}", e); + info!(target: "baseapp", "Transaction check error: {e}", ); resp.code = 1; - resp.log = format!("Transaction check error: {}", e); + resp.log = format!("Transaction check error: {e}",); } } }; @@ -294,9 +294,9 @@ impl crate::BaseApp { resp } Err(e) => { - error!(target: "baseapp", "Ethereum transaction deliver error: {}", e); + error!(target: "baseapp", "Ethereum transaction deliver error: {e}", ); resp.code = 1; - resp.log = format!("Ethereum transaction deliver error: {}", e); + resp.log = format!("Ethereum transaction deliver error: {e}",); resp } } @@ -334,8 +334,8 @@ impl crate::BaseApp { .write() .commit(block_height) .unwrap_or_else(|e| { - println!("{:?}", e); - panic!("Failed to commit chain state at height: {}", block_height) + println!("{e:?}",); + panic!("Failed to commit chain state at height: {block_height}",) }); // Commit module data based on root_hash @@ -347,7 +347,7 @@ impl crate::BaseApp { .write() .commit(block_height) .unwrap_or_else(|_| { - panic!("Failed to commit chain db at height: {}", block_height) + panic!("Failed to commit chain db at height: {block_height}",) }); // Reset the deliver state, but keep the ethereum cache diff --git a/src/components/contracts/baseapp/src/lib.rs b/src/components/contracts/baseapp/src/lib.rs index 05d003679d..3a899fe32c 100644 --- a/src/components/contracts/baseapp/src/lib.rs +++ b/src/components/contracts/baseapp/src/lib.rs @@ -310,7 +310,7 @@ impl BaseApp { } fn validate_height(&self, height: i64) -> Result<()> { - ensure!(height >= 1, format!("invalid height: {}", height)); + ensure!(height >= 1, format!("invalid height: {height}",)); let mut expected_height = self.chain_state.read().height().unwrap_or_default() as i64; if expected_height == 0 { @@ -320,7 +320,7 @@ impl BaseApp { } ensure!( height == expected_height, - format!("invalid height: {}; expected: {}", height, expected_height) + format!("invalid height: {height}; expected: {expected_height}") ); Ok(()) } @@ -356,7 +356,7 @@ impl BaseProvider for BaseApp { fn account_of(&self, who: &Address, height: Option) -> Result { let ctx = self.create_query_context(height, false)?; module_account::App::::account_of(&ctx, who, height) - .ok_or(eg!(format!("account does not exist: {}", who))) + .ok_or(eg!(format!("account does not exist: {who}",))) } fn current_block(&self, id: Option) -> Option { diff --git a/src/components/contracts/baseapp/src/modules.rs b/src/components/contracts/baseapp/src/modules.rs index f4982471cc..42d2d6346f 100644 --- a/src/components/contracts/baseapp/src/modules.rs +++ b/src/components/contracts/baseapp/src/modules.rs @@ -63,7 +63,7 @@ impl ModuleManager { self.template_module.query_route(ctx, path, req) } else { resp.code = 1; - resp.log = format!("Invalid query module route: {}!", module_name); + resp.log = format!("Invalid query module route: {module_name}!",); resp } } diff --git a/src/components/contracts/modules/account/src/impls.rs b/src/components/contracts/modules/account/src/impls.rs index c0ff983cf4..c4c64eb139 100644 --- a/src/components/contracts/modules/account/src/impls.rs +++ b/src/components/contracts/modules/account/src/impls.rs @@ -138,7 +138,7 @@ impl AccountAsset
for App { } let mut target_account = Self::account_of(ctx, target, None) - .c(d!(format!("account: {} does not exist", target)))?; + .c(d!(format!("account: {target} does not exist",)))?; target_account.balance = target_account .balance .checked_sub(balance) diff --git a/src/components/contracts/modules/account/src/tests.rs b/src/components/contracts/modules/account/src/tests.rs index 7d20c8733f..36c8c3322a 100644 --- a/src/components/contracts/modules/account/src/tests.rs +++ b/src/components/contracts/modules/account/src/tests.rs @@ -19,7 +19,7 @@ fn setup() -> Context { .unwrap() .as_nanos(); let mut path = temp_dir(); - path.push(format!("temp-findora-db–{}", time)); + path.push(format!("temp-findora-db–{time}",)); let fdb = FinDB::open(path).unwrap(); let chain_state = Arc::new(RwLock::new(ChainState::new( @@ -29,7 +29,7 @@ fn setup() -> Context { ))); let mut rocks_path = temp_dir(); - rocks_path.push(format!("temp-rocks-db–{}", time)); + rocks_path.push(format!("temp-rocks-db–{time}",)); let rdb = RocksDB::open(rocks_path).unwrap(); let chain_db = Arc::new(RwLock::new(ChainState::new( diff --git a/src/components/contracts/modules/ethereum/src/impls.rs b/src/components/contracts/modules/ethereum/src/impls.rs index 61654416b2..639098b04b 100644 --- a/src/components/contracts/modules/ethereum/src/impls.rs +++ b/src/components/contracts/modules/ethereum/src/impls.rs @@ -268,7 +268,7 @@ impl App { return Ok(ActionResult { code: 1, data: vec![], - log: format!("{}", e), + log: format!("{e}",), gas_wanted: gas_limit.low_u64(), gas_used: 0, events, @@ -343,7 +343,7 @@ impl App { let message_len = data[36..68].iter().sum::(); let body: &[u8] = &data[68..68 + message_len as usize]; if let Ok(reason) = std::str::from_utf8(body) { - message = format!("{} {}", message, reason); + message = format!("{message} {reason}"); } } (3, message) diff --git a/src/components/contracts/modules/ethereum/src/lib.rs b/src/components/contracts/modules/ethereum/src/lib.rs index 07c1803546..f329052388 100644 --- a/src/components/contracts/modules/ethereum/src/lib.rs +++ b/src/components/contracts/modules/ethereum/src/lib.rs @@ -228,8 +228,7 @@ impl ValidateUnsigned for App { let total_payment = transaction.value.saturating_add(fee); if balance < total_payment { return Err(eg!(format!( - "InsufficientBalance, origin: {:?}, actual balance {}, but expected payment {}", - origin, balance, total_payment + "InsufficientBalance, origin: {origin:?}, actual balance {balance}, but expected payment {total_payment}", ))); } diff --git a/src/components/contracts/modules/ethereum/tests/ethereum_db.rs b/src/components/contracts/modules/ethereum/tests/ethereum_db.rs index 1551e9a2f7..039159e9ac 100644 --- a/src/components/contracts/modules/ethereum/tests/ethereum_db.rs +++ b/src/components/contracts/modules/ethereum/tests/ethereum_db.rs @@ -18,7 +18,7 @@ fn setup() -> Context { .unwrap() .as_nanos(); let mut path = temp_dir(); - path.push(format!("temp-findora-db–{}", time)); + path.push(format!("temp-findora-db–{time}",)); let fdb = FinDB::open(path).unwrap(); let chain_state = Arc::new(RwLock::new(ChainState::new( @@ -28,7 +28,7 @@ fn setup() -> Context { ))); let mut rocks_path = temp_dir(); - rocks_path.push(format!("temp-rocks-db–{}", time)); + rocks_path.push(format!("temp-rocks-db–{time}",)); let rdb = RocksDB::open(rocks_path).unwrap(); let chain_db = Arc::new(RwLock::new(ChainState::new( diff --git a/src/components/contracts/modules/ethereum/tests/ethereum_integration.rs b/src/components/contracts/modules/ethereum/tests/ethereum_integration.rs index 2332c04e76..2fbc243841 100644 --- a/src/components/contracts/modules/ethereum/tests/ethereum_integration.rs +++ b/src/components/contracts/modules/ethereum/tests/ethereum_integration.rs @@ -114,7 +114,7 @@ fn test_abci_deliver_tx() { resp.code, resp.log ); - println!("transfer resp: {:?}", resp); + println!("transfer resp: {resp:?}",); // initial balance = 100_0000_0000_0000_0000_u64, gas limit = 21000, transfer balance = 10 assert_eq!( diff --git a/src/components/contracts/modules/evm/precompile/frc20/src/lib.rs b/src/components/contracts/modules/evm/precompile/frc20/src/lib.rs index 21a6fa2e31..2b083636e9 100644 --- a/src/components/contracts/modules/evm/precompile/frc20/src/lib.rs +++ b/src/components/contracts/modules/evm/precompile/frc20/src/lib.rs @@ -304,7 +304,7 @@ impl FRC20 { ); C::AccountAsset::approve(state, &caller, &spender_id, amount) - .map_err(|e| error(format!("{:?}", e)))?; + .map_err(|e| error(format!("{e:?}",)))?; Ok(PrecompileOutput { exit_status: ExitSucceed::Returned, @@ -349,7 +349,7 @@ impl FRC20 { ); C::AccountAsset::transfer(state, &caller, &recipient_id, amount) - .map_err(|e| error(format!("{:?}", e)))?; + .map_err(|e| error(format!("{e:?}",)))?; Ok(PrecompileOutput { exit_status: ExitSucceed::Returned, @@ -405,7 +405,7 @@ impl FRC20 { ); C::AccountAsset::transfer(state, &from_id, &recipient_id, amount) - .map_err(|e| error(format!("{:?}", e)))?; + .map_err(|e| error(format!("{e:?}",)))?; C::AccountAsset::approve( state, @@ -413,7 +413,7 @@ impl FRC20 { &caller, allowance.saturating_sub(amount), ) - .map_err(|e| error(format!("{:?}", e)))?; + .map_err(|e| error(format!("{e:?}",)))?; Ok(PrecompileOutput { exit_status: ExitSucceed::Returned, diff --git a/src/components/contracts/modules/evm/precompile/sha3fips/src/lib.rs b/src/components/contracts/modules/evm/precompile/sha3fips/src/lib.rs index 55d5e54932..8718f50d12 100644 --- a/src/components/contracts/modules/evm/precompile/sha3fips/src/lib.rs +++ b/src/components/contracts/modules/evm/precompile/sha3fips/src/lib.rs @@ -89,7 +89,7 @@ mod tests { Ok(()) } Err(e) => { - panic!("Test not expected to fail: {:?}", e); + panic!("Test not expected to fail: {e:?}",); } } } @@ -110,7 +110,7 @@ mod tests { Ok(()) } Err(e) => { - panic!("Test not expected to fail: {:?}", e); + panic!("Test not expected to fail: {e:?}",); } } } @@ -131,7 +131,7 @@ mod tests { Ok(()) } Err(e) => { - panic!("Test not expected to fail: {:?}", e); + panic!("Test not expected to fail: {e:?}",); } } } @@ -154,7 +154,7 @@ mod tests { Ok(()) } Err(e) => { - panic!("Test not expected to fail: {:?}", e); + panic!("Test not expected to fail: {e:?}",); } } } diff --git a/src/components/contracts/modules/evm/precompile/utils/src/tests.rs b/src/components/contracts/modules/evm/precompile/utils/src/tests.rs index f00e0e2c79..6ac27929f0 100644 --- a/src/components/contracts/modules/evm/precompile/utils/src/tests.rs +++ b/src/components/contracts/modules/evm/precompile/utils/src/tests.rs @@ -379,7 +379,7 @@ fn write_address_nested_array() { writer_output .chunks_exact(32) .map(H256::from_slice) - .for_each(|hash| println!("{:?}", hash)); + .for_each(|hash| println!("{hash:?}",)); // We can read this "manualy" using simpler functions since arrays are 32-byte aligned. let mut reader = EvmDataReader::new(&writer_output); diff --git a/src/components/contracts/modules/evm/src/precompile.rs b/src/components/contracts/modules/evm/src/precompile.rs index 828a067bec..54e8b8229a 100644 --- a/src/components/contracts/modules/evm/src/precompile.rs +++ b/src/components/contracts/modules/evm/src/precompile.rs @@ -17,12 +17,12 @@ pub trait PrecompileSet { /// Otherwise, calculate the amount of gas needed with given `input` and /// `target_gas`. Return `Some(Ok(status, output, gas_used))` if the execution /// is successful. Otherwise return `Some(Err(_))`. - fn execute<'context, 'vicinity, 'config, T>( + fn execute( address: H160, input: &[u8], target_gas: Option, context: &Context, - state: &mut FindoraStackState<'context, 'vicinity, 'config, T>, + state: &mut FindoraStackState<'_, '_, '_, T>, is_static: bool, ) -> Option; } @@ -53,12 +53,12 @@ pub trait PrecompileId { impl PrecompileSet for Tuple { for_tuples!( where #( Tuple: Precompile + PrecompileId )* ); - fn execute<'context, 'vicinity, 'config, T>( + fn execute( address: H160, input: &[u8], target_gas: Option, context: &Context, - state: &mut FindoraStackState<'context, 'vicinity, 'config, T>, + state: &mut FindoraStackState<'_, '_, '_, T>, _is_static: bool, ) -> Option { for_tuples!( #( diff --git a/src/components/contracts/modules/evm/tests/evm_integration.rs b/src/components/contracts/modules/evm/tests/evm_integration.rs index 7f6163ce2f..24e4fc1886 100644 --- a/src/components/contracts/modules/evm/tests/evm_integration.rs +++ b/src/components/contracts/modules/evm/tests/evm_integration.rs @@ -131,7 +131,7 @@ fn test_deploy_deliver_tx() -> (H160, ethabi::Contract) { resp.code, resp.log ); - println!("deploy erc20 result: {:?}\n", resp); + println!("deploy erc20 result: {resp:?}\n",); let info = serde_json::from_slice::(&resp.data).unwrap(); if let CallOrCreateInfo::Create(info) = info { @@ -144,7 +144,7 @@ fn test_deploy_deliver_tx() -> (H160, ethabi::Contract) { println!("erc20 contract address: {:?}\n", info.value); (info.value, contract_abi) } else { - panic!("not expected result: {:?}", info) + panic!("not expected result: {info:?}",) } } @@ -197,7 +197,7 @@ fn test_mint_deliver_tx(contract: ERC20) { resp.code, resp.log ); - println!("call erc20 mint result: {:?}\n", resp); + println!("call erc20 mint result: {resp:?}\n",); } fn test_transfer_check_tx(contract: ERC20) { @@ -239,7 +239,7 @@ fn test_transfer_deliver_tx(contract: ERC20) { resp.code, resp.log ); - println!("call erc20 transfer result: {:?}\n", resp); + println!("call erc20 transfer result: {resp:?}\n",); } fn test_balance_of_deliver_tx(contract: ERC20, who: H160) -> U256 { @@ -255,7 +255,7 @@ fn test_balance_of_deliver_tx(contract: ERC20, who: H160) -> U256 { resp.code, resp.log ); - println!("call erc20 balanceOf result: {:?}\n", resp); + println!("call erc20 balanceOf result: {resp:?}\n",); let info = serde_json::from_slice::(&resp.data).unwrap(); if let CallOrCreateInfo::Call(info) = info { @@ -267,7 +267,7 @@ fn test_balance_of_deliver_tx(contract: ERC20, who: H160) -> U256 { U256::from_big_endian(info.value.as_ref()) } else { - panic!("not expected result: {:?}", info) + panic!("not expected result: {info:?}",) } } @@ -297,7 +297,7 @@ fn test_balance_of_with_eth_call(contract: ERC20, who: H160) -> U256 { ) .unwrap(); - println!("eth call erc20 balanceOf result: {:?}\n", info); + println!("eth call erc20 balanceOf result: {info:?}\n",); U256::from_big_endian(info.value.as_ref()) } diff --git a/src/components/contracts/modules/evm/tests/utils/solidity.rs b/src/components/contracts/modules/evm/tests/utils/solidity.rs index 6fda0f06f1..64728b4ca9 100644 --- a/src/components/contracts/modules/evm/tests/utils/solidity.rs +++ b/src/components/contracts/modules/evm/tests/utils/solidity.rs @@ -28,8 +28,8 @@ impl ContractConstructor { P2: AsRef, P3: AsRef, { - let bin_file = format!("{}.bin", contract_name); - let abi_file = format!("{}.abi", contract_name); + let bin_file = format!("{contract_name}.bin",); + let abi_file = format!("{contract_name}.abi",); let hex_path = artifacts_base_path.as_ref().join(bin_file); let hex_rep = match std::fs::read_to_string(&hex_path) { Ok(hex) => hex, diff --git a/src/components/contracts/primitives/evm/src/lib.rs b/src/components/contracts/primitives/evm/src/lib.rs index 2b972ea600..172c098a7c 100644 --- a/src/components/contracts/primitives/evm/src/lib.rs +++ b/src/components/contracts/primitives/evm/src/lib.rs @@ -79,6 +79,6 @@ impl BlockId { impl core::fmt::Display for BlockId { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - write!(f, "{:?}", self) + write!(f, "{self:?}",) } } diff --git a/src/components/contracts/primitives/mocks/src/lib.rs b/src/components/contracts/primitives/mocks/src/lib.rs index f88cac0081..e34b7fdd1d 100644 --- a/src/components/contracts/primitives/mocks/src/lib.rs +++ b/src/components/contracts/primitives/mocks/src/lib.rs @@ -79,7 +79,7 @@ pub fn create_temp_db_path() -> PathBuf { .unwrap() .as_nanos(); let mut path = temp_dir(); - path.push(format!("temp-findora-db–{}", time)); + path.push(format!("temp-findora-db–{time}",)); path } diff --git a/src/components/contracts/primitives/rpc-core/src/types/block_number.rs b/src/components/contracts/primitives/rpc-core/src/types/block_number.rs index c94fc31a81..9a2523bb18 100644 --- a/src/components/contracts/primitives/rpc-core/src/types/block_number.rs +++ b/src/components/contracts/primitives/rpc-core/src/types/block_number.rs @@ -76,10 +76,9 @@ impl Serialize for BlockNumber { hash, require_canonical, } => serializer.serialize_str(&format!( - "{{ 'hash': '{}', 'requireCanonical': '{}' }}", - hash, require_canonical + "{{ 'hash': '{hash}', 'requireCanonical': '{require_canonical}' }}", )), - BlockNumber::Num(ref x) => serializer.serialize_str(&format!("0x{:x}", x)), + BlockNumber::Num(ref x) => serializer.serialize_str(&format!("0x{x:x}",)), BlockNumber::Latest => serializer.serialize_str("latest"), BlockNumber::Earliest => serializer.serialize_str("earliest"), BlockNumber::Pending => serializer.serialize_str("pending"), @@ -116,7 +115,7 @@ impl<'a> Visitor<'a> for BlockNumberVisitor { "pending" => Ok(BlockNumber::Pending), _ if value.starts_with("0x") => u64::from_str_radix(&value[2..], 16) .map(BlockNumber::Num) - .map_err(|e| Error::custom(format!("Invalid block number: {}", e))), + .map_err(|e| Error::custom(format!("Invalid block number: {e}",))), _ => value.parse::().map(BlockNumber::Num).map_err(|_| { Error::custom( "Invalid block number: non-decimal or missing 0x prefix".to_string(), @@ -148,7 +147,7 @@ impl<'a> Visitor<'a> for BlockNumberVisitor { let value: String = visitor.next_value()?; if let Some(v) = value.strip_prefix("0x") { let number = u64::from_str_radix(v, 16).map_err(|e| { - Error::custom(format!("Invalid block number: {}", e)) + Error::custom(format!("Invalid block number: {e}",)) })?; block_number = Some(number); @@ -165,7 +164,7 @@ impl<'a> Visitor<'a> for BlockNumberVisitor { "requireCanonical" => { require_canonical = visitor.next_value()?; } - key => return Err(Error::custom(format!("Unknown key: {}", key))), + key => return Err(Error::custom(format!("Unknown key: {key}",))), }, None => break, }; diff --git a/src/components/contracts/primitives/rpc-core/src/types/bytes.rs b/src/components/contracts/primitives/rpc-core/src/types/bytes.rs index 4aae0b7c38..d330ee5f57 100644 --- a/src/components/contracts/primitives/rpc-core/src/types/bytes.rs +++ b/src/components/contracts/primitives/rpc-core/src/types/bytes.rs @@ -85,7 +85,7 @@ impl<'a> Visitor<'a> for BytesVisitor { { if value.len() >= 2 && value.starts_with("0x") && value.len() & 1 == 0 { Ok(Bytes::new(FromHex::from_hex(&value[2..]).map_err(|e| { - Error::custom(format!("Invalid hex: {}", e)) + Error::custom(format!("Invalid hex: {e}",)) })?)) } else { Err(Error::custom( diff --git a/src/components/contracts/primitives/rpc-core/src/types/filter.rs b/src/components/contracts/primitives/rpc-core/src/types/filter.rs index c3d3b2221b..2b800e5400 100644 --- a/src/components/contracts/primitives/rpc-core/src/types/filter.rs +++ b/src/components/contracts/primitives/rpc-core/src/types/filter.rs @@ -59,7 +59,7 @@ where .map(VariadicValue::Single) .or_else(|_| from_value(v).map(VariadicValue::Multiple)) .map_err(|err| { - D::Error::custom(format!("Invalid variadic value type: {}", err)) + D::Error::custom(format!("Invalid variadic value type: {err}",)) }) } } diff --git a/src/components/contracts/primitives/rpc-core/src/types/index.rs b/src/components/contracts/primitives/rpc-core/src/types/index.rs index 30fcf63cb4..a3cd285520 100644 --- a/src/components/contracts/primitives/rpc-core/src/types/index.rs +++ b/src/components/contracts/primitives/rpc-core/src/types/index.rs @@ -56,11 +56,11 @@ impl<'a> Visitor<'a> for IndexVisitor { match value { _ if value.starts_with("0x") => usize::from_str_radix(&value[2..], 16) .map(Index) - .map_err(|e| Error::custom(format!("Invalid index: {}", e))), + .map_err(|e| Error::custom(format!("Invalid index: {e}",))), _ => value .parse::() .map(Index) - .map_err(|e| Error::custom(format!("Invalid index: {}", e))), + .map_err(|e| Error::custom(format!("Invalid index: {e}",))), } } diff --git a/src/components/contracts/primitives/rpc-core/src/types/pubsub.rs b/src/components/contracts/primitives/rpc-core/src/types/pubsub.rs index c9c7b5c1e0..2b28359d38 100644 --- a/src/components/contracts/primitives/rpc-core/src/types/pubsub.rs +++ b/src/components/contracts/primitives/rpc-core/src/types/pubsub.rs @@ -105,7 +105,7 @@ impl<'a> Deserialize<'a> for Params { from_value(v) .map(Params::Logs) - .map_err(|e| D::Error::custom(format!("Invalid Pub-Sub parameters: {}", e))) + .map_err(|e| D::Error::custom(format!("Invalid Pub-Sub parameters: {e}",))) } } diff --git a/src/components/contracts/primitives/storage/src/tests.rs b/src/components/contracts/primitives/storage/src/tests.rs index b67602afaf..b8e031abe7 100644 --- a/src/components/contracts/primitives/storage/src/tests.rs +++ b/src/components/contracts/primitives/storage/src/tests.rs @@ -12,7 +12,7 @@ fn setup_temp_db() -> Arc>> { .unwrap() .as_nanos(); let mut path = temp_dir(); - path.push(format!("temp-findora-db–{}", time)); + path.push(format!("temp-findora-db–{time}",)); let fdb = TempFinDB::open(path).unwrap(); let chain_state = Arc::new(RwLock::new(ChainState::new( fdb, diff --git a/src/components/contracts/primitives/utils/src/ecdsa.rs b/src/components/contracts/primitives/utils/src/ecdsa.rs index 4e71af6244..6bbf4fecdf 100644 --- a/src/components/contracts/primitives/utils/src/ecdsa.rs +++ b/src/components/contracts/primitives/utils/src/ecdsa.rs @@ -73,9 +73,8 @@ impl<'de> Deserialize<'de> for Public { { let pk = base64::decode_config(String::deserialize(deserializer)?, base64::URL_SAFE) - .map_err(|e| de::Error::custom(format!("{:?}", e)))?; - Public::try_from(pk.as_slice()) - .map_err(|e| de::Error::custom(format!("{:?}", e))) + .map_err(|e| de::Error::custom(format!("{e:?}",)))?; + Public::try_from(pk.as_slice()).map_err(|e| de::Error::custom(format!("{e:?}",))) } } @@ -174,9 +173,9 @@ impl<'de> Deserialize<'de> for Signature { D: Deserializer<'de>, { let signature_hex = hex::decode(String::deserialize(deserializer)?) - .map_err(|e| de::Error::custom(format!("{:?}", e)))?; + .map_err(|e| de::Error::custom(format!("{e:?}",)))?; Signature::try_from(signature_hex.as_ref()) - .map_err(|e| de::Error::custom(format!("{:?}", e))) + .map_err(|e| de::Error::custom(format!("{e:?}",))) } } @@ -444,7 +443,7 @@ mod test { "2f8c6129d816cf51c374bc7f08c3e63ed156cf78aefb4a6550d97b87997977ee00000000000000000200d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a4500000000000000" ); let signature = pair.sign(&message[..]); - println!("Correct signature: {:?}", signature); + println!("Correct signature: {signature:?}",); assert!(SecpPair::verify(&signature, &message[..], &public)); assert!(!SecpPair::verify(&signature, "Other message", &public)); } diff --git a/src/components/contracts/primitives/wasm/src/wasm.rs b/src/components/contracts/primitives/wasm/src/wasm.rs index f587e244c4..08b31bdbe8 100644 --- a/src/components/contracts/primitives/wasm/src/wasm.rs +++ b/src/components/contracts/primitives/wasm/src/wasm.rs @@ -47,7 +47,7 @@ pub fn recover_tx_signer(raw_tx: String) -> Result { .map_err(error_to_jsvalue)?; if let Action::Ethereum(EthAction::Transact(tx)) = unchecked_tx.function { let signer = recover_signer(&tx).c(d!()).map_err(error_to_jsvalue)?; - Ok(format!("{:?}", signer)) + Ok(format!("{signer:?}",)) } else { Err(error_to_jsvalue("invalid raw tx")) } @@ -67,7 +67,7 @@ pub fn evm_tx_hash(raw_tx: String) -> Result { .map_err(error_to_jsvalue)?; if let Action::Ethereum(EthAction::Transact(tx)) = unchecked_tx.function { let hash = H256::from_slice(Keccak256::digest(&rlp::encode(&tx)).as_slice()); - Ok(format!("{:?}", hash)) + Ok(format!("{hash:?}",)) } else { Err(error_to_jsvalue("invalid raw tx")) } @@ -89,7 +89,7 @@ mod test { if let Action::Ethereum(EthAction::Transact(tx)) = unchecked_tx.function { let signer = recover_signer(&tx).unwrap(); assert_eq!( - format!("{:?}", signer), + format!("{signer:?}",), "0xa5225cbee5052100ec2d2d94aa6d258558073757" ); } else { @@ -106,7 +106,7 @@ mod test { if let Action::Ethereum(EthAction::Transact(tx)) = unchecked_tx.function { let hash = H256::from_slice(Keccak256::digest(&rlp::encode(&tx)).as_slice()); assert_eq!( - format!("{:?}", hash), + format!("{hash:?}",), "0x0eeb0ff455b1b57b821634cf853e7247e584a675610f13097cc49c2022505df3" ); } else { diff --git a/src/components/contracts/rpc/src/eth.rs b/src/components/contracts/rpc/src/eth.rs index 5f572cb1b3..b1e7b8331c 100644 --- a/src/components/contracts/rpc/src/eth.rs +++ b/src/components/contracts/rpc/src/eth.rs @@ -103,8 +103,7 @@ impl EthApiImpl { Some(block) => Some(block.header.number.as_u64()), None => { return Err(internal_err(format!( - "block number not found, hash: {:?}", - hash + "block number not found, hash: {hash:?}", ))) } }, @@ -113,8 +112,7 @@ impl EthApiImpl { Some(num) } else { return Err(internal_err(format!( - "block number: {} exceeds version range: {:?}", - num, range + "block number: {num} exceeds version range: {range:?}", ))); } } @@ -379,7 +377,7 @@ impl EthApi for EthApiImpl { .read() .create_query_context(None, false) .map_err(|err| { - internal_err(format!("create query context error: {:?}", err)) + internal_err(format!("create query context error: {err:?}",)) })?; if let Some(block) = block { ctx.header @@ -406,9 +404,9 @@ impl EthApi for EthApiImpl { &ctx, call, &config, ) .map_err(|err| { - internal_err(format!("evm runner call error: {:?}", err)) + internal_err(format!("evm runner call error: {err:?}",)) })?; - debug!(target: "eth_rpc", "evm runner call result: {:?}", info); + debug!(target: "eth_rpc", "evm runner call result: {info:?}", ); error_on_execution_failure(&info.exit_reason, &info.value)?; @@ -428,9 +426,9 @@ impl EthApi for EthApiImpl { &ctx, create, &config, ) .map_err(|err| { - internal_err(format!("evm runner create error: {:?}", err)) + internal_err(format!("evm runner create error: {err:?}",)) })?; - debug!(target: "eth_rpc", "evm runner create result: {:?}", info); + debug!(target: "eth_rpc", "evm runner create result: {info:?}", ); error_on_execution_failure(&info.exit_reason, &[])?; @@ -774,8 +772,7 @@ impl EthApi for EthApiImpl { (Some(BlockId::Number(U256::from(num))), false) } else { return Err(internal_err(format!( - "block number: {} exceeds version range: {:?}", - num, range + "block number: {num} exceeds version range: {range:?}", ))); } } @@ -854,7 +851,7 @@ impl EthApi for EthApiImpl { .read() .create_query_context(if pending { None } else { Some(0) }, false) .map_err(|err| { - internal_err(format!("create query context error: {:?}", err)) + internal_err(format!("create query context error: {err:?}",)) })?; let CallRequest { @@ -891,9 +888,9 @@ impl EthApi for EthApiImpl { &ctx, call, &config, ) .map_err(|err| { - internal_err(format!("evm runner call error: {:?}", err)) + internal_err(format!("evm runner call error: {err:?}",)) })?; - debug!(target: "eth_rpc", "evm runner call result: {:?}", info); + debug!(target: "eth_rpc", "evm runner call result: {info:?}", ); Ok(ExecuteResult { data: info.value, @@ -915,9 +912,9 @@ impl EthApi for EthApiImpl { &ctx, create, &config, ) .map_err(|err| { - internal_err(format!("evm runner create error: {:?}", err)) + internal_err(format!("evm runner create error: {err:?}",)) })?; - debug!(target: "eth_rpc", "evm runner create result: {:?}", info); + debug!(target: "eth_rpc", "evm runner create result: {info:?}", ); Ok(ExecuteResult { data: vec![], @@ -986,7 +983,7 @@ impl EthApi for EthApiImpl { id = Some(BlockId::Number(number)); index = idx as usize } - println!("{:?}, {:?}", id, index); + println!("{id:?}, {index:?}"); let block = account_base_app.read().current_block(id.clone()); let statuses = account_base_app diff --git a/src/components/contracts/rpc/src/eth_filter.rs b/src/components/contracts/rpc/src/eth_filter.rs index 18c71814d6..eb82a4228b 100644 --- a/src/components/contracts/rpc/src/eth_filter.rs +++ b/src/components/contracts/rpc/src/eth_filter.rs @@ -154,8 +154,7 @@ impl EthFilterApiImpl { // Check for restrictions if ret.len() as u32 > max_past_logs { return Err(internal_err(format!( - "query returned more than {} results", - max_past_logs + "query returned more than {max_past_logs} results", ))); } if begin_request.elapsed() > max_duration { @@ -302,7 +301,7 @@ impl EthFilterApi for EthFilterApiImpl { _ => Err(internal_err("Method not available.")), } } else { - Err(internal_err(format!("Filter id {:?} does not exist.", key))) + Err(internal_err(format!("Filter id {key:?} does not exist.",))) } } else { Err(internal_err("Filter pool is not available.")) @@ -346,12 +345,11 @@ impl EthFilterApi for EthFilterApiImpl { Ok(ret) } _ => Err(internal_err(format!( - "Filter id {:?} is not a Log filter.", - key + "Filter id {key:?} is not a Log filter.", ))), } } else { - Err(internal_err(format!("Filter id {:?} does not exist.", key))) + Err(internal_err(format!("Filter id {key:?} does not exist.",))) } } else { Err(internal_err("Filter pool is not available.")) @@ -367,7 +365,7 @@ impl EthFilterApi for EthFilterApiImpl { if locked.remove(&key).is_some() { Ok(true) } else { - Err(internal_err(format!("Filter id {:?} does not exist.", key))) + Err(internal_err(format!("Filter id {key:?} does not exist.",))) } } else { Err(internal_err("Filter pool is not available.")) diff --git a/src/components/contracts/rpc/src/lib.rs b/src/components/contracts/rpc/src/lib.rs index d989d77bfa..51c482bb70 100644 --- a/src/components/contracts/rpc/src/lib.rs +++ b/src/components/contracts/rpc/src/lib.rs @@ -161,7 +161,7 @@ pub fn error_on_execution_failure( } Err(Error { code: ErrorCode::InternalError, - message: format!("evm error: {:?}", e), + message: format!("evm error: {e:?}",), data: Some(Value::String("0x".to_string())), }) } @@ -174,7 +174,7 @@ pub fn error_on_execution_failure( let message_len = data[36..68].iter().sum::(); let body: &[u8] = &data[68..68 + message_len as usize]; if let Ok(reason) = std::str::from_utf8(body) { - message = format!("{} {}", message, reason); + message = format!("{message} {reason}"); } } Err(Error { @@ -185,7 +185,7 @@ pub fn error_on_execution_failure( } ExitReason::Fatal(e) => Err(Error { code: ErrorCode::InternalError, - message: format!("evm fatal: {:?}", e), + message: format!("evm fatal: {e:?}"), data: Some(Value::String("0x".to_string())), }), } diff --git a/src/components/contracts/rpc/src/utils.rs b/src/components/contracts/rpc/src/utils.rs index 51745ebdb6..865f0021e6 100644 --- a/src/components/contracts/rpc/src/utils.rs +++ b/src/components/contracts/rpc/src/utils.rs @@ -6,7 +6,7 @@ use tokio::task::JoinError; pub fn convert_join_error_to_rpc_error(e: JoinError) -> Error { Error { code: ErrorCode::InternalError, - message: format!("{:?}", e), + message: format!("{e:?}",), data: None, } } @@ -14,7 +14,7 @@ pub fn convert_join_error_to_rpc_error(e: JoinError) -> Error { pub fn convert_error_to_rpc_error(e: impl Debug) -> Error { Error { code: ErrorCode::InternalError, - message: format!("{:?}", e), + message: format!("{e:?}",), data: None, } } diff --git a/src/components/finutils/src/bins/cfg_generator.rs b/src/components/finutils/src/bins/cfg_generator.rs index d41b09914a..66bb1a0b5c 100644 --- a/src/components/finutils/src/bins/cfg_generator.rs +++ b/src/components/finutils/src/bins/cfg_generator.rs @@ -76,8 +76,7 @@ fn gen() -> Result<()> { .and_then(|m| fs::write(&secret_info_path, m).c(d!())) .map(|_| { println!( - "\x1b[01mSecret info has been writed to \x1b[31m{}\x1b[00m", - secret_info_path + "\x1b[01mSecret info has been writed to \x1b[31m{secret_info_path}\x1b[00m", ); }) } diff --git a/src/components/finutils/src/bins/fn.rs b/src/components/finutils/src/bins/fn.rs index f8823e74b1..75240bbe3a 100644 --- a/src/components/finutils/src/bins/fn.rs +++ b/src/components/finutils/src/bins/fn.rs @@ -209,7 +209,7 @@ fn run() -> Result<()> { .c(d!())?; } else { let help = "fn asset [--create | --issue | --show]"; - println!("{}", help); + println!("{help}",); } } else if let Some(m) = matches.subcommand_matches("staker-update") { let vm = if let Some(memo) = m.value_of("validator-memo") { @@ -431,7 +431,7 @@ fn run() -> Result<()> { } if address.is_some() { let (account, info) = contract_account_info(address, is_address_fra)?; - println!("AccountId: {}\n{:#?}\n", account, info); + println!("AccountId: {account}\n{info:#?}\n",); } } else if let Some(m) = matches.subcommand_matches("contract-deposit") { let amount = m.value_of("amount").c(d!())?; @@ -542,7 +542,7 @@ fn run() -> Result<()> { if let Some(path) = m.value_of("file-path") { serde_json::to_writer_pretty(&File::create(path).c(d!())?, &keys).c(d!())?; - println!("Keys saved to file: {}", path); + println!("Keys saved to file: {path}",); } // print keys to terminal @@ -603,7 +603,7 @@ fn run() -> Result<()> { ); // Print UTXO table - println!("Owned utxos for {:?}", pk); + println!("Owned utxos for {pk:?}",); println!("{:-^1$}", "", 100); println!( "{0: <8} | {1: <18} | {2: <45} ", @@ -1132,7 +1132,7 @@ fn tip_fail(e: impl fmt::Display) { eprintln!( "\x1b[35;01mTips\x1b[01m:\n\tPlease send your error messages to us,\n\tif you can't understand their meanings ~^!^~\x1b[00m" ); - eprintln!("\n{}", e); + eprintln!("\n{e}",); } fn tip_success() { diff --git a/src/components/finutils/src/bins/stt/init/i_testing.rs b/src/components/finutils/src/bins/stt/init/i_testing.rs index 909fdc10af..271e655e36 100644 --- a/src/components/finutils/src/bins/stt/init/i_testing.rs +++ b/src/components/finutils/src/bins/stt/init/i_testing.rs @@ -394,7 +394,7 @@ struct TmValidator { } fn get_26657_validators(sa: &str) -> Result { - let url = format!("{}:26657/validators", sa); + let url = format!("{sa}:26657/validators",); attohttpc::get(url) .send() .c(d!())? diff --git a/src/components/finutils/src/bins/stt/init/mod.rs b/src/components/finutils/src/bins/stt/init/mod.rs index 7de620bcee..d0721d9994 100644 --- a/src/components/finutils/src/bins/stt/init/mod.rs +++ b/src/components/finutils/src/bins/stt/init/mod.rs @@ -40,7 +40,7 @@ pub fn init( } else { let root_kp = wallet::restore_keypair_from_mnemonic_default(ROOT_MNEMONIC).c(d!())?; - println!(">>> Block interval: {} seconds", interval); + println!(">>> Block interval: {interval} seconds",); println!(">>> Define and issue FRA ..."); common::utils::send_tx(&fra_gen_initial_tx(&root_kp)).c(d!())?; diff --git a/src/components/finutils/src/bins/stt/stt.rs b/src/components/finutils/src/bins/stt/stt.rs index 7f416affec..d757d80844 100644 --- a/src/components/finutils/src/bins/stt/stt.rs +++ b/src/components/finutils/src/bins/stt/stt.rs @@ -406,20 +406,20 @@ fn print_info( if show_user_list { let user_list = serde_json::to_string_pretty(&*USER_LIST).c(d!())?; - println!("\x1b[31;01mUSER LIST:\x1b[00m\n{}\n", user_list); + println!("\x1b[31;01mUSER LIST:\x1b[00m\n{user_list}\n",); } if show_validator_list { let validator_list = serde_json::to_string_pretty(&*VALIDATOR_LIST).c(d!())?; - println!("\x1b[31;01mVALIDATOR LIST:\x1b[00m\n{}\n", validator_list); + println!("\x1b[31;01mVALIDATOR LIST:\x1b[00m\n{validator_list}\n",); } if let Some(u) = user { let balance = get_balance(u).c(d!())?; - println!("\x1b[31;01mUSER BALANCE:\x1b[00m\n{} FRA units\n", balance); + println!("\x1b[31;01mUSER BALANCE:\x1b[00m\n{balance} FRA units\n",); let user_info = get_delegation_info(u).c(d!())?; - println!("\x1b[31;01mUSER DELEGATION:\x1b[00m\n{}\n", user_info); + println!("\x1b[31;01mUSER DELEGATION:\x1b[00m\n{user_info}\n",); } Ok(()) diff --git a/src/components/finutils/src/common/ddev/init.rs b/src/components/finutils/src/common/ddev/init.rs index 29419fd70d..93c7f631e4 100644 --- a/src/components/finutils/src/common/ddev/init.rs +++ b/src/components/finutils/src/common/ddev/init.rs @@ -48,7 +48,7 @@ pub(super) fn init(env: &mut Env) -> Result<()> { let port = ports[IDX_TM_RPC]; let page_size = env.custom_data.initial_validator_num; let tmrpc_endpoint = - format!("http://{}:{}/validators?per_page={}", addr, port, page_size); + format!("http://{addr}:{port}/validators?per_page={page_size}",); let tm_validators = attohttpc::get(&tmrpc_endpoint) .send() @@ -173,7 +173,7 @@ fn setup_initial_validators(env: &Env) -> Result<()> { fn send_tx(env: &Env, tx: &Transaction) -> Result<()> { let (addr, ports) = env.get_addrports_any_node(); let port = ports[IDX_APP_8669]; - let rpc_endpoint = format!("http://{}:{}/submit_transaction", addr, port); + let rpc_endpoint = format!("http://{addr}:{port}/submit_transaction"); attohttpc::post(&rpc_endpoint) .header(attohttpc::header::CONTENT_TYPE, "application/json") .bytes(&serde_json::to_vec(tx).c(d!())?) @@ -244,7 +244,7 @@ fn new_tx_builder(env: &Env) -> Result { fn gen_8668_endpoint(env: &Env) -> String { let (addr, ports) = env.get_addrports_any_node(); let port = ports[IDX_APP_8668]; - format!("http://{}:{}", addr, port) + format!("http://{addr}:{port}",) } #[derive(Debug, Clone, Deserialize, Serialize)] diff --git a/src/components/finutils/src/common/ddev/mod.rs b/src/components/finutils/src/common/ddev/mod.rs index 26a8421e57..a71e67b8e6 100644 --- a/src/components/finutils/src/common/ddev/mod.rs +++ b/src/components/finutils/src/common/ddev/mod.rs @@ -304,7 +304,7 @@ impl NodeOptsGenerator, EnvMeta>> for OptsGe ); if let Some(cp) = m.custom_data.checkpoint_file.as_ref() { - write!(opts, " --checkpoint-file {}", cp).unwrap(); + write!(opts, " --checkpoint-file {cp}",).unwrap(); } write!(opts, " {}", &m.app_extra_opts).unwrap(); diff --git a/src/components/finutils/src/common/dev/mod.rs b/src/components/finutils/src/common/dev/mod.rs index 926d0aaf7f..0692e7b2e8 100644 --- a/src/components/finutils/src/common/dev/mod.rs +++ b/src/components/finutils/src/common/dev/mod.rs @@ -182,7 +182,7 @@ impl NodeOptsGenerator, EnvMeta>> for OptsGe ); if let Some(cp) = m.custom_data.checkpoint_file.as_ref() { - write!(opts, " --checkpoint-file {}", cp).unwrap(); + write!(opts, " --checkpoint-file {cp}",).unwrap(); } write!(opts, " {}", &m.app_extra_opts).unwrap(); diff --git a/src/components/finutils/src/common/mod.rs b/src/components/finutils/src/common/mod.rs index 1f9e848fa4..7486d02f20 100644 --- a/src/components/finutils/src/common/mod.rs +++ b/src/components/finutils/src/common/mod.rs @@ -155,8 +155,7 @@ pub fn stake( || diff!(network_height, local_height) > 3 { println!( - "The difference in block height of your node and the remote network is too big: \n remote / local: {} / {}", - network_height, local_height + "The difference in block height of your node and the remote network is too big: \n remote / local: {network_height} / {local_height}", ); if !force { println!("Append option --force to ignore this warning."); @@ -329,7 +328,7 @@ pub fn show(basic: bool, is_address_fra: bool) -> Result<()> { let kp = get_keypair(is_address_fra).c(d!())?; let serv_addr = ruc::info!(get_serv_addr()).map(|i| { - println!("\x1b[31;01mServer URL:\x1b[00m\n{}\n", i); + println!("\x1b[31;01mServer URL:\x1b[00m\n{i}\n",); }); let xfr_account = ruc::info!(get_keypair(is_address_fra)).map(|i| { @@ -348,7 +347,7 @@ pub fn show(basic: bool, is_address_fra: bool) -> Result<()> { }); let self_balance = ruc::info!(utils::get_balance(&kp)).map(|i| { - println!("\x1b[31;01mNode Balance:\x1b[00m\n{} FRA units\n", i); + println!("\x1b[31;01mNode Balance:\x1b[00m\n{i} FRA units\n",); }); if basic { @@ -357,7 +356,7 @@ pub fn show(basic: bool, is_address_fra: bool) -> Result<()> { let td_info = ruc::info!(get_td_pubkey()).map(|i| { let addr = td_pubkey_to_td_addr(&i); - println!("\x1b[31;01mValidator Node Addr:\x1b[00m\n{}\n", addr); + println!("\x1b[31;01mValidator Node Addr:\x1b[00m\n{addr}\n",); (i, addr) }); @@ -371,7 +370,7 @@ pub fn show(basic: bool, is_address_fra: bool) -> Result<()> { serde_json::to_string_pretty(&di).c(d!("server returned invalid data")) }); let delegation_info = ruc::info!(delegation_info).map(|i| { - println!("\x1b[31;01mYour Delegation:\x1b[00m\n{}\n", i); + println!("\x1b[31;01mYour Delegation:\x1b[00m\n{i}\n",); }); if let Ok((tpk, addr)) = td_info.as_ref() { @@ -385,7 +384,7 @@ pub fn show(basic: bool, is_address_fra: bool) -> Result<()> { .c(d!("server returned invalid data")) }) .map(|i| { - println!("\x1b[31;01mYour Staking:\x1b[00m\n{}\n", i); + println!("\x1b[31;01mYour Staking:\x1b[00m\n{i}\n",); }); ruc::info_omit!(res); } @@ -639,8 +638,7 @@ pub fn gen_key(is_fra_address: bool) -> (String, String, String, XfrKeyPair) { pub fn gen_key_and_print(is_fra_address: bool) { let (wallet_addr, mnemonic, key, _) = gen_key(is_fra_address); println!( - "\n\x1b[31;01mWallet Address:\x1b[00m {}\n\x1b[31;01mMnemonic:\x1b[00m {}\n\x1b[31;01mKey:\x1b[00m {}\n", - wallet_addr, mnemonic, key + "\n\x1b[31;01mWallet Address:\x1b[00m {wallet_addr}\n\x1b[31;01mMnemonic:\x1b[00m {mnemonic}\n\x1b[31;01mKey:\x1b[00m {key}\n", ); } @@ -649,7 +647,7 @@ fn restore_keypair_from_str_with_default( is_fra_address: bool, ) -> Result { if let Some(sk) = sk_str { - serde_json::from_str::(&format!("\"{}\"", sk)) + serde_json::from_str::(&format!("\"{sk}\"",)) .map(|sk| sk.into_keypair()) .c(d!("Invalid secret key")) } else { @@ -905,7 +903,7 @@ pub fn show_asset(addr: &str) -> Result<()> { for asset in assets { let base64 = asset.body.asset.code.to_base64(); let h = hex::encode(asset.body.asset.code.val.0); - println!("Base64: {}, Hex: {}", base64, h); + println!("Base64: {base64}, Hex: {h}",); } Ok(()) @@ -924,12 +922,11 @@ pub fn convert_bar2abar( ) -> Result { // parse sender XfrSecretKey or generate from Mnemonic setup with wallet let from = match owner_sk { - Some(str) => ruc::info!(serde_json::from_str::(&format!( - "\"{}\"", - str - ))) - .c(d!())? - .into_keypair(), + Some(str) => { + ruc::info!(serde_json::from_str::(&format!("\"{str}\"",))) + .c(d!())? + .into_keypair() + } None => get_keypair(is_address_fra).c(d!())?, }; // parse receiver AxfrPubKey @@ -1397,7 +1394,7 @@ pub fn get_owned_abars( axfr_secret_key: AXfrKeyPair, commitments_list: &str, ) -> Result<()> { - println!("Abar data for commitments: {}", commitments_list); + println!("Abar data for commitments: {commitments_list}",); println!(); println!( "{0: <8} | {1: <18} | {2: <45} | {3: <9} | {4: <45}", diff --git a/src/components/finutils/src/common/utils.rs b/src/components/finutils/src/common/utils.rs index ef89aae623..d6f346350f 100644 --- a/src/components/finutils/src/common/utils.rs +++ b/src/components/finutils/src/common/utils.rs @@ -482,7 +482,7 @@ struct TmStatus { // retrieve tendermint status and node info #[inline(always)] fn get_network_status(addr: &str) -> Result { - let url = format!("{}:26657/status", addr); + let url = format!("{addr}:26657/status",); attohttpc::get(url) .send() diff --git a/src/components/finutils/src/txn_builder/mod.rs b/src/components/finutils/src/txn_builder/mod.rs index 102cba2544..ad40f086ea 100644 --- a/src/components/finutils/src/txn_builder/mod.rs +++ b/src/components/finutils/src/txn_builder/mod.rs @@ -799,7 +799,7 @@ impl TransactionBuilder { return Err(eg!("insufficient FRA to pay fees!")); } if fra_remainder > 0 { - println!("Transaction FRA Remainder Amount: {:?}", fra_remainder); + println!("Transaction FRA Remainder Amount: {fra_remainder:?}",); let oabar_money_back = OpenAnonAssetRecordBuilder::new() .amount(fra_remainder as u64) .asset_type(ASSET_TYPE_FRA) @@ -1353,7 +1353,7 @@ impl TransferOperationBuilder { .iter() .fold(0, |acc, ar| acc + ar.open_asset_record.amount); if input_total != output_total { - return Err(eg!(format!("{} != {}", input_total, output_total))); + return Err(eg!(format!("{input_total} != {output_total}",))); } Ok(()) @@ -1421,8 +1421,7 @@ impl TransferOperationBuilder { .fold(0, |acc, ar| acc + ar.open_asset_record.amount); if spend_total != output_total { return Err(eg!(format!( - "Spend total != output, {} != {}", - spend_total, output_total + "Spend total != output, {spend_total} != {output_total}", ))); } self.output_records.append(&mut partially_consumed_inputs); diff --git a/src/ledger/src/data_model/mod.rs b/src/ledger/src/data_model/mod.rs index a929225d55..0fe8314887 100644 --- a/src/ledger/src/data_model/mod.rs +++ b/src/ledger/src/data_model/mod.rs @@ -254,10 +254,7 @@ impl AssetTypeCode { val: NoahAssetType(buf), }) } - Err(e) => Err(eg!((format!( - "Failed to deserialize base64 '{}': {}", - b64, e - )))), + Err(e) => Err(eg!((format!("Failed to deserialize base64 '{b64}': {e}",)))), } } @@ -1037,7 +1034,7 @@ impl AssetTypePrefix { AssetTypePrefix::NFT => "02", }; - hex::decode(format!("{:0>64}", code)).unwrap() + hex::decode(format!("{code:0>64}",)).unwrap() } } diff --git a/src/ledger/src/data_model/test.rs b/src/ledger/src/data_model/test.rs index 145fdadd1d..8b0e1918d7 100755 --- a/src/ledger/src/data_model/test.rs +++ b/src/ledger/src/data_model/test.rs @@ -46,7 +46,7 @@ fn test_gen_random_with_rng() { let uniform_stddev = 1.0 / (12.0f64).sqrt(); let average = sum as f64 / sample_size as f64; let stddev = (uniform_stddev * 255.0) / (sample_size as f64).sqrt(); - println!("Average {}, stddev {}", average, stddev); + println!("Average {average}, stddev {stddev}"); assert!(average > 127.5 - 5.0 * stddev); assert!(average < 127.5 + 5.0 * stddev); } diff --git a/src/ledger/src/staking/cosig.rs b/src/ledger/src/staking/cosig.rs index e883333070..041631f71c 100644 --- a/src/ledger/src/staking/cosig.rs +++ b/src/ledger/src/staking/cosig.rs @@ -207,7 +207,7 @@ impl fmt::Display for CoSigErr { CoSigErr::WeightInsufficient => "total weight is lower than the threshold", CoSigErr::SigInvalid => "invalid signature", }; - write!(f, "{}", msg) + write!(f, "{msg}",) } } diff --git a/src/ledger/src/staking/mod.rs b/src/ledger/src/staking/mod.rs index 6d05458351..fca45ab10f 100644 --- a/src/ledger/src/staking/mod.rs +++ b/src/ledger/src/staking/mod.rs @@ -1461,7 +1461,7 @@ impl Staking { vd.addr_td_to_app .get(addr) .copied() - .c(d!(format!("Failed to get pk {}", addr))) + .c(d!(format!("Failed to get pk {addr}",))) }) } @@ -2452,8 +2452,7 @@ pub fn check_delegation_amount(am: Amount, is_append: bool) -> Result<()> { Ok(()) } else { let msg = format!( - "Invalid delegation amount: {} (min: {}, max: {})", - am, lowb, MAX_DELEGATION_AMOUNT + "Invalid delegation amount: {am} (min: {lowb}, max: {MAX_DELEGATION_AMOUNT})", ); Err(eg!(msg)) } diff --git a/src/ledger/src/store/api_cache.rs b/src/ledger/src/store/api_cache.rs index a08f3c2776..38bb290bc5 100644 --- a/src/ledger/src/store/api_cache.rs +++ b/src/ledger/src/store/api_cache.rs @@ -92,55 +92,45 @@ impl ApiCache { ApiCache { prefix: prefix.to_owned(), related_transactions: new_mapx!(format!( - "api_cache/{}related_transactions", - prefix + "api_cache/{prefix}related_transactions", )), - related_transfers: new_mapx!(format!( - "api_cache/{}related_transfers", - prefix - )), - claim_hist_txns: new_mapx!(format!("api_cache/{}claim_hist_txns", prefix)), + related_transfers: new_mapx!( + format!("api_cache/{prefix}related_transfers",) + ), + claim_hist_txns: new_mapx!(format!("api_cache/{prefix}claim_hist_txns",)), coinbase_oper_hist: new_mapx!(format!( - "api_cache/{}coinbase_oper_hist", - prefix + "api_cache/{prefix}coinbase_oper_hist", )), - created_assets: new_mapx!(format!("api_cache/{}created_assets", prefix)), - issuances: new_mapx!(format!("api_cache/{}issuances", prefix)), + created_assets: new_mapx!(format!("api_cache/{prefix}created_assets",)), + issuances: new_mapx!(format!("api_cache/{prefix}issuances",)), token_code_issuances: new_mapx!(format!( - "api_cache/{}token_code_issuances", - prefix + "api_cache/{prefix}token_code_issuances", )), - owner_memos: new_mapxnk!(format!("api_cache/{}owner_memos", prefix)), - abar_memos: new_mapx!(format!("api_cache/{}abar_memos", prefix)), + owner_memos: new_mapxnk!(format!("api_cache/{prefix}owner_memos",)), + abar_memos: new_mapx!(format!("api_cache/{prefix}abar_memos",)), utxos_to_map_index: new_mapxnk!(format!( - "api_cache/{}utxos_to_map_index", - prefix + "api_cache/{prefix}utxos_to_map_index", )), - txo_to_txnid: new_mapxnk!(format!("api_cache/{}txo_to_txnid", prefix)), - atxo_to_txnid: new_mapx!(format!("api_cache/{}atxo_to_txnid", prefix)), - txn_sid_to_hash: new_mapxnk!(format!("api_cache/{}txn_sid_to_hash", prefix)), - txn_hash_to_sid: new_mapx!(format!("api_cache/{}txn_hash_to_sid", prefix)), + txo_to_txnid: new_mapxnk!(format!("api_cache/{prefix}txo_to_txnid",)), + atxo_to_txnid: new_mapx!(format!("api_cache/{prefix}atxo_to_txnid",)), + txn_sid_to_hash: new_mapxnk!(format!("api_cache/{prefix}txn_sid_to_hash",)), + txn_hash_to_sid: new_mapx!(format!("api_cache/{prefix}txn_hash_to_sid",)), staking_global_rate_hist: new_mapxnk!(format!( - "api_cache/{}staking_global_rate_hist", - prefix + "api_cache/{prefix}staking_global_rate_hist", )), height_to_max_atxo: new_mapxnk!(format!( - "api_cache/{}height_to_max_atxo", - prefix + "api_cache/{prefix}height_to_max_atxo", )), staking_self_delegation_hist: new_mapx!(format!( - "api_cache/{}staking_self_delegation_hist", - prefix + "api_cache/{prefix}staking_self_delegation_hist", )), staking_delegation_amount_hist: new_mapx!(format!( - "api_cache/{}staking_delegation_amount_hist", - prefix + "api_cache/{prefix}staking_delegation_amount_hist", )), staking_delegation_rwd_hist: new_mapx!(format!( - "api_cache/{}staking_delegation_rwd_hist", - prefix + "api_cache/{prefix}staking_delegation_rwd_hist", )), - last_sid: new_mapx!(format!("api_cache/{}last_sid", prefix)), + last_sid: new_mapx!(format!("api_cache/{prefix}last_sid",)), state_commitment_version: None, } } diff --git a/src/ledger/src/store/helpers.rs b/src/ledger/src/store/helpers.rs index 5acbc8097f..b74d65475b 100644 --- a/src/ledger/src/store/helpers.rs +++ b/src/ledger/src/store/helpers.rs @@ -103,7 +103,7 @@ pub fn apply_transaction( } Err(e) => { fn unwrap_failed(msg: &str, error: impl Debug) -> ! { - panic!("{}: {:?}", msg, error) + panic!("{msg}: {error:?}",) } unwrap_failed("apply_transaction: error in compute_effect", e) } diff --git a/src/ledger/src/store/mod.rs b/src/ledger/src/store/mod.rs index 6c2d42e204..75fb1a7ef0 100644 --- a/src/ledger/src/store/mod.rs +++ b/src/ledger/src/store/mod.rs @@ -579,7 +579,7 @@ impl LedgerState { /// Initialize a new Ledger structure. pub fn new(basedir: &str, prefix: Option<&str>) -> Result { let prefix = if let Some(p) = prefix { - format!("{}_", p) + format!("{p}_",) } else { "".to_owned() }; @@ -1402,7 +1402,7 @@ impl LedgerStatus { /// Load or init LedgerStatus from snapshot #[inline(always)] pub fn new(basedir: &str, snapshot_file: &str) -> Result { - let path = format!("{}/{}", basedir, snapshot_file); + let path = format!("{basedir}/{snapshot_file}",); match fs::read_to_string(path) { Ok(s) => serde_json::from_str(&s).c(d!()), Err(e) => { @@ -1480,8 +1480,7 @@ impl LedgerStatus { // Check to see that this nrpt has not been seen before if self.sliding_set.has_key_at(seq_id as usize, rand) { return Err(eg!(format!( - "No replay token ({:?}, {})seen before at possible replay", - rand, seq_id + "No replay token ({rand:?}, {seq_id})seen before at possible replay", ))); } } @@ -1744,7 +1743,7 @@ impl LedgerStatus { no_replay_token.get_seq_id() as usize, ); if let Err(e) = self.sliding_set.insert(rand, seq_id) { - pd!(format!("Error inserting into window: {}", e)); + pd!(format!("Error inserting into window: {e}",)); } } block.no_replay_tokens.clear(); diff --git a/src/libs/bitmap/src/lib.rs b/src/libs/bitmap/src/lib.rs index fbf2bed15c..a30a08527b 100644 --- a/src/libs/bitmap/src/lib.rs +++ b/src/libs/bitmap/src/lib.rs @@ -293,8 +293,7 @@ impl BlockHeader { && block_contents != BIT_HEADER { return Err(eg!(format!( - "That content type ({}) is invalid.", - block_contents + "That content type ({block_contents}) is invalid.", ))); } @@ -671,10 +670,10 @@ impl BitMap { let file_size = file.seek(SeekFrom::End(0)).c(d!())?; if file_size % BLOCK_SIZE as u64 != 0 { - return Err(eg!(format!("That file size ({}) is invalid.", file_size))); + return Err(eg!(format!("That file size ({file_size}) is invalid.",))); } - file.seek(SeekFrom::Start(0)).c(d!())?; + file.rewind().c(d!())?; let total_blocks = file_size / BLOCK_SIZE as u64; // Reserve space in our vectors. @@ -737,11 +736,11 @@ impl BitMap { if validate_checksums { if let Err(e) = block.validate(BIT_ARRAY, i as u64) { - println!("Block {} failed validation: {}", i, e); + println!("Block {i} failed validation: {e}",); pass = false; } } else if let Err(e) = header.validate(BIT_ARRAY, i as u64) { - println!("Block {} failed validation: {}", i, e); + println!("Block {i} failed validation: {e}"); pass = false; } @@ -1254,7 +1253,7 @@ impl BitMap { let bytes_consumed = list_size as usize * INDEX_SIZE; if index + bytes_consumed > bytes.len() { - return Err(eg!(format!("An index list was too long: {}", list_size))); + return Err(eg!(format!("An index list was too long: {list_size}",))); } for _ in 0..list_size { diff --git a/src/libs/bitmap/src/test.rs b/src/libs/bitmap/src/test.rs index 58ff122d0b..619aeb2be7 100755 --- a/src/libs/bitmap/src/test.rs +++ b/src/libs/bitmap/src/test.rs @@ -30,7 +30,7 @@ fn test_header() { assert!(header.bit_id == id * BLOCK_BITS as u64); if let Err(e) = header.validate(BIT_ARRAY, id) { - panic!("Validation failed: {}", e); + panic!("Validation failed: {e}",); } header.magic ^= 1; @@ -138,7 +138,7 @@ fn test_basic_bitmap() { let mut bitmap = BitMap::create(file).unwrap(); if let Err(e) = bitmap.write() { - panic!("Write failed: {}", e); + panic!("Write failed: {e}",); } // Check our definition of the checksum of an empty tree. @@ -184,15 +184,15 @@ fn test_basic_bitmap() { // Try a flush now and then. if i % (BLOCK_BITS / 2) == 0 { if let Err(e) = bitmap.flush_old(0) { - panic!("flush_old failed: {}", e); + panic!("flush_old failed: {e}",); } } } let checksum1 = bitmap.compute_checksum(); let checksum2 = bitmap.compute_checksum(); - println!("Checksum 1: {:?}", checksum1); - println!("Checksum 2: {:?}", checksum2); + println!("Checksum 1: {checksum1:?}",); + println!("Checksum 2: {checksum2:?}",); assert!(checksum1 == checksum2); bitmap.clear_checksum_cache(); @@ -203,7 +203,7 @@ fn test_basic_bitmap() { let s1 = bitmap.serialize_partial(vec![0, BLOCK_BITS], 1); if let Err(x) = BitMap::deserialize(&s1) { - panic!("deserialize(&s1) failed: {}", x); + panic!("deserialize(&s1) failed: {x}",); } // Pick a random version number and serialize the entire @@ -212,7 +212,7 @@ fn test_basic_bitmap() { let s2 = bitmap.serialize(sparse_version); if let Err(x) = BitMap::deserialize(&s2) { - panic!("deserialize(&s2) failed: {}", x); + panic!("deserialize(&s2) failed: {x}",); } // Create SparseMaps from the serialized forms. @@ -237,7 +237,7 @@ fn test_basic_bitmap() { // Check that the sparse bitmap matches the source bitmap. if bitmap_result != sparse_result { - panic!("Sparse mismatch at {}", i); + panic!("Sparse mismatch at {i}",); } // Now check the partial bitmap. @@ -284,11 +284,11 @@ fn test_basic_bitmap() { let bits_initialized = bitmap.size(); if let Err(e) = bitmap.write() { - panic!("write failed: {}", e); + panic!("write failed: {e}",); } if let Err(e) = bitmap.flush_old(0) { - panic!("flush_old failed: {}", e); + panic!("flush_old failed: {e}",); } assert!(bitmap.validate(true)); diff --git a/src/libs/globutils/src/lib.rs b/src/libs/globutils/src/lib.rs index f2da30690d..ffa3c81ab4 100644 --- a/src/libs/globutils/src/lib.rs +++ b/src/libs/globutils/src/lib.rs @@ -48,7 +48,7 @@ pub fn fresh_tmp_dir() -> PathBuf { // Convert a u64 into a string with commas. fn commas_u64(input: u64) -> String { if input < 10000 { - return format!("{}", input); + return format!("{input}",); } let mut value = input; @@ -62,7 +62,7 @@ fn commas_u64(input: u64) -> String { if value == 1000 { result = "1,000".to_owned() + &result; } else { - result = format!("{}", value) + &result; + result = format!("{value}",) + &result; } result diff --git a/src/libs/globutils/src/logging.rs b/src/libs/globutils/src/logging.rs index 0b257fcdf5..81e1cba024 100644 --- a/src/libs/globutils/src/logging.rs +++ b/src/libs/globutils/src/logging.rs @@ -16,17 +16,17 @@ pub fn init_logging(verbose: Option<&str>) { env_filter = env_filter.add_directive(LevelFilter::DEBUG.into()); } else { env_filter = - env_filter.add_directive(format!("{}=debug", module).parse().unwrap()); + env_filter.add_directive(format!("{module}=debug",).parse().unwrap()); } } if let Ok(rust_log) = env::var("RUST_LOG") { - println!("{}", rust_log); + println!("{rust_log}",); if !rust_log.is_empty() { for directive in rust_log.split(',').filter_map(|s| match s.parse() { Ok(directive) => Some(directive), Err(err) => { - eprintln!("Ignoring directive `{}`: {}", s, err); + eprintln!("Ignoring directive `{s}`: {err}",); None } }) { diff --git a/src/libs/merkle_tree/src/lib.rs b/src/libs/merkle_tree/src/lib.rs index 4db52c3e1c..1d81d8f8b7 100644 --- a/src/libs/merkle_tree/src/lib.rs +++ b/src/libs/merkle_tree/src/lib.rs @@ -438,8 +438,7 @@ impl Block { for i in 0..limit { if self.hashes[i] == HashValue::new() { return Err(eg!(format!( - "Hash entry {} for block {} at level {} is invalid.", - i, id, level + "Hash entry {i} for block {id} at level {level} is invalid.", ))); } } @@ -583,7 +582,7 @@ impl Drop for AppendOnlyMerkle { #[inline(always)] fn drop(&mut self) { if let Err(e) = self.write() { - panic!("AppendOnlyMerkle: drop failed, err = {}", e); + panic!("AppendOnlyMerkle: drop failed, err = {e}",); } } } @@ -672,7 +671,7 @@ impl AppendOnlyMerkle { let save = path.to_owned() + &ext; if path::Path::new(&save).exists() { - return Err(eg!(format!("Rebuild path {} already exists.", save))); + return Err(eg!(format!("Rebuild path {save} already exists.",))); } // Rename the level zero file out of the way and then create @@ -709,7 +708,7 @@ impl AppendOnlyMerkle { let file_size = input.seek(SeekFrom::End(0)).c(d!())?; let block_count = file_size / BLOCK_SIZE as u64; - input.seek(SeekFrom::Start(0)).c(d!())?; + input.rewind().c(d!())?; self.files[0] = input; let mut entries = 0; @@ -807,8 +806,7 @@ impl AppendOnlyMerkle { Ok(b) => b, Err(x) => { return Err(eg!(format!( - "Reconstruction of block {} at level {} failed: {}", - block_id, level, x + "Reconstruction of block {block_id} at level {level} failed: {x}", ))); } }; @@ -907,7 +905,7 @@ impl AppendOnlyMerkle { let path = self.path.clone(); let extension = if level > 0 { - format!(".{}", level) + format!(".{level}",) } else { "".to_string() }; @@ -966,7 +964,7 @@ impl AppendOnlyMerkle { return self.recover_file(level); } - if self.files[level].seek(SeekFrom::Start(0)).is_err() { + if self.files[level].rewind().is_err() { return self.recover_file(level); } @@ -1251,7 +1249,7 @@ impl AppendOnlyMerkle { let (block, prev) = items; if let Err(x) = block.set_hash(¤t_hash) { - return Err(eg!(format!("The tree is corrupted: set_hash: {}", x))); + return Err(eg!(format!("The tree is corrupted: set_hash: {x}",))); } // If the block is full, and all the previous blocks are @@ -1344,8 +1342,7 @@ impl AppendOnlyMerkle { pub fn generate_proof(&self, transaction_id: u64, version: u64) -> Result { if transaction_id >= self.entry_count { return Err(eg!(format!( - "That transaction id ({}) does not exist.", - transaction_id + "That transaction id ({transaction_id}) does not exist.", ))); } @@ -1696,8 +1693,7 @@ impl AppendOnlyMerkle { Ok(n) => { if n != start_offset { return Err(eg!(format!( - "A seek to {} returned {}.", - start_offset, n + "A seek to {start_offset} returned {n}.", ))); } } @@ -1721,8 +1717,7 @@ impl AppendOnlyMerkle { if i < total_blocks - 1 && !block.full() { return Err(eg!(format!( - "Block {} at level {} should be full.", - i, level + "Block {i} at level {level} should be full.", ))); } @@ -1772,8 +1767,7 @@ impl AppendOnlyMerkle { if disk_bytes != expected_size { return Err(eg!(format!( - "check_disk: The file size ({}) at level {} should be {}.", - disk_bytes, level, expected_size + "check_disk: The file size ({disk_bytes}) at level {level} should be {expected_size}.", ))); } @@ -1783,13 +1777,12 @@ impl AppendOnlyMerkle { if flushed && blocks_on_disk != list_length { return Err(eg!(format!( - "check_disk: The count {} at level {} should be {}.", - blocks_on_disk, level, list_length + "check_disk: The count {blocks_on_disk} at level {level} should be {list_length}.", ))); } - if let Err(x) = self.files[level].seek(SeekFrom::Start(0)) { - return Err(eg!(format!("check_disk: The read seek failed: {}", x))); + if let Err(x) = self.files[level].rewind() { + return Err(eg!(format!("check_disk: The read seek failed: {x}",))); } let mut entry_count = 0_u64; @@ -1817,7 +1810,7 @@ impl AppendOnlyMerkle { current.push(block); } Err(x) => { - return Err(eg!(format!("check_disk: A read failed: {}", x))); + return Err(eg!(format!("check_disk: A read failed: {x}",))); } } } @@ -1828,9 +1821,8 @@ impl AppendOnlyMerkle { // contents if the memory has been flushed. if flushed && entry_count != entries_at_this_level { return Err(eg!(format!( - "check_disk: The entry counts ({}, {}) \ - at level {} didn't match.", - entry_count, entries_at_this_level, level + "check_disk: The entry counts ({entry_count}, {entries_at_this_level}) \ + at level {level} didn't match.", ))); } @@ -1936,8 +1928,7 @@ impl AppendOnlyMerkle { if !last && !last_block_full { return Err(eg!(format!( - "check: Block {} at level {} should be full.", - block_id, level + "check: Block {block_id} at level {level} should be full.", ))); } @@ -1957,8 +1948,7 @@ impl AppendOnlyMerkle { if leaf_count != leaves_at_this_level { return Err(eg!(format!( - "check: The entry counts ({}, {}) at level {} did not match", - leaf_count, leaves_at_this_level, level + "check: The entry counts ({leaf_count}, {leaves_at_this_level}) at level {level} did not match", ))); } @@ -1974,9 +1964,8 @@ impl AppendOnlyMerkle { if last_level && leaves_at_this_level > 0 { return Err(eg!(format!( - "Level {} has {} blocks, with {} upper leaves, \ + "Level {level} has {last_blocks} blocks, with {leaves_at_this_level} upper leaves, \ but no levels remain.", - level, last_blocks, leaves_at_this_level ))); } } @@ -2088,7 +2077,7 @@ mod tests { #[test] fn test_info() { println!("The block size is {} bytes.", mem::size_of::()); - println!("A block contains {} leaves.", LEAVES_IN_BLOCK); + println!("A block contains {LEAVES_IN_BLOCK} leaves.",); } // Do some basic tests on the block header code to make sure that @@ -2098,7 +2087,7 @@ mod tests { let mut header = BlockHeader::new(3, 5); if let Err(e) = header.check(3, 5) { - panic!("new() returned an invalid header: {}", e); + panic!("new() returned an invalid header: {e}",); } header.header_mark ^= 1; @@ -2131,7 +2120,7 @@ mod tests { fn check_block(block: &Block, level: usize, id: u64, disk_format: bool) { if let Err(e) = block.check(level, id, disk_format) { - panic!("Unexpected block check error: {}", e); + panic!("Unexpected block check error: {e}",); } } @@ -2162,13 +2151,13 @@ mod tests { hash.hash[1] = (i & 0xff) as u8; if let Err(e) = block.set_hash(&hash) { - panic!("Unexpected set_hash error: {} at {}", e, i); + panic!("Unexpected set_hash error: {e} at {i}"); } block.set_checksum(); if let Err(e) = block.check(1, 2, false) { - panic!("Block check failure at iteration {}: {}", i, e); + panic!("Block check failure at iteration {i}: {e}"); } // If the block is not full, there will still be hash entries @@ -2211,7 +2200,7 @@ mod tests { check_block(&block, 1, 2, false); if block.valid_leaves() != i as u64 + 1 { - panic!("valid_leaves() should be {}", i); + panic!("valid_leaves() should be {i}",); } if !block.full() { @@ -2226,7 +2215,7 @@ mod tests { let error = block.set_hash(&hash); if let Ok(()) = error { - panic!("Missing error at iteration {}.", i); + panic!("Missing error at iteration {i}.",); } } @@ -2237,7 +2226,7 @@ mod tests { // Now check that mismatched block ids and levels are // caught. First, make sure that the block is valid. if let Err(e) = block.check(1, 2, false) { - panic!("The block was corrupted by set_hash: {}", e); + panic!("The block was corrupted by set_hash: {e}",); } if block.check(0, 2, false).is_ok() { @@ -2258,7 +2247,7 @@ mod tests { block.header.check_bits.bits[0] ^= 1; if let Err(e) = block.check(1, 2, false) { - panic!("Testing error: {}", e); + panic!("Testing error: {e}",); } // Now corrupt checksum[last] and do the checks. @@ -2271,7 +2260,7 @@ mod tests { block.header.check_bits.bits[CHECK_SIZE - 1] ^= 1; if let Err(e) = block.check(1, 2, false) { - panic!("Testing error: {}", e); + panic!("Testing error: {e}",); } // Okay, corrupt a hash in the subtree. @@ -2333,7 +2322,7 @@ mod tests { let mut tree = match result { Ok(tree) => tree, Err(x) => { - panic!("Unexpected error: {}", x); + panic!("Unexpected error: {x}",); } }; @@ -2341,7 +2330,7 @@ mod tests { check_tree(&tree); if let Err(x) = AppendOnlyMerkle::open(&path) { - panic!("read() got an error: {}", x); + panic!("read() got an error: {x}",); } if tree.path() != path { @@ -2360,7 +2349,7 @@ mod tests { tree = match AppendOnlyMerkle::open(&path) { Err(x) => { - panic!("Open failed: {}", x); + panic!("Open failed: {x}",); } Ok(x) => x, }; @@ -2386,7 +2375,7 @@ mod tests { // Check that the image can be read and is reasonable. match AppendOnlyMerkle::open(&path) { Err(x) => { - panic!("The open failed: {}", x); + panic!("The open failed: {x}",); } Ok(new_tree) => { if new_tree.total_size() != tree.total_size() { @@ -2398,12 +2387,12 @@ mod tests { let level_path = tree.file_path(1); if let Err(x) = fs::remove_file(&level_path) { - panic!("remove_file failed: {}", x); + panic!("remove_file failed: {x}",); } let mut tree = match AppendOnlyMerkle::open(&path) { Err(x) => { - panic!("Open failed to rebuild: {}", x); + panic!("Open failed to rebuild: {x}",); } Ok(tree) => tree, }; @@ -2415,7 +2404,7 @@ mod tests { // Now make sure that the new write path deals well with // disk reset operations. if let Err(e) = tree.reset_disk() { - panic!("Unexpected error: {}", e); + panic!("Unexpected error: {e}",); } for _i in 0..2 * LEAVES_IN_BLOCK { @@ -2455,25 +2444,25 @@ mod tests { fn check_tree(tree: &AppendOnlyMerkle) { if let Err(e) = tree.check() { - panic!("Got check error: {}", e); + panic!("Got check error: {e}",); } } fn check_disk_tree(tree: &mut AppendOnlyMerkle, flushed: bool) { if let Err(e) = tree.check_disk(flushed) { - panic!("Got disk check error: {}", e); + panic!("Got disk check error: {e}",); } } fn write_tree(tree: &mut AppendOnlyMerkle) { if let Err(e) = tree.write() { - panic!("tree.write failed: {}", e); + panic!("tree.write failed: {e}",); } } fn reset_tree(tree: &mut AppendOnlyMerkle) { if let Err(e) = tree.reset_disk() { - panic!("tree.reset_disk failed: {}", e); + panic!("tree.reset_disk failed: {e}",); } } @@ -2482,7 +2471,7 @@ mod tests { let result = tree.append_hash(&hash); if let Err(x) = result { - panic!("append_hash failed: {}", x); + panic!("append_hash failed: {x}",); } result.unwrap() @@ -2500,7 +2489,7 @@ mod tests { let mut tree = match result { Err(x) => { - panic!("Unexpected error: {}", x); + panic!("Unexpected error: {x}",); } Ok(tree) => tree, }; @@ -2544,7 +2533,7 @@ mod tests { check_disk_tree(&mut tree, false); if let Err(x) = AppendOnlyMerkle::open(&path) { - panic!("Open failed: {}", x); + panic!("Open failed: {x}",); } } @@ -2577,11 +2566,11 @@ mod tests { // Try a reconstruct match tree.reconstruct(1, 0) { Err(x) => { - panic!("reconstruct failed: {}", x); + panic!("reconstruct failed: {x}",); } Ok(block) => { if let Err(e) = block.check(1, 0, true) { - panic!("The reconstruct block is bad: {}", e); + panic!("The reconstruct block is bad: {e}",); } for i in 0..HASHES_IN_BLOCK { @@ -2630,7 +2619,7 @@ mod tests { check_disk_tree(&mut tree, true); if let Err(x) = AppendOnlyMerkle::open(&path) { - panic!("open failed: {}", x); + panic!("open failed: {x}",); } reset_tree(&mut tree); @@ -2662,7 +2651,7 @@ mod tests { match result { Err(x) => { - panic!("The open failed: {}", x); + panic!("The open failed: {x}",); } Ok(x) => { tree = x; @@ -2685,7 +2674,7 @@ mod tests { // Okay, do a minimal test of the rewrite function. if let Err(e) = tree.reset_disk() { - panic!("test_tree: failed at tree.reset_disk with error {}", e); + panic!("test_tree: failed at tree.reset_disk with error {e}",); } println!("Syncing and checking the reopened tree."); @@ -2697,7 +2686,7 @@ mod tests { let tree = match AppendOnlyMerkle::rebuild(&path) { Err(x) => { - panic!("Rebuild failed: {}", x); + panic!("Rebuild failed: {x}",); } Ok(tree) => tree, }; @@ -2710,7 +2699,7 @@ mod tests { for i in 0..count { if tree.leaf(i as usize) != create_test_hash(i, false) { - panic!("Leaf {} does not match.", i); + panic!("Leaf {i} does not match.",); } } @@ -2837,7 +2826,7 @@ mod tests { } } - println!("Got {} hashes.", count); + println!("Got {count} hashes.",); assert!(count == 9); let last = entry.hashes.len() - 1; println!("hashes[last = {}] = {}", last, entry.hashes[last].desc()); @@ -2870,7 +2859,7 @@ mod tests { let mut tree = match AppendOnlyMerkle::create(&path) { Ok(x) => x, Err(x) => { - panic!("Error on open: {}", x); + panic!("Error on open: {x}",); } }; @@ -2895,7 +2884,7 @@ mod tests { for i in 0..tree.total_size() { match tree.generate_proof(i, tree.total_size()) { Err(x) => { - panic!("Error on proof for transaction {}: {}", i, x); + panic!("Error on proof for transaction {i}: {x}"); } Ok(proof) => { check_proof(&tree, &proof, i); @@ -2918,7 +2907,7 @@ mod tests { let mut tree = match AppendOnlyMerkle::create(&path) { Ok(x) => x, Err(x) => { - panic!("Error on open: {}", x); + panic!("Error on open: {x}",); } }; @@ -2934,7 +2923,7 @@ mod tests { // of a test. match tree.generate_proof(id, tree.total_size()) { Err(x) => { - panic!("Error on proof for transaction {}: {}", i, x); + panic!("Error on proof for transaction {i}: {x}"); } Ok(proof) => { assert!(id == i); @@ -2961,7 +2950,7 @@ mod tests { // Generating a proof for a non-existent transaction // should fail. if let Ok(_x) = tree.generate_proof(transactions, tree.total_size()) { - panic!("Transaction {} does not exist.", transactions); + panic!("Transaction {transactions} does not exist.",); } // @@ -3009,7 +2998,7 @@ mod tests { let mut tree = match AppendOnlyMerkle::create(&path) { Ok(x) => x, Err(e) => { - panic!("Create failed: {}", e); + panic!("Create failed: {e}",); } }; @@ -3036,24 +3025,24 @@ mod tests { let mut tree: AppendOnlyMerkle = match serde_json::from_str(&encoded) { Ok(x) => x, Err(e) => { - panic!("from_str failed: {}", e); + panic!("from_str failed: {e}",); } }; if let Err(e) = tree.finish_deserialize() { - panic!("test_serde: tree.finish_deserialize failed with err {}", e); + panic!("test_serde: tree.finish_deserialize failed with err {e}",); } if let Err(e) = tree.check() { - panic!("test_serde: tree.check failed with err {}", e); + panic!("test_serde: tree.check failed with err {e}",); } if let Err(e) = tree.write() { - panic!("test_serde: tree.write failed with err {}", e); + panic!("test_serde: tree.write failed with err {e}",); } if let Err(e) = tree.check_disk(true) { - panic!("test_serde: tree.check_disk failed with err {}", e); + panic!("test_serde: tree.check_disk failed with err {e}",); } if tree.total_size() != size as u64 { @@ -3079,7 +3068,7 @@ mod tests { let mut tree = match AppendOnlyMerkle::create(&path) { Ok(x) => x, Err(e) => { - panic!("Create failed: {}", e); + panic!("Create failed: {e}",); } }; @@ -3093,11 +3082,11 @@ mod tests { match tree.reconstruct(1, 0) { Err(x) => { - panic!("Reconstruct failed: {}", x); + panic!("Reconstruct failed: {x}",); } Ok(block) => { if let Err(e) = block.check(1, 0, true) { - panic!("block.check failed with {}", e); + panic!("block.check failed with {e}",); } for i in 0..HASHES_IN_BLOCK { @@ -3160,7 +3149,7 @@ mod tests { let mut tree = match AppendOnlyMerkle::create(&path) { Ok(tree) => tree, Err(x) => { - panic!("create failed: {}", x); + panic!("create failed: {x}",); } }; @@ -3169,7 +3158,7 @@ mod tests { } if let Err(e) = tree.write() { - panic!("test_basic_rebuild: tree.write failed with {}", e); + panic!("test_basic_rebuild: tree.write failed with {e}",); } let fake = path.to_owned() + "." + &tree.files.len().to_string(); @@ -3177,9 +3166,9 @@ mod tests { let result = OpenOptions::new().create(true).write(true).open(&fake); if let Err(x) = result { - panic!("I cannot create {}: {}", fake, x); + panic!("I cannot create {fake}: {x}"); } else { - println!("Created {}.", fake); + println!("Created {fake}."); } let final_size = tree.total_size(); @@ -3188,7 +3177,7 @@ mod tests { let tree = match AppendOnlyMerkle::rebuild(&path) { Ok(tree) => tree, Err(x) => { - panic!("rebuild failed: {}", x); + panic!("rebuild failed: {x}",); } }; @@ -3202,7 +3191,7 @@ mod tests { for i in 0..4 * LEAVES_IN_BLOCK { if tree.leaf(i) != create_test_hash(i as u64, false) { - panic!("Leaf {} does not match.", i); + panic!("Leaf {i} does not match.",); } } @@ -3228,7 +3217,7 @@ mod tests { let result = fs::remove_file(&fake_ext); if let Err(x) = result { - panic!("File {} was not deleted: {}", fake_ext, x); + panic!("File {fake_ext} was not deleted: {x}"); } } } diff --git a/src/libs/sliding_set/src/lib.rs b/src/libs/sliding_set/src/lib.rs index 9fd715a6cc..a6690ec022 100644 --- a/src/libs/sliding_set/src/lib.rs +++ b/src/libs/sliding_set/src/lib.rs @@ -65,15 +65,14 @@ impl SlidingSet { if index <= self.current && index + self.width >= (self.current + 1) { if self.map[index % self.width].contains(&key) { Err(eg!(format!( - "SlidingSet::insert: ({:?}, {}) already in set", - key, index + "SlidingSet::insert: ({key:?}, {index}) already in set", ))) } else { self.map[index % self.width].push(key); Ok(()) } } else { - Err(eg!(format!("({:?}, {}) is out of range", key, index))) + Err(eg!(format!("({key:?}, {index}) is out of range",))) } } } diff --git a/src/libs/sparse_merkle_tree/src/lib.rs b/src/libs/sparse_merkle_tree/src/lib.rs index df1b606a03..e06cace5c7 100644 --- a/src/libs/sparse_merkle_tree/src/lib.rs +++ b/src/libs/sparse_merkle_tree/src/lib.rs @@ -480,7 +480,7 @@ mod tests { .unwrap() .as_nanos(); let mut path = temp_dir(); - path.push(format!("temp-findora-db–{}", time)); + path.push(format!("temp-findora-db–{time}",)); TempRocksDB::open(path).expect("failed to open rocksdb") } @@ -910,7 +910,7 @@ fn test_nullfier() { .unwrap() .as_nanos(); let mut path = temp_dir(); - path.push(format!("temp-findora-db–{}", time)); + path.push(format!("temp-findora-db–{time}",)); let rocksdb = TempRocksDB::open(path).expect("failed to open rocksdb"); let mut smt = SmtMap256::new(rocksdb); From 13388f041f24f9c25516c870a849c7583dae8d86 Mon Sep 17 00:00:00 2001 From: simonjiao Date: Wed, 1 Feb 2023 11:13:32 +0800 Subject: [PATCH 5/6] Fix reentrant hang issue (#707) * fix unhandled transaction * fix evm deliver_tx nonce * update startnodes.sh and checkpoint file --------- Co-authored-by: simonjiao --- src/components/config/src/abci/mod.rs | 6 + .../contracts/modules/ethereum/src/impls.rs | 165 ++++++++++-------- .../contracts/modules/ethereum/src/lib.rs | 40 +++++ .../primitives/core/src/transaction.rs | 30 +++- tools/devnet/startnodes.sh | 5 - 5 files changed, 164 insertions(+), 82 deletions(-) diff --git a/src/components/config/src/abci/mod.rs b/src/components/config/src/abci/mod.rs index e4a94faee7..01f8e6ed6d 100644 --- a/src/components/config/src/abci/mod.rs +++ b/src/components/config/src/abci/mod.rs @@ -87,6 +87,10 @@ pub struct CheckPointConfig { // Fix the amount in the delegators that staking did not modify when it punished the validator. pub fix_delegators_am_height: u64, pub validators_limit_v2_height: u64, + + // https://github.com/FindoraNetwork/platform/pull/707 + // FO-1370: V0.3.30 EVM bug: receipt missing when error code === 1 + pub fix_deliver_tx_revert_nonce_height: i64, } impl CheckPointConfig { @@ -127,6 +131,7 @@ impl CheckPointConfig { proper_gas_set_height: 0, fix_delegators_am_height: 0, validators_limit_v2_height: 0, + fix_deliver_tx_revert_nonce_height: 0, }; #[cfg(not(feature = "debug_env"))] let config = CheckPointConfig { @@ -155,6 +160,7 @@ impl CheckPointConfig { fix_undelegation_missing_reward_height: 3000000, fix_delegators_am_height: 30000000, validators_limit_v2_height: 30000000, + fix_deliver_tx_revert_nonce_height: 40000000, }; let content = toml::to_string(&config).unwrap(); file.write_all(content.as_bytes()).unwrap(); diff --git a/src/components/contracts/modules/ethereum/src/impls.rs b/src/components/contracts/modules/ethereum/src/impls.rs index 639098b04b..be2f542d8b 100644 --- a/src/components/contracts/modules/ethereum/src/impls.rs +++ b/src/components/contracts/modules/ethereum/src/impls.rs @@ -16,6 +16,7 @@ use fp_core::{ use fp_events::Event; use fp_evm::{BlockId, CallOrCreateInfo, Runner, TransactionStatus}; use fp_storage::{Borrow, BorrowMut}; +use fp_types::crypto::Address; use fp_types::{ actions::evm as EvmAction, crypto::{secp256k1_ecdsa_recover, HA256}, @@ -249,72 +250,95 @@ impl App { transaction.action, ); - if let Err(e) = execute_ret { - let mut to = Default::default(); - if let ethereum::TransactionAction::Call(target) = transaction.action { - to = target; - } - events.push(Event::emit_event( - Self::name(), - TransactionExecuted { - sender: source, - to, - contract_address: Default::default(), - transaction_hash, - reason: ExitReason::Fatal(ExitFatal::UnhandledInterrupt), - }, - )); - - return Ok(ActionResult { - code: 1, - data: vec![], - log: format!("{e}",), - gas_wanted: gas_limit.low_u64(), - gas_used: 0, - events, - }); - } + let (ar_code, info, to, contract_address, reason, data, status, used_gas) = + match execute_ret { + Err(e) => { + let to = if let ethereum::TransactionAction::Call(target) = + transaction.action + { + Some(target) + } else { + None + }; + + let logs = vec![ethereum::Log { + address: source, + topics: vec![], + data: format!("{e}").as_str().into(), + }]; + + let reason = ExitReason::Fatal(ExitFatal::UnhandledInterrupt); + let data = vec![]; + let status = TransactionStatus { + transaction_hash, + transaction_index, + from: source, + to, + contract_address: None, + logs: logs.clone(), + logs_bloom: { + let mut bloom: Bloom = Bloom::default(); + Self::logs_bloom(logs, &mut bloom); + bloom + }, + }; + let used_gas = U256::zero(); + + (Some(1), None, to, None, reason, data, status, used_gas) + } - let (to, contract_address, info) = execute_ret.unwrap(); - - let (reason, data, status, used_gas) = match info.clone() { - CallOrCreateInfo::Call(info) => ( - info.exit_reason, - info.value.clone(), - TransactionStatus { - transaction_hash, - transaction_index, - from: source, - to, - contract_address: None, - logs: info.logs.clone(), - logs_bloom: { - let mut bloom: Bloom = Bloom::default(); - Self::logs_bloom(info.logs, &mut bloom); - bloom - }, - }, - info.used_gas, - ), - CallOrCreateInfo::Create(info) => ( - info.exit_reason, - vec![], - TransactionStatus { - transaction_hash, - transaction_index, - from: source, - to, - contract_address: Some(info.value), - logs: info.logs.clone(), - logs_bloom: { - let mut bloom: Bloom = Bloom::default(); - Self::logs_bloom(info.logs, &mut bloom); - bloom - }, - }, - info.used_gas, - ), - }; + Ok((to, contract_address, info)) => { + let (reason, data, status, used_gas) = match info.clone() { + CallOrCreateInfo::Call(info) => ( + info.exit_reason, + info.value.clone(), + TransactionStatus { + transaction_hash, + transaction_index, + from: source, + to, + contract_address: None, + logs: info.logs.clone(), + logs_bloom: { + let mut bloom: Bloom = Bloom::default(); + Self::logs_bloom(info.logs, &mut bloom); + bloom + }, + }, + info.used_gas, + ), + CallOrCreateInfo::Create(info) => ( + info.exit_reason, + vec![], + TransactionStatus { + transaction_hash, + transaction_index, + from: source, + to, + contract_address: Some(info.value), + logs: info.logs.clone(), + logs_bloom: { + let mut bloom: Bloom = Bloom::default(); + Self::logs_bloom(info.logs, &mut bloom); + bloom + }, + }, + info.used_gas, + ), + }; + + ( + None, + Some(info), + to, + contract_address, + reason, + data, + status, + used_gas, + ) + } + }; for log in &status.logs { debug!(target: "ethereum", "transaction status log: block: {:?}, address: {:?}, topics: {:?}, data: {:?}", @@ -332,7 +356,7 @@ impl App { let (code, message) = match reason { ExitReason::Succeed(_) => (0, String::new()), - // code 1 indicates `Failed to execute evm function`, see above + // code 1 indicates `Failed to execute evm function`, see the `ar_code` ExitReason::Error(_) => (2, "EVM error".to_string()), ExitReason::Revert(_) => { let mut message = @@ -348,7 +372,9 @@ impl App { } (3, message) } - ExitReason::Fatal(_) => (4, "EVM Fatal error".to_string()), + ExitReason::Fatal(_) => { + (ar_code.unwrap_or(4), "EVM Fatal error".to_string()) + } }; if code != 0 { @@ -393,7 +419,10 @@ impl App { Ok(ActionResult { code, - data: serde_json::to_vec(&info).unwrap_or_default(), + source: Some(Address::from(source)), + data: info + .and_then(|i| serde_json::to_vec(&i).ok()) + .unwrap_or_default(), log: message, gas_wanted: gas_limit.low_u64(), gas_used: used_gas.low_u64(), diff --git a/src/components/contracts/modules/ethereum/src/lib.rs b/src/components/contracts/modules/ethereum/src/lib.rs index f329052388..33ae06e799 100644 --- a/src/components/contracts/modules/ethereum/src/lib.rs +++ b/src/components/contracts/modules/ethereum/src/lib.rs @@ -24,6 +24,7 @@ use fp_traits::{ use fp_types::{actions::ethereum::Action, crypto::Address}; use ruc::*; use std::marker::PhantomData; +use tracing::debug; pub const MODULE_NAME: &str = "ethereum"; @@ -234,6 +235,45 @@ impl ValidateUnsigned for App { Ok(()) } + + fn post_execute(ctx: &Context, result: &ActionResult) -> Result<()> { + if result.code != 0 + && ctx.header.height >= CFG.checkpoint.fix_deliver_tx_revert_nonce_height + { + let prev = result + .source + .as_ref() + .map(|who| C::AccountAsset::nonce(ctx, who)) + .unwrap_or_default(); + + ctx.state.write().discard_session(); + + // If EVM transaction fails, state change gets reverted/discarded except nonce. + let current = result + .source + .as_ref() + .map(|who| C::AccountAsset::nonce(ctx, who)) + .unwrap_or_default(); + + if prev.gt(¤t) { + if let Some(who) = result.source.as_ref() { + debug!( + target: + "baseapp", + "In post_execute: source {} {} {}", + who, + prev, + current + ); + // Keep it same with `pre_execute` + let _ = C::AccountAsset::inc_nonce(ctx, who); + } else { + unreachable!(); + } + } + } + Ok(()) + } } impl BlockHashMapping for App { diff --git a/src/components/contracts/primitives/core/src/transaction.rs b/src/components/contracts/primitives/core/src/transaction.rs index 1cc848dcfc..efef55a6c2 100644 --- a/src/components/contracts/primitives/core/src/transaction.rs +++ b/src/components/contracts/primitives/core/src/transaction.rs @@ -1,7 +1,7 @@ use crate::context::{Context, RunTxMode}; use abci::Event; use config::abci::global_cfg::CFG; -use fp_types::transaction::CheckedTransaction; +use fp_types::{crypto::Address, transaction::CheckedTransaction}; use impl_trait_for_tuples::impl_for_tuples; use ruc::*; use std::fmt::Debug; @@ -117,6 +117,12 @@ pub trait ValidateUnsigned { /// /// Changes made to storage should be discarded by caller. fn validate_unsigned(ctx: &Context, call: &Self::Call) -> Result<()>; + + /// Do any post-flight stuff for an transaction. + /// + fn post_execute(_ctx: &Context, _result: &ActionResult) -> Result<()> { + Ok(()) + } } impl Applyable for CheckedTransaction @@ -143,12 +149,12 @@ where U: ValidateUnsigned, U: Executable, { - let (maybe_who, pre) = if let Some((sender, extra)) = self.signed { + let (signed_tx, maybe_who, pre) = if let Some((sender, extra)) = self.signed { let pre = Extra::pre_execute(extra, ctx, &sender)?; - (Some(sender), pre) + (true, Some(sender), pre) } else { U::pre_execute(ctx, &self.function)?; - (None, Default::default()) + (false, None, Default::default()) }; ctx.state.write().commit_session(); @@ -167,12 +173,16 @@ where res.log = String::from("ctx state is not good to commit"); ctx.state.write().discard_session(); - } else if res.code == 0 { - Extra::post_execute(ctx, pre, &res)?; - - ctx.state.write().commit_session(); + } else if signed_tx { + if res.code == 0 { + Extra::post_execute(ctx, pre, &res)?; + ctx.state.write().commit_session(); + } else { + ctx.state.write().discard_session(); + } } else { - ctx.state.write().discard_session(); + U::post_execute(ctx, &res)?; + ctx.state.write().commit_session(); } ctx.db.write().commit_session(); @@ -198,6 +208,8 @@ pub struct ActionResult { /// 4 - EVM ExitReason::Fatal /// 0xff - context state maybe messed up pub code: u32, + /// Record the source address + pub source: Option
, /// Data is any data returned from message or handler execution. pub data: Vec, /// Log contains the log information from message or handler execution. diff --git a/tools/devnet/startnodes.sh b/tools/devnet/startnodes.sh index 12511316b7..f887f5f237 100755 --- a/tools/devnet/startnodes.sh +++ b/tools/devnet/startnodes.sh @@ -2,11 +2,6 @@ # env source ./tools/devnet/env.sh || exit 1 -DEFAULT_BIN_CFG="release" -export BIN="target/$DEFAULT_BIN_CFG" - -$BIN/fn setup -S $ENDPOINT > /dev/null -$BIN/fn setup -O $WALLET/mnenomic.key > /dev/null # start one single node if specified Node="" From 3dd406cdb887c8e2a2319659d707fb41bfc10919 Mon Sep 17 00:00:00 2001 From: simonjiao Date: Thu, 2 Feb 2023 00:43:49 +0800 Subject: [PATCH 6/6] Fo-1159 (#708) * honor block_number in call rpc * add clean_aux() fmerk update * enable snapshot * update storage version * rename trace/fresh options * update noah version * fix build error --------- Co-authored-by: simonjiao Co-authored-by: harry --- src/components/abciapp/Cargo.toml | 4 +- src/components/abciapp/src/abci/server/mod.rs | 8 ++- src/components/abciapp/src/bins/abcid.rs | 3 +- src/components/abciapp/src/bins/findorad.rs | 12 +++- src/components/config/src/abci/mod.rs | 39 +++++++++++++ src/components/config/src/findora/mod.rs | 39 +++++++++++++ src/components/contracts/baseapp/Cargo.toml | 4 +- src/components/contracts/baseapp/src/lib.rs | 44 +++++++++----- .../contracts/modules/account/Cargo.toml | 10 ++-- .../contracts/modules/ethereum/Cargo.toml | 4 +- .../contracts/modules/evm/Cargo.toml | 10 ++-- .../modules/evm/precompile/Cargo.toml | 4 +- .../modules/evm/src/runtime/runner.rs | 15 ++--- .../modules/evm/src/runtime/stack.rs | 17 ++++-- .../contracts/primitives/core/Cargo.toml | 4 +- .../contracts/primitives/core/src/context.rs | 16 +++++ .../contracts/primitives/mocks/Cargo.toml | 2 +- .../contracts/primitives/mocks/src/lib.rs | 5 +- .../contracts/primitives/storage/Cargo.toml | 4 +- .../contracts/primitives/types/Cargo.toml | 4 +- src/components/contracts/rpc/src/eth.rs | 58 ++++++++----------- src/components/finutils/Cargo.toml | 6 +- src/components/wallet_mobile/Cargo.toml | 4 +- src/components/wasm/Cargo.toml | 6 +- src/ledger/Cargo.toml | 12 ++-- src/libs/credentials/Cargo.toml | 2 +- src/libs/globutils/Cargo.toml | 6 +- src/libs/sparse_merkle_tree/Cargo.toml | 6 +- tools/devnet/env.sh | 6 +- 29 files changed, 237 insertions(+), 117 deletions(-) diff --git a/src/components/abciapp/Cargo.toml b/src/components/abciapp/Cargo.toml index f2a4e393cf..0ec73a3667 100644 --- a/src/components/abciapp/Cargo.toml +++ b/src/components/abciapp/Cargo.toml @@ -44,8 +44,8 @@ ruc = { version = "1.0.5", default-features = false, features = ["compact"] } module-evm = { path = "../contracts/modules/evm"} ethereum-types = { version = "0.13.1", default-features = false } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.5" } config = { path = "../config"} diff --git a/src/components/abciapp/src/abci/server/mod.rs b/src/components/abciapp/src/abci/server/mod.rs index 8983e406e4..dc252eebd0 100644 --- a/src/components/abciapp/src/abci/server/mod.rs +++ b/src/components/abciapp/src/abci/server/mod.rs @@ -56,13 +56,17 @@ impl ABCISubmissionServer { None => { pnk!(AccountBaseAPP::new( tempfile::tempdir().unwrap().path(), - CFG.disable_eth_empty_blocks + CFG.disable_eth_empty_blocks, + CFG.arc_history, + CFG.arc_fresh )) } Some(basedir) => { pnk!(AccountBaseAPP::new( Path::new(basedir), - CFG.disable_eth_empty_blocks + CFG.disable_eth_empty_blocks, + CFG.arc_history, + CFG.arc_fresh )) } }; diff --git a/src/components/abciapp/src/bins/abcid.rs b/src/components/abciapp/src/bins/abcid.rs index 949b61c50a..0f78f14b4c 100644 --- a/src/components/abciapp/src/bins/abcid.rs +++ b/src/components/abciapp/src/bins/abcid.rs @@ -13,8 +13,7 @@ use { fn main() { globutils::logging::init_logging(None); - - tracing::info!(concat!( + tracing::info!(target: "abciapp", concat!( "Build: ", env!("VERGEN_SHA"), " ", diff --git a/src/components/abciapp/src/bins/findorad.rs b/src/components/abciapp/src/bins/findorad.rs index cf450af88c..6c66de5c3a 100644 --- a/src/components/abciapp/src/bins/findorad.rs +++ b/src/components/abciapp/src/bins/findorad.rs @@ -49,6 +49,13 @@ fn node_command() -> Result<()> { .checkpoint_file .clone() .unwrap_or_else(|| String::from("./checkpoint.toml")); + let arc_history_arg = { + if let Some(interval) = CFG.arc_history.1 { + format!("{},{}", CFG.arc_history.0, interval) + } else { + format!("{}", CFG.arc_history.0) + } + }; abcid .arg("--submission-service-port") @@ -58,7 +65,9 @@ fn node_command() -> Result<()> { .arg("--checkpoint-file") .arg(&checkpoint_file) .arg("--ledger-dir") - .arg(&CFG.ledger_dir); + .arg(&CFG.ledger_dir) + .arg("--arc-history") + .arg(&arc_history_arg); for (condition, action) in [ (CFG.enable_query_service, "--enable-query-service"), @@ -67,6 +76,7 @@ fn node_command() -> Result<()> { (CFG.enable_snapshot, "--enable-snapshot"), (CFG.snapshot_list, "--snapshot-list"), (CFG.snapshot_rollback, "--snapshot-rollback"), + (CFG.arc_fresh, "--arc-fresh"), ] { if condition { abcid.arg(action); diff --git a/src/components/config/src/abci/mod.rs b/src/components/config/src/abci/mod.rs index 01f8e6ed6d..52b0193cc8 100644 --- a/src/components/config/src/abci/mod.rs +++ b/src/components/config/src/abci/mod.rs @@ -315,6 +315,8 @@ pub mod global_cfg { pub struct Config { pub abci_host: String, pub abci_port: u16, + pub arc_history: (u16, Option), + pub arc_fresh: bool, pub tendermint_host: String, pub tendermint_port: u16, pub submission_service_port: u16, @@ -348,6 +350,8 @@ pub mod global_cfg { .about("An ABCI node implementation of FindoraNetwork.") .arg_from_usage("--abcid-host=[ABCId IP]") .arg_from_usage("--abcid-port=[ABCId Port]") + .arg_from_usage("--arc-history=[EVM archive node tracing history, format \"PERIOD,INTERVAL\" in days]") + .arg_from_usage("--arc-fresh 'EVM archive node with fresh tracing history'") .arg_from_usage("--tendermint-host=[Tendermint IP]") .arg_from_usage("--tendermint-port=[Tendermint Port]") .arg_from_usage("--submission-service-port=[Submission Service Port]") @@ -391,6 +395,39 @@ pub mod global_cfg { .unwrap_or_else(|| "26658".to_owned()) .parse::() .c(d!("Invalid `abcid-port`."))?; + let arh = { + let trace = m + .value_of("arc-history") + .map(|v| v.to_owned()) + .or_else(|| env::var("ARC-HISTORY").ok()) + .unwrap_or_else(|| "90,10".to_string()) + .trim() + .to_owned(); + if trace.is_empty() { + return Err(eg!("empty trace")); + } + if trace.contains(',') { + let t = trace.split(',').collect::>(); + let trace = t + .first() + .expect("missing trace period") + .parse::() + .c(d!("invalid trace period"))?; + let interval = Some( + t.get(1) + .expect("missing trace interval") + .parse::() + .c(d!("invalid trace interval"))?, + ); + (trace, interval) + } else if !trace.is_empty() { + let trace = trace.parse::().c(d!("invalid trace period"))?; + (trace, None) + } else { + return Err(eg!("invalid trace")); + } + }; + let arf = m.is_present("arc-fresh"); let th = m .value_of("tendermint-host") .map(|v| v.to_owned()) @@ -462,6 +499,8 @@ pub mod global_cfg { let res = Config { abci_host: ah, abci_port: ap, + arc_history: arh, + arc_fresh: arf, tendermint_host: th, tendermint_port: tp, submission_service_port: ssp, diff --git a/src/components/config/src/findora/mod.rs b/src/components/config/src/findora/mod.rs index 36fa156c20..e4081b65bd 100644 --- a/src/components/config/src/findora/mod.rs +++ b/src/components/config/src/findora/mod.rs @@ -151,6 +151,8 @@ pub mod config { pub struct Config { pub tendermint_host: String, pub tendermint_port: u16, + pub arc_history: (u16, Option), + pub arc_fresh: bool, pub submission_service_port: u16, pub ledger_service_port: u16, pub enable_query_service: bool, @@ -182,6 +184,8 @@ pub mod config { let node = SubCommand::with_name("node") .about("Start findora node.") .arg_from_usage("-c, --config=[FILE] 'Path to $TMHOM/config/config.toml'") + .arg_from_usage("--arc-history=[EVM archive node tracing history, format \"PERIOD,INTERVAL\" in days]") + .arg_from_usage("--arc-fresh 'EVM archive node with fresh tracing history'") .arg_from_usage("-H, --tendermint-host=[Tendermint Node IP]") .arg_from_usage("-P, --tendermint-port=[Tendermint Node Port]") .arg_from_usage("--submission-service-port=[Submission Service Port]") @@ -276,6 +280,39 @@ pub mod config { .unwrap_or_else(|| "26657".to_owned()) .parse::() .c(d!())?; + let arh = { + let trace = m + .value_of("arc-history") + .map(|v| v.to_owned()) + .or_else(|| env::var("ARC-HISTORY").ok()) + .unwrap_or_else(|| "90,10".to_string()) + .trim() + .to_owned(); + if trace.is_empty() { + return Err(eg!("empty trace")); + } + if trace.contains(',') { + let t = trace.split(',').collect::>(); + let trace = t + .first() + .expect("missing trace period") + .parse::() + .c(d!("invalid trace period"))?; + let interval = Some( + t.get(1) + .expect("missing trace interval") + .parse::() + .c(d!("invalid trace interval"))?, + ); + (trace, interval) + } else if !trace.is_empty() { + let trace = trace.parse::().c(d!("invalid trace period"))?; + (trace, None) + } else { + return Err(eg!("invalid trace")); + } + }; + let arf = m.is_present("arc-fresh"); let ssp = m .value_of("submission-service-port") .map(|v| v.to_owned()) @@ -336,6 +373,8 @@ pub mod config { let res = Config { tendermint_host: th, tendermint_port: tp, + arc_history: arh, + arc_fresh: arf, submission_service_port: ssp, ledger_service_port: lsp, enable_query_service: eqs, diff --git a/src/components/contracts/baseapp/Cargo.toml b/src/components/contracts/baseapp/Cargo.toml index 74bc31e815..493dcd3dbf 100644 --- a/src/components/contracts/baseapp/Cargo.toml +++ b/src/components/contracts/baseapp/Cargo.toml @@ -25,8 +25,8 @@ serde_json = "1.0.40" attohttpc = { version = "0.18", default-features = false, features = ["compress", "json", "tls-rustls"] } base64 = "0.13" once_cell = "1.10.0" -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0" } -fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } +fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } sha3 = "0.8" config = { path = "../../config"} diff --git a/src/components/contracts/baseapp/src/lib.rs b/src/components/contracts/baseapp/src/lib.rs index 3a899fe32c..2b808a3230 100644 --- a/src/components/contracts/baseapp/src/lib.rs +++ b/src/components/contracts/baseapp/src/lib.rs @@ -37,22 +37,21 @@ use parking_lot::RwLock; use primitive_types::{H160, H256, U256}; use ruc::{eg, Result}; use std::{borrow::BorrowMut, path::Path, sync::Arc}; -use storage::state::ChainState; +use storage::state::{ChainState, ChainStateOpts}; +use tracing::info; lazy_static! { /// An identifier that distinguishes different EVM chains. static ref EVM_CAHIN_ID: u64 = std::env::var("EVM_CHAIN_ID").map( |id| id.as_str().parse::().unwrap()).unwrap_or(2152); - static ref CHAIN_STATE_MIN_VERSIONS: u64 = BLOCKS_IN_DAY * std::env::var("CHAIN_STATE_VERSIONS").map( - |ver|ver.as_str().parse::().expect("chainstate versions should be a valid integer") - ).unwrap_or(90); } const APP_NAME: &str = "findora"; const CHAIN_STATE_PATH: &str = "state.db"; const CHAIN_HISTORY_DATA_PATH: &str = "history.db"; const BLOCKS_IN_DAY: u64 = 4 * 60 * 24; +const SNAPSHOT_INTERVAL: u64 = 10 * 24; #[derive(Clone)] pub struct BaseApp { @@ -161,22 +160,33 @@ impl module_xhub::Config for BaseApp { } impl BaseApp { - pub fn new(basedir: &Path, empty_block: bool) -> Result { - tracing::info!( - "create new baseapp with basedir {:?}, empty_block {}, history {} blocks", - basedir, - empty_block, - *CHAIN_STATE_MIN_VERSIONS + pub fn new( + basedir: &Path, + empty_block: bool, + arc_history: (u16, Option), + is_fresh: bool, + ) -> Result { + info!( + target: "baseapp", + "create new baseapp with basedir {:?}, empty_block {}, trace history {:?} days, is_fresh {}", + basedir, empty_block, arc_history, is_fresh ); // Creates a fresh chain state db and history db let fdb_path = basedir.join(CHAIN_STATE_PATH); let fdb = FinDB::open(fdb_path.as_path())?; - let chain_state = Arc::new(RwLock::new(ChainState::new( - fdb, - "findora_db".to_owned(), - *CHAIN_STATE_MIN_VERSIONS, - ))); + + let opts = ChainStateOpts { + name: Some("findora_db".to_owned()), + ver_window: BLOCKS_IN_DAY * arc_history.0 as u64, + cleanup_aux: is_fresh, + interval: arc_history + .1 + .map_or(SNAPSHOT_INTERVAL * arc_history.0 as u64, |v| { + BLOCKS_IN_DAY * v as u64 + }), + }; + let chain_state = Arc::new(RwLock::new(ChainState::create_with_opts(fdb, opts))); let rdb_path = basedir.join(CHAIN_HISTORY_DATA_PATH); let rdb = RocksDB::open(rdb_path.as_path())?; @@ -298,6 +308,10 @@ impl BaseApp { } } + pub fn create_context_at(&self, height: u64) -> Option { + self.check_state.state_at(height) + } + /// retrieve the context for the txBytes and other memoized values. pub fn retrieve_context(&mut self, mode: RunTxMode) -> &mut Context { let ctx = if mode == RunTxMode::Deliver { diff --git a/src/components/contracts/modules/account/Cargo.toml b/src/components/contracts/modules/account/Cargo.toml index 73fe420c1b..a22538a039 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.0.0" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } # primitives, don't depend on any modules fp-core = { path = "../../primitives/core" } @@ -28,9 +28,9 @@ config = {path = "../../../config"} [dev-dependencies] parking_lot = "0.12" rand_chacha = "0.3" -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0" } -fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0" } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } +fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } [features] -web3_service = ["enterprise-web3"] \ No newline at end of file +web3_service = ["enterprise-web3"] diff --git a/src/components/contracts/modules/ethereum/Cargo.toml b/src/components/contracts/modules/ethereum/Cargo.toml index 8f6ccaf0c5..8b3243bdbe 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", optional = true baseapp = { path = "../../baseapp" } fp-mocks = { path = "../../primitives/mocks" } module-account = { path = "../account" } -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0" } -fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } +fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } [features] default = [] diff --git a/src/components/contracts/modules/evm/Cargo.toml b/src/components/contracts/modules/evm/Cargo.toml index 6bac465ee4..163e19cb4a 100644 --- a/src/components/contracts/modules/evm/Cargo.toml +++ b/src/components/contracts/modules/evm/Cargo.toml @@ -24,8 +24,8 @@ serde_json = "1.0.64" sha3 = { version = "0.10", default-features = false } hex = "0.4.2" ethabi = "17.1.0" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } # primitives, don't depend on any modules fp-core = { path = "../../primitives/core" } @@ -35,8 +35,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.0.0" } -fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } +fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } ledger = { path = "../../../../ledger" } enterprise-web3 = { path = "../../primitives/enterprise-web3", optional = true } @@ -49,4 +49,4 @@ module-ethereum = { path = "../ethereum" } serde_json = "1.0.64" [features] -web3_service = ["enterprise-web3"] \ No newline at end of file +web3_service = ["enterprise-web3"] diff --git a/src/components/contracts/modules/evm/precompile/Cargo.toml b/src/components/contracts/modules/evm/precompile/Cargo.toml index 3e59e2ede1..1b2cc1baf0 100644 --- a/src/components/contracts/modules/evm/precompile/Cargo.toml +++ b/src/components/contracts/modules/evm/precompile/Cargo.toml @@ -17,7 +17,7 @@ evm-precompile-sha3fips = {path = "./sha3fips" } evm-precompile-modexp = { path = "./modexp" } evm-precompile-frc20 = { path = "./frc20" } evm-precompile-eth-pairings = { path = "./eth-pairings" } -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v0.2.2" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } fp-core = { path = "../../../primitives/core" } parking_lot = "0.12" -fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v0.2.2" } +fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } diff --git a/src/components/contracts/modules/evm/src/runtime/runner.rs b/src/components/contracts/modules/evm/src/runtime/runner.rs index 7525ac9b17..ffc9459487 100644 --- a/src/components/contracts/modules/evm/src/runtime/runner.rs +++ b/src/components/contracts/modules/evm/src/runtime/runner.rs @@ -16,6 +16,7 @@ use fp_types::actions::evm::*; use ruc::*; use sha3::{Digest, Keccak256}; use std::marker::PhantomData; +use tracing::{debug, trace}; #[derive(Default)] pub struct ActionRunner { @@ -96,7 +97,7 @@ impl ActionRunner { let used_gas = U256::from(executor.used_gas()); let actual_fee = executor.fee(gas_price); - tracing::debug!( + debug!( target: "evm", "Execution {:?} [source: {:?}, value: {}, gas_price {}, gas_limit: {}, actual_fee: {}]", reason, @@ -115,7 +116,7 @@ impl ActionRunner { let state = executor.into_state(); for address in state.substate.deletes { - tracing::debug!( + debug!( target: "evm", "Deleting account at {:?}", address @@ -124,7 +125,7 @@ impl ActionRunner { } for log in &state.substate.logs { - tracing::trace!( + trace!( target: "evm", "Inserting log for {:?}, topics ({}) {:?}, data ({}): {:?}]", log.address, @@ -176,7 +177,7 @@ impl ActionRunner { let state = executor.into_state(); for address in state.substate.deletes { - tracing::debug!( + debug!( target: "evm", "Deleting account at {:?}", address @@ -185,7 +186,7 @@ impl ActionRunner { } for log in &state.substate.logs { - tracing::trace!( + trace!( target: "evm", "Inserting log for {:?}, topics ({}) {:?}, data ({}): {:?}]", log.address, @@ -232,7 +233,7 @@ impl ActionRunner { let state = executor.into_state(); for address in state.substate.deletes { - tracing::debug!( + debug!( target: "evm", "Deleting account at {:?}", address @@ -241,7 +242,7 @@ impl ActionRunner { } for log in &state.substate.logs { - tracing::trace!( + trace!( target: "evm", "Inserting log for {:?}, topics ({}) {:?}, data ({}): {:?}]", log.address, diff --git a/src/components/contracts/modules/evm/src/runtime/stack.rs b/src/components/contracts/modules/evm/src/runtime/stack.rs index ed8f9fd2d3..b5d22ccad2 100644 --- a/src/components/contracts/modules/evm/src/runtime/stack.rs +++ b/src/components/contracts/modules/evm/src/runtime/stack.rs @@ -15,7 +15,7 @@ use fp_traits::{ }; use fp_utils::timestamp_converter; use std::{collections::btree_set::BTreeSet, marker::PhantomData, mem}; -use tracing::info; +use tracing::{debug, error, info}; pub struct FindoraStackSubstate<'context, 'config> { pub ctx: &'context Context, @@ -284,7 +284,7 @@ impl<'context, 'vicinity, 'config, C: Config> StackState<'config> fn set_storage(&mut self, address: H160, index: H256, value: H256) { if value == H256::default() { - tracing::debug!( + debug!( target: "evm", "Removing storage for {:?} [index: {:?}]", address, @@ -296,7 +296,7 @@ impl<'context, 'vicinity, 'config, C: Config> StackState<'config> &index.into(), ); } else { - tracing::debug!( + debug!( target: "evm", "Updating storage for {:?} [index: {:?}, value: {:?}]", address, @@ -309,7 +309,7 @@ impl<'context, 'vicinity, 'config, C: Config> StackState<'config> &index.into(), &value, ) { - tracing::error!( + error!( target: "evm", "Failed updating storage for {:?} [index: {:?}, value: {:?}], error: {:?}", address, @@ -365,6 +365,11 @@ impl<'context, 'vicinity, 'config, C: Config> StackState<'config> } fn reset_storage(&mut self, address: H160) { + debug!( + target: "evm", + "Removing storage with prefix {:?}", + address, + ); AccountStorages::remove_prefix( self.ctx.state.write().borrow_mut(), &address.into(), @@ -381,7 +386,7 @@ impl<'context, 'vicinity, 'config, C: Config> StackState<'config> fn set_code(&mut self, address: H160, code: Vec) { let code_len = code.len(); - tracing::debug!( + debug!( target: "evm", "Inserting code ({} bytes) at {:?}", code_len, @@ -392,7 +397,7 @@ impl<'context, 'vicinity, 'config, C: Config> StackState<'config> let result = App::::create_account(self.ctx, address.into(), code); if let Err(e) = result { - tracing::error!( + error!( target: "evm", "Failed inserting code ({} bytes) at {:?}, error: {:?}", code_len, diff --git a/src/components/contracts/primitives/core/Cargo.toml b/src/components/contracts/primitives/core/Cargo.toml index 42d2a6f1ba..292045260c 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.0.0", optional = true } -fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0", optional = true } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4", optional = true } +fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4", optional = true } serde_with = { version = "2.0.1"} # primitives diff --git a/src/components/contracts/primitives/core/src/context.rs b/src/components/contracts/primitives/core/src/context.rs index 3edf19d8a2..d1d34c8dfd 100644 --- a/src/components/contracts/primitives/core/src/context.rs +++ b/src/components/contracts/primitives/core/src/context.rs @@ -53,6 +53,22 @@ impl Context { } } + pub fn state_at(&self, height: u64) -> Option { + let state = self.state.read().state_at(height); + let db = State::new(self.db.read().chain_state(), false); + match state { + Ok(state) => Some(Context { + state: Arc::new(RwLock::new(state)), + db: Arc::new(RwLock::new(db)), + run_mode: RunTxMode::None, + header: Default::default(), + header_hash: Default::default(), + eth_cache: Default::default(), + }), + _ => None, + } + } + pub fn copy_with_state(&self) -> Self { Context { state: Arc::new(RwLock::new(self.state.read().copy())), diff --git a/src/components/contracts/primitives/mocks/Cargo.toml b/src/components/contracts/primitives/mocks/Cargo.toml index 6feb0138ea..ac613434cc 100644 --- a/src/components/contracts/primitives/mocks/Cargo.toml +++ b/src/components/contracts/primitives/mocks/Cargo.toml @@ -18,7 +18,7 @@ rand_chacha = "0.3" rlp = "0.5" serde_json = "1.0" sha3 = "0.10" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } # primitives fp-traits = { path = "../traits" } diff --git a/src/components/contracts/primitives/mocks/src/lib.rs b/src/components/contracts/primitives/mocks/src/lib.rs index e34b7fdd1d..302bf14f21 100644 --- a/src/components/contracts/primitives/mocks/src/lib.rs +++ b/src/components/contracts/primitives/mocks/src/lib.rs @@ -23,8 +23,9 @@ use std::sync::Mutex; use std::time::SystemTime; lazy_static! { - pub static ref BASE_APP: Mutex = - Mutex::new(BaseApp::new(create_temp_db_path().as_path(), false).unwrap()); + pub static ref BASE_APP: Mutex = Mutex::new( + BaseApp::new(create_temp_db_path().as_path(), false, (0, None), false).unwrap() + ); pub static ref ALICE_ECDSA: KeyPair = generate_address(1); pub static ref BOB_ECDSA: KeyPair = generate_address(2); pub static ref ALICE_XFR: XfrKeyPair = diff --git a/src/components/contracts/primitives/storage/Cargo.toml b/src/components/contracts/primitives/storage/Cargo.toml index 7d74e505ab..bdb5e4c61d 100644 --- a/src/components/contracts/primitives/storage/Cargo.toml +++ b/src/components/contracts/primitives/storage/Cargo.toml @@ -15,10 +15,10 @@ ruc = "1.0" serde = { version = "1.0.124", features = ["derive"] } serde_json = "1.0" sha2 = "0.10" -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } # primitives fp-core = { path = "../core" } [dev-dependencies] -temp_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.0.0" } +temp_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } diff --git a/src/components/contracts/primitives/types/Cargo.toml b/src/components/contracts/primitives/types/Cargo.toml index 21242aea8c..d840c46cfb 100644 --- a/src/components/contracts/primitives/types/Cargo.toml +++ b/src/components/contracts/primitives/types/Cargo.toml @@ -21,8 +21,8 @@ serde = { version = "1.0.124", features = ["derive"] } serde_json = "1.0" serde-big-array = "0.4" sha3 = "0.10" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } # primitives fp-utils = { path = "../utils" } diff --git a/src/components/contracts/rpc/src/eth.rs b/src/components/contracts/rpc/src/eth.rs index b1e7b8331c..97766777d8 100644 --- a/src/components/contracts/rpc/src/eth.rs +++ b/src/components/contracts/rpc/src/eth.rs @@ -339,9 +339,9 @@ impl EthApi for EthApiImpl { fn call( &self, request: CallRequest, - _: Option, + block_number: Option, ) -> BoxFuture> { - debug!(target: "eth_rpc", "call, request:{:?}", request); + debug!(target: "eth_rpc", "call, height {:?}, request:{:?}", block_number, request); let account_base_app = self.account_base_app.clone(); @@ -356,18 +356,14 @@ impl EthApi for EthApiImpl { nonce, } = request; - let block = account_base_app.read().current_block(None); + let id = native_block_id(block_number); + let block = account_base_app + .read() + .current_block(id) + .ok_or_else(|| internal_err("failed to get block"))?; + // use given gas limit or query current block's limit - let gas_limit = match gas { - Some(amount) => amount, - None => { - if let Some(block) = block.clone() { - block.header.gas_limit - } else { - ::BlockGasLimit::get() - } - } - }; + let gas_limit = gas.unwrap_or(block.header.gas_limit); let data = data.map(|d| d.0).unwrap_or_default(); let mut config = ::config().clone(); @@ -375,18 +371,13 @@ impl EthApi for EthApiImpl { let mut ctx = account_base_app .read() - .create_query_context(None, false) - .map_err(|err| { - internal_err(format!("create query context error: {err:?}",)) - })?; - if let Some(block) = block { - ctx.header - .mut_time() - .set_seconds(block.header.timestamp as i64); - ctx.header.height = block.header.number.as_u64() as i64; - ctx.header.proposer_address = - Vec::from(block.header.beneficiary.as_bytes()) - } + .create_context_at(block.header.number.as_u64()) + .ok_or_else(|| internal_err("create query context error"))?; + ctx.header + .mut_time() + .set_seconds(block.header.timestamp as i64); + ctx.header.height = block.header.number.as_u64() as i64; + ctx.header.proposer_address = Vec::from(block.header.beneficiary.as_bytes()); match to { Some(to) => { @@ -825,14 +816,15 @@ impl EthApi for EthApiImpl { } let allowance = available / gas_price; if highest < allowance { - tracing::warn!( - "Gas estimation capped by limited funds original {} balance {} sent {} feecap {} fundable {}", - highest, - balance, - request.value.unwrap_or_default(), - gas_price, - allowance - ); + warn!( + target: "eth_rpc", + "Gas estimation capped by limited funds original {} balance {} sent {} feecap {} fundable {}", + highest, + balance, + request.value.unwrap_or_default(), + gas_price, + allowance + ); highest = allowance; } } diff --git a/src/components/finutils/Cargo.toml b/src/components/finutils/Cargo.toml index 1782f2f984..01e29b35b3 100644 --- a/src/components/finutils/Cargo.toml +++ b/src/components/finutils/Cargo.toml @@ -25,9 +25,9 @@ tokio = "1.10.1" wasm-bindgen = { version = "=0.2.73", features = ["serde-serialize"] } getrandom = "0.2" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } ruc = "1.0" rucv3 = { package = "ruc", version = "3.0" } diff --git a/src/components/wallet_mobile/Cargo.toml b/src/components/wallet_mobile/Cargo.toml index 53086d49a0..ae87fe3663 100644 --- a/src/components/wallet_mobile/Cargo.toml +++ b/src/components/wallet_mobile/Cargo.toml @@ -32,8 +32,8 @@ serde = { version = "1.0.124", features = ["derive"] } serde_derive = "^1.0.59" serde_json = "1.0" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } finutils = { path = "../finutils", default-features = false, features = []} fp-types = { path = "../contracts/primitives/types" } diff --git a/src/components/wasm/Cargo.toml b/src/components/wasm/Cargo.toml index fbd9de16dc..67b5f55505 100644 --- a/src/components/wasm/Cargo.toml +++ b/src/components/wasm/Cargo.toml @@ -36,9 +36,9 @@ ruc = "1.0" # OR the compiling will fail. getrandom = { version = "0.2", features = ["js"] } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } finutils = { path = "../finutils", default-features = false } globutils = { path = "../../libs/globutils" } diff --git a/src/ledger/Cargo.toml b/src/ledger/Cargo.toml index b01a0231b8..c11f12ea95 100644 --- a/src/ledger/Cargo.toml +++ b/src/ledger/Cargo.toml @@ -34,9 +34,9 @@ fp-utils = { path = "../components/contracts/primitives/utils" } itertools = "0.10" ruc = "1.0" -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } bulletproofs = { git = "https://github.com/FindoraNetwork/bulletproofs", tag = "v1.0.1-f" } fbnc = { version = "0.2.9", default-features = false} @@ -68,10 +68,10 @@ features = ["f16", "serde"] parking_lot = "0.12" # sodiumoxide = "0.2.1" fs2 = "0.4" -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v0.2.2", optional = true } -fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v0.2.2", optional = true } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4", optional = true } +fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4", optional = true } sparse_merkle_tree = { path = "../libs/sparse_merkle_tree" } -noah-accumulators = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } +noah-accumulators = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } [target.'cfg(target_arch = "wasm32")'.dependencies] parking_lot = { version = "0.11", features = ["wasm-bindgen"] } diff --git a/src/libs/credentials/Cargo.toml b/src/libs/credentials/Cargo.toml index 8b1819d3af..e470b69068 100644 --- a/src/libs/credentials/Cargo.toml +++ b/src/libs/credentials/Cargo.toml @@ -12,5 +12,5 @@ linear-map = {version = "1.2.0", features = ["serde_impl"] } serde = "1.0.124" serde_derive = "1.0" wasm-bindgen = { version = "=0.2.73", features = ["serde-serialize"] } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } diff --git a/src/libs/globutils/Cargo.toml b/src/libs/globutils/Cargo.toml index 01bc71da1c..fcc4613db6 100644 --- a/src/libs/globutils/Cargo.toml +++ b/src/libs/globutils/Cargo.toml @@ -12,9 +12,9 @@ serde_json = "1.0" time = "0.3" rand = "0.8" cryptohash = { path = "../cryptohash" } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } -noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } -noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah-crypto = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } +noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } hex = "0.4.2" bip32 = "0.3.0" diff --git a/src/libs/sparse_merkle_tree/Cargo.toml b/src/libs/sparse_merkle_tree/Cargo.toml index aa3178d529..c90f569fd7 100644 --- a/src/libs/sparse_merkle_tree/Cargo.toml +++ b/src/libs/sparse_merkle_tree/Cargo.toml @@ -23,9 +23,9 @@ serde = "1.0.124" serde_derive = "1.0" serde_json = "1.0" sha2 = "0.10" -storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v0.2.2" } -noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.0" } +storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } +noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" } [dev-dependencies] -temp_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v0.2.2" } +temp_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" } quickcheck = "0.9.0" diff --git a/tools/devnet/env.sh b/tools/devnet/env.sh index a7be04db9e..ff39e0979d 100755 --- a/tools/devnet/env.sh +++ b/tools/devnet/env.sh @@ -35,11 +35,11 @@ PRIV_KEY="o9gXFI5ft1VOkzYhvFpgUTWVoskM1CEih0zJcm3-EAQ=" # create directories and file mkdir -p $WALLET mkdir -p $DEVNET -echo "$MNEMONIC" > $WALLET/mnenomic.key +echo "$MNEMONIC" >$WALLET/mnenomic.key # setup endpoint -$BIN/fn setup -S $ENDPOINT > /dev/null -$BIN/fn setup -O $WALLET/mnenomic.key > /dev/null +$BIN/fn setup -S $ENDPOINT >/dev/null +$BIN/fn setup -O $WALLET/mnenomic.key >/dev/null # show envs if [ "$1" == "s" ]; then