Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
49de894
pallet-xvm refactor.
shaunxw Jul 20, 2023
5ea897c
Add TODOs.
shaunxw Jul 20, 2023
57ad0c9
Update design.
shaunxw Jul 20, 2023
46263d2
Keep XVM call interface unified.
shaunxw Jul 20, 2023
5c79244
Renaming.
shaunxw Jul 20, 2023
2a81a2d
update & integration.
shaunxw Jul 25, 2023
e576f74
Update xvm precompiles mock & tests.
shaunxw Jul 25, 2023
401cf8c
Replace 'UnknownError' with concrete errors.
shaunxw Jul 26, 2023
e410631
Update CE & precompile.
shaunxw Jul 26, 2023
819c7f8
Clean up.
shaunxw Jul 26, 2023
50c04b2
Benchmarks and mock.
shaunxw Jul 26, 2023
eed8ce4
Merge branch 'master' into feat/pallet-xvm-refactor
shaunxw Jul 26, 2023
6b22ce6
Updates for polkadot-v0.9.43.
shaunxw Jul 26, 2023
61220e6
Fix benchmarks.
shaunxw Jul 26, 2023
7b92705
Add benchmarking result and weight info.
shaunxw Jul 26, 2023
8831ba9
Add license header to weight.rs.
shaunxw Jul 26, 2023
5666403
Add pallet description docstring.
shaunxw Jul 27, 2023
df8e062
Record gas cost in XVM precompile.
shaunxw Jul 27, 2023
34a3942
Less weight is available with overheads cost.
shaunxw Jul 27, 2023
e9ccd4b
Trace Ethereum transact result.
shaunxw Jul 27, 2023
cd5d2af
Handle record cost result.
shaunxw Jul 27, 2023
8d4f62e
Bump Shibuya semver and spec versoin.
shaunxw Jul 27, 2023
7482e7b
Apply review suggestions.
shaunxw Jul 27, 2023
3fa315e
Update with new benchmarking result.
shaunxw Jul 27, 2023
931117c
Improve XVM call benchmarking.
shaunxw Jul 27, 2023
ff3b41f
Make local/shibuya/shiden/astar runtimes and client have the same sem…
shaunxw Jul 27, 2023
f6a81fa
Update with new benchmarking result.
shaunxw Jul 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Replace 'UnknownError' with concrete errors.
  • Loading branch information
shaunxw committed Jul 26, 2023
commit 401cf8c9622f73441b80462e3a649d4caa2625ec
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.

2 changes: 2 additions & 0 deletions chain-extensions/types/xvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ homepage.workspace = true
repository.workspace = true

[dependencies]
astar-primitives = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
sp-runtime = { workspace = true }
Expand All @@ -21,4 +22,5 @@ std = [
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
"astar-primitives/std",
]
39 changes: 23 additions & 16 deletions chain-extensions/types/xvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,41 @@

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

use astar_primitives::xvm::CallError;
use parity_scale_codec::{Decode, Encode};
use sp_runtime::{DispatchError, ModuleError};
use sp_std::vec::Vec;

#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, Debug)]
pub enum XvmExecutionResult {
/// Success
Success = 0,
// TODO: expand this with concrete XVM errors
/// Error not (yet) covered by a dedidacted code
UnknownError = 255,
Ok,
/// Failure
Err(u32),
}

impl TryFrom<DispatchError> for XvmExecutionResult {
type Error = DispatchError;
impl From<CallError> for XvmExecutionResult {
fn from(input: CallError) -> Self {
use CallError::*;

fn try_from(input: DispatchError) -> Result<Self, Self::Error> {
let _error_text = match input {
DispatchError::Module(ModuleError { message, .. }) => message,
_ => Some("No module error Info"),
// `0` is reserved for `Ok`
let error_code = match input {
InvalidVmId => 1,
SameVmCallNotAllowed => 2,
InvalidTarget => 3,
InputTooLarge => 4,
ExecutionFailed(_) => 5,
};
Self::Err(error_code)
}
}

// TODO: expand this with concrete XVM errors (see dapps-staking types for example)
Ok(XvmExecutionResult::UnknownError)
impl From<XvmExecutionResult> for u32 {
fn from(input: XvmExecutionResult) -> Self {
match input {
XvmExecutionResult::Ok => 0,
XvmExecutionResult::Err(code) => code,
}
}
}

Expand All @@ -55,6 +65,3 @@ pub struct XvmCallArgs {
/// Encoded call params
pub input: Vec<u8>,
}

pub const FRONTIER_VM_ID: u8 = 0x0F;
pub const PARITY_WASM_VM_ID: u8 = 0x1F;
23 changes: 12 additions & 11 deletions chain-extensions/xvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ where
};

let vm_id = {
let result = vm_id.try_into();
match result {
match TryInto::<VmId>::try_into(vm_id) {
Ok(id) => id,
Err(_) => {
Err(err) => {
// TODO: Propagate error
return Ok(RetVal::Converging(XvmExecutionResult::UnknownError as u32));
let result = Into::<XvmExecutionResult>::into(err);
return Ok(RetVal::Converging(result.into()));
}
}
};
Expand All @@ -103,25 +103,26 @@ where
env.adjust_weight(charged_weight, actual_weight);

match call_result {
Ok(success) => {
Ok(info) => {
log::trace!(
target: "xvm-extension::xvm_call",
"success: {:?}", success
"info: {:?}", info
);

let buffer: sp_std::vec::Vec<_> = success.output.encode();
let buffer: sp_std::vec::Vec<_> = info.output.encode();
env.write(&buffer, false, None)?;
Ok(RetVal::Converging(XvmExecutionResult::Success as u32))
Ok(RetVal::Converging(XvmExecutionResult::Ok.into()))
}

Err(failure) => {
Err(err) => {
log::trace!(
target: "xvm-extension::xvm_call",
"failure: {:?}", failure
"err: {:?}", err
);

// TODO Propagate error
Ok(RetVal::Converging(XvmExecutionResult::UnknownError as u32))
let result = Into::<XvmExecutionResult>::into(err.error);
Ok(RetVal::Converging(result.into()))
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions pallets/xvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ std = [
"pallet-contracts/std",
"pallet-evm/std",
"scale-info/std",
"serde/std",
"serde",
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
"astar-primitives/std",
"pallet-ethereum-checked/std",
"frame-benchmarking?/std",
]

runtime-benchmarks = [
Expand Down
6 changes: 3 additions & 3 deletions precompiles/xvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ precompile-utils = { workspace = true, features = ["testing"] }

pallet-balances = { workspace = true }
pallet-contracts = { workspace = true }
pallet-timestamp = { workspace = true }
pallet-ethereum = { workspace = true }
pallet-ethereum-checked = { workspace = true }
pallet-insecure-randomness-collective-flip = { workspace = true }
pallet-timestamp = { workspace = true }
sp-runtime = { workspace = true }

[features]
Expand All @@ -60,6 +60,6 @@ std = [
"sp-runtime/std",
"pallet-xvm/std",
"astar-primitives/std",
"pallet-balances/std",
"pallet-ethereum/std",
"pallet-balances/std",
"pallet-ethereum/std",
]
12 changes: 6 additions & 6 deletions primitives/src/xvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ pub struct CallInfo {
pub enum CallError {
/// Invalid VM id.
InvalidVmId,
/// The call failed on EVM or WASM execution.
ExecutionFailed(Vec<u8>),
/// Input is too large.
InputTooLarge,
/// Target contract address is invalid.
InvalidTarget,
/// Calling the contracts in the same VM is not allowed.
SameVmCallNotAllowed,
/// Target contract address is invalid.
InvalidTarget,
/// Input is too large.
InputTooLarge,
/// The call failed on EVM or WASM execution.
ExecutionFailed(Vec<u8>),
}

/// XVM call error with used weight info.
Expand Down