difftreelog
build upgrade frontier
in: master
4 files changed
node/src/rpc.rsdiffbeforeafterboth--- 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<FilterPool>,
/// Backend.
pub backend: Arc<fc_db::Backend<Block>>,
+ /// Maximum number of logs in a query.
+ pub max_past_logs: u32,
+}
+
+struct AccountCodes<C, B> {
+ client: Arc<C>,
+ _marker: PhantomData<B>,
+}
+
+impl<C, Block> AccountCodes<C, Block>
+where
+ Block: sp_api::BlockT,
+ C: ProvideRuntimeApi<Block>,
+{
+ fn new(client: Arc<C>) -> Self {
+ Self {
+ client,
+ _marker: PhantomData,
+ }
+ }
}
+impl<C, Block> fc_rpc::AccountCodeProvider<Block> for AccountCodes<C, Block>
+where
+ Block: sp_api::BlockT,
+ C: ProvideRuntimeApi<Block>,
+ C::Api: pallet_nft::NftApi<Block>,
+{
+ fn code(&self, block: &sp_api::BlockId<Block>, account: sp_core::H160) -> Option<Vec<u8>> {
+ self.client.runtime_api().eth_contract_code(block, account).ok().flatten()
+ }
+}
+
/// Instantiate all full RPC extensions.
pub fn create_full<C, P, BE>(
deps: FullDeps<C, P>,
@@ -74,6 +108,7 @@
C::Api: pallet_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance, BlockNumber>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,
+ C::Api: pallet_nft::NftApi<Block>,
P: TransactionPool<Block=Block> + '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<dyn EthSigner>);
}
- 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<dyn StorageOverride<_> + Send + Sync>
+ Box::new(SchemaV1Override::new_with_code_provider(
+ client.clone(),
+ Arc::new(AccountCodes::<C, Block>::new(client.clone()))
+ )) as Box<dyn StorageOverride<_> + 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,
))
);
node/src/service.rsdiffbeforeafterboth--- 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,
pallets/nft/src/lib.rsdiffbeforeafterboth--- 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<Vec<u8>>;
+ }
+}
runtime/src/lib.rsdiffbeforeafterboth64use sp_arithmetic::{traits::{BaseArithmetic, Unsigned}};64use sp_arithmetic::{traits::{BaseArithmetic, Unsigned}};65use smallvec::smallvec;65use smallvec::smallvec;66use codec::{Encode, Decode};66use codec::{Encode, Decode};67use pallet_evm::{Account as EVMAccount, FeeCalculator};67use pallet_evm::{Account as EVMAccount, FeeCalculator, OnMethodCall};68use fp_rpc::TransactionStatus;68use fp_rpc::TransactionStatus;69use sp_core::H256;69use sp_core::H256;7070344}344}345345346impl pallet_evm::Config for Runtime {346impl pallet_evm::Config for Runtime {347 type BlockGasLimit = BlockGasLimit;347 type FeeCalculator = ();348 type FeeCalculator = ();348 type GasWeightMapping = ();349 type GasWeightMapping = ();349 type CallOrigin = EnsureAddressTruncated;350 type CallOrigin = EnsureAddressTruncated;350 type WithdrawOrigin = EnsureAddressTruncated;351 type WithdrawOrigin = EnsureAddressTruncated;351 type AddressMapping = HashedAddressMapping<BlakeTwo256>;352 type AddressMapping = HashedAddressMapping<Self::Hashing>;353 type Precompiles = ();352 type Currency = Balances;354 type Currency = Balances;353 type Event = Event;355 type Event = Event;354 type Precompiles = ();356 type OnMethodCall = pallet_nft::NftErcSupport<Self>;355 type ChainId = ChainId;357 type ChainId = ChainId;356 type Runner = pallet_evm::runner::stack::Runner<Self>;358 type Runner = pallet_evm::runner::stack::Runner<Self>;357 type OnChargeTransaction = ();359 type OnChargeTransaction = ();379 type Event = Event;381 type Event = Event;380 type FindAuthor = EthereumFindAuthor<Aura>;382 type FindAuthor = EthereumFindAuthor<Aura>;381 type StateRoot = pallet_ethereum::IntermediateStateRoot;383 type StateRoot = pallet_ethereum::IntermediateStateRoot;382 type BlockGasLimit = BlockGasLimit;383}384}384385385impl pallet_grandpa::Config for Runtime {386impl pallet_grandpa::Config for Runtime {657 frame_executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;658 frame_executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;658659659impl_runtime_apis! {660impl_runtime_apis! {661 impl pallet_nft::NftApi<Block>662 for Runtime663 {664 fn eth_contract_code(account: H160) -> Option<Vec<u8>> {665 <pallet_nft::NftErcSupport<Runtime>>::get_code(&account)666 }667 }660668661 impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber>669 impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber>662 for Runtime670 for Runtime