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

Reimplement EthereumNodeRecord for DNS discovery #7989

Merged
merged 14 commits into from
Jan 7, 2025

Conversation

usmansaleem
Copy link
Member

PR description

Reimplement EthereumNodeRecord to avoid dependency on tuweni-devp2p

Fixed Issue(s)

Fixes #7980

Thanks for sending a pull request! Have you done the following?

  • Checked out our contribution guidelines?
  • Considered documentation and added the doc-change-required label to this PR if updates are required.
  • Considered the changelog and included an update if required.
  • For database changes (e.g. KeyValueSegmentIdentifier) considered compatibility and performed forwards and backwards compatibility tests

Locally, you can run these tests to catch failures early:

  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests

@usmansaleem usmansaleem self-assigned this Dec 5, 2024
class EthereumNodeRecordTest {

@Test
void buildFromRLP() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

worth adding some tests for error handling? udp / tcp port values?

Copy link
Member Author

Choose a reason for hiding this comment

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

updated unit test and added additional test to cover error conditions.

while (!input.isEndOfCurrentList()) {
var key = new String(input.readBytes().toArrayUnsafe(), StandardCharsets.UTF_8);
if (input.nextIsList()) {
// skip list as we currently don't need and support complex structures
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// skip list as we currently don't need and support complex structures
// skip list as we currently don't need to support complex structures

Copy link
Member Author

Choose a reason for hiding this comment

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

modified this slightly.

Copy link

github-actions bot commented Jan 5, 2025

This pr is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the Stale label Jan 5, 2025
@usmansaleem usmansaleem removed the Stale label Jan 6, 2025
Copy link
Contributor

@Matilda-Clerke Matilda-Clerke left a comment

Choose a reason for hiding this comment

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

LGTM assuming the code I commented on matches the functionality of the tuweni implementation

Comment on lines 56 to 58
var curve = SignatureAlgorithmFactory.getInstance().getCurve();
var ecPoint = curve.getCurve().decodePoint(keyBytes.toArrayUnsafe());
return Bytes.wrap(ecPoint.getEncoded(false)).slice(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this equivalent to what the tuweni implementation does?

Copy link
Member Author

Choose a reason for hiding this comment

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

correct, the first byte is the encoding prefix i.e. 0x03 for compressed and 0x04 for decompressed public key I recall. We need the uncompressed public key without this prefix.

Signed-off-by: Usman Saleem <[email protected]>
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
EthereumNodeRecord that = (EthereumNodeRecord) o;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

    if (!(o instanceof EthereumNodeRecord that)) return false;

Copy link
Contributor

Choose a reason for hiding this comment

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

I would also encourage putting brackets to follow same code style as other code

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, regenerated equals/hashcode 👍🏼

@usmansaleem usmansaleem merged commit 01126c0 into hyperledger:main Jan 7, 2025
43 checks passed
@usmansaleem usmansaleem deleted the tuweni_devp2p branch January 7, 2025 03:14
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.

Remove tuweni-devp2p dependency
4 participants