-
Notifications
You must be signed in to change notification settings - Fork 134
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
feat: update portal_*Offer
to handle multiple pieces of content
#1507
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -509,13 +509,10 @@ where | |
pub async fn send_offer( | ||
&self, | ||
enr: Enr, | ||
content_key: RawContentKey, | ||
content_value: Vec<u8>, | ||
content_items: Vec<(RawContentKey, Vec<u8>)>, | ||
) -> Result<Accept, OverlayRequestError> { | ||
// Construct the request. | ||
let request = Request::PopulatedOffer(PopulatedOffer { | ||
content_items: vec![(content_key, content_value)], | ||
}); | ||
let request = Request::PopulatedOffer(PopulatedOffer { content_items }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion, check that number of content items is 1..=64 should happen here (in which case it should return In that case, it's probably not needed in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should move the request check to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason why I think it should be there is not because I want to avoid code duplication, but because this type of check should be at lower level. Reason being is that what if there is alternative call to this function (or is added in the future). Now that I think about it, we might want it at even lower level (e.g. right before sending offer request over network). Because poke, and gossip on deletion (and maybe some other mechanics) wouldn't have this check. But, regarding your point, it's fine to have it on upper level as well (and not make calls that we know would fail). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do have a check at the lower level https://github.com/ethereum/trin/blob/master/portalnet/src/gossip.rs#L103-L115 ... but i'd include an update in this pr to use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will update the code to use that const. I think it is fine if we have a lower and higher level check |
||
|
||
let direction = RequestDirection::Outgoing { | ||
destination: enr.clone(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,23 +179,35 @@ impl BeaconNetworkApiServer for BeaconNetworkApi { | |
Ok(proxy_to_subnet(&self.network, endpoint).await?) | ||
} | ||
|
||
/// Send an OFFER request with given ContentKey, to the designated peer and wait for a response. | ||
/// Does not store content locally. | ||
/// Send an OFFER request with given ContentItems, to the designated peer and wait for a | ||
/// response. Does not store content locally. | ||
/// Returns the content keys bitlist upon successful content transmission or empty bitlist | ||
/// receive. | ||
async fn offer( | ||
&self, | ||
enr: Enr, | ||
content_key: BeaconContentKey, | ||
content_value: RawContentValue, | ||
content_items: Vec<(BeaconContentKey, RawContentValue)>, | ||
) -> RpcResult<AcceptInfo> { | ||
let content_value = BeaconContentValue::decode(&content_key, &content_value) | ||
.map_err(RpcServeError::from)?; | ||
let endpoint = BeaconEndpoint::Offer(enr, content_key, content_value); | ||
if !(1..=64).contains(&content_items.len()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably define |
||
return Err(RpcServeError::Message(format!( | ||
"Invalid amount of content items: {}", | ||
content_items.len() | ||
)) | ||
.into()); | ||
} | ||
let content_items = content_items | ||
.into_iter() | ||
.map(|(key, value)| { | ||
BeaconContentValue::decode(&key, &value) | ||
.map(|value| (key, value)) | ||
.map_err(RpcServeError::from) | ||
}) | ||
.collect::<Result<Vec<_>, _>>()?; | ||
let endpoint = BeaconEndpoint::Offer(enr, content_items); | ||
Ok(proxy_to_subnet(&self.network, endpoint).await?) | ||
} | ||
|
||
/// Send an OFFER request with given ContentKey, to the designated peer. | ||
/// Send an OFFER request with given ContentItems, to the designated peer. | ||
/// Does not store the content locally. | ||
/// Returns trace info from the offer. | ||
async fn trace_offer( | ||
|
@@ -210,7 +222,7 @@ impl BeaconNetworkApiServer for BeaconNetworkApi { | |
Ok(proxy_to_subnet(&self.network, endpoint).await?) | ||
} | ||
|
||
/// Send an OFFER request with given ContentKeys, to the designated peer and wait for a | ||
/// Send an OFFER request with given ContentItemss, to the designated peer and wait for a | ||
/// response. Requires the content keys to be stored locally. | ||
/// Returns the content keys bitlist upon successful content transmission or empty bitlist | ||
/// receive. | ||
|
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.
Should we add test here as well?
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.
I will remove
WireOffer
thenOffer
will take it's place for tests which should be sufficient for test coverage