Test historic start times in tendermint-machine

Closes https://github.com/serai-dex/serai/issues/342.

Under ideal network conditions, this is fine. While I won't claim ideal network
conditions will occur IRL, b0fcdd3367 has the
Tributary rebroadcast messages and should brute-force its way into a
functioning system.
This commit is contained in:
Luke Parker 2023-11-13 00:43:35 -05:00
parent 3f7bdaa64b
commit bb8e034e68
No known key found for this signature in database

View file

@ -81,7 +81,7 @@ impl Weights for TestWeights {
4 4
} }
fn weight(&self, id: TestValidatorId) -> u64 { fn weight(&self, id: TestValidatorId) -> u64 {
[1; 4][usize::try_from(id).unwrap()] [1; 4][usize::from(id)]
} }
fn proposer(&self, number: BlockNumber, round: RoundNumber) -> TestValidatorId { fn proposer(&self, number: BlockNumber, round: RoundNumber) -> TestValidatorId {
@ -137,9 +137,8 @@ impl Network for TestNetwork {
} }
} }
async fn slash(&mut self, _: TestValidatorId, _: SlashEvent) { async fn slash(&mut self, id: TestValidatorId, event: SlashEvent) {
dbg!("Slash"); println!("Slash for {id} due to {event:?}");
todo!()
} }
async fn validate(&mut self, block: &TestBlock) -> Result<(), BlockError> { async fn validate(&mut self, block: &TestBlock) -> Result<(), BlockError> {
@ -151,7 +150,7 @@ impl Network for TestNetwork {
block: TestBlock, block: TestBlock,
commit: Commit<TestSignatureScheme>, commit: Commit<TestSignatureScheme>,
) -> Option<TestBlock> { ) -> Option<TestBlock> {
dbg!("Adding ", &block); println!("Adding {:?}", &block);
assert!(block.valid.is_ok()); assert!(block.valid.is_ok());
assert!(self.verify_commit(block.id(), &commit)); assert!(self.verify_commit(block.id(), &commit));
Some(TestBlock { id: (u32::from_le_bytes(block.id) + 1).to_le_bytes(), valid: Ok(()) }) Some(TestBlock { id: (u32::from_le_bytes(block.id) + 1).to_le_bytes(), valid: Ok(()) })
@ -161,6 +160,7 @@ impl Network for TestNetwork {
impl TestNetwork { impl TestNetwork {
async fn new( async fn new(
validators: usize, validators: usize,
start_time: u64,
) -> Arc<RwLock<Vec<(MessageSender<Self>, SyncedBlockSender<Self>, SyncedBlockResultReceiver)>>> ) -> Arc<RwLock<Vec<(MessageSender<Self>, SyncedBlockSender<Self>, SyncedBlockResultReceiver)>>>
{ {
let arc = Arc::new(RwLock::new(vec![])); let arc = Arc::new(RwLock::new(vec![]));
@ -172,7 +172,7 @@ impl TestNetwork {
TendermintMachine::new( TendermintMachine::new(
TestNetwork(i, arc.clone()), TestNetwork(i, arc.clone()),
BlockNumber(1), BlockNumber(1),
SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(), start_time,
TestBlock { id: 1u32.to_le_bytes(), valid: Ok(()) }, TestBlock { id: 1u32.to_le_bytes(), valid: Ok(()) },
) )
.await; .await;
@ -185,7 +185,13 @@ impl TestNetwork {
} }
#[tokio::test] #[tokio::test]
async fn test() { async fn test_machine() {
TestNetwork::new(4).await; TestNetwork::new(4, SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs()).await;
sleep(Duration::from_secs(30)).await;
}
#[tokio::test]
async fn test_machine_with_historic_start_time() {
TestNetwork::new(4, SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs() - 60).await;
sleep(Duration::from_secs(30)).await; sleep(Duration::from_secs(30)).await;
} }