From 7768ea90adc21da302d7aa342cd9303d09d98968 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Wed, 6 Dec 2023 09:53:06 -0500 Subject: [PATCH] signals-primitives, plus various minor tweaks --- Cargo.toml | 1 + substrate/dex/pallet/src/lib.rs | 1 + substrate/node/src/rpc.rs | 3 +- substrate/node/src/service.rs | 2 +- substrate/primitives/src/lib.rs | 3 ++ substrate/runtime/src/lib.rs | 51 +++++++++++-------------- substrate/signals/pallet/Cargo.toml | 4 ++ substrate/signals/pallet/src/lib.rs | 7 +--- substrate/signals/primitives/Cargo.toml | 42 ++++++++++++++++++++ substrate/signals/primitives/LICENSE | 21 ++++++++++ substrate/signals/primitives/src/lib.rs | 17 +++++++++ 11 files changed, 114 insertions(+), 38 deletions(-) create mode 100644 substrate/signals/primitives/Cargo.toml create mode 100644 substrate/signals/primitives/LICENSE create mode 100644 substrate/signals/primitives/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 14add4b9..45950950 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,7 @@ members = [ "substrate/validator-sets/primitives", "substrate/validator-sets/pallet", + "substrate/signals/primitives", "substrate/signals/pallet", "substrate/runtime", diff --git a/substrate/dex/pallet/src/lib.rs b/substrate/dex/pallet/src/lib.rs index e26ca0af..20753fb9 100644 --- a/substrate/dex/pallet/src/lib.rs +++ b/substrate/dex/pallet/src/lib.rs @@ -236,6 +236,7 @@ pub mod pallet { /// The amount of lp tokens that were burned of that id. lp_token_burned: SubstrateAmount, }, + /// Coins have been converted from one to another. Both `SwapExactTokenForToken` /// and `SwapTokenForExactToken` will generate this event. SwapExecuted { diff --git a/substrate/node/src/rpc.rs b/substrate/node/src/rpc.rs index 326b3bd9..45e2391a 100644 --- a/substrate/node/src/rpc.rs +++ b/substrate/node/src/rpc.rs @@ -8,8 +8,7 @@ use sp_api::ProvideRuntimeApi; use serai_runtime::{ primitives::{SubstrateAmount, PublicKey}, - opaque::Block, - Nonce, + Nonce, Block, }; pub use sc_rpc_api::DenyUnsafe; diff --git a/substrate/node/src/service.rs b/substrate/node/src/service.rs index bceb06b7..54eed109 100644 --- a/substrate/node/src/service.rs +++ b/substrate/node/src/service.rs @@ -17,7 +17,7 @@ use sc_client_api::{BlockBackend, Backend}; use sc_telemetry::{Telemetry, TelemetryWorker}; -use serai_runtime::{opaque::Block, RuntimeApi}; +use serai_runtime::{Block, RuntimeApi}; use sc_consensus_babe::{self, SlotProportion}; use sc_consensus_grandpa as grandpa; diff --git a/substrate/primitives/src/lib.rs b/substrate/primitives/src/lib.rs index c77be43f..965870e3 100644 --- a/substrate/primitives/src/lib.rs +++ b/substrate/primitives/src/lib.rs @@ -139,3 +139,6 @@ impl AsRef<[u8]> for Data { self.0.as_ref() } } + +pub type BlockNumber = u64; +pub type Header = sp_runtime::generic::Header; diff --git a/substrate/runtime/src/lib.rs b/substrate/runtime/src/lib.rs index 91b821ba..d9c2ca14 100644 --- a/substrate/runtime/src/lib.rs +++ b/substrate/runtime/src/lib.rs @@ -8,6 +8,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); // Re-export all components pub use serai_primitives as primitives; +pub use primitives::{BlockNumber, Header}; pub use frame_system as system; pub use frame_support as support; @@ -40,7 +41,7 @@ use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, KeyTypeId, traits::{Convert, BlakeTwo256, Block as BlockT}, transaction_validity::{TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, Perbill, + Perbill, ApplyExtrinsicResult, }; use primitives::{PublicKey, SeraiAddress, AccountLookup, Signature, SubstrateAmount}; @@ -58,24 +59,31 @@ use babe::AuthorityId as BabeId; use grandpa::AuthorityId as GrandpaId; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; -/// An index to a block. -pub type BlockNumber = u64; - /// Nonce of a transaction in the chain, for a given account. pub type Nonce = u32; /// A hash of some data used by the chain. pub type Hash = sp_core::H256; +pub type SignedExtra = ( + system::CheckNonZeroSender, + system::CheckSpecVersion, + system::CheckTxVersion, + system::CheckGenesis, + system::CheckEra, + system::CheckNonce, + system::CheckWeight, + transaction_payment::ChargeTransactionPayment, +); +pub type UncheckedExtrinsic = + generic::UncheckedExtrinsic; + +pub type Block = generic::Block; +pub type BlockId = generic::BlockId; + pub mod opaque { use super::*; - use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; - - pub type Header = generic::Header; - pub type Block = generic::Block; - pub type BlockId = generic::BlockId; - impl_opaque_keys! { pub struct SessionKeys { pub babe: Babe, @@ -296,21 +304,6 @@ impl grandpa::Config for Runtime { type EquivocationReportSystem = (); } -pub type Header = generic::Header; -pub type Block = generic::Block; -pub type SignedExtra = ( - system::CheckNonZeroSender, - system::CheckSpecVersion, - system::CheckTxVersion, - system::CheckGenesis, - system::CheckEra, - system::CheckNonce, - system::CheckWeight, - transaction_payment::ChargeTransactionPayment, -); -pub type UncheckedExtrinsic = - generic::UncheckedExtrinsic; -pub type SignedPayload = generic::SignedPayload; pub type Executive = frame_executive::Executive< Runtime, Block, @@ -372,7 +365,7 @@ sp_api::impl_runtime_apis! { Executive::execute_block(block); } - fn initialize_block(header: &::Header) { + fn initialize_block(header: &Header) { Executive::initialize_block(header) } } @@ -396,7 +389,7 @@ sp_api::impl_runtime_apis! { Executive::apply_extrinsic(extrinsic) } - fn finalize_block() -> ::Header { + fn finalize_block() -> Header { Executive::finalize_block() } @@ -423,7 +416,7 @@ sp_api::impl_runtime_apis! { } impl sp_offchain::OffchainWorkerApi for Runtime { - fn offchain_worker(header: &::Header) { + fn offchain_worker(header: &Header) { Executive::offchain_worker(header) } } @@ -475,7 +468,7 @@ sp_api::impl_runtime_apis! { } fn submit_report_equivocation_unsigned_extrinsic( - _: sp_consensus_babe::EquivocationProof<::Header>, + _: sp_consensus_babe::EquivocationProof
, _: sp_consensus_babe::OpaqueKeyOwnershipProof, ) -> Option<()> { None diff --git a/substrate/signals/pallet/Cargo.toml b/substrate/signals/pallet/Cargo.toml index bf2cb4dd..50b9c8a5 100644 --- a/substrate/signals/pallet/Cargo.toml +++ b/substrate/signals/pallet/Cargo.toml @@ -23,6 +23,8 @@ frame-system = { git = "https://github.com/serai-dex/substrate", default-feature frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false } serai-primitives = { path = "../../primitives", default-features = false } +serai-signals-primitives = { path = "../primitives", default-features = false } + validator-sets-pallet = { package = "serai-validator-sets-pallet", path = "../../validator-sets/pallet", default-features = false } in-instructions-pallet = { package = "serai-in-instructions-pallet", path = "../../in-instructions/pallet", default-features = false } @@ -38,6 +40,8 @@ std = [ "frame-support/std", "serai-primitives/std", + "serai-signals-primitives/std", + "validator-sets-pallet/std", "in-instructions-pallet/std", ] diff --git a/substrate/signals/pallet/src/lib.rs b/substrate/signals/pallet/src/lib.rs index 91717e5b..07f28448 100644 --- a/substrate/signals/pallet/src/lib.rs +++ b/substrate/signals/pallet/src/lib.rs @@ -12,6 +12,7 @@ pub mod pallet { use frame_support::{pallet_prelude::*, sp_runtime}; use serai_primitives::*; + use serai_signals_primitives::SignalId; use validator_sets_pallet::{primitives::ValidatorSet, Config as VsConfig, Pallet as VsPallet}; use in_instructions_pallet::{Config as IiConfig, Pallet as InInstructions}; @@ -47,12 +48,6 @@ pub mod pallet { #[pallet::pallet] pub struct Pallet(PhantomData); - #[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)] - pub enum SignalId { - Retirement([u8; 32]), - Halt(NetworkId), - } - #[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)] pub struct RegisteredRetirementSignal { in_favor_of: [u8; 32], diff --git a/substrate/signals/primitives/Cargo.toml b/substrate/signals/primitives/Cargo.toml new file mode 100644 index 00000000..7e8f41bb --- /dev/null +++ b/substrate/signals/primitives/Cargo.toml @@ -0,0 +1,42 @@ +[package] +name = "serai-signals-primitives" +version = "0.1.0" +description = "Signals primitives" +license = "MIT" +repository = "https://github.com/serai-dex/serai/tree/develop/substrate/signals/primitives" +authors = ["Luke Parker "] +edition = "2021" +rust-version = "1.74" + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] + +[dependencies] +zeroize = { version = "^1.5", features = ["derive"], optional = true } + +scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } +scale-info = { version = "2", default-features = false, features = ["derive"] } + +borsh = { version = "1", default-features = false, features = ["derive", "de_strict_order"], optional = true } +serde = { version = "1", default-features = false, features = ["derive", "alloc"], optional = true } + +serai-primitives = { path = "../../primitives", version = "0.1", default-features = false } + +[features] +std = [ + "zeroize", + + "scale/std", + "scale-info/std", + + "borsh?/std", + "serde?/std", + + "serai-primitives/std", +] + +borsh = ["dep:borsh"] +serde = ["dep:serde"] + +default = ["std"] diff --git a/substrate/signals/primitives/LICENSE b/substrate/signals/primitives/LICENSE new file mode 100644 index 00000000..e6bff13c --- /dev/null +++ b/substrate/signals/primitives/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Luke Parker + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/substrate/signals/primitives/src/lib.rs b/substrate/signals/primitives/src/lib.rs new file mode 100644 index 00000000..cfd8aac5 --- /dev/null +++ b/substrate/signals/primitives/src/lib.rs @@ -0,0 +1,17 @@ +#![cfg_attr(docsrs, feature(doc_cfg))] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] +#![cfg_attr(not(feature = "std"), no_std)] + +use scale::{Encode, Decode, MaxEncodedLen}; +use scale_info::TypeInfo; + +use serai_primitives::NetworkId; + +#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)] +#[cfg_attr(feature = "std", derive(zeroize::Zeroize))] +#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub enum SignalId { + Retirement([u8; 32]), + Halt(NetworkId), +}