mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 01:41:09 +00:00
refactor View to include finalized_number (#2128)
* refactor View to include finalized_number * guide: update the NetworkBridge on BlockFinalized * av-store: fix the tests * actually fix tests * grumbles * ignore macro doctest * use Hash::repeat_bytes more consistently * broadcast empty leaves updates as well * fix issuing view updates on empty leaves updates
This commit is contained in:
@@ -538,8 +538,8 @@ where
|
||||
process_block_activated(ctx, &subsystem.inner, activated, &subsystem.metrics).await?;
|
||||
}
|
||||
}
|
||||
FromOverseer::Signal(OverseerSignal::BlockFinalized(hash)) => {
|
||||
process_block_finalized(subsystem, ctx, &subsystem.inner, hash).await?;
|
||||
FromOverseer::Signal(OverseerSignal::BlockFinalized(_hash, number)) => {
|
||||
process_block_finalized(subsystem, &subsystem.inner, number).await?;
|
||||
}
|
||||
FromOverseer::Communication { msg } => {
|
||||
process_message(subsystem, ctx, msg).await?;
|
||||
@@ -564,20 +564,14 @@ where
|
||||
/// The state of data has to be changed from
|
||||
/// `CandidateState::Included` to `CandidateState::Finalized` and their pruning times have
|
||||
/// to be updated to `now` + keep_finalized_{block, chunk}_for`.
|
||||
#[tracing::instrument(level = "trace", skip(subsystem, ctx, db), fields(subsystem = LOG_TARGET))]
|
||||
async fn process_block_finalized<Context>(
|
||||
#[tracing::instrument(level = "trace", skip(subsystem, db), fields(subsystem = LOG_TARGET))]
|
||||
async fn process_block_finalized(
|
||||
subsystem: &AvailabilityStoreSubsystem,
|
||||
ctx: &mut Context,
|
||||
db: &Arc<dyn KeyValueDB>,
|
||||
hash: Hash,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
Context: SubsystemContext<Message=AvailabilityStoreMessage>
|
||||
{
|
||||
block_number: BlockNumber,
|
||||
) -> Result<(), Error> {
|
||||
let _timer = subsystem.metrics.time_process_block_finalized();
|
||||
|
||||
let block_number = get_block_number(ctx, hash).await?;
|
||||
|
||||
if let Some(mut pov_pruning) = pov_pruning(db) {
|
||||
// Since the records are sorted by time in which they need to be pruned and not by block
|
||||
// numbers we have to iterate through the whole collection here.
|
||||
|
||||
@@ -274,7 +274,7 @@ fn store_block_works() {
|
||||
let test_state = TestState::default();
|
||||
test_harness(test_state.pruning_config.clone(), store.clone(), |test_harness| async move {
|
||||
let TestHarness { mut virtual_overseer } = test_harness;
|
||||
let candidate_hash = CandidateHash(Hash::from([1; 32]));
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(1));
|
||||
let validator_index = 5;
|
||||
let n_validators = 10;
|
||||
|
||||
@@ -328,7 +328,7 @@ fn store_pov_and_query_chunk_works() {
|
||||
|
||||
test_harness(test_state.pruning_config.clone(), store.clone(), |test_harness| async move {
|
||||
let TestHarness { mut virtual_overseer } = test_harness;
|
||||
let candidate_hash = CandidateHash(Hash::from([1; 32]));
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(1));
|
||||
let n_validators = 10;
|
||||
|
||||
let pov = PoV {
|
||||
@@ -543,20 +543,9 @@ fn stored_data_kept_until_finalized() {
|
||||
|
||||
overseer_signal(
|
||||
&mut virtual_overseer,
|
||||
OverseerSignal::BlockFinalized(new_leaf)
|
||||
OverseerSignal::BlockFinalized(new_leaf, 10)
|
||||
).await;
|
||||
|
||||
assert_matches!(
|
||||
overseer_recv(&mut virtual_overseer).await,
|
||||
AllMessages::ChainApi(ChainApiMessage::BlockNumber(
|
||||
hash,
|
||||
tx,
|
||||
)) => {
|
||||
assert_eq!(hash, new_leaf);
|
||||
tx.send(Ok(Some(10))).unwrap();
|
||||
}
|
||||
);
|
||||
|
||||
// Wait for a half of the time finalized data should be available for
|
||||
Delay::new(test_state.pruning_config.keep_finalized_block_for / 2).await;
|
||||
|
||||
@@ -658,20 +647,9 @@ fn stored_chunk_kept_until_finalized() {
|
||||
|
||||
overseer_signal(
|
||||
&mut virtual_overseer,
|
||||
OverseerSignal::BlockFinalized(new_leaf)
|
||||
OverseerSignal::BlockFinalized(new_leaf, 10)
|
||||
).await;
|
||||
|
||||
assert_matches!(
|
||||
overseer_recv(&mut virtual_overseer).await,
|
||||
AllMessages::ChainApi(ChainApiMessage::BlockNumber(
|
||||
hash,
|
||||
tx,
|
||||
)) => {
|
||||
assert_eq!(hash, new_leaf);
|
||||
tx.send(Ok(Some(10))).unwrap();
|
||||
}
|
||||
);
|
||||
|
||||
// Wait for a half of the time finalized data should be available for
|
||||
Delay::new(test_state.pruning_config.keep_finalized_block_for / 2).await;
|
||||
|
||||
@@ -812,21 +790,9 @@ fn forkfullness_works() {
|
||||
|
||||
overseer_signal(
|
||||
&mut virtual_overseer,
|
||||
OverseerSignal::BlockFinalized(new_leaf_1)
|
||||
OverseerSignal::BlockFinalized(new_leaf_1, 5)
|
||||
).await;
|
||||
|
||||
assert_matches!(
|
||||
overseer_recv(&mut virtual_overseer).await,
|
||||
AllMessages::ChainApi(ChainApiMessage::BlockNumber(
|
||||
hash,
|
||||
tx,
|
||||
)) => {
|
||||
assert_eq!(hash, new_leaf_1);
|
||||
tx.send(Ok(Some(5))).unwrap();
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
// Data of both candidates should be still present in the DB.
|
||||
assert_eq!(
|
||||
query_available_data(&mut virtual_overseer, candidate_1_hash).await.unwrap(),
|
||||
|
||||
Reference in New Issue
Block a user