Skip to content

Commit

Permalink
Progress 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Jul 17, 2023
1 parent e58599f commit 8eb1c2d
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 55 deletions.
8 changes: 6 additions & 2 deletions bin/collator/src/local/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,12 @@ pub fn start_node(
.expect("Genesis block exists; qed"),
&config.chain_spec,
);
let net_config = sc_network::config::FullNetworkConfiguration::new(&config.network);

let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
net_config,
client: client.clone(),
transaction_pool: transaction_pool.clone(),
spawn_handle: task_manager.spawn_handle(),
Expand Down Expand Up @@ -258,7 +260,7 @@ pub fn start_node(
task_manager.spawn_essential_handle().spawn(
"frontier-mapping-sync-worker",
Some("frontier"),
fc_mapping_sync::MappingSyncWorker::new(
fc_mapping_sync::kv::MappingSyncWorker::new(
client.import_notification_stream(),
Duration::new(6, 0),
client.clone(),
Expand Down Expand Up @@ -491,10 +493,12 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
.expect("Genesis block exists; qed"),
&config.chain_spec,
);
let net_config = sc_network::config::FullNetworkConfiguration::new(&config.network);

let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
net_config,
client: client.clone(),
transaction_pool: transaction_pool.clone(),
spawn_handle: task_manager.spawn_handle(),
Expand Down Expand Up @@ -530,7 +534,7 @@ pub fn start_node(config: Configuration) -> Result<TaskManager, ServiceError> {
task_manager.spawn_essential_handle().spawn(
"frontier-mapping-sync-worker",
Some("frontier"),
fc_mapping_sync::MappingSyncWorker::new(
fc_mapping_sync::kv::MappingSyncWorker::new(
client.import_notification_stream(),
Duration::new(6, 0),
client.clone(),
Expand Down
14 changes: 9 additions & 5 deletions bin/collator/src/parachain/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, Ta
use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};
use sp_api::ConstructRuntimeApi;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_keystore::SyncCryptoStorePtr;
use sp_keystore::KeystorePtr;
use sp_runtime::traits::BlakeTwo256;
use sp_runtime::Percent;
use std::{collections::BTreeMap, sync::Arc, time::Duration};
Expand Down Expand Up @@ -377,7 +377,7 @@ where
>,
>,
Arc<SyncingService<Block>>,
SyncCryptoStorePtr,
KeystorePtr,
bool,
) -> Result<Box<dyn ParachainConsensus<Block>>, sc_service::Error>,
{
Expand All @@ -386,6 +386,7 @@ where
let params = new_partial::<RuntimeApi, Executor, BIQ>(&parachain_config, build_import_queue)?;
let (parachain_block_import, mut telemetry, telemetry_worker_handle, frontier_backend) =
params.other;
let net_config = sc_network::config::FullNetworkConfiguration::new(&parachain_config.network);

let client = params.client.clone();
let backend = params.backend.clone();
Expand All @@ -409,6 +410,7 @@ where
let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =
cumulus_client_service::build_network(BuildNetworkParams {
parachain_config: &parachain_config,
net_config,
para_id: id,
client: client.clone(),
transaction_pool: transaction_pool.clone(),
Expand Down Expand Up @@ -436,7 +438,7 @@ where
task_manager.spawn_essential_handle().spawn(
"frontier-mapping-sync-worker",
Some("frontier"),
fc_mapping_sync::MappingSyncWorker::new(
fc_mapping_sync::kv::MappingSyncWorker::new(
client.import_notification_stream(),
Duration::new(6, 0),
client.clone(),
Expand Down Expand Up @@ -695,7 +697,7 @@ where
>,
>,
Arc<SyncingService<Block>>,
SyncCryptoStorePtr,
KeystorePtr,
bool,
) -> Result<Box<dyn ParachainConsensus<Block>>, sc_service::Error>,
{
Expand All @@ -704,6 +706,7 @@ where
let params = new_partial::<RuntimeApi, Executor, BIQ>(&parachain_config, build_import_queue)?;
let (parachain_block_import, mut telemetry, telemetry_worker_handle, frontier_backend) =
params.other;
let net_config = sc_network::config::FullNetworkConfiguration::new(&parachain_config.network);

let client = params.client.clone();
let backend = params.backend.clone();
Expand All @@ -727,6 +730,7 @@ where
let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) =
cumulus_client_service::build_network(BuildNetworkParams {
parachain_config: &parachain_config,
net_config,
para_id: id,
client: client.clone(),
transaction_pool: transaction_pool.clone(),
Expand Down Expand Up @@ -775,7 +779,7 @@ where
task_manager.spawn_essential_handle().spawn(
"frontier-mapping-sync-worker",
Some("frontier"),
fc_mapping_sync::MappingSyncWorker::new(
fc_mapping_sync::kv::MappingSyncWorker::new(
client.import_notification_stream(),
Duration::new(6, 0),
client.clone(),
Expand Down
2 changes: 1 addition & 1 deletion bin/collator/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ where

Ok(Arc::new(fc_db::Backend::<Block>::new(
client,
&fc_db::DatabaseSettings {
&fc_db::kv::DatabaseSettings {
source: fc_db::DatabaseSource::RocksDb {
path,
cache_size: 0,
Expand Down
12 changes: 7 additions & 5 deletions chain-extensions/pallet-assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
pub mod weights;

use assets_chain_extension_types::{select_origin, Origin, Outcome};
use frame_support::traits::fungibles::InspectMetadata;
use frame_support::traits::tokens::fungibles::approvals::Inspect;
use frame_support::traits::{
fungibles::approvals::Inspect as ApprovalInspect,
fungibles::metadata::Inspect as MetadataInspect,
};
use frame_system::RawOrigin;
use pallet_assets::WeightInfo;
use pallet_contracts::chain_extension::{
Expand Down Expand Up @@ -362,7 +364,7 @@ where
let base_weight = <W as weights::WeightInfo>::metadata_name();
env.charge_weight(base_weight)?;

let name = pallet_assets::Pallet::<T>::name(&id);
let name = pallet_assets::Pallet::<T>::name(id.clone());
env.write(&name.encode(), false, None)?;
}
AssetsFunc::MetadataSymbol => {
Expand All @@ -371,7 +373,7 @@ where
let base_weight = <W as weights::WeightInfo>::metadata_symbol();
env.charge_weight(base_weight)?;

let symbol = pallet_assets::Pallet::<T>::symbol(&id);
let symbol = pallet_assets::Pallet::<T>::symbol(id.clone());
env.write(&symbol.encode(), false, None)?;
}
AssetsFunc::MetadataDecimals => {
Expand All @@ -380,7 +382,7 @@ where
let base_weight = <W as weights::WeightInfo>::metadata_decimals();
env.charge_weight(base_weight)?;

let decimals = pallet_assets::Pallet::<T>::decimals(&id);
let decimals = pallet_assets::Pallet::<T>::decimals(id.clone());
env.write(&decimals.encode(), false, None)?;
}
AssetsFunc::TransferOwnership => {
Expand Down
17 changes: 15 additions & 2 deletions chain-extensions/xvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@

use frame_support::dispatch::Encode;
use frame_support::weights::Weight;
use pallet_contracts::chain_extension::{ChainExtension, Environment, Ext, InitState, RetVal};
use pallet_contracts::{
chain_extension::{ChainExtension, Environment, Ext, InitState, RetVal},
Origin,
};
use pallet_xvm::XvmContext;
use sp_runtime::DispatchError;
use sp_std::marker::PhantomData;
Expand Down Expand Up @@ -73,7 +76,17 @@ where
let charged_weight =
env.charge_weight(remaining_weight.set_proof_size(32 * 1024))?;

let caller = env.ext().caller().clone();
let caller = match env.ext().caller().clone() {
Origin::Signed(address) => address,
Origin::Root => {
log::trace!(
target: "xvm-extension::xvm_call",
"root origin not supported"
);

return Ok(RetVal::Converging(XvmExecutionResult::UnknownError as u32));
}
};

let XvmCallArgs { vm_id, to, input } = env.read_as_unbounded(env.in_len())?;

Expand Down
2 changes: 1 addition & 1 deletion pallets/contracts-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub mod pallet {
initial: old.initial,
maximum: old.maximum,
code: old.code,
determinism: pallet_contracts::Enforced,
determinism: pallet_contracts::Determinism::Enforced,
})
});

Expand Down
4 changes: 4 additions & 0 deletions pallets/ethereum-checked/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ impl<T: Config> Pallet<T> {
is_transactional: true,
},
tx_data.into(),
// TODO: solve this prior to the merge
None,
// TODO: solve this prior to the merge
None,
)
// Gas limit validation. The fee payment has been validated as the tx is `checked`.
.validate_common()
Expand Down
7 changes: 6 additions & 1 deletion pallets/pallet-xvm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ where
Vec::new(),
is_transactional,
validate,
// TODO: set this properly before merging the PR
None,
// TODO: set this properly before merging the PR
None,
T::config(),
)
.map_err(|e| {
Expand All @@ -90,7 +94,8 @@ where
Ok(XvmCallOk {
output: info.value,
consumed_weight: T::GasWeightMapping::gas_to_weight(
info.used_gas.unique_saturated_into(),
// Temporary, will be updated once XVM is adjusted for the new code
info.used_gas.effective.unique_saturated_into(),
false,
)
.ref_time(),
Expand Down
2 changes: 2 additions & 0 deletions pallets/pallet-xvm/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ pub mod pallet {

let result = T::SyncVM::xvm_call(context, from, to, input);
let consumed_weight = consumed_weight(&result);
// TODO: solve this before merging the uplift PR - XVM should work with 2D weights!!!
let consumed_weight = Weight::from_parts(consumed_weight, 0);

log::trace!(
target: "xvm::pallet::xvm_call",
Expand Down
3 changes: 2 additions & 1 deletion pallets/pallet-xvm/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ where
gas_limit.into(),
None,
input,
false,
pallet_contracts::DebugInfo::Skip,
pallet_contracts::CollectEvents::Skip,
pallet_contracts::Determinism::Enforced,
);

Expand Down
12 changes: 6 additions & 6 deletions runtime/local/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use frame_support::{
construct_runtime, parameter_types,
traits::{
AsEnsureOriginWithArg, ConstU128, ConstU32, ConstU64, Currency, EitherOfDiverse,
EqualPrivilegeOnly, FindAuthor, Get, InstanceFilter, Nothing, WithdrawReasons,
EqualPrivilegeOnly, FindAuthor, Get, InstanceFilter, Nothing, OnFinalize, WithdrawReasons,
},
weights::{
constants::{RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND},
Expand Down Expand Up @@ -172,9 +172,6 @@ pub fn native_version() -> NativeVersion {
/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used
/// by Operational extrinsics.
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
/// We assume that ~10% of the block weight is consumed by `on_initalize` handlers.
/// This is used to limit the maximal weight of a single extrinsic.
const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);

parameter_types! {
pub const Version: RuntimeVersion = VERSION;
Expand Down Expand Up @@ -616,6 +613,7 @@ impl pallet_preimage::Config for Runtime {

parameter_types! {
pub CouncilMotionDuration: BlockNumber = 3 * MINUTES;
pub MaxProposalWeight: Weight = Perbill::from_percent(50) * RuntimeBlockWeights::get().max_block;
}

type CouncilCollective = pallet_collective::Instance1;
Expand All @@ -629,6 +627,7 @@ impl pallet_collective::Config<CouncilCollective> for Runtime {
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = EnsureRoot<Self::AccountId>;
type MaxProposalWeight = MaxProposalWeight;
}

parameter_types! {
Expand All @@ -646,6 +645,7 @@ impl pallet_collective::Config<TechnicalCommitteeCollective> for Runtime {
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = EnsureRoot<Self::AccountId>;
type MaxProposalWeight = MaxProposalWeight;
}

parameter_types! {
Expand Down Expand Up @@ -778,7 +778,7 @@ parameter_types! {
pub const DepositPerItem: Balance = deposit(1, 0);
pub const DepositPerByte: Balance = deposit(0, 1);
// Fallback value if storage deposit limit not set by the user
pub const DefaultDepositLimit: Balance = contracts_deposit(1024, 1024 * 1024);
pub const DefaultDepositLimit: Balance = deposit(1024, 1024 * 1024);
pub Schedule: pallet_contracts::Schedule<Runtime> = Default::default();
}

Expand Down Expand Up @@ -1509,7 +1509,7 @@ impl_runtime_apis! {

fn pending_block(
xts: Vec<<Block as BlockT>::Extrinsic>,
) -> (Option<pallet_ethereum::Block>, Option<Vec<TransactionStatus>>) {
) -> (Option<pallet_ethereum::Block>, Option<Vec<fp_rpc::TransactionStatus>>) {
for ext in xts.into_iter() {
let _ = Executive::apply_extrinsic(ext);
}
Expand Down
10 changes: 7 additions & 3 deletions runtime/shibuya/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ use frame_support::{
parameter_types,
traits::{
AsEnsureOriginWithArg, ConstU32, Contains, Currency, EitherOfDiverse, EqualPrivilegeOnly,
FindAuthor, Get, Imbalance, InstanceFilter, Nothing, OnUnbalanced, WithdrawReasons,
FindAuthor, Get, Imbalance, InstanceFilter, Nothing, OnFinalize, OnUnbalanced,
WithdrawReasons,
},
weights::{
constants::{
Expand Down Expand Up @@ -113,7 +114,7 @@ pub const fn deposit(items: u32, bytes: u32) -> Balance {
/// key can grow so it doesn't make sense to have as high deposit per item as in the general approach.
///
/// TODO: using this requires storage migration (good to test on Shibuya first!)
pub const fn _contracts_deposit(items: u32, bytes: u32) -> Balance {
pub const fn contracts_deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 4 * MILLISBY + (bytes as Balance) * STORAGE_BYTE_FEE
}

Expand Down Expand Up @@ -881,6 +882,7 @@ impl pallet_ethereum::Config for Runtime {

parameter_types! {
pub CouncilMotionDuration: BlockNumber = 36 * HOURS;
pub MaxProposalWeight: Weight = Perbill::from_percent(50) * RuntimeBlockWeights::get().max_block;
}

type CouncilCollective = pallet_collective::Instance1;
Expand All @@ -894,6 +896,7 @@ impl pallet_collective::Config<CouncilCollective> for Runtime {
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = EnsureRoot<Self::AccountId>;
type MaxProposalWeight = MaxProposalWeight;
}

parameter_types! {
Expand All @@ -911,6 +914,7 @@ impl pallet_collective::Config<TechnicalCommitteeCollective> for Runtime {
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = EnsureRoot<Self::AccountId>;
type MaxProposalWeight = MaxProposalWeight;
}

parameter_types! {
Expand Down Expand Up @@ -1771,7 +1775,7 @@ impl_runtime_apis! {

fn pending_block(
xts: Vec<<Block as BlockT>::Extrinsic>,
) -> (Option<pallet_ethereum::Block>, Option<Vec<TransactionStatus>>) {
) -> (Option<pallet_ethereum::Block>, Option<Vec<fp_rpc::TransactionStatus>>) {
for ext in xts.into_iter() {
let _ = Executive::apply_extrinsic(ext);
}
Expand Down
Loading

0 comments on commit 8eb1c2d

Please sign in to comment.