mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Restore workspace-wide clippy
Fixes accumulated errors in the Substrate code. Modifies the runtime build to work with a modern clippy. Removes e2e tests from the workspace.
This commit is contained in:
3332
Cargo.lock
generated
3332
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -144,9 +144,9 @@ members = [
|
|||||||
|
|
||||||
"tests/docker",
|
"tests/docker",
|
||||||
"tests/message-queue",
|
"tests/message-queue",
|
||||||
"tests/processor",
|
# TODO "tests/processor",
|
||||||
"tests/coordinator",
|
# TODO "tests/coordinator",
|
||||||
"tests/full-stack",
|
# TODO "tests/full-stack",
|
||||||
"tests/reproducible-runtime",
|
"tests/reproducible-runtime",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ impl<D: Db> ContinuallyRan for CanonicalEventStream<D> {
|
|||||||
batch = Some(ExecutedBatch {
|
batch = Some(ExecutedBatch {
|
||||||
id: *id,
|
id: *id,
|
||||||
publisher: *publishing_session,
|
publisher: *publishing_session,
|
||||||
external_network_block_hash: *external_network_block_hash,
|
external_network_block_hash: external_network_block_hash.0,
|
||||||
in_instructions_hash: *in_instructions_hash,
|
in_instructions_hash: *in_instructions_hash,
|
||||||
in_instruction_results: in_instruction_results
|
in_instruction_results: in_instruction_results
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ impl AggregateRangeWitness {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AggregateRangeStatement<'a> {
|
impl AggregateRangeStatement<'_> {
|
||||||
fn initial_transcript(&self) -> (Scalar, Vec<EdwardsPoint>) {
|
fn initial_transcript(&self) -> (Scalar, Vec<EdwardsPoint>) {
|
||||||
let V = self.commitments.iter().map(|c| c * INV_EIGHT()).collect::<Vec<_>>();
|
let V = self.commitments.iter().map(|c| c * INV_EIGHT()).collect::<Vec<_>>();
|
||||||
(keccak256_to_scalar(V.iter().flat_map(|V| V.compress().to_bytes()).collect::<Vec<_>>()), V)
|
(keccak256_to_scalar(V.iter().flat_map(|V| V.compress().to_bytes()).collect::<Vec<_>>()), V)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use crate::{
|
|||||||
// https://github.com/monero-project/monero/blob/ac02af92867590ca80b2779a7bbeafa99ff94dcb/
|
// https://github.com/monero-project/monero/blob/ac02af92867590ca80b2779a7bbeafa99ff94dcb/
|
||||||
// tests/unit_tests/test_tx_utils.cpp
|
// tests/unit_tests/test_tx_utils.cpp
|
||||||
// which is licensed
|
// which is licensed
|
||||||
|
#[allow(clippy::empty_line_after_outer_attr)] // rustfmt is for the comment, not for the const
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2014-2022, The Monero Project
|
Copyright (c) 2014-2022, The Monero Project
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use blake2::{digest::typenum::U32, Digest, Blake2b};
|
|||||||
use scale::Encode;
|
use scale::Encode;
|
||||||
use serai_db::{DbTxn, Db};
|
use serai_db::{DbTxn, Db};
|
||||||
|
|
||||||
|
use serai_primitives::BlockHash;
|
||||||
use serai_in_instructions_primitives::{MAX_BATCH_SIZE, Batch};
|
use serai_in_instructions_primitives::{MAX_BATCH_SIZE, Batch};
|
||||||
|
|
||||||
use primitives::{
|
use primitives::{
|
||||||
@@ -106,7 +107,7 @@ impl<D: Db, S: ScannerFeed> ContinuallyRan for BatchTask<D, S> {
|
|||||||
// If this block is notable, create the Batch(s) for it
|
// If this block is notable, create the Batch(s) for it
|
||||||
if notable {
|
if notable {
|
||||||
let network = S::NETWORK;
|
let network = S::NETWORK;
|
||||||
let external_network_block_hash = index::block_id(&txn, block_number);
|
let external_network_block_hash = BlockHash(index::block_id(&txn, block_number));
|
||||||
let mut batch_id = BatchDb::<S>::acquire_batch_id(&mut txn);
|
let mut batch_id = BatchDb::<S>::acquire_batch_id(&mut txn);
|
||||||
|
|
||||||
// start with empty batch
|
// start with empty batch
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pub enum Event {
|
|||||||
network: NetworkId,
|
network: NetworkId,
|
||||||
publishing_session: Session,
|
publishing_session: Session,
|
||||||
id: u32,
|
id: u32,
|
||||||
external_network_block_hash: [u8; 32],
|
external_network_block_hash: BlockHash,
|
||||||
in_instructions_hash: [u8; 32],
|
in_instructions_hash: [u8; 32],
|
||||||
in_instruction_results: bitvec::vec::BitVec<u8, bitvec::order::Lsb0>,
|
in_instruction_results: bitvec::vec::BitVec<u8, bitvec::order::Lsb0>,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -8,12 +8,13 @@ use blake2::{
|
|||||||
use scale::Encode;
|
use scale::Encode;
|
||||||
|
|
||||||
use serai_client::{
|
use serai_client::{
|
||||||
primitives::{Amount, NetworkId, Coin, Balance, BlockHash, SeraiAddress},
|
primitives::{BlockHash, NetworkId, Coin, Amount, Balance, SeraiAddress},
|
||||||
|
coins::CoinsEvent,
|
||||||
|
validator_sets::primitives::Session,
|
||||||
in_instructions::{
|
in_instructions::{
|
||||||
primitives::{InInstruction, InInstructionWithBalance, Batch},
|
primitives::{InInstruction, InInstructionWithBalance, Batch},
|
||||||
InInstructionsEvent,
|
InInstructionsEvent,
|
||||||
},
|
},
|
||||||
coins::CoinsEvent,
|
|
||||||
Serai,
|
Serai,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -32,9 +33,13 @@ serai_test!(
|
|||||||
let amount = Amount(OsRng.next_u64().saturating_add(1));
|
let amount = Amount(OsRng.next_u64().saturating_add(1));
|
||||||
let balance = Balance { coin, amount };
|
let balance = Balance { coin, amount };
|
||||||
|
|
||||||
|
let mut external_network_block_hash = BlockHash([0; 32]);
|
||||||
|
OsRng.fill_bytes(&mut external_network_block_hash.0);
|
||||||
|
|
||||||
let batch = Batch {
|
let batch = Batch {
|
||||||
network,
|
network,
|
||||||
id,
|
id,
|
||||||
|
external_network_block_hash,
|
||||||
instructions: vec![InInstructionWithBalance {
|
instructions: vec![InInstructionWithBalance {
|
||||||
instruction: InInstruction::Transfer(address),
|
instruction: InInstruction::Transfer(address),
|
||||||
balance,
|
balance,
|
||||||
@@ -51,8 +56,11 @@ serai_test!(
|
|||||||
batches,
|
batches,
|
||||||
vec![InInstructionsEvent::Batch {
|
vec![InInstructionsEvent::Batch {
|
||||||
network,
|
network,
|
||||||
|
publishing_session: Session(0),
|
||||||
id,
|
id,
|
||||||
instructions_hash: Blake2b::<U32>::digest(batch.instructions.encode()).into(),
|
external_network_block_hash,
|
||||||
|
in_instructions_hash: Blake2b::<U32>::digest(batch.instructions.encode()).into(),
|
||||||
|
in_instruction_results: bitvec::bitvec![u8, bitvec::order::Lsb0; 1; 1],
|
||||||
}]
|
}]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,19 +7,22 @@ use blake2::{
|
|||||||
|
|
||||||
use scale::Encode;
|
use scale::Encode;
|
||||||
|
|
||||||
use serai_abi::coins::primitives::OutInstructionWithBalance;
|
|
||||||
use sp_core::Pair;
|
use sp_core::Pair;
|
||||||
|
|
||||||
use serai_client::{
|
use serai_client::{
|
||||||
primitives::{
|
primitives::{
|
||||||
Amount, NetworkId, Coin, Balance, BlockHash, SeraiAddress, ExternalAddress,
|
BlockHash, NetworkId, Coin, Amount, Balance, SeraiAddress, ExternalAddress,
|
||||||
insecure_pair_from_name,
|
insecure_pair_from_name,
|
||||||
},
|
},
|
||||||
|
coins::{
|
||||||
|
primitives::{OutInstruction, OutInstructionWithBalance},
|
||||||
|
CoinsEvent,
|
||||||
|
},
|
||||||
|
validator_sets::primitives::Session,
|
||||||
in_instructions::{
|
in_instructions::{
|
||||||
InInstructionsEvent,
|
InInstructionsEvent,
|
||||||
primitives::{InInstruction, InInstructionWithBalance, Batch},
|
primitives::{InInstruction, InInstructionWithBalance, Batch},
|
||||||
},
|
},
|
||||||
coins::{primitives::OutInstruction, CoinsEvent},
|
|
||||||
Serai, SeraiCoins,
|
Serai, SeraiCoins,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -45,7 +48,7 @@ serai_test!(
|
|||||||
let batch = Batch {
|
let batch = Batch {
|
||||||
network,
|
network,
|
||||||
id,
|
id,
|
||||||
block: block_hash,
|
external_network_block_hash: block_hash,
|
||||||
instructions: vec![InInstructionWithBalance {
|
instructions: vec![InInstructionWithBalance {
|
||||||
instruction: InInstruction::Transfer(address),
|
instruction: InInstruction::Transfer(address),
|
||||||
balance,
|
balance,
|
||||||
@@ -61,9 +64,11 @@ serai_test!(
|
|||||||
batches,
|
batches,
|
||||||
vec![InInstructionsEvent::Batch {
|
vec![InInstructionsEvent::Batch {
|
||||||
network,
|
network,
|
||||||
|
publishing_session: Session(0),
|
||||||
id,
|
id,
|
||||||
block: block_hash,
|
external_network_block_hash: block_hash,
|
||||||
instructions_hash: Blake2b::<U32>::digest(batch.instructions.encode()).into(),
|
in_instructions_hash: Blake2b::<U32>::digest(batch.instructions.encode()).into(),
|
||||||
|
in_instruction_results: bitvec::bitvec![u8, bitvec::order::Lsb0; 1; 1],
|
||||||
}]
|
}]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ use schnorrkel::Schnorrkel;
|
|||||||
use sp_core::{sr25519::Signature, Pair as PairTrait};
|
use sp_core::{sr25519::Signature, Pair as PairTrait};
|
||||||
|
|
||||||
use serai_abi::{
|
use serai_abi::{
|
||||||
genesis_liquidity::primitives::{oraclize_values_message, Values},
|
|
||||||
validator_sets::primitives::{musig_context, Session, ValidatorSet},
|
|
||||||
in_instructions::primitives::{InInstruction, InInstructionWithBalance, Batch},
|
|
||||||
primitives::{
|
primitives::{
|
||||||
Amount, NetworkId, Coin, Balance, BlockHash, SeraiAddress, insecure_pair_from_name,
|
BlockHash, NetworkId, Coin, Amount, Balance, SeraiAddress, insecure_pair_from_name,
|
||||||
},
|
},
|
||||||
|
validator_sets::primitives::{musig_context, Session, ValidatorSet},
|
||||||
|
genesis_liquidity::primitives::{oraclize_values_message, Values},
|
||||||
|
in_instructions::primitives::{InInstruction, InInstructionWithBalance, Batch},
|
||||||
};
|
};
|
||||||
|
|
||||||
use serai_client::{Serai, SeraiGenesisLiquidity};
|
use serai_client::{Serai, SeraiGenesisLiquidity};
|
||||||
@@ -53,7 +53,7 @@ pub async fn set_up_genesis(
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
// set up bloch hash
|
// set up block hash
|
||||||
let mut block = BlockHash([0; 32]);
|
let mut block = BlockHash([0; 32]);
|
||||||
OsRng.fill_bytes(&mut block.0);
|
OsRng.fill_bytes(&mut block.0);
|
||||||
|
|
||||||
@@ -65,7 +65,12 @@ pub async fn set_up_genesis(
|
|||||||
})
|
})
|
||||||
.or_insert(0);
|
.or_insert(0);
|
||||||
|
|
||||||
let batch = Batch { network: coin.network(), id: batch_ids[&coin.network()], instructions };
|
let batch = Batch {
|
||||||
|
network: coin.network(),
|
||||||
|
external_network_block_hash: block,
|
||||||
|
id: batch_ids[&coin.network()],
|
||||||
|
instructions,
|
||||||
|
};
|
||||||
provide_batch(serai, batch).await;
|
provide_batch(serai, batch).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use scale::Encode;
|
|||||||
use sp_core::Pair;
|
use sp_core::Pair;
|
||||||
|
|
||||||
use serai_client::{
|
use serai_client::{
|
||||||
primitives::{insecure_pair_from_name, BlockHash, NetworkId, Balance, SeraiAddress},
|
primitives::{BlockHash, NetworkId, Balance, SeraiAddress, insecure_pair_from_name},
|
||||||
validator_sets::primitives::{ValidatorSet, KeyPair},
|
validator_sets::primitives::{ValidatorSet, KeyPair},
|
||||||
in_instructions::{
|
in_instructions::{
|
||||||
primitives::{Batch, SignedBatch, batch_message, InInstruction, InInstructionWithBalance},
|
primitives::{Batch, SignedBatch, batch_message, InInstruction, InInstructionWithBalance},
|
||||||
@@ -45,16 +45,29 @@ pub async fn provide_batch(serai: &Serai, batch: Batch) -> [u8; 32] {
|
|||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let batches = serai.as_of(block).in_instructions().batch_events().await.unwrap();
|
{
|
||||||
// TODO: impl From<Batch> for BatchEvent?
|
let mut batches = serai.as_of(block).in_instructions().batch_events().await.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(batches.len(), 1);
|
||||||
batches,
|
let InInstructionsEvent::Batch {
|
||||||
vec![InInstructionsEvent::Batch {
|
network,
|
||||||
network: batch.network,
|
publishing_session,
|
||||||
id: batch.id,
|
id,
|
||||||
instructions_hash: Blake2b::<U32>::digest(batch.instructions.encode()).into(),
|
external_network_block_hash,
|
||||||
}],
|
in_instructions_hash,
|
||||||
);
|
in_instruction_results: _,
|
||||||
|
} = batches.swap_remove(0)
|
||||||
|
else {
|
||||||
|
panic!("Batch event wasn't Batch event")
|
||||||
|
};
|
||||||
|
assert_eq!(network, batch.network);
|
||||||
|
assert_eq!(publishing_session, session);
|
||||||
|
assert_eq!(id, batch.id);
|
||||||
|
assert_eq!(external_network_block_hash, batch.external_network_block_hash);
|
||||||
|
assert_eq!(
|
||||||
|
in_instructions_hash,
|
||||||
|
<[u8; 32]>::from(Blake2b::<U32>::digest(batch.instructions.encode()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Check the tokens events
|
// TODO: Check the tokens events
|
||||||
|
|
||||||
@@ -75,7 +88,7 @@ pub async fn mint_coin(
|
|||||||
let batch = Batch {
|
let batch = Batch {
|
||||||
network,
|
network,
|
||||||
id: batch_id,
|
id: batch_id,
|
||||||
block: block_hash,
|
external_network_block_hash: block_hash,
|
||||||
instructions: vec![InInstructionWithBalance {
|
instructions: vec![InInstructionWithBalance {
|
||||||
instruction: InInstruction::Transfer(address),
|
instruction: InInstruction::Transfer(address),
|
||||||
balance,
|
balance,
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ use serai_abi::in_instructions::primitives::DexCall;
|
|||||||
|
|
||||||
use serai_client::{
|
use serai_client::{
|
||||||
primitives::{
|
primitives::{
|
||||||
Amount, NetworkId, Coin, Balance, BlockHash, insecure_pair_from_name, ExternalAddress,
|
BlockHash, NetworkId, Coin, Amount, Balance, SeraiAddress, ExternalAddress,
|
||||||
SeraiAddress,
|
insecure_pair_from_name,
|
||||||
},
|
},
|
||||||
in_instructions::primitives::{
|
in_instructions::primitives::{
|
||||||
InInstruction, InInstructionWithBalance, Batch, IN_INSTRUCTION_EXECUTOR, OutAddress,
|
InInstruction, InInstructionWithBalance, Batch, IN_INSTRUCTION_EXECUTOR, OutAddress,
|
||||||
@@ -229,7 +229,7 @@ serai_test!(
|
|||||||
let batch = Batch {
|
let batch = Batch {
|
||||||
network: NetworkId::Bitcoin,
|
network: NetworkId::Bitcoin,
|
||||||
id: batch_id,
|
id: batch_id,
|
||||||
block: block_hash,
|
external_network_block_hash: block_hash,
|
||||||
instructions: vec![InInstructionWithBalance {
|
instructions: vec![InInstructionWithBalance {
|
||||||
instruction: InInstruction::Dex(DexCall::SwapAndAddLiquidity(pair.public().into())),
|
instruction: InInstruction::Dex(DexCall::SwapAndAddLiquidity(pair.public().into())),
|
||||||
balance: Balance { coin: Coin::Bitcoin, amount: Amount(20_000_000_000_000) },
|
balance: Balance { coin: Coin::Bitcoin, amount: Amount(20_000_000_000_000) },
|
||||||
@@ -313,7 +313,7 @@ serai_test!(
|
|||||||
let batch = Batch {
|
let batch = Batch {
|
||||||
network: NetworkId::Monero,
|
network: NetworkId::Monero,
|
||||||
id: coin1_batch_id,
|
id: coin1_batch_id,
|
||||||
block: block_hash,
|
external_network_block_hash: block_hash,
|
||||||
instructions: vec![InInstructionWithBalance {
|
instructions: vec![InInstructionWithBalance {
|
||||||
instruction: InInstruction::Dex(DexCall::Swap(out_balance, out_address)),
|
instruction: InInstruction::Dex(DexCall::Swap(out_balance, out_address)),
|
||||||
balance: Balance { coin: coin1, amount: Amount(200_000_000_000_000) },
|
balance: Balance { coin: coin1, amount: Amount(200_000_000_000_000) },
|
||||||
@@ -353,7 +353,7 @@ serai_test!(
|
|||||||
let batch = Batch {
|
let batch = Batch {
|
||||||
network: NetworkId::Ethereum,
|
network: NetworkId::Ethereum,
|
||||||
id: coin2_batch_id,
|
id: coin2_batch_id,
|
||||||
block: block_hash,
|
external_network_block_hash: block_hash,
|
||||||
instructions: vec![InInstructionWithBalance {
|
instructions: vec![InInstructionWithBalance {
|
||||||
instruction: InInstruction::Dex(DexCall::Swap(out_balance, out_address.clone())),
|
instruction: InInstruction::Dex(DexCall::Swap(out_balance, out_address.clone())),
|
||||||
balance: Balance { coin: coin2, amount: Amount(200_000_000_000) },
|
balance: Balance { coin: coin2, amount: Amount(200_000_000_000) },
|
||||||
@@ -391,7 +391,7 @@ serai_test!(
|
|||||||
let batch = Batch {
|
let batch = Batch {
|
||||||
network: NetworkId::Monero,
|
network: NetworkId::Monero,
|
||||||
id: coin1_batch_id,
|
id: coin1_batch_id,
|
||||||
block: block_hash,
|
external_network_block_hash: block_hash,
|
||||||
instructions: vec![InInstructionWithBalance {
|
instructions: vec![InInstructionWithBalance {
|
||||||
instruction: InInstruction::Dex(DexCall::Swap(out_balance, out_address.clone())),
|
instruction: InInstruction::Dex(DexCall::Swap(out_balance, out_address.clone())),
|
||||||
balance: Balance { coin: coin1, amount: Amount(100_000_000_000_000) },
|
balance: Balance { coin: coin1, amount: Amount(100_000_000_000_000) },
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ use rand_core::{RngCore, OsRng};
|
|||||||
use serai_client::TemporalSerai;
|
use serai_client::TemporalSerai;
|
||||||
|
|
||||||
use serai_abi::{
|
use serai_abi::{
|
||||||
emissions::primitives::{INITIAL_REWARD_PER_BLOCK, SECURE_BY},
|
|
||||||
in_instructions::primitives::Batch,
|
|
||||||
primitives::{
|
primitives::{
|
||||||
BlockHash, Coin, COINS, FAST_EPOCH_DURATION, FAST_EPOCH_INITIAL_PERIOD, NETWORKS,
|
NETWORKS, COINS, TARGET_BLOCK_TIME, FAST_EPOCH_DURATION, FAST_EPOCH_INITIAL_PERIOD, BlockHash,
|
||||||
TARGET_BLOCK_TIME,
|
Coin,
|
||||||
},
|
},
|
||||||
validator_sets::primitives::Session,
|
validator_sets::primitives::Session,
|
||||||
|
emissions::primitives::{INITIAL_REWARD_PER_BLOCK, SECURE_BY},
|
||||||
|
in_instructions::primitives::Batch,
|
||||||
};
|
};
|
||||||
|
|
||||||
use serai_client::{
|
use serai_client::{
|
||||||
@@ -42,7 +42,16 @@ async fn send_batches(serai: &Serai, ids: &mut HashMap<NetworkId, u32>) {
|
|||||||
let mut block = BlockHash([0; 32]);
|
let mut block = BlockHash([0; 32]);
|
||||||
OsRng.fill_bytes(&mut block.0);
|
OsRng.fill_bytes(&mut block.0);
|
||||||
|
|
||||||
provide_batch(serai, Batch { network, id: ids[&network], block, instructions: vec![] }).await;
|
provide_batch(
|
||||||
|
serai,
|
||||||
|
Batch {
|
||||||
|
network,
|
||||||
|
id: ids[&network],
|
||||||
|
external_network_block_hash: block,
|
||||||
|
instructions: vec![],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use sp_core::{
|
|||||||
|
|
||||||
use serai_client::{
|
use serai_client::{
|
||||||
primitives::{
|
primitives::{
|
||||||
FAST_EPOCH_DURATION, TARGET_BLOCK_TIME, NETWORKS, EmbeddedEllipticCurve, NetworkId, BlockHash,
|
FAST_EPOCH_DURATION, TARGET_BLOCK_TIME, NETWORKS, BlockHash, NetworkId, EmbeddedEllipticCurve,
|
||||||
insecure_pair_from_name,
|
insecure_pair_from_name,
|
||||||
},
|
},
|
||||||
validator_sets::{
|
validator_sets::{
|
||||||
@@ -311,7 +311,8 @@ async fn validator_set_rotation() {
|
|||||||
// provide a batch to complete the handover and retire the previous set
|
// provide a batch to complete the handover and retire the previous set
|
||||||
let mut block_hash = BlockHash([0; 32]);
|
let mut block_hash = BlockHash([0; 32]);
|
||||||
OsRng.fill_bytes(&mut block_hash.0);
|
OsRng.fill_bytes(&mut block_hash.0);
|
||||||
let batch = Batch { network, id: 0, block: block_hash, instructions: vec![] };
|
let batch =
|
||||||
|
Batch { network, id: 0, external_network_block_hash: block_hash, instructions: vec![] };
|
||||||
publish_tx(
|
publish_tx(
|
||||||
&serai,
|
&serai,
|
||||||
&SeraiInInstructions::execute_batch(SignedBatch {
|
&SeraiInInstructions::execute_batch(SignedBatch {
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ ignored = ["scale", "scale-info"]
|
|||||||
workspace = true
|
workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
bitvec = { version = "1", default-features = false, features = ["alloc"] }
|
||||||
|
|
||||||
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
|
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
|
||||||
scale-info = { version = "2", default-features = false, features = ["derive"] }
|
scale-info = { version = "2", default-features = false, features = ["derive"] }
|
||||||
|
|
||||||
|
|||||||
@@ -63,10 +63,10 @@ pub mod pallet {
|
|||||||
Batch {
|
Batch {
|
||||||
network: NetworkId,
|
network: NetworkId,
|
||||||
publishing_session: Session,
|
publishing_session: Session,
|
||||||
external_network_block_hash: [u8; 32],
|
|
||||||
id: u32,
|
id: u32,
|
||||||
|
external_network_block_hash: BlockHash,
|
||||||
in_instructions_hash: [u8; 32],
|
in_instructions_hash: [u8; 32],
|
||||||
in_instruction_results: BitVec<u8, Lsb0>,
|
in_instruction_results: bitvec::vec::BitVec<u8, bitvec::order::Lsb0>,
|
||||||
},
|
},
|
||||||
Halt {
|
Halt {
|
||||||
network: NetworkId,
|
network: NetworkId,
|
||||||
@@ -101,9 +101,10 @@ pub mod pallet {
|
|||||||
// Use a dedicated transaction layer when executing this InInstruction
|
// Use a dedicated transaction layer when executing this InInstruction
|
||||||
// This lets it individually error without causing any storage modifications
|
// This lets it individually error without causing any storage modifications
|
||||||
#[frame_support::transactional]
|
#[frame_support::transactional]
|
||||||
fn execute(instruction: InInstructionWithBalance) -> Result<(), DispatchError> {
|
fn execute(instruction: &InInstructionWithBalance) -> Result<(), DispatchError> {
|
||||||
match instruction.instruction {
|
match &instruction.instruction {
|
||||||
InInstruction::Transfer(address) => {
|
InInstruction::Transfer(address) => {
|
||||||
|
let address = *address;
|
||||||
Coins::<T>::mint(address.into(), instruction.balance)?;
|
Coins::<T>::mint(address.into(), instruction.balance)?;
|
||||||
}
|
}
|
||||||
InInstruction::Dex(call) => {
|
InInstruction::Dex(call) => {
|
||||||
@@ -113,6 +114,7 @@ pub mod pallet {
|
|||||||
match call {
|
match call {
|
||||||
DexCall::SwapAndAddLiquidity(address) => {
|
DexCall::SwapAndAddLiquidity(address) => {
|
||||||
let origin = RawOrigin::Signed(IN_INSTRUCTION_EXECUTOR.into());
|
let origin = RawOrigin::Signed(IN_INSTRUCTION_EXECUTOR.into());
|
||||||
|
let address = *address;
|
||||||
let coin = instruction.balance.coin;
|
let coin = instruction.balance.coin;
|
||||||
|
|
||||||
// mint the given coin on the account
|
// mint the given coin on the account
|
||||||
@@ -207,7 +209,9 @@ pub mod pallet {
|
|||||||
let coin_balance =
|
let coin_balance =
|
||||||
Coins::<T>::balance(IN_INSTRUCTION_EXECUTOR.into(), out_balance.coin);
|
Coins::<T>::balance(IN_INSTRUCTION_EXECUTOR.into(), out_balance.coin);
|
||||||
let instruction = OutInstructionWithBalance {
|
let instruction = OutInstructionWithBalance {
|
||||||
instruction: OutInstruction { address: out_address.as_external().unwrap() },
|
instruction: OutInstruction {
|
||||||
|
address: out_address.clone().as_external().unwrap(),
|
||||||
|
},
|
||||||
balance: Balance { coin: out_balance.coin, amount: coin_balance },
|
balance: Balance { coin: out_balance.coin, amount: coin_balance },
|
||||||
};
|
};
|
||||||
Coins::<T>::burn_with_instruction(origin.into(), instruction)?;
|
Coins::<T>::burn_with_instruction(origin.into(), instruction)?;
|
||||||
@@ -216,12 +220,14 @@ pub mod pallet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
InInstruction::GenesisLiquidity(address) => {
|
InInstruction::GenesisLiquidity(address) => {
|
||||||
|
let address = *address;
|
||||||
Coins::<T>::mint(GENESIS_LIQUIDITY_ACCOUNT.into(), instruction.balance)?;
|
Coins::<T>::mint(GENESIS_LIQUIDITY_ACCOUNT.into(), instruction.balance)?;
|
||||||
GenesisLiq::<T>::add_coin_liquidity(address.into(), instruction.balance)?;
|
GenesisLiq::<T>::add_coin_liquidity(address.into(), instruction.balance)?;
|
||||||
}
|
}
|
||||||
InInstruction::SwapToStakedSRI(address, network) => {
|
InInstruction::SwapToStakedSRI(address, network) => {
|
||||||
|
let address = *address;
|
||||||
Coins::<T>::mint(POL_ACCOUNT.into(), instruction.balance)?;
|
Coins::<T>::mint(POL_ACCOUNT.into(), instruction.balance)?;
|
||||||
Emissions::<T>::swap_to_staked_sri(address.into(), network, instruction.balance)?;
|
Emissions::<T>::swap_to_staked_sri(address.into(), *network, instruction.balance)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -259,7 +265,7 @@ pub mod pallet {
|
|||||||
impl<T: Config> Pallet<T> {
|
impl<T: Config> Pallet<T> {
|
||||||
#[pallet::call_index(0)]
|
#[pallet::call_index(0)]
|
||||||
#[pallet::weight((0, DispatchClass::Operational))] // TODO
|
#[pallet::weight((0, DispatchClass::Operational))] // TODO
|
||||||
pub fn execute_batch(origin: OriginFor<T>, batch: SignedBatch) -> DispatchResult {
|
pub fn execute_batch(origin: OriginFor<T>, _batch: SignedBatch) -> DispatchResult {
|
||||||
ensure_none(origin)?;
|
ensure_none(origin)?;
|
||||||
|
|
||||||
// The entire Batch execution is handled in pre_dispatch
|
// The entire Batch execution is handled in pre_dispatch
|
||||||
@@ -309,7 +315,7 @@ pub mod pallet {
|
|||||||
Err(InvalidTransaction::BadProof)?;
|
Err(InvalidTransaction::BadProof)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let batch = batch.batch;
|
let batch = &batch.batch;
|
||||||
|
|
||||||
if Halted::<T>::contains_key(network) {
|
if Halted::<T>::contains_key(network) {
|
||||||
Err(InvalidTransaction::Custom(1))?;
|
Err(InvalidTransaction::Custom(1))?;
|
||||||
@@ -343,8 +349,8 @@ pub mod pallet {
|
|||||||
LastBatch::<T>::insert(batch.network, batch.id);
|
LastBatch::<T>::insert(batch.network, batch.id);
|
||||||
|
|
||||||
let in_instructions_hash = blake2_256(&batch.instructions.encode());
|
let in_instructions_hash = blake2_256(&batch.instructions.encode());
|
||||||
let mut in_instruction_results = BitVec::new();
|
let mut in_instruction_results = bitvec::vec::BitVec::new();
|
||||||
for (i, instruction) in batch.instructions.into_iter().enumerate() {
|
for instruction in &batch.instructions {
|
||||||
// Verify this coin is for this network
|
// Verify this coin is for this network
|
||||||
if instruction.balance.coin.network() != batch.network {
|
if instruction.balance.coin.network() != batch.network {
|
||||||
Err(InvalidTransaction::Custom(2))?;
|
Err(InvalidTransaction::Custom(2))?;
|
||||||
@@ -363,7 +369,7 @@ pub mod pallet {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ValidTransaction::with_tag_prefix("in-instructions")
|
ValidTransaction::with_tag_prefix("in-instructions")
|
||||||
.and_provides((batch.batch.network, batch.batch.id))
|
.and_provides((batch.network, batch.id))
|
||||||
// Set a 10 block longevity, though this should be included in the next block
|
// Set a 10 block longevity, though this should be included in the next block
|
||||||
.longevity(10)
|
.longevity(10)
|
||||||
.propagate(true)
|
.propagate(true)
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ use sp_application_crypto::sr25519::Signature;
|
|||||||
use sp_std::vec::Vec;
|
use sp_std::vec::Vec;
|
||||||
use sp_runtime::RuntimeDebug;
|
use sp_runtime::RuntimeDebug;
|
||||||
|
|
||||||
use serai_primitives::{Balance, NetworkId, SeraiAddress, ExternalAddress, system_address};
|
#[rustfmt::skip]
|
||||||
|
use serai_primitives::{BlockHash, NetworkId, Balance, SeraiAddress, ExternalAddress, system_address};
|
||||||
|
|
||||||
mod shorthand;
|
mod shorthand;
|
||||||
pub use shorthand::*;
|
pub use shorthand::*;
|
||||||
@@ -106,7 +107,7 @@ pub struct InInstructionWithBalance {
|
|||||||
pub struct Batch {
|
pub struct Batch {
|
||||||
pub network: NetworkId,
|
pub network: NetworkId,
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub external_network_block_hash: [u8; 32],
|
pub external_network_block_hash: BlockHash,
|
||||||
pub instructions: Vec<InInstructionWithBalance>,
|
pub instructions: Vec<InInstructionWithBalance>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,71 +20,71 @@ workspace = true
|
|||||||
name = "serai-node"
|
name = "serai-node"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
#rand_core = "0.6"
|
rand_core = "0.6"
|
||||||
#zeroize = "1"
|
zeroize = "1"
|
||||||
#hex = "0.4"
|
hex = "0.4"
|
||||||
#log = "0.4"
|
log = "0.4"
|
||||||
|
|
||||||
#schnorrkel = "0.11"
|
schnorrkel = "0.11"
|
||||||
|
|
||||||
#ciphersuite = { path = "../../crypto/ciphersuite" }
|
ciphersuite = { path = "../../crypto/ciphersuite" }
|
||||||
#embedwards25519 = { path = "../../crypto/evrf/embedwards25519" }
|
embedwards25519 = { path = "../../crypto/evrf/embedwards25519" }
|
||||||
#secq256k1 = { path = "../../crypto/evrf/secq256k1" }
|
secq256k1 = { path = "../../crypto/evrf/secq256k1" }
|
||||||
|
|
||||||
#libp2p = "0.52"
|
libp2p = "0.52"
|
||||||
|
|
||||||
#sp-core = { git = "https://github.com/serai-dex/substrate" }
|
sp-core = { git = "https://github.com/serai-dex/substrate" }
|
||||||
#sp-keystore = { 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-timestamp = { git = "https://github.com/serai-dex/substrate" }
|
||||||
#sp-io = { 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-blockchain = { git = "https://github.com/serai-dex/substrate" }
|
||||||
#sp-api = { 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-block-builder = { git = "https://github.com/serai-dex/substrate" }
|
||||||
#sp-consensus-babe = { git = "https://github.com/serai-dex/substrate" }
|
sp-consensus-babe = { git = "https://github.com/serai-dex/substrate" }
|
||||||
|
|
||||||
#frame-benchmarking = { git = "https://github.com/serai-dex/substrate" }
|
frame-benchmarking = { git = "https://github.com/serai-dex/substrate" }
|
||||||
|
|
||||||
#serai-runtime = { path = "../runtime", features = ["std"] }
|
serai-runtime = { path = "../runtime", features = ["std"] }
|
||||||
|
|
||||||
#clap = { version = "4", features = ["derive"] }
|
clap = { version = "4", features = ["derive"] }
|
||||||
|
|
||||||
#futures-util = "0.3"
|
futures-util = "0.3"
|
||||||
#tokio = { version = "1", features = ["sync", "rt-multi-thread"] }
|
tokio = { version = "1", features = ["sync", "rt-multi-thread"] }
|
||||||
#jsonrpsee = { version = "0.16", features = ["server"] }
|
jsonrpsee = { version = "0.16", features = ["server"] }
|
||||||
|
|
||||||
#sc-offchain = { git = "https://github.com/serai-dex/substrate" }
|
sc-offchain = { git = "https://github.com/serai-dex/substrate" }
|
||||||
#sc-transaction-pool = { 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-transaction-pool-api = { git = "https://github.com/serai-dex/substrate" }
|
||||||
#sc-basic-authorship = { 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-executor = { git = "https://github.com/serai-dex/substrate" }
|
||||||
#sc-service = { 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-client-api = { git = "https://github.com/serai-dex/substrate" }
|
||||||
#sc-network-common = { 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-network = { git = "https://github.com/serai-dex/substrate" }
|
||||||
|
|
||||||
#sc-consensus = { git = "https://github.com/serai-dex/substrate" }
|
sc-consensus = { git = "https://github.com/serai-dex/substrate" }
|
||||||
#sc-consensus-babe = { 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-consensus-grandpa = { git = "https://github.com/serai-dex/substrate" }
|
||||||
#sc-authority-discovery = { 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/substrate" }
|
sc-telemetry = { git = "https://github.com/serai-dex/substrate" }
|
||||||
#sc-cli = { 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" }
|
sc-rpc-api = { git = "https://github.com/serai-dex/substrate" }
|
||||||
|
|
||||||
#substrate-frame-rpc-system = { 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" }
|
pallet-transaction-payment-rpc = { git = "https://github.com/serai-dex/substrate" }
|
||||||
|
|
||||||
#serai-env = { path = "../../common/env" }
|
serai-env = { path = "../../common/env" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
#substrate-build-script-utils = { git = "https://github.com/serai-dex/substrate" }
|
substrate-build-script-utils = { git = "https://github.com/serai-dex/substrate" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
#default = []
|
default = []
|
||||||
#fast-epoch = ["serai-runtime/fast-epoch"]
|
fast-epoch = ["serai-runtime/fast-epoch"]
|
||||||
#runtime-benchmarks = [
|
runtime-benchmarks = [
|
||||||
# "frame-benchmarking/runtime-benchmarks",
|
"frame-benchmarking/runtime-benchmarks",
|
||||||
|
|
||||||
# "serai-runtime/runtime-benchmarks",
|
"serai-runtime/runtime-benchmarks",
|
||||||
#]
|
]
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
use substrate_wasm_builder::WasmBuilder;
|
use substrate_wasm_builder::WasmBuilder;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
WasmBuilder::new().with_current_project().export_heap_base().import_memory().build()
|
WasmBuilder::new()
|
||||||
|
.with_current_project()
|
||||||
|
// https://substrate.stackexchange.com/questions/12124
|
||||||
|
// TODO: Remove once we've moved to polkadot-sdk
|
||||||
|
.disable_runtime_version_section_check()
|
||||||
|
.export_heap_base()
|
||||||
|
.import_memory()
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ use scale::{Encode, Decode};
|
|||||||
use serai_abi::Call;
|
use serai_abi::Call;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Vec,
|
|
||||||
primitives::{PublicKey, SeraiAddress},
|
|
||||||
timestamp, coins, dex, genesis_liquidity,
|
timestamp, coins, dex, genesis_liquidity,
|
||||||
validator_sets::{self, MembershipProof},
|
validator_sets::{self, MembershipProof},
|
||||||
in_instructions, signals, babe, grandpa, RuntimeCall,
|
in_instructions, signals, babe, grandpa, RuntimeCall,
|
||||||
|
|||||||
@@ -1203,7 +1203,7 @@ pub mod pallet {
|
|||||||
// There must have been a previous session is PendingSlashReport is populated
|
// There must have been a previous session is PendingSlashReport is populated
|
||||||
let set =
|
let set =
|
||||||
ValidatorSet { network, session: Session(Self::session(network).unwrap().0 - 1) };
|
ValidatorSet { network, session: Session(Self::session(network).unwrap().0 - 1) };
|
||||||
if !key.verify(&report_slashes_message(&set, slashes), signature) {
|
if !key.verify(&slashes.report_slashes_message(), signature) {
|
||||||
Err(InvalidTransaction::BadProof)?;
|
Err(InvalidTransaction::BadProof)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,8 @@ fn basic_functionality() {
|
|||||||
},
|
},
|
||||||
b"Hello, World!".to_vec(),
|
b"Hello, World!".to_vec(),
|
||||||
)
|
)
|
||||||
.await;
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// Queue this twice, which message-queue should de-duplicate
|
// Queue this twice, which message-queue should de-duplicate
|
||||||
for _ in 0 .. 2 {
|
for _ in 0 .. 2 {
|
||||||
@@ -103,7 +104,8 @@ fn basic_functionality() {
|
|||||||
},
|
},
|
||||||
b"Hello, World, again!".to_vec(),
|
b"Hello, World, again!".to_vec(),
|
||||||
)
|
)
|
||||||
.await;
|
.await
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Successfully get it
|
// Successfully get it
|
||||||
@@ -146,7 +148,8 @@ fn basic_functionality() {
|
|||||||
},
|
},
|
||||||
b"Hello, World!".to_vec(),
|
b"Hello, World!".to_vec(),
|
||||||
)
|
)
|
||||||
.await;
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let monero = MessageQueue::new(
|
let monero = MessageQueue::new(
|
||||||
Service::Processor(NetworkId::Monero),
|
Service::Processor(NetworkId::Monero),
|
||||||
|
|||||||
Reference in New Issue
Block a user