Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

refactor! clean up ContentInfo type, remove unexpected paths #1528

Merged
merged 3 commits into from
Oct 19, 2024

Conversation

KolbyML
Copy link
Member

@KolbyML KolbyML commented Oct 14, 2024

What was wrong?

fixes #1526 (comment)

Basically the ContentInfo type we were using for our FindContent and GetContent RPC endpoints were leaking information implementation details not related to the endpoints

How was it fixed?

Split ContentInfo into

  • FindContentInfo
  • GetContentInfo

and only expose the datatypes specified in the portal-network-specs json-rpc specification

@KolbyML KolbyML marked this pull request as ready for review October 14, 2024 21:00
@KolbyML KolbyML self-assigned this Oct 14, 2024
@morph-dev
Copy link
Collaborator

Since this is somewhat related to changes in #1526, I will review if once that one is merged.

Alternatively, if you rebase this one on top of #1526 (as separate commit), I can take a look.

@KolbyML
Copy link
Member Author

KolbyML commented Oct 16, 2024

Since this is somewhat related to changes in #1526, I will review if once that one is merged.

Alternatively, if you rebase this one on top of #1526 (as separate commit), I can take a look.

rebased

@carver
Copy link
Collaborator

carver commented Oct 16, 2024

nit since it's a breaking change, it should use a ! instead of : to match the conventional commit standard.

Also, it would be good to get that breaking change updated in glados as soon as possible (and Hive, but I assume that was already on your mind).

Copy link
Collaborator

@morph-dev morph-dev left a comment

Choose a reason for hiding this comment

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

Looks mostly ok, except that changes in src/bin/poll_latest.rs. See comment there.

@@ -49,9 +49,7 @@ pub struct TraceGossipInfo {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: The documentation should be updated (it's not longer used for GetContent)

pub utp_transfer: bool,
}

/// Parsed response for TraceRecursiveFindContent endpoint
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Isn't this TraceGetContent now?

@@ -176,7 +176,7 @@ impl Era1Bridge {
let hunter_threshold = (content_keys_to_sample.len() as u64 * threshold / 100) as usize;
for content_key in content_keys_to_sample {
let result = self.portal_client.get_content(content_key.clone()).await;
if let Ok(ContentInfo::Content { .. }) = result {
if let Ok(GetContentInfo { .. }) = result {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Because GetContentInfo is not enum (as this result type used to be), I believe that this check can be simplified to:

if result.is_ok() {

Also in other places below.

@@ -61,7 +61,7 @@ async fn beacon_trace_gossip(
}
// if not, make rfc request to see if data is available on network
let result = BeaconNetworkApiClient::get_content(&client, content_key.clone()).await;
if let Ok(ContentInfo::Content { .. }) = result {
if let Ok(GetContentInfo { .. }) = result {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, and below.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that many of changes in this file are not needed. While it does preserve original functionality, I think original implementation was wrong (because it wasn't handling errors correctly).

Meaning, if GetContent fails (content not available) it should keep retrying, right?
So timeout and backoff should still be used.

In my opinion, in audit_content_key we should have something like:

while Instant::now() - timestamp < timeout {
    match client.get_content(content_key.clone()).await {
        Ok(_) => return Ok(Instant::now()),
        _ => {
            attempts += 1;
            let sleep_time = match backoff {
                Backoff::Exponential => attempts * 2,
                Backoff::Linear(delay) => delay,
            };
            sleep(Duration::from_secs(sleep_time)).await;
        }
    }
}

which is closer to the original implementation.


Otherwise, if you think new implementation is correct, than you should cleanup more of this file (remove Backoff, update documentation on how to run it, etc).

Copy link
Member Author

Choose a reason for hiding this comment

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

The new implementation is the same as the old implementation, but I agree that your example is most likely what was originally intended

@KolbyML KolbyML changed the title refactor: clean up ContentInfo type, remove unexpected paths refactor! clean up ContentInfo type, remove unexpected paths Oct 17, 2024
@@ -368,7 +368,7 @@ impl Era1Bridge {
let header_hash = block_tuple.header.header.hash();
let header_content_key = HistoryContentKey::new_block_header_by_hash(header_hash);
let header_content_info = portal_client.get_content(header_content_key.clone()).await;
if let Ok(ContentInfo::Content { .. }) = header_content_info {
if let Ok(GetContentInfo { .. }) = header_content_info {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: this could also be header_content_info.is_ok().

Also in 3 more places in this file below.

pub enum ContentInfo {
#[serde(rename_all = "camelCase")]
ConnectionId { connection_id: u16 },
pub enum FindContentInfo {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The documentation is still not updated.

@KolbyML KolbyML merged commit 4b212d4 into ethereum:master Oct 19, 2024
9 checks passed
@carver
Copy link
Collaborator

carver commented Oct 22, 2024

nit since it's a breaking change, it should use a ! instead of : to match the conventional commit standard.

BTW, sorry I misspoke about the conventional commits standard. For next time: it is supposed to be to add a ! before the :. Like: refactor!: clean up...

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants