-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into new_tx_pool_architecture
- Loading branch information
Showing
12 changed files
with
399 additions
and
256 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Rework the P2P service codecs to avoid unnecessary coupling between components. The refactoring makes it explicit that the Gossipsub and RequestResponse codecs only share encoding/decoding functionalities from the Postcard codec. It also makes handling Gossipsub and RequestResponse messages completely independent of each other. |
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,52 @@ | ||
use std::io; | ||
|
||
use fuel_core_types::fuel_tx::Transaction; | ||
|
||
use crate::gossipsub::messages::{ | ||
GossipTopicTag, | ||
GossipsubBroadcastRequest, | ||
GossipsubMessage, | ||
}; | ||
|
||
use super::{ | ||
Decode, | ||
Encode, | ||
Encoder, | ||
GossipsubCodec, | ||
}; | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct GossipsubMessageHandler<Codec> { | ||
pub(crate) codec: Codec, | ||
} | ||
|
||
impl<Codec> GossipsubCodec for GossipsubMessageHandler<Codec> | ||
where | ||
Codec: | ||
Encode<Transaction, Error = io::Error> + Decode<Transaction, Error = io::Error>, | ||
{ | ||
type RequestMessage = GossipsubBroadcastRequest; | ||
type ResponseMessage = GossipsubMessage; | ||
|
||
fn encode(&self, data: Self::RequestMessage) -> Result<Vec<u8>, io::Error> { | ||
match data { | ||
GossipsubBroadcastRequest::NewTx(tx) => { | ||
Ok(self.codec.encode(&tx)?.into_bytes()) | ||
} | ||
} | ||
} | ||
|
||
fn decode( | ||
&self, | ||
encoded_data: &[u8], | ||
gossipsub_tag: GossipTopicTag, | ||
) -> Result<Self::ResponseMessage, io::Error> { | ||
let decoded_response = match gossipsub_tag { | ||
GossipTopicTag::NewTx => { | ||
GossipsubMessage::NewTx(self.codec.decode(encoded_data)?) | ||
} | ||
}; | ||
|
||
Ok(decoded_response) | ||
} | ||
} |
Oops, something went wrong.