mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 07:01:05 +00:00
Prefer fetching small PoVs from backing group (#7173)
* impl QueryChunkSize Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * QueryChunkSize message Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * enable fetching from backing group for small pov Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * review feedback Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Refactor `bypass_availability_store` Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * review feedback Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> --------- Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
This commit is contained in:
@@ -1052,6 +1052,25 @@ fn process_message(
|
||||
let _ =
|
||||
tx.send(load_chunk(&subsystem.db, &subsystem.config, &candidate, validator_index)?);
|
||||
},
|
||||
AvailabilityStoreMessage::QueryChunkSize(candidate, tx) => {
|
||||
let meta = load_meta(&subsystem.db, &subsystem.config, &candidate)?;
|
||||
|
||||
let validator_index = meta.map_or(None, |meta| meta.chunks_stored.first_one());
|
||||
|
||||
let maybe_chunk_size = if let Some(validator_index) = validator_index {
|
||||
load_chunk(
|
||||
&subsystem.db,
|
||||
&subsystem.config,
|
||||
&candidate,
|
||||
ValidatorIndex(validator_index as u32),
|
||||
)?
|
||||
.map(|erasure_chunk| erasure_chunk.chunk.len())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let _ = tx.send(maybe_chunk_size);
|
||||
},
|
||||
AvailabilityStoreMessage::QueryAllChunks(candidate, tx) => {
|
||||
match load_meta(&subsystem.db, &subsystem.config, &candidate)? {
|
||||
None => {
|
||||
|
||||
@@ -1153,3 +1153,51 @@ async fn import_leaf(
|
||||
|
||||
new_leaf
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn query_chunk_size_works() {
|
||||
let store = test_store();
|
||||
|
||||
test_harness(TestState::default(), store.clone(), |mut virtual_overseer| async move {
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(33));
|
||||
let validator_index = ValidatorIndex(5);
|
||||
let n_validators = 10;
|
||||
|
||||
let chunk = ErasureChunk {
|
||||
chunk: vec![1, 2, 3],
|
||||
index: validator_index,
|
||||
proof: Proof::try_from(vec![vec![3, 4, 5]]).unwrap(),
|
||||
};
|
||||
|
||||
// Ensure an entry already exists. In reality this would come from watching
|
||||
// chain events.
|
||||
with_tx(&store, |tx| {
|
||||
super::write_meta(
|
||||
tx,
|
||||
&TEST_CONFIG,
|
||||
&candidate_hash,
|
||||
&CandidateMeta {
|
||||
data_available: false,
|
||||
chunks_stored: bitvec::bitvec![u8, BitOrderLsb0; 0; n_validators],
|
||||
state: State::Unavailable(BETimestamp(0)),
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
let chunk_msg =
|
||||
AvailabilityStoreMessage::StoreChunk { candidate_hash, chunk: chunk.clone(), tx };
|
||||
|
||||
overseer_send(&mut virtual_overseer, chunk_msg).await;
|
||||
assert_eq!(rx.await.unwrap(), Ok(()));
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let query_chunk_size = AvailabilityStoreMessage::QueryChunkSize(candidate_hash, tx);
|
||||
|
||||
overseer_send(&mut virtual_overseer, query_chunk_size).await;
|
||||
|
||||
assert_eq!(rx.await.unwrap().unwrap(), chunk.chunk.len());
|
||||
virtual_overseer
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user