diff --git a/Cargo.lock b/Cargo.lock index 8d15947..1ff77a6 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#b4a7d94526d5203f5f4f130002f99da55315246c" +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#b4a7d94526d5203f5f4f130002f99da55315246c" dependencies = [ "frame-support", "parity-scale-codec", @@ -1089,13 +1100,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", @@ -2064,13 +2076,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 +4680,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#b4a7d94526d5203f5f4f130002f99da55315246c" 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 +5025,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#b4a7d94526d5203f5f4f130002f99da55315246c" 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#b4a7d94526d5203f5f4f130002f99da55315246c" +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 +5130,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 +5162,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#b4a7d94526d5203f5f4f130002f99da55315246c" 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", ] @@ -9329,7 +9344,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/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..749d235 100644 --- a/rpc/src/attestor.rs +++ b/rpc/src/attestor.rs @@ -1,42 +1,35 @@ -use automata_primitives::{Block, BlockId}; -use automata_runtime::apis::AttestorApi as AttestorRuntimeApi; +use automata_primitives::{AccountId, Block, BlockId}; use jsonrpc_core::{Error, ErrorCode, Result}; use jsonrpc_derive::rpc; -use sc_light::blockchain::BlockchainHeaderBackend as HeaderBackend; 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 = "contextfree")] +use contextfree_runtime::apis::AttestorApi as AttestorRuntimeApi; +#[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 +41,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 +54,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) } } diff --git a/rpc/src/geode.rs b/rpc/src/geode.rs index ccd8a79..aabc68f 100644 --- a/rpc/src/geode.rs +++ b/rpc/src/geode.rs @@ -1,80 +1,36 @@ -use automata_primitives::{AccountId, Block, BlockId, BlockNumber, Hash}; -use automata_runtime::apis::GeodeApi as GeodeRuntimeApi; +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}; use jsonrpc_derive::rpc; -use pallet_geode::{Geode, GeodeState}; -use sc_light::blockchain::BlockchainHeaderBackend as HeaderBackend; +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; 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 +42,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) } } diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 8f559be..11dfc38 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -18,16 +18,24 @@ 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; // #[cfg(feature = "finitestate")] // use finitestate_runtime::apis::TransferApi as TransferRuntimeApi; #[cfg(feature = "finitestate")] +use finitestate_runtime::apis::AttestorApi as AttestorRuntimeApi; +#[cfg(feature = "finitestate")] use finitestate_runtime::apis::DAOPortalApi as DAOPortalRuntimeApi; #[cfg(feature = "finitestate")] +use finitestate_runtime::apis::GeodeApi as GeodeRuntimeApi; +#[cfg(feature = "finitestate")] use finitestate_runtime::apis::GmetadataApi as GmetadataRuntimeApi; use jsonrpc_pubsub::manager::SubscriptionManager; use pallet_ethereum::EthereumStorageSchema; @@ -68,9 +76,21 @@ 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; +#[cfg(feature = "finitestate")] +pub mod geode; + +#[cfg(feature = "finitestate")] +pub mod attestor; + /// Extra dependencies for BABE. pub struct BabeDeps { /// BABE protocol config. @@ -144,6 +164,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 +186,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(create_full_base::( // deps, // subscription_task_executor, @@ -192,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>, @@ -212,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) } 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..c1d0b33 100644 --- a/runtime/contextfree/Cargo.toml +++ b/runtime/contextfree/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', 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 +95,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 +119,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/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/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..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, @@ -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,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()