Skip to content

Commit

Permalink
FIx comliation error for node code
Browse files Browse the repository at this point in the history
  • Loading branch information
imstar15 committed Aug 9, 2024
1 parent d8e96ab commit 3ac7a85
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 137 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions node/src/chain_spec/turing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,13 @@ fn testnet_genesis(
code: turing_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
..Default::default()
},
balances: turing_runtime::BalancesConfig { balances: endowed_accounts },
parachain_info: turing_runtime::ParachainInfoConfig { parachain_id: para_id },
parachain_info: turing_runtime::ParachainInfoConfig {
parachain_id: para_id,
..Default::default()
},
session: turing_runtime::SessionConfig {
keys: invulnerables
.iter()
Expand Down Expand Up @@ -290,7 +294,10 @@ fn testnet_genesis(
phantom: Default::default(),
},
parachain_system: Default::default(),
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
polkadot_xcm: PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
..Default::default()
},
treasury: Default::default(),
// valve: ValveConfig { start_with_valve_closed: false, closed_gates: pallet_gates_closed },
// vesting: VestingConfig { vesting_schedule },
Expand Down
8 changes: 4 additions & 4 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ pub enum Subcommand {
subcommand_negates_reqs = true
)]
pub struct Cli {
#[clap(subcommand)]
#[command(subcommand)]
pub subcommand: Option<Subcommand>,

#[clap(flatten)]
#[command(flatten)]
pub run: cumulus_client_cli::RunCmd,

/// Disable automatic hardware benchmarks.
Expand All @@ -60,11 +60,11 @@ pub struct Cli {
///
/// The results are then printed out in the logs, and also sent as part of
/// telemetry, if telemetry is enabled.
#[clap(long)]
#[arg(long)]
pub no_hardware_benchmarks: bool,

/// Relay chain arguments
#[clap(raw = true)]
#[arg(raw = true)]
pub relay_chain_args: Vec<String>,
}

Expand Down
57 changes: 41 additions & 16 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ impl SubstrateCli for Cli {
}
}

impl Cli {
fn runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
#[cfg(not(feature = "turing-node"))]
panic!("{}", service::TURING_RUNTIME_NOT_AVAILABLE);

#[cfg(feature = "turing-node")]
return &service::turing_runtime::VERSION;
}
}

impl SubstrateCli for RelayChainCli {
fn impl_name() -> String {
"OAK Collator".into()
Expand Down Expand Up @@ -268,17 +278,24 @@ pub fn run() -> Result<()> {
})
},
Some(Subcommand::ExportGenesisState(cmd)) => {
let runner = cli.create_runner(cmd)?;
let chain_spec = &runner.config().chain_spec;
with_runtime_or_err!(chain_spec, {
{
runner.sync_run(|_config| {
let spec =
cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
let state_version = Cli::runtime_version(&spec).state_version();
cmd.run::<Block>(&*spec, &state_version)
})
}
})

// let runner = cli.create_runner(cmd)?;
// let chain_spec = &runner.config().chain_spec;
// with_runtime_or_err!(chain_spec, {
// {
// runner.sync_run(|_config| {
// let spec =
// cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
// let state_version = Cli::native_runtime_version(&spec).state_version();
// cmd.run::<Block>(&*spec, state_version)
// })
// }
// runner.sync_run(|_config| {
// let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
// let state_version = Cli::native_runtime_version(&spec).state_version();
// cmd.run::<Block>(&*spec, &state_version)
// })
// let runner = cli.create_runner(cmd)?;
// runner.sync_run(|config| {
Expand All @@ -293,11 +310,19 @@ pub fn run() -> Result<()> {
// cmd.run(&*config.chain_spec, &*partials.client)
// })

let runner = cli.create_runner(cmd)?;
runner.sync_run(|_config| {
let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
cmd.run(&*spec)
})
// let runner = cli.create_runner(cmd)?;
// runner.sync_run(|_config| {
// let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
// let state_version = Cli::runtime_version(&spec).state_version();
// cmd.run::<turing_runtime::Block>(&*spec, &state_version)
// })

// let runner = cli.create_runner(cmd)?;
// runner.sync_run(|_config| {
// let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
// let state_version = Cli::native_runtime_version(&spec).state_version();
// cmd.run::<Block>(&*spec, state_version)
// })
},
Some(Subcommand::ExportGenesisWasm(cmd)) => {
let runner = cli.create_runner(cmd)?;
Expand All @@ -315,7 +340,7 @@ pub fn run() -> Result<()> {
match cmd {
BenchmarkCmd::Pallet(cmd) => {
if cfg!(feature = "runtime-benchmarks") {
runner.sync_run(|config| cmd.run::<Block, Executor>(config))
runner.sync_run(|config| cmd.run::<Block, ()>(config))
} else {
Err("Benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`."
Expand Down
6 changes: 3 additions & 3 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ where
+ 'static,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_automation_time_rpc::AutomationTimeRuntimeApi<Block, AccountId, Hash, Balance>,
// C::Api: pallet_automation_time_rpc::AutomationTimeRuntimeApi<Block, AccountId, Hash, Balance>,
C::Api: pallet_automation_price_rpc::AutomationPriceRuntimeApi<Block, AccountId, Hash, Balance>,
C::Api: pallet_xcmp_handler_rpc::XcmpHandlerRuntimeApi<Block, Balance>,
C::Api: BlockBuilder<Block>,
P: TransactionPool + Sync + Send + 'static,
{
use pallet_automation_price_rpc::{AutomationPrice, AutomationPriceApiServer};
use pallet_automation_time_rpc::{AutomationTime, AutomationTimeApiServer};
// use pallet_automation_time_rpc::{AutomationTime, AutomationTimeApiServer};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use pallet_xcmp_handler_rpc::{XcmpHandler, XcmpHandlerApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};
Expand All @@ -60,7 +60,7 @@ where

module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
module.merge(AutomationTime::new(client.clone()).into_rpc())?;
// module.merge(AutomationTime::new(client.clone()).into_rpc())?;
module.merge(AutomationPrice::new(client.clone()).into_rpc())?;
module.merge(XcmpHandler::new(client).into_rpc())?;

Expand Down
2 changes: 1 addition & 1 deletion node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ where
+ cumulus_primitives_core::CollectCollationInfo<Block>
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>
+ pallet_automation_time_rpc::AutomationTimeRuntimeApi<Block, AccountId, Hash, Balance>
// + pallet_automation_time_rpc::AutomationTimeRuntimeApi<Block, AccountId, Hash, Balance>
+ pallet_automation_price_rpc::AutomationPriceRuntimeApi<Block, AccountId, Hash, Balance>
+ pallet_xcmp_handler_rpc::XcmpHandlerRuntimeApi<Block, Balance>,
sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<BlakeTwo256>,
Expand Down
1 change: 1 addition & 0 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ frame-support = { git = "https://github.com/paritytech/polkadot-sdk", default-fe
## Polkdadot deps
xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" }
xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.1.0" }

## ORML deps
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v1.1.0" }
Expand Down
100 changes: 7 additions & 93 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,72 +103,10 @@ use codec::{Compact, Encode};
use sp_io::hashing::blake2_256;
use xcm_executor::traits::ConvertLocation;

/// Means of converting a location into a stable and unique descriptive identifier.
pub trait DescribeLocation {
/// Create a description of the given `location` if possible. No two locations should have the
/// same descriptor.
fn describe_location(location: &MultiLocation) -> Option<Vec<u8>>;
}

#[impl_trait_for_tuples::impl_for_tuples(30)]
impl DescribeLocation for Tuple {
fn describe_location(l: &MultiLocation) -> Option<Vec<u8>> {
for_tuples!( #(
match Tuple::describe_location(l) {
Some(result) => return Some(result),
None => {},
}
)* );
None
}
}

pub struct DescribeTerminus;
impl DescribeLocation for DescribeTerminus {
fn describe_location(l: &MultiLocation) -> Option<Vec<u8>> {
match (l.parents, &l.interior) {
(0, Here) => Some(Vec::new()),
_ => None,
}
}
}

pub struct DescribePalletTerminal;
impl DescribeLocation for DescribePalletTerminal {
fn describe_location(l: &MultiLocation) -> Option<Vec<u8>> {
match (l.parents, &l.interior) {
(0, X1(PalletInstance(i))) => {
Some((b"Pallet", Compact::<u32>::from(*i as u32)).encode())
},
_ => return None,
}
}
}

pub struct DescribeAccountId32Terminal;
impl DescribeLocation for DescribeAccountId32Terminal {
fn describe_location(l: &MultiLocation) -> Option<Vec<u8>> {
match (l.parents, &l.interior) {
(0, X1(AccountId32 { id, .. })) => Some((b"AccountId32", id).encode()),
_ => None,
}
}
}

pub struct DescribeAccountKey20Terminal;
impl DescribeLocation for DescribeAccountKey20Terminal {
fn describe_location(l: &MultiLocation) -> Option<Vec<u8>> {
match (l.parents, &l.interior) {
(0, X1(AccountKey20 { key, .. })) => Some((b"AccountKey20", key).encode()),
_ => None,
}
}
}

pub type DescribeAccountIdTerminal = (DescribeAccountId32Terminal, DescribeAccountKey20Terminal);
pub type DescribeAccountIdTerminal = (xcm_builder::DescribeAccountId32Terminal, xcm_builder::DescribeAccountKey20Terminal);

pub struct DescribeBodyTerminal;
impl DescribeLocation for DescribeBodyTerminal {
impl xcm_builder::DescribeLocation for DescribeBodyTerminal {
fn describe_location(l: &MultiLocation) -> Option<Vec<u8>> {
match (l.parents, &l.interior) {
(0, X1(Plurality { id, part })) => Some((b"Body", id, part).encode()),
Expand All @@ -178,40 +116,16 @@ impl DescribeLocation for DescribeBodyTerminal {
}

pub type DescribeAllTerminal = (
DescribeTerminus,
DescribePalletTerminal,
DescribeAccountId32Terminal,
DescribeAccountKey20Terminal,
xcm_builder::DescribeTerminus,
xcm_builder::DescribePalletTerminal,
xcm_builder::DescribeAccountId32Terminal,
xcm_builder::DescribeAccountKey20Terminal,
DescribeBodyTerminal,
);

pub struct DescribeFamily<DescribeInterior>(PhantomData<DescribeInterior>);
impl<Suffix: DescribeLocation> DescribeLocation for DescribeFamily<Suffix> {
fn describe_location(l: &MultiLocation) -> Option<Vec<u8>> {
match (l.parents, l.interior.first()) {
(0, Some(Parachain(index))) => {
let tail = l.interior.split_first().0;
let interior = Suffix::describe_location(&tail.into())?;
Some((b"ChildChain", Compact::<u32>::from(*index), interior).encode())
},
(1, Some(Parachain(index))) => {
let tail = l.interior.split_first().0;
let interior = Suffix::describe_location(&tail.into())?;
Some((b"SiblingChain", Compact::<u32>::from(*index), interior).encode())
},
(1, _) => {
let tail = l.interior.into();
let interior = Suffix::describe_location(&tail)?;
Some((b"ParentChain", interior).encode())
},
_ => None,
}
}
}

pub struct HashedDescription<AccountId, Describe>(PhantomData<(AccountId, Describe)>);

impl<AccountId: From<[u8; 32]> + Clone, Describe: DescribeLocation> ConvertLocation<AccountId>
impl<AccountId: From<[u8; 32]> + Clone, Describe: xcm_builder::DescribeLocation> ConvertLocation<AccountId>
for HashedDescription<AccountId, Describe>
{
fn convert_location(location: &MultiLocation) -> Option<AccountId> {
Expand Down
45 changes: 29 additions & 16 deletions runtime/turing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ use sp_runtime::{
};

use xcm::latest::{prelude::*, MultiLocation};
use xcm_builder::Account32Hash;
use xcm_builder::{Account32Hash, DescribeFamily, HashedDescription};
use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
use xcm_executor::traits::ConvertLocation;
// use xcm_executor::traits::Convert;
// use xcm_builder::{DescribeFamily, HashedDescription, ParentIsPreset, SiblingParachainConvertsVia};

use xcm_config::RelayLocation;

Expand Down Expand Up @@ -107,7 +109,7 @@ use common_runtime::{
};
use primitives::{
AccountId, Address, Amount, AuraId, Balance, BlockNumber, EnsureProxy, Hash, Header, Index,
Signature, TransferCallCreator,
Signature, TransferCallCreator, DescribeAllTerminal,
};

// Custom pallet imports
Expand Down Expand Up @@ -1226,22 +1228,33 @@ impl_runtime_apis! {
}


// impl pallet_xcmp_handler_rpc_runtime_api::XcmpHandlerApi<Block, Balance> for Runtime {
// fn cross_chain_account(account_id: AccountId32) -> Result<AccountId32, Vec<u8>> {
// let parachain_id: u32 = ParachainInfo::parachain_id().into();
impl pallet_xcmp_handler_rpc_runtime_api::XcmpHandlerApi<Block, Balance> for Runtime {
fn cross_chain_account(account_id: AccountId32) -> Result<AccountId32, Vec<u8>> {
let parachain_id: u32 = ParachainInfo::parachain_id().into();

// let multiloc = MultiLocation::new(
// 1,
// X2(
// Parachain(parachain_id),
// Junction::AccountId32 { network: None, id: account_id.into() },
// ),
// );
let multiloc = MultiLocation::new(
1,
X2(
Parachain(parachain_id),
Junction::AccountId32 { network: None, id: account_id.into() },
),
);

// Account32Hash::<RelayNetwork, sp_runtime::AccountId32>::convert_ref(multiloc)
// .map_err(|_| "unable to convert account".into())
// }
// }

// 将 Option 转换为 Result,明确指定错误类型
let hashed_description = HashedDescription::<AccountId, DescribeFamily<DescribeAllTerminal>>::convert_location(&multiloc)
.ok_or_else(|| Vec::from("unable to convert account"))?;

Ok(hashed_description)

// xcm_builder::HashedDescriptionDescribeFamilyAllTerminal::<AccountId>::convert_location(
// &multiloc,
// ).map_err(|_| "unable to convert account".into())

// Account32Hash::<RelayNetwork, sp_runtime::AccountId32>::convert_ref(multiloc)
// .map_err(|_| "unable to convert account".into())
}
}

// impl pallet_automation_time_rpc_runtime_api::AutomationTimeApi<Block, AccountId, Hash, Balance> for Runtime {
// fn query_fee_details(
Expand Down
4 changes: 2 additions & 2 deletions runtime/turing/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use xcm_builder::{
AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds,
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeRevenue,
TakeWeightCredit, WithComputedOrigin,
TakeWeightCredit, WithComputedOrigin, DescribeFamily,
};
use xcm_executor::{Config, XcmExecutor};

Expand All @@ -38,7 +38,7 @@ use orml_xcm_support::{
};

use primitives::{
AbsoluteAndRelativeReserveProvider, DescribeAllTerminal, DescribeFamily, HashedDescription,
AbsoluteAndRelativeReserveProvider, DescribeAllTerminal, HashedDescription,
};

parameter_types! {
Expand Down

0 comments on commit 3ac7a85

Please sign in to comment.