Skip to content

Add getNodeRecordBuckets, addNodeRecord, and deleteNode to DiscoverySystem#188

Merged
Matilda-Clerke merged 11 commits intoConsensys:masterfrom
Matilda-Clerke:186-samba-support-changes
Apr 30, 2025
Merged

Add getNodeRecordBuckets, addNodeRecord, and deleteNode to DiscoverySystem#188
Matilda-Clerke merged 11 commits intoConsensys:masterfrom
Matilda-Clerke:186-samba-support-changes

Conversation

@Matilda-Clerke
Copy link
Copy Markdown
Contributor

Add some methods to aid in the development of the Samba portal client library.

#186

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 15, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Matilda-Clerke
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Apr 15, 2025
Copy link
Copy Markdown

@garyschulte garyschulte left a comment

Choose a reason for hiding this comment

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

Open question about explicit add/delete. If we were to run plugin code in the same process space it might pose a risk to allow modifying discovery system.

Also, seems like there is a broken (or flaky) integration test

Comment thread src/main/java/org/ethereum/beacon/discovery/DiscoverySystem.java Outdated
@Matilda-Clerke
Copy link
Copy Markdown
Contributor Author

Thanks Gary, I'll hold off on merging this until the Teku guys have a chance to take a look too. They're all on leave this week!

Comment thread src/main/java/org/ethereum/beacon/discovery/DiscoverySystem.java Outdated
Copy link
Copy Markdown

@meldsun0 meldsun0 left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread src/main/java/org/ethereum/beacon/discovery/DiscoverySystemBuilder.java Outdated
Copy link
Copy Markdown
Contributor

@Nashatyrev Nashatyrev left a comment

Choose a reason for hiding this comment

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

LGTM, just a minor comment

Comment thread src/main/java/org/ethereum/beacon/discovery/DiscoverySystem.java Outdated
Comment thread src/main/java/org/ethereum/beacon/discovery/DiscoverySystemBuilder.java Outdated
Comment on lines +15 to +22
void addNodeRecord(NodeRecord nodeRecord);

/**
* Deletes the NodeRecord identified by nodeId from the routing table
*
* @param nodeId The node ID to be deleted from the routing table
*/
void deleteNode(Bytes nodeId);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just an idea: I wonder if users of this mutable interface want some feedback on the operation they request? e.g. should we return a bool to indicate a successful operation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think it's required for Samba's usecase and it can be added later if desired, so I'll leave it for now.

Copy link
Copy Markdown

@pinges pinges left a comment

Choose a reason for hiding this comment

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

LGTM, just wanting to understand why these methods need to be synchronized (I know, it wasn't you who started it), and two suggestions for method names.

Comment thread src/main/java/org/ethereum/beacon/discovery/MutableDiscoverySystem.java Outdated
return getNode(nodeId).isPresent();
}

public synchronized List<List<NodeRecord>> getNodeRecordBuckets() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not sure I like this name. We are not returning the buckets, we are returning node records from all buckets. Maybe a simple name like getNodeRecords() is better?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I included the words buckets because each sub list is a list of node records from a bucket. I'm not sure getNodeRecords conveys quite the same meaning.

Personally, I don't understand why node records are organised like that, but it seems important.

@@ -143,4 +144,15 @@ public synchronized Optional<NodeRecord> getNode(final Bytes nodeId) {
public synchronized boolean containsNode(final Bytes nodeId) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't understand why these methods are synchronized. E.g. containsNode is always just for a certain point in time. The node record could be deleted just after leaving the synchronized method. Or the node could be added just after we returned false.
Same for the other methods.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I assume it's from an abundance of caution in a system intended to be used in a multi-threaded environment. Perhaps it would be good to overhaul it with ReentractReadWriteLock instead. It could increase performance if the discovery system is used frequently in multiple threads.

@Matilda-Clerke Matilda-Clerke merged commit b259700 into Consensys:master Apr 30, 2025
3 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants