Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2987e63
Add new gossip message with deserialization stuff and new trait
MitchTurner Feb 18, 2025
c58d79b
Add new topic to behavior creation
MitchTurner Feb 19, 2025
bbd92e4
Get test passing
MitchTurner Feb 19, 2025
9432057
Cleanup test, make more robust
MitchTurner Feb 19, 2025
d7347d6
Merge branch 'master' into feature/tx-confirmation-gossip
MitchTurner Feb 19, 2025
2da50de
Add reject test
MitchTurner Feb 19, 2025
b5cc5dc
Add test for p2p task for broadcasting the message
MitchTurner Feb 19, 2025
30e66cd
Add test for broadcast impl of shared state, refactor
MitchTurner Feb 19, 2025
fb58c03
Update CHANGELOG
MitchTurner Feb 19, 2025
4f35d55
Update the types to include key delagation and proper signatures
MitchTurner Feb 20, 2025
143804d
Rename type
MitchTurner Feb 20, 2025
33d7901
Merge branch 'master' into feature/tx-confirmation-gossip
MitchTurner Feb 20, 2025
c513c25
Fix serde feature stuff
MitchTurner Feb 20, 2025
e5d041e
More name changes
MitchTurner Feb 20, 2025
c78700a
Add boolean cli arg to control if subscribed to pre-confirmations
MitchTurner Feb 20, 2025
e759fe5
Merge remote-tracking branch 'origin' into feature/tx-confirmation-go…
MitchTurner Feb 20, 2025
94c4ae2
Complete merge
MitchTurner Feb 20, 2025
89e44b0
More renaming
MitchTurner Feb 20, 2025
6748d0c
Rename missed const
MitchTurner Feb 20, 2025
4eb4a1a
Merge branch 'master' into feature/tx-confirmation-gossip
MitchTurner Feb 21, 2025
2386cad
Merge branch 'master' into feature/tx-confirmation-gossip
MitchTurner Feb 21, 2025
5cbe218
Remove test refactor
MitchTurner Feb 23, 2025
68ea851
Merge branch 'master' into feature/tx-confirmation-gossip
MitchTurner Feb 23, 2025
226e8f2
Appease Clippy-sama
MitchTurner Feb 23, 2025
7f82371
Rename trait method
MitchTurner Feb 24, 2025
985f8dc
Merge branch 'master' into feature/tx-confirmation-gossip
MitchTurner Feb 24, 2025
a54218d
Merge branch 'master' into feature/tx-confirmation-gossip
MitchTurner Feb 24, 2025
770a33b
Merge branch 'master' into feature/tx-confirmation-gossip
MitchTurner Feb 25, 2025
23ce81e
Merge branch 'master' into feature/tx-confirmation-gossip
MitchTurner Feb 25, 2025
e142897
Rename topic
MitchTurner Feb 25, 2025
35ecbd9
Merge branch 'master' into feature/tx-confirmation-gossip
MitchTurner Feb 26, 2025
9bb3e86
Merge branch 'master' into feature/tx-confirmation-gossip
MitchTurner Feb 26, 2025
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: 6 additions & 0 deletions crates/services/p2p/src/codecs/postcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ impl GossipsubCodec for PostcardCodec {
fn encode(&self, data: Self::RequestMessage) -> Result<Vec<u8>, io::Error> {
let encoded_data = match data {
GossipsubBroadcastRequest::NewTx(tx) => postcard::to_stdvec(&*tx),
GossipsubBroadcastRequest::Confirmations(confirmations) => {
postcard::to_stdvec(&*confirmations)
}
};

encoded_data.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))
Expand All @@ -170,6 +173,9 @@ impl GossipsubCodec for PostcardCodec {
) -> Result<Self::ResponseMessage, io::Error> {
let decoded_response = match gossipsub_tag {
GossipTopicTag::NewTx => GossipsubMessage::NewTx(deserialize(encoded_data)?),
GossipTopicTag::TxConfirmations => {
GossipsubMessage::Confirmations(deserialize(encoded_data)?)
}
};

Ok(decoded_response)
Expand Down
16 changes: 14 additions & 2 deletions crates/services/p2p/src/gossipsub/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use super::topics::NEW_TX_GOSSIP_TOPIC;
use super::topics::{
NEW_TX_GOSSIP_TOPIC,
TX_CONFIRMATIONS_GOSSIP_TOPIC,
};
use crate::{
config::{
Config,
Expand Down Expand Up @@ -49,6 +52,8 @@ const MESH_SIZE: usize = 8;
// The weight applied to the score for delivering new transactions.
const NEW_TX_GOSSIP_WEIGHT: f64 = 0.05;

const TX_CONFIRMATIONS_GOSSIP_WEIGHT: f64 = 0.05;

// The threshold for a peer's score to be considered for greylisting.
// If a peer's score falls below this value, they will be greylisted.
// Greylisting is a lighter form of banning, where the peer's messages might be ignored or given lower priority,
Expand Down Expand Up @@ -222,7 +227,14 @@ fn initialize_gossipsub(gossipsub: &mut gossipsub::Behaviour, p2p_config: &Confi
.with_peer_score(peer_score_params, peer_score_thresholds)
.expect("gossipsub initialized with peer score");

let topics = vec![(NEW_TX_GOSSIP_TOPIC, NEW_TX_GOSSIP_WEIGHT)];
// TODO: Make topics configurable.
let topics = vec![
(NEW_TX_GOSSIP_TOPIC, NEW_TX_GOSSIP_WEIGHT),
(
TX_CONFIRMATIONS_GOSSIP_TOPIC,
TX_CONFIRMATIONS_GOSSIP_WEIGHT,
),
];

// subscribe to gossipsub topics with the network name suffix
for (topic, weight) in topics {
Expand Down
4 changes: 4 additions & 0 deletions crates/services/p2p/src/gossipsub/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::sync::Arc;

use fuel_core_types::fuel_tx::Transaction;

use fuel_core_types::services::p2p::TxConfirmations;
use serde::{
Deserialize,
Serialize,
Expand All @@ -12,6 +13,7 @@ use serde::{
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum GossipTopicTag {
NewTx,
TxConfirmations,
}

/// Takes `Arc<T>` and wraps it in a matching GossipsubBroadcastRequest
Expand All @@ -20,9 +22,11 @@ pub enum GossipTopicTag {
#[derive(Debug, Clone)]
pub enum GossipsubBroadcastRequest {
NewTx(Arc<Transaction>),
Confirmations(Arc<TxConfirmations>),
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum GossipsubMessage {
NewTx(Transaction),
Confirmations(TxConfirmations),
}
11 changes: 11 additions & 0 deletions crates/services/p2p/src/gossipsub/topics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,27 @@ use super::messages::{
};

pub const NEW_TX_GOSSIP_TOPIC: &str = "new_tx";
pub const TX_CONFIRMATIONS_GOSSIP_TOPIC: &str = "tx_confirmations";

/// Holds used Gossipsub Topics
/// Each field contains TopicHash of existing topics
/// in order to avoid converting topics to TopicHash on each received message
#[derive(Debug)]
pub struct GossipsubTopics {
new_tx_topic: TopicHash,
tx_confirmations_topic: TopicHash,
}

impl GossipsubTopics {
pub fn new(network_name: &str) -> Self {
let new_tx_topic: Sha256Topic =
Topic::new(format!("{NEW_TX_GOSSIP_TOPIC}/{network_name}"));
let tx_confirmations_topic: Sha256Topic =
Topic::new(format!("{TX_CONFIRMATIONS_GOSSIP_TOPIC}/{network_name}"));

Self {
new_tx_topic: new_tx_topic.hash(),
tx_confirmations_topic: tx_confirmations_topic.hash(),
}
}

Expand All @@ -36,6 +41,9 @@ impl GossipsubTopics {
) -> Option<GossipTopicTag> {
match incoming_topic {
hash if hash == &self.new_tx_topic => Some(GossipTopicTag::NewTx),
hash if hash == &self.tx_confirmations_topic => {
Some(GossipTopicTag::TxConfirmations)
}
_ => None,
}
}
Expand All @@ -48,6 +56,9 @@ impl GossipsubTopics {
) -> TopicHash {
match outgoing_request {
GossipsubBroadcastRequest::NewTx(_) => self.new_tx_topic.clone(),
GossipsubBroadcastRequest::Confirmations(_) => {
self.tx_confirmations_topic.clone()
}
}
}
}
Expand Down
Loading
Loading