Skip to content

Commit a7916a0

Browse files
committed
Switch to generic type parameter for content key when building ACCEPT response.
1 parent e7ece03 commit a7916a0

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

trin-core/src/portalnet/overlay_service.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
metrics::OverlayMetrics,
77
storage::PortalStorage,
88
types::{
9-
content_key::{HistoryContentKey, OverlayContentKey},
9+
content_key::OverlayContentKey,
1010
messages::{
1111
Accept, ByteList, Content, CustomPayload, FindContent, FindNodes, Message, Nodes,
1212
Offer, Ping, Pong, ProtocolId, Request, Response, SszEnr,
@@ -643,7 +643,7 @@ impl<TContentKey: OverlayContentKey + Send, TMetric: Metric + Send>
643643
}
644644
}
645645

646-
/// Attempts to build a `Accept` response for an `Offer` request.
646+
/// Attempts to build an `Accept` response for an `Offer` request.
647647
fn handle_offer(&self, request: Offer) -> Result<Accept, OverlayRequestError> {
648648
self.metrics
649649
.as_ref()
@@ -659,21 +659,25 @@ impl<TContentKey: OverlayContentKey + Send, TMetric: Metric + Send>
659659
let accept_keys = request.content_keys.clone();
660660

661661
for (i, key) in request.content_keys.into_iter().enumerate() {
662-
// TODO: This will not work when we receive state Offer message with state content keys
663-
// we need to refactor it in a way to get access to the protocol id in this method
664-
let key = HistoryContentKey::try_from(key)
665-
.map_err(|err| OverlayRequestError::AcceptError(err.to_string()))?;
662+
let key = (TContentKey::try_from)(key).map_err(|_| {
663+
OverlayRequestError::AcceptError(format!(
664+
"Unable to build content key from OFFER request."
665+
))
666+
})?;
667+
666668
requested_keys
667669
.set(
668670
i,
669-
self.storage.read().should_store(&key).map_err(|_| {
670-
OverlayRequestError::AcceptError(
671-
"Portal storage error: unable to check content availability".to_owned(),
672-
)
671+
self.storage.read().should_store(&key).map_err(|err| {
672+
OverlayRequestError::AcceptError(format!(
673+
"Unable to check content availability: {err}"
674+
))
673675
})?,
674676
)
675-
.map_err(|_| {
676-
OverlayRequestError::AcceptError("Unable to set requested keys bits".to_owned())
677+
.map_err(|err| {
678+
OverlayRequestError::AcceptError(format!(
679+
"Unable to set requested keys bits: {err:?}"
680+
))
677681
})?;
678682
}
679683

0 commit comments

Comments
 (0)