Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
VanBarbascu committed Feb 12, 2025
1 parent e913acf commit 3c20bb6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
19 changes: 17 additions & 2 deletions chain/network/src/test_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::sync::{Arc, Mutex};

use crate::client::{
BlockApproval, BlockHeadersRequest, BlockHeadersResponse, BlockRequest, BlockResponse,
ChunkEndorsementMessage, EpochSyncRequestMessage, EpochSyncResponseMessage, ProcessTxRequest,
ProcessTxResponse,
ChunkEndorsementMessage, EpochSyncRequestMessage, EpochSyncResponseMessage,
OptimisticBlockMessage, ProcessTxRequest, ProcessTxResponse,
};
use crate::shards_manager::ShardsManagerRequestFromNetwork;
use crate::state_witness::{
Expand Down Expand Up @@ -37,6 +37,7 @@ pub struct ClientSenderForTestLoopNetwork {
pub chunk_endorsement: AsyncSender<ChunkEndorsementMessage, ()>,
pub epoch_sync_request: Sender<EpochSyncRequestMessage>,
pub epoch_sync_response: Sender<EpochSyncResponseMessage>,
pub optimistic_block_receiver: Sender<OptimisticBlockMessage>,
}

#[derive(Clone, MultiSend, MultiSenderFrom)]
Expand Down Expand Up @@ -242,6 +243,20 @@ fn network_message_to_client_handler(
}
None
}
NetworkRequests::OptimisticBlock { optimistic_block } => {
let my_peer_id = shared_state.account_to_peer_id.get(&my_account_id).unwrap();
for account_id in shared_state.accounts() {
if account_id != &my_account_id {
let _ = shared_state.senders_for_account(account_id).client_sender.send(
OptimisticBlockMessage {
optimistic_block: optimistic_block.clone(),
from_peer: my_peer_id.clone(),
},
);
}
}
None
}
NetworkRequests::Approval { approval_message } => {
assert_ne!(
approval_message.target, my_account_id,
Expand Down
13 changes: 6 additions & 7 deletions integration-tests/src/test_loop/tests/optimistic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ fn test_optimistic_block() {
assert!(chain.optimistic_block_chunks.num_chunks() <= 3 * num_shards);
// There should be at least one optimistic block result in the cache.
assert!(chain.apply_chunk_results_cache.len() > 0);
// Optimistic block result should be used at least once.
assert!(
chain.apply_chunk_results_cache.hits() == chain.head().map_or(0, |t| t.height as usize)
);
// Optimistic block result should be used at every height.
// We do not process the genesis block nor the last block.
let expected_hits = chain.head().map_or(0, |t| t.height - 2);
assert!(chain.apply_chunk_results_cache.hits() >= (expected_hits as usize));

// Because there is no optimistic block distribution yet, there should
// be at least one miss for each shard.
assert!(chain.apply_chunk_results_cache.misses() == 0);
// Current logic queries cache multiple times. It is ok to see misses.
assert!(chain.apply_chunk_results_cache.misses() > 0);
}

env.shutdown_and_drain_remaining_events(Duration::seconds(20));
Expand Down

0 comments on commit 3c20bb6

Please sign in to comment.