5 Commits

Author SHA1 Message Date
Luke Parker
94faf098b6 Update nightly version 2025-10-05 18:44:04 -04:00
Luke Parker
03e45f73cd Merge branch 'develop' into next 2025-10-05 18:43:53 -04:00
Luke Parker
63f7e220c0 Update macOS labels in CI due to deprecation of macos-13 2025-10-05 10:59:40 -04:00
Luke Parker
7d49366373 Move develop to patch-polkadot-sdk (#678)
* Update `build-dependencies` CI action

* Update `develop` to `patch-polkadot-sdk`

Allows us to finally remove the old `serai-dex/substrate` repository _and_
should have CI pass without issue on `develop` again.

The changes made here should be trivial and maintain all prior
behavior/functionality. The most notable are to `chain_spec.rs`, in order to
still use a SCALE-encoded `GenesisConfig` (avoiding `serde_json`).

* CI fixes

* Add `/usr/local/opt/llvm/lib` to paths on macOS hosts

* Attempt to use `LD_LIBRARY_PATH` in macOS GitHub CI

* Use `libp2p 0.56` in `serai-node`

* Correct Windows build dependencies

* Correct `llvm/lib` path on macOS

* Correct how macOS 13 and 14 have different homebrew paths

* Use `sw_vers` instead of `uname` on macOS

Yields the macOS version instead of the kernel's version.

* Replace hard-coded path with the intended env variable to fix macOS 13

* Add `libclang-dev` as dependency to the Debian Dockerfile

* Set the `CODE` storage slot

* Update to a version of substrate without `wasmtimer`

Turns out `wasmtimer` is WASM only. This should restore the node's functioning
on non-WASM environments.

* Restore `clang` as a dependency due to the Debian Dockerfile as we require a C++ compiler

* Move from Debian bookworm to trixie

* Restore `chain_getBlockBin` to the RPC

* Always generate a new key for the P2P network

* Mention every account on-chain before they publish a transaction

`CheckNonce` required accounts have a provider in order to even have their
nonce considered. This shims that by claiming every account has a provider at
the start of a block, if it signs a transaction.

The actual execution could presumably diverge between block building (which
sets the provider before each transaction) and execution (which sets the
providers at the start of the block). It doesn't diverge in our current
configuration and it won't be propagated to `next` (which doesn't use
`CheckNonce`).

Also uses explicit indexes for the `serai_abi::{Call, Event}` `enum`s.

* Adopt `patch-polkadot-sdk` with fixed peering

* Manually insert the authority discovery key into the keystore

I did try pulling in `pallet-authority-discovery` for this, updating
`SessionKeys`, but that was insufficient for whatever reason.

* Update to latest `substrate-wasm-builder`

* Fix timeline for incrementing providers

e1671dd71b incremented the providers for every
single transaction's sender before execution, noting the solution was fragile
but it worked for us at this time. It did not work for us at this time.

The new solution replaces `inc_providers` with direct access to the `Account`
`StorageMap` to increment the providers, achieving the desired goal, _without_
emitting an event (which is ordered, and the disparate order between building
and execution was causing mismatches of the state root).

This solution is also fragile and may also be insufficient. None of this code
exists anymore on `next` however. It just has to work sufficiently for now.

* clippy
2025-10-05 10:58:08 -04:00
Luke Parker
55ed33d2d1 Update to a version of Substrate which no longer cites our fork of substrate-bip39 2025-09-30 19:30:40 -04:00
103 changed files with 3017 additions and 4150 deletions

View File

@@ -38,11 +38,15 @@ runs:
shell: bash
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt install -y ca-certificates protobuf-compiler
sudo apt install -y ca-certificates protobuf-compiler libclang-dev
elif [ "$RUNNER_OS" == "Windows" ]; then
choco install protoc
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install protobuf
brew install protobuf llvm
HOMEBREW_ROOT_PATH=/opt/homebrew # macOS 14+
if [ $(sw_vers -productVersion | awk -F "." '{ print $1 }') = "13" ]; then HOMEBREW_ROOT_PATH=/usr/local; fi # macOS 13
ls $HOMEBREW_ROOT_PATH/opt/llvm/lib | grep "libclang.dylib" # Make sure this installed `libclang`
echo "DYLD_LIBRARY_PATH=$HOMEBREW_ROOT_PATH/opt/llvm/lib:$DYLD_LIBRARY_PATH" >> "$GITHUB_ENV"
fi
- name: Install solc

View File

@@ -1 +1 @@
nightly-2025-09-01
nightly-2025-10-01

View File

@@ -11,7 +11,7 @@ jobs:
clippy:
strategy:
matrix:
os: [ubuntu-latest, macos-13, macos-14, windows-latest]
os: [ubuntu-latest, macos-15-intel, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:

5241
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,19 +1,6 @@
[workspace]
resolver = "2"
members = [
# Version patches
"patches/parking_lot",
"patches/zstd",
"patches/rocksdb",
# std patches
"patches/matches",
"patches/is-terminal",
# Rewrites/redirects
"patches/option-ext",
"patches/directories-next",
"common/std-shims",
"common/zalloc",
"common/patchable-async-sleep",
@@ -198,17 +185,6 @@ modular-frost = { path = "crypto/frost" }
# https://github.com/rust-lang-nursery/lazy-static.rs/issues/201
lazy_static = { git = "https://github.com/rust-lang-nursery/lazy-static.rs", rev = "5735630d46572f1e5377c8f2ba0f79d18f53b10c" }
parking_lot = { path = "patches/parking_lot" }
# wasmtime pulls in an old version for this
zstd = { path = "patches/zstd" }
# Needed for WAL compression
rocksdb = { path = "patches/rocksdb" }
# is-terminal now has an std-based solution with an equivalent API
is-terminal = { path = "patches/is-terminal" }
# So does matches
matches = { path = "patches/matches" }
# directories-next was created because directories was unmaintained
# directories-next is now unmaintained while directories is maintained
# The directories author pulls in ridiculously pointless crates and prefers

View File

@@ -17,7 +17,7 @@ rustdoc-args = ["--cfg", "docsrs"]
workspace = true
[dependencies]
parity-db = { version = "0.4", default-features = false, optional = true }
parity-db = { version = "0.5", default-features = false, optional = true }
rocksdb = { version = "0.24", default-features = false, features = ["zstd"], optional = true }
[features]

View File

@@ -35,7 +35,7 @@ tributary-sdk = { path = "../../tributary-sdk" }
futures-util = { version = "0.3", default-features = false, features = ["std"] }
tokio = { version = "1", default-features = false, features = ["sync"] }
libp2p = { version = "0.54", default-features = false, features = ["tokio", "tcp", "noise", "yamux", "ping", "request-response", "gossipsub", "macros"] }
libp2p = { version = "0.56", default-features = false, features = ["tokio", "tcp", "noise", "yamux", "ping", "request-response", "gossipsub", "macros"] }
log = { version = "0.4", default-features = false, features = ["std"] }
serai-task = { path = "../../../common/task", version = "0.1" }

View File

@@ -92,7 +92,8 @@ impl SwarmTask {
}
}
gossip::Event::Subscribed { .. } | gossip::Event::Unsubscribed { .. } => {}
gossip::Event::GossipsubNotSupported { peer_id } => {
gossip::Event::GossipsubNotSupported { peer_id } |
gossip::Event::SlowPeer { peer_id, .. } => {
let _: Result<_, _> = self.swarm.disconnect_peer_id(peer_id);
}
}

View File

@@ -284,7 +284,7 @@ async fn handle_network(
&mut txn,
ExternalValidatorSet { network, session },
slash_report,
Signature(signature),
Signature::from(signature),
);
}
},

View File

@@ -1,3 +1,5 @@
#![expect(clippy::cast_possible_truncation)]
use core::fmt::Debug;
use std::{

View File

@@ -1,3 +1,5 @@
#![expect(clippy::cast_possible_truncation)]
use std::collections::HashMap;
use scale::Encode;

View File

@@ -7,11 +7,10 @@ db-urls = ["https://github.com/rustsec/advisory-db"]
yanked = "deny"
ignore = [
"RUSTSEC-2020-0168", # mach is unmaintained
"RUSTSEC-2021-0139", # https://github.com/serai-dex/serai/228
"RUSTSEC-2022-0061", # https://github.com/serai-dex/serai/227
"RUSTSEC-2024-0370", # proc-macro-error is unmaintained
"RUSTSEC-2024-0384", # instant is unmaintained
"RUSTSEC-2024-0436", # paste is unmaintained
"RUSTSEC-2025-0057", # fxhash is unmaintained, fixed with bytecodealliance/wasmtime/pull/11634
]
[licenses]
@@ -30,10 +29,11 @@ allow = [
"ISC",
"Zlib",
"Unicode-3.0",
"OpenSSL",
# "OpenSSL", # Commented as it's not currently in-use within the Serai tree
"CDLA-Permissive-2.0",
# Non-invasive copyleft
"MPL-2.0",
# "MPL-2.0", # Commented as it's not currently in-use within the Serai tree
"Apache-2.0",
"Apache-2.0 WITH LLVM-exception",
"GPL-3.0-or-later WITH Classpath-exception-2.0",
@@ -80,6 +80,8 @@ exceptions = [
{ allow = ["AGPL-3.0-only"], name = "serai-coordinator-libp2p-p2p" },
{ allow = ["AGPL-3.0-only"], name = "serai-coordinator" },
{ allow = ["AGPL-3.0-only"], name = "pallet-session" },
{ allow = ["AGPL-3.0-only"], name = "serai-coins-pallet" },
{ allow = ["AGPL-3.0-only"], name = "serai-dex-pallet" },
@@ -124,6 +126,10 @@ highlight = "all"
deny = [
{ name = "serde_derive", version = ">=1.0.172, <1.0.185" },
{ name = "hashbrown", version = "=0.15.0" },
# Legacy which _no one_ should use anymore
{ name = "is-terminal", version = "*" },
# Stop introduction into the tree without realizing it
{ name = "once_cell_polyfill", version = "*" },
]
[sources]
@@ -132,10 +138,8 @@ unknown-git = "deny"
allow-registry = ["https://github.com/rust-lang/crates.io-index"]
allow-git = [
"https://github.com/rust-lang-nursery/lazy-static.rs",
"https://github.com/kayabaNerve/hybrid-array",
"https://github.com/kayabaNerve/elliptic-curves",
"https://github.com/monero-oxide/monero-oxide",
"https://github.com/serai-dex/substrate-bip39",
"https://github.com/serai-dex/substrate",
"https://github.com/kayabaNerve/monero-oxide",
"https://github.com/serai-dex/patch-polkadot-sdk",
]

View File

@@ -120,7 +120,7 @@ WORKDIR /home/{user}
Os::Debian => format!(
r#"
FROM debian:bookworm-slim AS image
FROM debian:trixie-slim AS image
COPY --from=mimalloc-debian libmimalloc.so /usr/lib
RUN echo "/usr/lib/libmimalloc.so" >> /etc/ld.so.preload
@@ -149,7 +149,7 @@ fn build_serai_service(prelude: &str, release: bool, features: &str, package: &s
format!(
r#"
FROM rust:1.90-slim-bookworm AS builder
FROM rust:1.90-slim-trixie AS builder
COPY --from=mimalloc-debian libmimalloc.so /usr/lib
RUN echo "/usr/lib/libmimalloc.so" >> /etc/ld.so.preload
@@ -157,7 +157,7 @@ RUN echo "/usr/lib/libmimalloc.so" >> /etc/ld.so.preload
RUN apt update && apt upgrade -y && apt autoremove -y && apt clean
# Add dev dependencies
RUN apt install -y pkg-config clang
RUN apt install -y pkg-config libclang-dev clang
# Dependencies for the Serai node
RUN apt install -y make protobuf-compiler

View File

@@ -16,7 +16,7 @@ RUN git clone https://github.com/microsoft/mimalloc && \
"#;
const DEBIAN_MIMALLOC: &str = r#"
FROM debian:bookworm-slim AS mimalloc-debian
FROM debian:trixie-slim AS mimalloc-debian
RUN apt update && apt upgrade -y && apt install -y gcc g++ make cmake git
RUN git clone https://github.com/microsoft/mimalloc && \

View File

@@ -1,14 +0,0 @@
[package]
name = "is-terminal"
version = "0.4.10"
description = "is-terminal written around std::io::IsTerminal"
license = "MIT"
repository = "https://github.com/serai-dex/serai/tree/develop/patches/is-terminal"
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
keywords = []
edition = "2021"
rust-version = "1.70"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

View File

@@ -1 +0,0 @@
pub use std::io::IsTerminal;

View File

@@ -1,14 +0,0 @@
[package]
name = "matches"
version = "0.1.10"
description = "Replacement for the matches polyfill which uses the std impl"
license = "MIT"
repository = "https://github.com/serai-dex/serai/tree/develop/patches/matches"
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
keywords = []
edition = "2018"
rust-version = "1.42"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

View File

@@ -1 +0,0 @@
pub use std::matches;

View File

@@ -1,16 +0,0 @@
[package]
name = "parking_lot"
version = "0.11.2"
description = "parking_lot which patches to the latest update"
license = "MIT"
repository = "https://github.com/serai-dex/serai/tree/develop/patches/parking_lot"
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
keywords = []
edition = "2021"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
parking_lot = "0.12"

View File

@@ -1 +0,0 @@
pub use parking_lot::*;

View File

@@ -1,25 +0,0 @@
[package]
name = "rocksdb"
version = "0.21.0"
description = "rocksdb which patches to the latest update"
license = "MIT"
repository = "https://github.com/serai-dex/serai/tree/develop/patches/rocksdb"
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
keywords = []
edition = "2021"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
rocksdb = { version = "0.24", default-features = false, features = ["bindgen-runtime"] }
[features]
jemalloc = [] # Dropped as this causes a compilation failure on windows
snappy = ["rocksdb/snappy"]
lz4 = ["rocksdb/lz4"]
zstd = ["rocksdb/zstd"]
zlib = ["rocksdb/zlib"]
bzip2 = ["rocksdb/bzip2"]
default = ["snappy", "lz4", "zstd", "zlib", "bzip2"]

View File

@@ -1 +0,0 @@
pub use rocksdb::*;

View File

@@ -1,16 +0,0 @@
[package]
name = "zstd"
version = "0.11.2+zstd.1.5.2"
description = "zstd which patches to the latest update"
license = "MIT"
repository = "https://github.com/serai-dex/serai/tree/develop/patches/zstd"
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
keywords = []
edition = "2021"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
zstd = "0.13"

View File

@@ -1 +0,0 @@
pub use zstd::*;

View File

@@ -1,3 +1,5 @@
#![expect(clippy::cast_possible_truncation)]
use core::fmt;
use std::collections::HashMap;

View File

@@ -119,7 +119,7 @@ impl<D: Db, C: Coordinator> ContinuallyRan for CoordinatorTask<D, C> {
self
.coordinator
.publish_slash_report_signature(session, slash_report, Signature(signature))
.publish_slash_report_signature(session, slash_report, Signature::from(signature))
.await
.map_err(|e| {
format!("couldn't send slash report signature to the coordinator: {e:?}")

View File

@@ -19,18 +19,18 @@ workspace = true
bitvec = { version = "1", default-features = false, features = ["alloc", "serde"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "bit-vec"] }
scale-info = { version = "2", default-features = false, features = ["derive", "bit-vec"] }
borsh = { version = "1", default-features = false, features = ["derive", "de_strict_order"], optional = true }
serde = { version = "1", default-features = false, features = ["derive", "alloc"], optional = true }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-consensus-babe = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-consensus-grandpa = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-consensus-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
serai-primitives = { path = "../primitives", version = "0.1", default-features = false }
serai-coins-primitives = { path = "../coins/primitives", version = "0.1", default-features = false }
@@ -45,7 +45,6 @@ std = [
"bitvec/std",
"scale/std",
"scale-info/std",
"borsh?/std",
"serde?/std",
@@ -56,6 +55,7 @@ std = [
"sp-consensus-babe/std",
"sp-consensus-grandpa/std",
"frame-system/std",
"frame-support/std",
"serai-primitives/std",

View File

@@ -2,7 +2,9 @@ use sp_consensus_babe::EquivocationProof;
use serai_primitives::{Header, SeraiAddress};
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
pub struct ReportEquivocation {
pub equivocation_proof: alloc::boxed::Box<EquivocationProof<Header>>,
pub key_owner_proof: SeraiAddress,
@@ -10,7 +12,9 @@ pub struct ReportEquivocation {
// We could define a Babe Config here and use the literal pallet_babe::Call
// The disadvantage to this would be the complexity and presence of junk fields such as `__Ignore`
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
pub enum Call {
report_equivocation(ReportEquivocation),
report_equivocation_unsigned(ReportEquivocation),

View File

@@ -3,7 +3,9 @@ use serai_primitives::{Balance, SeraiAddress};
pub use serai_coins_primitives as primitives;
use primitives::OutInstructionWithBalance;
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
@@ -13,7 +15,9 @@ pub enum Call {
burn_with_instruction { instruction: OutInstructionWithBalance },
}
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]

View File

@@ -5,7 +5,9 @@ use serai_primitives::*;
type PoolId = ExternalCoin;
type MaxSwapPathLength = sp_core::ConstU32<3>;
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum Call {
@@ -38,7 +40,9 @@ pub enum Call {
},
}
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum Event {

View File

@@ -1,6 +1,8 @@
use serai_primitives::ExternalNetworkId;
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Event {

View File

@@ -3,14 +3,18 @@ pub use serai_genesis_liquidity_primitives as primitives;
use serai_primitives::*;
use primitives::*;
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Call {
remove_coin_liquidity { balance: ExternalBalance },
oraclize_values { values: Values, signature: Signature },
}
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Event {

View File

@@ -2,19 +2,25 @@ use sp_consensus_grandpa::EquivocationProof;
use serai_primitives::{BlockNumber, SeraiAddress};
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
pub struct ReportEquivocation {
pub equivocation_proof: alloc::boxed::Box<EquivocationProof<[u8; 32], BlockNumber>>,
pub key_owner_proof: SeraiAddress,
}
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
pub enum Call {
report_equivocation(ReportEquivocation),
report_equivocation_unsigned(ReportEquivocation),
}
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum Event {

View File

@@ -4,7 +4,9 @@ pub use serai_in_instructions_primitives as primitives;
use primitives::SignedBatch;
use serai_validator_sets_primitives::Session;
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
@@ -12,7 +14,9 @@ pub enum Call {
execute_batch { batch: SignedBatch },
}
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum Event {

View File

@@ -2,6 +2,7 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(non_camel_case_types)]
#![expect(clippy::cast_possible_truncation)]
extern crate alloc;
@@ -31,45 +32,71 @@ pub mod grandpa;
pub mod tx;
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
pub enum Call {
#[codec(index = 1)]
Timestamp(timestamp::Call),
#[codec(index = 3)]
Coins(coins::Call),
#[codec(index = 4)]
LiquidityTokens(liquidity_tokens::Call),
#[codec(index = 5)]
Dex(dex::Call),
#[codec(index = 6)]
ValidatorSets(validator_sets::Call),
#[codec(index = 7)]
GenesisLiquidity(genesis_liquidity::Call),
#[codec(index = 10)]
InInstructions(in_instructions::Call),
#[codec(index = 11)]
Signals(signals::Call),
#[codec(index = 12)]
Babe(babe::Call),
#[codec(index = 13)]
Grandpa(grandpa::Call),
}
// TODO: Remove this
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
pub enum TransactionPaymentEvent {
TransactionFeePaid { who: serai_primitives::SeraiAddress, actual_fee: u64, tip: u64 },
}
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
pub enum Event {
#[codec(index = 0)]
System(system::Event),
Timestamp,
#[codec(index = 2)]
TransactionPayment(TransactionPaymentEvent),
#[codec(index = 3)]
Coins(coins::Event),
#[codec(index = 4)]
LiquidityTokens(liquidity_tokens::Event),
#[codec(index = 5)]
Dex(dex::Event),
#[codec(index = 6)]
ValidatorSets(validator_sets::Event),
#[codec(index = 7)]
GenesisLiquidity(genesis_liquidity::Event),
Emissions,
#[codec(index = 9)]
EconomicSecurity(economic_security::Event),
#[codec(index = 10)]
InInstructions(in_instructions::Event),
#[codec(index = 11)]
Signals(signals::Event),
Babe,
#[codec(index = 13)]
Grandpa(grandpa::Event),
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, Copy, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub struct Extra {
@@ -80,7 +107,9 @@ pub struct Extra {
pub tip: u64,
}
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]

View File

@@ -1,6 +1,8 @@
use serai_primitives::{Balance, SeraiAddress};
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Call {
@@ -8,7 +10,9 @@ pub enum Call {
transfer { to: SeraiAddress, balance: Balance },
}
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Event {

View File

@@ -5,7 +5,9 @@ use serai_validator_sets_primitives::ValidatorSet;
pub use serai_signals_primitives as primitives;
use primitives::SignalId;
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
@@ -17,7 +19,9 @@ pub enum Call {
stand_against { signal_id: SignalId, for_network: NetworkId },
}
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]

View File

@@ -1,13 +1,15 @@
use frame_support::dispatch::{DispatchInfo, DispatchError};
use frame_system::DispatchEventInfo;
use frame_support::sp_runtime::DispatchError;
use serai_primitives::SeraiAddress;
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
pub enum Event {
ExtrinsicSuccess { dispatch_info: DispatchInfo },
ExtrinsicFailed { dispatch_error: DispatchError, dispatch_info: DispatchInfo },
ExtrinsicSuccess { dispatch_info: DispatchEventInfo },
ExtrinsicFailed { dispatch_error: DispatchError, dispatch_info: DispatchEventInfo },
CodeUpdated,
NewAccount { account: SeraiAddress },
KilledAccount { account: SeraiAddress },
Remarked { sender: SeraiAddress, hash: [u8; 32] },
}

View File

@@ -1,4 +1,6 @@
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum Call {

View File

@@ -1,3 +1,5 @@
#![allow(deprecated)]
use scale::Encode;
use sp_core::sr25519::{Public, Signature};
@@ -8,18 +10,11 @@ use serai_primitives::SeraiAddress;
use frame_support::dispatch::GetDispatchInfo;
pub trait TransactionMember:
Clone + PartialEq + Eq + core::fmt::Debug + scale::Encode + scale::Decode + scale_info::TypeInfo
Clone + PartialEq + Eq + core::fmt::Debug + scale::Encode + scale::Decode
{
}
impl<
T: Clone
+ PartialEq
+ Eq
+ core::fmt::Debug
+ scale::Encode
+ scale::Decode
+ scale_info::TypeInfo,
> TransactionMember for T
impl<T: Clone + PartialEq + Eq + core::fmt::Debug + scale::Encode + scale::Decode> TransactionMember
for T
{
}
@@ -29,8 +24,8 @@ type TransactionDecodeAs<Extra> = (crate::Call, Option<(SeraiAddress, Signature,
// We use our own Transaction struct, over UncheckedExtrinsic, for more control, a bit more
// simplicity, and in order to be immune to https://github.com/paritytech/polkadot-sdk/issues/2947
#[allow(private_bounds)]
#[derive(Clone, PartialEq, Eq, Debug)]
#[allow(clippy::multiple_bound_locations)]
#[derive(Clone, PartialEq, Eq, Debug, scale::DecodeWithMemTracking)]
pub struct Transaction<
Call: 'static + TransactionMember + From<crate::Call>,
Extra: 'static + TransactionMember,
@@ -50,6 +45,10 @@ impl<Call: 'static + TransactionMember + From<crate::Call>, Extra: 'static + Tra
pub fn call(&self) -> &crate::Call {
&self.call
}
pub fn signer(&self) -> Option<SeraiAddress> {
self.signature.as_ref().map(|(address, _sig, _extra)| *address)
}
}
impl<Call: 'static + TransactionMember + From<crate::Call>, Extra: 'static + TransactionMember>
@@ -69,16 +68,6 @@ impl<Call: 'static + TransactionMember + From<crate::Call>, Extra: 'static + Tra
Ok(Self { call, mapped_call, signature })
}
}
impl<Call: 'static + TransactionMember + From<crate::Call>, Extra: 'static + TransactionMember>
scale_info::TypeInfo for Transaction<Call, Extra>
{
type Identity = TransactionDecodeAs<Extra>;
// Define the type info as the info of the type equivalent to what we encode as
fn type_info() -> scale_info::Type {
TransactionDecodeAs::<Extra>::type_info()
}
}
#[cfg(feature = "serde")]
mod _serde {
@@ -129,23 +118,14 @@ impl<
impl<
Call: 'static + TransactionMember + From<crate::Call> + TryInto<crate::Call>,
Extra: 'static + TransactionMember,
> frame_support::traits::ExtrinsicCall for Transaction<Call, Extra>
> frame_support::sp_runtime::traits::ExtrinsicCall for Transaction<Call, Extra>
{
type Call = Call;
fn call(&self) -> &Call {
&self.mapped_call
}
}
impl<
Call: 'static + TransactionMember + From<crate::Call>,
Extra: 'static + TransactionMember + sp_runtime::traits::SignedExtension,
> sp_runtime::traits::ExtrinsicMetadata for Transaction<Call, Extra>
{
type SignedExtensions = Extra;
const VERSION: u8 = 0;
}
impl<
Call: 'static + TransactionMember + From<crate::Call> + GetDispatchInfo,
Extra: 'static + TransactionMember,
@@ -156,9 +136,10 @@ impl<
}
}
use sp_runtime::generic::ExtrinsicFormat;
impl<
Call: 'static + TransactionMember + From<crate::Call>,
Extra: 'static + TransactionMember + sp_runtime::traits::SignedExtension,
Call: 'static + TransactionMember + From<crate::Call> + sp_runtime::traits::Dispatchable,
Extra: 'static + TransactionMember + sp_runtime::traits::TransactionExtension<Call>,
> sp_runtime::traits::BlindCheckable for Transaction<Call, Extra>
{
type Checked = sp_runtime::generic::CheckedExtrinsic<Public, Call, Extra>;
@@ -168,19 +149,33 @@ impl<
) -> Result<Self::Checked, sp_runtime::transaction_validity::TransactionValidityError> {
Ok(match self.signature {
Some((signer, signature, extra)) => {
if !signature.verify(
(&self.call, &extra, extra.additional_signed()?).encode().as_slice(),
&signer.into(),
) {
if !signature
.verify((&self.call, &extra, extra.implicit()?).encode().as_slice(), &signer.into())
{
Err(sp_runtime::transaction_validity::InvalidTransaction::BadProof)?
}
sp_runtime::generic::CheckedExtrinsic {
signed: Some((signer.into(), extra)),
format: ExtrinsicFormat::Signed(signer.into(), extra),
function: self.mapped_call,
}
}
None => sp_runtime::generic::CheckedExtrinsic { signed: None, function: self.mapped_call },
None => sp_runtime::generic::CheckedExtrinsic {
format: ExtrinsicFormat::Bare,
function: self.mapped_call,
},
})
}
}
impl<
Call: 'static + TransactionMember + From<crate::Call> + TryInto<crate::Call>,
Extra: 'static + TransactionMember,
> frame_support::traits::InherentBuilder for Transaction<Call, Extra>
{
/// Panics if the inherent isn't supported.
// TODO: Don't panic here
fn new_inherent(call: Self::Call) -> Self {
sp_runtime::traits::Extrinsic::new(call, None).expect("trying to build an unsupported inherent")
}
}

View File

@@ -5,7 +5,9 @@ pub use serai_validator_sets_primitives as primitives;
use serai_primitives::*;
use serai_validator_sets_primitives::*;
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]
pub enum Call {
@@ -38,7 +40,9 @@ pub enum Call {
},
}
#[derive(Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale_info::TypeInfo)]
#[derive(
Clone, PartialEq, Eq, Debug, scale::Encode, scale::Decode, scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(all(feature = "std", feature = "serde"), derive(serde::Deserialize))]

View File

@@ -31,9 +31,9 @@ serde_json = { version = "1", optional = true }
serai-abi = { path = "../abi", version = "0.1" }
multiaddr = { version = "0.18", optional = true }
sp-core = { git = "https://github.com/serai-dex/substrate", optional = true }
sp-runtime = { git = "https://github.com/serai-dex/substrate", optional = true }
frame-system = { git = "https://github.com/serai-dex/substrate", optional = true }
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", optional = true }
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", optional = true }
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", optional = true }
async-lock = "3"

View File

@@ -1,3 +1,5 @@
#![expect(clippy::cast_possible_truncation)]
#[cfg(feature = "networks")]
pub mod networks;

View File

@@ -291,7 +291,7 @@ impl Serai {
self
.0
.rpc()
.system_account_next_index(&sp_core::sr25519::Public(address.0).to_string())
.system_account_next_index(&sp_core::sr25519::Public::from(address.0).to_string())
.await
.map_err(|_| SeraiError::ConnectionError)
}
@@ -316,7 +316,7 @@ impl Serai {
&self,
network: ExternalNetworkId,
) -> Result<Vec<multiaddr::Multiaddr>, SeraiError> {
self.call("p2p_validators", network).await
self.call("p2p_validators", [network]).await
}
// TODO: move this to SeraiValidatorSets?

View File

@@ -8,7 +8,7 @@ use ciphersuite::{WrappedGroup, GroupIo};
use dkg_musig::musig;
use schnorrkel::Schnorrkel;
use sp_core::{sr25519::Signature, Pair as PairTrait};
use sp_core::Pair as PairTrait;
use serai_abi::{
primitives::{
@@ -117,6 +117,6 @@ async fn set_values(serai: &Serai, values: &Values) {
// oraclize values
let _ =
publish_tx(serai, &SeraiGenesisLiquidity::oraclize_values(*values, Signature(sig.to_bytes())))
publish_tx(serai, &SeraiGenesisLiquidity::oraclize_values(*values, sig.to_bytes().into()))
.await;
}

View File

@@ -8,12 +8,7 @@ use ciphersuite::{WrappedGroup, GroupIo};
use dkg_musig::musig;
use schnorrkel::Schnorrkel;
use sp_core::{
ConstU32,
bounded_vec::BoundedVec,
sr25519::{Pair, Signature},
Pair as PairTrait,
};
use sp_core::{ConstU32, bounded_vec::BoundedVec, sr25519::Pair, Pair as PairTrait};
use serai_abi::primitives::NetworkId;
@@ -73,7 +68,7 @@ pub async fn set_keys(
set.network,
key_pair.clone(),
bitvec::bitvec!(u8, bitvec::prelude::Lsb0; 1; musig_keys.len()),
Signature(sig.to_bytes()),
sig.to_bytes().into(),
),
)
.await;

View File

@@ -57,7 +57,7 @@ async fn set_network_keys<C: Ciphersuite>(
let network_priv_key = Zeroizing::new(C::F::random(&mut OsRng));
let network_key = (C::generator() * *network_priv_key).to_bytes().as_ref().to_vec();
let key_pair = KeyPair(Public(ristretto_key), network_key.try_into().unwrap());
let key_pair = KeyPair(Public::from(ristretto_key), network_key.try_into().unwrap());
let _ = set_keys(serai, set, key_pair, pairs).await;
}

View File

@@ -32,7 +32,7 @@ fn get_random_key_pair() -> KeyPair {
OsRng.fill_bytes(&mut ristretto_key);
let mut external_key = vec![0; 33];
OsRng.fill_bytes(&mut external_key);
KeyPair(Public(ristretto_key), external_key.try_into().unwrap())
KeyPair(Public::from(ristretto_key), external_key.try_into().unwrap())
}
async fn get_ordered_keys(serai: &Serai, network: NetworkId, accounts: &[Pair]) -> Vec<Pair> {

View File

@@ -13,29 +13,28 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[package.metadata.cargo-machete]
ignored = ["scale", "scale-info"]
ignored = ["scale"]
[lints]
workspace = true
[dependencies]
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
frame-system = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
pallet-transaction-payment = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-transaction-payment = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
serai-primitives = { path = "../../primitives", default-features = false, features = ["serde"] }
coins-primitives = { package = "serai-coins-primitives", path = "../primitives", default-features = false }
[dev-dependencies]
sp-io = { git = "https://github.com/serai-dex/substrate", default-features = false, features = ["std"] }
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false, features = ["std"] }
[features]
std = [

View File

@@ -43,12 +43,11 @@ pub mod pallet {
#[pallet::config]
pub trait Config<I: 'static = ()>: frame_system::Config<AccountId = Public> {
type RuntimeEvent: From<Event<Self, I>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
type AllowMint: AllowMint;
}
#[pallet::genesis_config]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
#[derive(Clone, Debug)]
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
pub accounts: Vec<(T::AccountId, Balance)>,
pub _ignore: PhantomData<I>,
@@ -281,6 +280,22 @@ pub mod pallet {
}
}
fn can_withdraw_fee(
who: &Public,
_call: &T::RuntimeCall,
_dispatch_info: &DispatchInfoOf<T::RuntimeCall>,
fee: Self::Balance,
_tip: Self::Balance,
) -> Result<(), TransactionValidityError> {
if fee == 0 {
return Ok(());
}
if Self::balance(*who, Coin::Serai).0 < fee {
Err(InvalidTransaction::Payment)?;
}
Ok(())
}
fn correct_and_deposit_fee(
who: &Public,
_dispatch_info: &DispatchInfoOf<T::RuntimeCall>,

View File

@@ -2,16 +2,10 @@
use super::*;
use frame_support::{
construct_runtime,
traits::{ConstU32, ConstU64},
};
use frame_support::{construct_runtime, derive_impl};
use sp_core::{H256, sr25519::Public};
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
use sp_core::sr25519::Public;
use sp_runtime::{traits::IdentityLookup, BuildStorage};
use crate as coins;
@@ -25,35 +19,14 @@ construct_runtime!(
}
);
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = Public;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = ConstU32<16>;
}
impl Config for Test {
type RuntimeEvent = RuntimeEvent;
type AllowMint = ();
}

View File

@@ -21,15 +21,14 @@ borsh = { version = "1", default-features = false, features = ["derive", "de_str
serde = { version = "1", default-features = false, features = ["derive", "alloc"], optional = true }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
serai-primitives = { path = "../../primitives", default-features = false }
[dev-dependencies]
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
[features]
std = ["zeroize", "borsh?/std", "serde?/std", "scale/std", "scale-info/std", "sp-runtime/std", "serai-primitives/std"]
std = ["zeroize", "borsh?/std", "serde?/std", "scale/std", "sp-runtime/std", "serai-primitives/std"]
borsh = ["dep:borsh", "serai-primitives/borsh"]
serde = ["dep:serde", "serai-primitives/serde"]
default = ["std"]

View File

@@ -1,6 +1,7 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
#![expect(clippy::cast_possible_truncation)]
#[cfg(feature = "std")]
use zeroize::Zeroize;
@@ -10,15 +11,14 @@ use borsh::{BorshSerialize, BorshDeserialize};
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
use scale::{Encode, Decode, DecodeWithMemTracking, MaxEncodedLen};
use serai_primitives::{ExternalBalance, SeraiAddress, ExternalAddress, system_address};
pub const FEE_ACCOUNT: SeraiAddress = system_address(b"Coins-fees");
// TODO: Replace entirely with just Address
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -26,7 +26,7 @@ pub struct OutInstruction {
pub address: ExternalAddress,
}
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -35,7 +35,7 @@ pub struct OutInstructionWithBalance {
pub balance: ExternalBalance,
}
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

View File

@@ -13,24 +13,23 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[package.metadata.cargo-machete]
ignored = ["scale", "scale-info"]
ignored = ["scale"]
[lints]
workspace = true
[dependencies]
scale = { package = "parity-scale-codec", version = "3.6.1", default-features = false }
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-io = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-api = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-system = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-benchmarking = { git = "https://github.com/serai-dex/substrate", default-features = false, optional = true }
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-benchmarking = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false, optional = true }
coins-pallet = { package = "serai-coins-pallet", path = "../../coins/pallet", default-features = false }
@@ -43,7 +42,6 @@ rand_core = { version = "0.6", default-features = false, features = ["getrandom"
default = ["std"]
std = [
"scale/std",
"scale-info/std",
"sp-std/std",
"sp-io/std",

View File

@@ -62,8 +62,10 @@
//! http://localhost:9933/
//! ```
//! (This can be run against the kitchen sync node in the `node` folder of this repo.)
#![deny(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
use frame_support::traits::DefensiveOption;
#[cfg(feature = "runtime-benchmarks")]
@@ -132,9 +134,6 @@ pub mod pallet {
+ CoinsConfig
+ coins_pallet::Config<coins_pallet::Instance1>
{
/// Overarching event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// A % the liquidity providers will take of every swap. Represents 10ths of a percent.
#[pallet::constant]
type LPFee: Get<u32>;

View File

@@ -24,15 +24,12 @@ use super::*;
use crate as dex;
use frame_support::{
construct_runtime,
construct_runtime, derive_impl,
traits::{ConstU16, ConstU32, ConstU64},
};
use sp_core::{H256, sr25519::Public};
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
use sp_core::sr25519::Public;
use sp_runtime::{traits::IdentityLookup, BuildStorage};
use serai_primitives::{Coin, Balance, Amount, system_address};
@@ -52,45 +49,22 @@ construct_runtime!(
}
);
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = Public;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = ConstU32<16>;
}
impl coins::Config for Test {
type RuntimeEvent = RuntimeEvent;
type AllowMint = ();
}
impl coins::Config<coins::Instance1> for Test {
type RuntimeEvent = RuntimeEvent;
type AllowMint = ();
}
impl Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type LPFee = ConstU32<3>; // means 0.3%
type MaxSwapPathLength = ConstU32<4>;

View File

@@ -13,17 +13,16 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[package.metadata.cargo-machete]
ignored = ["scale", "scale-info"]
ignored = ["scale"]
[lints]
workspace = true
[dependencies]
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
frame-system = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
dex-pallet = { package = "serai-dex-pallet", path = "../../dex/pallet", default-features = false }
coins-pallet = { package = "serai-coins-pallet", path = "../../coins/pallet", default-features = false }
@@ -31,21 +30,21 @@ coins-pallet = { package = "serai-coins-pallet", path = "../../coins/pallet", de
serai-primitives = { path = "../../primitives", default-features = false }
[dev-dependencies]
pallet-babe = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-grandpa = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-timestamp = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
pallet-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
validator-sets-pallet = { package = "serai-validator-sets-pallet", path = "../../validator-sets/pallet", default-features = false }
sp-io = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-consensus-babe = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
[features]
std = [
"scale/std",
"scale-info/std",
"frame-system/std",
"frame-support/std",

View File

@@ -23,9 +23,7 @@ pub mod pallet {
use serai_primitives::*;
#[pallet::config]
pub trait Config: frame_system::Config + CoinsConfig + DexConfig {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}
pub trait Config: frame_system::Config + CoinsConfig + DexConfig {}
#[pallet::event]
#[pallet::generate_deposit(fn deposit_event)]

View File

@@ -6,7 +6,7 @@ use core::marker::PhantomData;
use std::collections::HashMap;
use frame_support::{
construct_runtime,
derive_impl, construct_runtime,
traits::{ConstU16, ConstU32, ConstU64},
};
@@ -58,10 +58,9 @@ construct_runtime!(
}
);
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Nonce = u64;
@@ -72,16 +71,6 @@ impl frame_system::Config for Test {
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = ConstU32<16>;
}
impl timestamp::Config for Test {
@@ -91,6 +80,16 @@ impl timestamp::Config for Test {
type WeightInfo = ();
}
pub struct GetSession;
impl pallet_session::GetCurrentSessionForSubstrate for GetSession {
fn get() -> u32 {
0
}
}
impl pallet_session::Config for Test {
type Session = GetSession;
}
impl babe::Config for Test {
type EpochDuration = ConstU64<{ FAST_EPOCH_DURATION }>;
@@ -100,6 +99,7 @@ impl babe::Config for Test {
type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxAuthorities;
type KeyOwnerProof = MembershipProof<Self>;
type EquivocationReportSystem = ();
@@ -110,6 +110,7 @@ impl grandpa::Config for Test {
type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxAuthorities;
type MaxSetIdSessionEntries = ConstU64<0>;
type KeyOwnerProof = MembershipProof<Self>;
@@ -117,18 +118,14 @@ impl grandpa::Config for Test {
}
impl coins::Config for Test {
type RuntimeEvent = RuntimeEvent;
type AllowMint = ValidatorSets;
}
impl coins::Config<coins::Instance1> for Test {
type RuntimeEvent = RuntimeEvent;
type AllowMint = ();
}
impl dex::Config for Test {
type RuntimeEvent = RuntimeEvent;
type LPFee = ConstU32<3>; // 0.3%
type MintMinLiquidity = ConstU64<10000>;
@@ -140,13 +137,10 @@ impl dex::Config for Test {
}
impl validator_sets::Config for Test {
type RuntimeEvent = RuntimeEvent;
type ShouldEndSession = Babe;
}
impl Config for Test {
type RuntimeEvent = RuntimeEvent;
}
impl Config for Test {}
// For a const we can't define
pub fn genesis_participants() -> Vec<Pair> {
@@ -202,7 +196,7 @@ pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
.into_iter()
.map(|validator| (validator.public().into(), 1))
.collect(),
epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG),
epoch_config: BABE_GENESIS_EPOCH_CONFIG,
_config: PhantomData,
}
.assimilate_storage(&mut t)

View File

@@ -17,7 +17,7 @@ fn set_keys_for_session(network: ExternalNetworkId) {
network,
KeyPair(insecure_pair_from_name("Alice").public(), vec![].try_into().unwrap()),
vec![].try_into().unwrap(),
Signature([0u8; 64]),
Signature::from([0u8; 64]),
)
.unwrap();
}

View File

@@ -13,20 +13,19 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[package.metadata.cargo-machete]
ignored = ["scale", "scale-info"]
ignored = ["scale"]
[lints]
workspace = true
[dependencies]
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
frame-system = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
coins-pallet = { package = "serai-coins-pallet", path = "../../coins/pallet", default-features = false }
validator-sets-pallet = { package = "serai-validator-sets-pallet", path = "../../validator-sets/pallet", default-features = false }
@@ -42,7 +41,6 @@ emissions-primitives = { package = "serai-emissions-primitives", path = "../prim
[features]
std = [
"scale/std",
"scale-info/std",
"frame-system/std",
"frame-support/std",

View File

@@ -8,7 +8,6 @@
)]
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_system::{pallet_prelude::*, RawOrigin};
use frame_support::{pallet_prelude::*, sp_runtime::SaturatedConversion};
@@ -36,11 +35,10 @@ pub mod pallet {
+ GenesisLiquidityConfig
+ EconomicSecurityConfig
{
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}
#[pallet::genesis_config]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
#[derive(Clone, Debug)]
pub struct GenesisConfig<T: Config> {
/// Networks to spawn Serai with.
pub networks: Vec<(NetworkId, Amount)>,

View File

@@ -13,21 +13,20 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[package.metadata.cargo-machete]
ignored = ["scale", "scale-info"]
ignored = ["scale"]
[lints]
workspace = true
[dependencies]
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
frame-system = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-application-crypto = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-application-crypto = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
dex-pallet = { package = "serai-dex-pallet", path = "../../dex/pallet", default-features = false }
coins-pallet = { package = "serai-coins-pallet", path = "../../coins/pallet", default-features = false }
@@ -42,7 +41,6 @@ validator-sets-primitives = { package = "serai-validator-sets-primitives", path
[features]
std = [
"scale/std",
"scale-info/std",
"frame-system/std",
"frame-support/std",

View File

@@ -8,7 +8,6 @@
)]
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_system::{pallet_prelude::*, RawOrigin};
use frame_support::{pallet_prelude::*, sp_runtime::SaturatedConversion};
@@ -40,7 +39,6 @@ pub mod pallet {
+ CoinsConfig
+ coins_pallet::Config<coins_pallet::Instance1>
{
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}
#[pallet::error]

View File

@@ -22,9 +22,8 @@ borsh = { version = "1", default-features = false, features = ["derive", "de_str
serde = { version = "1", default-features = false, features = ["derive", "alloc"], optional = true }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
serai-primitives = { path = "../../primitives", default-features = false }
validator-sets-primitives = { package = "serai-validator-sets-primitives", path = "../../validator-sets/primitives", default-features = false }
@@ -35,7 +34,6 @@ std = [
"scale/std",
"borsh?/std",
"serde?/std",
"scale-info/std",
"serai-primitives/std",
"validator-sets-primitives/std",

View File

@@ -12,8 +12,7 @@ use serde::{Serialize, Deserialize};
use sp_std::vec::Vec;
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
use scale::{Encode, Decode, DecodeWithMemTracking, MaxEncodedLen};
use serai_primitives::*;
use validator_sets_primitives::ValidatorSet;
@@ -23,7 +22,9 @@ pub const INITIAL_GENESIS_LP_SHARES: u64 = 10_000;
// This is the account to hold and manage the genesis liquidity.
pub const GENESIS_LIQUIDITY_ACCOUNT: SeraiAddress = system_address(b"GenesisLiquidity-account");
#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(
Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -33,7 +34,9 @@ pub struct Values {
pub dai: u64,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(
Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

View File

@@ -13,7 +13,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[package.metadata.cargo-machete]
ignored = ["scale", "scale-info"]
ignored = ["scale"]
[lints]
workspace = true
@@ -22,16 +22,15 @@ workspace = true
bitvec = { version = "1", default-features = false, features = ["alloc"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-application-crypto = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-io = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-application-crypto = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-system = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
serai-primitives = { path = "../../primitives", default-features = false }
in-instructions-primitives = { package = "serai-in-instructions-primitives", path = "../primitives", default-features = false }
@@ -43,16 +42,16 @@ genesis-liquidity-pallet = { package = "serai-genesis-liquidity-pallet", path =
emissions-pallet = { package = "serai-emissions-pallet", path = "../../emissions/pallet", default-features = false }
[dev-dependencies]
pallet-babe = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-grandpa = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-timestamp = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
pallet-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
economic-security-pallet = { package = "serai-economic-security-pallet", path = "../../economic-security/pallet", default-features = false }
[features]
std = [
"scale/std",
"scale-info/std",
"sp-std/std",
"sp-application-crypto/std",

View File

@@ -58,7 +58,6 @@ pub mod pallet {
+ GenesisLiqConfig
+ EmissionsConfig
{
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}
#[pallet::event]

View File

@@ -5,7 +5,7 @@ use super::*;
use std::collections::HashMap;
use frame_support::{
construct_runtime,
derive_impl, construct_runtime,
traits::{ConstU16, ConstU32, ConstU64},
};
@@ -52,10 +52,9 @@ construct_runtime!(
}
);
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Nonce = u64;
@@ -66,16 +65,6 @@ impl frame_system::Config for Test {
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = ConstU32<16>;
}
impl timestamp::Config for Test {
@@ -85,6 +74,16 @@ impl timestamp::Config for Test {
type WeightInfo = ();
}
pub struct GetSession;
impl pallet_session::GetCurrentSessionForSubstrate for GetSession {
fn get() -> u32 {
0
}
}
impl pallet_session::Config for Test {
type Session = GetSession;
}
impl babe::Config for Test {
type EpochDuration = ConstU64<{ FAST_EPOCH_DURATION }>;
@@ -94,6 +93,7 @@ impl babe::Config for Test {
type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxAuthorities;
type KeyOwnerProof = MembershipProof<Self>;
type EquivocationReportSystem = ();
@@ -104,6 +104,7 @@ impl grandpa::Config for Test {
type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxAuthorities;
type MaxSetIdSessionEntries = ConstU64<0>;
type KeyOwnerProof = MembershipProof<Self>;
@@ -111,18 +112,14 @@ impl grandpa::Config for Test {
}
impl coins::Config for Test {
type RuntimeEvent = RuntimeEvent;
type AllowMint = ValidatorSets;
}
impl coins::Config<coins::Instance1> for Test {
type RuntimeEvent = RuntimeEvent;
type AllowMint = ();
}
impl dex::Config for Test {
type RuntimeEvent = RuntimeEvent;
type LPFee = ConstU32<3>; // 0.3%
type MintMinLiquidity = ConstU64<10000>;
@@ -134,25 +131,16 @@ impl dex::Config for Test {
}
impl validator_sets::Config for Test {
type RuntimeEvent = RuntimeEvent;
type ShouldEndSession = Babe;
}
impl genesis_liquidity::Config for Test {
type RuntimeEvent = RuntimeEvent;
}
impl genesis_liquidity::Config for Test {}
impl emissions::Config for Test {
type RuntimeEvent = RuntimeEvent;
}
impl emissions::Config for Test {}
impl economic_security::Config for Test {
type RuntimeEvent = RuntimeEvent;
}
impl economic_security::Config for Test {}
impl Config for Test {
type RuntimeEvent = RuntimeEvent;
}
impl Config for Test {}
// Amounts for single key share per network
pub fn key_shares() -> HashMap<NetworkId, Amount> {

View File

@@ -22,7 +22,7 @@ fn set_keys_for_session(key: Public) {
n,
KeyPair(key, vec![].try_into().unwrap()),
vec![].try_into().unwrap(),
Signature([0u8; 64]),
Signature::from([0u8; 64]),
)
.unwrap();
}
@@ -80,7 +80,7 @@ fn validate_batch() {
}
let call = pallet::Call::<Test>::execute_batch {
batch: SignedBatch { batch: batch.clone(), signature: Signature([0u8; 64]) },
batch: SignedBatch { batch: batch.clone(), signature: Signature::from([0u8; 64]) },
};
assert_eq!(
InInstructions::validate_unsigned(TransactionSource::External, &call),
@@ -95,7 +95,7 @@ fn validate_batch() {
// 0 signature should be invalid
let call = pallet::Call::<Test>::execute_batch {
batch: SignedBatch { batch: batch.clone(), signature: Signature([0u8; 64]) },
batch: SignedBatch { batch: batch.clone(), signature: Signature::from([0u8; 64]) },
};
assert_eq!(
InInstructions::validate_unsigned(TransactionSource::External, &call),
@@ -121,7 +121,7 @@ fn validate_batch() {
// can't submit in the first block(Block 0)
let call = pallet::Call::<Test>::execute_batch {
batch: SignedBatch { batch: batch.clone(), signature: signature.clone() },
batch: SignedBatch { batch: batch.clone(), signature },
};
assert_eq!(
InInstructions::validate_unsigned(TransactionSource::External, &call),
@@ -133,7 +133,7 @@ fn validate_batch() {
// first batch id should be 0
let call = pallet::Call::<Test>::execute_batch {
batch: SignedBatch { batch: batch.clone(), signature: signature.clone() },
batch: SignedBatch { batch: batch.clone(), signature },
};
assert_eq!(
InInstructions::validate_unsigned(TransactionSource::External, &call),
@@ -146,7 +146,7 @@ fn validate_batch() {
// can't have more than 1 batch per block
let call = pallet::Call::<Test>::execute_batch {
batch: SignedBatch { batch: batch.clone(), signature: signature.clone() },
batch: SignedBatch { batch: batch.clone(), signature },
};
assert_eq!(
InInstructions::validate_unsigned(TransactionSource::External, &call),
@@ -224,7 +224,7 @@ fn transfer_instruction() {
balance: ExternalBalance { coin, amount },
}],
},
signature: Signature([0u8; 64]),
signature: Signature::from([0u8; 64]),
};
InInstructions::execute_batch(RawOrigin::None.into(), batch).unwrap();
@@ -250,7 +250,7 @@ fn dex_instruction_add_liquidity() {
balance: ExternalBalance { coin, amount },
}],
},
signature: Signature([0u8; 64]),
signature: Signature::from([0u8; 64]),
};
// we should have a liquid pool before we can swap
@@ -328,7 +328,7 @@ fn dex_instruction_swap() {
balance: ExternalBalance { coin, amount },
}],
},
signature: Signature([0u8; 64]),
signature: Signature::from([0u8; 64]),
};
// we can't send SRI to external address
@@ -418,7 +418,7 @@ fn genesis_liquidity_instruction() {
balance: ExternalBalance { coin, amount },
}],
},
signature: Signature([0u8; 64]),
signature: Signature::from([0u8; 64]),
};
InInstructions::execute_batch(RawOrigin::None.into(), batch.clone()).unwrap();
@@ -456,7 +456,7 @@ fn swap_to_staked_sri_instruction() {
coin.network(),
KeyPair(insecure_pair_from_name("random-key").public(), Vec::new().try_into().unwrap()),
Vec::new().try_into().unwrap(),
Signature([0u8; 64]),
Signature::from([0u8; 64]),
)
.unwrap();
@@ -479,7 +479,7 @@ fn swap_to_staked_sri_instruction() {
balance: ExternalBalance { coin, amount },
}],
},
signature: Signature([0u8; 64]),
signature: Signature::from([0u8; 64]),
};
InInstructions::execute_batch(RawOrigin::None.into(), batch.clone()).unwrap();

View File

@@ -21,11 +21,9 @@ borsh = { version = "1", default-features = false, features = ["derive", "de_str
serde = { version = "1", default-features = false, features = ["derive", "alloc"], optional = true }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-application-crypto = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-application-crypto = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
serai-primitives = { path = "../../primitives", default-features = false }
coins-primitives = { package = "serai-coins-primitives", path = "../../coins/primitives", default-features = false }
@@ -38,11 +36,9 @@ std = [
"serde?/std",
"scale/std",
"scale-info/std",
"sp-std/std",
"sp-application-crypto/std",
"sp-runtime/std",
"serai-primitives/std",
"coins-primitives/std",

View File

@@ -1,6 +1,7 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
#![expect(clippy::cast_possible_truncation)]
#[cfg(feature = "std")]
use zeroize::Zeroize;
@@ -10,14 +11,12 @@ use borsh::{BorshSerialize, BorshDeserialize};
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
use scale::{Encode, Decode, DecodeWithMemTracking, MaxEncodedLen};
use sp_application_crypto::sr25519::Signature;
#[cfg(not(feature = "std"))]
use sp_std::vec::Vec;
use sp_runtime::RuntimeDebug;
#[rustfmt::skip]
use serai_primitives::{BlockHash, ExternalNetworkId, NetworkId, ExternalBalance, Balance, SeraiAddress, ExternalAddress, system_address};
@@ -30,7 +29,7 @@ pub const MAX_BATCH_SIZE: usize = 25_000; // ~25kb
// This is the account which will be the origin for any dispatched `InInstruction`s.
pub const IN_INSTRUCTION_EXECUTOR: SeraiAddress = system_address(b"InInstructions-executor");
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -59,7 +58,7 @@ impl OutAddress {
}
}
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -71,7 +70,7 @@ pub enum DexCall {
Swap(Balance, OutAddress),
}
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -82,7 +81,7 @@ pub enum InInstruction {
SwapToStakedSRI(SeraiAddress, NetworkId),
}
#[derive(Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen, TypeInfo, RuntimeDebug)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -91,7 +90,7 @@ pub struct RefundableInInstruction {
pub instruction: InInstruction,
}
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -100,7 +99,7 @@ pub struct InInstructionWithBalance {
pub balance: ExternalBalance,
}
#[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo, RuntimeDebug)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -111,7 +110,7 @@ pub struct Batch {
pub instructions: Vec<InInstructionWithBalance>,
}
#[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo, RuntimeDebug)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking)]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct SignedBatch {
@@ -130,7 +129,8 @@ pub struct SignedBatch {
impl Zeroize for SignedBatch {
fn zeroize(&mut self) {
self.batch.zeroize();
self.signature.as_mut().zeroize();
let signature: &mut [u8] = self.signature.as_mut();
signature.zeroize();
}
}

View File

@@ -6,8 +6,7 @@ use borsh::{BorshSerialize, BorshDeserialize};
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
use scale::{Encode, Decode, DecodeWithMemTracking, MaxEncodedLen};
use serai_primitives::{Amount, ExternalAddress, ExternalCoin, SeraiAddress};
@@ -17,7 +16,7 @@ use crate::RefundableInInstruction;
#[cfg(feature = "std")]
use crate::InInstruction;
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

View File

@@ -32,18 +32,20 @@ dalek-ff-group = { path = "../../crypto/dalek-ff-group" }
embedwards25519 = { path = "../../crypto/embedwards25519" }
secq256k1 = { path = "../../crypto/secq256k1" }
libp2p = "0.52"
libp2p = "0.56"
sp-core = { git = "https://github.com/serai-dex/substrate" }
sp-keystore = { git = "https://github.com/serai-dex/substrate" }
sp-timestamp = { git = "https://github.com/serai-dex/substrate" }
sp-io = { git = "https://github.com/serai-dex/substrate" }
sp-blockchain = { git = "https://github.com/serai-dex/substrate" }
sp-api = { git = "https://github.com/serai-dex/substrate" }
sp-block-builder = { git = "https://github.com/serai-dex/substrate" }
sp-consensus-babe = { git = "https://github.com/serai-dex/substrate" }
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sp-keystore = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sp-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sp-state-machine = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sp-blockchain = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sp-block-builder = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sp-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
frame-benchmarking = { git = "https://github.com/serai-dex/substrate" }
frame-benchmarking = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
serai-runtime = { path = "../runtime", features = ["std"] }
@@ -51,32 +53,28 @@ clap = { version = "4", features = ["derive"] }
futures-util = "0.3"
tokio = { version = "1", features = ["sync", "rt-multi-thread"] }
jsonrpsee = { version = "0.16", features = ["server"] }
jsonrpsee = { version = "0.24", features = ["server"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
sc-transaction-pool = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sc-transaction-pool-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sc-basic-authorship = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sc-executor = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sc-service = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sc-client-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sc-network = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sc-offchain = { git = "https://github.com/serai-dex/substrate" }
sc-transaction-pool = { git = "https://github.com/serai-dex/substrate" }
sc-transaction-pool-api = { git = "https://github.com/serai-dex/substrate" }
sc-basic-authorship = { git = "https://github.com/serai-dex/substrate" }
sc-executor = { git = "https://github.com/serai-dex/substrate" }
sc-service = { git = "https://github.com/serai-dex/substrate" }
sc-client-api = { git = "https://github.com/serai-dex/substrate" }
sc-network-common = { git = "https://github.com/serai-dex/substrate" }
sc-network = { git = "https://github.com/serai-dex/substrate" }
sc-consensus = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sc-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sc-consensus-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sc-authority-discovery = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sc-consensus = { git = "https://github.com/serai-dex/substrate" }
sc-consensus-babe = { git = "https://github.com/serai-dex/substrate" }
sc-consensus-grandpa = { git = "https://github.com/serai-dex/substrate" }
sc-authority-discovery = { git = "https://github.com/serai-dex/substrate" }
sc-telemetry = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sc-chain-spec = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sc-cli = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sc-telemetry = { git = "https://github.com/serai-dex/substrate" }
sc-cli = { git = "https://github.com/serai-dex/substrate" }
sc-rpc-api = { git = "https://github.com/serai-dex/substrate" }
substrate-frame-rpc-system = { git = "https://github.com/serai-dex/substrate" }
pallet-transaction-payment-rpc = { git = "https://github.com/serai-dex/substrate" }
frame-system-rpc-runtime-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
substrate-frame-rpc-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
pallet-transaction-payment-rpc = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
serai-env = { path = "../../common/env" }
@@ -85,7 +83,7 @@ bitcoin-serai = { path = "../../networks/bitcoin", default-features = false, fea
monero-address = { git = "https://github.com/monero-oxide/monero-oxide", rev = "4b7191e3da20e42f839bfd6d706f75364004a4b8", default-features = false, features = ["std"] }
[build-dependencies]
substrate-build-script-utils = { git = "https://github.com/serai-dex/substrate" }
substrate-build-script-utils = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
[features]
default = []

View File

@@ -1,3 +1,5 @@
#![expect(unused_imports, dead_code, redundant_closure_call)]
use core::marker::PhantomData;
use sp_core::Pair as PairTrait;
@@ -14,7 +16,7 @@ use serai_runtime::{
SignalsConfig, BabeConfig, GrandpaConfig, EmissionsConfig,
};
pub type ChainSpec = sc_service::GenericChainSpec<RuntimeGenesisConfig>;
pub type ChainSpec = sc_service::GenericChainSpec;
fn account_from_name(name: &'static str) -> PublicKey {
insecure_pair_from_name(name).public()
@@ -36,8 +38,8 @@ fn wasm_binary() -> Vec<u8> {
WASM_BINARY.ok_or("compiled in wasm not available").unwrap().to_vec()
}
/*
fn devnet_genesis(
wasm_binary: &[u8],
validators: &[&'static str],
endowed_accounts: Vec<PublicKey>,
) -> RuntimeGenesisConfig {
@@ -72,7 +74,7 @@ fn devnet_genesis(
.collect::<Vec<_>>();
RuntimeGenesisConfig {
system: SystemConfig { code: wasm_binary.to_vec(), _config: PhantomData },
system: SystemConfig { _config: PhantomData },
transaction_payment: Default::default(),
@@ -94,8 +96,8 @@ fn devnet_genesis(
},
signals: SignalsConfig::default(),
babe: BabeConfig {
authorities: validators.iter().map(|validator| (validator.0.into(), 1)).collect(),
epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG),
authorities: validators.iter().map(|validator| ((*validator).into(), 1)).collect(),
epoch_config: BABE_GENESIS_EPOCH_CONFIG,
_config: PhantomData,
},
grandpa: GrandpaConfig {
@@ -105,8 +107,7 @@ fn devnet_genesis(
}
}
/*
fn testnet_genesis(wasm_binary: &[u8], validators: Vec<&'static str>) -> RuntimeGenesisConfig {
fn testnet_genesis(validators: Vec<&'static str>) -> RuntimeGenesisConfig {
let validators = validators
.into_iter()
.map(|validator| Public::decode(&mut hex::decode(validator).unwrap().as_slice()).unwrap())
@@ -130,7 +131,7 @@ fn testnet_genesis(wasm_binary: &[u8], validators: Vec<&'static str>) -> Runtime
assert_eq!(validators.iter().collect::<HashSet<_>>().len(), validators.len());
RuntimeGenesisConfig {
system: SystemConfig { code: wasm_binary.to_vec(), _config: PhantomData },
system: SystemConfig { _config: PhantomData },
transaction_payment: Default::default(),
@@ -150,7 +151,7 @@ fn testnet_genesis(wasm_binary: &[u8], validators: Vec<&'static str>) -> Runtime
signals: SignalsConfig::default(),
babe: BabeConfig {
authorities: validators.iter().map(|validator| ((*validator).into(), 1)).collect(),
epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG),
epoch_config: BABE_GENESIS_EPOCH_CONFIG,
_config: PhantomData,
},
grandpa: GrandpaConfig {
@@ -161,18 +162,59 @@ fn testnet_genesis(wasm_binary: &[u8], validators: Vec<&'static str>) -> Runtime
}
*/
pub fn development_config() -> ChainSpec {
let wasm_binary = wasm_binary();
fn genesis(
name: &'static str,
id: &'static str,
chain_type: ChainType,
protocol_id: &'static str,
config: &RuntimeGenesisConfig,
) -> ChainSpec {
use sp_core::{
Encode,
traits::{RuntimeCode, WrappedRuntimeCode, CodeExecutor},
};
use sc_service::ChainSpec as _;
ChainSpec::from_genesis(
// Name
let bin = wasm_binary();
let hash = sp_core::blake2_256(&bin).to_vec();
let mut chain_spec = sc_chain_spec::ChainSpecBuilder::new(&bin, None)
.with_name(name)
.with_id(id)
.with_chain_type(chain_type)
.with_protocol_id(protocol_id)
.build();
let mut ext = sp_state_machine::BasicExternalities::new_empty();
let code_fetcher = WrappedRuntimeCode(bin.clone().into());
sc_executor::WasmExecutor::<sp_io::SubstrateHostFunctions>::builder()
.with_allow_missing_host_functions(true)
.build()
.call(
&mut ext,
&RuntimeCode { heap_pages: None, code_fetcher: &code_fetcher, hash },
"GenesisApi_build",
&config.encode(),
sp_core::traits::CallContext::Onchain,
)
.0
.unwrap();
let mut storage = ext.into_storages();
storage.top.insert(sp_core::storage::well_known_keys::CODE.to_vec(), bin);
chain_spec.set_storage(storage);
chain_spec
}
pub fn development_config() -> ChainSpec {
genesis(
"Development Network",
// ID
"devnet",
ChainType::Development,
move || {
devnet_genesis(
&wasm_binary,
"serai-devnet",
&(move || {
/*
let _ = devnet_genesis(
&["Alice"],
vec![
account_from_name("Alice"),
@@ -182,35 +224,22 @@ pub fn development_config() -> ChainSpec {
account_from_name("Eve"),
account_from_name("Ferdie"),
],
)
},
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
Some("serai-devnet"),
// Fork ID
None,
// Properties
None,
// Extensions
None,
);
*/
todo!("TODO")
})(),
)
}
pub fn local_config() -> ChainSpec {
let wasm_binary = wasm_binary();
ChainSpec::from_genesis(
// Name
genesis(
"Local Test Network",
// ID
"local",
ChainType::Local,
move || {
devnet_genesis(
&wasm_binary,
"serai-local",
&(move || {
/*
let _ = devnet_genesis(
&["Alice", "Bob", "Charlie", "Dave"],
vec![
account_from_name("Alice"),
@@ -220,55 +249,31 @@ pub fn local_config() -> ChainSpec {
account_from_name("Eve"),
account_from_name("Ferdie"),
],
)
},
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
Some("serai-local"),
// Fork ID
None,
// Properties
None,
// Extensions
None,
);
*/
todo!("TODO")
})(),
)
}
#[allow(clippy::redundant_closure_call)]
pub fn testnet_config() -> ChainSpec {
// let wasm_binary = wasm_binary();
ChainSpec::from_genesis(
// Name
"Test Network 2",
// ID
"testnet-2",
genesis(
"Test Network 0",
"testnet-0",
ChainType::Live,
move || {
// let _ = testnet_genesis(&wasm_binary, vec![])
todo!()
},
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
Some("serai-testnet-2"),
// Fork ID
None,
// Properties
None,
// Extensions
None,
"serai-testnet-0",
&(move || {
// let _ = testnet_genesis(vec![]);
todo!("TODO")
})(),
)
}
pub fn bootnode_multiaddrs(id: &str) -> Vec<libp2p::Multiaddr> {
match id {
"devnet" | "local" => vec![],
"testnet-2" => todo!(),
"testnet-0" => todo!("TODO"),
_ => panic!("unrecognized network ID"),
}
}

View File

@@ -48,7 +48,7 @@ impl SubstrateCli for Cli {
}
pub fn run() -> sc_cli::Result<()> {
let cli = Cli::from_args();
let mut cli = Cli::from_args();
match &cli.subcommand {
Some(Subcommand::Key(cmd)) => cmd.run(&cli),
@@ -98,11 +98,20 @@ pub fn run() -> sc_cli::Result<()> {
cli.create_runner(cmd)?.sync_run(|config| cmd.run::<Block>(&config))
}
None => cli.create_runner(&cli.run)?.run_node_until_exit(|mut config| async {
if config.role.is_authority() {
config.state_pruning = Some(PruningMode::ArchiveAll);
}
service::new_full(config).map_err(sc_cli::Error::Service)
}),
None => {
cli.run.network_params.node_key_params = sc_cli::NodeKeyParams {
node_key: None,
node_key_file: None,
node_key_type: sc_cli::arg_enums::NodeKeyType::Ed25519,
unsafe_force_node_key_generation: true,
};
cli.create_runner(&cli.run)?.run_node_until_exit(|mut config| async {
if config.role.is_authority() {
config.state_pruning = Some(PruningMode::ArchiveAll);
}
service::new_full(config).map_err(sc_cli::Error::Service)
})
}
}
}

View File

@@ -1,6 +1,6 @@
use zeroize::Zeroize;
use sp_core::{crypto::*, ed25519, sr25519};
use sp_core::{crypto::*, sr25519};
use sp_keystore::*;
pub struct Keystore(sr25519::Pair);
@@ -58,36 +58,19 @@ impl sp_keystore::Keystore for Keystore {
}
}
fn sr25519_vrf_output(
fn sr25519_vrf_pre_output(
&self,
_: KeyTypeId,
public: &sr25519::Public,
input: &sr25519::vrf::VrfInput,
) -> Result<Option<sr25519::vrf::VrfOutput>, Error> {
) -> Result<Option<sr25519::vrf::VrfPreOutput>, Error> {
if public == &self.0.public() {
Ok(Some(self.0.vrf_output(input)))
Ok(Some(self.0.vrf_pre_output(input)))
} else {
Ok(None)
}
}
fn ed25519_public_keys(&self, _: KeyTypeId) -> Vec<ed25519::Public> {
panic!("asked for ed25519 keys");
}
fn ed25519_generate_new(&self, _: KeyTypeId, _: Option<&str>) -> Result<ed25519::Public, Error> {
panic!("asked to generate an ed25519 key");
}
fn ed25519_sign(
&self,
_: KeyTypeId,
_: &ed25519::Public,
_: &[u8],
) -> Result<Option<ed25519::Signature>, Error> {
panic!("asked to produce an ed25519 signature");
}
fn insert(&self, _: KeyTypeId, _: &str, _: &[u8]) -> Result<(), ()> {
panic!("asked to insert a key");
}

View File

@@ -1,7 +1,10 @@
#![expect(unused_imports)]
use std::{sync::Arc, ops::Deref, collections::HashSet};
use rand_core::{RngCore, OsRng};
use sp_core::Encode;
use sp_blockchain::{Error as BlockchainError, HeaderBackend, HeaderMetadata};
use sp_block_builder::BlockBuilder;
use sp_api::ProvideRuntimeApi;
@@ -9,24 +12,25 @@ use sp_api::ProvideRuntimeApi;
use serai_runtime::{
in_instructions::primitives::Shorthand,
primitives::{ExternalNetworkId, NetworkId, PublicKey, SubstrateAmount, QuotePriceParams},
validator_sets::ValidatorSetsApi,
// validator_sets::ValidatorSetsApi,
dex::DexApi,
Block, Nonce,
Block,
Nonce,
SeraiRuntimeApi,
};
use tokio::sync::RwLock;
use jsonrpsee::{RpcModule, core::Error};
use scale::Encode;
use jsonrpsee::RpcModule;
// use scale::Encode;
pub use sc_rpc_api::DenyUnsafe;
use sc_client_api::BlockBackend;
use sc_transaction_pool_api::TransactionPool;
pub struct FullDeps<C, P> {
pub id: String,
pub client: Arc<C>,
pub pool: Arc<P>,
pub deny_unsafe: DenyUnsafe,
pub authority_discovery: Option<sc_authority_discovery::Service>,
}
@@ -34,6 +38,7 @@ pub fn create_full<
C: ProvideRuntimeApi<Block>
+ HeaderBackend<Block>
+ HeaderMetadata<Block, Error = BlockchainError>
+ BlockBackend<Block>
+ Send
+ Sync
+ 'static,
@@ -42,9 +47,9 @@ pub fn create_full<
deps: FullDeps<C, P>,
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
where
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, PublicKey, Nonce>
C::Api: frame_system_rpc_runtime_api::AccountNonceApi<Block, PublicKey, Nonce>
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, SubstrateAmount>
+ ValidatorSetsApi<Block>
+ SeraiRuntimeApi<Block>
+ DexApi<Block>
+ BlockBuilder<Block>,
{
@@ -56,9 +61,9 @@ where
use bitcoin_serai::bitcoin;
let mut module = RpcModule::new(());
let FullDeps { id, client, pool, deny_unsafe, authority_discovery } = deps;
let FullDeps { id, client, pool, authority_discovery } = deps;
module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(System::new(client.clone(), pool).into_rpc())?;
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
if let Some(authority_discovery) = authority_discovery {
@@ -66,17 +71,25 @@ where
RpcModule::new((id, client.clone(), RwLock::new(authority_discovery)));
authority_discovery_module.register_async_method(
"p2p_validators",
|params, context| async move {
let network: NetworkId = params.parse()?;
|params, context, _ext| async move {
let [network]: [NetworkId; 1] = params.parse()?;
let (id, client, authority_discovery) = &*context;
let latest_block = client.info().best_hash;
let validators = client.runtime_api().validators(latest_block, network).map_err(|_| {
Error::to_call_error(std::io::Error::other(format!(
"couldn't get validators from the latest block, which is likely a fatal bug. {}",
"please report this at https://github.com/serai-dex/serai/issues",
)))
})?;
jsonrpsee::types::error::ErrorObjectOwned::owned(
-1,
format!(
"couldn't get validators from the latest block, which is likely a fatal bug. {}",
"please report this at https://github.com/serai-dex/serai",
),
Option::<()>::None,
)
});
let validators = match validators {
Ok(validators) => validators,
Err(e) => return Err(e),
};
// Always return the protocol's bootnodes
let mut all_p2p_addresses = crate::chain_spec::bootnode_multiaddrs(id);
// Additionally returns validators found over the DHT
@@ -96,9 +109,9 @@ where
// It isn't beneficial to use multiple addresses for a single peer here
if !returned_addresses.is_empty() {
all_p2p_addresses.push(
returned_addresses.remove(
usize::try_from(OsRng.next_u64() >> 32).unwrap() % returned_addresses.len(),
),
returned_addresses
.remove(usize::try_from(OsRng.next_u64() >> 32).unwrap() % returned_addresses.len())
.into(),
);
}
}
@@ -108,6 +121,7 @@ where
module.merge(authority_discovery_module)?;
}
/* TODO
let mut serai_json_module = RpcModule::new(client);
// add network address rpc
@@ -199,5 +213,35 @@ where
})?;
module.merge(serai_json_module)?;
*/
let mut block_bin_module = RpcModule::new(client);
block_bin_module.register_async_method(
"chain_getBlockBin",
|params, client, _ext| async move {
let [block_hash]: [String; 1] = params.parse()?;
let Some(block_hash) = hex::decode(&block_hash).ok().and_then(|bytes| {
<[u8; 32]>::try_from(bytes.as_slice())
.map(<Block as sp_runtime::traits::Block>::Hash::from)
.ok()
}) else {
return Err(jsonrpsee::types::error::ErrorObjectOwned::owned(
-1,
"requested block hash wasn't a valid hash",
Option::<()>::None,
));
};
let Some(block) = client.block(block_hash).ok().flatten() else {
return Err(jsonrpsee::types::error::ErrorObjectOwned::owned(
-1,
"couldn't find requested block",
Option::<()>::None,
));
};
Ok(hex::encode(block.block.encode()))
},
)?;
module.merge(block_bin_module)?;
Ok(module)
}

View File

@@ -8,12 +8,11 @@ use sp_consensus_babe::{SlotDuration, inherents::InherentDataProvider as BabeInh
use sp_io::SubstrateHostFunctions;
use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, WasmExecutor};
use sc_network_common::sync::warp::WarpSyncParams;
use sc_network::{Event, NetworkEventStream};
use sc_network::{Event, NetworkEventStream, NetworkBackend};
use sc_service::{error::Error as ServiceError, Configuration, TaskManager, TFullClient};
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sc_client_api::{BlockBackend, Backend};
use sc_client_api::BlockBackend;
use sc_telemetry::{Telemetry, TelemetryWorker};
@@ -40,8 +39,8 @@ type PartialComponents = sc_service::PartialComponents<
FullClient,
FullBackend,
SelectChain,
sc_consensus::DefaultImportQueue<Block, FullClient>,
sc_transaction_pool::FullPool<Block, FullClient>,
sc_consensus::DefaultImportQueue<Block>,
sc_transaction_pool::TransactionPoolWrapper<Block, FullClient>,
(
BabeBlockImport,
sc_consensus_babe::BabeLink<Block>,
@@ -74,11 +73,11 @@ pub fn new_partial(
#[allow(deprecated)]
let executor = Executor::new(
config.wasm_method,
config.default_heap_pages,
config.max_runtime_instances,
config.executor.wasm_method,
config.executor.default_heap_pages,
config.executor.max_runtime_instances,
None,
config.runtime_cache_size,
config.executor.runtime_cache_size,
);
let (client, backend, keystore_container, task_manager) =
@@ -103,16 +102,19 @@ pub fn new_partial(
let select_chain = sc_consensus::LongestChain::new(backend.clone());
let transaction_pool = sc_transaction_pool::BasicPool::new_full(
config.transaction_pool.clone(),
config.role.is_authority().into(),
config.prometheus_registry(),
let transaction_pool = sc_transaction_pool::Builder::new(
task_manager.spawn_essential_handle(),
client.clone(),
);
config.role.is_authority().into(),
)
.with_options(config.transaction_pool.clone())
.with_prometheus(config.prometheus_registry())
.build();
let transaction_pool = Arc::new(transaction_pool);
let (grandpa_block_import, grandpa_link) = grandpa::block_import(
client.clone(),
u32::MAX,
&client,
select_chain.clone(),
telemetry.as_ref().map(Telemetry::handle),
@@ -181,22 +183,26 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
config.network.listen_addresses =
vec!["/ip4/0.0.0.0/tcp/30333".parse().unwrap(), "/ip6/::/tcp/30333".parse().unwrap()];
let mut net_config = sc_network::config::FullNetworkConfiguration::new(&config.network);
type N = sc_network::service::NetworkWorker<Block, <Block as sp_runtime::traits::Block>::Hash>;
let mut net_config = sc_network::config::FullNetworkConfiguration::<_, _, N>::new(
&config.network,
config.prometheus_registry().cloned(),
);
let metrics = N::register_notification_metrics(config.prometheus_registry());
let grandpa_protocol_name =
grandpa::protocol_standard_name(&client.block_hash(0).unwrap().unwrap(), &config.chain_spec);
net_config.add_notification_protocol(sc_consensus_grandpa::grandpa_peers_set_config(
grandpa_protocol_name.clone(),
));
let (grandpa_protocol_config, grandpa_notification_service) =
sc_consensus_grandpa::grandpa_peers_set_config::<Block, N>(
grandpa_protocol_name.clone(),
metrics.clone(),
net_config.peer_store_handle(),
);
net_config.add_notification_protocol(grandpa_protocol_config);
let publish_non_global_ips = config.network.allow_non_globals_in_dht;
let warp_sync = Arc::new(grandpa::warp_proof::NetworkProvider::new(
backend.clone(),
grandpa_link.shared_authority_set().clone(),
vec![],
));
let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
let (network, system_rpc_tx, tx_handler_controller, sync_service) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
net_config,
@@ -205,7 +211,9 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
spawn_handle: task_manager.spawn_handle(),
import_queue,
block_announce_validator_builder: None,
warp_sync_params: Some(WarpSyncParams::WithProvider(warp_sync)),
metrics,
block_relay: None,
warp_sync_config: None,
})?;
task_manager.spawn_handle().spawn("bootnodes", "bootnodes", {
@@ -217,7 +225,15 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
// While the PeerIds *should* be known in advance and hardcoded, that data wasn't collected in
// time and this fine for a testnet
let bootnodes = || async {
use libp2p::{Transport as TransportTrait, tcp::tokio::Transport, noise::Config};
use libp2p::{
core::{
Endpoint,
transport::{PortUse, DialOpts},
},
Transport as TransportTrait,
tcp::tokio::Transport,
noise::Config,
};
let bootnode_multiaddrs = crate::chain_spec::bootnode_multiaddrs(&id);
@@ -231,9 +247,17 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
.upgrade(libp2p::core::upgrade::Version::V1)
.authenticate(noise)
.multiplex(libp2p::yamux::Config::default());
let Ok(transport) = transport.dial(multiaddr.clone()) else { None? };
let Ok(transport) = transport.dial(
multiaddr.clone(),
DialOpts { role: Endpoint::Dialer, port_use: PortUse::Reuse },
) else {
None?
};
let Ok((peer_id, _)) = transport.await else { None? };
Some(sc_network::config::MultiaddrWithPeerId { multiaddr, peer_id })
Some(sc_network::config::MultiaddrWithPeerId {
multiaddr: multiaddr.into(),
peer_id: peer_id.into(),
})
}),
));
}
@@ -261,26 +285,12 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
}
});
if config.offchain_worker.enabled {
task_manager.spawn_handle().spawn(
"offchain-workers-runner",
"offchain-worker",
sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions {
runtime_api_provider: client.clone(),
is_validator: config.role.is_authority(),
keystore: Some(keystore_container.clone()),
offchain_db: backend.offchain_storage(),
transaction_pool: Some(OffchainTransactionPoolFactory::new(transaction_pool.clone())),
network_provider: network.clone(),
enable_http_requests: true,
custom_extensions: |_| vec![],
})
.run(client.clone(), task_manager.spawn_handle()),
);
}
let role = config.role.clone();
let role = config.role;
let keystore = keystore_container;
if let Some(seed) = config.dev_key_seed.as_ref() {
let _ =
keystore.sr25519_generate_new(sp_core::crypto::key_types::AUTHORITY_DISCOVERY, Some(seed));
}
let prometheus_registry = config.prometheus_registry().cloned();
// TODO: Ensure we're considered as an authority is a validator of an external network
@@ -294,7 +304,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
worker
},
client.clone(),
network.clone(),
Arc::new(network.clone()),
Box::pin(network.event_stream("authority-discovery").filter_map(|e| async move {
match e {
Event::Dht(e) => Some(e),
@@ -303,6 +313,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
})),
sc_authority_discovery::Role::PublishAndDiscover(keystore.clone()),
prometheus_registry.clone(),
task_manager.spawn_handle(),
);
task_manager.spawn_handle().spawn(
"authority-discovery-worker",
@@ -320,12 +331,11 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
let client = client.clone();
let pool = transaction_pool.clone();
Box::new(move |deny_unsafe, _| {
Box::new(move |_| {
crate::rpc::create_full(crate::rpc::FullDeps {
id: id.clone(),
client: client.clone(),
pool: pool.clone(),
deny_unsafe,
authority_discovery: authority_discovery.clone(),
})
.map_err(Into::into)
@@ -392,7 +402,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
grandpa::run_grandpa_voter(grandpa::GrandpaParams {
config: grandpa::Config {
gossip_duration: std::time::Duration::from_millis(333),
justification_period: 512,
justification_generation_period: 512,
name: Some(name),
observer_enabled: false,
keystore: if role.is_authority() { Some(keystore) } else { None },
@@ -408,10 +418,10 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
prometheus_registry,
shared_voter_state,
offchain_tx_pool_factory: OffchainTransactionPoolFactory::new(transaction_pool),
notification_service: grandpa_notification_service,
})?,
);
}
network_starter.start_network();
Ok(task_manager)
}

View File

@@ -21,24 +21,23 @@ zeroize = { version = "^1.5", features = ["derive"], optional = true }
ciphersuite = { path = "../../crypto/ciphersuite", default-features = false, optional = true }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
borsh = { version = "1", default-features = false, features = ["derive", "de_strict_order"], optional = true }
serde = { version = "1", default-features = false, features = ["derive", "alloc"], optional = true }
sp-application-crypto = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-io = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-application-crypto = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
[dev-dependencies]
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }
[features]
std = ["zeroize", "ciphersuite/std", "scale/std", "borsh?/std", "serde?/std", "scale-info/std", "sp-core/std", "sp-runtime/std", "sp-std/std", "frame-support/std"]
std = ["zeroize", "ciphersuite/std", "scale/std", "borsh?/std", "serde?/std", "sp-core/std", "sp-runtime/std", "sp-std/std", "frame-support/std"]
borsh = ["dep:borsh"]
serde = ["dep:serde"]
default = ["std"]

View File

@@ -6,8 +6,7 @@ use borsh::{BorshSerialize, BorshDeserialize};
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
use scale::{Encode, Decode, DecodeWithMemTracking, MaxEncodedLen};
use sp_core::sr25519::Public;
pub use sp_core::sr25519::Signature;
@@ -31,7 +30,7 @@ pub fn borsh_deserialize_public<R: borsh::io::Read>(
reader: &mut R,
) -> Result<Public, borsh::io::Error> {
let public: [u8; 32] = borsh::BorshDeserialize::deserialize_reader(reader)?;
Ok(Public(public))
Ok(public.into())
}
#[cfg(feature = "borsh")]
@@ -47,12 +46,23 @@ pub fn borsh_deserialize_signature<R: borsh::io::Read>(
reader: &mut R,
) -> Result<Signature, borsh::io::Error> {
let signature: [u8; 64] = borsh::BorshDeserialize::deserialize_reader(reader)?;
Ok(Signature(signature))
Ok(signature.into())
}
// TODO: Remove this for solely Public?
#[derive(
Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Encode, Decode, MaxEncodedLen, TypeInfo,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Debug,
Encode,
Decode,
DecodeWithMemTracking,
MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]

View File

@@ -11,8 +11,7 @@ use borsh::{BorshSerialize, BorshDeserialize};
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
use scale::{Encode, Decode, DecodeWithMemTracking, MaxEncodedLen};
/// The type used for amounts within Substrate.
// Distinct from Amount due to Substrate's requirements on this type.
@@ -22,7 +21,16 @@ use scale_info::TypeInfo;
pub type SubstrateAmount = u64;
/// The type used for amounts.
#[derive(
Clone, Copy, PartialEq, Eq, PartialOrd, Debug, Encode, Decode, MaxEncodedLen, TypeInfo,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Debug,
Encode,
Decode,
DecodeWithMemTracking,
MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]

View File

@@ -8,13 +8,14 @@ use borsh::{BorshSerialize, BorshDeserialize};
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
use scale::{Encode, Decode, DecodeWithMemTracking, MaxEncodedLen};
use crate::{Amount, Coin, ExternalCoin};
/// The type used for balances (a Coin and Balance).
#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(
Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -24,7 +25,9 @@ pub struct Balance {
}
/// The type used for balances (a Coin and Balance).
#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(
Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

View File

@@ -6,14 +6,23 @@ use borsh::{BorshSerialize, BorshDeserialize};
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
use scale::{Encode, Decode, DecodeWithMemTracking, MaxEncodedLen};
use sp_core::H256;
/// The type used to identify block numbers.
#[derive(
Clone, Copy, Default, PartialEq, Eq, Hash, Debug, Encode, Decode, MaxEncodedLen, TypeInfo,
Clone,
Copy,
Default,
PartialEq,
Eq,
Hash,
Debug,
Encode,
Decode,
DecodeWithMemTracking,
MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
@@ -30,7 +39,9 @@ impl From<u64> for BlockNumber {
// If a block exists with a hash which isn't 32-bytes, it can be hashed into a value with 32-bytes
// This would require the processor to maintain a mapping of 32-byte IDs to actual hashes, which
// would be fine
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(
Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

View File

@@ -10,8 +10,7 @@ use borsh::{BorshSerialize, BorshDeserialize};
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
use scale::{Encode, Decode, DecodeWithMemTracking, MaxEncodedLen};
#[cfg(test)]
use sp_io::TestExternalities;
@@ -65,7 +64,7 @@ pub fn borsh_deserialize_bounded_vec<R: borsh::io::Read, T: BorshDeserialize, co
pub const MAX_ADDRESS_LEN: u32 = 512;
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen)]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ExternalAddress(
@@ -103,6 +102,51 @@ impl AsRef<[u8]> for ExternalAddress {
}
}
// Should be enough for a Uniswap v3 call
pub const MAX_DATA_LEN: u32 = 512;
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen)]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Data(
#[cfg_attr(
feature = "borsh",
borsh(
serialize_with = "borsh_serialize_bounded_vec",
deserialize_with = "borsh_deserialize_bounded_vec"
)
)]
BoundedVec<u8, ConstU32<{ MAX_DATA_LEN }>>,
);
#[cfg(feature = "std")]
impl Zeroize for Data {
fn zeroize(&mut self) {
self.0.as_mut().zeroize()
}
}
impl Data {
#[cfg(feature = "std")]
pub fn new(data: Vec<u8>) -> Result<Data, &'static str> {
Ok(Data(data.try_into().map_err(|_| "data length exceeds {MAX_DATA_LEN}")?))
}
pub fn data(&self) -> &[u8] {
self.0.as_ref()
}
#[cfg(feature = "std")]
pub fn consume(self) -> Vec<u8> {
self.0.into_inner()
}
}
impl AsRef<[u8]> for Data {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
}
}
/// Lexicographically reverses a given byte array.
pub fn reverse_lexicographic_order<const N: usize>(bytes: [u8; N]) -> [u8; N] {
let mut res = [0u8; N];

View File

@@ -1,8 +1,7 @@
#[cfg(feature = "std")]
use zeroize::Zeroize;
use scale::{Decode, Encode, EncodeLike, MaxEncodedLen};
use scale_info::TypeInfo;
use scale::{Encode, EncodeLike, Decode, DecodeWithMemTracking, MaxEncodedLen};
#[cfg(feature = "borsh")]
use borsh::{BorshSerialize, BorshDeserialize};
@@ -16,7 +15,18 @@ use sp_std::{vec, vec::Vec};
use crate::{borsh_serialize_bounded_vec, borsh_deserialize_bounded_vec};
/// Identifier for an embedded elliptic curve.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(
Clone,
Copy,
PartialEq,
Eq,
Hash,
Debug,
Encode,
Decode,
MaxEncodedLen,
scale::DecodeWithMemTracking,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -26,7 +36,7 @@ pub enum EmbeddedEllipticCurve {
}
/// The type used to identify external networks.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TypeInfo)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum ExternalNetworkId {
@@ -57,6 +67,8 @@ impl Decode for ExternalNetworkId {
}
}
impl DecodeWithMemTracking for ExternalNetworkId {}
impl MaxEncodedLen for ExternalNetworkId {
fn max_encoded_len() -> usize {
1
@@ -83,7 +95,7 @@ impl BorshDeserialize for ExternalNetworkId {
}
/// The type used to identify networks.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord, TypeInfo)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum NetworkId {
@@ -110,6 +122,8 @@ impl Decode for NetworkId {
}
}
impl DecodeWithMemTracking for NetworkId {}
impl MaxEncodedLen for NetworkId {
fn max_encoded_len() -> usize {
1
@@ -220,7 +234,7 @@ pub const COINS: [Coin; 5] = [
];
/// The type used to identify external coins.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TypeInfo)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum ExternalCoin {
@@ -253,6 +267,9 @@ impl Decode for ExternalCoin {
}
}
}
impl DecodeWithMemTracking for ExternalCoin {}
impl MaxEncodedLen for ExternalCoin {
fn max_encoded_len() -> usize {
1
@@ -278,7 +295,7 @@ impl BorshDeserialize for ExternalCoin {
}
/// The type used to identify coins.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TypeInfo)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum Coin {
@@ -305,6 +322,8 @@ impl Decode for Coin {
}
}
impl DecodeWithMemTracking for Coin {}
impl MaxEncodedLen for Coin {
fn max_encoded_len() -> usize {
1

View File

@@ -12,48 +12,47 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[package.metadata.cargo-machete]
ignored = ["scale", "scale-info"]
ignored = ["scale"]
[lints]
workspace = true
[dependencies]
hashbrown = { version = "0.15", default-features = false, features = ["default-hasher", "inline-more"] }
hashbrown = { version = "0.16", default-features = false, features = ["default-hasher", "inline-more"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-offchain = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-version = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-inherents = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-offchain = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-version = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-inherents = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-session = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-consensus-babe = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-consensus-grandpa = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-consensus-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-authority-discovery = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-authority-discovery = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-transaction-pool = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-block-builder = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-transaction-pool = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-block-builder = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-api = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-system = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-executive = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-benchmarking = { git = "https://github.com/serai-dex/substrate", default-features = false, optional = true }
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-executive = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-benchmarking = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false, optional = true }
serai-primitives = { path = "../primitives", default-features = false }
serai-abi = { path = "../abi", default-features = false, features = ["serde"] }
pallet-timestamp = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-authorship = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
pallet-authorship = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
pallet-transaction-payment = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-transaction-payment = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
coins-pallet = { package = "serai-coins-pallet", path = "../coins/pallet", default-features = false }
dex-pallet = { package = "serai-dex-pallet", path = "../dex/pallet", default-features = false }
@@ -68,19 +67,19 @@ in-instructions-pallet = { package = "serai-in-instructions-pallet", path = "../
signals-pallet = { package = "serai-signals-pallet", path = "../signals/pallet", default-features = false }
pallet-babe = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-grandpa = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-system-rpc-runtime-api = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-system-rpc-runtime-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
[build-dependencies]
substrate-wasm-builder = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "19c487d6aa9893b6b09a21ce0ab8aefb1c299186" }
substrate-wasm-builder = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
[features]
std = [
"scale/std",
"scale-info/std",
"sp-core/std",
"sp-std/std",
@@ -127,6 +126,7 @@ std = [
"signals-pallet/std",
"pallet-session/std",
"pallet-babe/std",
"pallet-grandpa/std",

View File

@@ -201,6 +201,7 @@ impl TryInto<Call> for RuntimeCall {
fn try_into(self) -> Result<Call, ()> {
Ok(match self {
RuntimeCall::System(_) => Err(())?,
RuntimeCall::Timestamp(timestamp::Call::set { now }) => {
Call::Timestamp(serai_abi::timestamp::Call::set { now })
}

View File

@@ -1,3 +1,4 @@
#![allow(deprecated)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
@@ -36,13 +37,9 @@ pub use emissions_pallet as emissions;
pub use economic_security_pallet as economic_security;
// Actually used by the runtime
use sp_core::OpaqueMetadata;
use sp_std::prelude::*;
use sp_version::RuntimeVersion;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, KeyTypeId,
@@ -113,16 +110,12 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_name: create_runtime_str!("core"),
spec_version: 1,
impl_version: 1,
authoring_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
system_version: 1,
};
#[cfg(feature = "std")]
pub fn native_version() -> NativeVersion {
NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
}
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
pub const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration =
sp_consensus_babe::BabeEpochConfiguration {
@@ -136,8 +129,6 @@ parameter_types! {
pub const BlockHashCount: BlockNumber = 2400;
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);
@@ -181,9 +172,16 @@ impl system::Config for Runtime {
type AccountData = ();
type SystemWeightInfo = ();
type SS58Prefix = SS58Prefix; // TODO: Remove for Bech32m
type MaxConsumers = support::traits::ConstU32<16>;
type RuntimeTask = ();
type ExtensionsWeightInfo = (); // TODO
type SingleBlockMigrations = ();
type MultiBlockMigrator = ();
type PreInherents = ();
type PostInherents = ();
type PostTransactions = ();
}
impl timestamp::Config for Runtime {
@@ -200,21 +198,18 @@ impl transaction_payment::Config for Runtime {
type WeightToFee = IdentityFee<SubstrateAmount>;
type LengthToFee = IdentityFee<SubstrateAmount>;
type FeeMultiplierUpdate = ();
type WeightInfo = ();
}
impl coins::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type AllowMint = ValidatorSets;
}
impl coins::Config<coins::Instance1> for Runtime {
type RuntimeEvent = RuntimeEvent;
type AllowMint = ();
}
impl dex::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type LPFee = ConstU32<3>; // 0.3%
type MintMinLiquidity = ConstU64<10000>;
@@ -226,8 +221,6 @@ impl dex::Config for Runtime {
}
impl validator_sets::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ShouldEndSession = Babe;
}
@@ -239,7 +232,6 @@ impl Convert<PublicKey, Option<PublicKey>> for IdentityValidatorIdOf {
}
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) }>;
@@ -248,30 +240,13 @@ impl signals::Config for Runtime {
type RetirementLockInDuration = ConstU32<{ (2 * 7 * 24 * 60 * 60) / (TARGET_BLOCK_TIME as u32) }>;
}
impl in_instructions::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}
impl in_instructions::Config for Runtime {}
impl genesis_liquidity::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}
impl genesis_liquidity::Config for Runtime {}
impl emissions::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}
impl emissions::Config for Runtime {}
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;
}
impl economic_security::Config for Runtime {}
// for validating equivocation evidences.
// The following runtime construction doesn't actually implement the pallet as doing so is
@@ -301,6 +276,7 @@ impl babe::Config for Runtime {
type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxNominators = ConstU32<1>;
type KeyOwnerProof = MembershipProof<Self>;
type EquivocationReportSystem =
@@ -312,6 +288,7 @@ impl grandpa::Config for Runtime {
type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxNominators = ConstU32<1>;
type MaxSetIdSessionEntries = ConstU64<0>;
type KeyOwnerProof = MembershipProof<Self>;
@@ -319,6 +296,17 @@ impl grandpa::Config for Runtime {
grandpa::EquivocationReportSystem<Self, ValidatorSets, ValidatorSets, ReportLongevity>;
}
#[doc(hidden)]
pub struct GetCurrentSessionForSubstrate;
impl pallet_session::GetCurrentSessionForSubstrate for GetCurrentSessionForSubstrate {
fn get() -> u32 {
validator_sets::Pallet::<Runtime>::latest_decided_session(NetworkId::Serai).unwrap().0 - 1
}
}
impl pallet_session::Config for Runtime {
type Session = GetCurrentSessionForSubstrate;
}
pub type Executive = frame_executive::Executive<
Runtime,
Block,
@@ -329,7 +317,7 @@ pub type Executive = frame_executive::Executive<
construct_runtime!(
pub enum Runtime {
System: system exclude_parts { Call },
System: system,
Timestamp: timestamp,
@@ -374,6 +362,18 @@ mod benches {
);
}
sp_api::decl_runtime_apis! {
#[api_version(1)]
pub trait SeraiRuntimeApi {
fn validators(network_id: NetworkId) -> Vec<PublicKey>;
}
#[api_version(1)]
pub trait GenesisApi {
fn build(genesis: RuntimeGenesisConfig);
}
}
sp_api::impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
@@ -381,30 +381,35 @@ sp_api::impl_runtime_apis! {
}
fn execute_block(block: Block) {
for tx in &block.extrinsics {
if let Some(signer) = tx.signer() {
let signer = PublicKey::from(signer.0);
let mut info = frame_system::Account::<Runtime>::get(signer);
if info.providers == 0 {
info.providers = 1;
frame_system::Account::<Runtime>::set(signer, info);
}
}
}
Executive::execute_block(block);
}
fn initialize_block(header: &Header) {
Executive::initialize_block(header)
}
}
impl sp_api::Metadata<Block> for Runtime {
fn metadata() -> OpaqueMetadata {
OpaqueMetadata::new(Runtime::metadata().into())
}
fn metadata_at_version(version: u32) -> Option<OpaqueMetadata> {
Runtime::metadata_at_version(version)
}
fn metadata_versions() -> sp_std::vec::Vec<u32> {
Runtime::metadata_versions()
fn initialize_block(header: &Header) -> sp_runtime::ExtrinsicInclusionMode {
Executive::initialize_block(header);
sp_runtime::ExtrinsicInclusionMode::AllExtrinsics
}
}
impl sp_block_builder::BlockBuilder<Block> for Runtime {
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {
if let Some(signer) = extrinsic.signer() {
let signer = PublicKey::from(signer.0);
let mut info = frame_system::Account::<Runtime>::get(signer);
if info.providers == 0 {
info.providers = 1;
frame_system::Account::<Runtime>::set(signer, info);
}
}
Executive::apply_extrinsic(extrinsic)
}
@@ -430,6 +435,14 @@ sp_api::impl_runtime_apis! {
tx: <Block as BlockT>::Extrinsic,
block_hash: <Block as BlockT>::Hash,
) -> TransactionValidity {
if let Some(signer) = tx.signer() {
let signer = PublicKey::from(signer.0);
let mut info = frame_system::Account::<Runtime>::get(signer);
if info.providers == 0 {
info.providers = 1;
frame_system::Account::<Runtime>::set(signer, info);
}
}
Executive::validate_transaction(source, tx, block_hash)
}
}
@@ -582,6 +595,24 @@ sp_api::impl_runtime_apis! {
}
}
impl crate::SeraiRuntimeApi<Block> for Runtime {
fn validators(network_id: NetworkId) -> Vec<PublicKey> {
if network_id == NetworkId::Serai {
Babe::authorities()
.into_iter()
.map(|(id, _)| id.into_inner())
.collect()
} else {
ValidatorSets::participants_for_latest_decided_set(network_id)
.map_or(
vec![],
|vec| vec.into_inner().into_iter().map(|(validator, _)| validator).collect()
)
}
}
}
/*
impl validator_sets::ValidatorSetsApi<Block> for Runtime {
fn validators(network_id: NetworkId) -> Vec<PublicKey> {
if network_id == NetworkId::Serai {
@@ -602,6 +633,13 @@ sp_api::impl_runtime_apis! {
ValidatorSets::external_network_key(network)
}
}
*/
impl crate::GenesisApi<Block> for Runtime {
fn build(genesis: RuntimeGenesisConfig) {
<RuntimeGenesisConfig as frame_support::traits::BuildGenesisConfig>::build(&genesis)
}
}
impl dex::DexApi<Block> for Runtime {
fn quote_price_exact_tokens_for_tokens(
@@ -627,3 +665,20 @@ sp_api::impl_runtime_apis! {
}
}
}
impl<LocalCall> frame_system::offchain::CreateTransactionBase<LocalCall> for Runtime
where
RuntimeCall: From<LocalCall>,
{
type Extrinsic = <Block as BlockT>::Extrinsic;
type RuntimeCall = RuntimeCall;
}
impl<LocalCall> frame_system::offchain::CreateBare<LocalCall> for Runtime
where
RuntimeCall: From<LocalCall>,
{
fn create_bare(call: RuntimeCall) -> <Block as BlockT>::Extrinsic {
<<Block as BlockT>::Extrinsic as frame_support::traits::InherentBuilder>::new_inherent(call)
}
}

View File

@@ -13,20 +13,19 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[package.metadata.cargo-machete]
ignored = ["scale", "scale-info"]
ignored = ["scale"]
[lints]
workspace = true
[dependencies]
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-io = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-system = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
serai-primitives = { path = "../../primitives", default-features = false }
serai-signals-primitives = { path = "../primitives", default-features = false }
@@ -37,7 +36,6 @@ in-instructions-pallet = { package = "serai-in-instructions-pallet", path = "../
[features]
std = [
"scale/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",

View File

@@ -9,8 +9,6 @@
)] // TODO
#[frame_support::pallet]
pub mod pallet {
use scale_info::TypeInfo;
use sp_core::sr25519::Public;
use sp_io::hashing::blake2_256;
@@ -25,17 +23,13 @@ pub mod pallet {
use in_instructions_pallet::{Config as IiConfig, Pallet as InInstructions};
#[pallet::config]
pub trait Config:
frame_system::Config<AccountId = Public> + VsConfig + IiConfig + TypeInfo
{
type RuntimeEvent: IsType<<Self as frame_system::Config>::RuntimeEvent> + From<Event<Self>>;
pub trait Config: frame_system::Config<AccountId = Public> + VsConfig + IiConfig {
type RetirementValidityDuration: Get<u32>;
type RetirementLockInDuration: Get<u32>;
}
#[pallet::genesis_config]
#[derive(Debug, Encode, Decode)]
#[derive(Debug)]
pub struct GenesisConfig<T: Config> {
_config: PhantomData<T>,
}
@@ -56,7 +50,7 @@ pub mod pallet {
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen)]
pub struct RegisteredRetirementSignal<T: Config> {
in_favor_of: [u8; 32],
registrant: T::AccountId,

View File

@@ -19,7 +19,6 @@ workspace = true
zeroize = { version = "^1.5", features = ["derive"], optional = true }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
borsh = { version = "1", default-features = false, features = ["derive", "de_strict_order"], optional = true }
serde = { version = "1", default-features = false, features = ["derive", "alloc"], optional = true }
@@ -31,7 +30,6 @@ std = [
"zeroize",
"scale/std",
"scale-info/std",
"borsh?/std",
"serde?/std",

View File

@@ -1,13 +1,15 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
#![expect(clippy::cast_possible_truncation)]
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
use scale::{Encode, Decode, DecodeWithMemTracking, MaxEncodedLen};
use serai_primitives::ExternalNetworkId;
#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(
Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(zeroize::Zeroize))]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]

View File

@@ -12,31 +12,31 @@ rust-version = "1.85"
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[package.metadata.cargo-machete]
ignored = ["scale"]
[lints]
workspace = true
[dependencies]
bitvec = { version = "1", default-features = false, features = ["alloc", "serde"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "bit-vec"] }
scale-info = { version = "2", default-features = false, features = ["derive", "bit-vec"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
serde = { version = "1", default-features = false, features = ["derive", "alloc"] }
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-io = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-application-crypto = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-staking = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-io = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-api = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-application-crypto = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-session = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-staking = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-system = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
frame-system = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-babe = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-grandpa = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
serai-primitives = { path = "../../primitives", default-features = false }
validator-sets-primitives = { package = "serai-validator-sets-primitives", path = "../primitives", default-features = false }
@@ -45,9 +45,10 @@ coins-pallet = { package = "serai-coins-pallet", path = "../../coins/pallet", de
dex-pallet = { package = "serai-dex-pallet", path = "../../dex/pallet", default-features = false }
[dev-dependencies]
pallet-timestamp = { git = "https://github.com/serai-dex/substrate", default-features = false }
pallet-timestamp = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
pallet-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b" }
sp-consensus-babe = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-consensus-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
ciphersuite = { path = "../../../crypto/ciphersuite", default-features = false, features = ["std"] }
dalek-ff-group = { path = "../../../crypto/dalek-ff-group", default-features = false, features = ["std"] }
@@ -63,15 +64,13 @@ std = [
"bitvec/std",
"scale/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-std/std",
"sp-api/std",
"sp-application-crypto/std",
"sp-runtime/std",
"sp-session/std",
"sp-runtime/std",
"sp-staking/std",
"sp-consensus-babe/std",
@@ -79,6 +78,7 @@ std = [
"frame-system/std",
"frame-support/std",
"pallet-session/std",
"pallet-babe/std",
"pallet-grandpa/std",
"pallet-timestamp/std",

View File

@@ -8,13 +8,13 @@ mod tests;
use core::marker::PhantomData;
use scale::{Encode, Decode};
use scale_info::TypeInfo;
use scale::{Encode, Decode, DecodeWithMemTracking};
use sp_std::{vec, vec::Vec};
use sp_core::sr25519::{Public, Signature};
use sp_application_crypto::RuntimePublic;
use sp_session::{ShouldEndSession, GetSessionNumber, GetValidatorCount};
use sp_session::{GetSessionNumber, GetValidatorCount};
use pallet_session::ShouldEndSession;
use sp_runtime::{KeyTypeId, ConsensusEngineId, traits::IsMember};
use sp_staking::offence::{ReportOffence, Offence, OffenceError};
@@ -22,7 +22,7 @@ use frame_system::{pallet_prelude::*, RawOrigin};
use frame_support::{
pallet_prelude::*,
sp_runtime::SaturatedConversion,
traits::{DisabledValidators, KeyOwnerProofSystem, FindAuthor},
traits::{DisabledValidators, KeyOwnerProofSystem, FindAuthor, OneSessionHandler},
BoundedVec, WeakBoundedVec, StoragePrefixedMap,
};
@@ -41,7 +41,7 @@ use pallet_grandpa::{
EquivocationOffence as GrandpaEquivocationOffence,
};
#[derive(Debug, Encode, Decode, TypeInfo, PartialEq, Eq, Clone)]
#[derive(Debug, Encode, Decode, DecodeWithMemTracking, PartialEq, Eq, Clone)]
pub struct MembershipProof<T: pallet::Config>(pub Public, pub PhantomData<T>);
impl<T: pallet::Config> GetSessionNumber for MembershipProof<T> {
fn session(&self) -> u32 {
@@ -80,23 +80,21 @@ pub mod pallet {
frame_system::Config<AccountId = Public>
+ coins_pallet::Config
+ dex_pallet::Config
+ pallet_session::Config
+ pallet_babe::Config
+ pallet_grandpa::Config
+ TypeInfo
{
type RuntimeEvent: IsType<<Self as frame_system::Config>::RuntimeEvent> + From<Event<Self>>;
type ShouldEndSession: ShouldEndSession<BlockNumberFor<Self>>;
}
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
pub struct AllEmbeddedEllipticCurveKeysAtGenesis {
pub embedwards25519: BoundedVec<u8, ConstU32<{ MAX_KEY_LEN }>>,
pub secq256k1: BoundedVec<u8, ConstU32<{ MAX_KEY_LEN }>>,
}
#[pallet::genesis_config]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
#[derive(Clone, Debug)]
pub struct GenesisConfig<T: Config> {
/// Networks to spawn Serai with, and the stake requirement per key share.
///
@@ -266,7 +264,8 @@ pub mod pallet {
Amount(u64::from_be_bytes(raw))
}
fn recover_key_from_sorted_allocation_key(key: &[u8]) -> Public {
Public(key[(key.len() - 32) ..].try_into().unwrap())
let key: [u8; 32] = key[(key.len() - 32) ..].try_into().unwrap();
key.into()
}
// Returns if this validator already had an allocation set.
fn set_allocation(network: NetworkId, key: Public, amount: Amount) -> bool {
@@ -861,10 +860,13 @@ pub mod pallet {
),
Some(session),
);
Grandpa::<T>::new_session(
fn grandpa_map(i: &(Public, u64)) -> (&Public, GrandpaAuthorityId) {
(&i.0, i.0.into())
}
Grandpa::<T>::on_new_session(
true,
session,
now_validators.into_iter().map(|(id, w)| (GrandpaAuthorityId::from(id), w)).collect(),
now_validators.iter().map(grandpa_map),
next_validators.iter().map(grandpa_map),
);
// Clear SeraiDisabledIndices, only preserving keys still present in the new session
@@ -1370,19 +1372,17 @@ pub mod pallet {
fn is_disabled(index: u32) -> bool {
SeraiDisabledIndices::<T>::get(index).is_some()
}
}
}
sp_api::decl_runtime_apis! {
#[api_version(1)]
pub trait ValidatorSetsApi {
/// Returns the validator set for a given network.
fn validators(network_id: NetworkId) -> Vec<PublicKey>;
/// Returns the external network key for a given external network.
fn external_network_key(
network: ExternalNetworkId,
) -> Option<Vec<u8>>;
fn disabled_validators() -> Vec<u32> {
// TODO: Use a storage iterator here
let mut res = vec![];
for i in 0 .. MAX_KEY_SHARES_PER_SET {
let i = i.into();
if Self::is_disabled(i) {
res.push(i);
}
}
res
}
}
}

View File

@@ -5,7 +5,7 @@ use super::*;
use std::collections::HashMap;
use frame_support::{
construct_runtime,
derive_impl, construct_runtime,
traits::{ConstU16, ConstU32, ConstU64},
};
@@ -55,10 +55,9 @@ construct_runtime!(
}
);
#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Nonce = u64;
@@ -69,16 +68,6 @@ impl frame_system::Config for Test {
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = ConstU32<16>;
}
impl timestamp::Config for Test {
@@ -88,6 +77,16 @@ impl timestamp::Config for Test {
type WeightInfo = ();
}
pub struct GetSession;
impl pallet_session::GetCurrentSessionForSubstrate for GetSession {
fn get() -> u32 {
0
}
}
impl pallet_session::Config for Test {
type Session = GetSession;
}
impl babe::Config for Test {
type EpochDuration = ConstU64<{ FAST_EPOCH_DURATION }>;
@@ -97,6 +96,7 @@ impl babe::Config for Test {
type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxAuthorities;
type KeyOwnerProof = MembershipProof<Self>;
type EquivocationReportSystem = ();
@@ -107,6 +107,7 @@ impl grandpa::Config for Test {
type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxAuthorities;
type MaxSetIdSessionEntries = ConstU64<0>;
type KeyOwnerProof = MembershipProof<Self>;
@@ -114,18 +115,14 @@ impl grandpa::Config for Test {
}
impl coins::Config for Test {
type RuntimeEvent = RuntimeEvent;
type AllowMint = ValidatorSets;
}
impl coins::Config<coins::Instance1> for Test {
type RuntimeEvent = RuntimeEvent;
type AllowMint = ();
}
impl dex::Config for Test {
type RuntimeEvent = RuntimeEvent;
type LPFee = ConstU32<3>; // 0.3%
type MintMinLiquidity = ConstU64<10000>;
@@ -137,7 +134,6 @@ impl dex::Config for Test {
}
impl Config for Test {
type RuntimeEvent = RuntimeEvent;
type ShouldEndSession = Babe;
}
@@ -195,7 +191,7 @@ pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
.into_iter()
.map(|validator| (validator.public().into(), 1))
.collect(),
epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG),
epoch_config: BABE_GENESIS_EPOCH_CONFIG,
_config: PhantomData,
}
.assimilate_storage(&mut t)

View File

@@ -65,7 +65,7 @@ fn set_keys_for_session(network: ExternalNetworkId) {
network,
KeyPair(insecure_pair_from_name("Alice").public(), vec![].try_into().unwrap()),
vec![].try_into().unwrap(),
Signature([0u8; 64]),
Signature::from([0u8; 64]),
)
.unwrap();
}
@@ -103,7 +103,7 @@ fn set_keys_signature(set: &ExternalValidatorSet, key_pair: &KeyPair, pairs: &[P
&set_keys_message(set, key_pair),
);
Signature(sig.to_bytes())
Signature::from(sig.to_bytes())
}
fn get_ordered_keys(network: NetworkId, participants: &[Pair]) -> Vec<Pair> {
@@ -465,7 +465,7 @@ fn set_keys_keys_exist() {
network,
KeyPair(insecure_pair_from_name("name").public(), Vec::new().try_into().unwrap()),
vec![].try_into().unwrap(),
Signature([0u8; 64]),
Signature::from([0u8; 64]),
)
.unwrap();
@@ -473,7 +473,7 @@ fn set_keys_keys_exist() {
network,
key_pair: KeyPair(insecure_pair_from_name("name").public(), Vec::new().try_into().unwrap()),
signature_participants: vec![].try_into().unwrap(),
signature: Signature([0u8; 64]),
signature: Signature::from([0u8; 64]),
};
assert_eq!(

View File

@@ -26,15 +26,14 @@ borsh = { version = "1", default-features = false, features = ["derive", "de_str
serde = { version = "1", default-features = false, features = ["derive", "alloc"], optional = true }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-std = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-core = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
sp-std = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "da19e1f8ca7a9e2cbf39fbfa493918eeeb45e10b", default-features = false }
serai-primitives = { path = "../../primitives", default-features = false }
[features]
std = ["zeroize", "ciphersuite/std", "dkg-musig/std", "borsh?/std", "serde?/std", "scale/std", "scale-info/std", "sp-core/std", "sp-std/std", "serai-primitives/std"]
std = ["zeroize", "ciphersuite/std", "dkg-musig/std", "borsh?/std", "serde?/std", "scale/std", "sp-core/std", "sp-std/std", "serai-primitives/std"]
borsh = ["dep:borsh", "serai-primitives/borsh"]
serde = ["dep:serde", "serai-primitives/serde"]
default = ["std"]

View File

@@ -8,8 +8,7 @@ use zeroize::Zeroize;
use dalek_ff_group::Ristretto;
use ciphersuite::{group::GroupEncoding, GroupIo};
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
use scale::{Encode, Decode, DecodeWithMemTracking, MaxEncodedLen};
#[cfg(feature = "borsh")]
use borsh::{BorshSerialize, BorshDeserialize};
@@ -39,7 +38,17 @@ pub const MAX_KEY_SHARES_PER_SET_U32: u32 = MAX_KEY_SHARES_PER_SET as u32;
/// The type used to identify a specific session of validators.
#[derive(
Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Encode, Decode, TypeInfo, MaxEncodedLen,
Clone,
Copy,
PartialEq,
Eq,
Hash,
Default,
Debug,
Encode,
Decode,
DecodeWithMemTracking,
MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
@@ -48,7 +57,7 @@ pub struct Session(pub u32);
/// The type used to identify a specific validator set during a specific session.
#[derive(
Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Encode, Decode, TypeInfo, MaxEncodedLen,
Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
@@ -59,7 +68,9 @@ pub struct ValidatorSet {
}
/// The type used to identify a specific validator set during a specific session.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[derive(
Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -90,9 +101,8 @@ pub type ExternalKey = BoundedVec<u8, ConstU32<MAX_KEY_LEN>>;
/// The key pair for a validator set.
///
/// This is their Ristretto key, used for publishing data onto Serai, and their key on the external
/// network.
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
/// This is their Ristretto key, used for signing Batches, and their key on the external network.
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, DecodeWithMemTracking, MaxEncodedLen)]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct KeyPair(
@@ -141,7 +151,7 @@ pub fn musig_key(set: ValidatorSet, set_keys: &[Public]) -> Public {
<Ristretto as GroupIo>::read_G::<&[u8]>(&mut key.0.as_ref()).expect("invalid participant"),
);
}
Public(dkg_musig::musig_key_vartime::<Ristretto>(musig_context(set), &keys).unwrap().to_bytes())
dkg_musig::musig_key_vartime::<Ristretto>(musig_context(set), &keys).unwrap().to_bytes().into()
}
/// The message for the `set_keys` signature.

View File

@@ -1,10 +1,11 @@
#![expect(clippy::cast_possible_truncation)]
use core::{num::NonZero, time::Duration};
#[cfg(feature = "std")]
use zeroize::Zeroize;
use scale::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
use scale::{Encode, Decode, MaxEncodedLen, DecodeWithMemTracking};
#[cfg(feature = "borsh")]
use borsh::{BorshSerialize, BorshDeserialize};
@@ -26,7 +27,9 @@ fn downtime_per_slash_point(validators: NonZero<u16>) -> Duration {
}
/// A slash for a validator.
#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(
Clone, Copy, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, DecodeWithMemTracking,
)]
#[cfg_attr(feature = "std", derive(Zeroize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -206,7 +209,7 @@ impl Slash {
}
}
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode, MaxEncodedLen, DecodeWithMemTracking)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct SlashReport(pub BoundedVec<Slash, ConstU32<{ MAX_KEY_SHARES_PER_SET_U32 }>>);

Some files were not shown because too many files have changed in this diff Show More