mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-11 13:39:25 +00:00
Compare commits
8 Commits
c52f7634de
...
a793aa18ef
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a793aa18ef | ||
|
|
5662beeb8a | ||
|
|
509bd58f4e | ||
|
|
367a5769e8 | ||
|
|
cb6eb6430a | ||
|
|
4f82e5912c | ||
|
|
ac7af40f2e | ||
|
|
264bdd46ca |
2
.github/workflows/lint.yml
vendored
2
.github/workflows/lint.yml
vendored
@@ -26,7 +26,7 @@ jobs:
|
|||||||
uses: ./.github/actions/build-dependencies
|
uses: ./.github/actions/build-dependencies
|
||||||
|
|
||||||
- name: Install nightly rust
|
- name: Install nightly rust
|
||||||
run: rustup toolchain install ${{ steps.nightly.outputs.version }} --profile minimal -t wasm32v1-none -c rust-src -c clippy
|
run: rustup toolchain install ${{ steps.nightly.outputs.version }} --profile minimal -t wasm32v1-none -c clippy
|
||||||
|
|
||||||
- name: Run Clippy
|
- name: Run Clippy
|
||||||
run: cargo +${{ steps.nightly.outputs.version }} clippy --all-features --all-targets -- -D warnings -A clippy::items_after_test_module
|
run: cargo +${{ steps.nightly.outputs.version }} clippy --all-features --all-targets -- -D warnings -A clippy::items_after_test_module
|
||||||
|
|||||||
2
.github/workflows/pages.yml
vendored
2
.github/workflows/pages.yml
vendored
@@ -69,7 +69,7 @@ jobs:
|
|||||||
uses: ./.github/actions/build-dependencies
|
uses: ./.github/actions/build-dependencies
|
||||||
- name: Buld Rust docs
|
- name: Buld Rust docs
|
||||||
run: |
|
run: |
|
||||||
rustup toolchain install ${{ steps.nightly.outputs.version }} --profile minimal -t wasm32v1-none -c rust-docs -c rust-src
|
rustup toolchain install ${{ steps.nightly.outputs.version }} --profile minimal -t wasm32v1-none -c rust-docs
|
||||||
RUSTDOCFLAGS="--cfg docsrs" cargo +${{ steps.nightly.outputs.version }} doc --workspace --no-deps --all-features
|
RUSTDOCFLAGS="--cfg docsrs" cargo +${{ steps.nightly.outputs.version }} doc --workspace --no-deps --all-features
|
||||||
mv target/doc docs/_site/rust
|
mv target/doc docs/_site/rust
|
||||||
|
|
||||||
|
|||||||
@@ -201,6 +201,9 @@ lazy_static = { git = "https://github.com/rust-lang-nursery/lazy-static.rs", rev
|
|||||||
option-ext = { path = "patches/option-ext" }
|
option-ext = { path = "patches/option-ext" }
|
||||||
directories-next = { path = "patches/directories-next" }
|
directories-next = { path = "patches/directories-next" }
|
||||||
|
|
||||||
|
# Patch from a fork back to upstream
|
||||||
|
parity-bip39 = { path = "patches/parity-bip39" }
|
||||||
|
|
||||||
# Patch to include `FromUniformBytes<64>` over `Scalar`
|
# Patch to include `FromUniformBytes<64>` over `Scalar`
|
||||||
k256 = { git = "https://github.com/kayabaNerve/elliptic-curves", rev = "4994c9ab163781a88cd4a49beae812a89a44e8c3" }
|
k256 = { git = "https://github.com/kayabaNerve/elliptic-curves", rev = "4994c9ab163781a88cd4a49beae812a89a44e8c3" }
|
||||||
p256 = { git = "https://github.com/kayabaNerve/elliptic-curves", rev = "4994c9ab163781a88cd4a49beae812a89a44e8c3" }
|
p256 = { git = "https://github.com/kayabaNerve/elliptic-curves", rev = "4994c9ab163781a88cd4a49beae812a89a44e8c3" }
|
||||||
|
|||||||
13
deny.toml
13
deny.toml
@@ -10,7 +10,6 @@ ignore = [
|
|||||||
"RUSTSEC-2022-0061", # https://github.com/serai-dex/serai/227
|
"RUSTSEC-2022-0061", # https://github.com/serai-dex/serai/227
|
||||||
"RUSTSEC-2024-0370", # proc-macro-error is unmaintained
|
"RUSTSEC-2024-0370", # proc-macro-error is unmaintained
|
||||||
"RUSTSEC-2024-0436", # paste is unmaintained
|
"RUSTSEC-2024-0436", # paste is unmaintained
|
||||||
"RUSTSEC-2025-0057", # https://github.com/bytecodealliance/wasmtime/pull/11634
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[licenses]
|
[licenses]
|
||||||
@@ -126,12 +125,22 @@ multiple-versions = "warn"
|
|||||||
wildcards = "warn"
|
wildcards = "warn"
|
||||||
highlight = "all"
|
highlight = "all"
|
||||||
deny = [
|
deny = [
|
||||||
|
# Contains a non-reproducible binary blob
|
||||||
|
# https://github.com/serde-rs/serde/pull/2514
|
||||||
|
# https://github.com/serde-rs/serde/issues/2575
|
||||||
{ name = "serde_derive", version = ">=1.0.172, <1.0.185" },
|
{ name = "serde_derive", version = ">=1.0.172, <1.0.185" },
|
||||||
|
# Introduced an insecure implementation of `borsh` removed with `0.15.1`
|
||||||
|
# https://github.com/rust-lang/hashbrown/issues/576
|
||||||
{ name = "hashbrown", version = "=0.15.0" },
|
{ name = "hashbrown", version = "=0.15.0" },
|
||||||
|
|
||||||
# Legacy which _no one_ should use anymore
|
# Legacy which _no one_ should use anymore
|
||||||
{ name = "is-terminal", version = "*" },
|
{ name = "is-terminal", version = "*" },
|
||||||
# Stop introduction into the tree without realizing it
|
# Stop introduction into the tree without realizing it
|
||||||
{ name = "once_cell_polyfill", version = "*" },
|
{ name = "once_cell_polyfill", version = "*" },
|
||||||
|
|
||||||
|
# Conflicts with our usage of mimalloc
|
||||||
|
# https://github.com/serai-dex/serai/issues/690
|
||||||
|
{ name = "tikv-jemalloc-sys", version = "*" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[sources]
|
[sources]
|
||||||
@@ -143,5 +152,7 @@ allow-git = [
|
|||||||
"https://github.com/kayabaNerve/elliptic-curves",
|
"https://github.com/kayabaNerve/elliptic-curves",
|
||||||
"https://github.com/monero-oxide/monero-oxide",
|
"https://github.com/monero-oxide/monero-oxide",
|
||||||
"https://github.com/kayabaNerve/monero-oxide",
|
"https://github.com/kayabaNerve/monero-oxide",
|
||||||
|
"https://github.com/rust-bitcoin/rust-bip39",
|
||||||
|
"https://github.com/rust-rocksdb/rust-rocksdb",
|
||||||
"https://github.com/serai-dex/patch-polkadot-sdk",
|
"https://github.com/serai-dex/patch-polkadot-sdk",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -16,10 +16,12 @@ rustdoc-args = ["--cfg", "docsrs"]
|
|||||||
workspace = true
|
workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
subtle = { version = "2", default-features = false, features = ["std"] }
|
std-shims = { path = "../../../common/std-shims", version = "0.1", default-features = false }
|
||||||
sha3 = { version = "0.10", default-features = false, features = ["std"] }
|
|
||||||
group = { version = "0.13", default-features = false, features = ["alloc"] }
|
subtle = { version = "2", default-features = false }
|
||||||
k256 = { version = "^0.13.1", default-features = false, features = ["std", "arithmetic"] }
|
sha3 = { version = "0.10", default-features = false }
|
||||||
|
group = { version = "0.13", default-features = false }
|
||||||
|
k256 = { version = "^0.13.1", default-features = false, features = ["arithmetic"] }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
build-solidity-contracts = { path = "../build-contracts", version = "0.1" }
|
build-solidity-contracts = { path = "../build-contracts", version = "0.1" }
|
||||||
@@ -40,3 +42,8 @@ alloy-provider = { version = "1", default-features = false }
|
|||||||
alloy-node-bindings = { version = "1", default-features = false }
|
alloy-node-bindings = { version = "1", default-features = false }
|
||||||
|
|
||||||
tokio = { version = "1", default-features = false, features = ["macros"] }
|
tokio = { version = "1", default-features = false, features = ["macros"] }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
alloc = ["std-shims/alloc", "group/alloc"]
|
||||||
|
std = ["alloc", "std-shims/std", "subtle/std", "sha3/std", "k256/std"]
|
||||||
|
default = ["std"]
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#![doc = include_str!("../README.md")]
|
#![doc = include_str!("../README.md")]
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
mod public_key;
|
mod public_key;
|
||||||
pub use public_key::PublicKey;
|
pub use public_key::PublicKey;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::io;
|
use std_shims::io;
|
||||||
|
|
||||||
use sha3::{Digest, Keccak256};
|
use sha3::{Digest, Keccak256};
|
||||||
|
|
||||||
@@ -77,6 +77,7 @@ impl Signature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Write the signature.
|
/// Write the signature.
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
pub fn write(&self, writer: &mut impl io::Write) -> io::Result<()> {
|
pub fn write(&self, writer: &mut impl io::Write) -> io::Result<()> {
|
||||||
writer.write_all(&self.to_bytes())
|
writer.write_all(&self.to_bytes())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,9 @@
|
|||||||
# rust:1.91.1-slim-trixie as of November 11th, 2025 (GMT)
|
# rust:1.91.1-alpine as of November 11th, 2025 (GMT)
|
||||||
FROM --platform=linux/amd64 rust@sha256:ccdbe08a0b10498bc5f3cac3d736af7b8eb6cb0ecfc1e8a504e93d8ee76a8e8e AS deterministic
|
FROM --platform=linux/amd64 rust@sha256:700c0959b23445f69c82676b72caa97ca4359decd075dca55b13339df27dc4d3 AS deterministic
|
||||||
|
|
||||||
# Move to a Debian package snapshot
|
RUN apk add musl-dev=1.2.5-r10
|
||||||
RUN rm -rf /etc/apt/sources.list.d/debian.sources && \
|
|
||||||
rm -rf /var/lib/apt/lists/* && \
|
|
||||||
echo "deb [arch=amd64] http://snapshot.debian.org/archive/debian/20251111T000000Z trixie main" > /etc/apt/sources.list && \
|
|
||||||
apt update
|
|
||||||
|
|
||||||
# Install dependencies
|
|
||||||
RUN apt update -y && apt upgrade -y && apt install -y clang
|
|
||||||
|
|
||||||
# Add the wasm toolchain
|
# Add the wasm toolchain
|
||||||
RUN rustup component add rust-src
|
|
||||||
RUN rustup target add wasm32v1-none
|
RUN rustup target add wasm32v1-none
|
||||||
|
|
||||||
FROM deterministic
|
FROM deterministic
|
||||||
@@ -36,6 +28,7 @@ ADD AGPL-3.0 /serai
|
|||||||
WORKDIR /serai
|
WORKDIR /serai
|
||||||
|
|
||||||
# Build the runtime, copying it to the volume if it exists
|
# Build the runtime, copying it to the volume if it exists
|
||||||
|
ENV RUSTFLAGS="-Ctarget-feature=-crt-static"
|
||||||
CMD cargo build --release -p serai-runtime && \
|
CMD cargo build --release -p serai-runtime && \
|
||||||
mkdir -p /volume && \
|
mkdir -p /volume && \
|
||||||
cp /serai/target/release/wbuild/serai-runtime/serai_runtime.wasm /volume/serai.wasm
|
cp /serai/target/release/wbuild/serai-runtime/serai_runtime.wasm /volume/serai.wasm
|
||||||
|
|||||||
@@ -188,7 +188,6 @@ RUN apk add clang-dev
|
|||||||
&format!(
|
&format!(
|
||||||
r#"
|
r#"
|
||||||
# Add the wasm toolchain
|
# Add the wasm toolchain
|
||||||
RUN rustup component add rust-src
|
|
||||||
RUN rustup target add wasm32v1-none
|
RUN rustup target add wasm32v1-none
|
||||||
|
|
||||||
{prelude}
|
{prelude}
|
||||||
|
|||||||
30
patches/parity-bip39/Cargo.toml
Normal file
30
patches/parity-bip39/Cargo.toml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
[package]
|
||||||
|
name = "parity-bip39"
|
||||||
|
version = "2.99.99"
|
||||||
|
description = "Patch back to the upstream library"
|
||||||
|
license = "MIT"
|
||||||
|
repository = "https://github.com/serai-dex/serai/tree/develop/patches/parity-bip39"
|
||||||
|
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
|
||||||
|
keywords = []
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[package.metadata.docs.rs]
|
||||||
|
all-features = true
|
||||||
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bip39 = { git = "https://github.com/rust-bitcoin/rust-bip39", commit = "f735e2559f30049f6738d1bf68c69a0b7bd7b858", default-features = false }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["bip39/default"]
|
||||||
|
alloc = ["bip39/alloc"]
|
||||||
|
std = ["bip39/std"]
|
||||||
|
|
||||||
|
unicode-normalization = ["bip39/unicode-normalization"]
|
||||||
|
all-languages = ["bip39/all-languages"]
|
||||||
|
|
||||||
|
zeroize = ["bip39/zeroize"]
|
||||||
|
rand_core = ["bip39/rand_core"]
|
||||||
|
rand = ["bip39/rand"]
|
||||||
3
patches/parity-bip39/src/lib.rs
Normal file
3
patches/parity-bip39/src/lib.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
|
pub use bip39::*;
|
||||||
@@ -35,7 +35,7 @@ alloy-provider = { version = "1", default-features = false }
|
|||||||
|
|
||||||
revm = { version = "33", default-features = false }
|
revm = { version = "33", default-features = false }
|
||||||
|
|
||||||
ethereum-schnorr = { package = "ethereum-schnorr-contract", path = "../../../networks/ethereum/schnorr", default-features = false }
|
ethereum-schnorr = { package = "ethereum-schnorr-contract", path = "../../../networks/ethereum/schnorr", default-features = false, features = ["std"] }
|
||||||
|
|
||||||
ethereum-primitives = { package = "serai-processor-ethereum-primitives", path = "../primitives", default-features = false }
|
ethereum-primitives = { package = "serai-processor-ethereum-primitives", path = "../primitives", default-features = false }
|
||||||
ethereum-deployer = { package = "serai-processor-ethereum-deployer", path = "../deployer", default-features = false }
|
ethereum-deployer = { package = "serai-processor-ethereum-deployer", path = "../deployer", default-features = false }
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
channel = "1.91.1"
|
channel = "1.91.1"
|
||||||
targets = ["wasm32v1-none"]
|
targets = ["wasm32v1-none"]
|
||||||
profile = "minimal"
|
profile = "minimal"
|
||||||
components = ["rust-src", "rustfmt", "clippy"]
|
components = ["rustfmt", "clippy"]
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ workspace = true
|
|||||||
borsh = { version = "1", default-features = false, features = ["derive", "de_strict_order"] }
|
borsh = { version = "1", default-features = false, features = ["derive", "de_strict_order"] }
|
||||||
|
|
||||||
bitvec = { version = "1", default-features = false, features = ["alloc"] }
|
bitvec = { version = "1", default-features = false, features = ["alloc"] }
|
||||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
serde = { version = "1", default-features = false, features = ["derive"], optional = true }
|
serde = { version = "1", default-features = false, features = ["derive"], optional = true }
|
||||||
scale = { package = "parity-scale-codec", version = "3", 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 = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false, features = ["serde"], optional = true }
|
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false, features = ["serde"], optional = true }
|
||||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false, optional = true }
|
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false, optional = true }
|
||||||
|
|
||||||
serai-primitives = { path = "../primitives", version = "0.1", default-features = false }
|
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" }
|
serai-abi = { path = "../abi", version = "0.1" }
|
||||||
|
|
||||||
multiaddr = { version = "0.18", optional = true }
|
multiaddr = { version = "0.18", optional = true }
|
||||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", optional = true }
|
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", optional = true }
|
||||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", optional = true }
|
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", optional = true }
|
||||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", optional = true }
|
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", optional = true }
|
||||||
|
|
||||||
async-lock = "3"
|
async-lock = "3"
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#![doc = include_str!("../README.md")]
|
#![doc = include_str!("../README.md")]
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
use core::future::Future;
|
use core::{ops::Deref, convert::AsRef, future::Future};
|
||||||
use std::{sync::Arc, io::Read};
|
use std::{sync::Arc, io::Read};
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
@@ -19,6 +19,10 @@ use abi::{
|
|||||||
|
|
||||||
use async_lock::RwLock;
|
use async_lock::RwLock;
|
||||||
|
|
||||||
|
/// RPC client functionality for the validator sets module.
|
||||||
|
pub mod validator_sets;
|
||||||
|
use validator_sets::*;
|
||||||
|
|
||||||
/// An error from the RPC.
|
/// An error from the RPC.
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum RpcError {
|
pub enum RpcError {
|
||||||
@@ -177,3 +181,45 @@ impl Serai {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> TemporalSerai<'a> {
|
||||||
|
/// Fetch the events for this block.
|
||||||
|
///
|
||||||
|
/// The returned `Option` will always be `Some(_)`.
|
||||||
|
async fn events(&self) -> Result<async_lock::RwLockReadGuard<'_, Option<Vec<Event>>>, RpcError> {
|
||||||
|
let mut events = self.events.read().await;
|
||||||
|
if events.is_none() {
|
||||||
|
drop(events);
|
||||||
|
{
|
||||||
|
let mut events_mut = self.events.write().await;
|
||||||
|
if events_mut.is_none() {
|
||||||
|
*events_mut = Some(
|
||||||
|
self
|
||||||
|
.serai
|
||||||
|
.call::<Vec<String>>("serai_events", &format!(r#"["{}"]"#, self.block))
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.map(|event| {
|
||||||
|
Event::deserialize(
|
||||||
|
&mut hex::decode(&event)
|
||||||
|
.map_err(|_| {
|
||||||
|
RpcError::InvalidNode("node returned non-hex-encoded event".to_string())
|
||||||
|
})?
|
||||||
|
.as_slice(),
|
||||||
|
)
|
||||||
|
.map_err(|_| RpcError::InvalidNode("node returned invalid event".to_string()))
|
||||||
|
})
|
||||||
|
.collect::<Result<_, _>>()?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
events = self.events.read().await;
|
||||||
|
}
|
||||||
|
Ok(events)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Scope to the validator sets module.
|
||||||
|
pub fn validator_sets(&self) -> ValidatorSets<'_> {
|
||||||
|
ValidatorSets(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
50
substrate/client/serai/src/validator_sets.rs
Normal file
50
substrate/client/serai/src/validator_sets.rs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
pub use serai_abi::validator_sets::Event;
|
||||||
|
use crate::{RpcError, TemporalSerai};
|
||||||
|
|
||||||
|
/// A `TemporalSerai` scoped to the validator sets module.
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct ValidatorSets<'a>(pub(super) &'a TemporalSerai<'a>);
|
||||||
|
|
||||||
|
impl<'a> ValidatorSets<'a> {
|
||||||
|
/// The events from the validator sets module.
|
||||||
|
pub async fn events(&self) -> Result<Vec<Event>, RpcError> {
|
||||||
|
Ok(
|
||||||
|
self
|
||||||
|
.0
|
||||||
|
.events()
|
||||||
|
.await?
|
||||||
|
.as_ref()
|
||||||
|
.expect("`TemporalSerai::events` returned None")
|
||||||
|
.iter()
|
||||||
|
.filter_map(|event| match event {
|
||||||
|
serai_abi::Event::ValidatorSets(event) => Some(event.clone()),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The `SetDecided` events from the validator sets module.
|
||||||
|
pub async fn set_decided_events(&self) -> Result<Vec<Event>, RpcError> {
|
||||||
|
Ok(
|
||||||
|
self
|
||||||
|
.events()
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.filter(|event| matches!(event, Event::SetDecided { .. }))
|
||||||
|
.collect(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The `AcceptedHandover` events from the validator sets module.
|
||||||
|
pub async fn accepted_handover_events(&self) -> Result<Vec<Event>, RpcError> {
|
||||||
|
Ok(
|
||||||
|
self
|
||||||
|
.events()
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.filter(|event| matches!(event, Event::AcceptedHandover { .. }))
|
||||||
|
.collect(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,18 @@ async fn blockchain() {
|
|||||||
.run_async(async |ops| {
|
.run_async(async |ops| {
|
||||||
let serai = serai_substrate_tests::rpc(&ops, handle).await;
|
let serai = serai_substrate_tests::rpc(&ops, handle).await;
|
||||||
|
|
||||||
|
'outer: {
|
||||||
|
for _ in 0 .. (5 * 10) {
|
||||||
|
tokio::time::sleep(core::time::Duration::from_secs(6)).await;
|
||||||
|
|
||||||
|
let latest_finalized = serai.latest_finalized_block_number().await.unwrap();
|
||||||
|
if latest_finalized > 0 {
|
||||||
|
break 'outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic!("finalized block remained the genesis block for over five minutes");
|
||||||
|
};
|
||||||
|
|
||||||
// Check the sanity of fetching a block
|
// Check the sanity of fetching a block
|
||||||
let test_finalized_block = |number| {
|
let test_finalized_block = |number| {
|
||||||
let serai = &serai;
|
let serai = &serai;
|
||||||
|
|||||||
131
substrate/client/serai/tests/validator_sets.rs
Normal file
131
substrate/client/serai/tests/validator_sets.rs
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
use serai_abi::{
|
||||||
|
primitives::{
|
||||||
|
network_id::{ExternalNetworkId, NetworkId},
|
||||||
|
validator_sets::{Session, ValidatorSet},
|
||||||
|
},
|
||||||
|
validator_sets::Event,
|
||||||
|
};
|
||||||
|
|
||||||
|
use serai_client_serai::*;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn validator_sets() {
|
||||||
|
let mut test = dockertest::DockerTest::new();
|
||||||
|
let (composition, handle) = serai_substrate_tests::composition(
|
||||||
|
"alice",
|
||||||
|
serai_docker_tests::fresh_logs_folder(true, "serai-client/validator_sets"),
|
||||||
|
);
|
||||||
|
test.provide_container(
|
||||||
|
composition
|
||||||
|
.replace_cmd(
|
||||||
|
["serai-node", "--unsafe-rpc-external", "--rpc-cors", "all", "--dev"]
|
||||||
|
.into_iter()
|
||||||
|
.map(str::to_owned)
|
||||||
|
.collect(),
|
||||||
|
)
|
||||||
|
.replace_env([("RUST_LOG".to_string(), "runtime=debug".to_string())].into()),
|
||||||
|
);
|
||||||
|
|
||||||
|
test
|
||||||
|
.run_async(async |ops| {
|
||||||
|
let serai = serai_substrate_tests::rpc(&ops, handle).await;
|
||||||
|
|
||||||
|
'outer: {
|
||||||
|
for _ in 0 .. (5 * 10) {
|
||||||
|
tokio::time::sleep(core::time::Duration::from_secs(6)).await;
|
||||||
|
|
||||||
|
let latest_finalized = serai.latest_finalized_block_number().await.unwrap();
|
||||||
|
if latest_finalized > 0 {
|
||||||
|
break 'outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic!("finalized block remained the genesis block for over five minutes");
|
||||||
|
};
|
||||||
|
|
||||||
|
// The genesis block should have the expected events
|
||||||
|
{
|
||||||
|
{
|
||||||
|
let mut events = serai
|
||||||
|
.as_of(serai.block_by_number(0).await.unwrap().header.hash())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.validator_sets()
|
||||||
|
.set_decided_events()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
events.sort_by_key(|event| borsh::to_vec(event).unwrap());
|
||||||
|
let mut expected = vec![
|
||||||
|
Event::SetDecided {
|
||||||
|
set: ValidatorSet { network: NetworkId::Serai, session: Session(0) },
|
||||||
|
},
|
||||||
|
Event::SetDecided {
|
||||||
|
set: ValidatorSet { network: NetworkId::Serai, session: Session(1) },
|
||||||
|
},
|
||||||
|
Event::SetDecided {
|
||||||
|
set: ValidatorSet {
|
||||||
|
network: NetworkId::External(ExternalNetworkId::Bitcoin),
|
||||||
|
session: Session(0),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Event::SetDecided {
|
||||||
|
set: ValidatorSet {
|
||||||
|
network: NetworkId::External(ExternalNetworkId::Ethereum),
|
||||||
|
session: Session(0),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Event::SetDecided {
|
||||||
|
set: ValidatorSet {
|
||||||
|
network: NetworkId::External(ExternalNetworkId::Monero),
|
||||||
|
session: Session(0),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
expected.sort_by_key(|event| borsh::to_vec(event).unwrap());
|
||||||
|
assert_eq!(events, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
serai
|
||||||
|
.as_of(serai.block_by_number(0).await.unwrap().header.hash())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.validator_sets()
|
||||||
|
.accepted_handover_events()
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
vec![Event::AcceptedHandover {
|
||||||
|
set: ValidatorSet { network: NetworkId::Serai, session: Session(0) }
|
||||||
|
}]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The next block should not have these events
|
||||||
|
{
|
||||||
|
assert_eq!(
|
||||||
|
serai
|
||||||
|
.as_of(serai.block_by_number(1).await.unwrap().header.hash())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.validator_sets()
|
||||||
|
.set_decided_events()
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
vec![],
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
serai
|
||||||
|
.as_of(serai.block_by_number(1).await.unwrap().header.hash())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.validator_sets()
|
||||||
|
.accepted_handover_events()
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
vec![],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Finished `serai-client/blockchain` test");
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
@@ -18,10 +18,10 @@ workspace = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
||||||
|
|
||||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
serai-abi = { path = "../abi", default-features = false, features = ["substrate"] }
|
serai-abi = { path = "../abi", default-features = false, features = ["substrate"] }
|
||||||
serai-core-pallet = { path = "../core", default-features = false }
|
serai-core-pallet = { path = "../core", default-features = false }
|
||||||
@@ -29,7 +29,7 @@ serai-core-pallet = { path = "../core", default-features = false }
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] }
|
borsh = { version = "1", default-features = false, features = ["std", "derive", "de_strict_order"] }
|
||||||
|
|
||||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false, features = ["std"] }
|
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false, features = ["std"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
std = [
|
std = [
|
||||||
|
|||||||
@@ -28,18 +28,6 @@ impl crate::Config<CoinsInstance> for Test {
|
|||||||
type AllowMint = crate::AlwaysAllowMint;
|
type AllowMint = crate::AlwaysAllowMint;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<RuntimeEvent> for serai_abi::Event {
|
|
||||||
type Error = ();
|
|
||||||
fn try_from(event: RuntimeEvent) -> Result<serai_abi::Event, ()> {
|
|
||||||
match event {
|
|
||||||
RuntimeEvent::Core(serai_core_pallet::Event::Event(event)) => {
|
|
||||||
Ok(serai_abi::Event::deserialize_reader(&mut event.as_slice()).unwrap())
|
|
||||||
}
|
|
||||||
_ => Err(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
|
pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
|
||||||
let mut storage = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
let mut storage = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ fn mint() {
|
|||||||
// test events
|
// test events
|
||||||
let mint_events = Core::events()
|
let mint_events = Core::events()
|
||||||
.iter()
|
.iter()
|
||||||
|
.map(|event| borsh::from_slice::<serai_abi::Event>(event.as_slice()).unwrap())
|
||||||
.filter_map(|event| {
|
.filter_map(|event| {
|
||||||
if let serai_abi::Event::Coins(e) = &event {
|
if let serai_abi::Event::Coins(e) = &event {
|
||||||
if matches!(e, CoinsEvent::Mint { .. }) {
|
if matches!(e, CoinsEvent::Mint { .. }) {
|
||||||
@@ -82,6 +83,7 @@ fn burn_with_instruction() {
|
|||||||
|
|
||||||
let burn_events = Core::events()
|
let burn_events = Core::events()
|
||||||
.iter()
|
.iter()
|
||||||
|
.map(|event| borsh::from_slice::<serai_abi::Event>(event.as_slice()).unwrap())
|
||||||
.filter_map(|event| {
|
.filter_map(|event| {
|
||||||
if let serai_abi::Event::Coins(e) = &event {
|
if let serai_abi::Event::Coins(e) = &event {
|
||||||
if matches!(e, CoinsEvent::BurnWithInstruction { .. }) {
|
if matches!(e, CoinsEvent::BurnWithInstruction { .. }) {
|
||||||
|
|||||||
@@ -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"] }
|
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
||||||
|
|
||||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
serai-abi = { path = "../abi", default-features = false, features = ["substrate"] }
|
serai-abi = { path = "../abi", default-features = false, features = ["substrate"] }
|
||||||
|
|
||||||
|
|||||||
@@ -132,15 +132,16 @@ pub mod pallet {
|
|||||||
|
|
||||||
/// Fetch all of Serai's events.
|
/// Fetch all of Serai's events.
|
||||||
///
|
///
|
||||||
/// This MUST only be used for testing purposes.
|
/// This MUST NOT be called during a transaction/block's execution.
|
||||||
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
|
pub fn events() -> Vec<Vec<u8>>
|
||||||
pub fn events() -> Vec<serai_abi::Event>
|
|
||||||
where
|
where
|
||||||
serai_abi::Event: TryFrom<T::RuntimeEvent>,
|
T::RuntimeEvent: TryInto<Event<T>>,
|
||||||
{
|
{
|
||||||
frame_system::Pallet::<T>::events()
|
frame_system::Pallet::<T>::read_events_no_consensus()
|
||||||
.into_iter()
|
.filter_map(|e| match e.event.try_into() {
|
||||||
.filter_map(|e| serai_abi::Event::try_from(e.event).ok())
|
Ok(Event::Event(bytes)) => Some(bytes),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,15 +21,15 @@ workspace = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
scale = { package = "parity-scale-codec", version = "3.6.1", default-features = false }
|
scale = { package = "parity-scale-codec", version = "3.6.1", default-features = false }
|
||||||
|
|
||||||
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
frame-benchmarking = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false, optional = true }
|
frame-benchmarking = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false, optional = true }
|
||||||
|
|
||||||
coins-pallet = { package = "serai-coins-pallet", path = "../coins", default-features = false }
|
coins-pallet = { package = "serai-coins-pallet", path = "../coins", default-features = false }
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ workspace = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
||||||
|
|
||||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
dex-pallet = { package = "serai-dex-pallet", path = "../dex", 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 }
|
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 }
|
serai-primitives = { path = "../primitives", default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
pallet-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
pallet-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
validator-sets-pallet = { package = "serai-validator-sets-pallet", path = "../validator-sets", 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 = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
std = [
|
std = [
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ workspace = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
||||||
|
|
||||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
coins-pallet = { package = "serai-coins-pallet", path = "../coins", 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 }
|
validator-sets-pallet = { package = "serai-validator-sets-pallet", path = "../validator-sets", default-features = false }
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ workspace = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
||||||
|
|
||||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-application-crypto = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-application-crypto = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
dex-pallet = { package = "serai-dex-pallet", path = "../dex", 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 }
|
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"] }
|
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 = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-application-crypto = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-application-crypto = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
serai-primitives = { path = "../primitives", 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 }
|
emissions-pallet = { package = "serai-emissions-pallet", path = "../emissions", default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
pallet-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
pallet-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
economic-security-pallet = { package = "serai-economic-security-pallet", path = "../economic-security", default-features = false }
|
economic-security-pallet = { package = "serai-economic-security-pallet", path = "../economic-security", default-features = false }
|
||||||
|
|
||||||
|
|||||||
@@ -34,20 +34,20 @@ secq256k1 = { path = "../../crypto/secq256k1" }
|
|||||||
|
|
||||||
libp2p = "0.56"
|
libp2p = "0.56"
|
||||||
|
|
||||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sp-inherents = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sp-inherents = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sp-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sp-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sp-blockchain = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sp-blockchain = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sp-consensus = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sp-consensus = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sp-state-machine = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sp-state-machine = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sp-keystore = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sp-keystore = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sp-block-builder = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sp-block-builder = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sp-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sp-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
|
|
||||||
frame-benchmarking = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
frame-benchmarking = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
|
|
||||||
serai-abi = { path = "../abi", features = ["std", "substrate"] }
|
serai-abi = { path = "../abi", features = ["std", "substrate"] }
|
||||||
serai-runtime = { path = "../runtime", features = ["std"] }
|
serai-runtime = { path = "../runtime", features = ["std"] }
|
||||||
@@ -59,23 +59,23 @@ futures-util = "0.3"
|
|||||||
tokio = { version = "1", features = ["sync", "rt-multi-thread"] }
|
tokio = { version = "1", features = ["sync", "rt-multi-thread"] }
|
||||||
jsonrpsee = { version = "0.24", features = ["server"] }
|
jsonrpsee = { version = "0.24", features = ["server"] }
|
||||||
|
|
||||||
sc-transaction-pool = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sc-transaction-pool = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sc-transaction-pool-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sc-transaction-pool-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sc-basic-authorship = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sc-basic-authorship = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sc-executor = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sc-executor = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sc-service = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sc-service = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sc-client-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sc-client-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sc-network = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sc-network = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
|
|
||||||
sc-consensus = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sc-consensus = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sc-consensus-slots = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sc-consensus-slots = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sc-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sc-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sc-consensus-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sc-consensus-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sc-authority-discovery = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sc-authority-discovery = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
|
|
||||||
sc-telemetry = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sc-telemetry = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sc-chain-spec = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sc-chain-spec = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
sc-cli = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
sc-cli = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
|
|
||||||
serai-env = { path = "../../common/env" }
|
serai-env = { path = "../../common/env" }
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ use serai_abi::{
|
|||||||
},
|
},
|
||||||
SubstrateBlock as Block,
|
SubstrateBlock as Block,
|
||||||
};
|
};
|
||||||
use serai_runtime::*;
|
use serai_runtime::GenesisConfig;
|
||||||
|
|
||||||
pub type ChainSpec = sc_service::GenericChainSpec;
|
pub type ChainSpec = sc_service::GenericChainSpec;
|
||||||
|
|
||||||
@@ -66,95 +66,32 @@ fn wasm_binary(dev: bool) -> Vec<u8> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log::info!("using built-in wasm");
|
log::info!("using built-in wasm");
|
||||||
WASM_BINARY.ok_or("compiled in wasm not available").unwrap().to_vec()
|
serai_runtime::WASM_BINARY.ok_or("compiled in wasm not available").unwrap().to_vec()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn devnet_genesis(
|
fn devnet_genesis(validators: &[&'static str], endowed_accounts: Vec<Public>) -> GenesisConfig {
|
||||||
validators: &[&'static str],
|
GenesisConfig {
|
||||||
endowed_accounts: Vec<Public>,
|
validators: validators
|
||||||
) -> RuntimeGenesisConfig {
|
.iter()
|
||||||
let validators = validators
|
.map(|name| (insecure_account_from_name(name), insecure_embedded_elliptic_curve_keys(name)))
|
||||||
.iter()
|
.collect(),
|
||||||
.map(|name| (insecure_account_from_name(name), insecure_embedded_elliptic_curve_keys(name)))
|
coins: endowed_accounts
|
||||||
.collect::<Vec<_>>();
|
.into_iter()
|
||||||
|
.map(|address| (address, Balance { coin: Coin::Serai, amount: Amount(1 << 60) }))
|
||||||
RuntimeGenesisConfig {
|
.collect(),
|
||||||
system: SystemConfig { _config: PhantomData },
|
|
||||||
|
|
||||||
coins: CoinsConfig {
|
|
||||||
accounts: endowed_accounts
|
|
||||||
.into_iter()
|
|
||||||
.map(|address| (address.into(), Balance { coin: Coin::Serai, amount: Amount(1 << 60) }))
|
|
||||||
.collect(),
|
|
||||||
_instance: PhantomData,
|
|
||||||
},
|
|
||||||
|
|
||||||
liquidity_tokens: LiquidityTokensConfig { accounts: vec![], _instance: PhantomData },
|
|
||||||
|
|
||||||
validator_sets: ValidatorSetsConfig {
|
|
||||||
participants: validators
|
|
||||||
.iter()
|
|
||||||
.map(|validator| (validator.0.into(), validator.1.clone()))
|
|
||||||
.collect(),
|
|
||||||
},
|
|
||||||
signals: SignalsConfig::default(),
|
|
||||||
babe: BabeConfig {
|
|
||||||
// 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: vec![], _config: PhantomData },
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
fn testnet_genesis(validators: Vec<&'static str>) -> RuntimeGenesisConfig {
|
fn testnet_genesis(validators: &[&'static str]) -> GenesisConfig {
|
||||||
let validators = validators
|
GenesisConfig {
|
||||||
.into_iter()
|
validators: validators
|
||||||
.map(|validator| Public::decode(&mut hex::decode(validator).unwrap().as_slice()).unwrap())
|
.iter()
|
||||||
.collect::<Vec<_>>();
|
.map(|name| {
|
||||||
let key_shares = NETWORKS
|
(insecure_account_from_name(name), insecure_embedded_elliptic_curve_keys(name))
|
||||||
.iter()
|
})
|
||||||
.map(|network| match network {
|
.collect(),
|
||||||
NetworkId::Serai => (NetworkId::Serai, Amount(50_000 * 10_u64.pow(8))),
|
coins: vec![],
|
||||||
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)))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
assert_eq!(validators.iter().collect::<HashSet<_>>().len(), validators.len());
|
|
||||||
|
|
||||||
RuntimeGenesisConfig {
|
|
||||||
system: SystemConfig { _config: PhantomData },
|
|
||||||
|
|
||||||
coins: CoinsConfig {
|
|
||||||
accounts: validators
|
|
||||||
.iter()
|
|
||||||
.map(|a| (*a, Balance { coin: Coin::Serai, amount: Amount(5_000_000 * 10_u64.pow(8)) }))
|
|
||||||
.collect(),
|
|
||||||
},
|
|
||||||
|
|
||||||
validator_sets: ValidatorSetsConfig {
|
|
||||||
participants: validators.clone(),
|
|
||||||
},
|
|
||||||
signals: SignalsConfig::default(),
|
|
||||||
babe: BabeConfig {
|
|
||||||
authorities: validators.iter().map(|validator| ((*validator).into(), 1)).collect(),
|
|
||||||
epoch_config: BABE_GENESIS_EPOCH_CONFIG,
|
|
||||||
_config: PhantomData,
|
|
||||||
},
|
|
||||||
grandpa: GrandpaConfig {
|
|
||||||
authorities: validators.into_iter().map(|validator| (validator.into(), 1)).collect(),
|
|
||||||
_config: PhantomData,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
@@ -164,7 +101,7 @@ fn genesis(
|
|||||||
id: &'static str,
|
id: &'static str,
|
||||||
chain_type: ChainType,
|
chain_type: ChainType,
|
||||||
protocol_id: &'static str,
|
protocol_id: &'static str,
|
||||||
config: &RuntimeGenesisConfig,
|
config: &GenesisConfig,
|
||||||
) -> ChainSpec {
|
) -> ChainSpec {
|
||||||
use sp_core::{
|
use sp_core::{
|
||||||
Encode,
|
Encode,
|
||||||
|
|||||||
@@ -10,29 +10,21 @@ use sp_api::ProvideRuntimeApi;
|
|||||||
use sc_client_api::BlockBackend;
|
use sc_client_api::BlockBackend;
|
||||||
|
|
||||||
use serai_abi::{primitives::prelude::*, SubstrateBlock as Block};
|
use serai_abi::{primitives::prelude::*, SubstrateBlock as Block};
|
||||||
use serai_runtime::*;
|
|
||||||
|
use serai_runtime::SeraiApi;
|
||||||
|
|
||||||
use jsonrpsee::RpcModule;
|
use jsonrpsee::RpcModule;
|
||||||
|
|
||||||
pub(crate) fn module<
|
fn block_hash<
|
||||||
C: 'static
|
C: HeaderMetadata<Block, Error = BlockchainError>
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ HeaderMetadata<Block, Error = BlockchainError>
|
|
||||||
+ HeaderBackend<Block>
|
+ HeaderBackend<Block>
|
||||||
+ BlockBackend<Block>
|
+ BlockBackend<Block>
|
||||||
+ ProvideRuntimeApi<Block>,
|
+ ProvideRuntimeApi<Block>,
|
||||||
>(
|
>(
|
||||||
client: Arc<C>,
|
client: &C,
|
||||||
) -> Result<RpcModule<impl 'static + Send + Sync>, Box<dyn std::error::Error + Send + Sync>> {
|
params: &jsonrpsee::types::params::Params,
|
||||||
let mut module = RpcModule::new(client);
|
) -> Result<<Block as sp_runtime::traits::Block>::Hash, jsonrpsee::types::error::ErrorObjectOwned> {
|
||||||
|
Ok(if let Ok(block_hash) = params.sequence().next::<String>() {
|
||||||
module.register_method("serai_latestFinalizedBlockNumber", |_params, client, _ext| {
|
|
||||||
client.info().finalized_number
|
|
||||||
});
|
|
||||||
|
|
||||||
module.register_method("serai_isFinalized", |params, client, _ext| {
|
|
||||||
let [block_hash]: [String; 1] = params.parse()?;
|
|
||||||
let Some(block_hash) = hex::decode(&block_hash).ok().and_then(|bytes| {
|
let Some(block_hash) = hex::decode(&block_hash).ok().and_then(|bytes| {
|
||||||
<[u8; 32]>::try_from(bytes.as_slice())
|
<[u8; 32]>::try_from(bytes.as_slice())
|
||||||
.map(<Block as sp_runtime::traits::Block>::Hash::from)
|
.map(<Block as sp_runtime::traits::Block>::Hash::from)
|
||||||
@@ -44,6 +36,45 @@ pub(crate) fn module<
|
|||||||
Option::<()>::None,
|
Option::<()>::None,
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
block_hash
|
||||||
|
} else {
|
||||||
|
let Ok(block_number) = params.sequence().next::<u64>() else {
|
||||||
|
return Err(jsonrpsee::types::error::ErrorObjectOwned::owned(
|
||||||
|
-1,
|
||||||
|
"requested block wasn't a valid hash nor number",
|
||||||
|
Option::<()>::None,
|
||||||
|
));
|
||||||
|
};
|
||||||
|
let Ok(Some(block_hash)) = client.block_hash(block_number) else {
|
||||||
|
return Err(jsonrpsee::types::error::ErrorObjectOwned::owned(
|
||||||
|
-2,
|
||||||
|
"couldn't find requested block's hash",
|
||||||
|
Option::<()>::None,
|
||||||
|
));
|
||||||
|
};
|
||||||
|
block_hash
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn module<
|
||||||
|
C: 'static
|
||||||
|
+ Send
|
||||||
|
+ Sync
|
||||||
|
+ HeaderMetadata<Block, Error = BlockchainError>
|
||||||
|
+ HeaderBackend<Block>
|
||||||
|
+ BlockBackend<Block>
|
||||||
|
+ ProvideRuntimeApi<Block, Api: SeraiApi<Block>>,
|
||||||
|
>(
|
||||||
|
client: Arc<C>,
|
||||||
|
) -> Result<RpcModule<impl 'static + Send + Sync>, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
|
let mut module = RpcModule::new(client);
|
||||||
|
|
||||||
|
module.register_method("serai_latestFinalizedBlockNumber", |_params, client, _ext| {
|
||||||
|
client.info().finalized_number
|
||||||
|
});
|
||||||
|
|
||||||
|
module.register_method("serai_isFinalized", |params, client, _ext| {
|
||||||
|
let block_hash = block_hash(&**client, ¶ms)?;
|
||||||
let finalized = client.info().finalized_number;
|
let finalized = client.info().finalized_number;
|
||||||
let Ok(Some(number)) = client.number(block_hash) else {
|
let Ok(Some(number)) = client.number(block_hash) else {
|
||||||
return Err(jsonrpsee::types::error::ErrorObjectOwned::owned(
|
return Err(jsonrpsee::types::error::ErrorObjectOwned::owned(
|
||||||
@@ -66,37 +97,7 @@ pub(crate) fn module<
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
module.register_method("serai_block", |params, client, _ext| {
|
module.register_method("serai_block", |params, client, _ext| {
|
||||||
let block_hash = if let Ok([block_hash]) = params.parse::<[String; 1]>() {
|
let block_hash = block_hash(&**client, ¶ms)?;
|
||||||
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,
|
|
||||||
));
|
|
||||||
};
|
|
||||||
block_hash
|
|
||||||
} else {
|
|
||||||
let Ok([block_number]) = params.parse::<[u64; 1]>() else {
|
|
||||||
return Err(jsonrpsee::types::error::ErrorObjectOwned::owned(
|
|
||||||
-1,
|
|
||||||
"requested block wasn't a valid hash nor number",
|
|
||||||
Option::<()>::None,
|
|
||||||
));
|
|
||||||
};
|
|
||||||
let Ok(Some(block_hash)) = client.block_hash(block_number) else {
|
|
||||||
return Err(jsonrpsee::types::error::ErrorObjectOwned::owned(
|
|
||||||
-2,
|
|
||||||
"couldn't find requested block's hash",
|
|
||||||
Option::<()>::None,
|
|
||||||
));
|
|
||||||
};
|
|
||||||
block_hash
|
|
||||||
};
|
|
||||||
|
|
||||||
let Ok(Some(block)) = client.block(block_hash) else {
|
let Ok(Some(block)) = client.block(block_hash) else {
|
||||||
return Err(jsonrpsee::types::error::ErrorObjectOwned::owned(
|
return Err(jsonrpsee::types::error::ErrorObjectOwned::owned(
|
||||||
-2,
|
-2,
|
||||||
@@ -108,5 +109,17 @@ pub(crate) fn module<
|
|||||||
Ok(hex::encode(borsh::to_vec(&serai_abi::Block::from(block.block)).unwrap()))
|
Ok(hex::encode(borsh::to_vec(&serai_abi::Block::from(block.block)).unwrap()))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
module.register_method("serai_events", |params, client, _ext| {
|
||||||
|
let block_hash = block_hash(&**client, ¶ms)?;
|
||||||
|
let Ok(events) = client.runtime_api().events(block_hash) else {
|
||||||
|
return Err(jsonrpsee::types::error::ErrorObjectOwned::owned(
|
||||||
|
-2,
|
||||||
|
"couldn't fetch the events for the requested block",
|
||||||
|
Option::<()>::None,
|
||||||
|
));
|
||||||
|
};
|
||||||
|
Ok(events.into_iter().map(hex::encode).collect::<Vec<String>>())
|
||||||
|
})?;
|
||||||
|
|
||||||
Ok(module)
|
Ok(module)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ use sp_block_builder::BlockBuilder;
|
|||||||
use sp_api::ProvideRuntimeApi;
|
use sp_api::ProvideRuntimeApi;
|
||||||
|
|
||||||
use serai_abi::{primitives::prelude::*, SubstrateBlock as Block};
|
use serai_abi::{primitives::prelude::*, SubstrateBlock as Block};
|
||||||
use serai_runtime::*;
|
|
||||||
|
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
|
|||||||
@@ -7,18 +7,14 @@ use sp_blockchain::{Error as BlockchainError, HeaderBackend};
|
|||||||
use sp_api::ProvideRuntimeApi;
|
use sp_api::ProvideRuntimeApi;
|
||||||
|
|
||||||
use serai_abi::{primitives::prelude::*, SubstrateBlock as Block};
|
use serai_abi::{primitives::prelude::*, SubstrateBlock as Block};
|
||||||
use serai_runtime::*;
|
use serai_runtime::SeraiApi;
|
||||||
|
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use jsonrpsee::RpcModule;
|
use jsonrpsee::RpcModule;
|
||||||
|
|
||||||
pub(crate) fn module<
|
pub(crate) fn module<
|
||||||
C: 'static
|
C: 'static + Send + Sync + HeaderBackend<Block> + ProvideRuntimeApi<Block, Api: SeraiApi<Block>>,
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ HeaderBackend<Block>
|
|
||||||
+ ProvideRuntimeApi<Block, Api: serai_runtime::SeraiApi<Block>>,
|
|
||||||
>(
|
>(
|
||||||
id: String,
|
id: String,
|
||||||
client: Arc<C>,
|
client: Arc<C>,
|
||||||
@@ -62,7 +58,7 @@ pub(crate) fn module<
|
|||||||
let mut returned_addresses = authority_discovery
|
let mut returned_addresses = authority_discovery
|
||||||
.write()
|
.write()
|
||||||
.await
|
.await
|
||||||
.get_addresses_by_authority_id(validator.into())
|
.get_addresses_by_authority_id(sp_core::sr25519::Public::from(validator).into())
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(HashSet::new)
|
.unwrap_or_else(HashSet::new)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ borsh = { version = "1", default-features = false, features = ["derive", "de_str
|
|||||||
|
|
||||||
bitvec = { version = "1", default-features = false, features = ["alloc"] }
|
bitvec = { version = "1", default-features = false, features = ["alloc"] }
|
||||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"], optional = true }
|
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 = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["alloc"] }
|
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, features = ["alloc"] }
|
||||||
schnorr-signatures = { path = "../../crypto/schnorr", default-features = false }
|
schnorr-signatures = { path = "../../crypto/schnorr", default-features = false }
|
||||||
|
|||||||
@@ -20,28 +20,31 @@ workspace = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
||||||
|
|
||||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-version = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-inherents = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
|
||||||
sp-version = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-transaction-pool = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-inherents = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-block-builder = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-consensus-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-block-builder = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-consensus-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-transaction-pool = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-authority-discovery = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-authority-discovery = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
|
||||||
|
|
||||||
serai-abi = { path = "../abi", default-features = false, features = ["substrate"] }
|
serai-abi = { path = "../abi", default-features = false, features = ["substrate"] }
|
||||||
|
|
||||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
[target.'cfg(target_family = "wasm")'.dependencies]
|
||||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
frame-executive = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
pallet-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
pallet-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-executive = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
|
||||||
|
pallet-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
pallet-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
serai-core-pallet = { path = "../core", default-features = false }
|
serai-core-pallet = { path = "../core", default-features = false }
|
||||||
serai-coins-pallet = { path = "../coins", default-features = false }
|
serai-coins-pallet = { path = "../coins", default-features = false }
|
||||||
@@ -49,7 +52,7 @@ serai-validator-sets-pallet = { path = "../validator-sets", default-features = f
|
|||||||
serai-signals-pallet = { path = "../signals", default-features = false }
|
serai-signals-pallet = { path = "../signals", default-features = false }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
substrate-wasm-builder = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233" }
|
substrate-wasm-builder = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
std = [
|
std = [
|
||||||
@@ -57,13 +60,14 @@ std = [
|
|||||||
|
|
||||||
"sp-core/std",
|
"sp-core/std",
|
||||||
"sp-session/std",
|
"sp-session/std",
|
||||||
|
|
||||||
"sp-version/std",
|
"sp-version/std",
|
||||||
"sp-runtime/std",
|
"sp-runtime/std",
|
||||||
"sp-api/std",
|
"sp-api/std",
|
||||||
|
"sp-transaction-pool/std",
|
||||||
|
"sp-block-builder/std",
|
||||||
"sp-consensus-babe/std",
|
"sp-consensus-babe/std",
|
||||||
"sp-consensus-grandpa/std",
|
"sp-consensus-grandpa/std",
|
||||||
"sp-block-builder/std",
|
|
||||||
"sp-transaction-pool/std",
|
|
||||||
"sp-authority-discovery/std",
|
"sp-authority-discovery/std",
|
||||||
|
|
||||||
"serai-abi/std",
|
"serai-abi/std",
|
||||||
|
|||||||
@@ -1,736 +1,188 @@
|
|||||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
|
use alloc::vec::Vec;
|
||||||
|
use serai_abi::{
|
||||||
|
primitives::{
|
||||||
|
crypto::{Public, SignedEmbeddedEllipticCurveKeys},
|
||||||
|
network_id::NetworkId,
|
||||||
|
balance::Balance,
|
||||||
|
},
|
||||||
|
Event,
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||||
|
|
||||||
extern crate alloc;
|
#[cfg(target_family = "wasm")]
|
||||||
|
mod wasm;
|
||||||
|
|
||||||
use alloc::{borrow::Cow, vec::Vec};
|
/// The genesis configuration for Serai.
|
||||||
|
#[derive(scale::Encode, scale::Decode)]
|
||||||
use sp_core::{ConstU32, ConstU64, sr25519::Public};
|
pub struct GenesisConfig {
|
||||||
use sp_runtime::{Perbill, Weight};
|
/// The genesis validators for the network.
|
||||||
use sp_version::RuntimeVersion;
|
pub validators: Vec<(Public, Vec<SignedEmbeddedEllipticCurveKeys>)>,
|
||||||
|
/// The accounts to start with balances, intended solely for testing purposes.
|
||||||
use serai_abi::{
|
pub coins: Vec<(Public, Balance)>,
|
||||||
primitives::{
|
|
||||||
network_id::{ExternalNetworkId, NetworkId},
|
|
||||||
balance::{Amount, ExternalBalance},
|
|
||||||
validator_sets::ValidatorSet,
|
|
||||||
address::SeraiAddress,
|
|
||||||
},
|
|
||||||
SubstrateHeader as Header, SubstrateBlock,
|
|
||||||
};
|
|
||||||
|
|
||||||
use serai_coins_pallet::{CoinsInstance, LiquidityTokensInstance};
|
|
||||||
|
|
||||||
type Block = SubstrateBlock;
|
|
||||||
|
|
||||||
/// The lookup for a SeraiAddress -> Public.
|
|
||||||
pub struct Lookup;
|
|
||||||
impl sp_runtime::traits::StaticLookup for Lookup {
|
|
||||||
type Source = SeraiAddress;
|
|
||||||
type Target = Public;
|
|
||||||
fn lookup(source: SeraiAddress) -> Result<Public, sp_runtime::traits::LookupError> {
|
|
||||||
Ok(source.into())
|
|
||||||
}
|
|
||||||
fn unlookup(source: Public) -> SeraiAddress {
|
|
||||||
source.into()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove
|
|
||||||
#[sp_version::runtime_version]
|
|
||||||
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
|
||||||
spec_name: Cow::Borrowed("serai"),
|
|
||||||
impl_name: Cow::Borrowed("core"),
|
|
||||||
authoring_version: 0,
|
|
||||||
spec_version: 0,
|
|
||||||
impl_version: 0,
|
|
||||||
apis: RUNTIME_API_VERSIONS,
|
|
||||||
transaction_version: 0,
|
|
||||||
system_version: 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
frame_support::parameter_types! {
|
|
||||||
pub const Version: RuntimeVersion = VERSION;
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
pub BlockLength: frame_system::limits::BlockLength =
|
|
||||||
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(
|
|
||||||
2u64 * frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND,
|
|
||||||
u64::MAX,
|
|
||||||
),
|
|
||||||
Perbill::from_percent(75),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[frame_support::runtime]
|
|
||||||
mod runtime {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[runtime::runtime]
|
|
||||||
#[runtime::derive(RuntimeCall, RuntimeEvent, RuntimeError, RuntimeOrigin)]
|
|
||||||
pub struct Runtime;
|
|
||||||
|
|
||||||
#[runtime::pallet_index(0)]
|
|
||||||
pub type System = frame_system::Pallet<Runtime>;
|
|
||||||
|
|
||||||
#[runtime::pallet_index(1)]
|
|
||||||
pub type Core = serai_core_pallet::Pallet<Runtime>;
|
|
||||||
|
|
||||||
#[runtime::pallet_index(2)]
|
|
||||||
pub type Coins = serai_coins_pallet::Pallet<Runtime, CoinsInstance>;
|
|
||||||
|
|
||||||
#[runtime::pallet_index(3)]
|
|
||||||
pub type ValidatorSets = serai_validator_sets_pallet::Pallet<Runtime>;
|
|
||||||
|
|
||||||
#[runtime::pallet_index(4)]
|
|
||||||
pub type Signals = serai_signals_pallet::Pallet<Runtime>;
|
|
||||||
|
|
||||||
#[runtime::pallet_index(5)]
|
|
||||||
pub type LiquidityTokens = serai_coins_pallet::Pallet<Runtime, LiquidityTokensInstance>;
|
|
||||||
|
|
||||||
#[runtime::pallet_index(0xfe)]
|
|
||||||
pub type Babe = pallet_babe::Pallet<Runtime>;
|
|
||||||
|
|
||||||
#[runtime::pallet_index(0xff)]
|
|
||||||
pub type Grandpa = pallet_grandpa::Pallet<Runtime>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl frame_system::Config for Runtime {
|
|
||||||
type RuntimeEvent = RuntimeEvent;
|
|
||||||
type BaseCallFilter = frame_support::traits::Everything;
|
|
||||||
type BlockWeights = BlockWeights;
|
|
||||||
type BlockLength = BlockLength;
|
|
||||||
type RuntimeOrigin = RuntimeOrigin;
|
|
||||||
type RuntimeCall = RuntimeCall;
|
|
||||||
type RuntimeTask = ();
|
|
||||||
type Nonce = u32;
|
|
||||||
type Hash = <Self::Block as sp_runtime::traits::Block>::Hash;
|
|
||||||
type Hashing = sp_runtime::traits::BlakeTwo256;
|
|
||||||
type AccountId = sp_core::sr25519::Public;
|
|
||||||
type Lookup = Lookup;
|
|
||||||
type Block = Block;
|
|
||||||
// Don't track old block hashes within the System pallet
|
|
||||||
// We use not a number -> hash index, but a hash -> () index, in our own pallet
|
|
||||||
type BlockHashCount = ConstU64<1>;
|
|
||||||
type DbWeight = frame_support::weights::constants::RocksDbWeight;
|
|
||||||
type Version = Version;
|
|
||||||
type PalletInfo = PalletInfo;
|
|
||||||
type AccountData = ();
|
|
||||||
type OnNewAccount = ();
|
|
||||||
type OnKilledAccount = ();
|
|
||||||
// We use the default weights as we never expose/call any of these methods
|
|
||||||
type SystemWeightInfo = ();
|
|
||||||
// We also don't use the provided extensions framework
|
|
||||||
type ExtensionsWeightInfo = ();
|
|
||||||
// We don't invoke any hooks on-set-code as we don't perform upgrades via the blockchain yet via
|
|
||||||
// nodes, ensuring everyone who upgrades consents to the rules they upgrade to
|
|
||||||
type OnSetCode = ();
|
|
||||||
type MaxConsumers = ConstU32<{ u32::MAX }>;
|
|
||||||
// No migrations set
|
|
||||||
type SingleBlockMigrations = ();
|
|
||||||
type MultiBlockMigrator = ();
|
|
||||||
|
|
||||||
type PreInherents = serai_core_pallet::StartOfBlock<Runtime>;
|
|
||||||
type PostInherents = ();
|
|
||||||
type PostTransactions = serai_core_pallet::EndOfBlock<Runtime>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl serai_core_pallet::Config for Runtime {}
|
|
||||||
|
|
||||||
impl serai_coins_pallet::Config<CoinsInstance> for Runtime {
|
|
||||||
type AllowMint = serai_coins_pallet::AlwaysAllowMint; // TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub struct EconomicSecurity; // TODO
|
|
||||||
impl serai_abi::economic_security::EconomicSecurity for EconomicSecurity {
|
|
||||||
fn achieved_economic_security(_network: ExternalNetworkId) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
fn sri_value(_balance: ExternalBalance) -> Amount {
|
|
||||||
Amount(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl serai_validator_sets_pallet::Config for Runtime {
|
|
||||||
type ShouldEndSession = Babe;
|
|
||||||
type EconomicSecurity = EconomicSecurity;
|
|
||||||
}
|
|
||||||
impl serai_signals_pallet::Config for Runtime {
|
|
||||||
type RetirementValidityDuration = ConstU64<0>; // TODO
|
|
||||||
type RetirementLockInDuration = ConstU64<1>; // TODO
|
|
||||||
}
|
|
||||||
impl serai_coins_pallet::Config<LiquidityTokensInstance> for Runtime {
|
|
||||||
type AllowMint = serai_coins_pallet::AlwaysAllowMint;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
`pallet-babe` requires we implement `pallet-timestamp` for the associated constants. It does not
|
|
||||||
actually require we offer the timestamp pallet however, and we don't as we follow our methodology
|
|
||||||
(using the block header for timestamps, not an inherent transaction).
|
|
||||||
|
|
||||||
TODO: Set timestamp when executing a block.
|
|
||||||
*/
|
|
||||||
impl pallet_timestamp::Config for Runtime {
|
|
||||||
type Moment = u64;
|
|
||||||
type OnTimestampSet = Babe;
|
|
||||||
// TODO
|
|
||||||
type MinimumPeriod = ConstU64<{ (6 * 1000) / 2 }>;
|
|
||||||
type WeightInfo = ();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub struct GetCurrentSessionForSubstrate;
|
|
||||||
impl pallet_session::GetCurrentSessionForSubstrate for GetCurrentSessionForSubstrate {
|
|
||||||
fn get() -> u32 {
|
|
||||||
serai_validator_sets_pallet::Pallet::<Runtime>::current_session(NetworkId::Serai)
|
|
||||||
.map(|session| session.0)
|
|
||||||
.unwrap_or(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl pallet_session::Config for Runtime {
|
|
||||||
type Session = GetCurrentSessionForSubstrate;
|
|
||||||
}
|
|
||||||
|
|
||||||
type MaxAuthorities =
|
|
||||||
ConstU32<{ serai_abi::primitives::validator_sets::KeyShares::MAX_PER_SET_U32 }>;
|
|
||||||
impl pallet_babe::Config for Runtime {
|
|
||||||
// TODO
|
|
||||||
type EpochDuration = ConstU64<{ (7 * 24 * 60 * 60 * 1000) / (6 * 1000) }>;
|
|
||||||
|
|
||||||
type ExpectedBlockTime = ConstU64<{ 6 * 1000 }>; // TODO
|
|
||||||
type EpochChangeTrigger = pallet_babe::ExternalTrigger;
|
|
||||||
|
|
||||||
type WeightInfo = ();
|
|
||||||
type MaxAuthorities = MaxAuthorities;
|
|
||||||
type MaxNominators = ConstU32<1>;
|
|
||||||
|
|
||||||
// TODO: https://github.com/serai-dex/serai/issues/657
|
|
||||||
type DisabledValidators = ();
|
|
||||||
type KeyOwnerProof = sp_session::MembershipProof;
|
|
||||||
type EquivocationReportSystem = ();
|
|
||||||
}
|
|
||||||
impl pallet_grandpa::Config for Runtime {
|
|
||||||
type RuntimeEvent = RuntimeEvent;
|
|
||||||
|
|
||||||
type WeightInfo = ();
|
|
||||||
type MaxAuthorities = MaxAuthorities;
|
|
||||||
type MaxNominators = ConstU32<1>;
|
|
||||||
|
|
||||||
// TODO: https://github.com/serai-dex/serai/issues/657
|
|
||||||
type MaxSetIdSessionEntries = ConstU64<0>;
|
|
||||||
type KeyOwnerProof = sp_session::MembershipProof;
|
|
||||||
type EquivocationReportSystem = ();
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Option<SeraiAddress>> for RuntimeOrigin {
|
|
||||||
fn from(signer: Option<SeraiAddress>) -> Self {
|
|
||||||
match signer {
|
|
||||||
None => RuntimeOrigin::none(),
|
|
||||||
Some(signer) => RuntimeOrigin::signed(signer.into()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<serai_abi::Call> for RuntimeCall {
|
|
||||||
fn from(call: serai_abi::Call) -> Self {
|
|
||||||
match call {
|
|
||||||
serai_abi::Call::Coins(call) => {
|
|
||||||
use serai_abi::coins::Call;
|
|
||||||
use serai_coins_pallet::Call as Scall;
|
|
||||||
RuntimeCall::Coins(match call {
|
|
||||||
Call::transfer { to, coins } => Scall::transfer { to: to.into(), coins },
|
|
||||||
Call::burn { coins } => Scall::burn { coins },
|
|
||||||
Call::burn_with_instruction { instruction } => {
|
|
||||||
Scall::burn_with_instruction { instruction }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
serai_abi::Call::ValidatorSets(call) => {
|
|
||||||
use serai_abi::validator_sets::Call;
|
|
||||||
use serai_validator_sets_pallet::Call as Scall;
|
|
||||||
RuntimeCall::ValidatorSets(match call {
|
|
||||||
Call::set_keys { network, key_pair, signature_participants, signature } => {
|
|
||||||
Scall::set_keys { network, key_pair, signature_participants, signature }
|
|
||||||
}
|
|
||||||
Call::report_slashes { network, slashes, signature } => {
|
|
||||||
Scall::report_slashes { network, slashes, signature }
|
|
||||||
}
|
|
||||||
Call::set_embedded_elliptic_curve_keys { keys } => {
|
|
||||||
Scall::set_embedded_elliptic_curve_keys { keys }
|
|
||||||
}
|
|
||||||
Call::allocate { network, amount } => Scall::allocate { network, amount },
|
|
||||||
Call::deallocate { network, amount } => Scall::deallocate { network, amount },
|
|
||||||
Call::claim_deallocation { deallocation } => Scall::claim_deallocation {
|
|
||||||
network: deallocation.network,
|
|
||||||
session: deallocation.session,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
serai_abi::Call::Signals(call) => {
|
|
||||||
use serai_abi::signals::Call;
|
|
||||||
use serai_signals_pallet::Call as Scall;
|
|
||||||
RuntimeCall::Signals(match call {
|
|
||||||
Call::register_retirement_signal { in_favor_of } => {
|
|
||||||
Scall::register_retirement_signal { in_favor_of }
|
|
||||||
}
|
|
||||||
Call::revoke_retirement_signal { was_in_favor_of } => {
|
|
||||||
Scall::revoke_retirement_signal { retirement_signal: was_in_favor_of }
|
|
||||||
}
|
|
||||||
Call::favor { signal, with_network } => Scall::favor { signal, with_network },
|
|
||||||
Call::revoke_favor { signal, with_network } => {
|
|
||||||
Scall::revoke_favor { signal, with_network }
|
|
||||||
}
|
|
||||||
Call::stand_against { signal, with_network } => {
|
|
||||||
Scall::stand_against { signal, with_network }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
serai_abi::Call::Dex(call) => {
|
|
||||||
use serai_abi::dex::Call;
|
|
||||||
match call {
|
|
||||||
Call::transfer_liquidity { to, liquidity_tokens } => {
|
|
||||||
RuntimeCall::LiquidityTokens(serai_coins_pallet::Call::transfer {
|
|
||||||
to: to.into(),
|
|
||||||
coins: liquidity_tokens.into(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
Call::add_liquidity { .. } |
|
|
||||||
Call::remove_liquidity { .. } |
|
|
||||||
Call::swap_exact { .. } |
|
|
||||||
Call::swap_for_exact { .. } => todo!("TODO"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
serai_abi::Call::GenesisLiquidity(call) => {
|
|
||||||
use serai_abi::genesis_liquidity::Call;
|
|
||||||
match call {
|
|
||||||
Call::oraclize_values { .. } | Call::remove_liquidity { .. } => todo!("TODO"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
serai_abi::Call::InInstructions(call) => {
|
|
||||||
use serai_abi::in_instructions::Call;
|
|
||||||
match call {
|
|
||||||
Call::execute_batch { .. } => todo!("TODO"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Executive = frame_executive::Executive<Runtime, Block, Context, Runtime, AllPalletsWithSystem>;
|
|
||||||
|
|
||||||
sp_api::decl_runtime_apis! {
|
sp_api::decl_runtime_apis! {
|
||||||
#[api_version(1)]
|
|
||||||
pub trait GenesisApi {
|
pub trait GenesisApi {
|
||||||
fn build(genesis: RuntimeGenesisConfig);
|
fn build(genesis: GenesisConfig);
|
||||||
}
|
}
|
||||||
#[api_version(1)]
|
|
||||||
pub trait SeraiApi {
|
pub trait SeraiApi {
|
||||||
|
fn events() -> Vec<Vec<u8>>;
|
||||||
fn validators(network_id: NetworkId) -> Vec<Public>;
|
fn validators(network_id: NetworkId) -> Vec<Public>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
|
// We stub `impl_runtime_apis` to generate the `RuntimeApi` object the node needs
|
||||||
pub const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration =
|
#[cfg(not(target_family = "wasm"))]
|
||||||
sp_consensus_babe::BabeEpochConfiguration {
|
mod apis {
|
||||||
c: PRIMARY_PROBABILITY,
|
use alloc::borrow::Cow;
|
||||||
allowed_slots: sp_consensus_babe::AllowedSlots::PrimaryAndSecondaryPlainSlots,
|
use serai_abi::{SubstrateHeader as Header, SubstrateBlock as Block};
|
||||||
|
|
||||||
|
#[sp_version::runtime_version]
|
||||||
|
pub const VERSION: sp_version::RuntimeVersion = sp_version::RuntimeVersion {
|
||||||
|
spec_name: Cow::Borrowed("serai"),
|
||||||
|
impl_name: Cow::Borrowed("core"),
|
||||||
|
authoring_version: 0,
|
||||||
|
// Use the highest possible value so the node doesn't attempt to use this in place of the WASM
|
||||||
|
spec_version: 0xffffffff,
|
||||||
|
impl_version: 0,
|
||||||
|
apis: RUNTIME_API_VERSIONS,
|
||||||
|
transaction_version: 0,
|
||||||
|
system_version: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
sp_api::impl_runtime_apis! {
|
/// A `struct` representing the runtime as necessary to define the available APIs.
|
||||||
impl crate::GenesisApi<Block> for Runtime {
|
pub struct Runtime;
|
||||||
fn build(genesis: RuntimeGenesisConfig) {
|
sp_api::impl_runtime_apis! {
|
||||||
Core::genesis();
|
impl sp_api::Core<Block> for Runtime {
|
||||||
Core::start_transaction();
|
fn version() -> sp_version::RuntimeVersion {
|
||||||
<RuntimeGenesisConfig as frame_support::traits::BuildGenesisConfig>::build(&genesis);
|
VERSION
|
||||||
Core::end_transaction([0; 32]);
|
}
|
||||||
<
|
fn initialize_block(header: &Header) -> sp_runtime::ExtrinsicInclusionMode {
|
||||||
serai_core_pallet::EndOfBlock<Runtime> as frame_support::traits::PostTransactions
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
>::post_transactions();
|
}
|
||||||
}
|
fn execute_block(block: Block) {
|
||||||
}
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
|
|
||||||
impl sp_api::Core<Block> for Runtime {
|
|
||||||
fn version() -> RuntimeVersion {
|
|
||||||
VERSION
|
|
||||||
}
|
|
||||||
fn initialize_block(header: &Header) -> sp_runtime::ExtrinsicInclusionMode {
|
|
||||||
Executive::initialize_block(header)
|
|
||||||
}
|
|
||||||
fn execute_block(block: Block) {
|
|
||||||
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 {
|
impl sp_block_builder::BlockBuilder<Block> for Runtime {
|
||||||
Babe::current_epoch_start()
|
fn apply_extrinsic(
|
||||||
}
|
extrinsic: <Block as sp_runtime::traits::Block>::Extrinsic,
|
||||||
|
) -> sp_runtime::ApplyExtrinsicResult {
|
||||||
fn current_epoch() -> sp_consensus_babe::Epoch {
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
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 finalize_block() -> Header {
|
||||||
fn validators(network: NetworkId) -> Vec<Public> {
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
// 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
|
fn inherent_extrinsics(
|
||||||
// online again, this may cause a liveness failure.
|
data: sp_inherents::InherentData,
|
||||||
//
|
) -> Vec<<Block as sp_runtime::traits::Block>::Extrinsic> {
|
||||||
// This is assumed not to matter in real life, yet an interesting note.
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
let Some(session) = ValidatorSets::latest_decided_session(network) else {
|
}
|
||||||
return alloc::vec![]
|
|
||||||
};
|
fn check_inherents(
|
||||||
ValidatorSets::selected_validators(ValidatorSet { network, session })
|
block: Block,
|
||||||
.map(|validator| validator.0)
|
data: sp_inherents::InherentData,
|
||||||
.collect()
|
) -> sp_inherents::CheckInherentsResult {
|
||||||
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl sp_consensus_babe::BabeApi<Block> for Runtime {
|
||||||
|
fn configuration() -> sp_consensus_babe::BabeConfiguration {
|
||||||
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn current_epoch_start() -> sp_consensus_babe::Slot {
|
||||||
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn current_epoch() -> sp_consensus_babe::Epoch {
|
||||||
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next_epoch() -> sp_consensus_babe::Epoch {
|
||||||
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generate_key_ownership_proof(
|
||||||
|
_slot: sp_consensus_babe::Slot,
|
||||||
|
_authority_id: sp_consensus_babe::AuthorityId,
|
||||||
|
) -> Option<sp_consensus_babe::OpaqueKeyOwnershipProof> {
|
||||||
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn submit_report_equivocation_unsigned_extrinsic(
|
||||||
|
equivocation_proof: sp_consensus_babe::EquivocationProof<Header>,
|
||||||
|
_: sp_consensus_babe::OpaqueKeyOwnershipProof,
|
||||||
|
) -> Option<()> {
|
||||||
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl sp_consensus_grandpa::GrandpaApi<Block> for Runtime {
|
||||||
|
fn grandpa_authorities() -> sp_consensus_grandpa::AuthorityList {
|
||||||
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn current_set_id() -> sp_consensus_grandpa::SetId {
|
||||||
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generate_key_ownership_proof(
|
||||||
|
_set_id: sp_consensus_grandpa::SetId,
|
||||||
|
_authority_id: sp_consensus_grandpa::AuthorityId,
|
||||||
|
) -> Option<sp_consensus_grandpa::OpaqueKeyOwnershipProof> {
|
||||||
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
|
}
|
||||||
|
|
||||||
|
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<()> {
|
||||||
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl sp_authority_discovery::AuthorityDiscoveryApi<Block> for Runtime {
|
||||||
|
fn authorities() -> Vec<sp_authority_discovery::AuthorityId> {
|
||||||
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl crate::SeraiApi<Block> for Runtime {
|
||||||
|
fn events() -> Vec<Vec<u8>> {
|
||||||
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
|
}
|
||||||
|
fn validators(
|
||||||
|
network: serai_abi::primitives::network_id::NetworkId
|
||||||
|
) -> Vec<serai_abi::primitives::crypto::Public> {
|
||||||
|
unimplemented!("runtime is only implemented when WASM")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
#[derive(Clone, Default, PartialEq, Eq, Debug)]
|
pub use apis::RuntimeApi;
|
||||||
struct Context;
|
|
||||||
impl serai_abi::TransactionContext for Context {
|
|
||||||
// TODO
|
|
||||||
const SIGNED_WEIGHT: Weight = Weight::zero();
|
|
||||||
|
|
||||||
type RuntimeCall = RuntimeCall;
|
|
||||||
|
|
||||||
/// The implicit context to verify transactions with.
|
|
||||||
fn implicit_context() -> serai_abi::ImplicitContext {
|
|
||||||
serai_abi::ImplicitContext {
|
|
||||||
genesis: System::block_hash(0).into(),
|
|
||||||
protocol_id: [0; 32], // TODO via build script
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// If a block is present in the blockchain.
|
|
||||||
fn block_is_present_in_blockchain(&self, hash: &serai_abi::primitives::BlockHash) -> bool {
|
|
||||||
serai_core_pallet::Pallet::<Runtime>::block_exists(hash)
|
|
||||||
}
|
|
||||||
/// The time embedded into the current block.
|
|
||||||
fn current_time(&self) -> Option<u64> {
|
|
||||||
todo!("TODO")
|
|
||||||
}
|
|
||||||
/// Get the next nonce for an account.
|
|
||||||
fn next_nonce(&self, signer: &SeraiAddress) -> u32 {
|
|
||||||
serai_core_pallet::Pallet::<Runtime>::next_nonce(signer)
|
|
||||||
}
|
|
||||||
/// If the signer can pay the SRI fee.
|
|
||||||
fn can_pay_fee(
|
|
||||||
&self,
|
|
||||||
signer: &SeraiAddress,
|
|
||||||
fee: serai_abi::primitives::balance::Amount,
|
|
||||||
) -> Result<(), sp_runtime::transaction_validity::TransactionValidityError> {
|
|
||||||
use serai_abi::primitives::coin::Coin;
|
|
||||||
if serai_coins_pallet::Pallet::<Runtime, CoinsInstance>::balance(signer, Coin::Serai) >= fee {
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(sp_runtime::transaction_validity::TransactionValidityError::Invalid(
|
|
||||||
sp_runtime::transaction_validity::InvalidTransaction::Payment,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn start_transaction(&self) {
|
|
||||||
Core::start_transaction()
|
|
||||||
}
|
|
||||||
fn consume_next_nonce(&self, signer: &SeraiAddress) {
|
|
||||||
serai_core_pallet::Pallet::<Runtime>::consume_next_nonce(signer)
|
|
||||||
}
|
|
||||||
/// Have the transaction pay its SRI fee.
|
|
||||||
fn pay_fee(
|
|
||||||
&self,
|
|
||||||
signer: &SeraiAddress,
|
|
||||||
fee: serai_abi::primitives::balance::Amount,
|
|
||||||
) -> Result<(), sp_runtime::transaction_validity::TransactionValidityError> {
|
|
||||||
use serai_abi::primitives::{coin::*, balance::*};
|
|
||||||
serai_coins_pallet::Pallet::<Runtime, CoinsInstance>::burn(
|
|
||||||
RuntimeOrigin::signed(Public::from(*signer)),
|
|
||||||
Balance { coin: Coin::Serai, amount: fee },
|
|
||||||
)
|
|
||||||
.map_err(|_| {
|
|
||||||
sp_runtime::transaction_validity::TransactionValidityError::Invalid(
|
|
||||||
sp_runtime::transaction_validity::InvalidTransaction::Payment,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
fn end_transaction(&self, transaction_hash: [u8; 32]) {
|
|
||||||
Core::end_transaction(transaction_hash);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO
|
|
||||||
use validator_sets::MembershipProof;
|
|
||||||
|
|
||||||
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
|
|
||||||
|
|
||||||
parameter_types! {
|
|
||||||
pub const Version: RuntimeVersion = VERSION;
|
|
||||||
|
|
||||||
pub const SS58Prefix: u8 = 42; // TODO: Remove for Bech32m
|
|
||||||
|
|
||||||
// 1 MB block size limit
|
|
||||||
pub BlockLength: system::limits::BlockLength =
|
|
||||||
system::limits::BlockLength::max_with_normal_ratio(BLOCK_SIZE, NORMAL_DISPATCH_RATIO);
|
|
||||||
pub BlockWeights: system::limits::BlockWeights =
|
|
||||||
system::limits::BlockWeights::with_sensible_defaults(
|
|
||||||
Weight::from_parts(2u64 * WEIGHT_REF_TIME_PER_SECOND, u64::MAX),
|
|
||||||
NORMAL_DISPATCH_RATIO,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl timestamp::Config for Runtime {
|
|
||||||
type Moment = u64;
|
|
||||||
type OnTimestampSet = Babe;
|
|
||||||
type MinimumPeriod = ConstU64<{ (TARGET_BLOCK_TIME * 1000) / 2 }>;
|
|
||||||
type WeightInfo = ();
|
|
||||||
}
|
|
||||||
|
|
||||||
impl coins::Config for Runtime {
|
|
||||||
type AllowMint = ValidatorSets;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl dex::Config for Runtime {
|
|
||||||
type LPFee = ConstU32<3>; // 0.3%
|
|
||||||
type MintMinLiquidity = ConstU64<10000>;
|
|
||||||
|
|
||||||
type MaxSwapPathLength = ConstU32<3>; // coin1 -> SRI -> coin2
|
|
||||||
|
|
||||||
type MedianPriceWindowLength = ConstU16<{ MEDIAN_PRICE_WINDOW_LENGTH }>;
|
|
||||||
|
|
||||||
type WeightInfo = dex::weights::SubstrateWeight<Runtime>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct IdentityValidatorIdOf;
|
|
||||||
impl Convert<PublicKey, Option<PublicKey>> for IdentityValidatorIdOf {
|
|
||||||
fn convert(key: PublicKey) -> Option<PublicKey> {
|
|
||||||
Some(key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl signals::Config for Runtime {
|
|
||||||
type RuntimeEvent = RuntimeEvent;
|
|
||||||
// 1 week
|
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
|
||||||
type RetirementValidityDuration = ConstU32<{ (7 * 24 * 60 * 60) / (TARGET_BLOCK_TIME as u32) }>;
|
|
||||||
// 2 weeks
|
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
|
||||||
type RetirementLockInDuration = ConstU32<{ (2 * 7 * 24 * 60 * 60) / (TARGET_BLOCK_TIME as u32) }>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl in_instructions::Config for Runtime {
|
|
||||||
type RuntimeEvent = RuntimeEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl genesis_liquidity::Config for Runtime {
|
|
||||||
type RuntimeEvent = RuntimeEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl emissions::Config for Runtime {
|
|
||||||
type RuntimeEvent = RuntimeEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl economic_security::Config for Runtime {
|
|
||||||
type RuntimeEvent = RuntimeEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
// for publishing equivocation evidences.
|
|
||||||
impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
|
|
||||||
where
|
|
||||||
RuntimeCall: From<C>,
|
|
||||||
{
|
|
||||||
type Extrinsic = Transaction;
|
|
||||||
type OverarchingCall = RuntimeCall;
|
|
||||||
}
|
|
||||||
|
|
||||||
// for validating equivocation evidences.
|
|
||||||
// The following runtime construction doesn't actually implement the pallet as doing so is
|
|
||||||
// unnecessary
|
|
||||||
// TODO: Replace the requirement on Config for a requirement on FindAuthor directly
|
|
||||||
impl pallet_authorship::Config for Runtime {
|
|
||||||
type FindAuthor = ValidatorSets;
|
|
||||||
type EventHandler = ();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Longevity of an offence report.
|
|
||||||
pub type ReportLongevity = <Runtime as pallet_babe::Config>::EpochDuration;
|
|
||||||
|
|
||||||
#[cfg(feature = "runtime-benchmarks")]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate frame_benchmarking;
|
|
||||||
|
|
||||||
#[cfg(feature = "runtime-benchmarks")]
|
|
||||||
mod benches {
|
|
||||||
define_benchmarks!(
|
|
||||||
[frame_benchmarking, BaselineBench::<Runtime>]
|
|
||||||
|
|
||||||
[system, SystemBench::<Runtime>]
|
|
||||||
|
|
||||||
[pallet_timestamp, Timestamp]
|
|
||||||
|
|
||||||
[balances, Balances]
|
|
||||||
|
|
||||||
[babe, Babe]
|
|
||||||
[grandpa, Grandpa]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
sp_api::impl_runtime_apis! {
|
|
||||||
impl validator_sets::ValidatorSetsApi<Block> for Runtime {
|
|
||||||
fn external_network_key(network: ExternalNetworkId) -> Option<Vec<u8>> {
|
|
||||||
ValidatorSets::external_network_key(network)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl dex::DexApi<Block> for Runtime {
|
|
||||||
fn quote_price_exact_tokens_for_tokens(
|
|
||||||
coin1: Coin,
|
|
||||||
coin2: Coin,
|
|
||||||
amount: SubstrateAmount,
|
|
||||||
include_fee: bool
|
|
||||||
) -> Option<SubstrateAmount> {
|
|
||||||
Dex::quote_price_exact_tokens_for_tokens(coin1, coin2, amount, include_fee)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn quote_price_tokens_for_exact_tokens(
|
|
||||||
coin1: Coin,
|
|
||||||
coin2: Coin,
|
|
||||||
amount: SubstrateAmount,
|
|
||||||
include_fee: bool
|
|
||||||
) -> Option<SubstrateAmount> {
|
|
||||||
Dex::quote_price_tokens_for_exact_tokens(coin1, coin2, amount, include_fee)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_reserves(coin1: Coin, coin2: Coin) -> Option<(SubstrateAmount, SubstrateAmount)> {
|
|
||||||
Dex::get_reserves(&coin1, &coin2).ok()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|||||||
747
substrate/runtime/src/wasm/mod.rs
Normal file
747
substrate/runtime/src/wasm/mod.rs
Normal file
@@ -0,0 +1,747 @@
|
|||||||
|
use core::marker::PhantomData;
|
||||||
|
use alloc::{borrow::Cow, vec, vec::Vec};
|
||||||
|
|
||||||
|
use sp_core::{ConstU32, ConstU64, sr25519::Public};
|
||||||
|
use sp_runtime::{Perbill, Weight};
|
||||||
|
use sp_version::RuntimeVersion;
|
||||||
|
|
||||||
|
use serai_abi::{
|
||||||
|
primitives::{
|
||||||
|
network_id::{ExternalNetworkId, NetworkId},
|
||||||
|
balance::{Amount, ExternalBalance},
|
||||||
|
validator_sets::ValidatorSet,
|
||||||
|
address::SeraiAddress,
|
||||||
|
},
|
||||||
|
SubstrateHeader as Header, SubstrateBlock,
|
||||||
|
};
|
||||||
|
|
||||||
|
use serai_coins_pallet::{CoinsInstance, LiquidityTokensInstance};
|
||||||
|
|
||||||
|
type Block = SubstrateBlock;
|
||||||
|
|
||||||
|
/// The lookup for a SeraiAddress -> Public.
|
||||||
|
pub struct Lookup;
|
||||||
|
impl sp_runtime::traits::StaticLookup for Lookup {
|
||||||
|
type Source = SeraiAddress;
|
||||||
|
type Target = Public;
|
||||||
|
fn lookup(source: SeraiAddress) -> Result<Public, sp_runtime::traits::LookupError> {
|
||||||
|
Ok(source.into())
|
||||||
|
}
|
||||||
|
fn unlookup(source: Public) -> SeraiAddress {
|
||||||
|
source.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Remove
|
||||||
|
#[sp_version::runtime_version]
|
||||||
|
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||||
|
spec_name: Cow::Borrowed("serai"),
|
||||||
|
impl_name: Cow::Borrowed("core"),
|
||||||
|
authoring_version: 0,
|
||||||
|
spec_version: 0,
|
||||||
|
impl_version: 0,
|
||||||
|
apis: RUNTIME_API_VERSIONS,
|
||||||
|
transaction_version: 0,
|
||||||
|
system_version: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
frame_support::parameter_types! {
|
||||||
|
pub const Version: RuntimeVersion = VERSION;
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
pub BlockLength: frame_system::limits::BlockLength =
|
||||||
|
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(
|
||||||
|
2u64 * frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND,
|
||||||
|
u64::MAX,
|
||||||
|
),
|
||||||
|
Perbill::from_percent(75),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[frame_support::runtime]
|
||||||
|
mod runtime {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[runtime::runtime]
|
||||||
|
#[runtime::derive(RuntimeCall, RuntimeEvent, RuntimeError, RuntimeOrigin)]
|
||||||
|
pub struct Runtime;
|
||||||
|
|
||||||
|
#[runtime::pallet_index(0)]
|
||||||
|
pub type System = frame_system::Pallet<Runtime>;
|
||||||
|
|
||||||
|
#[runtime::pallet_index(1)]
|
||||||
|
pub type Core = serai_core_pallet::Pallet<Runtime>;
|
||||||
|
|
||||||
|
#[runtime::pallet_index(2)]
|
||||||
|
pub type Coins = serai_coins_pallet::Pallet<Runtime, CoinsInstance>;
|
||||||
|
|
||||||
|
#[runtime::pallet_index(3)]
|
||||||
|
pub type ValidatorSets = serai_validator_sets_pallet::Pallet<Runtime>;
|
||||||
|
|
||||||
|
#[runtime::pallet_index(4)]
|
||||||
|
pub type Signals = serai_signals_pallet::Pallet<Runtime>;
|
||||||
|
|
||||||
|
#[runtime::pallet_index(5)]
|
||||||
|
pub type LiquidityTokens = serai_coins_pallet::Pallet<Runtime, LiquidityTokensInstance>;
|
||||||
|
|
||||||
|
#[runtime::pallet_index(0xfe)]
|
||||||
|
pub type Babe = pallet_babe::Pallet<Runtime>;
|
||||||
|
|
||||||
|
#[runtime::pallet_index(0xff)]
|
||||||
|
pub type Grandpa = pallet_grandpa::Pallet<Runtime>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl frame_system::Config for Runtime {
|
||||||
|
type RuntimeEvent = RuntimeEvent;
|
||||||
|
type BaseCallFilter = frame_support::traits::Everything;
|
||||||
|
type BlockWeights = BlockWeights;
|
||||||
|
type BlockLength = BlockLength;
|
||||||
|
type RuntimeOrigin = RuntimeOrigin;
|
||||||
|
type RuntimeCall = RuntimeCall;
|
||||||
|
type RuntimeTask = ();
|
||||||
|
type Nonce = u32;
|
||||||
|
type Hash = <Self::Block as sp_runtime::traits::Block>::Hash;
|
||||||
|
type Hashing = sp_runtime::traits::BlakeTwo256;
|
||||||
|
type AccountId = sp_core::sr25519::Public;
|
||||||
|
type Lookup = Lookup;
|
||||||
|
type Block = Block;
|
||||||
|
// Don't track old block hashes within the System pallet
|
||||||
|
// We use not a number -> hash index, but a hash -> () index, in our own pallet
|
||||||
|
type BlockHashCount = ConstU64<1>;
|
||||||
|
type DbWeight = frame_support::weights::constants::RocksDbWeight;
|
||||||
|
type Version = Version;
|
||||||
|
type PalletInfo = PalletInfo;
|
||||||
|
type AccountData = ();
|
||||||
|
type OnNewAccount = ();
|
||||||
|
type OnKilledAccount = ();
|
||||||
|
// We use the default weights as we never expose/call any of these methods
|
||||||
|
type SystemWeightInfo = ();
|
||||||
|
// We also don't use the provided extensions framework
|
||||||
|
type ExtensionsWeightInfo = ();
|
||||||
|
// We don't invoke any hooks on-set-code as we don't perform upgrades via the blockchain yet via
|
||||||
|
// nodes, ensuring everyone who upgrades consents to the rules they upgrade to
|
||||||
|
type OnSetCode = ();
|
||||||
|
type MaxConsumers = ConstU32<{ u32::MAX }>;
|
||||||
|
// No migrations set
|
||||||
|
type SingleBlockMigrations = ();
|
||||||
|
type MultiBlockMigrator = ();
|
||||||
|
|
||||||
|
type PreInherents = serai_core_pallet::StartOfBlock<Runtime>;
|
||||||
|
type PostInherents = ();
|
||||||
|
type PostTransactions = serai_core_pallet::EndOfBlock<Runtime>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl serai_core_pallet::Config for Runtime {}
|
||||||
|
|
||||||
|
impl serai_coins_pallet::Config<CoinsInstance> for Runtime {
|
||||||
|
type AllowMint = serai_coins_pallet::AlwaysAllowMint; // TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub struct EconomicSecurity; // TODO
|
||||||
|
impl serai_abi::economic_security::EconomicSecurity for EconomicSecurity {
|
||||||
|
fn achieved_economic_security(_network: ExternalNetworkId) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
fn sri_value(_balance: ExternalBalance) -> Amount {
|
||||||
|
Amount(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl serai_validator_sets_pallet::Config for Runtime {
|
||||||
|
type ShouldEndSession = Babe;
|
||||||
|
type EconomicSecurity = EconomicSecurity;
|
||||||
|
}
|
||||||
|
impl serai_signals_pallet::Config for Runtime {
|
||||||
|
type RetirementValidityDuration = ConstU64<0>; // TODO
|
||||||
|
type RetirementLockInDuration = ConstU64<1>; // TODO
|
||||||
|
}
|
||||||
|
impl serai_coins_pallet::Config<LiquidityTokensInstance> for Runtime {
|
||||||
|
type AllowMint = serai_coins_pallet::AlwaysAllowMint;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
`pallet-babe` requires we implement `pallet-timestamp` for the associated constants. It does not
|
||||||
|
actually require we offer the timestamp pallet however, and we don't as we follow our methodology
|
||||||
|
(using the block header for timestamps, not an inherent transaction).
|
||||||
|
|
||||||
|
TODO: Set timestamp when executing a block.
|
||||||
|
*/
|
||||||
|
impl pallet_timestamp::Config for Runtime {
|
||||||
|
type Moment = u64;
|
||||||
|
type OnTimestampSet = Babe;
|
||||||
|
// TODO
|
||||||
|
type MinimumPeriod = ConstU64<{ (6 * 1000) / 2 }>;
|
||||||
|
type WeightInfo = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub struct GetCurrentSessionForSubstrate;
|
||||||
|
impl pallet_session::GetCurrentSessionForSubstrate for GetCurrentSessionForSubstrate {
|
||||||
|
fn get() -> u32 {
|
||||||
|
serai_validator_sets_pallet::Pallet::<Runtime>::current_session(NetworkId::Serai)
|
||||||
|
.map(|session| session.0)
|
||||||
|
.unwrap_or(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl pallet_session::Config for Runtime {
|
||||||
|
type Session = GetCurrentSessionForSubstrate;
|
||||||
|
}
|
||||||
|
|
||||||
|
type MaxAuthorities =
|
||||||
|
ConstU32<{ serai_abi::primitives::validator_sets::KeyShares::MAX_PER_SET_U32 }>;
|
||||||
|
impl pallet_babe::Config for Runtime {
|
||||||
|
// TODO
|
||||||
|
type EpochDuration = ConstU64<{ (7 * 24 * 60 * 60 * 1000) / (6 * 1000) }>;
|
||||||
|
|
||||||
|
type ExpectedBlockTime = ConstU64<{ 6 * 1000 }>; // TODO
|
||||||
|
type EpochChangeTrigger = pallet_babe::ExternalTrigger;
|
||||||
|
|
||||||
|
type WeightInfo = ();
|
||||||
|
type MaxAuthorities = MaxAuthorities;
|
||||||
|
type MaxNominators = ConstU32<1>;
|
||||||
|
|
||||||
|
// TODO: https://github.com/serai-dex/serai/issues/657
|
||||||
|
type DisabledValidators = ();
|
||||||
|
type KeyOwnerProof = sp_session::MembershipProof;
|
||||||
|
type EquivocationReportSystem = ();
|
||||||
|
}
|
||||||
|
impl pallet_grandpa::Config for Runtime {
|
||||||
|
type RuntimeEvent = RuntimeEvent;
|
||||||
|
|
||||||
|
type WeightInfo = ();
|
||||||
|
type MaxAuthorities = MaxAuthorities;
|
||||||
|
type MaxNominators = ConstU32<1>;
|
||||||
|
|
||||||
|
// TODO: https://github.com/serai-dex/serai/issues/657
|
||||||
|
type MaxSetIdSessionEntries = ConstU64<0>;
|
||||||
|
type KeyOwnerProof = sp_session::MembershipProof;
|
||||||
|
type EquivocationReportSystem = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Option<SeraiAddress>> for RuntimeOrigin {
|
||||||
|
fn from(signer: Option<SeraiAddress>) -> Self {
|
||||||
|
match signer {
|
||||||
|
None => RuntimeOrigin::none(),
|
||||||
|
Some(signer) => RuntimeOrigin::signed(signer.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<serai_abi::Call> for RuntimeCall {
|
||||||
|
fn from(call: serai_abi::Call) -> Self {
|
||||||
|
match call {
|
||||||
|
serai_abi::Call::Coins(call) => {
|
||||||
|
use serai_abi::coins::Call;
|
||||||
|
use serai_coins_pallet::Call as Scall;
|
||||||
|
RuntimeCall::Coins(match call {
|
||||||
|
Call::transfer { to, coins } => Scall::transfer { to: to.into(), coins },
|
||||||
|
Call::burn { coins } => Scall::burn { coins },
|
||||||
|
Call::burn_with_instruction { instruction } => {
|
||||||
|
Scall::burn_with_instruction { instruction }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
serai_abi::Call::ValidatorSets(call) => {
|
||||||
|
use serai_abi::validator_sets::Call;
|
||||||
|
use serai_validator_sets_pallet::Call as Scall;
|
||||||
|
RuntimeCall::ValidatorSets(match call {
|
||||||
|
Call::set_keys { network, key_pair, signature_participants, signature } => {
|
||||||
|
Scall::set_keys { network, key_pair, signature_participants, signature }
|
||||||
|
}
|
||||||
|
Call::report_slashes { network, slashes, signature } => {
|
||||||
|
Scall::report_slashes { network, slashes, signature }
|
||||||
|
}
|
||||||
|
Call::set_embedded_elliptic_curve_keys { keys } => {
|
||||||
|
Scall::set_embedded_elliptic_curve_keys { keys }
|
||||||
|
}
|
||||||
|
Call::allocate { network, amount } => Scall::allocate { network, amount },
|
||||||
|
Call::deallocate { network, amount } => Scall::deallocate { network, amount },
|
||||||
|
Call::claim_deallocation { deallocation } => Scall::claim_deallocation {
|
||||||
|
network: deallocation.network,
|
||||||
|
session: deallocation.session,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
serai_abi::Call::Signals(call) => {
|
||||||
|
use serai_abi::signals::Call;
|
||||||
|
use serai_signals_pallet::Call as Scall;
|
||||||
|
RuntimeCall::Signals(match call {
|
||||||
|
Call::register_retirement_signal { in_favor_of } => {
|
||||||
|
Scall::register_retirement_signal { in_favor_of }
|
||||||
|
}
|
||||||
|
Call::revoke_retirement_signal { was_in_favor_of } => {
|
||||||
|
Scall::revoke_retirement_signal { retirement_signal: was_in_favor_of }
|
||||||
|
}
|
||||||
|
Call::favor { signal, with_network } => Scall::favor { signal, with_network },
|
||||||
|
Call::revoke_favor { signal, with_network } => {
|
||||||
|
Scall::revoke_favor { signal, with_network }
|
||||||
|
}
|
||||||
|
Call::stand_against { signal, with_network } => {
|
||||||
|
Scall::stand_against { signal, with_network }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
serai_abi::Call::Dex(call) => {
|
||||||
|
use serai_abi::dex::Call;
|
||||||
|
match call {
|
||||||
|
Call::transfer_liquidity { to, liquidity_tokens } => {
|
||||||
|
RuntimeCall::LiquidityTokens(serai_coins_pallet::Call::transfer {
|
||||||
|
to: to.into(),
|
||||||
|
coins: liquidity_tokens.into(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Call::add_liquidity { .. } |
|
||||||
|
Call::remove_liquidity { .. } |
|
||||||
|
Call::swap_exact { .. } |
|
||||||
|
Call::swap_for_exact { .. } => todo!("TODO"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
serai_abi::Call::GenesisLiquidity(call) => {
|
||||||
|
use serai_abi::genesis_liquidity::Call;
|
||||||
|
match call {
|
||||||
|
Call::oraclize_values { .. } | Call::remove_liquidity { .. } => todo!("TODO"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
serai_abi::Call::InInstructions(call) => {
|
||||||
|
use serai_abi::in_instructions::Call;
|
||||||
|
match call {
|
||||||
|
Call::execute_batch { .. } => todo!("TODO"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Executive = frame_executive::Executive<Runtime, Block, Context, Runtime, AllPalletsWithSystem>;
|
||||||
|
|
||||||
|
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: crate::GenesisConfig) {
|
||||||
|
let config = RuntimeGenesisConfig {
|
||||||
|
system: SystemConfig { _config: PhantomData },
|
||||||
|
|
||||||
|
coins: CoinsConfig {
|
||||||
|
accounts: genesis.coins.into_iter().map(|(key, balance)| (key.into(), balance)).collect(),
|
||||||
|
_instance: PhantomData,
|
||||||
|
},
|
||||||
|
|
||||||
|
liquidity_tokens: LiquidityTokensConfig { accounts: vec![], _instance: PhantomData },
|
||||||
|
|
||||||
|
validator_sets: ValidatorSetsConfig {
|
||||||
|
participants:
|
||||||
|
genesis.validators.into_iter().map(|(key, keys)| (key.into(), keys)).collect(),
|
||||||
|
},
|
||||||
|
signals: SignalsConfig::default(),
|
||||||
|
|
||||||
|
// We leave these `authorities` empty as `serai-validator-sets-pallet` initializes them
|
||||||
|
babe: BabeConfig {
|
||||||
|
authorities: vec![],
|
||||||
|
epoch_config: BABE_GENESIS_EPOCH_CONFIG,
|
||||||
|
_config: PhantomData,
|
||||||
|
},
|
||||||
|
grandpa: GrandpaConfig { authorities: vec![], _config: PhantomData },
|
||||||
|
};
|
||||||
|
|
||||||
|
Core::genesis();
|
||||||
|
Core::start_transaction();
|
||||||
|
<RuntimeGenesisConfig as frame_support::traits::BuildGenesisConfig>::build(&config);
|
||||||
|
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
|
||||||
|
}
|
||||||
|
fn initialize_block(header: &Header) -> sp_runtime::ExtrinsicInclusionMode {
|
||||||
|
Executive::initialize_block(header)
|
||||||
|
}
|
||||||
|
fn execute_block(block: Block) {
|
||||||
|
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: sp_consensus_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: sp_consensus_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 super::runtime_decl_for_serai_api::SeraiApi<Block>>::validators(network) {
|
||||||
|
all.insert(sp_core::sr25519::Public::from(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 events() -> Vec<Vec<u8>> {
|
||||||
|
Core::events()
|
||||||
|
}
|
||||||
|
fn validators(network: NetworkId) -> Vec<serai_abi::primitives::crypto::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 vec![]
|
||||||
|
};
|
||||||
|
ValidatorSets::selected_validators(ValidatorSet { network, session })
|
||||||
|
.map(|validator| validator.0.into())
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Default, PartialEq, Eq, Debug)]
|
||||||
|
struct Context;
|
||||||
|
impl serai_abi::TransactionContext for Context {
|
||||||
|
// TODO
|
||||||
|
const SIGNED_WEIGHT: Weight = Weight::zero();
|
||||||
|
|
||||||
|
type RuntimeCall = RuntimeCall;
|
||||||
|
|
||||||
|
/// The implicit context to verify transactions with.
|
||||||
|
fn implicit_context() -> serai_abi::ImplicitContext {
|
||||||
|
serai_abi::ImplicitContext {
|
||||||
|
genesis: System::block_hash(0).into(),
|
||||||
|
protocol_id: [0; 32], // TODO via build script
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// If a block is present in the blockchain.
|
||||||
|
fn block_is_present_in_blockchain(&self, hash: &serai_abi::primitives::BlockHash) -> bool {
|
||||||
|
serai_core_pallet::Pallet::<Runtime>::block_exists(hash)
|
||||||
|
}
|
||||||
|
/// The time embedded into the current block.
|
||||||
|
fn current_time(&self) -> Option<u64> {
|
||||||
|
todo!("TODO")
|
||||||
|
}
|
||||||
|
/// Get the next nonce for an account.
|
||||||
|
fn next_nonce(&self, signer: &SeraiAddress) -> u32 {
|
||||||
|
serai_core_pallet::Pallet::<Runtime>::next_nonce(signer)
|
||||||
|
}
|
||||||
|
/// If the signer can pay the SRI fee.
|
||||||
|
fn can_pay_fee(
|
||||||
|
&self,
|
||||||
|
signer: &SeraiAddress,
|
||||||
|
fee: serai_abi::primitives::balance::Amount,
|
||||||
|
) -> Result<(), sp_runtime::transaction_validity::TransactionValidityError> {
|
||||||
|
use serai_abi::primitives::coin::Coin;
|
||||||
|
if serai_coins_pallet::Pallet::<Runtime, CoinsInstance>::balance(signer, Coin::Serai) >= fee {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(sp_runtime::transaction_validity::TransactionValidityError::Invalid(
|
||||||
|
sp_runtime::transaction_validity::InvalidTransaction::Payment,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start_transaction(&self) {
|
||||||
|
Core::start_transaction()
|
||||||
|
}
|
||||||
|
fn consume_next_nonce(&self, signer: &SeraiAddress) {
|
||||||
|
serai_core_pallet::Pallet::<Runtime>::consume_next_nonce(signer)
|
||||||
|
}
|
||||||
|
/// Have the transaction pay its SRI fee.
|
||||||
|
fn pay_fee(
|
||||||
|
&self,
|
||||||
|
signer: &SeraiAddress,
|
||||||
|
fee: serai_abi::primitives::balance::Amount,
|
||||||
|
) -> Result<(), sp_runtime::transaction_validity::TransactionValidityError> {
|
||||||
|
use serai_abi::primitives::{coin::*, balance::*};
|
||||||
|
serai_coins_pallet::Pallet::<Runtime, CoinsInstance>::burn(
|
||||||
|
RuntimeOrigin::signed(Public::from(*signer)),
|
||||||
|
Balance { coin: Coin::Serai, amount: fee },
|
||||||
|
)
|
||||||
|
.map_err(|_| {
|
||||||
|
sp_runtime::transaction_validity::TransactionValidityError::Invalid(
|
||||||
|
sp_runtime::transaction_validity::InvalidTransaction::Payment,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fn end_transaction(&self, transaction_hash: [u8; 32]) {
|
||||||
|
Core::end_transaction(transaction_hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO
|
||||||
|
use validator_sets::MembershipProof;
|
||||||
|
|
||||||
|
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
|
||||||
|
|
||||||
|
parameter_types! {
|
||||||
|
pub const Version: RuntimeVersion = VERSION;
|
||||||
|
|
||||||
|
pub const SS58Prefix: u8 = 42; // TODO: Remove for Bech32m
|
||||||
|
|
||||||
|
// 1 MB block size limit
|
||||||
|
pub BlockLength: system::limits::BlockLength =
|
||||||
|
system::limits::BlockLength::max_with_normal_ratio(BLOCK_SIZE, NORMAL_DISPATCH_RATIO);
|
||||||
|
pub BlockWeights: system::limits::BlockWeights =
|
||||||
|
system::limits::BlockWeights::with_sensible_defaults(
|
||||||
|
Weight::from_parts(2u64 * WEIGHT_REF_TIME_PER_SECOND, u64::MAX),
|
||||||
|
NORMAL_DISPATCH_RATIO,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl timestamp::Config for Runtime {
|
||||||
|
type Moment = u64;
|
||||||
|
type OnTimestampSet = Babe;
|
||||||
|
type MinimumPeriod = ConstU64<{ (TARGET_BLOCK_TIME * 1000) / 2 }>;
|
||||||
|
type WeightInfo = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl coins::Config for Runtime {
|
||||||
|
type AllowMint = ValidatorSets;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl dex::Config for Runtime {
|
||||||
|
type LPFee = ConstU32<3>; // 0.3%
|
||||||
|
type MintMinLiquidity = ConstU64<10000>;
|
||||||
|
|
||||||
|
type MaxSwapPathLength = ConstU32<3>; // coin1 -> SRI -> coin2
|
||||||
|
|
||||||
|
type MedianPriceWindowLength = ConstU16<{ MEDIAN_PRICE_WINDOW_LENGTH }>;
|
||||||
|
|
||||||
|
type WeightInfo = dex::weights::SubstrateWeight<Runtime>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct IdentityValidatorIdOf;
|
||||||
|
impl Convert<PublicKey, Option<PublicKey>> for IdentityValidatorIdOf {
|
||||||
|
fn convert(key: PublicKey) -> Option<PublicKey> {
|
||||||
|
Some(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl signals::Config for Runtime {
|
||||||
|
type RuntimeEvent = RuntimeEvent;
|
||||||
|
// 1 week
|
||||||
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
|
type RetirementValidityDuration = ConstU32<{ (7 * 24 * 60 * 60) / (TARGET_BLOCK_TIME as u32) }>;
|
||||||
|
// 2 weeks
|
||||||
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
|
type RetirementLockInDuration = ConstU32<{ (2 * 7 * 24 * 60 * 60) / (TARGET_BLOCK_TIME as u32) }>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl in_instructions::Config for Runtime {
|
||||||
|
type RuntimeEvent = RuntimeEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl genesis_liquidity::Config for Runtime {
|
||||||
|
type RuntimeEvent = RuntimeEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl emissions::Config for Runtime {
|
||||||
|
type RuntimeEvent = RuntimeEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl economic_security::Config for Runtime {
|
||||||
|
type RuntimeEvent = RuntimeEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for publishing equivocation evidences.
|
||||||
|
impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime
|
||||||
|
where
|
||||||
|
RuntimeCall: From<C>,
|
||||||
|
{
|
||||||
|
type Extrinsic = Transaction;
|
||||||
|
type OverarchingCall = RuntimeCall;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for validating equivocation evidences.
|
||||||
|
// The following runtime construction doesn't actually implement the pallet as doing so is
|
||||||
|
// unnecessary
|
||||||
|
// TODO: Replace the requirement on Config for a requirement on FindAuthor directly
|
||||||
|
impl pallet_authorship::Config for Runtime {
|
||||||
|
type FindAuthor = ValidatorSets;
|
||||||
|
type EventHandler = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Longevity of an offence report.
|
||||||
|
pub type ReportLongevity = <Runtime as pallet_babe::Config>::EpochDuration;
|
||||||
|
|
||||||
|
#[cfg(feature = "runtime-benchmarks")]
|
||||||
|
#[macro_use]
|
||||||
|
extern crate frame_benchmarking;
|
||||||
|
|
||||||
|
#[cfg(feature = "runtime-benchmarks")]
|
||||||
|
mod benches {
|
||||||
|
define_benchmarks!(
|
||||||
|
[frame_benchmarking, BaselineBench::<Runtime>]
|
||||||
|
|
||||||
|
[system, SystemBench::<Runtime>]
|
||||||
|
|
||||||
|
[pallet_timestamp, Timestamp]
|
||||||
|
|
||||||
|
[balances, Balances]
|
||||||
|
|
||||||
|
[babe, Babe]
|
||||||
|
[grandpa, Grandpa]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sp_api::impl_runtime_apis! {
|
||||||
|
impl validator_sets::ValidatorSetsApi<Block> for Runtime {
|
||||||
|
fn external_network_key(network: ExternalNetworkId) -> Option<Vec<u8>> {
|
||||||
|
ValidatorSets::external_network_key(network)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl dex::DexApi<Block> for Runtime {
|
||||||
|
fn quote_price_exact_tokens_for_tokens(
|
||||||
|
coin1: Coin,
|
||||||
|
coin2: Coin,
|
||||||
|
amount: SubstrateAmount,
|
||||||
|
include_fee: bool
|
||||||
|
) -> Option<SubstrateAmount> {
|
||||||
|
Dex::quote_price_exact_tokens_for_tokens(coin1, coin2, amount, include_fee)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn quote_price_tokens_for_exact_tokens(
|
||||||
|
coin1: Coin,
|
||||||
|
coin2: Coin,
|
||||||
|
amount: SubstrateAmount,
|
||||||
|
include_fee: bool
|
||||||
|
) -> Option<SubstrateAmount> {
|
||||||
|
Dex::quote_price_tokens_for_exact_tokens(coin1, coin2, amount, include_fee)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_reserves(coin1: Coin, coin2: Coin) -> Option<(SubstrateAmount, SubstrateAmount)> {
|
||||||
|
Dex::get_reserves(&coin1, &coin2).ok()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
@@ -21,10 +21,10 @@ workspace = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
|
||||||
|
|
||||||
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
serai-abi = { path = "../abi", default-features = false, features = ["substrate"] }
|
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"] }
|
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 = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-application-crypto = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-application-crypto = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
pallet-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
pallet-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "726437c7bbff34ec322483dac2b657e126c22233", default-features = false }
|
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "71fa60b900c8ad068f1b9ce8100508506377fbf5", default-features = false }
|
||||||
|
|
||||||
serai-abi = { path = "../abi", default-features = false, features = ["substrate"] }
|
serai-abi = { path = "../abi", default-features = false, features = ["substrate"] }
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ frost-schnorrkel = { path = "../../crypto/schnorrkel", default-features = false,
|
|||||||
|
|
||||||
bitcoin-serai = { path = "../../networks/bitcoin", default-features = false, features = ["hazmat"], optional = true }
|
bitcoin-serai = { path = "../../networks/bitcoin", default-features = false, features = ["hazmat"], optional = true }
|
||||||
|
|
||||||
|
ethereum-schnorr-contract = { path = "../../networks/ethereum/schnorr", default-features = false }
|
||||||
|
|
||||||
serai-client-bitcoin = { path = "../../substrate/client/bitcoin", default-features = false, optional = true }
|
serai-client-bitcoin = { path = "../../substrate/client/bitcoin", default-features = false, optional = true }
|
||||||
serai-client-ethereum = { path = "../../substrate/client/ethereum", default-features = false, optional = true }
|
serai-client-ethereum = { path = "../../substrate/client/ethereum", default-features = false, optional = true }
|
||||||
|
|
||||||
@@ -79,6 +81,8 @@ alloc = [
|
|||||||
|
|
||||||
"bitcoin-serai",
|
"bitcoin-serai",
|
||||||
|
|
||||||
|
"ethereum-schnorr-contract/alloc",
|
||||||
|
|
||||||
"serai-client-bitcoin",
|
"serai-client-bitcoin",
|
||||||
"serai-client-ethereum",
|
"serai-client-ethereum",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ pub use embedwards25519;
|
|||||||
|
|
||||||
pub use schnorr_signatures;
|
pub use schnorr_signatures;
|
||||||
|
|
||||||
|
pub use ethereum_schnorr_contract;
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
pub mod alloc {
|
pub mod alloc {
|
||||||
pub use multiexp;
|
pub use multiexp;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ pub fn reproducibly_builds() {
|
|||||||
use dockertest::{PullPolicy, Image, TestBodySpecification, DockerTest};
|
use dockertest::{PullPolicy, Image, TestBodySpecification, DockerTest};
|
||||||
|
|
||||||
const RUNS: usize = 3;
|
const RUNS: usize = 3;
|
||||||
const TIMEOUT: u16 = 180 * 60; // 3 hours
|
const TIMEOUT: u16 = 3 * 60 * 60; // 3 hours
|
||||||
|
|
||||||
serai_docker_tests::build("runtime".to_string());
|
serai_docker_tests::build("runtime".to_string());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user