Skip to content

Commit

Permalink
Test historic start times in tendermint-machine
Browse files Browse the repository at this point in the history
Closes #342.

Under ideal network conditions, this is fine. While I won't claim ideal network
conditions will occur IRL, b0fcdd3 has the
Tributary rebroadcast messages and should brute-force its way into a
functioning system.
  • Loading branch information
kayabaNerve committed Nov 13, 2023
1 parent 3f7bdaa commit bb8e034
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions coordinator/tributary/tendermint/tests/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl Weights for TestWeights {
4
}
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 {
Expand Down Expand Up @@ -137,9 +137,8 @@ impl Network for TestNetwork {
}
}

async fn slash(&mut self, _: TestValidatorId, _: SlashEvent) {
dbg!("Slash");
todo!()
async fn slash(&mut self, id: TestValidatorId, event: SlashEvent) {
println!("Slash for {id} due to {event:?}");
}

async fn validate(&mut self, block: &TestBlock) -> Result<(), BlockError> {
Expand All @@ -151,7 +150,7 @@ impl Network for TestNetwork {
block: TestBlock,
commit: Commit<TestSignatureScheme>,
) -> Option<TestBlock> {
dbg!("Adding ", &block);
println!("Adding {:?}", &block);
assert!(block.valid.is_ok());
assert!(self.verify_commit(block.id(), &commit));
Some(TestBlock { id: (u32::from_le_bytes(block.id) + 1).to_le_bytes(), valid: Ok(()) })
Expand All @@ -161,6 +160,7 @@ impl Network for TestNetwork {
impl TestNetwork {
async fn new(
validators: usize,
start_time: u64,
) -> Arc<RwLock<Vec<(MessageSender<Self>, SyncedBlockSender<Self>, SyncedBlockResultReceiver)>>>
{
let arc = Arc::new(RwLock::new(vec![]));
Expand All @@ -172,7 +172,7 @@ impl TestNetwork {
TendermintMachine::new(
TestNetwork(i, arc.clone()),
BlockNumber(1),
SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(),
start_time,
TestBlock { id: 1u32.to_le_bytes(), valid: Ok(()) },
)
.await;
Expand All @@ -185,7 +185,13 @@ impl TestNetwork {
}

#[tokio::test]
async fn test() {
TestNetwork::new(4).await;
async fn test_machine() {
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;
}

0 comments on commit bb8e034

Please sign in to comment.