mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
* Update the coordinator to give key shares based on weight, not based on existence Participants are now identified by their starting index. While this compiles, the following is unimplemented: 1) A conversion for DKG `i` values. It assumes the threshold `i` values used will be identical for the MuSig signature used to confirm the DKG. 2) Expansion from compressed values to full values before forwarding to the processor. * Add a fn to the DkgConfirmer to convert `i` values as needed Also removes TODOs regarding Serai ensuring validator key uniqueness + validity. The current infra achieves both. * Have the Tributary DB track participation by shares, not by count * Prevent a node from obtaining 34% of the maximum amount of key shares This is actually mainly intended to set a bound on message sizes in the coordinator. Message sizes are amplified by the amount of key shares held, so setting an upper bound on said amount lets it determine constants. While that upper bound could be 150, that'd be unreasonable and increase the potential for DoS attacks. * Correct the mechanism to detect if sufficient accumulation has occured It used to check if the latest accumulation hit the required threshold. Now, accumulations may jump past the required threshold. The required mechanism is to check the threshold wasn't prior met and is now met. * Finish updating the coordinator to handle a multiple key share per validator environment * Adjust stategy re: preventing noce reuse in DKG Confirmer * Add TODOs regarding dropped transactions, add possible TODO fix * Update tests/coordinator This doesn't add new multi-key-share tests, it solely updates the existing single key-share tests to compile and run, with the necessary fixes to the coordinator. * Update processor key_gen to handle generating multiple key shares at once * Update SubstrateSigner * Update signer, clippy * Update processor tests * Update processor docker tests
57 lines
1.8 KiB
Rust
57 lines
1.8 KiB
Rust
use core::time::Duration;
|
|
|
|
use rand_core::{RngCore, OsRng};
|
|
|
|
use tokio::time::sleep;
|
|
|
|
use serai_db::MemDb;
|
|
|
|
use tributary::{
|
|
transaction::Transaction as TransactionTrait, Transaction as TributaryTransaction, Tributary,
|
|
};
|
|
|
|
use crate::{
|
|
tributary::Transaction,
|
|
tests::{
|
|
LocalP2p,
|
|
tributary::{new_keys, new_spec, new_tributaries, run_tributaries, wait_for_tx_inclusion},
|
|
},
|
|
};
|
|
|
|
#[tokio::test]
|
|
async fn tx_test() {
|
|
let keys = new_keys(&mut OsRng);
|
|
let spec = new_spec(&mut OsRng, &keys);
|
|
|
|
let tributaries = new_tributaries(&keys, &spec).await;
|
|
|
|
// Run the tributaries in the background
|
|
tokio::spawn(run_tributaries(tributaries.clone()));
|
|
|
|
// Send a TX from a random Tributary
|
|
let sender =
|
|
usize::try_from(OsRng.next_u64() % u64::try_from(tributaries.len()).unwrap()).unwrap();
|
|
let key = keys[sender].clone();
|
|
|
|
let attempt = 0;
|
|
let mut commitments = vec![0; 256];
|
|
OsRng.fill_bytes(&mut commitments);
|
|
|
|
// Create the TX with a null signature so we can get its sig hash
|
|
let block_before_tx = tributaries[sender].1.tip().await;
|
|
let mut tx =
|
|
Transaction::DkgCommitments(attempt, vec![commitments.clone()], Transaction::empty_signed());
|
|
tx.sign(&mut OsRng, spec.genesis(), &key, 0);
|
|
|
|
assert_eq!(tributaries[sender].1.add_transaction(tx.clone()).await, Ok(true));
|
|
let included_in = wait_for_tx_inclusion(&tributaries[sender].1, block_before_tx, tx.hash()).await;
|
|
// Also sleep for the block time to ensure the block is synced around before we run checks on it
|
|
sleep(Duration::from_secs(Tributary::<MemDb, Transaction, LocalP2p>::block_time().into())).await;
|
|
|
|
// All tributaries should have acknowledged this transaction in a block
|
|
for (_, tributary) in tributaries {
|
|
let block = tributary.reader().block(&included_in).unwrap();
|
|
assert_eq!(block.transactions, vec![TributaryTransaction::Application(tx.clone())]);
|
|
}
|
|
}
|