mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Initial In Instructions pallet and Serai client lib (#233)
* Initial work on an In Inherents pallet * Add an event for when a batch is executed * Add a dummy provider for InInstructions * Add in-instructions to the node * Add the Serai runtime API to the processor * Move processor tests around * Build a subxt Client around Serai * Successfully get Batch events from Serai Renamed processor/substrate to processor/serai. * Much more robust InInstruction pallet * Implement the workaround from https://github.com/paritytech/subxt/issues/602 * Initial prototype of processor generated InInstructions * Correct PendingCoins data flow for InInstructions * Minor lint to in-instructions * Remove the global Serai connection for a partial re-impl * Correct ID handling of the processor test * Workaround the delay in the subscription * Make an unwrap an if let Some, remove old comments * Lint the processor toml * Rebase and update * Move substrate/in-instructions to substrate/in-instructions/pallet * Start an in-instructions primitives lib * Properly update processor to subxt 0.24 Also corrects failures from the rebase. * in-instructions cargo update * Implement IsFatalError * is_inherent -> true * Rename in-instructions crates and misc cleanup * Update documentation * cargo update * Misc update fixes * Replace height with block_number * Update processor src to latest subxt * Correct pipeline for InInstructions testing * Remove runtime::AccountId for serai_primitives::NativeAddress * Rewrite the in-instructions pallet Complete with respect to the currently written docs. Drops the custom serializer for just using SCALE. Makes slight tweaks as relevant. * Move instructions' InherentDataProvider to a client crate * Correct doc gen * Add serde to in-instructions-primitives * Add in-instructions-primitives to pallet * Heights -> BlockNumbers * Get batch pub test loop working * Update in instructions pallet terminology Removes the ambiguous Coin for Update. Removes pending/artificial latency for furture client work. Also moves to using serai_primitives::Coin. * Add a BlockNumber primitive * Belated cargo fmt * Further document why DifferentBatch isn't fatal * Correct processor sleeps * Remove metadata at compile time, add test framework for Serai nodes * Remove manual RPC client * Simplify update test * Improve re-exporting behavior of serai-runtime It now re-exports all pallets underneath it. * Add a function to get storage values to the Serai RPC * Update substrate/ to latest substrate * Create a dedicated crate for the Serai RPC * Remove unused dependencies in substrate/ * Remove unused dependencies in coins/ Out of scope for this branch, just minor and path of least resistance. * Use substrate/serai/client for the Serai RPC lib It's a bit out of place, since these client folders are intended for the node to access pallets and so on. This is for end-users to access Serai as a whole. In that sense, it made more sense as a top level folder, yet that also felt out of place. * Move InInstructions test to serai-client for now * Final cleanup * Update deny.toml * Cargo.lock update from merging develop * Update nightly Attempt to work around the current CI failure, which is a Rust ICE. We previously didn't upgrade due to clippy 10134, yet that's been reverted. * clippy * clippy * fmt * NativeAddress -> SeraiAddress * Sec fix on non-provided updates and doc fixes * Add Serai as a Coin Necessary in order to swap to Serai. * Add a BlockHash type, used for batch IDs * Remove origin from InInstruction Makes InInstructionTarget. Adds RefundableInInstruction with origin. * Document storage items in in-instructions * Rename serai/client/tests/serai.rs to updates.rs It only tested publishing updates and their successful acceptance.
This commit is contained in:
@@ -14,17 +14,11 @@ name = "serai-node"
|
||||
[dependencies]
|
||||
async-trait = "0.1"
|
||||
|
||||
log = "0.4"
|
||||
|
||||
futures = { version = "0.3" }
|
||||
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
|
||||
jsonrpsee = { version = "0.16", features = ["server"] }
|
||||
|
||||
sp-core = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-application-crypto = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-keystore = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-keyring = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-inherents = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-runtime = { git = "https://github.com/serai-dex/substrate" }
|
||||
@@ -33,7 +27,11 @@ sp-api = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-block-builder = { git = "https://github.com/serai-dex/substrate" }
|
||||
sp-consensus = { git = "https://github.com/serai-dex/substrate" }
|
||||
|
||||
sc-keystore = { git = "https://github.com/serai-dex/substrate" }
|
||||
frame-benchmarking = { git = "https://github.com/serai-dex/substrate" }
|
||||
frame-benchmarking-cli = { git = "https://github.com/serai-dex/substrate" }
|
||||
|
||||
serai-runtime = { path = "../runtime" }
|
||||
|
||||
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" }
|
||||
@@ -47,24 +45,13 @@ sc-consensus = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-telemetry = { git = "https://github.com/serai-dex/substrate" }
|
||||
sc-cli = { git = "https://github.com/serai-dex/substrate" }
|
||||
|
||||
frame-system = { git = "https://github.com/serai-dex/substrate" }
|
||||
frame-benchmarking = { git = "https://github.com/serai-dex/substrate" }
|
||||
frame-benchmarking-cli = { git = "https://github.com/serai-dex/substrate" }
|
||||
pallet-transaction-payment = { git = "https://github.com/serai-dex/substrate", default-features = false }
|
||||
|
||||
sc-rpc = { 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" }
|
||||
|
||||
serai-primitives = { path = "../serai/primitives" }
|
||||
in-instructions-client = { path = "../in-instructions/client" }
|
||||
|
||||
validator-sets-pallet = { path = "../validator-sets/pallet" }
|
||||
|
||||
sp-tendermint = { path = "../tendermint/primitives" }
|
||||
pallet-tendermint = { path = "../tendermint/pallet", default-features = false }
|
||||
serai-runtime = { path = "../runtime" }
|
||||
sc-tendermint = { path = "../tendermint/client" }
|
||||
|
||||
[build-dependencies]
|
||||
|
||||
@@ -3,12 +3,9 @@ use sp_runtime::traits::TrailingZeroInput;
|
||||
|
||||
use sc_service::ChainType;
|
||||
|
||||
use serai_primitives::*;
|
||||
use pallet_tendermint::crypto::Public;
|
||||
|
||||
use serai_runtime::{
|
||||
WASM_BINARY, AccountId, opaque::SessionKeys, GenesisConfig, SystemConfig, BalancesConfig,
|
||||
AssetsConfig, ValidatorSetsConfig, SessionConfig,
|
||||
primitives::*, tendermint::crypto::Public, WASM_BINARY, opaque::SessionKeys, GenesisConfig,
|
||||
SystemConfig, BalancesConfig, AssetsConfig, ValidatorSetsConfig, SessionConfig,
|
||||
};
|
||||
|
||||
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;
|
||||
@@ -17,22 +14,22 @@ fn insecure_pair_from_name(name: &'static str) -> Pair {
|
||||
Pair::from_string(&format!("//{name}"), None).unwrap()
|
||||
}
|
||||
|
||||
fn account_id_from_name(name: &'static str) -> AccountId {
|
||||
fn address_from_name(name: &'static str) -> SeraiAddress {
|
||||
insecure_pair_from_name(name).public()
|
||||
}
|
||||
|
||||
fn testnet_genesis(
|
||||
wasm_binary: &[u8],
|
||||
validators: &[&'static str],
|
||||
endowed_accounts: Vec<AccountId>,
|
||||
endowed_accounts: Vec<SeraiAddress>,
|
||||
) -> GenesisConfig {
|
||||
let session_key = |name| {
|
||||
let key = account_id_from_name(name);
|
||||
let key = address_from_name(name);
|
||||
(key, key, SessionKeys { tendermint: Public::from(key) })
|
||||
};
|
||||
|
||||
// TODO: Replace with a call to the pallet to ask for its account
|
||||
let owner = AccountId::decode(&mut TrailingZeroInput::new(b"tokens")).unwrap();
|
||||
let owner = SeraiAddress::decode(&mut TrailingZeroInput::new(b"tokens")).unwrap();
|
||||
|
||||
GenesisConfig {
|
||||
system: SystemConfig { code: wasm_binary.to_vec() },
|
||||
@@ -54,8 +51,8 @@ fn testnet_genesis(
|
||||
|
||||
validator_sets: ValidatorSetsConfig {
|
||||
bond: Amount(1_000_000) * COIN,
|
||||
coins: Coin(4),
|
||||
participants: validators.iter().map(|name| account_id_from_name(name)).collect(),
|
||||
coins: vec![BITCOIN, ETHER, DAI, MONERO],
|
||||
participants: validators.iter().map(|name| address_from_name(name)).collect(),
|
||||
},
|
||||
session: SessionConfig { keys: validators.iter().map(|name| session_key(*name)).collect() },
|
||||
}
|
||||
@@ -75,18 +72,18 @@ pub fn development_config() -> Result<ChainSpec, &'static str> {
|
||||
wasm_binary,
|
||||
&["Alice"],
|
||||
vec![
|
||||
account_id_from_name("Alice"),
|
||||
account_id_from_name("Bob"),
|
||||
account_id_from_name("Charlie"),
|
||||
account_id_from_name("Dave"),
|
||||
account_id_from_name("Eve"),
|
||||
account_id_from_name("Ferdie"),
|
||||
account_id_from_name("Alice//stash"),
|
||||
account_id_from_name("Bob//stash"),
|
||||
account_id_from_name("Charlie//stash"),
|
||||
account_id_from_name("Dave//stash"),
|
||||
account_id_from_name("Eve//stash"),
|
||||
account_id_from_name("Ferdie//stash"),
|
||||
address_from_name("Alice"),
|
||||
address_from_name("Bob"),
|
||||
address_from_name("Charlie"),
|
||||
address_from_name("Dave"),
|
||||
address_from_name("Eve"),
|
||||
address_from_name("Ferdie"),
|
||||
address_from_name("Alice//stash"),
|
||||
address_from_name("Bob//stash"),
|
||||
address_from_name("Charlie//stash"),
|
||||
address_from_name("Dave//stash"),
|
||||
address_from_name("Eve//stash"),
|
||||
address_from_name("Ferdie//stash"),
|
||||
],
|
||||
)
|
||||
},
|
||||
@@ -119,18 +116,18 @@ pub fn testnet_config() -> Result<ChainSpec, &'static str> {
|
||||
wasm_binary,
|
||||
&["Alice", "Bob", "Charlie"],
|
||||
vec![
|
||||
account_id_from_name("Alice"),
|
||||
account_id_from_name("Bob"),
|
||||
account_id_from_name("Charlie"),
|
||||
account_id_from_name("Dave"),
|
||||
account_id_from_name("Eve"),
|
||||
account_id_from_name("Ferdie"),
|
||||
account_id_from_name("Alice//stash"),
|
||||
account_id_from_name("Bob//stash"),
|
||||
account_id_from_name("Charlie//stash"),
|
||||
account_id_from_name("Dave//stash"),
|
||||
account_id_from_name("Eve//stash"),
|
||||
account_id_from_name("Ferdie//stash"),
|
||||
address_from_name("Alice"),
|
||||
address_from_name("Bob"),
|
||||
address_from_name("Charlie"),
|
||||
address_from_name("Dave"),
|
||||
address_from_name("Eve"),
|
||||
address_from_name("Ferdie"),
|
||||
address_from_name("Alice//stash"),
|
||||
address_from_name("Bob//stash"),
|
||||
address_from_name("Charlie//stash"),
|
||||
address_from_name("Dave//stash"),
|
||||
address_from_name("Eve//stash"),
|
||||
address_from_name("Ferdie//stash"),
|
||||
],
|
||||
)
|
||||
},
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use sc_service::{PruningMode, PartialComponents};
|
||||
use frame_benchmarking_cli::{ExtrinsicFactory, BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
|
||||
use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli};
|
||||
|
||||
use serai_runtime::Block;
|
||||
|
||||
use sc_service::{PruningMode, PartialComponents};
|
||||
|
||||
use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli};
|
||||
use frame_benchmarking_cli::{ExtrinsicFactory, BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
|
||||
|
||||
use crate::{
|
||||
chain_spec,
|
||||
cli::{Cli, Subcommand},
|
||||
|
||||
@@ -9,8 +9,11 @@ use sp_runtime::OpaqueExtrinsic;
|
||||
use sc_cli::Result;
|
||||
use sc_client_api::BlockBackend;
|
||||
|
||||
use serai_runtime as runtime;
|
||||
use runtime::SystemCall;
|
||||
use serai_runtime::{
|
||||
VERSION, BlockHashCount,
|
||||
system::{self, Call as SystemCall},
|
||||
transaction_payment, RuntimeCall, UncheckedExtrinsic, SignedPayload, Runtime,
|
||||
};
|
||||
|
||||
use crate::service::FullClient;
|
||||
|
||||
@@ -45,35 +48,33 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for RemarkBuilder {
|
||||
pub fn create_benchmark_extrinsic(
|
||||
client: &FullClient,
|
||||
sender: sp_core::sr25519::Pair,
|
||||
call: runtime::RuntimeCall,
|
||||
call: RuntimeCall,
|
||||
nonce: u32,
|
||||
) -> runtime::UncheckedExtrinsic {
|
||||
) -> UncheckedExtrinsic {
|
||||
let extra = (
|
||||
frame_system::CheckNonZeroSender::<runtime::Runtime>::new(),
|
||||
frame_system::CheckSpecVersion::<runtime::Runtime>::new(),
|
||||
frame_system::CheckTxVersion::<runtime::Runtime>::new(),
|
||||
frame_system::CheckGenesis::<runtime::Runtime>::new(),
|
||||
frame_system::CheckEra::<runtime::Runtime>::from(sp_runtime::generic::Era::mortal(
|
||||
u64::from(
|
||||
runtime::BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2),
|
||||
),
|
||||
system::CheckNonZeroSender::<Runtime>::new(),
|
||||
system::CheckSpecVersion::<Runtime>::new(),
|
||||
system::CheckTxVersion::<Runtime>::new(),
|
||||
system::CheckGenesis::<Runtime>::new(),
|
||||
system::CheckEra::<Runtime>::from(sp_runtime::generic::Era::mortal(
|
||||
u64::from(BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2)),
|
||||
client.chain_info().best_number.into(),
|
||||
)),
|
||||
frame_system::CheckNonce::<runtime::Runtime>::from(nonce),
|
||||
frame_system::CheckWeight::<runtime::Runtime>::new(),
|
||||
pallet_transaction_payment::ChargeTransactionPayment::<runtime::Runtime>::from(0),
|
||||
system::CheckNonce::<Runtime>::from(nonce),
|
||||
system::CheckWeight::<Runtime>::new(),
|
||||
transaction_payment::ChargeTransactionPayment::<Runtime>::from(0),
|
||||
);
|
||||
|
||||
runtime::UncheckedExtrinsic::new_signed(
|
||||
UncheckedExtrinsic::new_signed(
|
||||
call.clone(),
|
||||
sender.public(),
|
||||
runtime::SignedPayload::from_raw(
|
||||
SignedPayload::from_raw(
|
||||
call,
|
||||
extra.clone(),
|
||||
(
|
||||
(),
|
||||
runtime::VERSION.spec_version,
|
||||
runtime::VERSION.transaction_version,
|
||||
VERSION.spec_version,
|
||||
VERSION.transaction_version,
|
||||
client.block_hash(0).ok().flatten().unwrap(),
|
||||
client.chain_info().best_hash,
|
||||
(),
|
||||
|
||||
@@ -3,13 +3,13 @@ use std::sync::Arc;
|
||||
use jsonrpsee::RpcModule;
|
||||
|
||||
use sp_blockchain::{Error as BlockchainError, HeaderBackend, HeaderMetadata};
|
||||
use sc_transaction_pool_api::TransactionPool;
|
||||
use sp_block_builder::BlockBuilder;
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
|
||||
pub use sc_rpc_api::DenyUnsafe;
|
||||
use serai_runtime::{primitives::SeraiAddress, opaque::Block, Balance, Index};
|
||||
|
||||
use serai_runtime::{opaque::Block, AccountId, Balance, Index};
|
||||
pub use sc_rpc_api::DenyUnsafe;
|
||||
use sc_transaction_pool_api::TransactionPool;
|
||||
|
||||
pub struct FullDeps<C, P> {
|
||||
pub client: Arc<C>,
|
||||
@@ -29,7 +29,7 @@ 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, AccountId, Index>
|
||||
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, SeraiAddress, Index>
|
||||
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
|
||||
+ BlockBuilder<Block>,
|
||||
{
|
||||
|
||||
@@ -11,6 +11,8 @@ use sp_inherents::CreateInherentDataProviders;
|
||||
use sp_consensus::DisableProofRecording;
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
|
||||
use in_instructions_client::InherentDataProvider as InstructionsProvider;
|
||||
|
||||
use sc_executor::{NativeVersion, NativeExecutionDispatch, NativeElseWasmExecutor};
|
||||
use sc_transaction_pool::FullPool;
|
||||
use sc_network::NetworkService;
|
||||
@@ -24,7 +26,7 @@ pub(crate) use sc_tendermint::{
|
||||
TendermintClientMinimal, TendermintValidator, TendermintImport, TendermintAuthority,
|
||||
TendermintSelectChain, import_queue,
|
||||
};
|
||||
use serai_runtime::{self, BLOCK_SIZE, TARGET_BLOCK_TIME, opaque::Block, RuntimeApi};
|
||||
use serai_runtime::{self as runtime, BLOCK_SIZE, TARGET_BLOCK_TIME, opaque::Block, RuntimeApi};
|
||||
|
||||
type FullBackend = sc_service::TFullBackend<Block>;
|
||||
pub type FullClient = TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
|
||||
@@ -46,7 +48,7 @@ impl NativeExecutionDispatch for ExecutorDispatch {
|
||||
type ExtendHostFunctions = ();
|
||||
|
||||
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
|
||||
serai_runtime::api::dispatch(method, data)
|
||||
runtime::api::dispatch(method, data)
|
||||
}
|
||||
|
||||
fn native_version() -> NativeVersion {
|
||||
@@ -57,13 +59,13 @@ impl NativeExecutionDispatch for ExecutorDispatch {
|
||||
pub struct Cidp;
|
||||
#[async_trait::async_trait]
|
||||
impl CreateInherentDataProviders<Block, ()> for Cidp {
|
||||
type InherentDataProviders = ();
|
||||
type InherentDataProviders = (InstructionsProvider,);
|
||||
async fn create_inherent_data_providers(
|
||||
&self,
|
||||
_: <Block as BlockTrait>::Hash,
|
||||
_: (),
|
||||
) -> Result<Self::InherentDataProviders, Box<dyn Send + Sync + Error>> {
|
||||
Ok(())
|
||||
Ok((InstructionsProvider::new(),))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user