-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* make examples folder * more readme docs
- Loading branch information
1 parent
5e80513
commit dc48228
Showing
15 changed files
with
286 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::collections::VecDeque; | ||
use tokio::sync::{mpsc, Mutex}; | ||
use std::{ | ||
time::{SystemTime, UNIX_EPOCH}, | ||
}; | ||
|
||
use tokio_stream::StreamExt; | ||
use tendermint::crypto::ECDSAKeypair; | ||
use tendermint::messages::SignedMessage; | ||
use tendermint::process::Process; | ||
use tendermint::rpc_server::Server; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
// Network configuration: | ||
// - peers: (pubkey,address)[] | ||
|
||
// Setup RPC server. | ||
// Setup RPC client for each peer. | ||
// Setup process. | ||
// Run process. | ||
|
||
// let peers = [ | ||
// ("http://localhost:3001"), | ||
// ]; | ||
|
||
let keypair = ECDSAKeypair::new(); | ||
|
||
let mut peer_senders = Vec::new(); | ||
|
||
let api_server = Server::<SignedMessage>::new(3030); | ||
let receiver = api_server.get_receiver(); | ||
tokio::spawn(async move { | ||
api_server.run().await; | ||
}); | ||
// tokio::spawn(async move { | ||
// client.start().await; | ||
// }); | ||
|
||
let get_value = || SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs().to_string(); | ||
|
||
// Define proposer sequence (round-robin) | ||
let proposer_sequence: Vec<usize> = (0..4).collect(); | ||
let mut process = | ||
Process::new(0, keypair, receiver, peer_senders, proposer_sequence.clone(), get_value); | ||
|
||
// Listen to events from node0. | ||
let mut subscriber1 = process.subscribe(); | ||
tokio::spawn(async move { | ||
while let Some(event) = subscriber1.next().await { | ||
println!("Subscriber 1 received: {:?}", event); | ||
} | ||
}); | ||
|
||
tokio::spawn(async move { | ||
process.run_epoch(None).await; | ||
}).await.unwrap(); | ||
|
||
println!("Consensus reached."); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use std::collections::VecDeque; | ||
|
||
use std::{ | ||
sync::Arc, | ||
time::{SystemTime, UNIX_EPOCH}, | ||
}; | ||
use tokio::sync::{mpsc, Mutex}; | ||
use tokio_stream::StreamExt; | ||
use tendermint::crypto::ECDSAKeypair; | ||
use tendermint::params::*; | ||
use tendermint::process::*; | ||
|
||
|
||
async fn setup_pure_sendreceive() { | ||
// Create channels for each node | ||
let mut senders = Vec::new(); | ||
let mut receivers = VecDeque::new(); | ||
|
||
let get_value = || SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs().to_string(); | ||
|
||
// Separate the creation of senders and receivers | ||
for _ in 0..NODES { | ||
let (tx, rx) = mpsc::channel(100); | ||
senders.push(tx); | ||
receivers.push_back(rx); | ||
} | ||
|
||
// Define proposer sequence (round-robin) | ||
let proposer_sequence: Vec<usize> = (0..NODES).collect(); | ||
|
||
// Initialize nodes | ||
let mut nodes = Vec::new(); | ||
for i in 0..NODES { | ||
let mut node_senders = Vec::new(); | ||
for j in 0..NODES { | ||
if i != j { | ||
node_senders.push(senders[j].clone()); | ||
} | ||
} | ||
let keypair = ECDSAKeypair::new(); | ||
let receiver = receivers.pop_front().unwrap(); | ||
let node = Process::new( | ||
i, | ||
keypair, | ||
Arc::new(Mutex::new(receiver)), | ||
node_senders, | ||
proposer_sequence.clone(), | ||
get_value, | ||
); | ||
nodes.push(node); | ||
} | ||
|
||
// Listen to events from node0. | ||
let mut subscriber1 = nodes[0].subscribe(); | ||
tokio::spawn(async move { | ||
while let Some(event) = subscriber1.next().await { | ||
println!("Subscriber 1 received: {:?}", event); | ||
} | ||
}); | ||
|
||
// Run all nodes | ||
let handles: Vec<_> = nodes | ||
.into_iter() | ||
.map(|mut node| { | ||
tokio::spawn(async move { | ||
node.run_epoch(None).await; | ||
}) | ||
}) | ||
.collect(); | ||
|
||
// Wait for all nodes to finish | ||
for handle in handles { | ||
let _ = handle.await; | ||
} | ||
|
||
println!("Consensus reached."); | ||
} | ||
|
||
|
||
#[tokio::main] | ||
async fn main() { | ||
setup_pure_sendreceive().await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use std::collections::VecDeque; | ||
use std::time::{SystemTime, UNIX_EPOCH}; | ||
use tokio_stream::StreamExt; | ||
use tendermint::crypto::ECDSAKeypair; | ||
use tendermint::params::*; | ||
use tendermint::process::*; | ||
use tendermint::rpc_client::RpcClient; | ||
use tendermint::rpc_server::Server; | ||
use tendermint::messages::SignedMessage; | ||
|
||
async fn setup_api_servers() { | ||
// Create channels for each node | ||
let mut senders = Vec::new(); | ||
let mut receivers = VecDeque::new(); | ||
|
||
let get_value = || SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs().to_string(); | ||
|
||
// Setup node API servers. | ||
for i in 0..NODES { | ||
let server = Server::<SignedMessage>::new(3030 + i as u16); | ||
receivers.push_back(server.get_receiver()); | ||
let client = RpcClient::<SignedMessage>::new( | ||
100, | ||
format!("http://localhost:{}/inbox/", server.port), | ||
); | ||
senders.push(client.get_sender()); | ||
|
||
tokio::spawn(async move { | ||
server.run().await; | ||
}); | ||
tokio::spawn(async move { | ||
client.start().await; | ||
}); | ||
} | ||
|
||
// Define proposer sequence (round-robin) | ||
let proposer_sequence: Vec<usize> = (0..NODES).collect(); | ||
|
||
// Initialize nodes | ||
let mut nodes = Vec::new(); | ||
for i in 0..NODES { | ||
let mut node_senders = Vec::new(); | ||
for j in 0..NODES { | ||
if i != j { | ||
node_senders.push(senders[j].clone()); | ||
} | ||
} | ||
|
||
let keypair = ECDSAKeypair::new(); | ||
let receiver = receivers.pop_front().unwrap(); | ||
let node = | ||
Process::new(i, keypair, receiver, node_senders, proposer_sequence.clone(), get_value); | ||
nodes.push(node); | ||
} | ||
|
||
// Listen to events from node0. | ||
let mut subscriber1 = nodes[0].subscribe(); | ||
tokio::spawn(async move { | ||
while let Some(event) = subscriber1.next().await { | ||
println!("Subscriber 1 received: {:?}", event); | ||
} | ||
}); | ||
|
||
// Run all nodes | ||
let handles: Vec<_> = nodes | ||
.into_iter() | ||
.map(|mut node| { | ||
tokio::spawn(async move { | ||
node.run_epoch(None).await; | ||
}) | ||
}) | ||
.collect(); | ||
|
||
// Wait for all nodes to finish | ||
for handle in handles { | ||
let _ = handle.await.unwrap(); | ||
} | ||
|
||
println!("Consensus reached."); | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
println!("Main"); | ||
setup_api_servers().await; | ||
|
||
// just wait for sigkill | ||
tokio::signal::ctrl_c().await.unwrap(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.