Skip to content

Commit

Permalink
added at-source-block argument
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik committed May 6, 2024
1 parent 5dee754 commit 1450c3d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
22 changes: 21 additions & 1 deletion bridges/relays/lib-substrate-relay/src/cli/relay_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ use sp_core::Pair;
use structopt::StructOpt;

use bp_messages::MessageNonce;
use bp_runtime::HeaderIdProvider;
use relay_substrate_client::{
AccountIdOf, AccountKeyPairOf, BalanceOf, ChainWithRuntimeVersion, ChainWithTransactions,
AccountIdOf, AccountKeyPairOf, BalanceOf, Chain, ChainWithRuntimeVersion, ChainWithTransactions,
};
use relay_utils::UniqueSaturatedInto;

/// Messages relaying params.
#[derive(StructOpt)]
Expand All @@ -52,6 +54,10 @@ pub struct RelayMessagesParams {
/// Messages range relaying params.
#[derive(StructOpt)]
pub struct RelayMessagesRangeParams {
/// Number of the source chain header that we will use to prepare a messages proof.
/// This header must be previously proved to the target chain.
#[structopt(long)]
at_source_block: u128,
/// Hex-encoded lane id that should be served by the relay. Defaults to `00000000`.
#[structopt(long, default_value = "00000000")]
lane: HexLaneId,
Expand Down Expand Up @@ -122,11 +128,25 @@ where
let target_sign = data.target_sign.to_keypair::<Self::Target>()?;
let target_transactions_mortality = data.target_sign.transactions_mortality()?;

let at_source_block = source_client
.header_by_number(data.at_source_block.unique_saturated_into())
.await
.map_err(|e| {
log::trace!(
target: "bridge",
"Failed to read {} header with number {}: {e:?}",
Self::Source::NAME,
data.at_source_block,
);
anyhow::format_err!("The command has failed")
})?.id();

crate::messages_lane::relay_messages_range::<Self::MessagesLane>(
source_client,
target_client,
TransactionParams { signer: source_sign, mortality: source_transactions_mortality },
TransactionParams { signer: target_sign, mortality: target_transactions_mortality },
at_source_block,
data.lane.into(),
data.messages_start..=data.messages_end,
data.outbound_state_proof_required,
Expand Down
2 changes: 2 additions & 0 deletions bridges/relays/lib-substrate-relay/src/messages_lane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ pub async fn relay_messages_range<P: SubstrateMessageLane>(
target_client: Client<P::TargetChain>,
source_transaction_params: TransactionParams<AccountKeyPairOf<P::SourceChain>>,
target_transaction_params: TransactionParams<AccountKeyPairOf<P::TargetChain>>,
at_source_block: HeaderIdOf<P::SourceChain>,
lane_id: LaneId,
range: RangeInclusive<MessageNonce>,
outbound_state_proof_required: bool,
Expand Down Expand Up @@ -309,6 +310,7 @@ where
target_transaction_params,
None,
),
at_source_block,
range,
outbound_state_proof_required,
)
Expand Down
14 changes: 1 addition & 13 deletions bridges/relays/messages/src/message_race_delivery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,10 @@ pub async fn run<P: MessageLane>(
pub async fn relay_messages_range<P: MessageLane>(
source_client: impl MessageLaneSourceClient<P>,
target_client: impl MessageLaneTargetClient<P>,
at: SourceHeaderIdOf<P>,
range: RangeInclusive<MessageNonce>,
outbound_state_proof_required: bool,
) -> Result<(), ()> {
// select best source chain header to use as anchor later
let at = source_client
.state()
.await
.map_err(|e| {
log::error!(
target: "bridge",
"Failed to get state of {}: {:?}",
P::SOURCE_NAME,
e,
);
})?
.best_self;
// compute cumulative dispatch weight of all messages in given range
let dispatch_weight = source_client
.generated_message_details(at.clone(), range.clone())
Expand Down

0 comments on commit 1450c3d

Please sign in to comment.