-
Notifications
You must be signed in to change notification settings - Fork 135
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
refactor: perform local db content lookup at OverlayService level #1637
refactor: perform local db content lookup at OverlayService level #1637
Conversation
// Lookup content locally before querying the network. | ||
if let Ok(Some(content)) = self.store.read().get(&target) { | ||
let local_enr = self.local_enr(); | ||
let mut query_trace = QueryTrace::new(&local_enr, target.content_id().into()); | ||
query_trace.node_responded_with_content(&local_enr); | ||
query_trace.content_validated(local_enr.into()); | ||
if let Some(callback) = callback { | ||
let _ = callback.send(Ok(( | ||
RawContentValue::from(content), | ||
false, | ||
Some(query_trace), | ||
))); | ||
return; | ||
} else { | ||
warn!("Local content found but no callback to return it to overlay protocol, continuing with network query & ignoring local content."); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Lookup content locally before querying the network. | |
if let Ok(Some(content)) = self.store.read().get(&target) { | |
let local_enr = self.local_enr(); | |
let mut query_trace = QueryTrace::new(&local_enr, target.content_id().into()); | |
query_trace.node_responded_with_content(&local_enr); | |
query_trace.content_validated(local_enr.into()); | |
if let Some(callback) = callback { | |
let _ = callback.send(Ok(( | |
RawContentValue::from(content), | |
false, | |
Some(query_trace), | |
))); | |
return; | |
} else { | |
warn!("Local content found but no callback to return it to overlay protocol, continuing with network query & ignoring local content."); | |
} | |
} | |
// Lookup content locally before querying the network. | |
if let Ok(Some(content)) = self.store.read().get(&target) { | |
let local_enr = self.local_enr(); | |
let mut query_trace = QueryTrace::new(&local_enr, target.content_id().into()); | |
query_trace.node_responded_with_content(&local_enr); | |
query_trace.content_validated(local_enr.into()); | |
if let Some(callback) = callback { | |
let _ = callback.send(Ok(( | |
RawContentValue::from(content), | |
false, | |
Some(query_trace), | |
))); | |
return; | |
} else { | |
warn!("Local content found but no callback to return it to overlay protocol, continuing with network query & ignoring local content."); | |
} | |
} |
I think we should remove the Option on the callback, the option is only used for testing, which tastes weird, also we should remove this warn!
and check if there is a channel, before checking local storage as this is an expensive operation.
But as I said before we should just remove the option, I don't think we should have special arguments just for writing unit tests.
It doesn't make sense to do a storage lookup, if we aren't going to use it.
@@ -2369,9 +2358,27 @@ impl< | |||
target: TContentKey, | |||
callback: Option<oneshot::Sender<RecursiveFindContentResult>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
callback: Option<oneshot::Sender<RecursiveFindContentResult>>, | |
callback: oneshot::Sender<RecursiveFindContentResult>, |
I don't think this should be an option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this PR looks very good
What was wrong?
Fixes #1329
This feature is needed to more efficiently perform beacon sync inside hive tests.
How was it fixed?
OverlayService
level rather than atJsonRpc
level.To-Do