[F104] Deduplicates requested operation IDs before cloning/assembling responses#5132
Conversation
| let block_op_ids_set: PreHashSet<OperationId> = | ||
| block_op_ids.iter().copied().collect(); | ||
| asked_ops.retain(|id| block_op_ids_set.contains(id)); | ||
| let mut seen = PreHashSet::default(); |
There was a problem hiding this comment.
That looks good.
But I think we could catch this issue earlier, in massa-protocol-worker/src/handlers/block_handler/messages.rs:287 in
impl Deserializer<BlockMessage> for BlockMessageDeserializer {
fn deserialize<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>()applying the same principle, Operations deserializer would become something like:
BlockInfoType::Operations => self
.operation_ids_deserializer
.deserialize(rest)
.map(|(rest, operation_ids)| {
let deduplicated: Vec<OperationId> = operation_ids
.into_iter()
.collect::<PreHashSet<_>>()
.into_iter()
.collect();
(rest, AskForBlockInfo::Operations(deduplicated))
}),what do you think?
There was a problem hiding this comment.
Second opinion: I think we could go with @bilboquet's approach if we don't intend to punish the peer for duplicated ops.
(in the issue recomandations: optionally treat excessive duplicates as a peer offense). If we want to punish our peer, I think the current location of this dedup makes more sence.
I could go either way personally.
There was a problem hiding this comment.
Reading my comment a second time, I realize I was not clear.
It was not a counter proposal: I was suggesting to do it in both places.
EDIT: never mind, that's dumb. My "proposal for an early filter" would prevent any action against the guilty peer.
So it's probably better to keep the PR version and decide what to do with peer.
(thanks leo for the remark)
resync_checkflag