-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Simple p2p network * Add peer manager * Implement p2p network * Upgrade dependencies to latest versions * Bump libp2p version to 0.54 * Add initial implementation for P2P messaging * Shift p2p Network implementation to a library * Remove deprecated files and clean up code * Add boot_nodes parameter to P2P network config * Retrieve P2P network config from general node configuration * Create separate channels for node and P2P network communication
- Loading branch information
1 parent
b1b0ad5
commit 9cd08b1
Showing
25 changed files
with
9,445 additions
and
415 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,29 @@ | ||
use crate::utils::node_message::NodeMessage; | ||
use p2p_network::network::{P2PNetwork, P2PNetworkConfig}; | ||
use tokio::sync::mpsc::{Receiver, Sender}; | ||
use tokio::task; | ||
use tracing::info; | ||
|
||
pub struct AVSp2p { | ||
node_tx: Sender<NodeMessage>, | ||
avs_p2p_rx: Receiver<String>, | ||
node_tx: Sender<Vec<u8>>, | ||
node_to_p2p_rx: Receiver<Vec<u8>>, | ||
} | ||
|
||
impl AVSp2p { | ||
pub fn new(node_tx: Sender<NodeMessage>, avs_p2p_rx: Receiver<String>) -> Self { | ||
pub fn new(node_tx: Sender<Vec<u8>>, node_to_p2p_rx: Receiver<Vec<u8>>) -> Self { | ||
AVSp2p { | ||
node_tx, | ||
avs_p2p_rx, | ||
node_to_p2p_rx, | ||
} | ||
} | ||
|
||
// Consumes self and fires up threads | ||
pub fn start(mut self) { | ||
pub async fn start(self, config: P2PNetworkConfig) { | ||
info!("Starting P2P network"); | ||
|
||
//TODO for initial testing | ||
let node_tx = self.node_tx.clone(); | ||
tokio::spawn(async move { | ||
loop { | ||
node_tx | ||
.send(NodeMessage::P2P("Hello from avs p2p!".to_string())) | ||
.await | ||
.unwrap(); | ||
tokio::time::sleep(tokio::time::Duration::from_secs(60)).await; | ||
} | ||
}); | ||
let mut p2p = P2PNetwork::new(&config, self.node_tx.clone(), self.node_to_p2p_rx).await; | ||
|
||
tokio::spawn(async move { | ||
while let Some(message) = self.avs_p2p_rx.recv().await { | ||
tracing::debug!("AVS p2p received: {}", message); | ||
} | ||
task::spawn(async move { | ||
p2p.run(&config).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,20 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Block { | ||
pub tx_list_hash: [u8; 32], | ||
#[serde(with = "serde_bytes")] | ||
pub signature: [u8; 96], // BLS 96 bytes signature | ||
} | ||
|
||
impl From<Block> for Vec<u8> { | ||
fn from(val: Block) -> Self { | ||
bincode::serialize(&val).expect("Serialization failed") | ||
} | ||
} | ||
|
||
impl From<Vec<u8>> for Block { | ||
fn from(bytes: Vec<u8>) -> Self { | ||
bincode::deserialize(&bytes).expect("Deserialization failed") | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
pub mod block; | ||
pub mod block_proposed; | ||
pub mod commit; | ||
pub mod config; | ||
pub mod node_message; | ||
pub mod rpc_client; | ||
pub mod rpc_server; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
Oops, something went wrong.