Skip to content

Commit b29841f

Browse files
committed
add some logs and simplify submit_transaction in the same way Alex did
1 parent 6967ae4 commit b29841f

File tree

1 file changed

+13
-23
lines changed
  • subxt/src/backend/unstable

1 file changed

+13
-23
lines changed

subxt/src/backend/unstable/mod.rs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -437,28 +437,13 @@ impl<T: Config + Send + Sync + 'static> Backend<T> for UnstableBackend<T> {
437437
extrinsic: &[u8],
438438
) -> Result<StreamOfResults<TransactionStatus<T::Hash>>, Error> {
439439
// We care about new and finalized block hashes.
440-
enum SeenBlock<Ref> {
441-
New(Ref),
442-
Finalized(Vec<Ref>),
443-
}
444440
enum SeenBlockMarker {
445441
New,
446442
Finalized,
447443
}
448444

449-
// First, subscribe to all new and finalized block refs.
450-
// - we subscribe to new refs so that when we see `BestChainBlockIncluded`, we
451-
// can try to return a block ref for the best block.
452-
// - we subscribe to finalized refs so that when we see `Finalized`, we can
453-
// guarantee that when we return here, the finalized block we report has been
454-
// reported from chainHead_follow already.
455-
let mut seen_blocks_sub = self.follow_handle.subscribe().events().filter_map(|ev| {
456-
std::future::ready(match ev {
457-
FollowEvent::NewBlock(ev) => Some(SeenBlock::New(ev.block_hash)),
458-
FollowEvent::Finalized(ev) => Some(SeenBlock::Finalized(ev.finalized_block_hashes)),
459-
_ => None,
460-
})
461-
});
445+
// First, subscribe to new blocks.
446+
let mut seen_blocks_sub = self.follow_handle.subscribe().events();
462447

463448
// Then, submit the transaction.
464449
let mut tx_progress = self
@@ -485,31 +470,36 @@ impl<T: Config + Send + Sync + 'static> Backend<T> for UnstableBackend<T> {
485470
// Make a note of new or finalized blocks that have come in since we started the TX.
486471
if let Poll::Ready(Some(seen_block)) = seen_blocks_sub.poll_next_unpin(cx) {
487472
match seen_block {
488-
SeenBlock::New(block_ref) => {
473+
FollowEvent::NewBlock(ev) => {
474+
println!("New block seen: {:?}", ev.block_hash.hash());
489475
// Optimization: once we have a `finalized_hash`, we only care about finalized
490476
// block refs now and can avoid bothering to save new blocks.
491477
if finalized_hash.is_none() {
492478
seen_blocks
493-
.insert(block_ref.hash(), (SeenBlockMarker::New, block_ref));
479+
.insert(ev.block_hash.hash(), (SeenBlockMarker::New, ev.block_hash));
494480
}
495481
}
496-
SeenBlock::Finalized(block_refs) => {
497-
for block_ref in block_refs {
482+
FollowEvent::Finalized(ev) => {
483+
for block_ref in ev.finalized_block_hashes {
484+
println!("Finalized block seen: {:?}", block_ref.hash());
498485
seen_blocks.insert(
499486
block_ref.hash(),
500487
(SeenBlockMarker::Finalized, block_ref),
501488
);
502489
}
503-
}
490+
},
491+
_ => {}
504492
}
505493
continue;
506494
}
507495

508496
// If we have a finalized hash, we are done looking for tx events and we are just waiting
509497
// for a pinned block with a matching hash (which must appear eventually given it's finalized).
510498
if let Some(hash) = &finalized_hash {
499+
println!("Looking for finalized hash {hash:?}");
511500
if let Some((SeenBlockMarker::Finalized, block_ref)) = seen_blocks.remove(hash)
512501
{
502+
println!("Found finalized hash!");
513503
// Found it! Hand back the event with a pinned block. We're done.
514504
done = true;
515505
let ev = TransactionStatus::InFinalizedBlock {
@@ -534,7 +524,7 @@ impl<T: Config + Send + Sync + 'static> Backend<T> for UnstableBackend<T> {
534524
Poll::Ready(Some(Err(e))) => return Poll::Ready(Some(Err(e))),
535525
Poll::Ready(Some(Ok(ev))) => ev,
536526
};
537-
527+
println!("TX Event seen: {ev:?}");
538528
// When we get one, map it to the correct format (or for finalized ev, wait for the pinned block):
539529
let ev = match ev {
540530
rpc_methods::TransactionStatus::Finalized { block } => {

0 commit comments

Comments
 (0)