Skip to content

Commit

Permalink
fix: small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
etherhood committed Dec 2, 2024
1 parent 5f05358 commit 376742e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 32 deletions.
5 changes: 1 addition & 4 deletions portalnet/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,7 @@ impl Discovery {
}
};

let response = self
.discv5
.talk_req(enr, protocol, request.to_vec())
.await?;
let response = self.discv5.talk_req(enr, protocol, request).await?;
Ok(Bytes::from(response))
}
}
Expand Down
10 changes: 3 additions & 7 deletions portalnet/src/overlay/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ impl<
// over the uTP stream.
let utp = Arc::clone(&self.utp_controller);
tokio::spawn(async move {
utp.accept_outbound_stream(cid, content.as_ref()).await;
utp.accept_outbound_stream(cid, &content).await;
drop(permit);
});

Expand Down Expand Up @@ -1342,11 +1342,7 @@ impl<
// which will be received in the main loop.
tokio::spawn(async move {
let response = match discovery
.send_talk_req(
destination,
protocol,
Message::from(request).as_ssz_bytes().to_vec(),
)
.send_talk_req(destination, protocol, Message::from(request).as_ssz_bytes())
.await
{
Ok(talk_resp) => match Message::try_from(talk_resp.to_vec()) {
Expand Down Expand Up @@ -1604,7 +1600,7 @@ impl<
}
};
let result = utp_controller
.connect_outbound_stream(cid, content_payload.as_ref())
.connect_outbound_stream(cid, &content_payload)
.await;
if let Some(tx) = gossip_result_tx {
if result {
Expand Down
15 changes: 3 additions & 12 deletions trin-state/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ impl StateStorage {
pub mod test {
use std::path::PathBuf;

use alloy::hex::FromHex;
use anyhow::Result;
use ethportal_api::RawContentValue;
use rstest::rstest;
Expand Down Expand Up @@ -277,17 +276,9 @@ pub mod test {

for value in value.as_sequence().unwrap() {
result.push(ContentData {
key: StateContentKey::deserialize(value.get("content_key").unwrap())?,
store_value: RawContentValue::from_hex(
value.get("content_value_offer").unwrap().as_str().unwrap(),
)?,
lookup_value: RawContentValue::from_hex(
value
.get("content_value_retrieval")
.unwrap()
.as_str()
.unwrap(),
)?,
key: StateContentKey::deserialize(&value["content_key"])?,
store_value: RawContentValue::deserialize(&value["content_value_offer"])?,
lookup_value: RawContentValue::deserialize(&value["content_value_retrieval"])?,
});
}

Expand Down
16 changes: 7 additions & 9 deletions trin-storage/src/versioned/id_indexed_v1/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,16 +581,14 @@ mod tests {
config: &IdIndexedV1StoreConfig,
distance: u8,
) -> (IdentityContentKey, RawContentValue) {
let (key, value) =
generate_key_value_with_content_size(config, distance, CONTENT_DEFAULT_SIZE_BYTES);
(key, RawContentValue::copy_from_slice(value.as_ref()))
generate_key_value_with_content_size(config, distance, CONTENT_DEFAULT_SIZE_BYTES)
}

fn generate_key_value_with_content_size(
config: &IdIndexedV1StoreConfig,
distance: u8,
content_size: u64,
) -> (IdentityContentKey, Vec<u8>) {
) -> (IdentityContentKey, RawContentValue) {
let mut key = rand::random::<[u8; 32]>();
key[0] = config.node_id.raw()[0] ^ distance;
let key = IdentityContentKey::new(key);
Expand All @@ -599,7 +597,7 @@ mod tests {
panic!("Content size of at least 64 bytes is required (32 for id + 32 for key)")
}
let value = generate_random_bytes((content_size - 2 * 32) as usize);
(key, value)
(key, RawContentValue::copy_from_slice(value.as_ref()))
}

// Creates table and content at approximate middle distance (first byte distance is 0.80).
Expand Down Expand Up @@ -946,7 +944,7 @@ mod tests {
0,
rng.gen_range((CONTENT_DEFAULT_SIZE_BYTES)..(4 * CONTENT_DEFAULT_SIZE_BYTES)),
);
store.insert(&key, value.into())?;
store.insert(&key, value)?;
important_keys.push(key);
}

Expand All @@ -962,7 +960,7 @@ mod tests {
0xFF - i,
rng.gen_range((CONTENT_DEFAULT_SIZE_BYTES)..(3 * CONTENT_DEFAULT_SIZE_BYTES)),
);
store.insert(&key, value.into())?;
store.insert(&key, value)?;
assert!(store.usage_stats.total_entry_size_bytes <= config.storage_capacity_bytes);

assert!(store.radius() <= last_radius);
Expand Down Expand Up @@ -998,7 +996,7 @@ mod tests {
/* distance = */ 0,
store.config.storage_capacity_bytes / 2,
);
store.insert(&big_value_key, value.into())?;
store.insert(&big_value_key, value)?;
assert_eq!(store.usage_stats.entry_count, 51);
assert_eq!(
store.usage_stats.total_entry_size_bytes,
Expand Down Expand Up @@ -1094,7 +1092,7 @@ mod tests {
/* distance = */ 0,
store.config.storage_capacity_bytes / 2,
);
store.insert(&big_value_key, value.into())?;
store.insert(&big_value_key, value)?;

// big_value_key should still be stored
assert!(store.has_content(&big_value_key.content_id().into())?);
Expand Down

0 comments on commit 376742e

Please sign in to comment.