Skip to content

Conversation

@theuni
Copy link
Member

@theuni theuni commented Apr 10, 2017

As discussed in #10143.

  • Explicitly define NodeId's size as an int64_t. This keeps the range uniform so that it may be exposed to external APIs. Signed ints are allowed in order to represent special values.

  • 
    

Edit: as per the discussion below, only the int64_t change is needed.

@laanwj
Copy link
Member

laanwj commented Apr 11, 2017

I'm a bit ambivalent about going to 64 bit ints for the node id. I think it is a good temporary workaround for the wrap-around problem, but as you do want to handle wrapping, it seems a double measure. At the least please add a regression test for the wrapping code, as with 64 bits is so unlikely to ever trigger that the code will rot.

@gmaxwell
Copy link
Contributor

We could take a tip from the linux kernel counter handling and cause it to immediately wrap shortly after start by starting shortly below the wrap point, but esp with 64-bit IDs, the really long IDs would be kind of obnoxious. (also this wouldn't test the skipping code)

src/net.cpp Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Not -1? (or =0 and having the ++ in an else?) Why should it fail to reconsider reusing 0?

Copy link
Contributor

@gmaxwell gmaxwell Apr 11, 2017

Choose a reason for hiding this comment

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

The theoretical infinite loop is perhaps unfortunate, perhaps there should be an assert if size of the set is => max. (the reason for doing that would be more obvious if you imagine someone deciding to reduce the id to a s16 since its more than enough for current connections. :) )... or an exception.

Copy link
Member Author

@theuni theuni Apr 11, 2017

Choose a reason for hiding this comment

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

Thanks, I'll address both of those.
Edit: No need to address these if we're not going to worry about wrapping.

@jnewbery
Copy link
Contributor

jnewbery commented Apr 11, 2017

utACK 17c93bf4f6cdf259c735becffd2e319ecc222dd4 , although I'd prefer NodeID to by a uint32_t

EDIT: I'd prefer either using a uint32_t with this wrapping logic or a uint64_t without the new logic. Perhaps just add an assert in GetNewNodeId that we haven't reached std::numeric_limits::max().

@TheBlueMatt
Copy link
Contributor

I'd kinda prefer we /just/ switch it to a int64_t and drop all the wrap logic. With a 64-bit ID you'd need billions of connections per second for years.

@sipa
Copy link
Member

sipa commented Apr 11, 2017

Agree with @TheBlueMatt.

With a 64-bit ID you'd need billions of connections per second for years.

585 years of 1 billion connections per second. I think that's sufficient.

@theuni
Copy link
Member Author

theuni commented Apr 11, 2017

Hmm.

This originally switched to int32_t and addressed the wrapping as a non-theoretical problem. @TheBlueMatt pointed out that it may be possible that a user could mistakenly assume that the post-wrap nodeid "0" today is the same nodeid "0" that was connected 3 months ago, and take an action on the wrong node. Bumping to an int64_t solves that, so it seemed like a reasonable change.

Thinking about this again after that change, yea, I suppose there's now no need to worry about wrapping at all.

This should make occurances of NodeId wrapping essentially impossible for
real-world usage.
@theuni
Copy link
Member Author

theuni commented Apr 12, 2017

Updated after discussion here.

@TheBlueMatt
Copy link
Contributor

utACK c851be4

@jnewbery
Copy link
Contributor

Looks good. ACK c851be4

Did you consider asserting in GetNewNodeID():

    assert(nLastNodeId.load() < std::numeric_limits<int64_t>::max());

@jtimon
Copy link
Contributor

jtimon commented Apr 12, 2017

utACK c851be4

@laanwj
Copy link
Member

laanwj commented Apr 13, 2017

585 years of 1 billion connections per second. I think that's sufficient.

Yes, restarting your node every century at least is a good precaution in any case.

Some JSON implementations will start to lose precision at 52 bits (due to using doubles for numbers). But not worried about that here.

utACK c851be4 (also for 0.14)

@laanwj laanwj added this to the 0.14.1 milestone Apr 13, 2017
@laanwj laanwj merged commit c851be4 into bitcoin:master Apr 13, 2017
laanwj added a commit that referenced this pull request Apr 13, 2017
c851be4 net: define NodeId as an int64_t (Cory Fields)

Tree-SHA512: 2ccc931cfcdc555313b9434d8de2f6cea759b31891212ca62f962208f60157d4fc593010e3ca61265d1a20d6f78c6ca79103600b85df77983d5509d192875b96
laanwj pushed a commit that referenced this pull request Apr 14, 2017
This should make occurances of NodeId wrapping essentially impossible for
real-world usage.

Github-Pull: #10176
Rebased-From: c851be4
codablock pushed a commit to codablock/dash that referenced this pull request Jan 26, 2018
c851be4 net: define NodeId as an int64_t (Cory Fields)

Tree-SHA512: 2ccc931cfcdc555313b9434d8de2f6cea759b31891212ca62f962208f60157d4fc593010e3ca61265d1a20d6f78c6ca79103600b85df77983d5509d192875b96
andvgal pushed a commit to energicryptocurrency/gen2-energi that referenced this pull request Jan 6, 2019
c851be4 net: define NodeId as an int64_t (Cory Fields)

Tree-SHA512: 2ccc931cfcdc555313b9434d8de2f6cea759b31891212ca62f962208f60157d4fc593010e3ca61265d1a20d6f78c6ca79103600b85df77983d5509d192875b96
CryptoCentric pushed a commit to absolute-community/absolute that referenced this pull request Feb 27, 2019
c851be4 net: define NodeId as an int64_t (Cory Fields)

Tree-SHA512: 2ccc931cfcdc555313b9434d8de2f6cea759b31891212ca62f962208f60157d4fc593010e3ca61265d1a20d6f78c6ca79103600b85df77983d5509d192875b96
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants