backend: Add timeline for new + finalized entries

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2024-01-09 13:51:24 +02:00
parent 81b5b1c315
commit 8d0d17c810
+19 -11
View File
@@ -525,20 +525,27 @@ impl<T: Config + Send + Sync + 'static> Backend<T> for UnstableBackend<T> {
// if finalized_hash.is_none() { // if finalized_hash.is_none() {
seen_blocks.insert( seen_blocks.insert(
block_ref.hash(), block_ref.hash(),
(SeenBlockMarker::New, block_ref, parent), (
SeenBlockMarker::New,
block_ref,
parent,
Some(now.elapsed()),
None,
),
); );
// } // }
} }
SeenBlock::Finalized(block_refs) => { SeenBlock::Finalized(block_refs) => {
for block_ref in block_refs { for block_ref in block_refs {
seen_blocks let entry = seen_blocks.entry(block_ref.hash()).or_insert((
.entry(block_ref.hash()) SeenBlockMarker::Finalized,
.or_insert(( block_ref.clone(),
SeenBlockMarker::Finalized, block_ref,
block_ref.clone(), None,
block_ref, Some(now.elapsed()),
)) ));
.0 = SeenBlockMarker::Finalized; entry.0 = SeenBlockMarker::Finalized;
entry.4 = Some(now.elapsed());
// .get_mut(&block_ref.hash()) // .get_mut(&block_ref.hash())
// .expect("finalized block seen before new block") // .expect("finalized block seen before new block")
@@ -552,7 +559,8 @@ impl<T: Config + Send + Sync + 'static> Backend<T> for UnstableBackend<T> {
// If we have a finalized hash, we are done looking for tx events and we are just waiting // If we have a finalized hash, we are done looking for tx events and we are just waiting
// for a pinned block with a matching hash (which must appear eventually given it's finalized). // for a pinned block with a matching hash (which must appear eventually given it's finalized).
if let Some(hash) = &finalized_hash { if let Some(hash) = &finalized_hash {
if let Some((SeenBlockMarker::Finalized, block_ref, _)) = seen_blocks.get(hash) if let Some((SeenBlockMarker::Finalized, block_ref, _, _, _)) =
seen_blocks.get(hash)
{ {
// Found it! Hand back the event with a pinned block. We're done. // Found it! Hand back the event with a pinned block. We're done.
done = true; done = true;
@@ -598,7 +606,7 @@ impl<T: Config + Send + Sync + 'static> Backend<T> for UnstableBackend<T> {
// block on the node a tx was sent to will ever be known about on the // block on the node a tx was sent to will ever be known about on the
// chainHead_follow subscription. // chainHead_follow subscription.
let block_ref = match seen_blocks.get(&block.hash) { let block_ref = match seen_blocks.get(&block.hash) {
Some((_, block_ref, _)) => block_ref.clone().into(), Some((_, block_ref, _, _, _)) => block_ref.clone().into(),
None => BlockRef::from_hash(block.hash), None => BlockRef::from_hash(block.hash),
}; };
TransactionStatus::InBestBlock { hash: block_ref } TransactionStatus::InBestBlock { hash: block_ref }