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

Fix failed deserialization of TransactionEvents in HttpKVStore #5308

Merged
merged 2 commits into from
Feb 14, 2025
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
3 changes: 1 addition & 2 deletions crates/iota-storage/src/http_key_value_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,7 @@ impl TransactionKeyValueStoreTrait for HttpKVStore {
.zip(digests.iter())
.map(map_fetch)
.map(|maybe_bytes| {
maybe_bytes
.and_then(|(bytes, key)| deser::<_, TransactionEvents>(&key, &bytes.slice(1..)))
maybe_bytes.and_then(|(bytes, key)| deser::<_, TransactionEvents>(&key, bytes))
})
.collect::<Vec<_>>())
}
Expand Down
27 changes: 24 additions & 3 deletions crates/iota-storage/tests/key_value_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ mod simtests {
use iota_macros::sim_test;
use iota_simulator::configs::constant_latency_ms;
use iota_storage::http_key_value_store::*;
use iota_types::event::Event;
use rustls::crypto::{CryptoProvider, ring};
use tracing::info;

Expand Down Expand Up @@ -420,6 +421,11 @@ mod simtests {
startup_receiver.changed().await.unwrap();
}

fn random_events() -> TransactionEvents {
let event = Event::random_for_testing();
TransactionEvents { data: vec![event] }
}

#[sim_test(config = "constant_latency_ms(250)")]
async fn test_multi_fetch() {
if CryptoProvider::get_default().is_none() {
Expand All @@ -429,21 +435,30 @@ mod simtests {
let mut data = HashMap::new();

let tx = random_tx();
let tx_digest = *tx.digest();
let random_digest = TransactionDigest::random();
let fx = random_fx();
let ev = random_events();

{
let bytes = bcs::to_bytes(&tx).unwrap();
assert_eq!(tx, bcs::from_bytes::<Transaction>(&bytes).unwrap());

let bytes = bcs::to_bytes(&fx).unwrap();
assert_eq!(fx, bcs::from_bytes::<TransactionEffects>(&bytes).unwrap());

let bytes = bcs::to_bytes(&ev).unwrap();
assert_eq!(ev, bcs::from_bytes::<TransactionEvents>(&bytes).unwrap());
}

data.insert(
format!("{}/tx", encode_digest(tx.digest())),
format!("{}/tx", encode_digest(&tx_digest)),
bcs::to_bytes(&tx).unwrap(),
);
data.insert(
format!("{}/evtx", encode_digest(&tx_digest)),
bcs::to_bytes(&ev).unwrap(),
);
data.insert(
format!("{}/fx", encode_digest(fx.transaction_digest())),
bcs::to_bytes(&fx).unwrap(),
Expand All @@ -461,12 +476,12 @@ mod simtests {
let store = HttpKVStore::new("http://10.10.10.10:8080").unwrap();

// send one request to warm up the client (and open a connection)
store.multi_get(&[*tx.digest()], &[]).await.unwrap();
store.multi_get(&[tx_digest], &[]).await.unwrap();

let start_time = Instant::now();
let result = store
.multi_get(
&[*tx.digest(), *random_tx().digest()],
&[tx_digest, *random_tx().digest()],
&[*fx.transaction_digest()],
)
.await
Expand All @@ -480,5 +495,11 @@ mod simtests {

let result = store.multi_get(&[random_digest], &[]).await.unwrap();
assert_eq!(result, (vec![None], vec![]));

let result = store
.multi_get_events_by_tx_digests(&[tx_digest])
.await
.unwrap();
assert_eq!(result, vec![Some(ev)]);
}
}
Loading