mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 07:31:02 +00:00
refactor transaction sign scheme (#1621)
This commit is contained in:
committed by
Bastian Köcher
parent
01538bc5fa
commit
a979340e49
@@ -36,7 +36,6 @@ impl SubstrateFinalitySyncPipeline for MillauFinalityToRialto {
|
||||
rialto_runtime::Runtime,
|
||||
rialto_runtime::MillauGrandpaInstance,
|
||||
>;
|
||||
type TransactionSignScheme = relay_rialto_client::Rialto;
|
||||
}
|
||||
|
||||
//// `Millau` to `Rialto` bridge definition.
|
||||
|
||||
@@ -54,7 +54,6 @@ impl SubstrateFinalitySyncPipeline for MillauFinalityToRialtoParachain {
|
||||
rialto_parachain_runtime::Runtime,
|
||||
rialto_parachain_runtime::MillauGrandpaInstance,
|
||||
>;
|
||||
type TransactionSignScheme = relay_rialto_parachain_client::RialtoParachain;
|
||||
}
|
||||
|
||||
//// `Millau` to `RialtoParachain` bridge definition.
|
||||
|
||||
@@ -49,9 +49,6 @@ impl SubstrateMessageLane for MillauMessagesToRialto {
|
||||
type SourceChain = Millau;
|
||||
type TargetChain = Rialto;
|
||||
|
||||
type SourceTransactionSignScheme = Millau;
|
||||
type TargetTransactionSignScheme = Rialto;
|
||||
|
||||
type ReceiveMessagesProofCallBuilder = DirectReceiveMessagesProofCallBuilder<
|
||||
Self,
|
||||
rialto_runtime::Runtime,
|
||||
|
||||
@@ -54,9 +54,6 @@ impl SubstrateMessageLane for MillauMessagesToRialtoParachain {
|
||||
type SourceChain = Millau;
|
||||
type TargetChain = RialtoParachain;
|
||||
|
||||
type SourceTransactionSignScheme = Millau;
|
||||
type TargetTransactionSignScheme = RialtoParachain;
|
||||
|
||||
type ReceiveMessagesProofCallBuilder = DirectReceiveMessagesProofCallBuilder<
|
||||
Self,
|
||||
rialto_parachain_runtime::Runtime,
|
||||
|
||||
@@ -40,7 +40,7 @@ mod tests {
|
||||
use codec::Encode;
|
||||
use relay_millau_client::Millau;
|
||||
use relay_rialto_client::Rialto;
|
||||
use relay_substrate_client::{SignParam, TransactionSignScheme, UnsignedTransaction};
|
||||
use relay_substrate_client::{ChainWithTransactions, SignParam, UnsignedTransaction};
|
||||
|
||||
#[test]
|
||||
fn maximal_rialto_to_millau_message_size_is_computed_correctly() {
|
||||
|
||||
@@ -36,7 +36,6 @@ impl SubstrateFinalitySyncPipeline for RialtoFinalityToMillau {
|
||||
millau_runtime::Runtime,
|
||||
millau_runtime::RialtoGrandpaInstance,
|
||||
>;
|
||||
type TransactionSignScheme = relay_millau_client::Millau;
|
||||
}
|
||||
|
||||
//// `Rialto` to `Millau` bridge definition.
|
||||
|
||||
@@ -49,9 +49,6 @@ impl SubstrateMessageLane for RialtoMessagesToMillau {
|
||||
type SourceChain = Rialto;
|
||||
type TargetChain = Millau;
|
||||
|
||||
type SourceTransactionSignScheme = Rialto;
|
||||
type TargetTransactionSignScheme = Millau;
|
||||
|
||||
type ReceiveMessagesProofCallBuilder = DirectReceiveMessagesProofCallBuilder<
|
||||
Self,
|
||||
millau_runtime::Runtime,
|
||||
|
||||
@@ -54,9 +54,6 @@ impl SubstrateMessageLane for RialtoParachainMessagesToMillau {
|
||||
type SourceChain = RialtoParachain;
|
||||
type TargetChain = Millau;
|
||||
|
||||
type SourceTransactionSignScheme = RialtoParachain;
|
||||
type TargetTransactionSignScheme = Millau;
|
||||
|
||||
type ReceiveMessagesProofCallBuilder = DirectReceiveMessagesProofCallBuilder<
|
||||
Self,
|
||||
millau_runtime::Runtime,
|
||||
|
||||
@@ -40,7 +40,6 @@ impl SubstrateParachainsPipeline for RialtoParachainsToMillau {
|
||||
type TargetChain = Millau;
|
||||
|
||||
type SubmitParachainHeadsCallBuilder = RialtoParachainsToMillauSubmitParachainHeadsCallBuilder;
|
||||
type TransactionSignScheme = Millau;
|
||||
|
||||
const SOURCE_PARACHAIN_PARA_ID: u32 = bp_rialto_parachain::RIALTO_PARACHAIN_ID;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ impl SubstrateFinalitySyncPipeline for WestendFinalityToMillau {
|
||||
millau_runtime::Runtime,
|
||||
millau_runtime::WestendGrandpaInstance,
|
||||
>;
|
||||
type TransactionSignScheme = relay_millau_client::Millau;
|
||||
}
|
||||
|
||||
//// `Westend` to `Millau` bridge definition.
|
||||
|
||||
@@ -39,7 +39,6 @@ impl SubstrateParachainsPipeline for WestendParachainsToMillau {
|
||||
type TargetChain = Millau;
|
||||
|
||||
type SubmitParachainHeadsCallBuilder = WestendParachainsToMillauSubmitParachainHeadsCallBuilder;
|
||||
type TransactionSignScheme = Millau;
|
||||
|
||||
const SOURCE_PARACHAIN_PARA_ID: u32 = bp_westend::WESTMINT_PARACHAIN_ID;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ use crate::cli::CliChain;
|
||||
use messages_relay::relay_strategy::MixStrategy;
|
||||
use pallet_bridge_parachains::{RelayBlockHash, RelayBlockHasher, RelayBlockNumber};
|
||||
use parachains_relay::ParachainsPipeline;
|
||||
use relay_substrate_client::{AccountKeyPairOf, Chain, RelayChain, TransactionSignScheme};
|
||||
use relay_substrate_client::{AccountKeyPairOf, Chain, ChainWithTransactions, RelayChain};
|
||||
use strum::{EnumString, EnumVariantNames};
|
||||
use substrate_relay_helper::{
|
||||
finality::SubstrateFinalitySyncPipeline, messages_lane::SubstrateMessageLane,
|
||||
@@ -58,9 +58,7 @@ pub trait CliBridgeBase: Sized {
|
||||
/// The source chain.
|
||||
type Source: Chain + CliChain;
|
||||
/// The target chain.
|
||||
type Target: Chain
|
||||
+ TransactionSignScheme<Chain = Self::Target>
|
||||
+ CliChain<KeyPair = AccountKeyPairOf<Self::Target>>;
|
||||
type Target: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Self::Target>>;
|
||||
}
|
||||
|
||||
/// Bridge representation that can be used from the CLI for relaying headers
|
||||
@@ -70,7 +68,6 @@ pub trait RelayToRelayHeadersCliBridge: CliBridgeBase {
|
||||
type Finality: SubstrateFinalitySyncPipeline<
|
||||
SourceChain = Self::Source,
|
||||
TargetChain = Self::Target,
|
||||
TransactionSignScheme = Self::Target,
|
||||
>;
|
||||
}
|
||||
|
||||
@@ -87,13 +84,11 @@ pub trait ParachainToRelayHeadersCliBridge: CliBridgeBase {
|
||||
SourceRelayChain = Self::SourceRelay,
|
||||
SourceParachain = Self::Source,
|
||||
TargetChain = Self::Target,
|
||||
TransactionSignScheme = Self::Target,
|
||||
> + ParachainsPipeline<SourceChain = Self::SourceRelay, TargetChain = Self::Target>;
|
||||
/// Finality proofs synchronization pipeline (source relay chain -> target).
|
||||
type RelayFinality: SubstrateFinalitySyncPipeline<
|
||||
SourceChain = Self::SourceRelay,
|
||||
TargetChain = Self::Target,
|
||||
TransactionSignScheme = Self::Target,
|
||||
>;
|
||||
}
|
||||
|
||||
@@ -106,8 +101,6 @@ pub trait MessagesCliBridge: CliBridgeBase {
|
||||
type MessagesLane: SubstrateMessageLane<
|
||||
SourceChain = Self::Source,
|
||||
TargetChain = Self::Target,
|
||||
SourceTransactionSignScheme = Self::Source,
|
||||
TargetTransactionSignScheme = Self::Target,
|
||||
RelayStrategy = MixStrategy,
|
||||
>;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ use bp_messages::LaneId;
|
||||
use bp_runtime::{BalanceOf, BlockNumberOf};
|
||||
use messages_relay::relay_strategy::MixStrategy;
|
||||
use relay_substrate_client::{
|
||||
AccountIdOf, AccountKeyPairOf, Chain, ChainWithBalances, Client, TransactionSignScheme,
|
||||
AccountIdOf, AccountKeyPairOf, Chain, ChainWithBalances, ChainWithTransactions, Client,
|
||||
};
|
||||
use relay_utils::metrics::MetricsParams;
|
||||
use sp_core::Pair;
|
||||
@@ -93,8 +93,8 @@ pub struct HeadersAndMessagesSharedParams {
|
||||
}
|
||||
|
||||
pub struct Full2WayBridgeCommonParams<
|
||||
Left: TransactionSignScheme + CliChain,
|
||||
Right: TransactionSignScheme + CliChain,
|
||||
Left: ChainWithTransactions + CliChain,
|
||||
Right: ChainWithTransactions + CliChain,
|
||||
> {
|
||||
pub shared: HeadersAndMessagesSharedParams,
|
||||
pub left: BridgeEndCommonParams<Left>,
|
||||
@@ -105,7 +105,7 @@ pub struct Full2WayBridgeCommonParams<
|
||||
pub right_to_left_metrics: StandaloneMessagesMetrics<Right, Left>,
|
||||
}
|
||||
|
||||
impl<Left: TransactionSignScheme + CliChain, Right: TransactionSignScheme + CliChain>
|
||||
impl<Left: ChainWithTransactions + CliChain, Right: ChainWithTransactions + CliChain>
|
||||
Full2WayBridgeCommonParams<Left, Right>
|
||||
{
|
||||
pub fn new<L2R: MessagesCliBridge<Source = Left, Target = Right>>(
|
||||
@@ -132,7 +132,7 @@ impl<Left: TransactionSignScheme + CliChain, Right: TransactionSignScheme + CliC
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BridgeEndCommonParams<Chain: TransactionSignScheme + CliChain> {
|
||||
pub struct BridgeEndCommonParams<Chain: ChainWithTransactions + CliChain> {
|
||||
pub client: Client<Chain>,
|
||||
pub sign: AccountKeyPairOf<Chain>,
|
||||
pub transactions_mortality: Option<u32>,
|
||||
@@ -142,8 +142,8 @@ pub struct BridgeEndCommonParams<Chain: TransactionSignScheme + CliChain> {
|
||||
|
||||
struct FullBridge<
|
||||
'a,
|
||||
Source: TransactionSignScheme + CliChain,
|
||||
Target: TransactionSignScheme + CliChain,
|
||||
Source: ChainWithTransactions + CliChain,
|
||||
Target: ChainWithTransactions + CliChain,
|
||||
Bridge: MessagesCliBridge<Source = Source, Target = Target>,
|
||||
> {
|
||||
shared: &'a HeadersAndMessagesSharedParams,
|
||||
@@ -156,8 +156,8 @@ struct FullBridge<
|
||||
|
||||
impl<
|
||||
'a,
|
||||
Source: TransactionSignScheme<Chain = Source> + CliChain,
|
||||
Target: TransactionSignScheme<Chain = Target> + CliChain,
|
||||
Source: ChainWithTransactions + CliChain,
|
||||
Target: ChainWithTransactions + CliChain,
|
||||
Bridge: MessagesCliBridge<Source = Source, Target = Target>,
|
||||
> FullBridge<'a, Source, Target, Bridge>
|
||||
where
|
||||
@@ -186,7 +186,6 @@ where
|
||||
};
|
||||
substrate_relay_helper::conversion_rate_update::run_conversion_rate_update_loop::<
|
||||
Bridge::MessagesLane,
|
||||
Source,
|
||||
>(
|
||||
self.source.client.clone(),
|
||||
TransactionParams {
|
||||
@@ -266,11 +265,9 @@ trait Full2WayBridgeBase: Sized + Send + Sync {
|
||||
/// The CLI params for the bridge.
|
||||
type Params;
|
||||
/// The left relay chain.
|
||||
type Left: TransactionSignScheme<Chain = Self::Left>
|
||||
+ CliChain<KeyPair = AccountKeyPairOf<Self::Left>>;
|
||||
type Left: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Self::Left>>;
|
||||
/// The right destination chain (it can be a relay or a parachain).
|
||||
type Right: TransactionSignScheme<Chain = Self::Right>
|
||||
+ CliChain<KeyPair = AccountKeyPairOf<Self::Right>>;
|
||||
type Right: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Self::Right>>;
|
||||
|
||||
fn common(&self) -> &Full2WayBridgeCommonParams<Self::Left, Self::Right>;
|
||||
|
||||
@@ -295,14 +292,12 @@ where
|
||||
type Base: Full2WayBridgeBase<Left = Self::Left, Right = Self::Right>;
|
||||
|
||||
/// The left relay chain.
|
||||
type Left: Chain
|
||||
type Left: ChainWithTransactions
|
||||
+ ChainWithBalances
|
||||
+ TransactionSignScheme<Chain = Self::Left>
|
||||
+ CliChain<KeyPair = AccountKeyPairOf<Self::Left>>;
|
||||
/// The right relay chain.
|
||||
type Right: Chain
|
||||
type Right: ChainWithTransactions
|
||||
+ ChainWithBalances
|
||||
+ TransactionSignScheme<Chain = Self::Right>
|
||||
+ CliChain<KeyPair = AccountKeyPairOf<Self::Right>>;
|
||||
|
||||
// Left to Right bridge
|
||||
|
||||
+7
-7
@@ -28,7 +28,7 @@ use crate::cli::{
|
||||
use bp_polkadot_core::parachains::ParaHash;
|
||||
use bp_runtime::BlockNumberOf;
|
||||
use pallet_bridge_parachains::{RelayBlockHash, RelayBlockHasher, RelayBlockNumber};
|
||||
use relay_substrate_client::{AccountIdOf, AccountKeyPairOf, Chain, Client, TransactionSignScheme};
|
||||
use relay_substrate_client::{AccountIdOf, AccountKeyPairOf, Chain, ChainWithTransactions, Client};
|
||||
use sp_core::Pair;
|
||||
use substrate_relay_helper::{
|
||||
finality::SubstrateFinalitySyncPipeline,
|
||||
@@ -95,9 +95,9 @@ macro_rules! declare_relay_to_parachain_bridge_schema {
|
||||
|
||||
impl [<$left_chain $right_parachain HeadersAndMessages>] {
|
||||
async fn into_bridge<
|
||||
Left: TransactionSignScheme + CliChain<KeyPair = AccountKeyPairOf<Left>>,
|
||||
Right: TransactionSignScheme + CliChain<KeyPair = AccountKeyPairOf<Right>>,
|
||||
RightRelay: TransactionSignScheme + CliChain,
|
||||
Left: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Left>>,
|
||||
Right: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Right>>,
|
||||
RightRelay: ChainWithTransactions + CliChain,
|
||||
L2R: CliBridgeBase<Source = Left, Target = Right> + MessagesCliBridge + RelayToRelayHeadersCliBridge,
|
||||
R2L: CliBridgeBase<Source = Right, Target = Left>
|
||||
+ MessagesCliBridge
|
||||
@@ -146,12 +146,12 @@ macro_rules! declare_relay_to_parachain_bridge_schema {
|
||||
|
||||
#[async_trait]
|
||||
impl<
|
||||
Left: Chain + TransactionSignScheme<Chain = Left> + CliChain<KeyPair = AccountKeyPairOf<Left>>,
|
||||
Left: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Left>>,
|
||||
Right: Chain<Hash = ParaHash>
|
||||
+ TransactionSignScheme<Chain = Right>
|
||||
+ ChainWithTransactions
|
||||
+ CliChain<KeyPair = AccountKeyPairOf<Right>>,
|
||||
RightRelay: Chain<BlockNumber = RelayBlockNumber, Hash = RelayBlockHash, Hasher = RelayBlockHasher>
|
||||
+ TransactionSignScheme
|
||||
+ ChainWithTransactions
|
||||
+ CliChain,
|
||||
L2R: CliBridgeBase<Source = Left, Target = Right>
|
||||
+ MessagesCliBridge
|
||||
|
||||
@@ -23,7 +23,7 @@ use crate::cli::{
|
||||
CliChain,
|
||||
};
|
||||
use bp_runtime::BlockNumberOf;
|
||||
use relay_substrate_client::{AccountIdOf, AccountKeyPairOf, Chain, TransactionSignScheme};
|
||||
use relay_substrate_client::{AccountIdOf, AccountKeyPairOf, ChainWithTransactions};
|
||||
use sp_core::Pair;
|
||||
use substrate_relay_helper::{
|
||||
finality::SubstrateFinalitySyncPipeline,
|
||||
@@ -77,8 +77,8 @@ macro_rules! declare_relay_to_relay_bridge_schema {
|
||||
|
||||
impl [<$left_chain $right_chain HeadersAndMessages>] {
|
||||
async fn into_bridge<
|
||||
Left: TransactionSignScheme + CliChain<KeyPair = AccountKeyPairOf<Left>>,
|
||||
Right: TransactionSignScheme + CliChain<KeyPair = AccountKeyPairOf<Right>>,
|
||||
Left: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Left>>,
|
||||
Right: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Right>>,
|
||||
L2R: CliBridgeBase<Source = Left, Target = Right> + MessagesCliBridge + RelayToRelayHeadersCliBridge,
|
||||
R2L: CliBridgeBase<Source = Right, Target = Left> + MessagesCliBridge + RelayToRelayHeadersCliBridge,
|
||||
>(
|
||||
@@ -117,8 +117,8 @@ macro_rules! declare_relay_to_relay_bridge_schema {
|
||||
|
||||
#[async_trait]
|
||||
impl<
|
||||
Left: Chain + TransactionSignScheme<Chain = Left> + CliChain<KeyPair = AccountKeyPairOf<Left>>,
|
||||
Right: Chain + TransactionSignScheme<Chain = Right> + CliChain<KeyPair = AccountKeyPairOf<Right>>,
|
||||
Left: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Left>>,
|
||||
Right: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Right>>,
|
||||
L2R: CliBridgeBase<Source = Left, Target = Right>
|
||||
+ MessagesCliBridge
|
||||
+ RelayToRelayHeadersCliBridge,
|
||||
|
||||
@@ -26,7 +26,7 @@ use crate::chains::{
|
||||
rialto_parachains_to_millau::RialtoParachainToMillauCliBridge,
|
||||
};
|
||||
use messages_relay::relay_strategy::MixStrategy;
|
||||
use relay_substrate_client::{AccountIdOf, AccountKeyPairOf, BalanceOf, TransactionSignScheme};
|
||||
use relay_substrate_client::{AccountIdOf, AccountKeyPairOf, BalanceOf, ChainWithTransactions};
|
||||
use substrate_relay_helper::{messages_lane::MessagesRelayParams, TransactionParams};
|
||||
|
||||
use crate::cli::{bridge::*, chain_schema::*, CliChain, HexLaneId, PrometheusParams};
|
||||
@@ -77,8 +77,7 @@ pub struct RelayMessages {
|
||||
#[async_trait]
|
||||
trait MessagesRelayer: MessagesCliBridge
|
||||
where
|
||||
Self::Source: TransactionSignScheme<Chain = Self::Source>
|
||||
+ CliChain<KeyPair = AccountKeyPairOf<Self::Source>>,
|
||||
Self::Source: ChainWithTransactions + CliChain<KeyPair = AccountKeyPairOf<Self::Source>>,
|
||||
AccountIdOf<Self::Source>: From<<AccountKeyPairOf<Self::Source> as Pair>::Public>,
|
||||
AccountIdOf<Self::Target>: From<<AccountKeyPairOf<Self::Target> as Pair>::Public>,
|
||||
BalanceOf<Self::Source>: TryFrom<BalanceOf<Self::Target>>,
|
||||
|
||||
@@ -20,8 +20,8 @@ use bp_runtime::HeaderIdProvider;
|
||||
use codec::{Decode, Encode};
|
||||
use num_traits::{One, Zero};
|
||||
use relay_substrate_client::{
|
||||
BlockWithJustification, Chain, Client, Error as SubstrateError, HeaderIdOf, HeaderOf,
|
||||
SignParam, TransactionSignScheme,
|
||||
AccountKeyPairOf, BlockWithJustification, Chain, ChainWithTransactions, Client,
|
||||
Error as SubstrateError, HeaderIdOf, HeaderOf, SignParam,
|
||||
};
|
||||
use relay_utils::FailedClient;
|
||||
use sp_core::Bytes;
|
||||
@@ -111,7 +111,7 @@ impl ResubmitTransactions {
|
||||
|
||||
relay_utils::relay_loop((), client)
|
||||
.run(relay_loop_name, move |_, client, _| {
|
||||
run_until_connection_lost::<Target, TargetSign>(
|
||||
run_until_connection_lost(
|
||||
client,
|
||||
transaction_params.clone(),
|
||||
Context {
|
||||
@@ -140,16 +140,16 @@ impl ResubmitTransactions {
|
||||
|
||||
impl PrioritySelectionStrategy {
|
||||
/// Select target priority.
|
||||
async fn select_target_priority<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
async fn select_target_priority<C: ChainWithTransactions>(
|
||||
&self,
|
||||
client: &Client<C>,
|
||||
context: &Context<C>,
|
||||
) -> Result<Option<TransactionPriority>, SubstrateError> {
|
||||
match *self {
|
||||
PrioritySelectionStrategy::MakeItBestTransaction =>
|
||||
read_previous_block_best_priority::<C, S>(client, context).await,
|
||||
read_previous_block_best_priority(client, context).await,
|
||||
PrioritySelectionStrategy::MakeItBetterThanQueuedTransaction =>
|
||||
select_priority_from_queue::<C, S>(client, context).await,
|
||||
select_priority_from_queue(client, context).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,16 +202,15 @@ impl<C: Chain> Context<C> {
|
||||
}
|
||||
|
||||
/// Run resubmit transactions loop.
|
||||
async fn run_until_connection_lost<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
async fn run_until_connection_lost<C: ChainWithTransactions>(
|
||||
client: Client<C>,
|
||||
transaction_params: TransactionParams<S::AccountKeyPair>,
|
||||
transaction_params: TransactionParams<AccountKeyPairOf<C>>,
|
||||
mut context: Context<C>,
|
||||
) -> Result<(), FailedClient> {
|
||||
loop {
|
||||
async_std::task::sleep(C::AVERAGE_BLOCK_INTERVAL).await;
|
||||
|
||||
let result =
|
||||
run_loop_iteration::<C, S>(client.clone(), transaction_params.clone(), context).await;
|
||||
let result = run_loop_iteration(client.clone(), transaction_params.clone(), context).await;
|
||||
context = match result {
|
||||
Ok(context) => context,
|
||||
Err(error) => {
|
||||
@@ -228,9 +227,9 @@ async fn run_until_connection_lost<C: Chain, S: TransactionSignScheme<Chain = C>
|
||||
}
|
||||
|
||||
/// Run single loop iteration.
|
||||
async fn run_loop_iteration<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
async fn run_loop_iteration<C: ChainWithTransactions>(
|
||||
client: Client<C>,
|
||||
transaction_params: TransactionParams<S::AccountKeyPair>,
|
||||
transaction_params: TransactionParams<AccountKeyPairOf<C>>,
|
||||
mut context: Context<C>,
|
||||
) -> Result<Context<C>, SubstrateError> {
|
||||
// correct best header is required for all other actions
|
||||
@@ -238,7 +237,7 @@ async fn run_loop_iteration<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
|
||||
// check if there's queued transaction, signed by given author
|
||||
let original_transaction =
|
||||
match lookup_signer_transaction::<C, S>(&client, &transaction_params.signer).await? {
|
||||
match lookup_signer_transaction(&client, &transaction_params.signer).await? {
|
||||
Some(original_transaction) => original_transaction,
|
||||
None => {
|
||||
log::trace!(target: "bridge", "No {} transactions from required signer in the txpool", C::NAME);
|
||||
@@ -262,17 +261,16 @@ async fn run_loop_iteration<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
}
|
||||
|
||||
// select priority for updated transaction
|
||||
let target_priority =
|
||||
match context.strategy.select_target_priority::<C, S>(&client, &context).await? {
|
||||
Some(target_priority) => target_priority,
|
||||
None => {
|
||||
log::trace!(target: "bridge", "Failed to select target priority");
|
||||
return Ok(context)
|
||||
},
|
||||
};
|
||||
let target_priority = match context.strategy.select_target_priority(&client, &context).await? {
|
||||
Some(target_priority) => target_priority,
|
||||
None => {
|
||||
log::trace!(target: "bridge", "Failed to select target priority");
|
||||
return Ok(context)
|
||||
},
|
||||
};
|
||||
|
||||
// update transaction tip
|
||||
let (is_updated, updated_transaction) = update_transaction_tip::<C, S>(
|
||||
let (is_updated, updated_transaction) = update_transaction_tip(
|
||||
&client,
|
||||
&transaction_params,
|
||||
context.best_header.id(),
|
||||
@@ -304,15 +302,15 @@ async fn run_loop_iteration<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
}
|
||||
|
||||
/// Search transaction pool for transaction, signed by given key pair.
|
||||
async fn lookup_signer_transaction<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
async fn lookup_signer_transaction<C: ChainWithTransactions>(
|
||||
client: &Client<C>,
|
||||
key_pair: &S::AccountKeyPair,
|
||||
) -> Result<Option<S::SignedTransaction>, SubstrateError> {
|
||||
key_pair: &AccountKeyPairOf<C>,
|
||||
) -> Result<Option<C::SignedTransaction>, SubstrateError> {
|
||||
let pending_transactions = client.pending_extrinsics().await?;
|
||||
for pending_transaction in pending_transactions {
|
||||
let pending_transaction = S::SignedTransaction::decode(&mut &pending_transaction.0[..])
|
||||
let pending_transaction = C::SignedTransaction::decode(&mut &pending_transaction.0[..])
|
||||
.map_err(SubstrateError::ResponseParseFailed)?;
|
||||
if !S::is_signed_by(key_pair, &pending_transaction) {
|
||||
if !C::is_signed_by(key_pair, &pending_transaction) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -323,7 +321,7 @@ async fn lookup_signer_transaction<C: Chain, S: TransactionSignScheme<Chain = C>
|
||||
}
|
||||
|
||||
/// Read priority of best signed transaction of previous block.
|
||||
async fn read_previous_block_best_priority<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
async fn read_previous_block_best_priority<C: ChainWithTransactions>(
|
||||
client: &Client<C>,
|
||||
context: &Context<C>,
|
||||
) -> Result<Option<TransactionPriority>, SubstrateError> {
|
||||
@@ -331,8 +329,8 @@ async fn read_previous_block_best_priority<C: Chain, S: TransactionSignScheme<Ch
|
||||
let best_transaction = best_block
|
||||
.extrinsics()
|
||||
.iter()
|
||||
.filter_map(|xt| S::SignedTransaction::decode(&mut &xt[..]).ok())
|
||||
.find(|xt| S::is_signed(xt));
|
||||
.filter_map(|xt| C::SignedTransaction::decode(&mut &xt[..]).ok())
|
||||
.find(|xt| C::is_signed(xt));
|
||||
match best_transaction {
|
||||
Some(best_transaction) => Ok(Some(
|
||||
client
|
||||
@@ -345,7 +343,7 @@ async fn read_previous_block_best_priority<C: Chain, S: TransactionSignScheme<Ch
|
||||
}
|
||||
|
||||
/// Select priority of some queued transaction.
|
||||
async fn select_priority_from_queue<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
async fn select_priority_from_queue<C: ChainWithTransactions>(
|
||||
client: &Client<C>,
|
||||
context: &Context<C>,
|
||||
) -> Result<Option<TransactionPriority>, SubstrateError> {
|
||||
@@ -356,7 +354,7 @@ async fn select_priority_from_queue<C: Chain, S: TransactionSignScheme<Chain = C
|
||||
None => return Ok(None),
|
||||
};
|
||||
|
||||
let selected_transaction = S::SignedTransaction::decode(&mut &selected_transaction[..])
|
||||
let selected_transaction = C::SignedTransaction::decode(&mut &selected_transaction[..])
|
||||
.map_err(SubstrateError::ResponseParseFailed)?;
|
||||
let target_priority = client
|
||||
.validate_transaction(context.best_header.hash(), selected_transaction)
|
||||
@@ -389,18 +387,18 @@ fn select_transaction_from_queue<C: Chain>(
|
||||
}
|
||||
|
||||
/// Try to find appropriate tip for transaction so that its priority is larger than given.
|
||||
async fn update_transaction_tip<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
async fn update_transaction_tip<C: ChainWithTransactions>(
|
||||
client: &Client<C>,
|
||||
transaction_params: &TransactionParams<S::AccountKeyPair>,
|
||||
transaction_params: &TransactionParams<AccountKeyPairOf<C>>,
|
||||
at_block: HeaderIdOf<C>,
|
||||
tx: S::SignedTransaction,
|
||||
tx: C::SignedTransaction,
|
||||
tip_step: C::Balance,
|
||||
tip_limit: C::Balance,
|
||||
target_priority: TransactionPriority,
|
||||
) -> Result<(bool, S::SignedTransaction), SubstrateError> {
|
||||
) -> Result<(bool, C::SignedTransaction), SubstrateError> {
|
||||
let stx = format!("{tx:?}");
|
||||
let mut current_priority = client.validate_transaction(at_block.1, tx.clone()).await??.priority;
|
||||
let mut unsigned_tx = S::parse_transaction(tx).ok_or_else(|| {
|
||||
let mut unsigned_tx = C::parse_transaction(tx).ok_or_else(|| {
|
||||
SubstrateError::Custom(format!("Failed to parse {} transaction {stx}", C::NAME,))
|
||||
})?;
|
||||
let old_tip = unsigned_tx.tip;
|
||||
@@ -425,7 +423,7 @@ async fn update_transaction_tip<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
current_priority = client
|
||||
.validate_transaction(
|
||||
at_block.1,
|
||||
S::sign_transaction(
|
||||
C::sign_transaction(
|
||||
SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
@@ -449,7 +447,7 @@ async fn update_transaction_tip<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
|
||||
Ok((
|
||||
old_tip != unsigned_tx.tip,
|
||||
S::sign_transaction(
|
||||
C::sign_transaction(
|
||||
SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
|
||||
@@ -32,7 +32,7 @@ use crate::{
|
||||
use async_trait::async_trait;
|
||||
use codec::{Decode, Encode};
|
||||
use relay_substrate_client::{
|
||||
AccountIdOf, AccountKeyPairOf, Chain, ChainBase, SignParam, TransactionSignScheme,
|
||||
AccountIdOf, AccountKeyPairOf, Chain, ChainBase, ChainWithTransactions, SignParam,
|
||||
UnsignedTransaction,
|
||||
};
|
||||
use sp_core::{Bytes, Pair};
|
||||
@@ -96,12 +96,12 @@ pub struct SendMessage {
|
||||
trait MessageSender: MessagesCliBridge
|
||||
where
|
||||
Self::Source: ChainBase<Index = u32>
|
||||
+ TransactionSignScheme<Chain = Self::Source>
|
||||
+ ChainWithTransactions
|
||||
+ CliChain<KeyPair = AccountKeyPairOf<Self::Source>>
|
||||
+ CliEncodeMessage,
|
||||
<Self::Source as ChainBase>::Balance: Display + From<u64> + Into<u128>,
|
||||
<Self::Source as Chain>::Call: Sync,
|
||||
<Self::Source as TransactionSignScheme>::SignedTransaction: Sync,
|
||||
<Self::Source as ChainWithTransactions>::SignedTransaction: Sync,
|
||||
AccountIdOf<Self::Source>: From<<AccountKeyPairOf<Self::Source> as Pair>::Public>,
|
||||
AccountId32: From<<AccountKeyPairOf<Self::Source> as Pair>::Public>,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user