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

Fix large nonce issue #3013

Merged
merged 5 commits into from
Jul 29, 2020
Merged

Fix large nonce issue #3013

merged 5 commits into from
Jul 29, 2020

Conversation

mfornet
Copy link
Member

@mfornet mfornet commented Jul 20, 2020

Nonces within edges are used for nodes to determine the status of the communication between a pair of nodes. The higher the nonce, the more recent the information is. Nodes should update nonce +2 on each creation, so there is no problem with overflow using u64, but there was an issue that nodes were accepting higher nonce without checking edge with previous nonce existed.

The fix is just not accepting edge proposals with higher nonce, honest nodes will never try to send higher nonce than expected since the way syncing edges is working today new nodes joining the network, even if they loose the information about old connections they will learn nonce immediately after connecting to other nodes via RoutingTable Syncing

Test plan

pytest/tests/sanity/controlled_edge_nonce.py should pass

@mfornet mfornet requested a review from bowenwang1996 July 20, 2020 22:23
@mfornet mfornet requested a review from SkidanovAlex as a code owner July 20, 2020 22:23
@gitpod-io
Copy link

gitpod-io bot commented Jul 20, 2020

@mfornet mfornet changed the base branch from master to network-pytest July 20, 2020 22:30
@SkidanovAlex
Copy link
Collaborator

Are we certain it will not cause issues?
An alternative would be to allow nonces to grow no more than 1000 at a time, which still renders overflows impossible, but will handle gracefully cases when two nodes fail out of sync wrt nonces.

@mfornet
Copy link
Member Author

mfornet commented Jul 21, 2020

Are we certain it will not cause issues?
An alternative would be to allow nonces to grow no more than 1000 at a time, which still renders overflows impossible, but will handle gracefully cases when two nodes fail out of sync wrt nonces.

It shouldn't be a problem, since nodes will be out of sync very short amount of time ~HIGHEST_LATENCY between pair of nodes and after that they should be able to connect, but anyway I like your proposal, will use 1000 instead and then there shouldn't be any problems between honest nodes ever.

@mfornet mfornet changed the base branch from network-pytest to master July 23, 2020 20:15
@mfornet mfornet removed the automerge label Jul 24, 2020
mfornet added 3 commits July 29, 2020 12:26
On Hanndshake peers checked to larger nonce
than previously known nonce to them, but they were not
checking and controlling larger nonce, hence accepting
every edge as long as the nonce was increasing. While
this is not fundamentally wrong it can be abused,
provoking overflow and eventually crashing the node.

Test plan
=========
This behavior was created in
- tests/spec/network/controlled_edge_nonce

Now this test should pass
@codecov
Copy link

codecov bot commented Jul 29, 2020

Codecov Report

Merging #3013 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3013   +/-   ##
=======================================
  Coverage   87.59%   87.59%           
=======================================
  Files         212      212           
  Lines       41269    41269           
=======================================
  Hits        36151    36151           
  Misses       5118     5118           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 13aa111...b81b90d. Read the comment docs.

@nearprotocol-bulldozer nearprotocol-bulldozer bot merged commit 6196ca7 into master Jul 29, 2020
@nearprotocol-bulldozer nearprotocol-bulldozer bot deleted the fix-large-nonce branch July 29, 2020 22:39
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