diff --git a/Cargo.lock b/Cargo.lock index 7e1630e2ec..afa83a1edf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5815,7 +5815,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.9.0)", + "sp-std 14.0.0 (git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2)", ] [[package]] diff --git a/client/mapping-sync/src/kv/mod.rs b/client/mapping-sync/src/kv/mod.rs index 03cafe6a40..a5cdcf438c 100644 --- a/client/mapping-sync/src/kv/mod.rs +++ b/client/mapping-sync/src/kv/mod.rs @@ -187,11 +187,7 @@ where } let best_hash = client.info().best_hash; - if SyncStrategy::Parachain == strategy - && !frontier_backend - .mapping() - .is_synced(&best_hash)? - { + if SyncStrategy::Parachain == strategy && !frontier_backend.mapping().is_synced(&best_hash)? { // Add best block to current_syncing_tips current_syncing_tips.push(best_hash); } diff --git a/client/rpc/src/eth/execute.rs b/client/rpc/src/eth/execute.rs index ce161e8dbf..5c6f2223fa 100644 --- a/client/rpc/src/eth/execute.rs +++ b/client/rpc/src/eth/execute.rs @@ -50,6 +50,125 @@ use crate::{ /// Default JSONRPC error code return by geth pub const JSON_RPC_ERROR_DEFAULT: i32 = -32000; +/// The types contained in this module are required for backwards compatility when decoding +/// results produced by old versions of substrate. +/// The changes contained in https://github.com/paritytech/substrate/pull/10776 changed the +/// scale encoding for variant `DispatchError::Module`. +mod old_types { + use scale_codec::{Decode, Encode}; + + /// Description of what went wrong when trying to complete an operation on a token. + #[derive(Eq, PartialEq, Clone, Copy, Encode, Decode, Debug)] + pub enum TokenError { + /// Funds are unavailable. + NoFunds, + /// Account that must exist would die. + WouldDie, + /// Account cannot exist with the funds that would be given. + BelowMinimum, + /// Account cannot be created. + CannotCreate, + /// The asset in question is unknown. + UnknownAsset, + /// Funds exist but are frozen. + Frozen, + /// Operation is not supported by the asset. + Unsupported, + } + + /// Arithmetic errors. + #[derive(Eq, PartialEq, Clone, Copy, Encode, Decode, Debug)] + pub enum ArithmeticError { + /// Underflow. + Underflow, + /// Overflow. + Overflow, + /// Division by zero. + DivisionByZero, + } + + #[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, Debug)] + pub enum DispatchErrorV1 { + /// Some error occurred. + Other(#[codec(skip)] &'static str), + /// Failed to lookup some data. + CannotLookup, + /// A bad origin. + BadOrigin, + /// A custom error in a module. + Module { + /// Module index, matching the metadata module index. + index: u8, + /// Module specific error value. + error: u8, + /// Optional error message. + #[codec(skip)] + message: Option<&'static str>, + }, + /// At least one consumer is remaining so the account cannot be destroyed. + ConsumerRemaining, + /// There are no providers so the account cannot be created. + NoProviders, + /// An error to do with tokens. + Token(TokenError), + /// An arithmetic error. + Arithmetic(ArithmeticError), + } + + #[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, Debug)] + pub enum DispatchErrorV2 { + /// Some error occurred. + Other(#[codec(skip)] &'static str), + /// Failed to lookup some data. + CannotLookup, + /// A bad origin. + BadOrigin, + /// A custom error in a module. + Module { + /// Module index, matching the metadata module index. + index: u8, + /// Module specific error value. + error: u8, + /// Optional error message. + #[codec(skip)] + message: Option<&'static str>, + }, + /// At least one consumer is remaining so the account cannot be destroyed. + ConsumerRemaining, + /// There are no providers so the account cannot be created. + NoProviders, + /// There are too many consumers so the account cannot be created. + TooManyConsumers, + /// An error to do with tokens. + Token(TokenError), + /// An arithmetic error. + Arithmetic(ArithmeticError), + } + + /// Reason why a dispatch call failed. + #[derive(PartialEq, Eq, Clone, Copy, Debug)] + pub enum OldDispatchError { + V1(DispatchErrorV1), + V2(DispatchErrorV2), + } + + impl Decode for OldDispatchError { + fn decode(input: &mut I) -> Result { + let remaining = input.remaining_len()?; + let mut v = vec![0u8; remaining.unwrap_or(0)]; + let _ = input.read(&mut v); + + if let Ok(r) = DispatchErrorV1::decode(&mut v.as_slice()) { + return Ok(OldDispatchError::V1(r)); + } + + Ok(OldDispatchError::V2(DispatchErrorV2::decode( + &mut v.as_slice(), + )?)) + } + } +} + /// Allow to adapt a request for `estimate_gas`. /// Can be used to estimate gas of some contracts using a different function /// in the case the normal gas estimation doesn't work. @@ -104,7 +223,11 @@ where ( details.gas_price, // Old runtimes require max_fee_per_gas to be None for non transactional calls. - if details.max_fee_per_gas == Some(U256::zero()) { None } else { details.max_fee_per_gas }, + if details.max_fee_per_gas == Some(U256::zero()) { + None + } else { + details.max_fee_per_gas + }, details.max_priority_fee_per_gas, ) }; @@ -259,7 +382,7 @@ where .call_api_at(params) .and_then(|r| { Result::map_err( - >, DispatchError> as Decode>::decode(&mut &r[..]), + >, old_types::OldDispatchError> as Decode>::decode(&mut &r[..]), |error| sp_api::ApiError::FailedToDecodeReturnValue { function: "EthereumRuntimeRPCApi_call", error, @@ -1054,3 +1177,31 @@ fn fee_details( }), } } + +#[cfg(test)] +mod tests { + use super::old_types::*; + use scale_codec::{Decode, Encode}; + + #[test] + fn test_dispatch_error() { + let v1 = DispatchErrorV1::Module { + index: 1, + error: 1, + message: None, + }; + let v2 = DispatchErrorV2::TooManyConsumers; + + let encoded_v1 = v1.encode(); + let encoded_v2 = v2.encode(); + + assert_eq!( + OldDispatchError::decode(&mut encoded_v1.as_slice()), + Ok(OldDispatchError::V1(v1)) + ); + assert_eq!( + OldDispatchError::decode(&mut encoded_v2.as_slice()), + Ok(OldDispatchError::V2(v2)) + ); + } +}