Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revamped TIER1 discovery protocol #8085

Merged
merged 7 commits into from
Nov 22, 2022
Merged

Conversation

pompon0
Copy link
Contributor

@pompon0 pompon0 commented Nov 18, 2022

  • added some extra fields to AccountData, renamed a bunch of them for better readability. This PR is not backward compatible in a sense that the old binary won't accept new AccountData and vice versa (protobuf compatibility is preserved, however the custom validation logic will treat different fields as required). That's ok as the broadcasted data is not interpreted yet.
  • changed identifier of AccountData from (EpochId,AccountId) to AccountKey, which simplifies a lot of stuff and generally makes more sense
  • changed version ID of AccountData from an UTC timestamp to an integer: this allows to avoid bad impact of a wall clock time shift, which can be especially dangerous since we do not version AccountData by EpochId any more. The creation timestamp is still present in AccountData to be able to debug data freshness. We can additionally implement an expiration policy in the future based on the timestamp.
  • rearranged the code related to broadcasting AccountData to align with the TIER1-related code which comes next after this PR

@pompon0 pompon0 requested a review from a team as a code owner November 18, 2022 13:43
@pompon0 pompon0 requested review from mm-near and matklad and removed request for mm-near November 18, 2022 13:43
@pompon0 pompon0 requested a review from matklad November 20, 2022 22:52
Copy link
Contributor

@matklad matklad left a comment

Choose a reason for hiding this comment

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

Overall LGTM, two Qs:

  1. should we check that at least one proxy/stun server is configured?
  2. why do we need version? Timestamp should be enough.

chain/network/src/accounts_data/mod.rs Outdated Show resolved Hide resolved
chain/network/src/accounts_data/mod.rs Outdated Show resolved Hide resolved
chain/network/src/config.rs Show resolved Hide resolved
chain/network/src/config.rs Show resolved Hide resolved
Comment on lines +213 to 218
// Version of the AccountData. A node can override a previous version,
// by broadcasting a never version.
uint64 version = 7;
// Time of creation of this AccountData.
// TODO(gprusak): consider expiring the AccountData based on this field.
google.protobuf.Timestamp timestamp = 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need both version and timestamp? It seeems that the timestamp can double as version for the purposes of invalidation, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

timestamp is the UTC time at which the AccountData was created. There is no guarantee that UTC clock will be monotone, and we want to be able to override the previous version of AccountData even if UTC clock moved backwards in time.

Copy link
Contributor

@matklad matklad Nov 21, 2022

Choose a reason for hiding this comment

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

So we can do smth like max(prev_timestamp + 1, utc::now()), basically force monotonicity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, look, I want to actually track the time at which the thing was signed, so that I can view it and debug.
And I don't want a situation in which somebody at some point produces a piece of data 100 years into the future and then suddenly the timestamp is broken for the next 100 years.

I also want to eventually implement expiration policy on these data and given that the clocks on different machines are skewed it will really make it hard to reason about this if we add custom behavior of max(prev_timestamp+1,now()) on top of that.

chain/network/src/peer_manager/network_state/tier1.rs Outdated Show resolved Hide resolved
chain/network/src/peer_manager/peer_manager_actor.rs Outdated Show resolved Hide resolved
@pompon0
Copy link
Contributor Author

pompon0 commented Nov 21, 2022

@matklad I've answered the questions inline.

@pompon0 pompon0 requested a review from matklad November 21, 2022 16:06
@pompon0 pompon0 requested review from a team and akhi3030 and removed request for a team November 22, 2022 08:53
@near-bulldozer near-bulldozer bot merged commit 824880f into master Nov 22, 2022
@near-bulldozer near-bulldozer bot deleted the gprusak-tier1-discovery-v2 branch November 22, 2022 08:58
nikurt pushed a commit that referenced this pull request Nov 22, 2022
* added some extra fields to AccountData, renamed a bunch of them for better readability. This PR is not backward compatible in a sense that the old binary won't accept new AccountData and vice versa (protobuf compatibility is preserved, however the custom validation logic will treat different fields as required). That's ok as the broadcasted data is not interpreted yet.
* changed identifier of AccountData from (EpochId,AccountId) to AccountKey, which simplifies a lot of stuff and generally makes more sense
* changed version ID of AccountData from an UTC timestamp to an integer: this allows to avoid bad impact of a wall clock time shift, which can be especially dangerous since we do not version AccountData by EpochId any more. The creation timestamp is still present in AccountData to be able to debug data freshness. We can additionally implement an expiration policy in the future based on the timestamp.
* rearranged the code related to broadcasting AccountData to align with the TIER1-related code which comes next after this PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants