From 6e0419083caa3d87f3375981b75dafc2107b8d24 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Fri, 30 Apr 2021 15:15:41 +0000 Subject: [PATCH] build: upgrade frontier --- --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -4,10 +4,13 @@ //! capabilities that are specific to this project's runtime configuration. use std::sync::Arc; +use core::marker::PhantomData; use std::collections::BTreeMap; +use fc_rpc::RuntimeApiStorageOverride; +use fc_rpc::OverrideHandle; use fc_rpc_core::types::{PendingTransactions, FilterPool}; -use nft_runtime::{Hash, AccountId, Index, opaque::Block, BlockNumber, Balance}; +use nft_runtime::{Hash, AccountId, Index, opaque::Block, BlockNumber, Balance, NftApi}; use sp_api::ProvideRuntimeApi; use sp_blockchain::{Error as BlockChainError, HeaderMetadata, HeaderBackend}; use sc_client_api::{ @@ -56,8 +59,39 @@ pub filter_pool: Option, /// Backend. pub backend: Arc>, + /// Maximum number of logs in a query. + pub max_past_logs: u32, +} + +struct AccountCodes { + client: Arc, + _marker: PhantomData, +} + +impl AccountCodes +where + Block: sp_api::BlockT, + C: ProvideRuntimeApi, +{ + fn new(client: Arc) -> Self { + Self { + client, + _marker: PhantomData, + } + } } +impl fc_rpc::AccountCodeProvider for AccountCodes +where + Block: sp_api::BlockT, + C: ProvideRuntimeApi, + C::Api: pallet_nft::NftApi, +{ + fn code(&self, block: &sp_api::BlockId, account: sp_core::H160) -> Option> { + self.client.runtime_api().eth_contract_code(block, account).ok().flatten() + } +} + /// Instantiate all full RPC extensions. pub fn create_full( deps: FullDeps, @@ -74,6 +108,7 @@ C::Api: pallet_contracts_rpc::ContractsRuntimeApi, C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, C::Api: fp_rpc::EthereumRuntimeRPCApi, + C::Api: pallet_nft::NftApi, P: TransactionPool + 'static, { use substrate_frame_rpc_system::{FullSystem, SystemApi}; @@ -95,6 +130,7 @@ filter_pool, backend, enable_dev_signer, + max_past_logs, } = deps; io.extend_with( @@ -113,11 +149,20 @@ if enable_dev_signer { signers.push(Box::new(EthDevSigner::new()) as Box); } - let mut overrides = BTreeMap::new(); - overrides.insert( + let mut overrides_map = BTreeMap::new(); + overrides_map.insert( EthereumStorageSchema::V1, - Box::new(SchemaV1Override::new(client.clone())) as Box + Send + Sync> + Box::new(SchemaV1Override::new_with_code_provider( + client.clone(), + Arc::new(AccountCodes::::new(client.clone())) + )) as Box + Send + Sync> ); + + let overrides = Arc::new(OverrideHandle { + schemas: overrides_map, + fallback: Box::new(RuntimeApiStorageOverride::new(client.clone())), + }); + io.extend_with( EthApiServer::to_delegate(EthApi::new( client.clone(), @@ -126,9 +171,10 @@ network.clone(), pending_transactions.clone(), signers, - overrides, + overrides.clone(), backend, is_authority, + max_past_logs, )) ); @@ -138,6 +184,8 @@ client.clone(), filter_pool.clone(), 500 as usize, // max stored filters + overrides.clone(), + max_past_logs, )) ); } @@ -164,6 +212,7 @@ HexEncodedIdProvider::default(), Arc::new(subscription_task_executor) ), + overrides, )) ); --- a/node/src/service.rs +++ b/node/src/service.rs @@ -237,6 +237,8 @@ let pending = pending_transactions.clone(); let filter_pool = filter_pool.clone(); let frontier_backend = frontier_backend.clone(); + // TODO: Tune + let max_past_logs = 10000; Box::new(move |deny_unsafe, _| { let deps = crate::rpc::FullDeps { @@ -249,6 +251,7 @@ pending_transactions: pending.clone(), filter_pool: filter_pool.clone(), backend: frontier_backend.clone(), + max_past_logs, }; crate::rpc::create_full( deps, --- a/pallets/nft/src/lib.rs +++ b/pallets/nft/src/lib.rs @@ -2889,4 +2889,11 @@ } } -// #endregion \ No newline at end of file +// #endregion + +sp_api::decl_runtime_apis! { + pub trait NftApi { + /// Used for ethereum integration + fn eth_contract_code(account: H160) -> Option>; + } +} --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -64,7 +64,7 @@ use sp_arithmetic::{traits::{BaseArithmetic, Unsigned}}; use smallvec::smallvec; use codec::{Encode, Decode}; -use pallet_evm::{Account as EVMAccount, FeeCalculator}; +use pallet_evm::{Account as EVMAccount, FeeCalculator, OnMethodCall}; use fp_rpc::TransactionStatus; use sp_core::H256; @@ -344,14 +344,16 @@ } impl pallet_evm::Config for Runtime { + type BlockGasLimit = BlockGasLimit; type FeeCalculator = (); type GasWeightMapping = (); type CallOrigin = EnsureAddressTruncated; type WithdrawOrigin = EnsureAddressTruncated; - type AddressMapping = HashedAddressMapping; + type AddressMapping = HashedAddressMapping; + type Precompiles = (); type Currency = Balances; type Event = Event; - type Precompiles = (); + type OnMethodCall = pallet_nft::NftErcSupport; type ChainId = ChainId; type Runner = pallet_evm::runner::stack::Runner; type OnChargeTransaction = (); @@ -379,7 +381,6 @@ type Event = Event; type FindAuthor = EthereumFindAuthor; type StateRoot = pallet_ethereum::IntermediateStateRoot; - type BlockGasLimit = BlockGasLimit; } impl pallet_grandpa::Config for Runtime { @@ -657,6 +658,13 @@ frame_executive::Executive, Runtime, AllModules>; impl_runtime_apis! { + impl pallet_nft::NftApi + for Runtime + { + fn eth_contract_code(account: H160) -> Option> { + >::get_code(&account) + } + } impl pallet_contracts_rpc_runtime_api::ContractsApi for Runtime -- gitstuff