Skip to content

Portal Client: Add debug parameter to generate node id having a given prefix #3313

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

Merged
merged 4 commits into from
May 21, 2025

Conversation

bhartnett
Copy link
Contributor

@bhartnett bhartnett commented May 21, 2025

This debug parameter allows us to on startup generate a private key which has a node id matching the given prefix.

This will be useful for the portal bridge when we connect to multiple locally running portal clients. In order to get better coverage of the network we can use this parameter to start Nimbus Portal instances that are more uniformly distributed across the network.

For example if we want to run 8 nodes locally we can start them having the following prefixes:

  • 0x00
  • 0x20
  • 0x40
  • 0x60
  • 0x80
  • 0xA0
  • 0xC0
  • 0xE0

@bhartnett bhartnett requested a review from kdeme May 21, 2025 08:11
@bhartnett
Copy link
Contributor Author

When making this change, I've discovered a minor issue where when a private key is supplied on the command line then we don't write it out to the key file but the enr on disk does get updated. If the node previously was started without the the private key param then this leads to a problem where the key file and enr on disk are out of sync and then we get this error:

lientcolonObjectType_EEN25nimbus_portal_client_conf10PortalConfE
/home/user/development/status-im/nimbus-eth1/vendor/nim-eth/eth/p2p/discoveryv5/protocol.nim(1089) _ZN8protocol11newProtocolEN4keys10PrivateKeyE3OptIN3net9IpAddressEE3OptIN13nativesockets4PortEE3OptIN13nativesockets4PortEE9openArrayI5tupleI6string3seqI5uInt8EEE9openArrayIN3enr6RecordEE3OptIN3enr6RecordEEN13nativesockets4PortEN3net9IpAddressE4bool4boolN8protocol15DiscoveryConfigE3refIN12bearssl_rand15HmacDrbgContextEE.constprop.0
/home/user/development/status-im/nimbus-eth1/vendor/nim-results/results.nim(946) _ZN7results6expectE6ResultI4void7cstringE6string
/home/user/development/status-im/nimbus-eth1/vendor/nim-results/results.nim(433) _ZN7results17raiseResultDefectE6string7cstring
/home/user/development/status-im/nimbus-eth1/vendor/nimbus-build-system/vendor/Nim/lib/system/excpt.nim(349) _ZN6system18rawWriteStackTraceE3varI3seqIN6system15StackTraceEntryEEE
/home/user/development/status-im/nimbus-eth1/vendor/nimbus-build-system/vendor/Nim/lib/system/stacktraces.nim(62) _ZN11stacktraces30auxWriteStackTraceWithOverrideE3varI3seqIN6system15StackTraceEntryEEE
Error: unhandled exception: Record within size limits and correct key: Public key does not correspond with given private key [ResultDefect]

If we no longer write the ENR to disk then this problem will likely be solved. One more reason to do that change.

Copy link
Contributor

@kdeme kdeme left a comment

Choose a reason for hiding this comment

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

Would it not make more sense to add this NodeId prefix option as something that runs only on first start for the usual networkKeyFile option? So basically, under the condition that the network key file does not exist yet, and else it doesn't do anything.

When using this to set up a few nodes for a bridge it would be better for this generation to happen only once?

@bhartnett
Copy link
Contributor Author

Would it not make more sense to add this NodeId prefix option as something that runs only on first start for the usual networkKeyFile option? So basically, under the condition that the network key file does not exist yet, and else it doesn't do anything.

When using this to set up a few nodes for a bridge it would be better for this generation to happen only once?

Yes I agree. I'll change it to work this way.

@bhartnett bhartnett requested a review from kdeme May 21, 2025 13:16
@bhartnett bhartnett merged commit db4ded3 into master May 21, 2025
9 of 10 checks passed
@bhartnett bhartnett deleted the portal-generate-nodeId-with-prefix branch May 21, 2025 15:02
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.

2 participants