Skip to content

Commit

Permalink
chore(upgrade): v1.6.0 to v1.7.0
Browse files Browse the repository at this point in the history
- Upgrade Polkadot-sdk to v.1.7.0.
- Update weights to reflect the new version.

Notable Changes:
- [Allow custom error types in Jsonrpsee](paritytech/polkadot-sdk#1313)

For more details, please refer to:

[Release Notes](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.7.0)

issue-1870
  • Loading branch information
enddynayn committed Jul 10, 2024
1 parent 1b583a7 commit 547e34f
Show file tree
Hide file tree
Showing 14 changed files with 1,063 additions and 1,015 deletions.
1,770 changes: 896 additions & 874 deletions Cargo.lock

Large diffs are not rendered by default.

198 changes: 99 additions & 99 deletions Cargo.toml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions common/helpers/src/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use core::result::Result as CoreResult;
use jsonrpsee::{
core::{Error as RpcError, RpcResult},
types::error::{CallError, ErrorCode, ErrorObject},
core::RpcResult,
types::error::{ErrorCode, ErrorObject},
};
use sp_api::ApiError;

/// Converts CoreResult to Result for RPC calls
pub fn map_rpc_result<T>(response: CoreResult<T, ApiError>) -> RpcResult<T> {
match response {
Ok(res) => Ok(res),
Err(e) => Err(RpcError::Call(CallError::Custom(ErrorObject::owned(
Err(e) => Err(ErrorObject::owned(
ErrorCode::ServerError(300).code(), // No real reason for this value
"Api Error",
Some(format!("{:?}", e)),
)))),
)),
}
}

Expand Down
6 changes: 3 additions & 3 deletions node/service/src/block_sealing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub fn frequency_dev_sealing(
false => None,
};

move |deny_unsafe, _| {
Box::new(move |deny_unsafe, _| {
let deps = crate::rpc::FullDeps {
client: client.clone(),
pool: transaction_pool.clone(),
Expand All @@ -196,11 +196,11 @@ pub fn frequency_dev_sealing(
};

crate::rpc::create_full(deps, backend.clone()).map_err(Into::into)
}
})
};

sc_service::spawn_tasks(sc_service::SpawnTasksParams {
rpc_builder: Box::new(rpc_extensions_builder),
rpc_builder: rpc_extensions_builder,
client: client.clone(),
transaction_pool: transaction_pool.clone(),
task_manager: &mut task_manager,
Expand Down
8 changes: 4 additions & 4 deletions node/service/src/rpc/frequency_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use common_primitives::rpc::RpcEvent;
use jsonrpsee::{
core::{async_trait, RpcResult},
proc_macros::rpc,
types::error::{CallError, ErrorObject},
types::error::ErrorObject,
};
use parity_scale_codec::{Codec, Decode, Encode};
use sc_transaction_pool_api::{InPoolTransaction, TransactionPool};
Expand Down Expand Up @@ -73,9 +73,9 @@ where
let api = self.client.runtime_api();
let best = self.client.info().best_hash;

let nonce = api.account_nonce(best, account.clone()).map_err(|e| {
CallError::Custom(ErrorObject::owned(1, "Unable to query nonce.", Some(e.to_string())))
})?;
let nonce = api
.account_nonce(best, account.clone())
.map_err(|e| ErrorObject::owned(1, "Unable to query nonce.", Some(e.to_string())))?;
Ok(get_missing_nonces(&*self.pool, account, nonce))
}
}
Expand Down
1 change: 1 addition & 0 deletions node/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ fn start_consensus(
proposer,
collator_service,
authoring_duration: Duration::from_millis(1500),
reinitialize: true, // look into this one
};

let fut =
Expand Down
19 changes: 8 additions & 11 deletions pallets/frequency-tx-payment/src/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
use std::{convert::TryInto, sync::Arc};

use jsonrpsee::{
core::{async_trait, Error as JsonRpseeError, RpcResult},
core::{async_trait, RpcResult},
proc_macros::rpc,
types::{
error::{CallError, ErrorCode},
ErrorObject,
},
types::{error::ErrorCode, ErrorObject},
};
use pallet_frequency_tx_payment_runtime_api::{FeeDetails, InclusionFee};
use parity_scale_codec::{Codec, Decode};
Expand Down Expand Up @@ -102,27 +99,27 @@ where

let encoded_len = encoded_xt.len() as u32;
let uxt: Block::Extrinsic = Decode::decode(&mut &*encoded_xt).map_err(|e| {
CallError::Custom(ErrorObject::owned(
ErrorObject::owned(
Error::DecodeError.into(),
"Unable to query capacity fee details.",
Some(format!("{:?}", e)),
))
)
})?;
let fee_details = api.compute_capacity_fee(at_hash, uxt, encoded_len).map_err(|e| {
CallError::Custom(ErrorObject::owned(
ErrorObject::owned(
Error::RuntimeError.into(),
"Unable to query capacity fee details.",
Some(format!("{:?}", e)),
))
)
})?;

let try_into_rpc_balance = |value: Balance| {
value.try_into().map_err(|_| {
JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
ErrorObject::owned(
ErrorCode::InvalidParams.code(),
format!("{} doesn't fit in NumberOrHex representation", value),
None::<()>,
)))
)
})
};

Expand Down
11 changes: 8 additions & 3 deletions pallets/handles/src/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ use common_primitives::{
msa::MessageSourceId,
};
use jsonrpsee::{
core::{async_trait, Error as RpcError, RpcResult},
core::{async_trait, RpcResult},
proc_macros::rpc,
types::{error::ErrorObjectOwned, ErrorObject},
};
use pallet_handles_runtime_api::HandlesRuntimeApi;
use sp_api::ProvideRuntimeApi;
Expand Down Expand Up @@ -73,9 +74,13 @@ pub enum HandlesRpcError {
InvalidHandle,
}

impl From<HandlesRpcError> for RpcError {
impl From<HandlesRpcError> for ErrorObjectOwned {
fn from(e: HandlesRpcError) -> Self {
RpcError::Custom(format!("{:?}", e))
let msg = format!("{:?}", e);

match e {
HandlesRpcError::InvalidHandle => ErrorObject::owned(1, msg, None::<()>),
}
}
}

Expand Down
12 changes: 9 additions & 3 deletions pallets/messages/src/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ use common_helpers::rpc::map_rpc_result;
use common_primitives::{messages::*, schema::*};
use frame_support::{ensure, fail};
use jsonrpsee::{
core::{async_trait, Error as JsonRpseeError, RpcResult},
core::{async_trait, RpcResult},
proc_macros::rpc,
types::{ErrorObject, ErrorObjectOwned},
};
use pallet_messages_runtime_api::MessagesRuntimeApi;
use sp_api::ProvideRuntimeApi;
Expand Down Expand Up @@ -61,9 +62,14 @@ pub enum MessageRpcError {
InvalidSchemaId,
}

impl From<MessageRpcError> for JsonRpseeError {
impl From<MessageRpcError> for ErrorObjectOwned {
fn from(e: MessageRpcError) -> Self {
JsonRpseeError::Custom(format!("{:?}", e))
let msg = format!("{:?}", e);
match e {
MessageRpcError::InvalidPaginationRequest => ErrorObject::owned(1, msg, None::<()>),
MessageRpcError::TypeConversionOverflow => ErrorObject::owned(2, msg, None::<()>),
MessageRpcError::InvalidSchemaId => ErrorObject::owned(3, msg, None::<()>),
}
}
}

Expand Down
14 changes: 11 additions & 3 deletions pallets/msa/src/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ use common_primitives::{
schema::SchemaId,
};
use jsonrpsee::{
core::{async_trait, Error as JsonRpseeError, RpcResult},
core::{async_trait, RpcResult},
proc_macros::rpc,
tracing::warn,
types::{error::ErrorObjectOwned, ErrorObject},
};
use pallet_msa_runtime_api::MsaRuntimeApi;
use parity_scale_codec::{Codec, Decode};
Expand Down Expand Up @@ -101,9 +102,16 @@ pub enum MsaOffchainRpcError {
OffchainIndexingNotEnabled,
}

impl From<MsaOffchainRpcError> for JsonRpseeError {
impl From<MsaOffchainRpcError> for ErrorObjectOwned {
fn from(e: MsaOffchainRpcError) -> Self {
JsonRpseeError::Custom(format!("{:?}", e))
let msg = format!("{:?}", e);

match e {
MsaOffchainRpcError::ErrorAcquiringLock => ErrorObject::owned(1, msg, None::<()>),
MsaOffchainRpcError::ErrorDecodingData => ErrorObject::owned(2, msg, None::<()>),
MsaOffchainRpcError::OffchainIndexingNotEnabled =>
ErrorObject::owned(3, msg, None::<()>),
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions pallets/schemas/src/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
use common_helpers::{avro, rpc::map_rpc_result};
use common_primitives::schema::*;
use jsonrpsee::{
core::{async_trait, Error as RpcError, RpcResult},
core::{async_trait, RpcResult},
proc_macros::rpc,
types::error::{CallError, ErrorObject},
types::error::ErrorObject,
};
use pallet_schemas_runtime_api::SchemasRuntimeApi;
use sp_api::ProvideRuntimeApi;
Expand Down Expand Up @@ -89,11 +89,11 @@ where
let validated_schema = avro::validate_raw_avro_schema(&model);
match validated_schema {
Ok(_) => Ok(true),
Err(e) => Err(RpcError::Call(CallError::Custom(ErrorObject::owned(
Err(e) => Err(ErrorObject::owned(
SchemaRpcError::SchemaValidationError.into(),
"Unable to validate schema",
Some(format!("{:?}", e)),
)))),
)),
}
}

Expand Down
12 changes: 6 additions & 6 deletions pallets/stateful-storage/src/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use common_primitives::{
stateful_storage::{ItemizedStoragePageResponse, PaginatedStorageResponse},
};
use jsonrpsee::{
core::{async_trait, Error as RpcError, RpcResult},
core::{async_trait, RpcResult},
proc_macros::rpc,
types::error::{CallError, ErrorCode, ErrorObject},
types::error::{ErrorCode, ErrorObject},
};
use pallet_stateful_storage_runtime_api::StatefulStorageRuntimeApi;
use sp_api::{ApiError, ProvideRuntimeApi};
Expand Down Expand Up @@ -95,15 +95,15 @@ where
fn map_result<T>(api_result: Result<Result<T, DispatchError>, ApiError>) -> RpcResult<T> {
match api_result {
Ok(Ok(result)) => Ok(result),
Ok(Err(e)) => Err(RpcError::Call(CallError::Custom(ErrorObject::owned(
Ok(Err(e)) => Err(ErrorObject::owned(
ErrorCode::ServerError(300).code(), // No real reason for this value
"Runtime Error",
Some(format!("{:?}", e)),
)))),
Err(e) => Err(RpcError::Call(CallError::Custom(ErrorObject::owned(
)),
Err(e) => Err(ErrorObject::owned(
ErrorCode::ServerError(301).code(), // No real reason for this value
"Api Error",
Some(format!("{:?}", e)),
)))),
)),
}
}
10 changes: 10 additions & 0 deletions runtime/common/src/weights/pallet_balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ use core::marker::PhantomData;
/// Weights for `pallet_balances` using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_balances::WeightInfo for SubstrateWeight<T> {
fn force_adjust_total_issuance () -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `5078`
// Minimum execution time: 43_182_000 picoseconds.
Weight::from_parts(43_728_000, 5078)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))

}
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn transfer_allow_death() -> Weight {
Expand Down
1 change: 0 additions & 1 deletion runtime/frequency/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,6 @@ impl pallet_balances::Config for Runtime {
type WeightInfo = weights::pallet_balances::SubstrateWeight<Runtime>;
type MaxReserves = BalancesMaxReserves;
type ReserveIdentifier = [u8; 8];
type MaxHolds = ConstU32<1>;
type MaxFreezes = BalancesMaxFreezes;
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeFreezeReason;
Expand Down

0 comments on commit 547e34f

Please sign in to comment.