Skip to content

Commit

Permalink
Bump to polkadot-v0.9.39 as a base for substrate related deps (#829)
Browse files Browse the repository at this point in the history
* Use locked/polkadot-v0.9.39 substrate and frontier deps

* Update frontier

* [substrate-apply] BlockId removal: CallApiAt::state_at #13394

* [frontier-apply] chore: remove deprecated storage getter for all pallets (#1034)

* Add missed evm related config params

* [frontier-apply] populate parent hash for indexers (#1044)

* [frontier-apply] Improve block import notification strategy (#1030)

* [frontier-apply] implement eth_call state override (#1027)

* [substrate-apply] add warp to target block for parachains (#12761)

* Fix occured move

* Fix mock env

* Fix tests for benchmarks

* [substrate-apply] try-runtime::fast-forward (#12896)

* Fix try-runtime build

* Make constants mod pub at humanode-runtime

* Update frontier

* Update features snapshot

* [substrate-apply] Improve Weight Template and API (#13355)

* remove deprecated trait Store for all pallets

* Improve docs at pallet-bioatuh

* Edit comment

Co-authored-by: MOZGIII <[email protected]>

* Move CallApiAt to the same line with ProvideRuntimeApi

* Improve traits requirements

Co-authored-by: MOZGIII <[email protected]>

* Move ExtraDataLength to constants mod

---------

Co-authored-by: MOZGIII <[email protected]>
  • Loading branch information
dmitrylavrenov and MOZGIII authored Nov 28, 2023
1 parent 13b2868 commit 33bc65a
Show file tree
Hide file tree
Showing 30 changed files with 624 additions and 525 deletions.
648 changes: 342 additions & 306 deletions Cargo.lock

Large diffs are not rendered by default.

176 changes: 88 additions & 88 deletions Cargo.toml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions crates/author-ext-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,20 @@ where
.map_err(SetKeysError::KeyExtraction)
.map_err(errtype)?;

let at = sp_api::BlockId::Hash(self.client.info().best_hash);
let at = self.client.info().best_hash;

let signed_set_keys_extrinsic = self
.client
.runtime_api()
.create_signed_set_keys_extrinsic(&at, &validator_key, session_keys.0)
.create_signed_set_keys_extrinsic(at, &validator_key, session_keys.0)
.map_err(SetKeysError::RuntimeApi)
.map_err(errtype)?
.map_err(SetKeysError::ExtrinsicCreation)
.map_err(errtype)?;

self.pool
.submit_and_watch(
&at,
&sp_api::BlockId::Hash(at),
sp_runtime::transaction_validity::TransactionSource::Local,
signed_set_keys_extrinsic,
)
Expand Down
10 changes: 5 additions & 5 deletions crates/bioauth-flow-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,12 @@ where
};

// Extract an id of the last imported block.
let at = sp_api::BlockId::Hash(self.client.info().best_hash);
let at = self.client.info().best_hash;

let status = self
.client
.runtime_api()
.bioauth_status(&at, &own_key)
.bioauth_status(at, &own_key)
.map_err(StatusError::RuntimeApi)?;

Ok(status.into())
Expand Down Expand Up @@ -354,21 +354,21 @@ where

info!(message = "We've obtained an auth ticket", auth_ticket = ?response.auth_ticket);

let at = sp_api::BlockId::Hash(self.client.info().best_hash);
let at = self.client.info().best_hash;

let ext = self
.client
.runtime_api()
.create_authenticate_extrinsic(
&at,
at,
response.auth_ticket.into(),
response.auth_ticket_signature.into(),
)
.map_err(AuthenticateError::RuntimeApi).map_err(errtype)?;

self.pool
.submit_and_watch(
&at,
&sp_api::BlockId::Hash(at),
sp_runtime::transaction_validity::TransactionSource::Local,
ext,
)
Expand Down
4 changes: 2 additions & 2 deletions crates/humanode-peer/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use sp_consensus_babe::SlotDuration;
use sp_core::{Encode, Pair};
use sp_inherents::{InherentData, InherentDataProvider};
use sp_keyring::Sr25519Keyring;
use sp_runtime::{generic, OpaqueExtrinsic, SaturatedConversion};
use sp_runtime::{OpaqueExtrinsic, SaturatedConversion};

use crate::configuration::Configuration;
use crate::service::FullClient;
Expand Down Expand Up @@ -168,6 +168,6 @@ fn fetch_nonce(client: &FullClient, account: sp_core::sr25519::Pair) -> u32 {
let best_hash = client.chain_info().best_hash;
client
.runtime_api()
.account_nonce(&generic::BlockId::Hash(best_hash), account.public().into())
.account_nonce(best_hash, account.public().into())
.expect("Fetching account nonce failed")
}
10 changes: 9 additions & 1 deletion crates/humanode-peer/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ use humanode_runtime::Runtime;
use sc_service::PartialComponents;
#[cfg(feature = "runtime-benchmarks")]
use sp_core::Get;
#[cfg(feature = "try-runtime")]
use {
humanode_runtime::constants::babe::SLOT_DURATION,
try_runtime_cli::block_building_info::substrate_info,
};

use super::{bioauth, Root, Subcommand};
#[cfg(feature = "runtime-benchmarks")]
Expand Down Expand Up @@ -248,11 +253,14 @@ pub async fn run() -> sc_cli::Result<()> {
registry,
)
.map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?;

let info_provider = substrate_info(SLOT_DURATION);

Ok((
cmd.run::<Block, ExtendedHostFunctions<
sp_io::SubstrateHostFunctions,
<service::ExecutorDispatch as NativeExecutionDispatch>::ExtendHostFunctions,
>>(),
>, _>(Some(info_provider)),
task_manager,
))
})
Expand Down
15 changes: 15 additions & 0 deletions crates/humanode-peer/src/service/frontier.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! The Frontier related stuff.
use humanode_runtime::opaque::Block;
use sc_cli::SubstrateCli;
use sc_client_api::backend::Backend;
use sc_service::BasePath;

/// Create frontier dir.
Expand All @@ -14,3 +16,16 @@ pub fn db_config_dir(config: &sc_service::Configuration) -> std::path::PathBuf {
.config_dir(config.chain_spec.id())
})
}

/// Default ethereum config.
pub struct DefaultEthConfig<C, BE>(std::marker::PhantomData<(C, BE)>);

impl<C, BE> fc_rpc::EthConfig<Block, C> for DefaultEthConfig<C, BE>
where
C: sc_client_api::StorageProvider<Block, BE> + Sync + Send + 'static,
BE: Backend<Block> + 'static,
{
type EstimateGasAdapter = ();
type RuntimeStorageOverride =
fc_rpc::frontier_backend_client::SystemAccountId20StorageOverride<Block, C, BE>;
}
28 changes: 24 additions & 4 deletions crates/humanode-peer/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use sc_client_api::{BlockBackend, BlockchainEvents};
use sc_consensus_babe::SlotProportion;
pub use sc_executor::NativeElseWasmExecutor;
use sc_finality_grandpa::SharedVoterState;
use sc_service::{Error as ServiceError, KeystoreContainer, PartialComponents, TaskManager};
use sc_service::{
Error as ServiceError, KeystoreContainer, PartialComponents, TaskManager, WarpSyncParams,
};
use sc_telemetry::{Telemetry, TelemetryWorker};
use tracing::*;

Expand Down Expand Up @@ -283,6 +285,10 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
let eth_fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new()));
let eth_fee_history_limit = ethereum_rpc_config.fee_history_limit;
let eth_overrides = fc_storage::overrides_handle(Arc::clone(&client));
let eth_pubsub_notification_sinks =
Arc::new(fc_mapping_sync::EthereumBlockNotificationSinks::<
fc_mapping_sync::EthereumBlockNotification<Block>,
>::default());

let proposer_factory = sc_basic_authorship::ProposerFactory::new(
task_manager.spawn_handle(),
Expand All @@ -306,7 +312,7 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
spawn_handle: task_manager.spawn_handle(),
import_queue,
block_announce_validator_builder: None,
warp_sync: Some(warp_sync),
warp_sync_params: Some(WarpSyncParams::WithProvider(warp_sync)),
})?;

if config.offchain_worker.enabled {
Expand Down Expand Up @@ -367,9 +373,19 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
config.prometheus_registry().cloned(),
));
let eth_fee_history_cache = Arc::clone(&eth_fee_history_cache);
let eth_pubsub_notification_sinks = Arc::clone(&eth_pubsub_notification_sinks);

Box::new(move |deny_unsafe, subscription_task_executor| {
Ok(humanode_rpc::create(humanode_rpc::Deps {
Ok(humanode_rpc::create::<
_,
_,
_,
_,
_,
_,
_,
frontier::DefaultEthConfig<_, _>,
>(humanode_rpc::Deps {
client: Arc::clone(&client),
pool: Arc::clone(&pool),
deny_unsafe,
Expand Down Expand Up @@ -408,6 +424,8 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
eth_block_data_cache: Arc::clone(&eth_block_data_cache),
eth_execute_gas_limit_multiplier: ethereum_rpc_config
.execute_gas_limit_multiplier,
eth_forced_parent_hashes: None,
eth_pubsub_notification_sinks: Arc::clone(&eth_pubsub_notification_sinks),
},
subscription_task_executor,
})?)
Expand Down Expand Up @@ -475,7 +493,7 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
let grandpa_config = sc_finality_grandpa::GrandpaParams {
config: grandpa_config,
link: grandpa_link,
network,
network: Arc::clone(&network),
voting_rule: sc_finality_grandpa::VotingRulesBuilder::default().build(),
prometheus_registry,
shared_voter_state: SharedVoterState::empty(),
Expand Down Expand Up @@ -504,6 +522,8 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
// sync_from: <Block::Header as HeaderT>::Number,
0,
SyncStrategy::Normal,
network,
eth_pubsub_notification_sinks,
)
.for_each(|()| futures::future::ready(())),
);
Expand Down
2 changes: 2 additions & 0 deletions crates/humanode-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ humanode-runtime = { path = "../humanode-runtime" }
robonode-client = { path = "../robonode-client" }

fc-db = { workspace = true }
fc-mapping-sync = { workspace = true }
fc-rpc = { workspace = true, features = ["rpc-binary-search-estimate"] }
fc-rpc-core = { workspace = true }
fc-storage = { workspace = true }
Expand All @@ -38,6 +39,7 @@ sp-block-builder = { workspace = true }
sp-blockchain = { workspace = true }
sp-consensus = { workspace = true }
sp-consensus-babe = { workspace = true }
sp-core = { workspace = true }
sp-keystore = { workspace = true }
sp-runtime = { workspace = true }
substrate-frame-rpc-system = { workspace = true }
30 changes: 25 additions & 5 deletions crates/humanode-rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! RPC subsystem instantiation logic.
use std::sync::Arc;
use std::{collections::BTreeMap, sync::Arc};

use author_ext_api::AuthorExtApi;
use author_ext_rpc::{AuthorExt, AuthorExtServer};
use bioauth_flow_rpc::{Bioauth, BioauthServer, Signer, SignerFactory};
use bioauth_keys::traits::KeyExtractor as KeyExtractorT;
use fc_rpc::{
Eth, EthApiServer, EthBlockDataCacheTask, EthFilter, EthFilterApiServer, EthPubSub,
Eth, EthApiServer, EthBlockDataCacheTask, EthConfig, EthFilter, EthFilterApiServer, EthPubSub,
EthPubSubApiServer, Net, NetApiServer, Web3, Web3ApiServer,
};
use fc_rpc_core::types::{FeeHistoryCache, FilterPool};
Expand All @@ -33,11 +33,12 @@ pub use sc_rpc_api::DenyUnsafe;
use sc_rpc_spec_v2::chain_spec::{ChainSpec, ChainSpecApiServer};
use sc_transaction_pool::{ChainApi, Pool};
use sc_transaction_pool_api::TransactionPool;
use sp_api::{Encode, ProvideRuntimeApi};
use sp_api::{CallApiAt, Encode, ProvideRuntimeApi};
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sp_consensus::SelectChain;
use sp_consensus_babe::BabeApi;
use sp_core::H256;
use sp_keystore::SyncCryptoStorePtr;

/// Extra dependencies for `AuthorExt`.
Expand Down Expand Up @@ -101,6 +102,18 @@ pub struct EvmDeps {
/// When using eth_call/eth_estimateGas, the maximum allowed gas limit will be
/// block.gas_limit * execute_gas_limit_multiplier.
pub eth_execute_gas_limit_multiplier: u64,
/// Mandated parent hashes for a given block hash.
pub eth_forced_parent_hashes: Option<BTreeMap<H256, H256>>,
/// Sinks for pubsub notifications.
///
/// Everytime a new subscription is created, a new mpsc channel is added to the sink pool.
/// The MappingSyncWorker sends through the channel on block import and the subscription
/// emits a notification to the subscriber on receiving a message through this channel.
pub eth_pubsub_notification_sinks: Arc<
fc_mapping_sync::EthereumBlockNotificationSinks<
fc_mapping_sync::EthereumBlockNotification<Block>,
>,
>,
}

/// RPC subsystem dependencies.
Expand Down Expand Up @@ -136,13 +149,14 @@ pub struct Deps<C, P, BE, VKE, VSF, A: ChainApi, SC> {
}

/// Instantiate all RPC extensions.
pub fn create<C, P, BE, VKE, VSF, A, SC>(
pub fn create<C, P, BE, VKE, VSF, A, SC, EC>(
deps: Deps<C, P, BE, VKE, VSF, A, SC>,
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
where
BE: Backend<Block> + 'static,
BE::State: StateBackend<sp_runtime::traits::HashFor<Block>>,
C: ProvideRuntimeApi<Block> + BlockBackend<Block> + StorageProvider<Block, BE> + AuxStore,
C: ProvideRuntimeApi<Block> + CallApiAt<Block>,
C: BlockBackend<Block> + StorageProvider<Block, BE> + AuxStore,
C: BlockchainEvents<Block>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
C: Send + Sync + 'static,
Expand All @@ -164,6 +178,7 @@ where
std::error::Error + 'static,
A: ChainApi<Block = Block> + 'static,
SC: SelectChain<Block> + 'static,
EC: EthConfig<Block, C>,
{
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};
Expand Down Expand Up @@ -220,6 +235,8 @@ where
eth_overrides,
eth_block_data_cache,
eth_execute_gas_limit_multiplier,
eth_forced_parent_hashes,
eth_pubsub_notification_sinks,
} = evm;

let chain_name = chain_spec.name().to_string();
Expand Down Expand Up @@ -295,7 +312,9 @@ where
eth_fee_history_cache,
eth_fee_history_limit,
eth_execute_gas_limit_multiplier,
eth_forced_parent_hashes,
)
.replace_config::<EC>()
.into_rpc(),
)?;

Expand All @@ -308,6 +327,7 @@ where
Arc::clone(&network),
Arc::clone(&subscription_task_executor),
Arc::clone(&eth_overrides),
Arc::clone(&eth_pubsub_notification_sinks),
)
.into_rpc(),
)?;
Expand Down
8 changes: 8 additions & 0 deletions crates/humanode-runtime/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,11 @@ pub mod evm_fees {
/// The value below is a nice round number that fits the requirements outlined above.
pub const FEE_PER_GAS: u128 = 10_000_000_000_000;
}

/// Ethereum related constants.
pub mod ethereum {
/// The maximum length of the extra data in the executed event.
///
/// Current value has been taken based on moonbeam runtime ethereum pallet configuration.
pub const EXTRA_DATA_LENGTH: u32 = 30;
}
Loading

0 comments on commit 33bc65a

Please sign in to comment.