diff --git a/bridges/relays/bin-substrate/src/cli/resubmit_transactions.rs b/bridges/relays/bin-substrate/src/cli/resubmit_transactions.rs
index 03a9c114b0..d20cff17f6 100644
--- a/bridges/relays/bin-substrate/src/cli/resubmit_transactions.rs
+++ b/bridges/relays/bin-substrate/src/cli/resubmit_transactions.rs
@@ -14,12 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Parity Bridges Common. If not, see .
-use crate::cli::{TargetConnectionParams, TargetSigningParams};
+use crate::cli::{Balance, TargetConnectionParams, TargetSigningParams};
use codec::{Decode, Encode};
use num_traits::{One, Zero};
use relay_substrate_client::{
- BlockWithJustification, Chain, Client, Error as SubstrateError, TransactionSignScheme,
+ BlockWithJustification, Chain, Client, Error as SubstrateError, HeaderOf, TransactionSignScheme,
};
use relay_utils::FailedClient;
use sp_core::Bytes;
@@ -40,6 +40,19 @@ pub struct ResubmitTransactions {
target: TargetConnectionParams,
#[structopt(flatten)]
target_sign: TargetSigningParams,
+ /// Number of blocks we see before considering queued transaction as stalled.
+ #[structopt(long, default_value = "5")]
+ stalled_blocks: u32,
+ /// Tip limit. We'll never submit transaction with larger tip.
+ #[structopt(long)]
+ tip_limit: Balance,
+ /// Tip increase step. We'll be checking updated transaction priority by increasing its tip by
+ /// this step.
+ #[structopt(long)]
+ tip_step: Balance,
+ /// Priority selection strategy.
+ #[structopt(subcommand)]
+ strategy: PrioritySelectionStrategy,
}
/// Chain, which transactions we're going to track && resubmit.
@@ -47,6 +60,28 @@ pub struct ResubmitTransactions {
#[strum(serialize_all = "kebab_case")]
pub enum RelayChain {
Millau,
+ Kusama,
+ Polkadot,
+}
+
+/// Strategy to use for priority selection.
+#[derive(StructOpt, Debug, PartialEq, Eq, Clone, Copy)]
+pub enum PrioritySelectionStrategy {
+ /// Strategy selects tip that changes transaction priority to be better than priority of
+ /// the first transaction of previous block.
+ ///
+ /// It only makes sense to use this strategy for Millau transactions. Millau has transactions
+ /// that are close to block limits, so if there are any other queued transactions, 'large'
+ /// transaction won't fit the block && will be postponed. To avoid this, we change its priority
+ /// to some large value, making it best transaction => it'll be 'mined' first.
+ MakeItBestTransaction,
+ /// Strategy selects tip that changes transaction priority to be better than priority of
+ /// selected queued transaction.
+ ///
+ /// When we first see stalled transaction, we make it better than worst 1/4 of queued
+ /// transactions. If it is still stalled, we'll make it better than 1/3 of queued transactions,
+ /// ...
+ MakeItBetterThanQueuedTransaction,
}
macro_rules! select_bridge {
@@ -56,20 +91,17 @@ macro_rules! select_bridge {
type Target = relay_millau_client::Millau;
type TargetSign = relay_millau_client::Millau;
- // When large message is being sent from Millau to Rialto AND other transactions are
- // blocking it from being mined, we'll see something like this in logs:
- //
- // Millau transaction priority with tip=0: 17800827994. Target priority:
- // 526186677695
- //
- // So since fee multiplier in Millau is `1` and `WeightToFee` is `IdentityFee`, then
- // we need tip around `526186677695 - 17800827994 = 508_385_849_701`. Let's round it
- // up to `1_000_000_000_000`.
+ $generic
+ },
+ RelayChain::Kusama => {
+ type Target = relay_kusama_client::Kusama;
+ type TargetSign = relay_kusama_client::Kusama;
- const TIP_STEP: bp_millau::Balance = 1_000_000_000;
- const TIP_LIMIT: bp_millau::Balance = 1_000_000_000_000;
-
- const STALLED_BLOCKS: bp_millau::BlockNumber = 5;
+ $generic
+ },
+ RelayChain::Polkadot => {
+ type Target = relay_polkadot_client::Polkadot;
+ type TargetSign = relay_polkadot_client::Polkadot;
$generic
},
@@ -91,11 +123,20 @@ impl ResubmitTransactions {
client,
key_pair.clone(),
Context {
+ strategy: self.strategy,
+ best_header: HeaderOf::::new(
+ Default::default(),
+ Default::default(),
+ Default::default(),
+ Default::default(),
+ Default::default(),
+ ),
transaction: None,
+ resubmitted: 0,
stalled_for: Zero::zero(),
- stalled_for_limit: STALLED_BLOCKS,
- tip_step: TIP_STEP,
- tip_limit: TIP_LIMIT,
+ stalled_for_limit: self.stalled_blocks.into(),
+ tip_step: self.tip_step.cast().into(),
+ tip_limit: self.tip_limit.cast().into(),
},
)
})
@@ -104,10 +145,32 @@ impl ResubmitTransactions {
}
}
-#[derive(Debug, Default)]
+impl PrioritySelectionStrategy {
+ /// Select target priority.
+ async fn select_target_priority>(
+ &self,
+ client: &Client,
+ context: &Context,
+ ) -> Result