Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions packages/examples/kademlia-discovery/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::BTreeSet;

use anyhow::Result;
use anyhow::{bail, Result};

use kolme::*;
use libp2p::identity::Keypair;
Expand Down Expand Up @@ -41,6 +41,7 @@ impl MerkleDeserialize for State {
#[serde(rename_all = "snake_case")]
pub enum KademliaTestMessage {
SayHi {},
RejectMe {},
}

// Another keypair for client testing:
Expand Down Expand Up @@ -94,6 +95,7 @@ impl KolmeApp for KademliaTestApp {
) -> Result<()> {
match msg {
KademliaTestMessage::SayHi {} => ctx.state_mut().hi_count += 1,
KademliaTestMessage::RejectMe {} => bail!("Avada Kedavra!"),
}
Ok(())
}
Expand Down Expand Up @@ -204,7 +206,7 @@ pub async fn client(validator_addr: &str) -> Result<()> {
let block = kolme
.sign_propose_await_transaction(
&SecretKey::random(&mut rand::thread_rng()),
vec![Message::App(KademliaTestMessage::SayHi {})],
vec![Message::App(KademliaTestMessage::RejectMe {})],
)
.await?;
println!("New block landed: {}", block.height());
Expand Down
7 changes: 5 additions & 2 deletions packages/kolme/src/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,10 @@ impl<App: KolmeApp> Gossip<App> {
async fn broadcast_mempool_entries(&self, swarm: &mut Swarm<KolmeBehaviour<App::Message>>) {
for tx in self.kolme.get_mempool_entries() {
let txhash = tx.hash();
let msg = GossipMessage::BroadcastTx { tx };
let msg = GossipMessage::BroadcastTx {
tx,
timestamp: jiff::Timestamp::now(),
};
if let Err(e) = msg.publish(self, swarm).await {
tracing::error!(
"{}: Unable to broadcast transaction {txhash}: {e:?}",
Expand Down Expand Up @@ -536,7 +539,7 @@ impl<App: KolmeApp> Gossip<App> {
peers_with_blocks.try_send(report).ok();
}
}
GossipMessage::BroadcastTx { tx } => {
GossipMessage::BroadcastTx { tx, timestamp } => {
self.kolme.propose_transaction(tx);
}
}
Expand Down
8 changes: 6 additions & 2 deletions packages/kolme/src/gossip/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub(super) enum GossipMessage<App: KolmeApp> {
Notification(Notification<App::Message>),
BroadcastTx {
tx: Arc<SignedTransaction<App::Message>>,
timestamp: jiff::Timestamp,
},
}

Expand All @@ -55,8 +56,8 @@ impl<App: KolmeApp> Display for GossipMessage<App> {
GossipMessage::Notification(notification) => {
write!(f, "Notification: {notification:?}")
}
GossipMessage::BroadcastTx { tx } => {
write!(f, "Broadcast {}", tx.hash())
GossipMessage::BroadcastTx { tx, timestamp } => {
write!(f, "Broadcast {}, {timestamp}", tx.hash())
}
}
}
Expand Down Expand Up @@ -103,6 +104,9 @@ impl<App: KolmeApp> GossipMessage<App> {
gossip: &Gossip<App>,
swarm: &mut Swarm<KolmeBehaviour<App::Message>>,
) -> Result<()> {
if let Self::Notification(notification) = &self {
tracing::debug!("Got Notification message: {:?}", notification);
}
tracing::debug!(
"{}: Publishing message to gossipsub: {self}",
gossip.local_display_name
Expand Down
Loading