backend: Capture all events from the follow subscription

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2024-01-09 14:31:35 +02:00
parent 8d0d17c810
commit fb0e2c75ea
+45 -3
View File
@@ -441,6 +441,7 @@ impl<T: Config + Send + Sync + 'static> Backend<T> for UnstableBackend<T> {
enum SeenBlock<Ref> {
New((Ref, Ref)),
Finalized(Vec<Ref>),
Other(OtherEvent),
}
#[derive(Debug)]
enum SeenBlockMarker {
@@ -448,6 +449,19 @@ impl<T: Config + Send + Sync + 'static> Backend<T> for UnstableBackend<T> {
Finalized,
}
#[derive(Debug)]
enum OtherEvent {
BestBlockChanged,
OperationBodyDone,
OperationCallDone,
OperationStorageItems,
OperationWaitingForContinue,
OperationStorageDone,
OperationInaccessible,
OperationError,
Stop,
}
static mut FIN_BLOCK: Option<String> = None;
unsafe { FIN_BLOCK = None };
@@ -475,10 +489,33 @@ impl<T: Config + Send + Sync + 'static> Backend<T> for UnstableBackend<T> {
unsafe {
PRUNED = Some(format!(" pruned {:?} {:?}", PRUNED, ev.pruned_block_hashes));
}
Some(SeenBlock::Finalized(ev.finalized_block_hashes))
}
_ => None,
FollowEvent::BestBlockChanged(_) => {
Some(SeenBlock::Other(OtherEvent::BestBlockChanged))
}
FollowEvent::OperationBodyDone(_) => {
Some(SeenBlock::Other(OtherEvent::OperationBodyDone))
}
FollowEvent::OperationCallDone(_) => {
Some(SeenBlock::Other(OtherEvent::OperationCallDone))
}
FollowEvent::OperationStorageItems(_) => {
Some(SeenBlock::Other(OtherEvent::OperationStorageItems))
}
FollowEvent::OperationWaitingForContinue(_) => {
Some(SeenBlock::Other(OtherEvent::OperationWaitingForContinue))
}
FollowEvent::OperationStorageDone(_) => {
Some(SeenBlock::Other(OtherEvent::OperationStorageDone))
}
FollowEvent::OperationInaccessible(_) => {
Some(SeenBlock::Other(OtherEvent::OperationInaccessible))
}
FollowEvent::OperationError(_) => {
Some(SeenBlock::Other(OtherEvent::OperationError))
}
FollowEvent::Stop => Some(SeenBlock::Other(OtherEvent::Stop)),
})
});
@@ -489,6 +526,7 @@ impl<T: Config + Send + Sync + 'static> Backend<T> for UnstableBackend<T> {
.await?;
let mut seen_blocks = HashMap::new();
let mut seen_other = Vec::new();
let mut done = false;
// If we see the finalized event, we start waiting until we find a finalized block that
@@ -507,8 +545,9 @@ impl<T: Config + Send + Sync + 'static> Backend<T> for UnstableBackend<T> {
println!("Pruned block {:?}", unsafe { &PRUNED });
println!("MemLog: {:#?}", mem_log);
println!("SeenBlocksLog: {:#?}", seen_blocks);
println!("SeenOther: {:#?}", seen_other);
panic!("{:#?} {:#?}", mem_log, seen_blocks);
panic!("{:#?} {:#?} {:#?}", mem_log, seen_blocks, seen_other);
}
// Bail early if no more tx events; we don't want to keep polling for pinned blocks.
@@ -552,6 +591,9 @@ impl<T: Config + Send + Sync + 'static> Backend<T> for UnstableBackend<T> {
// .0 = SeenBlockMarker::Finalized;
}
}
SeenBlock::Other(other) => {
seen_other.push((now.elapsed(), other));
}
}
continue;
}