From 30972207b8e9b71bed54d2a8a25e223c3714f93a Mon Sep 17 00:00:00 2001 From: ChenYe Date: Wed, 20 Jul 2022 15:28:53 +0800 Subject: [PATCH 1/6] use gee version --- Cargo.lock | 99 ++++++++++--------- rpc/Cargo.toml | 2 +- rpc/src/attestor.rs | 114 +++++++--------------- rpc/src/geode.rs | 167 ++++++++++++-------------------- rpc/src/lib.rs | 20 ++++ runtime/automata/Cargo.toml | 6 -- runtime/contextfree/Cargo.toml | 6 -- runtime/finitestate/Cargo.toml | 7 +- runtime/finitestate/src/apis.rs | 13 +++ runtime/finitestate/src/lib.rs | 88 +++++++++++++++++ 10 files changed, 276 insertions(+), 246 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d15947..bb0ca48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -440,6 +440,20 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "automata-primitives" +version = "0.1.0" +source = "git+https://github.com/automata-network/automata-common?branch=gee#6965f91efec33c6018cde97781a24df53d03a87f" +dependencies = [ + "frame-system", + "impl-trait-for-tuples 0.2.1", + "parity-scale-codec", + "sp-application-crypto", + "sp-core", + "sp-runtime", + "uint", +] + [[package]] name = "automata-primitives" version = "0.1.0" @@ -548,7 +562,6 @@ dependencies = [ "frame-system-benchmarking", "frame-system-rpc-runtime-api", "hex-literal", - "pallet-attestor", "pallet-authority-discovery", "pallet-authorship", "pallet-babe", @@ -562,11 +575,9 @@ dependencies = [ "pallet-ethereum", "pallet-evm", "pallet-evm-precompile-simple", - "pallet-geode", "pallet-grandpa", "pallet-im-online", "pallet-indices", - "pallet-liveness", "pallet-membership", "pallet-offences", "pallet-randomness-collective-flip", @@ -620,7 +631,7 @@ dependencies = [ [[package]] name = "automata-traits" version = "0.1.0" -source = "git+https://github.com/automata-network/automata-common#32c60ead64859cdbfab8f2c5965bc6288816b159" +source = "git+https://github.com/automata-network/automata-common?branch=gee#6965f91efec33c6018cde97781a24df53d03a87f" dependencies = [ "frame-support", "parity-scale-codec", @@ -1072,7 +1083,6 @@ dependencies = [ "frame-system-benchmarking", "frame-system-rpc-runtime-api", "hex-literal", - "pallet-attestor", "pallet-authority-discovery", "pallet-authorship", "pallet-babe", @@ -1088,12 +1098,10 @@ dependencies = [ "pallet-evm", "pallet-evm-precompile-simple", "pallet-game", - "pallet-geode", "pallet-gmetadata", "pallet-grandpa", "pallet-im-online", "pallet-indices", - "pallet-liveness", "pallet-membership", "pallet-offences", "pallet-randomness-collective-flip", @@ -2064,13 +2072,14 @@ dependencies = [ "pallet-evm-precompile-simple", "pallet-game", "pallet-geode", + "pallet-geodesession", "pallet-gmetadata", "pallet-grandpa", "pallet-im-online", "pallet-indices", - "pallet-liveness", "pallet-membership", "pallet-offences", + "pallet-order", "pallet-randomness-collective-flip", "pallet-scheduler", "pallet-session", @@ -4667,15 +4676,17 @@ dependencies = [ [[package]] name = "pallet-attestor" version = "0.1.0" -source = "git+https://github.com/automata-network/automata-common#32c60ead64859cdbfab8f2c5965bc6288816b159" +source = "git+https://github.com/automata-network/automata-common?branch=gee#6965f91efec33c6018cde97781a24df53d03a87f" dependencies = [ - "automata-primitives 0.1.0 (git+https://github.com/automata-network/automata-common)", + "automata-primitives 0.1.0 (git+https://github.com/automata-network/automata-common?branch=gee)", "automata-traits", "frame-benchmarking", "frame-support", "frame-system", "hex-literal", + "log", "parity-scale-codec", + "serde", "sp-core", "sp-runtime", "sp-std", @@ -5010,16 +5021,33 @@ dependencies = [ [[package]] name = "pallet-geode" version = "0.1.0" -source = "git+https://github.com/automata-network/automata-common#32c60ead64859cdbfab8f2c5965bc6288816b159" +source = "git+https://github.com/automata-network/automata-common?branch=gee#6965f91efec33c6018cde97781a24df53d03a87f" dependencies = [ - "automata-primitives 0.1.0 (git+https://github.com/automata-network/automata-common)", + "automata-primitives 0.1.0 (git+https://github.com/automata-network/automata-common?branch=gee)", "automata-traits", "frame-support", "frame-system", + "log", "pallet-attestor", "parity-scale-codec", "serde", "serde_json", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-geodesession" +version = "0.1.0" +source = "git+https://github.com/automata-network/automata-common?branch=gee#6965f91efec33c6018cde97781a24df53d03a87f" +dependencies = [ + "automata-primitives 0.1.0 (git+https://github.com/automata-network/automata-common?branch=gee)", + "automata-traits", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", "sp-runtime", "sp-std", ] @@ -5098,23 +5126,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-liveness" -version = "0.1.0" -source = "git+https://github.com/automata-network/automata-common#32c60ead64859cdbfab8f2c5965bc6288816b159" -dependencies = [ - "automata-primitives 0.1.0 (git+https://github.com/automata-network/automata-common)", - "automata-traits", - "frame-support", - "frame-system", - "pallet-attestor", - "pallet-geode", - "pallet-service", - "parity-scale-codec", - "sp-runtime", - "sp-std", -] - [[package]] name = "pallet-membership" version = "4.0.0-dev" @@ -5147,45 +5158,45 @@ dependencies = [ ] [[package]] -name = "pallet-randomness-collective-flip" -version = "4.0.0-dev" -source = "git+https://github.com/automata-network/substrate.git?branch=polkadot-v0.9.10#d49cdc05f6b784049b9ee48d0b787cfbda7e80b8" +name = "pallet-order" +version = "0.1.0" +source = "git+https://github.com/automata-network/automata-common?branch=gee#6965f91efec33c6018cde97781a24df53d03a87f" dependencies = [ + "automata-primitives 0.1.0 (git+https://github.com/automata-network/automata-common?branch=gee)", + "automata-traits", "frame-support", "frame-system", + "log", "parity-scale-codec", - "safe-mix", + "sp-core", "sp-runtime", "sp-std", ] [[package]] -name = "pallet-scheduler" +name = "pallet-randomness-collective-flip" version = "4.0.0-dev" source = "git+https://github.com/automata-network/substrate.git?branch=polkadot-v0.9.10#d49cdc05f6b784049b9ee48d0b787cfbda7e80b8" dependencies = [ - "frame-benchmarking", "frame-support", "frame-system", - "log", "parity-scale-codec", - "sp-io", + "safe-mix", "sp-runtime", "sp-std", ] [[package]] -name = "pallet-service" -version = "0.1.0" -source = "git+https://github.com/automata-network/automata-common#32c60ead64859cdbfab8f2c5965bc6288816b159" +name = "pallet-scheduler" +version = "4.0.0-dev" +source = "git+https://github.com/automata-network/substrate.git?branch=polkadot-v0.9.10#d49cdc05f6b784049b9ee48d0b787cfbda7e80b8" dependencies = [ - "automata-primitives 0.1.0 (git+https://github.com/automata-network/automata-common)", + "frame-benchmarking", "frame-support", "frame-system", - "pallet-geode", + "log", "parity-scale-codec", - "sha2 0.9.9", - "sp-core", + "sp-io", "sp-runtime", "sp-std", ] diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 7bada85..81a9d40 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -46,7 +46,7 @@ automata-primitives = { path = "../primitives" } automata-runtime = { path = '../runtime/automata', optional = true } contextfree-runtime = { path = '../runtime/contextfree', optional = true } finitestate-runtime = { path = '../runtime/finitestate', optional = true } -pallet-geode = { git = 'https://github.com/automata-network/automata-common', version = '0.1.0' } +pallet-geode = { git = 'https://github.com/automata-network/automata-common', branch = 'gee' } pallet-transfer = { git = 'https://github.com/automata-network/automata-common', version = '0.1.0' } pallet-daoportal = { git = 'https://github.com/automata-network/automata-common', branch = 'main' } pallet-daoportal-cf = { git = 'https://github.com/automata-network/automata-common', rev = '2b56383496e416e176569a25bfeb6d9ef2c6dced', package = 'pallet-daoportal' } diff --git a/rpc/src/attestor.rs b/rpc/src/attestor.rs index fa25156..02f83b3 100644 --- a/rpc/src/attestor.rs +++ b/rpc/src/attestor.rs @@ -1,42 +1,33 @@ -use automata_primitives::{Block, BlockId}; -use automata_runtime::apis::AttestorApi as AttestorRuntimeApi; use jsonrpc_core::{Error, ErrorCode, Result}; use jsonrpc_derive::rpc; -use sc_light::blockchain::BlockchainHeaderBackend as HeaderBackend; +use automata_primitives::{Block, BlockId, AccountId}; use sp_api::ProvideRuntimeApi; -use sp_core::crypto::Pair; -use sp_core::sr25519::Pair as Sr25519Pair; -use sp_core::sr25519::{Public, Signature}; +use sp_blockchain::HeaderBackend; use sp_runtime::traits::Block as BlockT; use std::sync::Arc; +#[cfg(feature = "finitestate")] +use finitestate_runtime::apis::AttestorApi as AttestorRuntimeApi; + const RUNTIME_ERROR: i64 = 1; #[rpc] /// Attestor RPC methods pub trait AttestorServer { - /// return the attestor list + /// return the registered geode list #[rpc(name = "attestor_list")] fn attestor_list(&self) -> Result, Vec, u32)>>; - /// return the attestor attesting a geode - #[rpc(name = "geode_attestors")] - fn geode_attestors(&self, geode: [u8; 32]) -> Result, Vec)>>; - /// attestor notify chain for liveness update - #[rpc(name = "attestor_notify_chain")] - fn attestor_notify_chain( - &self, - attestor_notify: Vec, - signature_raw_bytes: Vec, - ) -> Result; + #[rpc(name = "attestor_attested_appids")] + fn attestor_attested_appids(&self, attestor: [u8; 32]) -> Result>; + #[rpc(name = "attestor_heartbeat")] + fn attestor_heartbeat(&self, message: Vec, signature_raw_bytes: Vec) -> Result; } -/// An implementation of attestor specific RPC methods. pub struct AttestorApi { client: Arc, } impl AttestorApi { - /// Create new `Attestor` with the given reference to the client. pub fn new(client: Arc) -> Self { AttestorApi { client } } @@ -48,12 +39,11 @@ where C: ProvideRuntimeApi + HeaderBackend, C::Api: AttestorRuntimeApi, { - /// get attestor list fn attestor_list(&self) -> Result, Vec, u32)>> { + use sp_api::BlockId; let api = self.client.runtime_api(); let best = self.client.info().best_hash; let at = BlockId::hash(best); - let attestor_list = api.attestor_list(&at).map_err(|e| Error { code: ErrorCode::ServerError(RUNTIME_ERROR), message: "Runtime unable to get attestor list.".into(), @@ -62,73 +52,39 @@ where Ok(attestor_list) } - /// return the attestor attesting a geode - fn geode_attestors(&self, geode: [u8; 32]) -> Result, Vec)>> { + fn attestor_attested_appids(&self, attestor: [u8; 32]) -> Result> { + use sp_api::BlockId; let api = self.client.runtime_api(); let best = self.client.info().best_hash; let at = BlockId::hash(best); - - let attestors = api.geode_attestors(&at, geode.into()).map_err(|e| Error { - code: ErrorCode::ServerError(RUNTIME_ERROR), - message: "Runtime unable to get geode attestors.".into(), - data: Some(format!("{:?}", e).into()), - })?; - Ok(attestors) + let attestor_attested_geodes_list = api + .attestor_attested_appids(&at, attestor.into()) + .map_err(|e| Error { + code: ErrorCode::ServerError(RUNTIME_ERROR), + message: "Runtime unable to get attestor attested app list.".into(), + data: Some(format!("{:?}", e).into()), + })?; + let attestor_attested_geodes_list: Vec<[u8; 32]> = attestor_attested_geodes_list + .into_iter() + .map(|e| e.into()) + .collect(); + Ok(attestor_attested_geodes_list) } - /// attestor notify chain for liveness update - fn attestor_notify_chain( - &self, - attestor_notify: Vec, - signature_raw_bytes: Vec, - ) -> Result { + fn attestor_heartbeat(&self, message: Vec, signature_raw_bytes: Vec) -> Result { + use sp_api::BlockId; let api = self.client.runtime_api(); let best = self.client.info().best_hash; let at = BlockId::hash(best); - - if attestor_notify.len() != 40 { - return Err(Error { - code: ErrorCode::ServerError(RUNTIME_ERROR), - message: "message size incorrect.".into(), - data: None, - }); - } - - let mut attestor = [0u8; 32]; - attestor.copy_from_slice(&attestor_notify[0..32]); - - let signature_raw_bytes_64; - if signature_raw_bytes.len() == 64 { - let ptr = signature_raw_bytes.as_ptr() as *const [u8; 64]; - unsafe { signature_raw_bytes_64 = *ptr } - } else { - return Err(Error { - code: ErrorCode::ServerError(RUNTIME_ERROR), - message: "signature size incorrect.".into(), - data: None, - }); - } - - // validate inputs - let pubkey = Public::from_raw(attestor); - let signature = Signature::from_raw(signature_raw_bytes_64.clone()); - if !Sr25519Pair::verify(&signature, &attestor_notify, &pubkey) { - return Err(Error { - code: ErrorCode::ServerError(RUNTIME_ERROR), - message: "signature invalid.".into(), - data: None, - }); - } - - //submit a unsigned extrinsics into transaction pool - let _ = api - .unsigned_attestor_notify_chain(&at, attestor_notify, signature_raw_bytes_64) + let mut signature = [0_u8; 64]; + signature.copy_from_slice(&signature_raw_bytes); + let result = api + .unsigned_attestor_heartbeat(&at, message, signature) .map_err(|e| Error { code: ErrorCode::ServerError(RUNTIME_ERROR), - message: "Failed to submit unsigned extrinsics.".into(), + message: "Runtime unable to send heartbeat.".into(), data: Some(format!("{:?}", e).into()), - }); - - Ok(true) + })?; + Ok(result) } -} +} \ No newline at end of file diff --git a/rpc/src/geode.rs b/rpc/src/geode.rs index ccd8a79..04491ab 100644 --- a/rpc/src/geode.rs +++ b/rpc/src/geode.rs @@ -1,80 +1,34 @@ -use automata_primitives::{AccountId, Block, BlockId, BlockNumber, Hash}; -use automata_runtime::apis::GeodeApi as GeodeRuntimeApi; use jsonrpc_core::{Error, ErrorCode, Result}; use jsonrpc_derive::rpc; -use pallet_geode::{Geode, GeodeState}; -use sc_light::blockchain::BlockchainHeaderBackend as HeaderBackend; +use automata_primitives::{Block}; +use sp_api::BlockId; use sp_api::ProvideRuntimeApi; -use sp_runtime::{traits::Block as BlockT, RuntimeDebug}; -use sp_std::{collections::btree_map::BTreeMap, prelude::*}; +use sp_blockchain::HeaderBackend; +use sp_runtime::traits::Block as BlockT; +#[cfg(feature = "finitestate")] +use finitestate_runtime::apis::GeodeApi as GeodeRuntimeApi; use std::sync::Arc; -// #[cfg(feature = "std")] -use serde::{Deserialize, Serialize}; - const RUNTIME_ERROR: i64 = 1; #[rpc] -/// Geode RPC methods pub trait GeodeServer { - /// return the registered geode list - #[rpc(name = "registered_geodes")] - fn registered_geodes(&self) -> Result>>; - /// return the attested geode list - #[rpc(name = "attested_geodes")] - fn attested_geodes(&self) -> Result>>; - /// Return list geode an attestor is attesting - #[rpc(name = "attestor_attested_geodes")] - fn attestor_attested_geodes(&self, attestor: [u8; 32]) -> Result>>; - /// Return the current state of a geode - #[rpc(name = "geode_state")] - fn geode_state(&self, geode: [u8; 32]) -> Result>; -} - -/// The geode struct shows its status -// #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -#[derive(PartialEq, Eq, Clone, RuntimeDebug, Default, Serialize, Deserialize)] -pub struct WrappedGeode { - /// Geode id. - pub id: [u8; 32], - /// Provider id - pub provider: [u8; 32], - /// Assigned order hash - pub order: Option, - /// Geode's public ip. - pub ip: Vec, - /// Geode's dns. - pub dns: Vec, - /// Geodes' properties - pub props: BTreeMap, Vec>, - /// Current state of the geode and the block number of since last state change - pub state: GeodeState, - /// promise to be online until which block - pub promise: BlockNumber, -} - -impl From> for WrappedGeode { - fn from(geode: Geode) -> Self { - WrappedGeode { - id: geode.id.into(), - provider: geode.provider.into(), - order: geode.order, - ip: geode.ip, - dns: geode.dns, - props: geode.props, - state: geode.state, - promise: geode.promise, - } - } + #[rpc(name = "geode_ready")] + fn geode_ready(&self, message: Vec, signature_raw_bytes: Vec) -> Result; + #[rpc(name = "geode_finalizing")] + fn geode_finalizing(&self, message: Vec, signature_raw_bytes: Vec) -> Result; + #[rpc(name = "geode_finalized")] + fn geode_finalized(&self, message: Vec, signature_raw_bytes: Vec) -> Result; + #[rpc(name = "geode_finalize_failed")] + fn geode_finalize_failed(&self, message: Vec, signature_raw_bytes: Vec) + -> Result; } -/// An implementation of geode specific RPC methods. pub struct GeodeApi { client: Arc, } impl GeodeApi { - /// Create new `Geode` with the given reference to the client. pub fn new(client: Arc) -> Self { GeodeApi { client } } @@ -86,72 +40,71 @@ where C: ProvideRuntimeApi + HeaderBackend, C::Api: GeodeRuntimeApi, { - /// get registered geode list - fn registered_geodes(&self) -> Result>> { + fn geode_ready(&self, message: Vec, signature_raw_bytes: Vec) -> Result { let api = self.client.runtime_api(); let best = self.client.info().best_hash; let at = BlockId::hash(best); - - let registered_geodes_list = api.registered_geodes(&at).map_err(|e| Error { - code: ErrorCode::ServerError(RUNTIME_ERROR), - message: "Runtime unable to get registered geodes list.".into(), - data: Some(format!("{:?}", e).into()), - })?; - let mut res = Vec::>::new(); - for geode in registered_geodes_list { - res.push(geode.into()) - } - Ok(res) + let mut signature = [0_u8; 64]; + signature.copy_from_slice(&signature_raw_bytes); + let result = api + .unsigned_geode_ready(&at, message, signature) + .map_err(|e| Error { + code: ErrorCode::ServerError(RUNTIME_ERROR), + message: "Runtime unable to call geode_ready.".into(), + data: Some(format!("{:?}", e).into()), + })?; + Ok(result) } - /// get registered geode list - fn attested_geodes(&self) -> Result>> { + fn geode_finalizing(&self, message: Vec, signature_raw_bytes: Vec) -> Result { let api = self.client.runtime_api(); let best = self.client.info().best_hash; let at = BlockId::hash(best); - - let attested_geodes_list = api.attested_geodes(&at).map_err(|e| Error { - code: ErrorCode::ServerError(RUNTIME_ERROR), - message: "Runtime unable to get attested geodes list.".into(), - data: Some(format!("{:?}", e).into()), - })?; - let mut res = Vec::>::new(); - for geode in attested_geodes_list { - res.push(geode.into()) - } - Ok(res) + let mut signature = [0_u8; 64]; + signature.copy_from_slice(&signature_raw_bytes); + let result = api + .unsigned_geode_finalizing(&at, message, signature) + .map_err(|e| Error { + code: ErrorCode::ServerError(RUNTIME_ERROR), + message: "Runtime unable to call geode_finalizing.".into(), + data: Some(format!("{:?}", e).into()), + })?; + Ok(result) } - /// Return list geode an attestor is attesting - fn attestor_attested_geodes(&self, attestor: [u8; 32]) -> Result>> { + fn geode_finalized(&self, message: Vec, signature_raw_bytes: Vec) -> Result { let api = self.client.runtime_api(); let best = self.client.info().best_hash; let at = BlockId::hash(best); - let attestor_attested_geodes_list = api - .attestor_attested_geodes(&at, attestor.into()) + let mut signature = [0_u8; 64]; + signature.copy_from_slice(&signature_raw_bytes); + let result = api + .unsigned_geode_finalized(&at, message, signature) .map_err(|e| Error { code: ErrorCode::ServerError(RUNTIME_ERROR), - message: "Runtime unable to get attestor attested geodes list.".into(), + message: "Runtime unable to geode_finalized.".into(), data: Some(format!("{:?}", e).into()), })?; - let mut res = Vec::>::new(); - for geode in attestor_attested_geodes_list { - res.push(geode.into()) - } - Ok(res) + Ok(result) } - /// Return the current state of a geode - fn geode_state(&self, geode: [u8; 32]) -> Result> { + fn geode_finalize_failed( + &self, + message: Vec, + signature_raw_bytes: Vec, + ) -> Result { let api = self.client.runtime_api(); let best = self.client.info().best_hash; let at = BlockId::hash(best); - let geode_state = api.geode_state(&at, geode.into()).map_err(|e| Error { - code: ErrorCode::ServerError(RUNTIME_ERROR), - message: "Runtime unable to get geode state.".into(), - data: Some(format!("{:?}", e).into()), - })?; - - Ok(geode_state) + let mut signature = [0_u8; 64]; + signature.copy_from_slice(&signature_raw_bytes); + let result = api + .unsigned_geode_finalize_failed(&at, message, signature) + .map_err(|e| Error { + code: ErrorCode::ServerError(RUNTIME_ERROR), + message: "Runtime unable to call geode_finalized.".into(), + data: Some(format!("{:?}", e).into()), + })?; + Ok(result) } -} +} \ No newline at end of file diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 8f559be..f211510 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -29,6 +29,10 @@ use fc_rpc_core::types::PendingTransactions; use finitestate_runtime::apis::DAOPortalApi as DAOPortalRuntimeApi; #[cfg(feature = "finitestate")] use finitestate_runtime::apis::GmetadataApi as GmetadataRuntimeApi; +#[cfg(feature = "finitestate")] +use finitestate_runtime::apis::GeodeApi as GeodeRuntimeApi; +#[cfg(feature = "finitestate")] +use finitestate_runtime::apis::AttestorApi as AttestorRuntimeApi; use jsonrpc_pubsub::manager::SubscriptionManager; use pallet_ethereum::EthereumStorageSchema; use sc_client_api::{ @@ -71,6 +75,12 @@ pub mod gmetadata; #[cfg(feature = "finitestate")] pub mod gmetadata; +#[cfg(feature = "finitestate")] +pub mod geode; + +#[cfg(feature = "finitestate")] +pub mod attestor; + /// Extra dependencies for BABE. pub struct BabeDeps { /// BABE protocol config. @@ -144,6 +154,8 @@ where C::Api: BlockBuilder, C::Api: DAOPortalRuntimeApi, C::Api: GmetadataRuntimeApi, + C::Api: GeodeRuntimeApi, + C::Api: AttestorRuntimeApi, P: TransactionPool + 'static, B: sc_client_api::Backend + Send + Sync + 'static, B::State: sc_client_api::StateBackend>, @@ -164,6 +176,14 @@ where _client.clone(), ))); + use attestor::AttestorServer; + io.extend_with(AttestorServer::to_delegate(attestor::AttestorApi::new( + _client.clone(), + ))); + + use geode::GeodeServer; + io.extend_with(GeodeServer::to_delegate(geode::GeodeApi::new(_client.clone()))); + // Ok(create_full_base::( // deps, // subscription_task_executor, diff --git a/runtime/automata/Cargo.toml b/runtime/automata/Cargo.toml index 30e7990..0c7f4cd 100644 --- a/runtime/automata/Cargo.toml +++ b/runtime/automata/Cargo.toml @@ -73,10 +73,7 @@ pallet-indices = { default-features = false, git = 'https://github.com/automata- static_assertions = "1.1.0" # local dependencies -pallet-attestor = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0' } -pallet-geode = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0' } pallet-transfer = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0' } -pallet-liveness = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0' } pallet-bridge = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0'} pallet-bridgetransfer = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0'} pallet-vesting = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0'} @@ -92,7 +89,6 @@ runtime-benchmarks = [ 'frame-system/runtime-benchmarks', 'pallet-balances/runtime-benchmarks', - 'pallet-attestor/runtime-benchmarks', 'pallet-timestamp/runtime-benchmarks', 'sp-runtime/runtime-benchmarks', 'pallet-election-provider-multi-phase/runtime-benchmarks' @@ -116,8 +112,6 @@ std = [ "pallet-authority-discovery/std", 'pallet-staking/std', "pallet-session/std", - 'pallet-attestor/std', - 'pallet-attestor/full_crypto', 'pallet-timestamp/std', 'pallet-transaction-payment-rpc-runtime-api/std', 'pallet-transaction-payment/std', diff --git a/runtime/contextfree/Cargo.toml b/runtime/contextfree/Cargo.toml index 88ed0e5..c8e55b4 100644 --- a/runtime/contextfree/Cargo.toml +++ b/runtime/contextfree/Cargo.toml @@ -74,10 +74,7 @@ frame-election-provider-support = { default-features = false, git = 'https://git static_assertions = "1.1.0" # local dependencies -pallet-attestor = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0' } -pallet-geode = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0' } pallet-transfer = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0' } -pallet-liveness = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0' } pallet-bridge = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0'} pallet-bridgetransfer = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0'} pallet-game = { default-features = false, git = 'https://github.com/automata-network/automata-common', branch = 'main' } @@ -94,7 +91,6 @@ runtime-benchmarks = [ 'frame-system-benchmarking', 'frame-system/runtime-benchmarks', 'pallet-balances/runtime-benchmarks', - 'pallet-attestor/runtime-benchmarks', 'pallet-timestamp/runtime-benchmarks', 'sp-runtime/runtime-benchmarks', 'pallet-election-provider-multi-phase/runtime-benchmarks' @@ -119,8 +115,6 @@ std = [ 'pallet-staking/std', 'pallet-election-provider-multi-phase/std', "pallet-session/std", - 'pallet-attestor/std', - 'pallet-attestor/full_crypto', 'pallet-timestamp/std', 'pallet-transaction-payment-rpc-runtime-api/std', 'pallet-transaction-payment/std', diff --git a/runtime/finitestate/Cargo.toml b/runtime/finitestate/Cargo.toml index b53e1ad..0808906 100644 --- a/runtime/finitestate/Cargo.toml +++ b/runtime/finitestate/Cargo.toml @@ -74,10 +74,11 @@ frame-election-provider-support = { default-features = false, git = 'https://git static_assertions = "1.1.0" # local dependencies -pallet-attestor = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0' } -pallet-geode = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0' } +pallet-attestor = { default-features = false, git = 'https://github.com/automata-network/automata-common', branch = 'gee' } +pallet-geode = { default-features = false, git = 'https://github.com/automata-network/automata-common', branch = 'gee' } +pallet-geodesession = { default-features = false, git = 'https://github.com/automata-network/automata-common', branch = 'gee' } +pallet-order = { default-features = false, git = 'https://github.com/automata-network/automata-common', branch = 'gee' } pallet-transfer = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0' } -pallet-liveness = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0' } pallet-bridge = { default-features = false, git = 'https://github.com/automata-network/automata-common', branch = 'main' } pallet-bridgetransfer = { default-features = false, git = 'https://github.com/automata-network/automata-common', branch = 'main' } pallet-game = { default-features = false, git = 'https://github.com/automata-network/automata-common', branch = 'main' } diff --git a/runtime/finitestate/src/apis.rs b/runtime/finitestate/src/apis.rs index f132a90..ea8b67f 100644 --- a/runtime/finitestate/src/apis.rs +++ b/runtime/finitestate/src/apis.rs @@ -29,4 +29,17 @@ sp_api::decl_runtime_apis! { limit: u64 ) -> GmetadataQueryResult; } + + pub trait AttestorApi { + fn attestor_list() -> Vec<(Vec, Vec, u32)>; + fn attestor_attested_appids(attestor: AccountId) -> Vec; + fn unsigned_attestor_heartbeat(message: Vec, signature_raw_bytes: [u8; 64]) -> bool; + } + + pub trait GeodeApi { + fn unsigned_geode_ready(message: Vec, signature_raw_bytes: [u8; 64]) -> bool; + fn unsigned_geode_finalizing(message: Vec, signature_raw_bytes: [u8; 64]) -> bool; + fn unsigned_geode_finalized(message: Vec, signature_raw_bytes: [u8; 64]) -> bool; + fn unsigned_geode_finalize_failed(message: Vec, signature_raw_bytes: [u8; 64]) -> bool; + } } diff --git a/runtime/finitestate/src/lib.rs b/runtime/finitestate/src/lib.rs index 7494b7b..af6d5c9 100644 --- a/runtime/finitestate/src/lib.rs +++ b/runtime/finitestate/src/lib.rs @@ -191,6 +191,9 @@ impl Contains for CallFilter { | Call::Treasury(_) | Call::PhragmenElection(_) | Call::Scheduler(_) + | Call::Attestor(_) + | Call::Geode(_) + | Call::GeodeSession(_) | Call::Balances(_) => true, // These modules are not allowed to be called by transactions: @@ -833,6 +836,42 @@ impl pallet_treasury::Config for Runtime { type WeightInfo = pallet_treasury::weights::SubstrateWeight; } +impl pallet_order::Config for Runtime { + type Event = Event; +} + +parameter_types! { + pub const MinimumAttestorNum: u16 = 1; + pub const ExpectedAttestorNum: u16 = 2; + pub const AttestorHeartbeatTimeoutBlockNumber: u32 = 5; +} + +impl pallet_attestor::Config for Runtime { + type Event = Event; + type Currency = Balances; + type Call = Call; + type MinimumAttestorNum = MinimumAttestorNum; + type ExpectedAttestorNum = ExpectedAttestorNum; + type HeartbeatTimeoutBlockNumber = AttestorHeartbeatTimeoutBlockNumber; + type ApplicationHandler = pallet_geode::Pallet; +} + +impl pallet_geode::Config for Runtime { + type Event = Event; + type AttestorHandler = pallet_attestor::Pallet; + type OrderHandler = pallet_order::Pallet; +} + +parameter_types!{ + pub const SessionBlocks: u32 = 100; +} + +impl pallet_geodesession::Config for Runtime { + type Event = Event; + type GeodeHandler = pallet_geode::Pallet; + type Blocks = SessionBlocks; +} + /// Fixed gas price of `1`. pub struct FixedGasPrice; @@ -1089,6 +1128,11 @@ construct_runtime!( Game: pallet_game::{Pallet, Call, Storage, Event}, DAOPortal: pallet_daoportal::{Pallet, Call, Storage, Event}, Gmetadata: pallet_gmetadata::{Pallet, Call, Storage, Event}, + + Order: pallet_order::{Pallet, Storage, Event}, + Attestor: pallet_attestor::{Pallet, Call, Storage, Event, ValidateUnsigned}, + Geode: pallet_geode::{Pallet, Call, Storage, Event, ValidateUnsigned}, + GeodeSession: pallet_geodesession::{Pallet, Call, Storage, Event}, } ); @@ -1336,6 +1380,50 @@ impl_runtime_apis! { } } + impl apis::AttestorApi for Runtime { + fn attestor_list() -> Vec<(Vec, Vec, u32)> { + Attestor::attestor_list() + } + + fn attestor_attested_appids(attestor: AccountId) -> Vec { + Attestor::attestor_attested_appids(attestor) + } + + fn unsigned_attestor_heartbeat(message: Vec, signature_raw_bytes: [u8; 64]) -> bool { + match Attestor::unsigned_attestor_heartbeat(message, signature_raw_bytes) { + Ok(_) => true, + Err(_) => false, + } + } + } + + impl apis::GeodeApi for Runtime { + fn unsigned_geode_ready(message: Vec, signature_raw_bytes: [u8; 64]) -> bool { + match Geode::rpc_unsigned_geode_ready(message, signature_raw_bytes) { + Ok(_) => true, + Err(_) => false, + } + } + fn unsigned_geode_finalizing(message: Vec, signature_raw_bytes: [u8; 64]) -> bool { + match Geode::rpc_unsigned_geode_finalizing(message, signature_raw_bytes) { + Ok(_) => true, + Err(_) => false, + } + } + fn unsigned_geode_finalized(message: Vec, signature_raw_bytes: [u8; 64]) -> bool { + match Geode::rpc_unsigned_geode_finalized(message, signature_raw_bytes) { + Ok(_) => true, + Err(_) => false, + } + } + fn unsigned_geode_finalize_failed(message: Vec, signature_raw_bytes: [u8; 64]) -> bool { + match Geode::rpc_unsigned_geode_finalize_failed(message, signature_raw_bytes) { + Ok(_) => true, + Err(_) => false, + } + } + } + impl fp_rpc::EthereumRuntimeRPCApi for Runtime { fn chain_id() -> u64 { ::ChainId::get() From 5a2f415d031b5c957d95ecfd542b202d7aaa12f8 Mon Sep 17 00:00:00 2001 From: ChenYe Date: Wed, 20 Jul 2022 15:43:58 +0800 Subject: [PATCH 2/6] format code --- rpc/src/attestor.rs | 4 ++-- rpc/src/geode.rs | 8 ++++---- rpc/src/lib.rs | 10 ++++++---- runtime/finitestate/src/lib.rs | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/rpc/src/attestor.rs b/rpc/src/attestor.rs index 02f83b3..a027491 100644 --- a/rpc/src/attestor.rs +++ b/rpc/src/attestor.rs @@ -1,6 +1,6 @@ +use automata_primitives::{AccountId, Block, BlockId}; use jsonrpc_core::{Error, ErrorCode, Result}; use jsonrpc_derive::rpc; -use automata_primitives::{Block, BlockId, AccountId}; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_runtime::traits::Block as BlockT; @@ -87,4 +87,4 @@ where })?; Ok(result) } -} \ No newline at end of file +} diff --git a/rpc/src/geode.rs b/rpc/src/geode.rs index 04491ab..c258419 100644 --- a/rpc/src/geode.rs +++ b/rpc/src/geode.rs @@ -1,12 +1,12 @@ +use automata_primitives::Block; +#[cfg(feature = "finitestate")] +use finitestate_runtime::apis::GeodeApi as GeodeRuntimeApi; use jsonrpc_core::{Error, ErrorCode, Result}; use jsonrpc_derive::rpc; -use automata_primitives::{Block}; use sp_api::BlockId; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_runtime::traits::Block as BlockT; -#[cfg(feature = "finitestate")] -use finitestate_runtime::apis::GeodeApi as GeodeRuntimeApi; use std::sync::Arc; const RUNTIME_ERROR: i64 = 1; @@ -107,4 +107,4 @@ where })?; Ok(result) } -} \ No newline at end of file +} diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index f211510..8c87b15 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -26,13 +26,13 @@ use fc_rpc_core::types::PendingTransactions; // #[cfg(feature = "finitestate")] // use finitestate_runtime::apis::TransferApi as TransferRuntimeApi; #[cfg(feature = "finitestate")] -use finitestate_runtime::apis::DAOPortalApi as DAOPortalRuntimeApi; +use finitestate_runtime::apis::AttestorApi as AttestorRuntimeApi; #[cfg(feature = "finitestate")] -use finitestate_runtime::apis::GmetadataApi as GmetadataRuntimeApi; +use finitestate_runtime::apis::DAOPortalApi as DAOPortalRuntimeApi; #[cfg(feature = "finitestate")] use finitestate_runtime::apis::GeodeApi as GeodeRuntimeApi; #[cfg(feature = "finitestate")] -use finitestate_runtime::apis::AttestorApi as AttestorRuntimeApi; +use finitestate_runtime::apis::GmetadataApi as GmetadataRuntimeApi; use jsonrpc_pubsub::manager::SubscriptionManager; use pallet_ethereum::EthereumStorageSchema; use sc_client_api::{ @@ -182,7 +182,9 @@ where ))); use geode::GeodeServer; - io.extend_with(GeodeServer::to_delegate(geode::GeodeApi::new(_client.clone()))); + io.extend_with(GeodeServer::to_delegate(geode::GeodeApi::new( + _client.clone(), + ))); // Ok(create_full_base::( // deps, diff --git a/runtime/finitestate/src/lib.rs b/runtime/finitestate/src/lib.rs index af6d5c9..3725c16 100644 --- a/runtime/finitestate/src/lib.rs +++ b/runtime/finitestate/src/lib.rs @@ -862,7 +862,7 @@ impl pallet_geode::Config for Runtime { type OrderHandler = pallet_order::Pallet; } -parameter_types!{ +parameter_types! { pub const SessionBlocks: u32 = 100; } From 73deb33bbb82a29ad63dda1227903f708a5887b9 Mon Sep 17 00:00:00 2001 From: ChenYe Date: Wed, 20 Jul 2022 16:10:21 +0800 Subject: [PATCH 3/6] fix build --- Cargo.lock | 14 +++++++------- runtime/finitestate/src/lib.rs | 4 ---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb0ca48..74beea3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -443,7 +443,7 @@ dependencies = [ [[package]] name = "automata-primitives" version = "0.1.0" -source = "git+https://github.com/automata-network/automata-common?branch=gee#6965f91efec33c6018cde97781a24df53d03a87f" +source = "git+https://github.com/automata-network/automata-common?branch=gee#eda96e6b82c6e4eda42b0832cf5cfd5f5901e6f5" dependencies = [ "frame-system", "impl-trait-for-tuples 0.2.1", @@ -631,7 +631,7 @@ dependencies = [ [[package]] name = "automata-traits" version = "0.1.0" -source = "git+https://github.com/automata-network/automata-common?branch=gee#6965f91efec33c6018cde97781a24df53d03a87f" +source = "git+https://github.com/automata-network/automata-common?branch=gee#eda96e6b82c6e4eda42b0832cf5cfd5f5901e6f5" dependencies = [ "frame-support", "parity-scale-codec", @@ -4676,7 +4676,7 @@ dependencies = [ [[package]] name = "pallet-attestor" version = "0.1.0" -source = "git+https://github.com/automata-network/automata-common?branch=gee#6965f91efec33c6018cde97781a24df53d03a87f" +source = "git+https://github.com/automata-network/automata-common?branch=gee#eda96e6b82c6e4eda42b0832cf5cfd5f5901e6f5" dependencies = [ "automata-primitives 0.1.0 (git+https://github.com/automata-network/automata-common?branch=gee)", "automata-traits", @@ -5021,7 +5021,7 @@ dependencies = [ [[package]] name = "pallet-geode" version = "0.1.0" -source = "git+https://github.com/automata-network/automata-common?branch=gee#6965f91efec33c6018cde97781a24df53d03a87f" +source = "git+https://github.com/automata-network/automata-common?branch=gee#eda96e6b82c6e4eda42b0832cf5cfd5f5901e6f5" dependencies = [ "automata-primitives 0.1.0 (git+https://github.com/automata-network/automata-common?branch=gee)", "automata-traits", @@ -5040,7 +5040,7 @@ dependencies = [ [[package]] name = "pallet-geodesession" version = "0.1.0" -source = "git+https://github.com/automata-network/automata-common?branch=gee#6965f91efec33c6018cde97781a24df53d03a87f" +source = "git+https://github.com/automata-network/automata-common?branch=gee#eda96e6b82c6e4eda42b0832cf5cfd5f5901e6f5" dependencies = [ "automata-primitives 0.1.0 (git+https://github.com/automata-network/automata-common?branch=gee)", "automata-traits", @@ -5160,7 +5160,7 @@ dependencies = [ [[package]] name = "pallet-order" version = "0.1.0" -source = "git+https://github.com/automata-network/automata-common?branch=gee#6965f91efec33c6018cde97781a24df53d03a87f" +source = "git+https://github.com/automata-network/automata-common?branch=gee#eda96e6b82c6e4eda42b0832cf5cfd5f5901e6f5" dependencies = [ "automata-primitives 0.1.0 (git+https://github.com/automata-network/automata-common?branch=gee)", "automata-traits", @@ -9340,7 +9340,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ "cfg-if 1.0.0", - "rand 0.8.5", + "rand 0.3.23", "static_assertions", ] diff --git a/runtime/finitestate/src/lib.rs b/runtime/finitestate/src/lib.rs index 3725c16..d9f8504 100644 --- a/runtime/finitestate/src/lib.rs +++ b/runtime/finitestate/src/lib.rs @@ -841,8 +841,6 @@ impl pallet_order::Config for Runtime { } parameter_types! { - pub const MinimumAttestorNum: u16 = 1; - pub const ExpectedAttestorNum: u16 = 2; pub const AttestorHeartbeatTimeoutBlockNumber: u32 = 5; } @@ -850,8 +848,6 @@ impl pallet_attestor::Config for Runtime { type Event = Event; type Currency = Balances; type Call = Call; - type MinimumAttestorNum = MinimumAttestorNum; - type ExpectedAttestorNum = ExpectedAttestorNum; type HeartbeatTimeoutBlockNumber = AttestorHeartbeatTimeoutBlockNumber; type ApplicationHandler = pallet_geode::Pallet; } From 89c6074b28d1c302a78f8e3956f2ec3c997235c0 Mon Sep 17 00:00:00 2001 From: ChenYe Date: Thu, 21 Jul 2022 11:59:41 +0800 Subject: [PATCH 4/6] update automata-common --- Cargo.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 74beea3..4a4543e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -443,7 +443,7 @@ dependencies = [ [[package]] name = "automata-primitives" version = "0.1.0" -source = "git+https://github.com/automata-network/automata-common?branch=gee#eda96e6b82c6e4eda42b0832cf5cfd5f5901e6f5" +source = "git+https://github.com/automata-network/automata-common?branch=gee#b4a7d94526d5203f5f4f130002f99da55315246c" dependencies = [ "frame-system", "impl-trait-for-tuples 0.2.1", @@ -631,7 +631,7 @@ dependencies = [ [[package]] name = "automata-traits" version = "0.1.0" -source = "git+https://github.com/automata-network/automata-common?branch=gee#eda96e6b82c6e4eda42b0832cf5cfd5f5901e6f5" +source = "git+https://github.com/automata-network/automata-common?branch=gee#b4a7d94526d5203f5f4f130002f99da55315246c" dependencies = [ "frame-support", "parity-scale-codec", @@ -4676,7 +4676,7 @@ dependencies = [ [[package]] name = "pallet-attestor" version = "0.1.0" -source = "git+https://github.com/automata-network/automata-common?branch=gee#eda96e6b82c6e4eda42b0832cf5cfd5f5901e6f5" +source = "git+https://github.com/automata-network/automata-common?branch=gee#b4a7d94526d5203f5f4f130002f99da55315246c" dependencies = [ "automata-primitives 0.1.0 (git+https://github.com/automata-network/automata-common?branch=gee)", "automata-traits", @@ -5021,7 +5021,7 @@ dependencies = [ [[package]] name = "pallet-geode" version = "0.1.0" -source = "git+https://github.com/automata-network/automata-common?branch=gee#eda96e6b82c6e4eda42b0832cf5cfd5f5901e6f5" +source = "git+https://github.com/automata-network/automata-common?branch=gee#b4a7d94526d5203f5f4f130002f99da55315246c" dependencies = [ "automata-primitives 0.1.0 (git+https://github.com/automata-network/automata-common?branch=gee)", "automata-traits", @@ -5040,7 +5040,7 @@ dependencies = [ [[package]] name = "pallet-geodesession" version = "0.1.0" -source = "git+https://github.com/automata-network/automata-common?branch=gee#eda96e6b82c6e4eda42b0832cf5cfd5f5901e6f5" +source = "git+https://github.com/automata-network/automata-common?branch=gee#b4a7d94526d5203f5f4f130002f99da55315246c" dependencies = [ "automata-primitives 0.1.0 (git+https://github.com/automata-network/automata-common?branch=gee)", "automata-traits", @@ -5160,7 +5160,7 @@ dependencies = [ [[package]] name = "pallet-order" version = "0.1.0" -source = "git+https://github.com/automata-network/automata-common?branch=gee#eda96e6b82c6e4eda42b0832cf5cfd5f5901e6f5" +source = "git+https://github.com/automata-network/automata-common?branch=gee#b4a7d94526d5203f5f4f130002f99da55315246c" dependencies = [ "automata-primitives 0.1.0 (git+https://github.com/automata-network/automata-common?branch=gee)", "automata-traits", From b0ce69a6fa7a1fb1e9e6621a81e5ccd1f9a726de Mon Sep 17 00:00:00 2001 From: ChenYe Date: Wed, 24 Aug 2022 23:35:46 +0800 Subject: [PATCH 5/6] gee to cf --- Cargo.lock | 4 ++ rpc/src/attestor.rs | 2 + rpc/src/geode.rs | 2 + rpc/src/lib.rs | 12 +++++ runtime/contextfree/Cargo.toml | 4 ++ runtime/contextfree/src/apis.rs | 13 +++++ runtime/contextfree/src/lib.rs | 86 ++++++++++++++++++++++++++++++++- runtime/finitestate/src/lib.rs | 2 +- 8 files changed, 123 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4a4543e..1ff77a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1083,6 +1083,7 @@ dependencies = [ "frame-system-benchmarking", "frame-system-rpc-runtime-api", "hex-literal", + "pallet-attestor", "pallet-authority-discovery", "pallet-authorship", "pallet-babe", @@ -1098,12 +1099,15 @@ dependencies = [ "pallet-evm", "pallet-evm-precompile-simple", "pallet-game", + "pallet-geode", + "pallet-geodesession", "pallet-gmetadata", "pallet-grandpa", "pallet-im-online", "pallet-indices", "pallet-membership", "pallet-offences", + "pallet-order", "pallet-randomness-collective-flip", "pallet-scheduler", "pallet-session", diff --git a/rpc/src/attestor.rs b/rpc/src/attestor.rs index a027491..749d235 100644 --- a/rpc/src/attestor.rs +++ b/rpc/src/attestor.rs @@ -6,6 +6,8 @@ use sp_blockchain::HeaderBackend; use sp_runtime::traits::Block as BlockT; use std::sync::Arc; +#[cfg(feature = "contextfree")] +use contextfree_runtime::apis::AttestorApi as AttestorRuntimeApi; #[cfg(feature = "finitestate")] use finitestate_runtime::apis::AttestorApi as AttestorRuntimeApi; diff --git a/rpc/src/geode.rs b/rpc/src/geode.rs index c258419..aabc68f 100644 --- a/rpc/src/geode.rs +++ b/rpc/src/geode.rs @@ -1,4 +1,6 @@ use automata_primitives::Block; +#[cfg(feature = "contextfree")] +use contextfree_runtime::apis::GeodeApi as GeodeRuntimeApi; #[cfg(feature = "finitestate")] use finitestate_runtime::apis::GeodeApi as GeodeRuntimeApi; use jsonrpc_core::{Error, ErrorCode, Result}; diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 8c87b15..3baf84a 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -18,8 +18,12 @@ use automata_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Index}; // #[cfg(feature = "contextfree")] // use contextfree_runtime::apis::TransferApi as TransferRuntimeApi; #[cfg(feature = "contextfree")] +use contextfree_runtime::apis::AttestorApi as AttestorRuntimeApi; +#[cfg(feature = "contextfree")] use contextfree_runtime::apis::DAOPortalApi as DAOPortalRuntimeApi; #[cfg(feature = "contextfree")] +use contextfree_runtime::apis::GeodeApi as GeodeRuntimeApi; +#[cfg(feature = "contextfree")] use contextfree_runtime::apis::GmetadataApi as GmetadataRuntimeApi; use fc_rpc::{OverrideHandle, RuntimeApiStorageOverride, SchemaV1Override, StorageOverride}; use fc_rpc_core::types::PendingTransactions; @@ -72,6 +76,12 @@ pub mod daoportal; #[cfg(feature = "contextfree")] pub mod gmetadata; +#[cfg(feature = "contextfree")] +pub mod geode; + +#[cfg(feature = "contextfree")] +pub mod attestor; + #[cfg(feature = "finitestate")] pub mod gmetadata; @@ -214,6 +224,8 @@ where C::Api: BlockBuilder, C::Api: DAOPortalRuntimeApi, C::Api: GmetadataRuntimeApi, + C::Api: GeodeRuntimeApi, + C::Api: AttestorRuntimeApi, P: TransactionPool + 'static, B: sc_client_api::Backend + Send + Sync + 'static, B::State: sc_client_api::StateBackend>, diff --git a/runtime/contextfree/Cargo.toml b/runtime/contextfree/Cargo.toml index c8e55b4..c1d0b33 100644 --- a/runtime/contextfree/Cargo.toml +++ b/runtime/contextfree/Cargo.toml @@ -74,6 +74,10 @@ frame-election-provider-support = { default-features = false, git = 'https://git static_assertions = "1.1.0" # local dependencies +pallet-attestor = { default-features = false, git = 'https://github.com/automata-network/automata-common', branch = 'gee' } +pallet-geode = { default-features = false, git = 'https://github.com/automata-network/automata-common', branch = 'gee' } +pallet-geodesession = { default-features = false, git = 'https://github.com/automata-network/automata-common', branch = 'gee' } +pallet-order = { default-features = false, git = 'https://github.com/automata-network/automata-common', branch = 'gee' } pallet-transfer = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0' } pallet-bridge = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0'} pallet-bridgetransfer = { default-features = false, git = 'https://github.com/automata-network/automata-common', version = '0.1.0'} diff --git a/runtime/contextfree/src/apis.rs b/runtime/contextfree/src/apis.rs index 8465892..4f4c35e 100644 --- a/runtime/contextfree/src/apis.rs +++ b/runtime/contextfree/src/apis.rs @@ -27,4 +27,17 @@ sp_api::decl_runtime_apis! { limit: u64 ) -> GmetadataQueryResult; } + + pub trait AttestorApi { + fn attestor_list() -> Vec<(Vec, Vec, u32)>; + fn attestor_attested_appids(attestor: AccountId) -> Vec; + fn unsigned_attestor_heartbeat(message: Vec, signature_raw_bytes: [u8; 64]) -> bool; + } + + pub trait GeodeApi { + fn unsigned_geode_ready(message: Vec, signature_raw_bytes: [u8; 64]) -> bool; + fn unsigned_geode_finalizing(message: Vec, signature_raw_bytes: [u8; 64]) -> bool; + fn unsigned_geode_finalized(message: Vec, signature_raw_bytes: [u8; 64]) -> bool; + fn unsigned_geode_finalize_failed(message: Vec, signature_raw_bytes: [u8; 64]) -> bool; + } } diff --git a/runtime/contextfree/src/lib.rs b/runtime/contextfree/src/lib.rs index c371e9c..03185e7 100644 --- a/runtime/contextfree/src/lib.rs +++ b/runtime/contextfree/src/lib.rs @@ -127,7 +127,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 1006, + spec_version: 1007, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -191,6 +191,9 @@ impl Contains for CallFilter { | Call::Treasury(_) | Call::PhragmenElection(_) | Call::Scheduler(_) + | Call::Attestor(_) + | Call::Geode(_) + | Call::GeodeSession(_) | Call::Utility(_) => true, // These modules are not allowed to be called by transactions: @@ -877,6 +880,38 @@ impl pallet_treasury::Config for Runtime { type WeightInfo = pallet_treasury::weights::SubstrateWeight; } +impl pallet_order::Config for Runtime { + type Event = Event; +} + +parameter_types! { + pub const AttestorHeartbeatTimeoutBlockNumber: u32 = 5; +} + +impl pallet_attestor::Config for Runtime { + type Event = Event; + type Currency = Balances; + type Call = Call; + type HeartbeatTimeoutBlockNumber = AttestorHeartbeatTimeoutBlockNumber; + type ApplicationHandler = pallet_geode::Pallet; +} + +impl pallet_geode::Config for Runtime { + type Event = Event; + type AttestorHandler = pallet_attestor::Pallet; + type OrderHandler = pallet_order::Pallet; +} + +parameter_types! { + pub const SessionBlocks: u32 = 100; +} + +impl pallet_geodesession::Config for Runtime { + type Event = Event; + type GeodeHandler = pallet_geode::Pallet; + type Blocks = SessionBlocks; +} + /// Fixed gas price of `1`. pub struct FixedGasPrice; @@ -1089,6 +1124,11 @@ construct_runtime!( Game: pallet_game::{Pallet, Call, Storage, Event}, DAOPortal: pallet_daoportal::{Pallet, Call, Storage, Event}, Gmetadata: pallet_gmetadata::{Pallet, Call, Storage, Event}, + + Order: pallet_order::{Pallet, Storage, Event}, + Attestor: pallet_attestor::{Pallet, Call, Storage, Event, ValidateUnsigned}, + Geode: pallet_geode::{Pallet, Call, Storage, Event, ValidateUnsigned}, + GeodeSession: pallet_geodesession::{Pallet, Call, Storage, Event}, } ); @@ -1336,6 +1376,50 @@ impl_runtime_apis! { } } + impl apis::AttestorApi for Runtime { + fn attestor_list() -> Vec<(Vec, Vec, u32)> { + Attestor::attestor_list() + } + + fn attestor_attested_appids(attestor: AccountId) -> Vec { + Attestor::attestor_attested_appids(attestor) + } + + fn unsigned_attestor_heartbeat(message: Vec, signature_raw_bytes: [u8; 64]) -> bool { + match Attestor::unsigned_attestor_heartbeat(message, signature_raw_bytes) { + Ok(_) => true, + Err(_) => false, + } + } + } + + impl apis::GeodeApi for Runtime { + fn unsigned_geode_ready(message: Vec, signature_raw_bytes: [u8; 64]) -> bool { + match Geode::rpc_unsigned_geode_ready(message, signature_raw_bytes) { + Ok(_) => true, + Err(_) => false, + } + } + fn unsigned_geode_finalizing(message: Vec, signature_raw_bytes: [u8; 64]) -> bool { + match Geode::rpc_unsigned_geode_finalizing(message, signature_raw_bytes) { + Ok(_) => true, + Err(_) => false, + } + } + fn unsigned_geode_finalized(message: Vec, signature_raw_bytes: [u8; 64]) -> bool { + match Geode::rpc_unsigned_geode_finalized(message, signature_raw_bytes) { + Ok(_) => true, + Err(_) => false, + } + } + fn unsigned_geode_finalize_failed(message: Vec, signature_raw_bytes: [u8; 64]) -> bool { + match Geode::rpc_unsigned_geode_finalize_failed(message, signature_raw_bytes) { + Ok(_) => true, + Err(_) => false, + } + } + } + impl fp_rpc::EthereumRuntimeRPCApi for Runtime { fn chain_id() -> u64 { ::ChainId::get() diff --git a/runtime/finitestate/src/lib.rs b/runtime/finitestate/src/lib.rs index d9f8504..3ea7aec 100644 --- a/runtime/finitestate/src/lib.rs +++ b/runtime/finitestate/src/lib.rs @@ -127,7 +127,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 1028, + spec_version: 1029, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 0ca230e934bd69b5930d732906a2be898c5a9740 Mon Sep 17 00:00:00 2001 From: ChenYe Date: Thu, 25 Aug 2022 10:17:19 +0800 Subject: [PATCH 6/6] add rpc --- rpc/src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 3baf84a..11dfc38 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -246,6 +246,16 @@ where _client.clone(), ))); + use attestor::AttestorServer; + io.extend_with(AttestorServer::to_delegate(attestor::AttestorApi::new( + _client.clone(), + ))); + + use geode::GeodeServer; + io.extend_with(GeodeServer::to_delegate(geode::GeodeApi::new( + _client.clone(), + ))); + Ok(io) }