Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade polkadot sdk and frontier version #362

Merged
merged 36 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4f47ae7
upgrade polkadot-sdk to release v1.10.1 (WIP)
0xbillw May 21, 2024
59f9098
compile ok use polkadot-sdk runtime copy (reduced pallet)
0xbillw May 22, 2024
e9d0d97
apply frontier
0xbillw May 23, 2024
02c54dd
change babe to rrsc
0xbillw May 23, 2024
d05b48b
remove unused generic type argument: `Balancing`
0xbillw May 23, 2024
d8c297c
change to cess staking
0xbillw May 24, 2024
a8764ac
integrated `ces-mq` and `tee-worker`
0xbillw May 24, 2024
98ef59b
integrated remain modules
0xbillw May 24, 2024
201e55c
use workspace dependencies manage `cess-node-runtime`
0xbillw May 24, 2024
ed574f0
upgrade `ces-node-rpc-ext`
0xbillw May 24, 2024
849b302
move runtime opaque mod to `cess-node-primitives`
0xbillw May 24, 2024
9389ecb
fix `frontier` mod unit test compile error
0xbillw May 24, 2024
e11ecf7
remove `beefy` in `cess-node-runtime`
0xbillw May 24, 2024
2803aa8
let `cess-node` compile success
0xbillw May 24, 2024
8033174
let's `cestory` crate compile success
0xbillw May 27, 2024
3dfa2b9
fix cifrost about grandpa (WIP)
0xbillw May 28, 2024
7e4eb2d
fix authority set change about grandpa
0xbillw May 29, 2024
e67ec48
revert to former authority change sync
0xbillw May 29, 2024
a633a32
upgrade some irrelevant dependent versions
0xbillw May 29, 2024
b77af3c
fix: fix a benchmark compile error
ytqaljn Jun 3, 2024
305b812
fix: fix a benchmark compile error
ytqaljn Jun 3, 2024
d5ba2f6
fix: fix a benchmark compile error
ytqaljn Jun 3, 2024
9ca98e9
fix: use wrong features in `runtime-benchmarks` dependencies
0xbillw Jun 3, 2024
63e6354
fix: remove `runtime-benchmark` code about `pallet-session` and `pall…
0xbillw Jun 3, 2024
d7dea93
fix: temporarily remove the `pallet_cess_treasury` code for `runtime-…
0xbillw Jun 3, 2024
25e090d
fix: some indirect dependency crates of `polkadot-sdk` version leakage
0xbillw Jun 3, 2024
932a725
chore: remove unused feature: `getrandom`
0xbillw Jun 3, 2024
b0e8f89
chore: disable `subxt` default features on workspace
0xbillw Jun 3, 2024
5aef763
fix: the `runtime-benchmark` feature of `cess-node` compile error
0xbillw Jun 3, 2024
c4b2ab6
fix: cess pallet benchmark
ytqaljn Jun 3, 2024
2e9581d
style: update chain spec
ytqaljn Jun 3, 2024
4e27171
fix: fix token decimals and epoch
ytqaljn Jun 4, 2024
5cc925a
style: update devnet chan spec
ytqaljn Jun 4, 2024
861c1bb
fix: era payout
ytqaljn Jun 6, 2024
cd4a32d
style: update chain spec
ytqaljn Jun 6, 2024
04a791a
Merge branch 'main' into upgrade-polkadot-sdk
0xbillw Jun 12, 2024
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
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
Loading