Skip to content

Commit

Permalink
rollback topic limit
Browse files Browse the repository at this point in the history
Signed-off-by: ozkanonur <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Apr 17, 2023
1 parent 0da7d9e commit 4d2cacc
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 16 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
- p2p stack is improved [#1755](https://github.com/KomodoPlatform/atomicDEX-API/pull/1755)
- - Validate topics if they are mixed or not.
- - Do early return if the message data is not valid (since no point to iterate over and over on the invalid message)
- - Avoid decoding messages that have more than 25 topics
- - Break the loop right after processing any of `SWAP_PREFIX`, `WATCHER_PREFIX`, `TX_HELPER_PREFIX` topic.


Expand Down
16 changes: 1 addition & 15 deletions mm2src/gossipsub/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ impl Decoder for GossipsubCodec {
type Error = io::Error;

fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
const MAX_TOPICS: usize = 25;

let packet = some_or_return_ok_none!(self.length_codec.decode(src)?);

let rpc = rpc_proto::Rpc::decode(&packet[..])?;
Expand All @@ -231,24 +229,12 @@ impl Decoder for GossipsubCodec {
));
}

let topics = publish.topic_ids.into_iter().map(TopicHash::from_raw);
if topics.len() > MAX_TOPICS {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!(
"Too many topics provided. Allowed topic count: {}, Received topic count: {}",
MAX_TOPICS,
topics.len()
),
));
}

messages.push(GossipsubMessage {
source: PeerId::from_bytes(&publish.from.unwrap_or_default())
.map_err(|_| io::Error::new(io::ErrorKind::InvalidData, "Invalid Peer Id"))?,
data: publish.data.unwrap_or_default(),
sequence_number: BigEndian::read_u64(&seq_no),
topics: topics.collect(),
topics: publish.topic_ids.into_iter().map(TopicHash::from_raw).collect(),
});
}

Expand Down

0 comments on commit 4d2cacc

Please sign in to comment.