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

Continue the RecursiveFindContent query until the uTP transfer is complete and the content is validated #1395

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions ethportal-api/src/types/query_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type ContentId = [u8; 32];
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct QueryTrace {
/// Node ID from which the content was received. None if the content was not found.
/// Node ID from which the content was received. None if the content was not found & verified.
pub received_from: Option<NodeId>,
/// The local node.
pub origin: NodeId,
Expand Down Expand Up @@ -71,10 +71,13 @@ impl QueryTrace {
self.add_metadata(enr, true);
}

/// Mark the node that responded with the content, and when it was received.
/// Mark that a node responded with content, and when it was received.
/// Multiple nodes might respond, for a variety of reasons, including:
/// - they sent content that was later invalidated
/// - they claimed to have content for utp transfer, but disappeared before transmission
/// - they sent content too slowly, and we found it elsewhere
pub fn node_responded_with_content(&mut self, enr: &Enr) {
let node_id = enr.into();
self.received_from = Some(node_id);
let timestamp_u64 = QueryTrace::timestamp_millis_u64(self.started_at_ms);
self.responses.insert(
node_id,
Expand All @@ -86,6 +89,13 @@ impl QueryTrace {
self.add_metadata(enr, true);
}

/// Mark the node that sent the content that was finally verified.
pub fn content_validated(&mut self, node_id: NodeId) {
if self.received_from.is_none() {
self.received_from = Some(node_id);
}
}

/// Returns milliseconds since the time provided.
fn timestamp_millis_u64(since: SystemTime) -> u64 {
let timestamp_millis_u128 = SystemTime::now()
Expand Down Expand Up @@ -177,6 +187,7 @@ mod tests {
tracer.node_responded_with(&enr_a, vec![]);
tracer.node_responded_with(&enr_b, vec![&enr_d]);
tracer.node_responded_with_content(&enr_c);
tracer.content_validated(*node_id_c);

let origin_entry = tracer.responses.get(local_node_id).unwrap();

Expand Down
1 change: 1 addition & 0 deletions portalnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ alloy-primitives.workspace = true
anyhow.workspace = true
async-trait.workspace = true
bytes.workspace = true
crossbeam-channel = "0.5.13"
delay_map.workspace = true
directories.workspace = true
discv5.workspace = true
Expand Down
Loading
Loading