Skip to content

Commit

Permalink
Updates for polkadot-v0.9.43.
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunxw committed Jul 26, 2023
1 parent eed8ce4 commit 6b22ce6
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 17 deletions.
3 changes: 2 additions & 1 deletion chain-extensions/types/xvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ impl From<CallError> for XvmExecutionResult {
SameVmCallNotAllowed => 2,
InvalidTarget => 3,
InputTooLarge => 4,
ExecutionFailed(_) => 5,
BadOrigin => 5,
ExecutionFailed(_) => 6,
};
Self::Err(error_code)
}
Expand Down
12 changes: 8 additions & 4 deletions chain-extensions/xvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@

#![cfg_attr(not(feature = "std"), no_std)]

use astar_primitives::xvm::{Context, VmId, XvmCall};
use astar_primitives::xvm::{CallError, Context, VmId, XvmCall};
use frame_support::dispatch::Encode;
use pallet_contracts::{chain_extension::{ChainExtension, Environment, Ext, InitState, RetVal}, Origin};
use pallet_contracts::{
chain_extension::{ChainExtension, Environment, Ext, InitState, RetVal},
Origin,
};
use sp_runtime::DispatchError;
use sp_std::marker::PhantomData;
use xvm_chain_extension_types::{XvmCallArgs, XvmExecutionResult};
Expand Down Expand Up @@ -80,8 +83,9 @@ where
target: "xvm-extension::xvm_call",
"root origin not supported"
);
// TODO: expand XvmErrors with BadOrigin
return Ok(RetVal::Converging(XvmExecutionResult::UnknownError as u32));
return Ok(RetVal::Converging(
XvmExecutionResult::from(CallError::BadOrigin).into(),
));
}
};

Expand Down
6 changes: 3 additions & 3 deletions pallets/xvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ pallet-contracts = { workspace = true }
astar-primitives = { workspace = true }

[dev-dependencies]
sp-io = { workspace = true }
fp-evm = { workspace = true }
pallet-timestamp = { workspace = true, features = ["std"] }
pallet-balances = { workspace = true, features = ["std"] }
pallet-insecure-randomness-collective-flip = { workspace = true, features = ["std"] }
pallet-timestamp = { workspace = true, features = ["std"] }
sp-io = { workspace = true }

[features]
default = ["std"]
Expand All @@ -47,7 +47,7 @@ std = [
"frame-system/std",
"pallet-contracts/std",
"pallet-evm/std",
"pallet-insecure-randomness-collective-flip/std",
"pallet-insecure-randomness-collective-flip/std",
"scale-info/std",
"serde",
"sp-core/std",
Expand Down
6 changes: 4 additions & 2 deletions pallets/xvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

use frame_support::{ensure, pallet_prelude::*, traits::ConstU32, BoundedVec};
use pallet_contracts::{CollectEvents, DebugInfo, Determinism};
use pallet_evm::GasWeightMapping;
use parity_scale_codec::Decode;
use sp_core::U256;
Expand Down Expand Up @@ -209,8 +210,9 @@ impl<T: Config> Pallet<T> {
context.weight_limit,
None,
input,
false,
pallet_contracts::Determinism::Deterministic,
DebugInfo::Skip,
CollectEvents::Skip,
Determinism::Enforced,
);
log::trace!(target: "xvm::wasm_call", "WASM call result: {:?}", call_result);

Expand Down
17 changes: 12 additions & 5 deletions pallets/xvm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use super::*;
use crate as pallet_xvm;

use fp_evm::{CallInfo as EvmCallInfo, ExitReason, ExitSucceed};
use fp_evm::{CallInfo as EvmCallInfo, ExitReason, ExitSucceed, UsedGas};
use frame_support::{
construct_runtime,
dispatch::{DispatchErrorWithPostInfo, PostDispatchInfo},
Expand Down Expand Up @@ -79,6 +79,10 @@ impl pallet_balances::Config for TestRuntime {
type ExistentialDeposit = ConstU128<2>;
type AccountStore = System;
type WeightInfo = ();
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ConstU32<0>;
type MaxFreezes = ConstU32<0>;
}

impl pallet_timestamp::Config for TestRuntime {
Expand All @@ -93,7 +97,7 @@ impl pallet_insecure_randomness_collective_flip::Config for TestRuntime {}
parameter_types! {
pub const DepositPerItem: Balance = 1_000;
pub const DepositPerByte: Balance = 1_000;
pub DeletionWeightLimit: Weight = Weight::from_parts(u64::MAX, u64::MAX);
pub const DefaultDepositLimit: Balance = 1_000;
pub Schedule: pallet_contracts::Schedule<TestRuntime> = Default::default();
}

Expand All @@ -106,12 +110,11 @@ impl pallet_contracts::Config for TestRuntime {
type CallFilter = Nothing;
type DepositPerItem = DepositPerItem;
type DepositPerByte = DepositPerByte;
type DefaultDepositLimit = DefaultDepositLimit;
type CallStack = [pallet_contracts::Frame<Self>; 5];
type WeightPrice = ();
type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
type ChainExtension = ();
type DeletionQueueDepth = ConstU32<128>;
type DeletionWeightLimit = DeletionWeightLimit;
type Schedule = Schedule;
type AddressGenerator = pallet_contracts::DefaultAddressGenerator;
type MaxCodeLen = ConstU32<{ 123 * 1024 }>;
Expand Down Expand Up @@ -142,8 +145,12 @@ impl CheckedEthereumTransact for MockEthereumTransact {
EvmCallInfo {
exit_reason: ExitReason::Succeed(ExitSucceed::Returned),
value: Default::default(),
used_gas: Default::default(),
used_gas: UsedGas {
standard: Default::default(),
effective: Default::default(),
},
logs: Default::default(),
weight_info: None,
},
))
}
Expand Down
4 changes: 3 additions & 1 deletion precompiles/xvm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ use super::*;

use fp_evm::IsPrecompileResult;
use frame_support::{
construct_runtime, ensure, parameter_types, traits::{ConstU32, ConstU64, Everything}, weights::Weight,
construct_runtime, ensure, parameter_types,
traits::{ConstU32, ConstU64, Everything},
weights::Weight,
};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
Expand Down
2 changes: 2 additions & 0 deletions primitives/src/xvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ pub enum CallError {
InvalidTarget,
/// Input is too large.
InputTooLarge,
/// Bad origin.
BadOrigin,
/// The call failed on EVM or WASM execution.
ExecutionFailed(Vec<u8>),
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/shibuya/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ runtime-benchmarks = [
"pallet-preimage/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
"pallet-ethereum-checked/runtime-benchmarks",
"pallet-xvm/runtime-benchmarks",
"pallet-xvm/runtime-benchmarks",
"polkadot-runtime/runtime-benchmarks",
"orml-xtokens/runtime-benchmarks",
"astar-primitives/runtime-benchmarks",
Expand Down

0 comments on commit 6b22ce6

Please sign in to comment.