Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Do not send messages twice in bitfield distribution #2005

Merged
merged 3 commits into from
Nov 24, 2020

Conversation

bkchr
Copy link
Member

@bkchr bkchr commented Nov 24, 2020

This removes a bug which resulted in sending bitfield messages multiple
times by not checking if we already relayed them. Besides that it also
adds an optimization to not relay a message to a peer that send us
this message.

This removes a bug which resulted in sending bitfield messages multiple
times by not checking if we already relayed them. Besides that it also
adds an optimization to not relay a message to a peer that send us
this message.
@bkchr bkchr added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. labels Nov 24, 2020
@@ -443,6 +447,9 @@ where
}
one_per_validator.insert(validator.clone(), message.clone());

// If the peer has sent us a message, we don't need to send him the same.
job_data.message_sent_to_peer.entry(origin.clone()).or_default().insert(validator.clone());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is the set of received messages.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good point. But why should we update the message_sent_to_peer if we've only received the message? It seems like we should only update the message_received_from_peer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also check message_received_from_peer in the interested_peers computation in relay_peers, I guess.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good point. But why should we update the message_sent_to_peer if we've only received the message? It seems like we should only update the message_received_from_peer

If I have received the message from you, what is the benefit of sending you the same message again? This would happen below in `relay_message'. While you will not decrease my reputation for this, as I did not yet send you this message, I just waste my bandwidth for a message that is already known by you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who says they're the same message? We only know that they're from the same validator. The bitfield distribution section of the guide goes deeper into the rationale.

That is a good point, but we actually don't account for this in the code? As far as I have seen, we only check if we have send/received a message based on the validator is message is coming from.

You are saying that we actually should look into the message and check if they are different, is that correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are saying that we actually should look into the message and check if they are different, is that correct?

No, the change I suggest is just to check if we've received a message from the peer before sending a message. I think the thing this is trying to work around is where both peers send each other the message at the same time and then report each other.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't try to work around this and this did not happen. We also just report a peer if it sends us the same message twice. We don't check if we send the message to this peer already for reporting the peer. Because as you said, this is very likely to end in a race condition.

However, I will do your requested changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other thing that I spoke about is that the code currently assumes that each validator only sends one bitfield per relay chain. Will this always be true or will we may change this in the future?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be true for the foreseeable future

Copy link
Contributor

@rphmeier rphmeier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except for my one comment about duplicate check

// create a signed message by validator 0
let payload = AvailabilityBitfield(bitvec![bitvec::order::Lsb0, u8; 1u8; 32]);
let signed_bitfield =
executor::block_on(Signed::<AvailabilityBitfield>::sign(&keystore, payload, &signing_context, 0, &validator))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind wrapping this and other lines introduced by this PR that grew unwieldly?

@rphmeier rphmeier merged commit bb91bed into master Nov 24, 2020
@rphmeier rphmeier deleted the bkchr-bitfield-distribution-optimizations branch November 24, 2020 21:40
ordian added a commit that referenced this pull request Nov 25, 2020
* master:
  Some code cleanup in overseer (#2008)
  PoV Distribution optimization (#1990)
  Approval Distribution Subsystem (#1951)
  Session management for approval voting (#1973)
  Do not send messages twice in bitfield distribution (#2005)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants