Skip to content

Commit

Permalink
Merge pull request #362 from CESSProject/upgrade-polkadot-sdk
Browse files Browse the repository at this point in the history
Upgrade `polkadot-sdk` and `frontier` version to `v1.10.1`
  • Loading branch information
0xbillw authored Jun 12, 2024
2 parents cce1549 + 04a791a commit 7edd2eb
Show file tree
Hide file tree
Showing 95 changed files with 15,840 additions and 10,852 deletions.
7,373 changes: 4,170 additions & 3,203 deletions Cargo.lock

Large diffs are not rendered by default.

440 changes: 218 additions & 222 deletions Cargo.toml

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions crates/ces-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@ sp-application-crypto = { workspace = true }

ring = { workspace = true, features = ["alloc"] }
curve25519-dalek = { workspace = true }
schnorrkel = { workspace = true, features = ["preaudit_deprecated", "u64_backend"] }
schnorrkel = { workspace = true, features = ["preaudit_deprecated"] }
aead = { workspace = true, optional = true }
typenum = { workspace = true, optional = true }
aead-io = { workspace = true, optional = true }

[dev-dependencies]
rand = "0.8.5"
hex = "0.4"
schnorrkel = { workspace = true, features = ["preaudit_deprecated", "u64_backend", "getrandom"] }

[features]
default = [ "full_crypto" ]
std = [ "aead/std" ]
getrandom = [ "schnorrkel/getrandom" ]
full_crypto = [
"sp-core/full_crypto",
"sp-application-crypto/full_crypto",
Expand Down
3 changes: 0 additions & 3 deletions crates/ces-mq/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "sgx")]
pub extern crate serde_sgx as serde;

extern crate alloc;

mod signer;
Expand Down
5 changes: 0 additions & 5 deletions crates/ces-mq/src/signer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
use alloc::vec::Vec;

use crate::SignedMessage;

pub trait MessageSigner {
fn sign(&self, data: &[u8]) -> Vec<u8>;
}
pub trait MessageVerifier {
fn verify(&self, message: &SignedMessage) -> bool;
}

#[cfg(feature = "signers")]
pub mod signers {
Expand Down
12 changes: 5 additions & 7 deletions crates/ces-node-rpc-ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@ log = { workspace = true }
hex = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }

# primitives
sp-runtime = { workspace = true }
sp-blockchain = { workspace = true }
sp-api = { workspace = true }

sp-state-machine = { workspace = true }
# client dependencies
sc-client-api = { workspace = true }
sc-transaction-pool-api = { workspace = true }
sc-rpc = { workspace = true }

ces-mq = { workspace = true }
ces-pallet-mq = { workspace = true }
ces-pallet-mq-runtime-api = { workspace = true }
ext-types = { workspace = true }
ces-mq = { workspace = true, default-features = true }
ces-pallet-mq = { workspace = true, default-features = true }
ces-pallet-mq-runtime-api = { workspace = true, default-features = true }
ces-node-rpc-ext-types = { workspace = true, default-features = true }
94 changes: 79 additions & 15 deletions crates/ces-node-rpc-ext/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
use std::{marker::PhantomData, sync::Arc};

use ces_pallet_mq_runtime_api::MqApi;
use jsonrpsee::{
core::{async_trait, Error as JsonRpseeError, RpcResult},
core::async_trait,
proc_macros::rpc,
types::error::{CallError, ErrorObject, ErrorObjectOwned},
types::{ErrorObject, ErrorObjectOwned},
};
use parity_scale_codec::Encode;
use sc_client_api::{
blockchain::{HeaderBackend, HeaderMetadata},
Backend, BlockBackend, StorageProvider,
};
use sc_transaction_pool_api::{InPoolTransaction, TransactionPool};
use sp_api::{ApiExt, Core, ProvideRuntimeApi, StateBackend};
use sp_api::{ApiExt, Core, ProvideRuntimeApi};
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, Header},
};
use std::fmt::Display;
use sp_state_machine::backend::Backend as StateBackend;
use std::{fmt::Display, marker::PhantomData, result::Result, sync::Arc};

pub use storage_changes::{
GetStorageChangesResponse, GetStorageChangesResponseWithRoot, MakeInto, StorageChanges,
Expand All @@ -28,7 +27,72 @@ mod mq_seq;
mod storage_changes;

/// Base code for all errors.
const CUSTOM_RPC_ERROR: i32 = 20000;
const RPC_ERR_BASE: i32 = 20000;

/// Top-level error type for the RPC handler.
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("invalid sender")]
InvalidSender,

#[error("{0}")]
ApiError(#[from] sp_api::ApiError),

/// Provided block range couldn't be resolved to a list of blocks.
#[error("Cannot resolve a block range ['{from}' ... '{to}].")]
InvalidBlockRange {
/// Beginning of the block range.
from: String,
/// End of the block range.
to: String,
},

/// Aborted due resource limiting such as MAX_NUMBER_OF_BLOCKS.
#[error("Resource limited, {0}.")]
ResourceLimited(String),

/// Error occurred while processing some block.
#[error("Error occurred while processing the block {0}.")]
InvalidBlock(String),

/// The RPC is unavailable.
#[error("This RPC is unavailable. {0}")]
Unavailable(String),

/// Errors that can be formatted as a String
#[error("{0}")]
StringError(String),
}

impl Error {
fn invalid_block<Block: BlockT, E: Display>(id: BlockId<Block>, error: E) -> Self {
Self::InvalidBlock(format!("{id}: {error}"))
}
}

impl From<Error> for ErrorObjectOwned {
fn from(error: Error) -> Self {
match error {
Error::InvalidSender => {
ErrorObject::owned(RPC_ERR_BASE + 1, error.to_string(), None::<()>)
}
Error::ApiError(e) => ErrorObject::owned(RPC_ERR_BASE + 2, e.to_string(), None::<()>),
Error::InvalidBlockRange { .. } => {
ErrorObject::owned(RPC_ERR_BASE + 3, error.to_string(), None::<()>)
}
Error::ResourceLimited(e) => {
ErrorObject::owned(RPC_ERR_BASE + 4, e.to_string(), None::<()>)
}
Error::InvalidBlock(e) => {
ErrorObject::owned(RPC_ERR_BASE + 5, e.to_string(), None::<()>)
}
Error::Unavailable(e) => {
ErrorObject::owned(RPC_ERR_BASE + 6, e.to_string(), None::<()>)
}
Error::StringError(e) => ErrorObject::owned(RPC_ERR_BASE + 7, e, None::<()>),
}
}
}

#[rpc(server, namespace = "ces")]
pub trait NodeRpcExtApi<BlockHash> {
Expand All @@ -41,25 +105,25 @@ pub trait NodeRpcExtApi<BlockHash> {
&self,
from: BlockHash,
to: BlockHash,
) -> RpcResult<GetStorageChangesResponse>;
) -> Result<GetStorageChangesResponse, Error>;

/// Same as get_storage_changes but also return the state root of each block.
#[method(name = "getStorageChangesWithRoot")]
fn get_storage_changes_with_root(
&self,
from: BlockHash,
to: BlockHash,
) -> RpcResult<GetStorageChangesResponseWithRoot>;
) -> Result<GetStorageChangesResponseWithRoot, Error>;

/// Get storage changes made by given block.
/// Returns `hex_encode(scale_encode(StorageChanges))`
#[method(name = "getStorageChangesAt")]
fn get_storage_changes_at(&self, block: BlockHash) -> RpcResult<String>;
fn get_storage_changes_at(&self, block: BlockHash) -> Result<String, Error>;

/// Return the next mq sequence number for given sender which take the ready transactions in
/// count.
#[method(name = "getMqNextSequence")]
fn get_mq_seq(&self, sender_hex: String) -> RpcResult<u64>;
fn get_mq_seq(&self, sender_hex: String) -> Result<u64, Error>;
}

/// Stuffs for custom RPC
Expand Down Expand Up @@ -115,7 +179,7 @@ where
&self,
from: Block::Hash,
to: Block::Hash,
) -> RpcResult<GetStorageChangesResponse> {
) -> Result<GetStorageChangesResponse, Error> {
let changes = storage_changes::get_storage_changes(
self.client.as_ref(),
self.backend.as_ref(),
Expand All @@ -130,7 +194,7 @@ where
&self,
from: Block::Hash,
to: Block::Hash,
) -> RpcResult<GetStorageChangesResponseWithRoot> {
) -> Result<GetStorageChangesResponseWithRoot, Error> {
Ok(storage_changes::get_storage_changes(
self.client.as_ref(),
self.backend.as_ref(),
Expand All @@ -140,14 +204,14 @@ where
)?)
}

fn get_storage_changes_at(&self, block: Block::Hash) -> RpcResult<String> {
fn get_storage_changes_at(&self, block: Block::Hash) -> Result<String, Error> {
let changes = self.get_storage_changes(block, block)?;
// get_storage_changes never returns empty vec without error.
let encoded = changes[0].encode();
Ok(impl_serde::serialize::to_hex(&encoded, false))
}

fn get_mq_seq(&self, sender_hex: String) -> RpcResult<u64> {
fn get_mq_seq(&self, sender_hex: String) -> Result<u64, Error> {
let result = mq_seq::get_mq_seq(&*self.client, &self.pool, sender_hex);
Ok(result?)
}
Expand Down
25 changes: 0 additions & 25 deletions crates/ces-node-rpc-ext/src/mq_seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,6 @@ use ces_mq::MessageOrigin;
use ces_pallet_mq::tag;
use ces_pallet_mq_runtime_api::MqApi;
use parity_scale_codec::Decode;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
#[error("invalid sender")]
InvalidSender,
#[error("{0}")]
ApiError(#[from] sp_api::ApiError),
}

impl From<Error> for JsonRpseeError {
fn from(e: Error) -> Self {
JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
CUSTOM_RPC_ERROR,
e.to_string(),
Option::<()>::None,
)))
}
}

impl From<Error> for ErrorObjectOwned {
fn from(e: Error) -> Self {
ErrorObject::owned(CUSTOM_RPC_ERROR, e.to_string(), Option::<()>::None)
}
}

pub(super) fn get_mq_seq<Client, BE, Block, P>(
client: &Client,
Expand Down
56 changes: 2 additions & 54 deletions crates/ces-node-rpc-ext/src/storage_changes.rs
Original file line number Diff line number Diff line change
@@ -1,58 +1,7 @@
use super::*;
pub use ext_types::*;
pub use ces_node_rpc_ext_types::*;
use sp_runtime::StateVersion;

/// State RPC errors.
#[derive(Debug, thiserror::Error)]
pub enum Error {
/// Provided block range couldn't be resolved to a list of blocks.
#[error("Cannot resolve a block range ['{from}' ... '{to}].")]
InvalidBlockRange {
/// Beginning of the block range.
from: String,
/// End of the block range.
to: String,
},

/// Aborted due resource limiting such as MAX_NUMBER_OF_BLOCKS.
#[error("Resource limited, {0}.")]
ResourceLimited(String),

/// Error occurred while processing some block.
#[error("Error occurred while processing the block {0}.")]
InvalidBlock(String),

/// The RPC is unavailable.
#[error("This RPC is unavailable. {0}")]
Unavailable(String),
}

impl Error {
fn invalid_block<Block: BlockT, E: Display>(id: BlockId<Block>, error: E) -> Self {
Self::InvalidBlock(format!("{id}: {error}"))
}
}

impl From<Error> for JsonRpseeError {
fn from(e: Error) -> Self {
JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
CUSTOM_RPC_ERROR,
e.to_string(),
Option::<()>::None,
)))
}
}

impl From<Error> for ErrorObjectOwned {
fn from(e: Error) -> Self {
ErrorObject::owned(
CUSTOM_RPC_ERROR,
e.to_string(),
Option::<()>::None,
)
}
}

pub(super) fn get_storage_changes<Client, BE, Block>(
client: &Client,
backend: &BE,
Expand All @@ -68,8 +17,7 @@ where
+ HeaderMetadata<Block, Error = sp_blockchain::Error>
+ ProvideRuntimeApi<Block>,
Block: BlockT + 'static,
Client::Api:
sp_api::Metadata<Block> + ApiExt<Block>,
Client::Api: sp_api::Metadata<Block> + ApiExt<Block>,
<<Block as BlockT>::Header as Header>::Number: Into<u64>,
{
fn header<Client: HeaderBackend<Block>, Block: BlockT>(
Expand Down
2 changes: 0 additions & 2 deletions crates/ces-pois/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ edition = "2021"
[dependencies]
anyhow = { workspace = true }
bigdecimal = { workspace = true }
byteorder = { workspace = true }
bytes = { workspace = true }
dashmap = { workspace = true }
hex = { workspace = true, features = ["alloc"] }
lazy_static = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/ces-pois/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn copy_data(target: &mut [u8], src: &[&[u8]]) {
}
}

pub fn parse_key(path: &str) -> Result<RsaKey> {
pub fn parse_key(path: &str) -> Result<RsaKey, std::io::Error> {
let data = fs::read(path)?;
Ok(get_key_from_bytes(&data))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ces-serde-more/src/pubkey_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pub fn serialize<S: Serializer>(data: &sr25519::Public, ser: S) -> Result<S::Ok,

pub fn deserialize<'de, De: Deserializer<'de>>(der: De) -> Result<sr25519::Public, De::Error> {
let bytes = Deserialize::deserialize(der)?;
Ok(sr25519::Public(bytes))
Ok(sr25519::Public::from_raw(bytes))
}
Loading

0 comments on commit 7edd2eb

Please sign in to comment.