mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 07:11:06 +00:00
backend: Use master
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
@@ -437,13 +437,28 @@ impl<T: Config + Send + Sync + 'static> Backend<T> for UnstableBackend<T> {
|
||||
extrinsic: &[u8],
|
||||
) -> Result<StreamOfResults<TransactionStatus<T::Hash>>, Error> {
|
||||
// We care about new and finalized block hashes.
|
||||
enum SeenBlock<Ref> {
|
||||
New(Ref),
|
||||
Finalized(Vec<Ref>),
|
||||
}
|
||||
enum SeenBlockMarker {
|
||||
New,
|
||||
Finalized,
|
||||
}
|
||||
|
||||
// First, subscribe to all new and finalized block refs.
|
||||
let mut seen_blocks_sub = self.follow_handle.subscribe().events();
|
||||
// - we subscribe to new refs so that when we see `BestChainBlockIncluded`, we
|
||||
// can try to return a block ref for the best block.
|
||||
// - we subscribe to finalized refs so that when we see `Finalized`, we can
|
||||
// guarantee that when we return here, the finalized block we report has been
|
||||
// reported from chainHead_follow already.
|
||||
let mut seen_blocks_sub = self.follow_handle.subscribe().events().filter_map(|ev| {
|
||||
std::future::ready(match ev {
|
||||
FollowEvent::NewBlock(ev) => Some(SeenBlock::New(ev.block_hash)),
|
||||
FollowEvent::Finalized(ev) => Some(SeenBlock::Finalized(ev.finalized_block_hashes)),
|
||||
_ => None,
|
||||
})
|
||||
});
|
||||
|
||||
// Then, submit the transaction.
|
||||
let mut tx_progress = self
|
||||
@@ -470,22 +485,23 @@ impl<T: Config + Send + Sync + 'static> Backend<T> for UnstableBackend<T> {
|
||||
// Make a note of new or finalized blocks that have come in since we started the TX.
|
||||
if let Poll::Ready(Some(seen_block)) = seen_blocks_sub.poll_next_unpin(cx) {
|
||||
match seen_block {
|
||||
FollowEvent::NewBlock(new_block) => {
|
||||
seen_blocks.insert(
|
||||
new_block.block_hash.hash(),
|
||||
(SeenBlockMarker::New, new_block.block_hash),
|
||||
);
|
||||
SeenBlock::New(block_ref) => {
|
||||
// Optimization: once we have a `finalized_hash`, we only care about finalized
|
||||
// block refs now and can avoid bothering to save new blocks.
|
||||
if finalized_hash.is_none() {
|
||||
seen_blocks
|
||||
.insert(block_ref.hash(), (SeenBlockMarker::New, block_ref));
|
||||
}
|
||||
}
|
||||
FollowEvent::Finalized(finalized_block) => {
|
||||
for block_ref in finalized_block.finalized_block_hashes {
|
||||
SeenBlock::Finalized(block_refs) => {
|
||||
for block_ref in block_refs {
|
||||
seen_blocks.insert(
|
||||
block_ref.hash(),
|
||||
(SeenBlockMarker::Finalized, block_ref),
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user