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 11, 2024
1 parent 3ebbb71 commit d4e48b2
Show file tree
Hide file tree
Showing 25 changed files with 1,079 additions and 1,034 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
1 change: 0 additions & 1 deletion pallets/capacity/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ impl pallet_balances::Config for Test {
type WeightInfo = ();
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = ConstU32<1>;
type MaxHolds = ConstU32<0>;
type RuntimeHoldReason = ();
type RuntimeFreezeReason = ();
}
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
1 change: 0 additions & 1 deletion pallets/frequency-tx-payment/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ impl pallet_balances::Config for Test {
type FreezeIdentifier = RuntimeFreezeReason;
type RuntimeFreezeReason = ();
type MaxFreezes = ConstU32<1>;
type MaxHolds = ConstU32<0>;
type RuntimeHoldReason = ();
}

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
2 changes: 1 addition & 1 deletion pallets/handles/src/rpc/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sp_api::mock_impl_runtime_apis! {
}
}

type HandleResult = Result<Option<HandleResponse>, jsonrpsee::core::Error>;
type HandleResult = Result<Option<HandleResponse>, jsonrpsee::types::ErrorObjectOwned>;

#[tokio::test]
async fn get_handle_with_non_existent_msa_id_should_return_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
9 changes: 4 additions & 5 deletions pallets/messages/src/rpc/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type GetMessagesBySchemaResult = Result<
common_primitives::messages::BlockPaginationResponse<
common_primitives::messages::MessageResponse,
>,
jsonrpsee::core::Error,
jsonrpsee::types::ErrorObjectOwned,
>;

#[tokio::test]
Expand All @@ -77,7 +77,7 @@ async fn get_messages_by_schema_with_invalid_request_should_panic() {
);

assert_eq!(true, result.is_err());
assert_eq!("Custom error: InvalidPaginationRequest", result.unwrap_err().to_string());
assert_eq!("InvalidPaginationRequest", result.unwrap_err().message());
}

#[tokio::test]
Expand All @@ -90,9 +90,8 @@ async fn get_messages_by_schema_with_bad_schema_id_should_err() {
BlockPaginationRequest { from_block: 1, to_block: 5, from_index: 0, page_size: 10 },
);

assert_eq!(true, result.is_err());
// assert_eq!("RPC call failed: ErrorObject { code: ServerError(300), message: \"Api Error\", data: Some(RawValue(\"InvalidSchemaId\")) }", result.unwrap_err().to_string());
assert_eq!("Custom error: InvalidSchemaId", result.unwrap_err().to_string());
assert_eq!(true, result.clone().is_err());
assert_eq!("InvalidSchemaId", result.unwrap_err().message());
}

#[tokio::test]
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
4 changes: 2 additions & 2 deletions pallets/msa/src/rpc/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ async fn get_keys_by_msa_id_with_disabled_offchain_should_fail() {

let result = api.get_keys_by_msa_id(NOT_EXIST_MSA);

assert_eq!(true, result.is_err());
assert_eq!("Custom error: OffchainIndexingNotEnabled", result.unwrap_err().to_string());
assert_eq!(true, result.clone().is_err());
assert_eq!("OffchainIndexingNotEnabled", result.unwrap_err().message());
}

#[tokio::test]
Expand Down
1 change: 0 additions & 1 deletion pallets/passkey/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ impl pallet_balances::Config for Test {
type FreezeIdentifier = RuntimeFreezeReason;
type RuntimeFreezeReason = ();
type MaxFreezes = ConstU32<1>;
type MaxHolds = ConstU32<0>;
type RuntimeHoldReason = ();
}

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
4 changes: 2 additions & 2 deletions pallets/schemas/src/rpc/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ sp_api::mock_impl_runtime_apis! {
}
}

type SchemaResult = Result<Option<SchemaResponse>, jsonrpsee::core::Error>;
type VersionResult = Result<Option<Vec<SchemaVersionResponse>>, jsonrpsee::core::Error>;
type SchemaResult = Result<Option<SchemaResponse>, jsonrpsee::types::ErrorObjectOwned>;
type VersionResult = Result<Option<Vec<SchemaVersionResponse>>, jsonrpsee::types::ErrorObjectOwned>;

#[tokio::test]
async fn get_schema_with_non_existent_schema_id_should_return_none() {
Expand Down
1 change: 1 addition & 0 deletions pallets/schemas/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum SerdeError {

pub fn validate_json_model(json_schema: Vec<u8>) -> Result<(), SerdeError> {
let result: Value = from_slice(&json_schema).map_err(|_| SerdeError::DeserializationError)?;

match result {
Value::Null => Err(SerdeError::InvalidNullSchema),
Value::Object(_) => Ok(()),
Expand Down
2 changes: 1 addition & 1 deletion pallets/schemas/src/tests/serde_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn serde_helper_deserialzer_error() {
r#"{ 56: "number" }"#, // KeyMustBeAString
r#"{ "file address": "file path" \r\n}"#, // EofWhileParsingObject
r#"{ "unicode code point": "\ud83f" }"#, // InvalidUnicodeCodePoint
r#"{ "v": 300e715100 }"#, // NumberOutOfRange
// r#"{ "v": 300e715100 }"#, // NumberOutOfRange
] {
assert_noop!(
validate_json_model(create_schema_vec(test_str_raw)),
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)),
)))),
)),
}
}
5 changes: 3 additions & 2 deletions pallets/stateful-storage/src/rpc/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ sp_api::mock_impl_runtime_apis! {
}
}

type PaginatedStateResult = Result<Vec<PaginatedStorageResponse>, jsonrpsee::core::Error>;
type ItemizedStateResult = Result<ItemizedStoragePageResponse, jsonrpsee::core::Error>;
type PaginatedStateResult =
Result<Vec<PaginatedStorageResponse>, jsonrpsee::types::ErrorObjectOwned>;
type ItemizedStateResult = Result<ItemizedStoragePageResponse, jsonrpsee::types::ErrorObjectOwned>;

#[tokio::test]
async fn get_paginated_storage_with_non_existent_schema_id_should_return_error() {
Expand Down
1 change: 0 additions & 1 deletion pallets/time-release/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ impl pallet_balances::Config for Test {
type WeightInfo = ();
type FreezeIdentifier = RuntimeFreezeReason;
type MaxFreezes = ConstU32<1>;
type MaxHolds = ConstU32<0>;
type RuntimeHoldReason = ();
type RuntimeFreezeReason = ();
}
Expand Down
Loading

0 comments on commit d4e48b2

Please sign in to comment.