Update substrate

This commit is contained in:
Luke Parker 2023-07-18 22:30:55 -04:00
parent a7c9c1ef55
commit 64402914ba
No known key found for this signature in database
23 changed files with 881 additions and 798 deletions

1261
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -36,9 +36,7 @@ pub mod pallet {
use super::*;
#[pallet::config]
pub trait Config:
frame_system::Config<BlockNumber = u64> + ValidatorSetsConfig + TokensConfig
{
pub trait Config: frame_system::Config + ValidatorSetsConfig + TokensConfig {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}

View file

@ -13,11 +13,11 @@ rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
zeroize = { version = "^1.5", features = ["derive"], optional = true }
serde = { version = "1", default-features = false, features = ["derive", "alloc"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
serde = { version = "1", features = ["derive"], optional = true }
sp-application-crypto = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
@ -29,11 +29,11 @@ tokens-primitives = { package = "serai-tokens-primitives", path = "../../tokens/
std = [
"zeroize",
"serde/std",
"scale/std",
"scale-info/std",
"serde",
"sp-std/std",
"sp-runtime/std",

View file

@ -5,12 +5,11 @@
#[cfg(feature = "std")]
use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use sp_application_crypto::sr25519::Signature;
#[cfg(not(feature = "std"))]
@ -22,42 +21,51 @@ use serai_primitives::{BlockHash, Balance, NetworkId, SeraiAddress, ExternalAddr
mod shorthand;
pub use shorthand::*;
#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[rustfmt::skip]
#[derive(
Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub enum Application {
DEX,
}
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[derive(
Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct ApplicationCall {
pub application: Application,
pub data: Data,
}
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[derive(
Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub enum InInstruction {
Transfer(SeraiAddress),
Call(ApplicationCall),
}
#[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Encode, Decode, TypeInfo, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct RefundableInInstruction {
pub origin: Option<ExternalAddress>,
pub instruction: InInstruction,
}
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[derive(
Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct InInstructionWithBalance {
pub instruction: InInstruction,
pub balance: Balance,
}
#[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Encode, Decode, TypeInfo, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct Batch {
pub network: NetworkId,
pub id: u32,
@ -65,8 +73,7 @@ pub struct Batch {
pub instructions: Vec<InInstructionWithBalance>,
}
#[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Encode, Decode, TypeInfo, RuntimeDebug)]
pub struct SignedBatch {
pub batch: Batch,
pub signature: Signature,

View file

@ -1,12 +1,11 @@
#[cfg(feature = "std")]
use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use serai_primitives::{Coin, Amount, SeraiAddress, ExternalAddress, Data};
use tokens_primitives::OutInstruction;
@ -15,8 +14,10 @@ use crate::RefundableInInstruction;
#[cfg(feature = "std")]
use crate::InInstruction;
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[derive(
Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub enum Shorthand {
Raw(Data),
Swap {

View file

@ -33,6 +33,7 @@ frame-benchmarking-cli = { git = "https://github.com/serai-dex/substrate" }
serai-runtime = { path = "../runtime", features = ["std"] }
sc-offchain = { git = "https://github.com/serai-dex/substrate" }
sc-transaction-pool = { git = "https://github.com/serai-dex/substrate" }
sc-transaction-pool-api = { git = "https://github.com/serai-dex/substrate" }
sc-basic-authorship = { git = "https://github.com/serai-dex/substrate" }

View file

@ -1,14 +1,16 @@
use core::marker::PhantomData;
use sp_core::Pair as PairTrait;
use sc_service::ChainType;
use serai_runtime::{
primitives::*, tokens::primitives::ADDRESS as TOKENS_ADDRESS, WASM_BINARY, opaque::SessionKeys,
BABE_GENESIS_EPOCH_CONFIG, GenesisConfig, SystemConfig, BalancesConfig, AssetsConfig,
BABE_GENESIS_EPOCH_CONFIG, RuntimeGenesisConfig, SystemConfig, BalancesConfig, AssetsConfig,
ValidatorSetsConfig, SessionConfig, BabeConfig, GrandpaConfig, AuthorityDiscoveryConfig,
};
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;
pub type ChainSpec = sc_service::GenericChainSpec<RuntimeGenesisConfig>;
fn account_from_name(name: &'static str) -> PublicKey {
insecure_pair_from_name(name).public()
@ -18,7 +20,7 @@ fn testnet_genesis(
wasm_binary: &[u8],
validators: &[&'static str],
endowed_accounts: Vec<PublicKey>,
) -> GenesisConfig {
) -> RuntimeGenesisConfig {
let session_key = |name| {
let key = account_from_name(name);
(
@ -28,8 +30,8 @@ fn testnet_genesis(
)
};
GenesisConfig {
system: SystemConfig { code: wasm_binary.to_vec() },
RuntimeGenesisConfig {
system: SystemConfig { code: wasm_binary.to_vec(), _config: PhantomData },
balances: BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
@ -61,10 +63,14 @@ fn testnet_genesis(
participants: validators.iter().map(|name| account_from_name(name)).collect(),
},
session: SessionConfig { keys: validators.iter().map(|name| session_key(*name)).collect() },
babe: BabeConfig { authorities: vec![], epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG) },
grandpa: GrandpaConfig { authorities: vec![] },
babe: BabeConfig {
authorities: vec![],
epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG),
_config: PhantomData,
},
grandpa: GrandpaConfig { authorities: vec![], _config: PhantomData },
authority_discovery: AuthorityDiscoveryConfig { keys: vec![] },
authority_discovery: AuthorityDiscoveryConfig { keys: vec![], _config: PhantomData },
}
}

View file

@ -4,7 +4,7 @@ use serai_runtime::Block;
use sc_service::{PruningMode, PartialComponents};
use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli};
use sc_cli::SubstrateCli;
use frame_benchmarking_cli::{ExtrinsicFactory, BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use crate::{
@ -46,10 +46,6 @@ impl SubstrateCli for Cli {
_ => panic!("Unknown network ID"),
}
}
fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
&serai_runtime::VERSION
}
}
pub fn run() -> sc_cli::Result<()> {
@ -99,29 +95,7 @@ pub fn run() -> sc_cli::Result<()> {
}),
Some(Subcommand::Benchmark(cmd)) => cli.create_runner(cmd)?.sync_run(|config| match cmd {
BenchmarkCmd::Pallet(cmd) => {
use sc_executor::{NativeVersion, NativeExecutionDispatch};
use serai_runtime as runtime;
struct ExecutorDispatch;
impl NativeExecutionDispatch for ExecutorDispatch {
#[cfg(feature = "runtime-benchmarks")]
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
#[cfg(not(feature = "runtime-benchmarks"))]
type ExtendHostFunctions = ();
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
runtime::api::dispatch(method, data)
}
fn native_version() -> NativeVersion {
runtime::native_version()
}
}
cmd.run::<Block, ExecutorDispatch>(config)
}
BenchmarkCmd::Pallet(cmd) => cmd.run::<Block, ()>(config),
BenchmarkCmd::Block(cmd) => cmd.run(service::new_partial(&config)?.client),

View file

@ -12,7 +12,8 @@ use sc_network_common::sync::warp::WarpSyncParams;
use sc_network::{Event, NetworkEventStream};
use sc_service::{error::Error as ServiceError, Configuration, TaskManager, TFullClient};
use sc_client_api::BlockBackend;
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sc_client_api::{BlockBackend, Backend};
use sc_telemetry::{Telemetry, TelemetryWorker};
@ -116,17 +117,21 @@ pub fn new_partial(config: &Configuration) -> Result<PartialComponents, ServiceE
)?;
let slot_duration = babe_link.config().slot_duration();
let (import_queue, babe_handle) = sc_consensus_babe::import_queue(
babe_link.clone(),
block_import.clone(),
Some(Box::new(justification_import)),
client.clone(),
select_chain.clone(),
move |_, _| async move { Ok(create_inherent_data_providers(slot_duration)) },
&task_manager.spawn_essential_handle(),
config.prometheus_registry(),
telemetry.as_ref().map(Telemetry::handle),
)?;
let (import_queue, babe_handle) =
sc_consensus_babe::import_queue(sc_consensus_babe::ImportQueueParams {
link: babe_link.clone(),
block_import: block_import.clone(),
justification_import: Some(Box::new(justification_import)),
client: client.clone(),
select_chain: select_chain.clone(),
create_inherent_data_providers: move |_, _| async move {
Ok(create_inherent_data_providers(slot_duration))
},
spawner: &task_manager.spawn_essential_handle(),
registry: config.prometheus_registry(),
telemetry: telemetry.as_ref().map(Telemetry::handle),
offchain_tx_pool_factory: OffchainTransactionPoolFactory::new(transaction_pool.clone()),
})?;
// This can't be dropped, or BABE breaks
// We don't have anything to do with it though
// This won't grow in size, so forgetting this isn't a disastrous memleak
@ -184,11 +189,20 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
})?;
if config.offchain_worker.enabled {
sc_service::build_offchain_workers(
&config,
task_manager.spawn_handle(),
client.clone(),
network.clone(),
task_manager.spawn_handle().spawn(
"offchain-workers-runner",
"offchain-worker",
sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions {
runtime_api_provider: client.clone(),
is_validator: config.role.is_authority(),
keystore: Some(keystore_container.keystore()),
offchain_db: backend.offchain_storage(),
transaction_pool: Some(OffchainTransactionPoolFactory::new(transaction_pool.clone())),
network_provider: network.clone(),
enable_http_requests: true,
custom_extensions: |_| vec![],
})
.run(client.clone(), task_manager.spawn_handle()),
);
}
@ -238,7 +252,7 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
env: sc_basic_authorship::ProposerFactory::new(
task_manager.spawn_handle(),
client.clone(),
transaction_pool,
transaction_pool.clone(),
prometheus_registry.as_ref(),
telemetry.as_ref().map(Telemetry::handle),
),
@ -312,6 +326,7 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
voting_rule: grandpa::VotingRulesBuilder::default().build(),
prometheus_registry,
shared_voter_state,
offchain_tx_pool_factory: OffchainTransactionPoolFactory::new(transaction_pool),
})?,
);
}

View file

@ -16,14 +16,14 @@ lazy_static = { version = "1", optional = true }
zeroize = { version = "^1.5", features = ["derive"], optional = true }
serde = { version = "1", default-features = false, features = ["derive", "alloc"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
serde = { version = "1", features = ["derive"], optional = true }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
[features]
std = ["lazy_static", "zeroize", "scale/std", "scale-info/std", "serde", "sp-core/std", "sp-runtime/std"]
std = ["lazy_static", "zeroize", "scale/std", "scale-info/std", "serde/std", "sp-core/std", "sp-runtime/std"]
default = ["std"]

View file

@ -1,12 +1,11 @@
#[cfg(feature = "std")]
use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use sp_core::sr25519::Public;
pub use sp_core::sr25519::Signature;
#[cfg(feature = "std")]
@ -17,9 +16,21 @@ use sp_runtime::traits::{LookupError, Lookup, StaticLookup};
pub type PublicKey = Public;
#[derive(
Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Encode, Decode, MaxEncodedLen, TypeInfo,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
Debug,
Serialize,
Deserialize,
Encode,
Decode,
MaxEncodedLen,
TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct SeraiAddress(pub [u8; 32]);
impl SeraiAddress {
pub fn new(key: [u8; 32]) -> SeraiAddress {

View file

@ -6,10 +6,10 @@ use core::{
#[cfg(feature = "std")]
use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
/// The type used for amounts within Substrate.
// Distinct from Amount due to Substrate's requirements on this type.
@ -19,9 +19,20 @@ use serde::{Serialize, Deserialize};
pub type SubstrateAmount = u64;
/// The type used for amounts.
#[derive(
Clone, Copy, PartialEq, Eq, PartialOrd, Debug, Encode, Decode, MaxEncodedLen, TypeInfo,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Debug,
Serialize,
Deserialize,
Encode,
Decode,
MaxEncodedLen,
TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct Amount(pub SubstrateAmount);
impl Add for Amount {

View file

@ -3,16 +3,19 @@ use core::ops::{Add, Sub, Mul};
#[cfg(feature = "std")]
use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use crate::{Coin, Amount};
/// The type used for balances (a Coin and Balance).
#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[rustfmt::skip]
#[derive(
Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct Balance {
pub coin: Coin,
pub amount: Amount,

View file

@ -1,19 +1,30 @@
#[cfg(feature = "std")]
use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use sp_core::H256;
/// The type used to identify block numbers.
#[derive(
Clone, Copy, Default, PartialEq, Eq, Hash, Debug, Encode, Decode, MaxEncodedLen, TypeInfo,
Clone,
Copy,
Default,
PartialEq,
Eq,
Hash,
Debug,
Serialize,
Deserialize,
Encode,
Decode,
MaxEncodedLen,
TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct BlockNumber(pub u64);
impl From<u64> for BlockNumber {
fn from(number: u64) -> BlockNumber {
@ -26,8 +37,21 @@ impl From<u64> for BlockNumber {
// If a block exists with a hash which isn't 32-bytes, it can be hashed into a value with 32-bytes
// This would require the processor to maintain a mapping of 32-byte IDs to actual hashes, which
// would be fine
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[derive(
Clone,
Copy,
PartialEq,
Eq,
Hash,
Debug,
Serialize,
Deserialize,
Encode,
Decode,
MaxEncodedLen,
TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct BlockHash(pub [u8; 32]);
impl AsRef<[u8]> for BlockHash {

View file

@ -4,17 +4,29 @@ use std::collections::HashMap;
#[cfg(feature = "std")]
use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_core::{ConstU32, bounded::BoundedVec};
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
/// The type used to identify networks.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[derive(
Clone,
Copy,
PartialEq,
Eq,
Hash,
Debug,
Serialize,
Deserialize,
Encode,
Decode,
MaxEncodedLen,
TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub enum NetworkId {
Serai,
Bitcoin,
@ -23,8 +35,21 @@ pub enum NetworkId {
}
/// The type used to identify coins.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[derive(
Clone,
Copy,
PartialEq,
Eq,
Hash,
Debug,
Serialize,
Deserialize,
Encode,
Decode,
MaxEncodedLen,
TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub enum Coin {
Serai,
Bitcoin,
@ -55,8 +80,9 @@ impl Coin {
pub const MAX_COINS_PER_NETWORK: u32 = 8;
/// Network definition.
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(
Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
pub struct Network {
coins: BoundedVec<Coin, ConstU32<{ MAX_COINS_PER_NETWORK }>>,
}

View file

@ -5,10 +5,10 @@
#[cfg(feature = "std")]
use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use sp_core::{ConstU32, bounded::BoundedVec};
@ -32,8 +32,9 @@ pub use account::*;
// When JAMTIS arrives, it'll become 114 bytes
pub const MAX_ADDRESS_LEN: u32 = 128;
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(
Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
pub struct ExternalAddress(BoundedVec<u8, ConstU32<{ MAX_ADDRESS_LEN }>>);
#[cfg(feature = "std")]
@ -67,8 +68,9 @@ impl AsRef<[u8]> for ExternalAddress {
// Should be enough for a Uniswap v3 call
pub const MAX_DATA_LEN: u32 = 512;
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(
Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
pub struct Data(BoundedVec<u8, ConstU32<{ MAX_DATA_LEN }>>);
#[cfg(feature = "std")]

View file

@ -94,7 +94,6 @@ use opaque::SessionKeys;
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("serai"),
impl_name: create_runtime_str!("core"),
authoring_version: 1,
// TODO: 1? Do we prefer some level of compatibility or our own path?
spec_version: 100,
impl_version: 1,
@ -188,11 +187,10 @@ impl system::Config for Runtime {
type AccountId = PublicKey;
type RuntimeCall = RuntimeCall;
type Lookup = AccountLookup;
type Index = Index;
type BlockNumber = BlockNumber;
type Hash = Hash;
type Hashing = BlakeTwo256;
type Header = Header;
type Nonce = u32;
type Block = Block;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
@ -224,8 +222,8 @@ impl balances::Config for Runtime {
type Balance = SubstrateAmount;
type ReserveIdentifier = ();
type HoldIdentifier = ();
type FreezeIdentifier = ();
type RuntimeHoldReason = ();
type MaxLocks = ();
type MaxReserves = ();
@ -380,11 +378,7 @@ pub type Executive = frame_executive::Executive<
>;
construct_runtime!(
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
pub enum Runtime {
System: system,
Timestamp: timestamp,

View file

@ -13,16 +13,16 @@ rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
zeroize = { version = "^1.5", features = ["derive"], optional = true }
serde = { version = "1", default-features = false, features = ["derive", "alloc"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
serde = { version = "1", features = ["derive"], optional = true }
serai-primitives = { path = "../../primitives", default-features = false }
[dev-dependencies]
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
[features]
std = ["zeroize", "scale/std", "scale-info/std", "serde", "sp-runtime/std", "serai-primitives/std"]
std = ["zeroize", "serde/std", "scale/std", "scale-info/std", "sp-runtime/std", "serai-primitives/std"]
default = ["std"]

View file

@ -5,32 +5,37 @@
#[cfg(feature = "std")]
use zeroize::Zeroize;
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use serai_primitives::{Balance, SeraiAddress, ExternalAddress, Data, pallet_address};
pub const ADDRESS: SeraiAddress = pallet_address(b"Tokens");
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[derive(
Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct OutInstruction {
pub address: ExternalAddress,
pub data: Option<Data>,
}
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[derive(
Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct OutInstructionWithBalance {
pub instruction: OutInstruction,
pub balance: Balance,
}
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[derive(
Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Encode, Decode, MaxEncodedLen, TypeInfo,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub enum Destination {
Native(SeraiAddress),
External(OutInstruction),

View file

@ -20,6 +20,7 @@ scale-info = { version = "2", default-features = false, features = ["derive"] }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-application-crypto = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-system = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false }

View file

@ -34,10 +34,13 @@ pub mod pallet {
pub participants: Vec<T::AccountId>,
}
#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
GenesisConfig { bond: Amount(1), networks: vec![], participants: vec![] }
GenesisConfig {
bond: Amount(1),
networks: Default::default(),
participants: Default::default(),
}
}
}
@ -68,7 +71,7 @@ pub mod pallet {
}
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
let hash_set =
self.participants.iter().map(|key| key.0).collect::<hashbrown::HashSet<[u8; 32]>>();

View file

@ -14,11 +14,11 @@ rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
zeroize = { version = "^1.5", features = ["derive"], optional = true }
serde = { version = "1", features = ["derive"], optional = true }
ciphersuite = { path = "../../../crypto/ciphersuite", version = "0.3", default-features = false, features = ["alloc", "ristretto"] }
dkg = { path = "../../../crypto/dkg", version = "0.4", default-features = false }
serde = { version = "1", default-features = false, features = ["derive", "alloc"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
@ -28,5 +28,5 @@ sp-std = { git = "https://github.com/serai-dex/substrate", default-features = fa
serai-primitives = { path = "../../primitives", default-features = false }
[features]
std = ["zeroize", "serde", "ciphersuite/std", "dkg/std", "scale/std", "scale-info/std", "sp-core/std", "sp-std/std", "serai-primitives/std"]
std = ["zeroize", "ciphersuite/std", "dkg/std", "serde/std", "scale/std", "scale-info/std", "sp-core/std", "sp-std/std", "serai-primitives/std"]
default = ["std"]

View file

@ -3,13 +3,11 @@
#[cfg(feature = "std")]
use zeroize::Zeroize;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use ciphersuite::{group::GroupEncoding, Ciphersuite, Ristretto};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
use serde::{Serialize, Deserialize};
use sp_core::{ConstU32, sr25519::Public, bounded::BoundedVec};
#[cfg(not(feature = "std"))]
@ -21,13 +19,39 @@ use serai_primitives::{NetworkId, Network, Amount};
const MAX_KEY_LEN: u32 = 96;
/// The type used to identify a specific session of validators.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[derive(
Clone,
Copy,
PartialEq,
Eq,
Hash,
Debug,
Serialize,
Deserialize,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct Session(pub u32);
/// The type used to identify a specific validator set during a specific session.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Zeroize, Serialize, Deserialize))]
#[derive(
Clone,
Copy,
PartialEq,
Eq,
Hash,
Debug,
Serialize,
Deserialize,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
pub struct ValidatorSet {
pub session: Session,
pub network: NetworkId,