mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-10 13:09:24 +00:00
Compare commits
2 Commits
d2f58232c8
...
31874ceeae
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31874ceeae | ||
|
|
012b8fddae |
@@ -22,12 +22,12 @@ workspace = true
|
||||
borsh = { version = "1", default-features = false, features = ["derive", "de_strict_order"] }
|
||||
|
||||
bitvec = { version = "1", default-features = false, features = ["alloc"] }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
serde = { version = "1", default-features = false, features = ["derive"], optional = true }
|
||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"], optional = true }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false, features = ["serde"], optional = true }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false, optional = true }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false, features = ["serde"], optional = true }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false, optional = true }
|
||||
|
||||
serai-primitives = { path = "../primitives", version = "0.1", default-features = false }
|
||||
|
||||
|
||||
@@ -31,9 +31,9 @@ serde_json = { version = "1", optional = true }
|
||||
serai-abi = { path = "../abi", version = "0.1" }
|
||||
|
||||
multiaddr = { version = "0.18", optional = true }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", optional = true }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", optional = true }
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", optional = true }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", optional = true }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", optional = true }
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", optional = true }
|
||||
|
||||
async-lock = "3"
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@ workspace = true
|
||||
[dependencies]
|
||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
||||
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
serai-abi = { path = "../abi", default-features = false, features = ["substrate"] }
|
||||
serai-core-pallet = { path = "../core", default-features = false }
|
||||
@@ -29,7 +29,7 @@ serai-core-pallet = { path = "../core", default-features = false }
|
||||
[dev-dependencies]
|
||||
borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] }
|
||||
|
||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false, features = ["std"] }
|
||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false, features = ["std"] }
|
||||
|
||||
[features]
|
||||
std = [
|
||||
|
||||
@@ -20,10 +20,10 @@ borsh = { version = "1", default-features = false, features = ["derive", "de_str
|
||||
|
||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
||||
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
serai-abi = { path = "../abi", default-features = false, features = ["substrate"] }
|
||||
|
||||
|
||||
@@ -98,6 +98,13 @@ pub mod pallet {
|
||||
});
|
||||
}
|
||||
|
||||
/// The code to run on genesis.
|
||||
pub fn genesis() {
|
||||
BlocksCommitmentMerkle::<T>::new_expecting_none();
|
||||
BlockTransactionsCommitmentMerkle::<T>::new_expecting_none();
|
||||
BlockEventsCommitmentMerkle::<T>::new_expecting_none();
|
||||
}
|
||||
|
||||
/// The code to run when beginning execution of a transaction.
|
||||
///
|
||||
/// The caller MUST ensure two transactions aren't simultaneously started.
|
||||
@@ -126,6 +133,7 @@ pub mod pallet {
|
||||
/// Fetch all of Serai's events.
|
||||
///
|
||||
/// This MUST only be used for testing purposes.
|
||||
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
|
||||
pub fn events() -> Vec<serai_abi::Event>
|
||||
where
|
||||
serai_abi::Event: TryFrom<T::RuntimeEvent>,
|
||||
@@ -144,15 +152,13 @@ pub struct StartOfBlock<T: Config>(PhantomData<T>);
|
||||
impl<T: Config> frame_support::traits::PreInherents for StartOfBlock<T> {
|
||||
fn pre_inherents() {
|
||||
use frame_support::pallet_prelude::Zero;
|
||||
// `Pallet::genesis` is expected to be used for the genesis block
|
||||
assert!(!frame_system::Pallet::<T>::block_number().is_zero());
|
||||
|
||||
if frame_system::Pallet::<T>::block_number().is_zero() {
|
||||
BlocksCommitmentMerkle::<T>::new_expecting_none();
|
||||
} else {
|
||||
let parent_hash = frame_system::Pallet::<T>::parent_hash();
|
||||
Blocks::<T>::set(parent_hash, Some(()));
|
||||
let parent_hash: [u8; 32] = parent_hash.into();
|
||||
BlocksCommitmentMerkle::<T>::append(&parent_hash);
|
||||
}
|
||||
let parent_hash = frame_system::Pallet::<T>::parent_hash();
|
||||
Blocks::<T>::set(parent_hash, Some(()));
|
||||
let parent_hash: [u8; 32] = parent_hash.into();
|
||||
BlocksCommitmentMerkle::<T>::append(&parent_hash);
|
||||
|
||||
BlockTransactionsCommitmentMerkle::<T>::new_expecting_none();
|
||||
BlockEventsCommitmentMerkle::<T>::new_expecting_none();
|
||||
|
||||
@@ -21,15 +21,15 @@ workspace = true
|
||||
[dependencies]
|
||||
scale = { package = "parity-scale-codec", version = "3.6.1", default-features = false }
|
||||
|
||||
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-benchmarking = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false, optional = true }
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
frame-benchmarking = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false, optional = true }
|
||||
|
||||
coins-pallet = { package = "serai-coins-pallet", path = "../coins", default-features = false }
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ workspace = true
|
||||
[dependencies]
|
||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
||||
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
dex-pallet = { package = "serai-dex-pallet", path = "../dex", default-features = false }
|
||||
coins-pallet = { package = "serai-coins-pallet", path = "../coins", default-features = false }
|
||||
@@ -30,16 +30,16 @@ coins-pallet = { package = "serai-coins-pallet", path = "../coins", default-feat
|
||||
serai-primitives = { path = "../primitives", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
pallet-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
pallet-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
validator-sets-pallet = { package = "serai-validator-sets-pallet", path = "../validator-sets", default-features = false }
|
||||
|
||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
[features]
|
||||
std = [
|
||||
|
||||
@@ -21,11 +21,11 @@ workspace = true
|
||||
[dependencies]
|
||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
||||
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
coins-pallet = { package = "serai-coins-pallet", path = "../coins", default-features = false }
|
||||
validator-sets-pallet = { package = "serai-validator-sets-pallet", path = "../validator-sets", default-features = false }
|
||||
|
||||
@@ -21,12 +21,12 @@ workspace = true
|
||||
[dependencies]
|
||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
||||
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-application-crypto = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-application-crypto = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
dex-pallet = { package = "serai-dex-pallet", path = "../dex", default-features = false }
|
||||
coins-pallet = { package = "serai-coins-pallet", path = "../coins", default-features = false }
|
||||
|
||||
@@ -24,14 +24,14 @@ bitvec = { version = "1", default-features = false, features = ["alloc"] }
|
||||
|
||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
|
||||
|
||||
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-application-crypto = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-application-crypto = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
serai-primitives = { path = "../primitives", default-features = false }
|
||||
|
||||
@@ -42,9 +42,9 @@ genesis-liquidity-pallet = { package = "serai-genesis-liquidity-pallet", path =
|
||||
emissions-pallet = { package = "serai-emissions-pallet", path = "../emissions", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
pallet-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
pallet-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
economic-security-pallet = { package = "serai-economic-security-pallet", path = "../economic-security", default-features = false }
|
||||
|
||||
|
||||
@@ -34,19 +34,20 @@ secq256k1 = { path = "../../crypto/secq256k1" }
|
||||
|
||||
libp2p = "0.56"
|
||||
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sp-keystore = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sp-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sp-state-machine = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sp-blockchain = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sp-block-builder = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sp-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sp-keystore = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sp-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sp-state-machine = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sp-blockchain = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sp-block-builder = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sp-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
|
||||
frame-benchmarking = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
frame-benchmarking = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
|
||||
serai-abi = { path = "../abi", features = ["std", "substrate"] }
|
||||
serai-runtime = { path = "../runtime", features = ["std"] }
|
||||
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
@@ -55,24 +56,22 @@ futures-util = "0.3"
|
||||
tokio = { version = "1", features = ["sync", "rt-multi-thread"] }
|
||||
jsonrpsee = { version = "0.24", features = ["server"] }
|
||||
|
||||
sc-transaction-pool = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sc-transaction-pool-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sc-basic-authorship = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sc-executor = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sc-service = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sc-client-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sc-network = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sc-transaction-pool = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sc-transaction-pool-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sc-basic-authorship = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sc-executor = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sc-service = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sc-client-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sc-network = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
|
||||
sc-consensus = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sc-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sc-consensus-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sc-authority-discovery = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sc-consensus = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sc-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sc-consensus-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sc-authority-discovery = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
|
||||
sc-telemetry = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sc-chain-spec = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sc-cli = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
|
||||
frame-system-rpc-runtime-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
sc-telemetry = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sc-chain-spec = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
sc-cli = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
|
||||
serai-env = { path = "../../common/env" }
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
use substrate_build_script_utils::generate_cargo_keys;
|
||||
|
||||
fn main() {
|
||||
generate_cargo_keys();
|
||||
}
|
||||
@@ -1,112 +1,109 @@
|
||||
#![expect(unused_imports, dead_code, redundant_closure_call)]
|
||||
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use sp_core::Pair as PairTrait;
|
||||
|
||||
use sc_service::ChainType;
|
||||
|
||||
use ciphersuite::{group::GroupEncoding, Ciphersuite};
|
||||
use rand_core::OsRng;
|
||||
use zeroize::Zeroizing;
|
||||
use ciphersuite::{
|
||||
group::{ff::Field, GroupEncoding},
|
||||
WrappedGroup, Ciphersuite,
|
||||
};
|
||||
use embedwards25519::Embedwards25519;
|
||||
use secq256k1::Secq256k1;
|
||||
|
||||
use serai_runtime::{
|
||||
primitives::*, validator_sets::AllEmbeddedEllipticCurveKeysAtGenesis, WASM_BINARY,
|
||||
BABE_GENESIS_EPOCH_CONFIG, RuntimeGenesisConfig, SystemConfig, CoinsConfig, ValidatorSetsConfig,
|
||||
SignalsConfig, BabeConfig, GrandpaConfig, EmissionsConfig,
|
||||
use serai_abi::{
|
||||
primitives::{
|
||||
prelude::*,
|
||||
crypto::{Public, SignedEmbeddedEllipticCurveKeys},
|
||||
},
|
||||
SubstrateBlock as Block,
|
||||
};
|
||||
use serai_runtime::*;
|
||||
|
||||
pub type ChainSpec = sc_service::GenericChainSpec;
|
||||
|
||||
fn account_from_name(name: &'static str) -> PublicKey {
|
||||
insecure_pair_from_name(name).public()
|
||||
fn insecure_account_from_name(name: &'static str) -> Public {
|
||||
sp_core::sr25519::Pair::from_string(&format!("//{name}"), None).unwrap().public().into()
|
||||
}
|
||||
|
||||
fn insecure_arbitrary_public_key_from_name<C: Ciphersuite>(name: &'static str) -> Vec<u8> {
|
||||
let key = insecure_arbitrary_key_from_name::<C>(name);
|
||||
(C::generator() * key).to_bytes().as_ref().to_vec()
|
||||
fn insecure_embedded_elliptic_curve_keys(
|
||||
name: &'static str,
|
||||
) -> Vec<SignedEmbeddedEllipticCurveKeys> {
|
||||
vec![
|
||||
SignedEmbeddedEllipticCurveKeys::bitcoin(
|
||||
&mut OsRng,
|
||||
insecure_account_from_name(name),
|
||||
&Zeroizing::new(<Embedwards25519 as WrappedGroup>::F::random(&mut OsRng)),
|
||||
&Zeroizing::new(<Secq256k1 as WrappedGroup>::F::random(&mut OsRng)),
|
||||
),
|
||||
SignedEmbeddedEllipticCurveKeys::ethereum(
|
||||
&mut OsRng,
|
||||
insecure_account_from_name(name),
|
||||
&Zeroizing::new(<Embedwards25519 as WrappedGroup>::F::random(&mut OsRng)),
|
||||
&Zeroizing::new(<Secq256k1 as WrappedGroup>::F::random(&mut OsRng)),
|
||||
),
|
||||
SignedEmbeddedEllipticCurveKeys::monero(
|
||||
&mut OsRng,
|
||||
insecure_account_from_name(name),
|
||||
&Zeroizing::new(<Embedwards25519 as WrappedGroup>::F::random(&mut OsRng)),
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
fn wasm_binary() -> Vec<u8> {
|
||||
// TODO: Accept a config of runtime path
|
||||
const WASM_PATH: &str = "/runtime/serai.wasm";
|
||||
if let Ok(binary) = std::fs::read(WASM_PATH) {
|
||||
log::info!("using {WASM_PATH}");
|
||||
const DEFAULT_WASM_PATH: &str = "/runtime/serai.wasm";
|
||||
let path = serai_env::var("SERAI_WASM").unwrap_or(DEFAULT_WASM_PATH.to_string());
|
||||
if let Ok(binary) = std::fs::read(&path) {
|
||||
log::info!("using {path} for the WASM");
|
||||
return binary;
|
||||
}
|
||||
log::info!("using built-in wasm");
|
||||
WASM_BINARY.ok_or("compiled in wasm not available").unwrap().to_vec()
|
||||
}
|
||||
|
||||
/*
|
||||
fn devnet_genesis(
|
||||
validators: &[&'static str],
|
||||
endowed_accounts: Vec<PublicKey>,
|
||||
endowed_accounts: Vec<Public>,
|
||||
) -> RuntimeGenesisConfig {
|
||||
let validators = validators
|
||||
.iter()
|
||||
.map(|name| {
|
||||
(
|
||||
account_from_name(name),
|
||||
AllEmbeddedEllipticCurveKeysAtGenesis {
|
||||
embedwards25519: insecure_arbitrary_public_key_from_name::<Embedwards25519>(name)
|
||||
.try_into()
|
||||
.unwrap(),
|
||||
secq256k1: insecure_arbitrary_public_key_from_name::<Secq256k1>(name).try_into().unwrap(),
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let key_shares = NETWORKS
|
||||
.iter()
|
||||
.map(|network| match network {
|
||||
NetworkId::Serai => (NetworkId::Serai, Amount(50_000 * 10_u64.pow(8))),
|
||||
NetworkId::External(ExternalNetworkId::Bitcoin) => {
|
||||
(NetworkId::External(ExternalNetworkId::Bitcoin), Amount(1_000_000 * 10_u64.pow(8)))
|
||||
}
|
||||
NetworkId::External(ExternalNetworkId::Ethereum) => {
|
||||
(NetworkId::External(ExternalNetworkId::Ethereum), Amount(1_000_000 * 10_u64.pow(8)))
|
||||
}
|
||||
NetworkId::External(ExternalNetworkId::Monero) => {
|
||||
(NetworkId::External(ExternalNetworkId::Monero), Amount(100_000 * 10_u64.pow(8)))
|
||||
}
|
||||
})
|
||||
.map(|name| (insecure_account_from_name(name), insecure_embedded_elliptic_curve_keys(name)))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
RuntimeGenesisConfig {
|
||||
system: SystemConfig { _config: PhantomData },
|
||||
|
||||
transaction_payment: Default::default(),
|
||||
|
||||
coins: CoinsConfig {
|
||||
accounts: endowed_accounts
|
||||
.into_iter()
|
||||
.map(|a| (a, Balance { coin: Coin::Serai, amount: Amount(1 << 60) }))
|
||||
.map(|address| (address.into(), Balance { coin: Coin::Serai, amount: Amount(1 << 60) }))
|
||||
.collect(),
|
||||
_ignore: Default::default(),
|
||||
_instance: PhantomData,
|
||||
},
|
||||
|
||||
liquidity_tokens: LiquidityTokensConfig { accounts: vec![], _instance: PhantomData },
|
||||
|
||||
validator_sets: ValidatorSetsConfig {
|
||||
networks: key_shares.clone(),
|
||||
participants: validators.clone(),
|
||||
},
|
||||
emissions: EmissionsConfig {
|
||||
networks: key_shares,
|
||||
participants: validators.iter().map(|(validator, _)| *validator).collect(),
|
||||
participants: validators
|
||||
.iter()
|
||||
.map(|validator| (validator.0.into(), validator.1.clone()))
|
||||
.collect(),
|
||||
},
|
||||
signals: SignalsConfig::default(),
|
||||
babe: BabeConfig {
|
||||
authorities: validators.iter().map(|validator| ((*validator).into(), 1)).collect(),
|
||||
// We leave this empty as `serai-validator-sets-pallet` initializes the authorities
|
||||
authorities: vec![],
|
||||
epoch_config: BABE_GENESIS_EPOCH_CONFIG,
|
||||
_config: PhantomData,
|
||||
},
|
||||
grandpa: GrandpaConfig {
|
||||
authorities: validators.into_iter().map(|validator| (validator.0.into(), 1)).collect(),
|
||||
_config: PhantomData,
|
||||
},
|
||||
grandpa: GrandpaConfig { authorities: vec![], _config: PhantomData },
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
fn testnet_genesis(validators: Vec<&'static str>) -> RuntimeGenesisConfig {
|
||||
let validators = validators
|
||||
.into_iter()
|
||||
@@ -133,21 +130,16 @@ fn testnet_genesis(validators: Vec<&'static str>) -> RuntimeGenesisConfig {
|
||||
RuntimeGenesisConfig {
|
||||
system: SystemConfig { _config: PhantomData },
|
||||
|
||||
transaction_payment: Default::default(),
|
||||
|
||||
coins: CoinsConfig {
|
||||
accounts: validators
|
||||
.iter()
|
||||
.map(|a| (*a, Balance { coin: Coin::Serai, amount: Amount(5_000_000 * 10_u64.pow(8)) }))
|
||||
.collect(),
|
||||
_ignore: Default::default(),
|
||||
},
|
||||
|
||||
validator_sets: ValidatorSetsConfig {
|
||||
networks: key_shares.clone(),
|
||||
participants: validators.clone(),
|
||||
},
|
||||
emissions: EmissionsConfig { networks: key_shares, participants: validators.clone() },
|
||||
signals: SignalsConfig::default(),
|
||||
babe: BabeConfig {
|
||||
authorities: validators.iter().map(|validator| ((*validator).into(), 1)).collect(),
|
||||
@@ -212,22 +204,17 @@ pub fn development_config() -> ChainSpec {
|
||||
"devnet",
|
||||
ChainType::Development,
|
||||
"serai-devnet",
|
||||
&(move || {
|
||||
/*
|
||||
let _ = devnet_genesis(
|
||||
&["Alice"],
|
||||
vec![
|
||||
account_from_name("Alice"),
|
||||
account_from_name("Bob"),
|
||||
account_from_name("Charlie"),
|
||||
account_from_name("Dave"),
|
||||
account_from_name("Eve"),
|
||||
account_from_name("Ferdie"),
|
||||
],
|
||||
);
|
||||
*/
|
||||
todo!("TODO")
|
||||
})(),
|
||||
&devnet_genesis(
|
||||
&["Alice"],
|
||||
vec![
|
||||
insecure_account_from_name("Alice"),
|
||||
insecure_account_from_name("Bob"),
|
||||
insecure_account_from_name("Charlie"),
|
||||
insecure_account_from_name("Dave"),
|
||||
insecure_account_from_name("Eve"),
|
||||
insecure_account_from_name("Ferdie"),
|
||||
],
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -237,22 +224,17 @@ pub fn local_config() -> ChainSpec {
|
||||
"local",
|
||||
ChainType::Local,
|
||||
"serai-local",
|
||||
&(move || {
|
||||
/*
|
||||
let _ = devnet_genesis(
|
||||
&["Alice", "Bob", "Charlie", "Dave"],
|
||||
vec![
|
||||
account_from_name("Alice"),
|
||||
account_from_name("Bob"),
|
||||
account_from_name("Charlie"),
|
||||
account_from_name("Dave"),
|
||||
account_from_name("Eve"),
|
||||
account_from_name("Ferdie"),
|
||||
],
|
||||
);
|
||||
*/
|
||||
todo!("TODO")
|
||||
})(),
|
||||
&devnet_genesis(
|
||||
&["Alice", "Bob", "Charlie", "Dave"],
|
||||
vec![
|
||||
insecure_account_from_name("Alice"),
|
||||
insecure_account_from_name("Bob"),
|
||||
insecure_account_from_name("Charlie"),
|
||||
insecure_account_from_name("Dave"),
|
||||
insecure_account_from_name("Eve"),
|
||||
insecure_account_from_name("Ferdie"),
|
||||
],
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use serai_runtime::Block;
|
||||
use serai_abi::SubstrateBlock as Block;
|
||||
|
||||
use sc_service::{PruningMode, PartialComponents};
|
||||
|
||||
@@ -18,15 +18,15 @@ impl SubstrateCli for Cli {
|
||||
}
|
||||
|
||||
fn impl_version() -> String {
|
||||
env!("SUBSTRATE_CLI_IMPL_VERSION").to_string()
|
||||
String::new()
|
||||
}
|
||||
|
||||
fn description() -> String {
|
||||
env!("CARGO_PKG_DESCRIPTION").to_string()
|
||||
String::new()
|
||||
}
|
||||
|
||||
fn author() -> String {
|
||||
env!("CARGO_PKG_AUTHORS").to_string()
|
||||
String::new()
|
||||
}
|
||||
|
||||
fn support_url() -> String {
|
||||
|
||||
@@ -5,6 +5,12 @@ use sp_keystore::*;
|
||||
|
||||
pub struct Keystore(sr25519::Pair);
|
||||
|
||||
impl From<sr25519::Pair> for Keystore {
|
||||
fn from(keypair: sr25519::Pair) -> Self {
|
||||
Self(keypair)
|
||||
}
|
||||
}
|
||||
|
||||
impl Keystore {
|
||||
pub fn from_env() -> Option<Self> {
|
||||
let mut key_hex = serai_env::var("KEY")?;
|
||||
|
||||
@@ -9,20 +9,12 @@ use sp_blockchain::{Error as BlockchainError, HeaderBackend, HeaderMetadata};
|
||||
use sp_block_builder::BlockBuilder;
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
|
||||
use serai_runtime::{
|
||||
in_instructions::primitives::Shorthand,
|
||||
primitives::{ExternalNetworkId, NetworkId, PublicKey, SubstrateAmount, QuotePriceParams},
|
||||
// validator_sets::ValidatorSetsApi,
|
||||
dex::DexApi,
|
||||
Block,
|
||||
Nonce,
|
||||
SeraiRuntimeApi,
|
||||
};
|
||||
use serai_abi::{primitives::prelude::*, SubstrateBlock as Block};
|
||||
use serai_runtime::*;
|
||||
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use jsonrpsee::RpcModule;
|
||||
// use scale::Encode;
|
||||
|
||||
use sc_client_api::BlockBackend;
|
||||
use sc_transaction_pool_api::TransactionPool;
|
||||
@@ -35,50 +27,44 @@ pub struct FullDeps<C, P> {
|
||||
}
|
||||
|
||||
pub fn create_full<
|
||||
C: ProvideRuntimeApi<Block>
|
||||
+ HeaderBackend<Block>
|
||||
+ HeaderMetadata<Block, Error = BlockchainError>
|
||||
+ BlockBackend<Block>
|
||||
C: 'static
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
P: TransactionPool + 'static,
|
||||
+ ProvideRuntimeApi<Block, Api: BlockBuilder<Block> + serai_runtime::SeraiApi<Block>>
|
||||
+ HeaderBackend<Block>
|
||||
+ HeaderMetadata<Block, Error = BlockchainError>
|
||||
+ BlockBackend<Block>,
|
||||
P: 'static + TransactionPool,
|
||||
>(
|
||||
deps: FullDeps<C, P>,
|
||||
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
|
||||
where
|
||||
C::Api: frame_system_rpc_runtime_api::AccountNonceApi<Block, PublicKey, Nonce>
|
||||
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, SubstrateAmount>
|
||||
+ SeraiRuntimeApi<Block>
|
||||
+ DexApi<Block>
|
||||
+ BlockBuilder<Block>,
|
||||
{
|
||||
use substrate_frame_rpc_system::{System, SystemApiServer};
|
||||
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
|
||||
use ciphersuite::{GroupIo, WithPreferredHash};
|
||||
use ciphersuite_kp256::{k256::elliptic_curve::point::AffineCoordinates, Secp256k1};
|
||||
use dalek_ff_group::Ed25519;
|
||||
use bitcoin_serai::bitcoin;
|
||||
|
||||
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>> {
|
||||
let mut module = RpcModule::new(());
|
||||
let FullDeps { id, client, pool, authority_discovery } = deps;
|
||||
|
||||
module.merge(System::new(client.clone(), pool).into_rpc())?;
|
||||
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
|
||||
|
||||
if let Some(authority_discovery) = authority_discovery {
|
||||
let mut authority_discovery_module =
|
||||
RpcModule::new((id, client.clone(), RwLock::new(authority_discovery)));
|
||||
authority_discovery_module.register_async_method(
|
||||
"p2p_validators",
|
||||
|params, context, _ext| async move {
|
||||
let [network]: [NetworkId; 1] = params.parse()?;
|
||||
let [network]: [String; 1] = params.parse()?;
|
||||
let network = match network.to_lowercase().as_str() {
|
||||
"serai" => NetworkId::Serai,
|
||||
"bitcoin" => ExternalNetworkId::Bitcoin.into(),
|
||||
"ethereum" => ExternalNetworkId::Ethereum.into(),
|
||||
"monero" => ExternalNetworkId::Monero.into(),
|
||||
_ => Err(jsonrpsee::types::error::ErrorObjectOwned::owned(
|
||||
-1,
|
||||
"network to fetch the `p2p_validators` of was unrecognized".to_string(),
|
||||
Option::<()>::None,
|
||||
))?,
|
||||
};
|
||||
let (id, client, authority_discovery) = &*context;
|
||||
let latest_block = client.info().best_hash;
|
||||
|
||||
let validators = client.runtime_api().validators(latest_block, network).map_err(|_| {
|
||||
jsonrpsee::types::error::ErrorObjectOwned::owned(
|
||||
-1,
|
||||
-2,
|
||||
format!(
|
||||
"couldn't get validators from the latest block, which is likely a fatal bug. {}",
|
||||
"please report this at https://github.com/serai-dex/serai",
|
||||
@@ -122,6 +108,11 @@ where
|
||||
}
|
||||
|
||||
/* TODO
|
||||
use ciphersuite::{GroupIo, WithPreferredHash};
|
||||
use ciphersuite_kp256::{k256::elliptic_curve::point::AffineCoordinates, Secp256k1};
|
||||
use dalek_ff_group::Ed25519;
|
||||
use bitcoin_serai::bitcoin;
|
||||
|
||||
let mut serai_json_module = RpcModule::new(client);
|
||||
|
||||
// add network address rpc
|
||||
@@ -216,31 +207,28 @@ where
|
||||
*/
|
||||
|
||||
let mut block_bin_module = RpcModule::new(client);
|
||||
block_bin_module.register_async_method(
|
||||
"chain_getBlockBin",
|
||||
|params, client, _ext| async move {
|
||||
let [block_hash]: [String; 1] = params.parse()?;
|
||||
let Some(block_hash) = hex::decode(&block_hash).ok().and_then(|bytes| {
|
||||
<[u8; 32]>::try_from(bytes.as_slice())
|
||||
.map(<Block as sp_runtime::traits::Block>::Hash::from)
|
||||
.ok()
|
||||
}) else {
|
||||
return Err(jsonrpsee::types::error::ErrorObjectOwned::owned(
|
||||
-1,
|
||||
"requested block hash wasn't a valid hash",
|
||||
Option::<()>::None,
|
||||
));
|
||||
};
|
||||
let Some(block) = client.block(block_hash).ok().flatten() else {
|
||||
return Err(jsonrpsee::types::error::ErrorObjectOwned::owned(
|
||||
-1,
|
||||
"couldn't find requested block",
|
||||
Option::<()>::None,
|
||||
));
|
||||
};
|
||||
Ok(hex::encode(block.block.encode()))
|
||||
},
|
||||
)?;
|
||||
block_bin_module.register_async_method("serai_block", |params, client, _ext| async move {
|
||||
let [block_hash]: [String; 1] = params.parse()?;
|
||||
let Some(block_hash) = hex::decode(&block_hash).ok().and_then(|bytes| {
|
||||
<[u8; 32]>::try_from(bytes.as_slice())
|
||||
.map(<Block as sp_runtime::traits::Block>::Hash::from)
|
||||
.ok()
|
||||
}) else {
|
||||
return Err(jsonrpsee::types::error::ErrorObjectOwned::owned(
|
||||
-1,
|
||||
"requested block hash wasn't a valid hash",
|
||||
Option::<()>::None,
|
||||
));
|
||||
};
|
||||
let Some(block) = client.block(block_hash).ok().flatten() else {
|
||||
return Err(jsonrpsee::types::error::ErrorObjectOwned::owned(
|
||||
-1,
|
||||
"couldn't find requested block",
|
||||
Option::<()>::None,
|
||||
));
|
||||
};
|
||||
Ok(hex::encode(block.block.encode()))
|
||||
})?;
|
||||
module.merge(block_bin_module)?;
|
||||
|
||||
Ok(module)
|
||||
|
||||
@@ -16,7 +16,8 @@ use sc_client_api::BlockBackend;
|
||||
|
||||
use sc_telemetry::{Telemetry, TelemetryWorker};
|
||||
|
||||
use serai_runtime::{Block, RuntimeApi};
|
||||
use serai_abi::SubstrateBlock as Block;
|
||||
use serai_runtime::RuntimeApi;
|
||||
|
||||
use sc_consensus_babe::{self, SlotProportion};
|
||||
use sc_consensus_grandpa as grandpa;
|
||||
@@ -91,6 +92,11 @@ pub fn new_partial(
|
||||
let keystore: Arc<dyn sp_keystore::Keystore> =
|
||||
if let Some(keystore) = crate::keystore::Keystore::from_env() {
|
||||
Arc::new(keystore)
|
||||
} else if let Some(seed) = config.dev_key_seed.as_ref() {
|
||||
Arc::new(crate::keystore::Keystore::from(
|
||||
<sp_core::sr25519::Pair as sp_core::Pair>::from_string(seed, None)
|
||||
.expect("dev key had invalid seed"),
|
||||
))
|
||||
} else {
|
||||
keystore_container.keystore()
|
||||
};
|
||||
@@ -287,10 +293,6 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
|
||||
|
||||
let role = config.role;
|
||||
let keystore = keystore_container;
|
||||
if let Some(seed) = config.dev_key_seed.as_ref() {
|
||||
let _ =
|
||||
keystore.sr25519_generate_new(sp_core::crypto::key_types::AUTHORITY_DISCOVERY, Some(seed));
|
||||
}
|
||||
let prometheus_registry = config.prometheus_registry().cloned();
|
||||
|
||||
// TODO: Ensure we're considered as an authority is a validator of an external network
|
||||
|
||||
@@ -16,12 +16,14 @@ rustdoc-args = ["--cfg", "docsrs"]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
rand_core = { version = "0.6", default-features = false }
|
||||
|
||||
zeroize = { version = "^1.5", features = ["derive"] }
|
||||
borsh = { version = "1", default-features = false, features = ["derive", "de_strict_order"] }
|
||||
|
||||
bitvec = { version = "1", default-features = false, features = ["alloc"] }
|
||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"], optional = true }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["alloc"] }
|
||||
schnorr-signatures = { path = "../../crypto/schnorr", default-features = false }
|
||||
@@ -34,23 +36,26 @@ schnorrkel = { version = "0.11", default-features = false }
|
||||
|
||||
bech32 = { version = "0.11", default-features = false }
|
||||
|
||||
[dev-dependencies]
|
||||
rand_core = { version = "0.6", default-features = false, features = ["std"] }
|
||||
|
||||
[features]
|
||||
std = [
|
||||
"rand_core/std",
|
||||
|
||||
"zeroize/std",
|
||||
"borsh/std",
|
||||
|
||||
"bitvec/std",
|
||||
"scale?/std",
|
||||
"sp-core/std",
|
||||
|
||||
"ciphersuite/std",
|
||||
"schnorr-signatures/std",
|
||||
"dalek-ff-group/std",
|
||||
"embedwards25519/std",
|
||||
"secq256k1/std",
|
||||
"dkg/std",
|
||||
|
||||
"schnorrkel/std",
|
||||
|
||||
"bech32/std"
|
||||
]
|
||||
serde = []
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
use zeroize::Zeroize;
|
||||
use core::ops::Deref;
|
||||
|
||||
use rand_core::{RngCore, CryptoRng};
|
||||
|
||||
use zeroize::{Zeroize, Zeroizing};
|
||||
use borsh::{io, BorshSerialize, BorshDeserialize};
|
||||
|
||||
use sp_core::{ConstU32, bounded::BoundedVec};
|
||||
|
||||
use ciphersuite::{
|
||||
group::{ff::FromUniformBytes, GroupEncoding},
|
||||
group::{
|
||||
ff::{Field, PrimeField, FromUniformBytes},
|
||||
GroupEncoding,
|
||||
},
|
||||
WrappedGroup, GroupCanonicalEncoding,
|
||||
};
|
||||
use embedwards25519::Embedwards25519;
|
||||
@@ -211,9 +218,7 @@ impl SignedEmbeddedEllipticCurveKeys {
|
||||
}
|
||||
}
|
||||
|
||||
/// Verify these key(s)' signature(s), returning the key(s) if valid.
|
||||
pub fn verify(self, validator: Public) -> Option<EmbeddedEllipticCurveKeys> {
|
||||
// Sample a unified challenge
|
||||
fn transcript(&self, validator: Public) -> [u8; 64] {
|
||||
let transcript = match &self {
|
||||
Self::Bitcoin(e, s, e_sig, s_sig) => [
|
||||
[ExternalNetworkId::Bitcoin as u8].as_slice(),
|
||||
@@ -237,7 +242,12 @@ impl SignedEmbeddedEllipticCurveKeys {
|
||||
[[ExternalNetworkId::Monero as u8].as_slice(), &validator.0, e, &e_sig[.. 32]].concat()
|
||||
}
|
||||
};
|
||||
let challenge = sp_core::hashing::blake2_512(&transcript);
|
||||
sp_core::hashing::blake2_512(&transcript)
|
||||
}
|
||||
|
||||
/// Verify these key(s)' signature(s), returning the key(s) if valid.
|
||||
pub fn verify(self, validator: Public) -> Option<EmbeddedEllipticCurveKeys> {
|
||||
let challenge = self.transcript(validator);
|
||||
|
||||
// Verify the Schnorr signatures
|
||||
match &self {
|
||||
@@ -275,6 +285,137 @@ impl SignedEmbeddedEllipticCurveKeys {
|
||||
Self::Monero(e, _) => EmbeddedEllipticCurveKeys::Monero(e),
|
||||
})
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn bitcoin(
|
||||
rng: &mut (impl RngCore + CryptoRng),
|
||||
validator: Public,
|
||||
embedwards25519: &Zeroizing<<Embedwards25519 as WrappedGroup>::F>,
|
||||
secq256k1: &Zeroizing<<Secq256k1 as WrappedGroup>::F>,
|
||||
) -> Self {
|
||||
let em_public_key =
|
||||
(<Embedwards25519 as WrappedGroup>::generator() * embedwards25519.deref()).to_bytes();
|
||||
let em_nonce = Zeroizing::new(<Embedwards25519 as WrappedGroup>::F::random(&mut *rng));
|
||||
let em_nonce_commitment = <Embedwards25519 as WrappedGroup>::generator() * em_nonce.deref();
|
||||
let mut em_sig = [0; 64];
|
||||
em_sig[.. 32].copy_from_slice(em_nonce_commitment.to_bytes().as_ref());
|
||||
|
||||
let secq_public_key = (<Secq256k1 as WrappedGroup>::generator() * secq256k1.deref()).to_bytes();
|
||||
let secq_nonce = Zeroizing::new(<Secq256k1 as WrappedGroup>::F::random(&mut *rng));
|
||||
let secq_nonce_commitment = <Secq256k1 as WrappedGroup>::generator() * secq_nonce.deref();
|
||||
let mut secq_sig = [0; 65];
|
||||
secq_sig[.. 33].copy_from_slice(secq_nonce_commitment.to_bytes().as_ref());
|
||||
|
||||
let challenge =
|
||||
SignedEmbeddedEllipticCurveKeys::Bitcoin(em_public_key, secq_public_key, em_sig, secq_sig)
|
||||
.transcript(validator);
|
||||
|
||||
em_sig[32 ..].copy_from_slice(
|
||||
SchnorrSignature::<Embedwards25519>::sign(
|
||||
embedwards25519,
|
||||
em_nonce,
|
||||
<<Embedwards25519 as WrappedGroup>::F as FromUniformBytes<_>>::from_uniform_bytes(
|
||||
&challenge,
|
||||
),
|
||||
)
|
||||
.s
|
||||
.to_repr()
|
||||
.as_ref(),
|
||||
);
|
||||
|
||||
secq_sig[33 ..].copy_from_slice(
|
||||
SchnorrSignature::<Secq256k1>::sign(
|
||||
secq256k1,
|
||||
secq_nonce,
|
||||
<<Secq256k1 as WrappedGroup>::F as FromUniformBytes<_>>::from_uniform_bytes(&challenge),
|
||||
)
|
||||
.s
|
||||
.to_repr()
|
||||
.as_ref(),
|
||||
);
|
||||
|
||||
SignedEmbeddedEllipticCurveKeys::Bitcoin(em_public_key, secq_public_key, em_sig, secq_sig)
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn ethereum(
|
||||
rng: &mut (impl RngCore + CryptoRng),
|
||||
validator: Public,
|
||||
embedwards25519: &Zeroizing<<Embedwards25519 as WrappedGroup>::F>,
|
||||
secq256k1: &Zeroizing<<Secq256k1 as WrappedGroup>::F>,
|
||||
) -> Self {
|
||||
let em_public_key =
|
||||
(<Embedwards25519 as WrappedGroup>::generator() * embedwards25519.deref()).to_bytes();
|
||||
let em_nonce = Zeroizing::new(<Embedwards25519 as WrappedGroup>::F::random(&mut *rng));
|
||||
let em_nonce_commitment = <Embedwards25519 as WrappedGroup>::generator() * em_nonce.deref();
|
||||
let mut em_sig = [0; 64];
|
||||
em_sig[.. 32].copy_from_slice(em_nonce_commitment.to_bytes().as_ref());
|
||||
|
||||
let secq_public_key = (<Secq256k1 as WrappedGroup>::generator() * secq256k1.deref()).to_bytes();
|
||||
let secq_nonce = Zeroizing::new(<Secq256k1 as WrappedGroup>::F::random(&mut *rng));
|
||||
let secq_nonce_commitment = <Secq256k1 as WrappedGroup>::generator() * secq_nonce.deref();
|
||||
let mut secq_sig = [0; 65];
|
||||
secq_sig[.. 33].copy_from_slice(secq_nonce_commitment.to_bytes().as_ref());
|
||||
|
||||
let challenge =
|
||||
SignedEmbeddedEllipticCurveKeys::Ethereum(em_public_key, secq_public_key, em_sig, secq_sig)
|
||||
.transcript(validator);
|
||||
|
||||
em_sig[32 ..].copy_from_slice(
|
||||
SchnorrSignature::<Embedwards25519>::sign(
|
||||
embedwards25519,
|
||||
em_nonce,
|
||||
<<Embedwards25519 as WrappedGroup>::F as FromUniformBytes<_>>::from_uniform_bytes(
|
||||
&challenge,
|
||||
),
|
||||
)
|
||||
.s
|
||||
.to_repr()
|
||||
.as_ref(),
|
||||
);
|
||||
|
||||
secq_sig[33 ..].copy_from_slice(
|
||||
SchnorrSignature::<Secq256k1>::sign(
|
||||
secq256k1,
|
||||
secq_nonce,
|
||||
<<Secq256k1 as WrappedGroup>::F as FromUniformBytes<_>>::from_uniform_bytes(&challenge),
|
||||
)
|
||||
.s
|
||||
.to_repr()
|
||||
.as_ref(),
|
||||
);
|
||||
|
||||
SignedEmbeddedEllipticCurveKeys::Ethereum(em_public_key, secq_public_key, em_sig, secq_sig)
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn monero(
|
||||
rng: &mut (impl RngCore + CryptoRng),
|
||||
validator: Public,
|
||||
embedwards25519: &Zeroizing<<Embedwards25519 as WrappedGroup>::F>,
|
||||
) -> Self {
|
||||
let em_public_key =
|
||||
(<Embedwards25519 as WrappedGroup>::generator() * embedwards25519.deref()).to_bytes();
|
||||
let em_nonce = Zeroizing::new(<Embedwards25519 as WrappedGroup>::F::random(&mut *rng));
|
||||
let em_nonce_commitment = <Embedwards25519 as WrappedGroup>::generator() * em_nonce.deref();
|
||||
let mut em_sig = [0; 64];
|
||||
em_sig[.. 32].copy_from_slice(em_nonce_commitment.to_bytes().as_ref());
|
||||
let challenge =
|
||||
SignedEmbeddedEllipticCurveKeys::Monero(em_public_key, em_sig).transcript(validator);
|
||||
em_sig[32 ..].copy_from_slice(
|
||||
SchnorrSignature::<Embedwards25519>::sign(
|
||||
embedwards25519,
|
||||
em_nonce,
|
||||
<<Embedwards25519 as WrappedGroup>::F as FromUniformBytes<_>>::from_uniform_bytes(
|
||||
&challenge,
|
||||
),
|
||||
)
|
||||
.s
|
||||
.to_repr()
|
||||
.as_ref(),
|
||||
);
|
||||
SignedEmbeddedEllipticCurveKeys::Monero(em_public_key, em_sig)
|
||||
}
|
||||
}
|
||||
|
||||
impl BorshSerialize for SignedEmbeddedEllipticCurveKeys {
|
||||
|
||||
@@ -20,22 +20,28 @@ workspace = true
|
||||
[dependencies]
|
||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
||||
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-version = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-inherents = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-version = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-consensus-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-block-builder = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-transaction-pool = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-authority-discovery = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
serai-abi = { path = "../abi", default-features = false, features = ["substrate"] }
|
||||
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-executive = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
frame-executive = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
pallet-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
pallet-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
pallet-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
pallet-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
serai-core-pallet = { path = "../core", default-features = false }
|
||||
serai-coins-pallet = { path = "../coins", default-features = false }
|
||||
@@ -43,7 +49,7 @@ serai-validator-sets-pallet = { path = "../validator-sets", default-features = f
|
||||
serai-signals-pallet = { path = "../signals", default-features = false }
|
||||
|
||||
[build-dependencies]
|
||||
substrate-wasm-builder = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4" }
|
||||
substrate-wasm-builder = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef" }
|
||||
|
||||
[features]
|
||||
std = [
|
||||
@@ -54,6 +60,11 @@ std = [
|
||||
"sp-version/std",
|
||||
"sp-runtime/std",
|
||||
"sp-api/std",
|
||||
"sp-consensus-babe/std",
|
||||
"sp-consensus-grandpa/std",
|
||||
"sp-block-builder/std",
|
||||
"sp-transaction-pool/std",
|
||||
"sp-authority-discovery/std",
|
||||
|
||||
"serai-abi/std",
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
use alloc::borrow::Cow;
|
||||
use alloc::{borrow::Cow, vec::Vec};
|
||||
|
||||
use sp_core::{ConstU32, ConstU64, sr25519::Public};
|
||||
use sp_runtime::{Perbill, Weight};
|
||||
@@ -16,6 +16,7 @@ use serai_abi::{
|
||||
primitives::{
|
||||
network_id::{ExternalNetworkId, NetworkId},
|
||||
balance::{Amount, ExternalBalance},
|
||||
validator_sets::ValidatorSet,
|
||||
address::SeraiAddress,
|
||||
},
|
||||
SubstrateHeader as Header, SubstrateBlock,
|
||||
@@ -56,12 +57,18 @@ frame_support::parameter_types! {
|
||||
|
||||
// TODO
|
||||
pub BlockLength: frame_system::limits::BlockLength =
|
||||
frame_system::limits::BlockLength::max_with_normal_ratio(0, Perbill::from_percent(0));
|
||||
frame_system::limits::BlockLength::max_with_normal_ratio(
|
||||
100 * 1024,
|
||||
Perbill::from_percent(75),
|
||||
);
|
||||
// TODO
|
||||
pub BlockWeights: frame_system::limits::BlockWeights =
|
||||
frame_system::limits::BlockWeights::with_sensible_defaults(
|
||||
Weight::from_parts(0, 0),
|
||||
Perbill::from_percent(0),
|
||||
Weight::from_parts(
|
||||
2u64 * frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND,
|
||||
u64::MAX,
|
||||
),
|
||||
Perbill::from_percent(75),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -160,7 +167,7 @@ impl serai_validator_sets_pallet::Config for Runtime {
|
||||
}
|
||||
impl serai_signals_pallet::Config for Runtime {
|
||||
type RetirementValidityDuration = ConstU64<0>; // TODO
|
||||
type RetirementLockInDuration = ConstU64<0>; // TODO
|
||||
type RetirementLockInDuration = ConstU64<1>; // TODO
|
||||
}
|
||||
impl serai_coins_pallet::Config<LiquidityTokensInstance> for Runtime {
|
||||
type AllowMint = serai_coins_pallet::AlwaysAllowMint;
|
||||
@@ -176,7 +183,8 @@ impl serai_coins_pallet::Config<LiquidityTokensInstance> for Runtime {
|
||||
impl pallet_timestamp::Config for Runtime {
|
||||
type Moment = u64;
|
||||
type OnTimestampSet = Babe;
|
||||
type MinimumPeriod = ConstU64<0>; // TODO
|
||||
// TODO
|
||||
type MinimumPeriod = ConstU64<{ (6 * 1000) / 2 }>;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
@@ -196,9 +204,10 @@ impl pallet_session::Config for Runtime {
|
||||
type MaxAuthorities =
|
||||
ConstU32<{ serai_abi::primitives::validator_sets::KeyShares::MAX_PER_SET_U32 }>;
|
||||
impl pallet_babe::Config for Runtime {
|
||||
type EpochDuration = ConstU64<0>; // TODO
|
||||
// TODO
|
||||
type EpochDuration = ConstU64<{ (7 * 24 * 60 * 60 * 1000) / (6 * 1000) }>;
|
||||
|
||||
type ExpectedBlockTime = ConstU64<0>; // TODO
|
||||
type ExpectedBlockTime = ConstU64<{ 6 * 1000 }>; // TODO
|
||||
type EpochChangeTrigger = pallet_babe::ExternalTrigger;
|
||||
|
||||
type WeightInfo = ();
|
||||
@@ -319,7 +328,37 @@ impl From<serai_abi::Call> for RuntimeCall {
|
||||
|
||||
type Executive = frame_executive::Executive<Runtime, Block, Context, Runtime, AllPalletsWithSystem>;
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
#[api_version(1)]
|
||||
pub trait GenesisApi {
|
||||
fn build(genesis: RuntimeGenesisConfig);
|
||||
}
|
||||
#[api_version(1)]
|
||||
pub trait SeraiApi {
|
||||
fn validators(network_id: NetworkId) -> Vec<Public>;
|
||||
}
|
||||
}
|
||||
|
||||
const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
|
||||
pub const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration =
|
||||
sp_consensus_babe::BabeEpochConfiguration {
|
||||
c: PRIMARY_PROBABILITY,
|
||||
allowed_slots: sp_consensus_babe::AllowedSlots::PrimaryAndSecondaryPlainSlots,
|
||||
};
|
||||
|
||||
sp_api::impl_runtime_apis! {
|
||||
impl crate::GenesisApi<Block> for Runtime {
|
||||
fn build(genesis: RuntimeGenesisConfig) {
|
||||
Core::genesis();
|
||||
Core::start_transaction();
|
||||
<RuntimeGenesisConfig as frame_support::traits::BuildGenesisConfig>::build(&genesis);
|
||||
Core::end_transaction([0; 32]);
|
||||
<
|
||||
serai_core_pallet::EndOfBlock<Runtime> as frame_support::traits::PostTransactions
|
||||
>::post_transactions();
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_api::Core<Block> for Runtime {
|
||||
fn version() -> RuntimeVersion {
|
||||
VERSION
|
||||
@@ -331,6 +370,148 @@ sp_api::impl_runtime_apis! {
|
||||
Executive::execute_block(block);
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_block_builder::BlockBuilder<Block> for Runtime {
|
||||
fn apply_extrinsic(
|
||||
extrinsic: <Block as sp_runtime::traits::Block>::Extrinsic,
|
||||
) -> sp_runtime::ApplyExtrinsicResult {
|
||||
Executive::apply_extrinsic(extrinsic)
|
||||
}
|
||||
|
||||
fn finalize_block() -> Header {
|
||||
Executive::finalize_block()
|
||||
}
|
||||
|
||||
fn inherent_extrinsics(
|
||||
data: sp_inherents::InherentData,
|
||||
) -> Vec<<Block as sp_runtime::traits::Block>::Extrinsic> {
|
||||
data.create_extrinsics()
|
||||
}
|
||||
|
||||
fn check_inherents(
|
||||
block: Block,
|
||||
data: sp_inherents::InherentData,
|
||||
) -> sp_inherents::CheckInherentsResult {
|
||||
data.check_extrinsics(&block)
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
|
||||
fn validate_transaction(
|
||||
source: sp_runtime::transaction_validity::TransactionSource,
|
||||
tx: <Block as sp_runtime::traits::Block>::Extrinsic,
|
||||
block_hash: <Block as sp_runtime::traits::Block>::Hash,
|
||||
) -> sp_runtime::transaction_validity::TransactionValidity {
|
||||
Executive::validate_transaction(source, tx, block_hash)
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_consensus_babe::BabeApi<Block> for Runtime {
|
||||
fn configuration() -> sp_consensus_babe::BabeConfiguration {
|
||||
use frame_support::traits::Get;
|
||||
|
||||
let epoch_config = Babe::epoch_config().unwrap_or(BABE_GENESIS_EPOCH_CONFIG);
|
||||
sp_consensus_babe::BabeConfiguration {
|
||||
slot_duration: Babe::slot_duration(),
|
||||
epoch_length: <Runtime as pallet_babe::Config>::EpochDuration::get(),
|
||||
c: epoch_config.c,
|
||||
authorities: Babe::authorities().to_vec(),
|
||||
randomness: Babe::randomness(),
|
||||
allowed_slots: epoch_config.allowed_slots,
|
||||
}
|
||||
}
|
||||
|
||||
fn current_epoch_start() -> sp_consensus_babe::Slot {
|
||||
Babe::current_epoch_start()
|
||||
}
|
||||
|
||||
fn current_epoch() -> sp_consensus_babe::Epoch {
|
||||
Babe::current_epoch()
|
||||
}
|
||||
|
||||
fn next_epoch() -> sp_consensus_babe::Epoch {
|
||||
Babe::next_epoch()
|
||||
}
|
||||
|
||||
// TODO: Revisit
|
||||
fn generate_key_ownership_proof(
|
||||
_slot: sp_consensus_babe::Slot,
|
||||
_authority_id: pallet_babe::AuthorityId,
|
||||
) -> Option<sp_consensus_babe::OpaqueKeyOwnershipProof> {
|
||||
None
|
||||
}
|
||||
|
||||
// TODO: Revisit
|
||||
fn submit_report_equivocation_unsigned_extrinsic(
|
||||
equivocation_proof: sp_consensus_babe::EquivocationProof<Header>,
|
||||
_: sp_consensus_babe::OpaqueKeyOwnershipProof,
|
||||
) -> Option<()> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_consensus_grandpa::GrandpaApi<Block> for Runtime {
|
||||
fn grandpa_authorities() -> sp_consensus_grandpa::AuthorityList {
|
||||
Grandpa::grandpa_authorities()
|
||||
}
|
||||
|
||||
fn current_set_id() -> sp_consensus_grandpa::SetId {
|
||||
Grandpa::current_set_id()
|
||||
}
|
||||
|
||||
// TODO: Revisit
|
||||
fn generate_key_ownership_proof(
|
||||
_set_id: sp_consensus_grandpa::SetId,
|
||||
_authority_id: pallet_grandpa::AuthorityId,
|
||||
) -> Option<sp_consensus_grandpa::OpaqueKeyOwnershipProof> {
|
||||
None
|
||||
}
|
||||
|
||||
// TODO: Revisit
|
||||
fn submit_report_equivocation_unsigned_extrinsic(
|
||||
equivocation_proof: sp_consensus_grandpa::EquivocationProof<
|
||||
<Block as sp_runtime::traits::Block>::Hash,
|
||||
u64,
|
||||
>,
|
||||
_: sp_consensus_grandpa::OpaqueKeyOwnershipProof,
|
||||
) -> Option<()> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_authority_discovery::AuthorityDiscoveryApi<Block> for Runtime {
|
||||
fn authorities() -> Vec<sp_authority_discovery::AuthorityId> {
|
||||
// Converts to `[u8; 32]` so it can be hashed
|
||||
let mut all = alloc::collections::BTreeSet::<[u8; 32]>::new();
|
||||
for network in NetworkId::all() {
|
||||
for participant in
|
||||
<Self as crate::runtime_decl_for_serai_api::SeraiApi<Block>>::validators(network) {
|
||||
all.insert(participant.into());
|
||||
}
|
||||
}
|
||||
all
|
||||
.into_iter()
|
||||
.map(|id| sp_authority_discovery::AuthorityId::from(sp_core::sr25519::Public::from(id)))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::SeraiApi<Block> for Runtime {
|
||||
fn validators(network: NetworkId) -> Vec<Public> {
|
||||
// Returning the latest-decided, not latest and active, means the active set
|
||||
// may fail to peer find if there isn't sufficient overlap. If a large amount reboot,
|
||||
// forcing some validators to successfully peer find in order for the threshold to become
|
||||
// online again, this may cause a liveness failure.
|
||||
//
|
||||
// This is assumed not to matter in real life, yet an interesting note.
|
||||
let Some(session) = ValidatorSets::latest_decided_session(network) else {
|
||||
return alloc::vec![]
|
||||
};
|
||||
ValidatorSets::selected_validators(ValidatorSet { network, session })
|
||||
.map(|validator| validator.0)
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, PartialEq, Eq, Debug)]
|
||||
@@ -406,96 +587,8 @@ impl serai_abi::TransactionContext for Context {
|
||||
}
|
||||
|
||||
/* TODO
|
||||
use core::marker::PhantomData;
|
||||
|
||||
// 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;
|
||||
|
||||
pub use pallet_timestamp as timestamp;
|
||||
|
||||
pub use pallet_transaction_payment as transaction_payment;
|
||||
|
||||
pub use coins_pallet as coins;
|
||||
pub use dex_pallet as dex;
|
||||
|
||||
pub use validator_sets_pallet as validator_sets;
|
||||
|
||||
pub use in_instructions_pallet as in_instructions;
|
||||
|
||||
pub use signals_pallet as signals;
|
||||
|
||||
pub use genesis_liquidity_pallet as genesis_liquidity;
|
||||
pub use emissions_pallet as emissions;
|
||||
|
||||
pub use economic_security_pallet as economic_security;
|
||||
|
||||
// Actually used by the runtime
|
||||
use sp_core::OpaqueMetadata;
|
||||
use sp_std::prelude::*;
|
||||
|
||||
use sp_version::RuntimeVersion;
|
||||
#[cfg(feature = "std")]
|
||||
use sp_version::NativeVersion;
|
||||
|
||||
use sp_runtime::{
|
||||
create_runtime_str, generic, impl_opaque_keys, KeyTypeId,
|
||||
traits::{Convert, BlakeTwo256, Block as BlockT},
|
||||
transaction_validity::{TransactionSource, TransactionValidity},
|
||||
BoundedVec, Perbill, ApplyExtrinsicResult,
|
||||
};
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use primitives::{
|
||||
NetworkId, ExternalNetworkId, PublicKey, AccountLookup, SubstrateAmount, Coin, EXTERNAL_NETWORKS,
|
||||
MEDIAN_PRICE_WINDOW_LENGTH, HOURS, DAYS, MINUTES, TARGET_BLOCK_TIME, BLOCK_SIZE,
|
||||
FAST_EPOCH_DURATION,
|
||||
};
|
||||
|
||||
use support::{
|
||||
traits::{ConstU8, ConstU16, ConstU32, ConstU64, Contains},
|
||||
weights::{
|
||||
constants::{RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND},
|
||||
IdentityFee, Weight,
|
||||
},
|
||||
parameter_types, construct_runtime,
|
||||
};
|
||||
|
||||
use validator_sets::MembershipProof;
|
||||
|
||||
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
|
||||
use babe::AuthorityId as BabeId;
|
||||
use grandpa::AuthorityId as GrandpaId;
|
||||
|
||||
/// A hash of some data used by the chain.
|
||||
pub type Hash = sp_core::H256;
|
||||
|
||||
pub type SignedExtra = (
|
||||
system::CheckNonZeroSender<Runtime>,
|
||||
system::CheckWeight<Runtime>, TODO
|
||||
);
|
||||
|
||||
pub mod opaque {
|
||||
use super::*;
|
||||
|
||||
impl_opaque_keys! {
|
||||
pub struct SessionKeys {
|
||||
pub babe: Babe,
|
||||
pub grandpa: Grandpa,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
|
||||
pub const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration =
|
||||
sp_consensus_babe::BabeEpochConfiguration {
|
||||
c: PRIMARY_PROBABILITY,
|
||||
allowed_slots: sp_consensus_babe::AllowedSlots::PrimaryAndSecondaryPlainSlots,
|
||||
};
|
||||
|
||||
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
|
||||
|
||||
parameter_types! {
|
||||
@@ -589,33 +682,6 @@ impl pallet_authorship::Config for Runtime {
|
||||
/// Longevity of an offence report.
|
||||
pub type ReportLongevity = <Runtime as pallet_babe::Config>::EpochDuration;
|
||||
|
||||
construct_runtime!(
|
||||
pub enum Runtime {
|
||||
System: system exclude_parts { Call },
|
||||
|
||||
Timestamp: timestamp,
|
||||
|
||||
TransactionPayment: transaction_payment,
|
||||
|
||||
Coins: coins,
|
||||
LiquidityTokens: coins::<Instance1>::{Pallet, Call, Storage, Event<T>},
|
||||
Dex: dex,
|
||||
|
||||
ValidatorSets: validator_sets,
|
||||
GenesisLiquidity: genesis_liquidity,
|
||||
Emissions: emissions,
|
||||
|
||||
EconomicSecurity: economic_security,
|
||||
|
||||
InInstructions: in_instructions,
|
||||
|
||||
Signals: signals,
|
||||
|
||||
Babe: babe,
|
||||
Grandpa: grandpa,
|
||||
}
|
||||
);
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
#[macro_use]
|
||||
extern crate frame_benchmarking;
|
||||
@@ -637,229 +703,7 @@ mod benches {
|
||||
}
|
||||
|
||||
sp_api::impl_runtime_apis! {
|
||||
impl sp_api::Core<Block> for Runtime {
|
||||
fn version() -> RuntimeVersion {
|
||||
VERSION
|
||||
}
|
||||
|
||||
fn execute_block(block: Block) {
|
||||
Executive::execute_block(block);
|
||||
}
|
||||
|
||||
fn initialize_block(header: &Header) {
|
||||
Executive::initialize_block(header)
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_api::Metadata<Block> for Runtime {
|
||||
fn metadata() -> OpaqueMetadata {
|
||||
OpaqueMetadata::new(Runtime::metadata().into())
|
||||
}
|
||||
|
||||
fn metadata_at_version(version: u32) -> Option<OpaqueMetadata> {
|
||||
Runtime::metadata_at_version(version)
|
||||
}
|
||||
|
||||
fn metadata_versions() -> sp_std::vec::Vec<u32> {
|
||||
Runtime::metadata_versions()
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_block_builder::BlockBuilder<Block> for Runtime {
|
||||
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
|
||||
Executive::apply_extrinsic(extrinsic)
|
||||
}
|
||||
|
||||
fn finalize_block() -> Header {
|
||||
Executive::finalize_block()
|
||||
}
|
||||
|
||||
fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {
|
||||
data.create_extrinsics()
|
||||
}
|
||||
|
||||
fn check_inherents(
|
||||
block: Block,
|
||||
data: sp_inherents::InherentData,
|
||||
) -> sp_inherents::CheckInherentsResult {
|
||||
data.check_extrinsics(&block)
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
|
||||
fn validate_transaction(
|
||||
source: TransactionSource,
|
||||
tx: <Block as BlockT>::Extrinsic,
|
||||
block_hash: <Block as BlockT>::Hash,
|
||||
) -> TransactionValidity {
|
||||
Executive::validate_transaction(source, tx, block_hash)
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
|
||||
fn offchain_worker(header: &Header) {
|
||||
Executive::offchain_worker(header)
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_session::SessionKeys<Block> for Runtime {
|
||||
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
|
||||
opaque::SessionKeys::generate(seed)
|
||||
}
|
||||
|
||||
fn decode_session_keys(
|
||||
encoded: Vec<u8>,
|
||||
) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {
|
||||
opaque::SessionKeys::decode_into_raw_public_keys(&encoded)
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_consensus_babe::BabeApi<Block> for Runtime {
|
||||
fn configuration() -> sp_consensus_babe::BabeConfiguration {
|
||||
use support::traits::Get;
|
||||
|
||||
let epoch_config = Babe::epoch_config().unwrap_or(BABE_GENESIS_EPOCH_CONFIG);
|
||||
sp_consensus_babe::BabeConfiguration {
|
||||
slot_duration: Babe::slot_duration(),
|
||||
epoch_length: <Runtime as babe::Config>::EpochDuration::get(),
|
||||
c: epoch_config.c,
|
||||
authorities: Babe::authorities().to_vec(),
|
||||
randomness: Babe::randomness(),
|
||||
allowed_slots: epoch_config.allowed_slots,
|
||||
}
|
||||
}
|
||||
|
||||
fn current_epoch_start() -> sp_consensus_babe::Slot {
|
||||
Babe::current_epoch_start()
|
||||
}
|
||||
|
||||
fn current_epoch() -> sp_consensus_babe::Epoch {
|
||||
Babe::current_epoch()
|
||||
}
|
||||
|
||||
fn next_epoch() -> sp_consensus_babe::Epoch {
|
||||
Babe::next_epoch()
|
||||
}
|
||||
|
||||
// This refers to a key being 'owned' by an authority in a system with multiple keys per
|
||||
// validator
|
||||
// Since we do not have such an infrastructure, we do not need this
|
||||
fn generate_key_ownership_proof(
|
||||
_slot: sp_consensus_babe::Slot,
|
||||
_authority_id: BabeId,
|
||||
) -> Option<sp_consensus_babe::OpaqueKeyOwnershipProof> {
|
||||
Some(sp_consensus_babe::OpaqueKeyOwnershipProof::new(vec![]))
|
||||
}
|
||||
|
||||
fn submit_report_equivocation_unsigned_extrinsic(
|
||||
equivocation_proof: sp_consensus_babe::EquivocationProof<Header>,
|
||||
_: sp_consensus_babe::OpaqueKeyOwnershipProof,
|
||||
) -> Option<()> {
|
||||
let proof = MembershipProof(equivocation_proof.offender.clone().into(), PhantomData);
|
||||
Babe::submit_unsigned_equivocation_report(equivocation_proof, proof)
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_consensus_grandpa::GrandpaApi<Block> for Runtime {
|
||||
fn grandpa_authorities() -> sp_consensus_grandpa::AuthorityList {
|
||||
Grandpa::grandpa_authorities()
|
||||
}
|
||||
|
||||
fn current_set_id() -> sp_consensus_grandpa::SetId {
|
||||
Grandpa::current_set_id()
|
||||
}
|
||||
|
||||
fn generate_key_ownership_proof(
|
||||
_set_id: sp_consensus_grandpa::SetId,
|
||||
_authority_id: GrandpaId,
|
||||
) -> Option<sp_consensus_grandpa::OpaqueKeyOwnershipProof> {
|
||||
Some(sp_consensus_grandpa::OpaqueKeyOwnershipProof::new(vec![]))
|
||||
}
|
||||
|
||||
fn submit_report_equivocation_unsigned_extrinsic(
|
||||
equivocation_proof: sp_consensus_grandpa::EquivocationProof<<Block as BlockT>::Hash, u64>,
|
||||
_: sp_consensus_grandpa::OpaqueKeyOwnershipProof,
|
||||
) -> Option<()> {
|
||||
let proof = MembershipProof(equivocation_proof.offender().clone().into(), PhantomData);
|
||||
Grandpa::submit_unsigned_equivocation_report(equivocation_proof, proof)
|
||||
}
|
||||
}
|
||||
|
||||
impl frame_system_rpc_runtime_api::AccountNonceApi<Block, PublicKey, Nonce> for Runtime {
|
||||
fn account_nonce(account: PublicKey) -> Nonce {
|
||||
System::account_nonce(account)
|
||||
}
|
||||
}
|
||||
|
||||
impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<
|
||||
Block,
|
||||
SubstrateAmount
|
||||
> for Runtime {
|
||||
fn query_info(
|
||||
uxt: <Block as BlockT>::Extrinsic,
|
||||
len: u32,
|
||||
) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<SubstrateAmount> {
|
||||
TransactionPayment::query_info(uxt, len)
|
||||
}
|
||||
|
||||
fn query_fee_details(
|
||||
uxt: <Block as BlockT>::Extrinsic,
|
||||
len: u32,
|
||||
) -> transaction_payment::FeeDetails<SubstrateAmount> {
|
||||
TransactionPayment::query_fee_details(uxt, len)
|
||||
}
|
||||
|
||||
fn query_weight_to_fee(weight: Weight) -> SubstrateAmount {
|
||||
TransactionPayment::weight_to_fee(weight)
|
||||
}
|
||||
|
||||
fn query_length_to_fee(length: u32) -> SubstrateAmount {
|
||||
TransactionPayment::length_to_fee(length)
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_authority_discovery::AuthorityDiscoveryApi<Block> for Runtime {
|
||||
fn authorities() -> Vec<AuthorityDiscoveryId> {
|
||||
// Converts to `[u8; 32]` so it can be hashed
|
||||
let serai_validators = Babe::authorities()
|
||||
.into_iter()
|
||||
.map(|(id, _)| id.into_inner().0)
|
||||
.collect::<hashbrown::HashSet<_>>();
|
||||
let mut all = serai_validators;
|
||||
for network in EXTERNAL_NETWORKS {
|
||||
// Returning the latest-decided, not latest and active, means the active set
|
||||
// may fail to peer find if there isn't sufficient overlap. If a large amount reboot,
|
||||
// forcing some validators to successfully peer find in order for the threshold to become
|
||||
// online again, this may cause a liveness failure.
|
||||
//
|
||||
// This is assumed not to matter in real life, yet an interesting note.
|
||||
let participants =
|
||||
ValidatorSets::participants_for_latest_decided_set(NetworkId::from(network))
|
||||
.map_or(vec![], BoundedVec::into_inner);
|
||||
for (participant, _) in participants {
|
||||
all.insert(participant.0);
|
||||
}
|
||||
}
|
||||
all.into_iter().map(|id| AuthorityDiscoveryId::from(PublicKey::from_raw(id))).collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl validator_sets::ValidatorSetsApi<Block> for Runtime {
|
||||
fn validators(network_id: NetworkId) -> Vec<PublicKey> {
|
||||
if network_id == NetworkId::Serai {
|
||||
Babe::authorities()
|
||||
.into_iter()
|
||||
.map(|(id, _)| id.into_inner())
|
||||
.collect()
|
||||
} else {
|
||||
ValidatorSets::participants_for_latest_decided_set(network_id)
|
||||
.map_or(
|
||||
vec![],
|
||||
|vec| vec.into_inner().into_iter().map(|(validator, _)| validator).collect()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn external_network_key(network: ExternalNetworkId) -> Option<Vec<u8>> {
|
||||
ValidatorSets::external_network_key(network)
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ workspace = true
|
||||
[dependencies]
|
||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
||||
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
serai-abi = { path = "../abi", default-features = false, features = ["substrate"] }
|
||||
|
||||
|
||||
@@ -20,17 +20,17 @@ bitvec = { version = "1", default-features = false, features = ["alloc", "serde"
|
||||
|
||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "bit-vec"] }
|
||||
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-application-crypto = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-application-crypto = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
pallet-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "5dfddc95c32994c1c09bd0c7a9e3633f1e5c7cc4", default-features = false }
|
||||
pallet-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "dd8f2ab6c80c609f15714f554194529116b717ef", default-features = false }
|
||||
|
||||
serai-abi = { path = "../abi", default-features = false, features = ["substrate"] }
|
||||
|
||||
|
||||
@@ -301,6 +301,12 @@ mod pallet {
|
||||
requirement
|
||||
}
|
||||
|
||||
pub fn selected_validators(
|
||||
set: ValidatorSet,
|
||||
) -> impl Iterator<Item = (Public, KeySharesStruct)> {
|
||||
Abstractions::<T>::selected_validators(set)
|
||||
}
|
||||
|
||||
/* TODO
|
||||
pub fn distribute_block_rewards(
|
||||
network: NetworkId,
|
||||
|
||||
Reference in New Issue
Block a user