Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
990251c
mailbox feature
ong-jonas Oct 19, 2023
2396d8d
merge refactor into feature
ong-jonas Oct 27, 2023
8e73502
message ID no longer overridden
ong-jonas Oct 27, 2023
28d9103
removed engine.rs
ong-jonas Oct 27, 2023
d55849b
renamed SMR topics to hotstuff_rs
ong-jonas Oct 27, 2023
7da376a
added mailbox subscription feature
ong-jonas Oct 27, 2023
043800a
update network tests
ong-jonas Oct 27, 2023
dd322db
removed droppedtx message type
ong-jonas Oct 30, 2023
cde45ef
added different message handlers and updated hotstuff dependency to 0.3
ong-jonas Oct 30, 2023
0f945a7
updated config keypair to pchain type
ong-jonas Oct 31, 2023
0879474
added helper function in network tests
ong-jonas Oct 31, 2023
17673c0
mempool messages accepts V1 or V2
ong-jonas Nov 1, 2023
4a7c7aa
Update lib.rs
Nov 1, 2023
ef789f2
Fix: serialize TransactionV1 and TransactionV2 separately in messages.rs
Nov 1, 2023
725d99b
Update libp2p deprecated package
Nov 1, 2023
30d2dd4
update message serialization and handler channels
ong-jonas Nov 8, 2023
994834c
update message handlers to FnMut
Nov 9, 2023
f01c511
FIX: removed deprecated dependencies
ong-jonas Nov 16, 2023
54ffb64
REFACTOR: removed with_dns, added nodelay(true)
ong-jonas Nov 16, 2023
29ea7c7
REFACTOR: try_from to filter_gossipsub_messages, Vec<msg_handlers> to…
ong-jonas Nov 21, 2023
6b3543d
deps: update dependency to hotstuff_rs
ong-jonas Nov 30, 2023
5a7c61e
refactor: update pchain-types dependency version
ong-jonas Dec 1, 2023
8556c0f
Merge branch 'v0.5' into mailbox/feature
ong-jonas Dec 5, 2023
5b379a9
REFACTOR: documentation update to reflect single message handler
ong-jonas Dec 5, 2023
f66e4c2
refactor: moved is_close_peer function to peer.rs and updated PeerSta…
ong-jonas Dec 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated config keypair to pchain type
  • Loading branch information
ong-jonas committed Oct 31, 2023
commit 0f945a7891bc3e7b91b84fd71eb298a70dc62df4
10 changes: 6 additions & 4 deletions src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mod test {
identity::{ed25519, PeerId},
Multiaddr,
};
use pchain_types::cryptography::PublicAddress;
use pchain_types::cryptography::{PublicAddress, self};

use crate::{
config::Config,
Expand All @@ -212,8 +212,10 @@ mod test {
}

fn create_new_peer() -> Peer {
let keypair = ed25519::Keypair::generate();
let local_keypair = cryptography::Keypair::from_keypair_bytes(&keypair.to_bytes()).unwrap();
let config = Config {
keypair: ed25519::Keypair::generate(),
keypair: local_keypair,
topics_to_subscribe: vec![Topic::HotStuffRsBroadcast],
listening_port: 25519,
boot_nodes: vec![],
Expand All @@ -222,11 +224,11 @@ mod test {
kademlia_protocol_name: String::from("/test"),
};

let public_address = config.keypair.public().to_bytes();
let public_address = config.keypair.verifying_key().to_bytes();

let behaviour = Behaviour::new(
public_address,
&config.keypair,
&keypair,
config.kademlia_protocol_name,
);

Expand Down
5 changes: 2 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//!
//! ```no_run
//! let config = Config {
//! keypair: libp2p_identity::ed25519::Keypair::generate(),
//! keypair: pchain_types::cryptography::Keypair,
//! topics_to_subscribe: vec![Topic::HotStuffRsBroadcast],
//! listening_port: 25519,
//! boot_nodes: vec![],
Expand All @@ -20,8 +20,7 @@
//! ```
//!
use std::net::Ipv4Addr;
use libp2p::identity::ed25519::Keypair;
use pchain_types::cryptography::PublicAddress;
use pchain_types::cryptography::{Keypair, PublicAddress};

use crate::messages::Topic;

Expand Down
18 changes: 12 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//!
//! // 1. Build a configuration.
//! let config = Config {
//! keypair, // libp2p_identity::ed25519::Keypair::generate()
//! keypair, // pchain_types::cryptography::Keypair
//! topics_to_subscribe, // vec![Topic::HotStuffRsBroadcast]
//! listening_port, // 25519
//! boot_nodes, // vec![]
Expand All @@ -27,13 +27,18 @@
//!
//! // 2. Create message handlers
//! let (tx, rx) = mpsc::channel();
//! let message_sender = tx.clone();
//! let message_handler = move |msg_orgin: [u8;32], msg: Message| {
//! // processing the message...
//! let _ = message_sender.send((msg_origin, msg));
//! let hotstuff_sender = tx.clone();
//! let hotstuff_handler = move |msg_orgin: [u8;32], msg: Message| {
//! match msg {
//! Message::HotStuffRs(hotstuff_message) => {
//! //process hotstuff message
//! let _ = hotstuff_sender.send((msg_origin, Message::HotStuffRs(hotstuff_message)));
//! }
//! _ => {}
//! }
//! };
//! let mut message_handlers: Vec<Box<dyn Fn(PublicAddress, Message) + Send>> = vec![];
//! message_handlers.push(Box::new(message_handler));
//! message_handlers.push(Box::new(hotstuff_handler));
//!
//! // 3. Start P2P network.
//! let peer = Peer::start(config, message_handlers)
Expand All @@ -49,6 +54,7 @@
pub mod behaviour;

pub mod config;
pub use config::Config;

pub mod conversions;

Expand Down
18 changes: 11 additions & 7 deletions src/peer.rs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking at PeerStartError::SystemConfigError. Its itemdoc says that the variant corresponds to the case where we "Failed to read from system configuration path". However, I don't see anywhere in the code where we read a file at a path.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated it with the correct error variant.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use libp2p::{
core::{muxing::StreamMuxerBox, transport::Boxed},
dns::TokioDnsConfig,
gossipsub,
identify, identity::{self}, noise,
identify, identity::{self, ed25519::Keypair}, noise,
swarm::{SwarmBuilder, SwarmEvent},
tcp, yamux, PeerId, Transport,
};
Expand Down Expand Up @@ -141,18 +141,19 @@ pub(crate) enum PeerCommand {
async fn set_up_transport(config: &Config) -> Result<libp2p::Swarm<Behaviour>,std::io::Error> {
// Read network configuration
let local_keypair = &config.keypair;
let local_public_address: PublicAddress = local_keypair.public().to_bytes();
let local_peer_id = identity::Keypair::from(local_keypair.clone())
let local_public_address: PublicAddress = local_keypair.verifying_key().to_bytes();
let local_libp2p_keypair = Keypair::try_from_bytes(config.keypair.to_keypair_bytes().as_mut_slice()).unwrap();
let local_peer_id = identity::Keypair::from(local_libp2p_keypair.clone())
.public()
.to_peer_id();

log::info!("Local PeerId: {:?}", local_peer_id);

// Instantiate Swarm
let transport = build_transport(local_keypair.clone()).await?;
let transport = build_transport(local_libp2p_keypair.clone()).await?;
let behaviour = Behaviour::new(
local_public_address,
&local_keypair,
&local_libp2p_keypair,
config.kademlia_protocol_name.clone(),
);
let swarm = SwarmBuilder::with_tokio_executor(transport, behaviour, local_peer_id).build();
Expand Down Expand Up @@ -211,10 +212,13 @@ fn establish_network_connections(mut swarm: libp2p::Swarm<Behaviour> , config: &
fn start_event_handling(mut swarm: libp2p::Swarm<Behaviour>, config: &Config, message_handlers: Vec<Box<dyn Fn(PublicAddress, Message) + Send>>) ->
(JoinHandle<()>,tokio::sync::mpsc::Sender<PeerCommand>) {
// 4. Start p2p networking
let local_public_address = config.keypair.public().to_bytes();
let local_peer_id = identity::Keypair::from(config.keypair.clone())
let local_keypair = &config.keypair;
let local_public_address: PublicAddress = local_keypair.verifying_key().to_bytes();
let local_libp2p_keypair = Keypair::try_from_bytes(config.keypair.to_keypair_bytes().as_mut_slice()).unwrap();
let local_peer_id = identity::Keypair::from(local_libp2p_keypair.clone())
.public()
.to_peer_id();

let (sender, mut receiver) =
tokio::sync::mpsc::channel::<PeerCommand>(config.outgoing_msgs_buffer_capacity);
let mut discover_tick =
Expand Down
5 changes: 3 additions & 2 deletions tests/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use pchain_network::{
config::Config,
messages::{Topic, Message},
};
use pchain_types::cryptography;
use pchain_types::{blockchain::TransactionV1, cryptography::PublicAddress};

fn base_tx(signer: PublicAddress) -> TransactionV1 {
Expand Down Expand Up @@ -470,9 +471,9 @@ pub async fn node(
boot_nodes: Vec<([u8;32], Ipv4Addr, u16)>,
topics_to_subscribe: Vec<Topic>
) -> (Peer, std::sync::mpsc::Receiver<(PublicAddress, Message)>) {

let local_keypair = cryptography::Keypair::from_keypair_bytes(&keypair.to_bytes()).unwrap();
let config = Config {
keypair,
keypair: local_keypair,
topics_to_subscribe,
listening_port,
boot_nodes,
Expand Down