Define HeaderIdProvider trait

Define HeaderIdProvider trait

Signed-off-by: Serban Iorga <serban@parity.io>
This commit is contained in:
Serban Iorga
2022-07-14 17:49:18 +03:00
committed by Bastian Köcher
parent 2b03f4e9e9
commit dc38e3d079
7 changed files with 47 additions and 26 deletions
+9 -11
View File
@@ -25,6 +25,7 @@ use crate::{
use async_std::sync::{Arc, Mutex};
use async_trait::async_trait;
use bp_runtime::HeaderIdProvider;
use codec::{Decode, Encode};
use frame_system::AccountInfo;
use futures::{SinkExt, StreamExt};
@@ -33,10 +34,10 @@ use jsonrpsee::{
types::params::ParamsSer,
ws_client::{WsClient as RpcClient, WsClientBuilder as RpcClientBuilder},
};
use num_traits::{Bounded, CheckedSub, One, Zero};
use num_traits::{Bounded, Zero};
use pallet_balances::AccountData;
use pallet_transaction_payment::InclusionFee;
use relay_utils::{relay_loop::RECONNECT_DELAY, HeaderId};
use relay_utils::relay_loop::RECONNECT_DELAY;
use sp_core::{
storage::{StorageData, StorageKey},
Bytes, Hasher,
@@ -484,14 +485,11 @@ impl<C: Chain> Client<C> {
let best_header = self.best_header().await?;
// By using parent of best block here, we are protecing again best-block reorganizations.
// E.g. transaction my have been submitted when the best block was `A[num=100]`. Then it has
// been changed to `B[num=100]`. Hash of `A` has been included into transaction signature
// payload. So when signature will be checked, the check will fail and transaction will be
// dropped from the pool.
let best_header_id = match best_header.number().checked_sub(&One::one()) {
Some(parent_block_number) => HeaderId(parent_block_number, *best_header.parent_hash()),
None => HeaderId(*best_header.number(), best_header.hash()),
};
// E.g. transaction may have been submitted when the best block was `A[num=100]`. Then it
// has been changed to `B[num=100]`. Hash of `A` has been included into transaction
// signature payload. So when signature will be checked, the check will fail and transaction
// will be dropped from the pool.
let best_header_id = best_header.parent_id().unwrap_or_else(|| best_header.id());
self.jsonrpsee_execute(move |client| async move {
let extrinsic = prepare_extrinsic(best_header_id, transaction_nonce)?;
@@ -524,7 +522,7 @@ impl<C: Chain> Client<C> {
let _guard = self.submit_signed_extrinsic_lock.lock().await;
let transaction_nonce = self.next_account_index(extrinsic_signer).await?;
let best_header = self.best_header().await?;
let best_header_id = HeaderId(*best_header.number(), best_header.hash());
let best_header_id = best_header.id();
let subscription = self
.jsonrpsee_execute(move |client| async move {
let extrinsic = prepare_extrinsic(best_header_id, transaction_nonce)?;