Skip to content

Commit d32fb4d

Browse files
committed
BatchDeliveryTransaction impl
1 parent 0dcdec8 commit d32fb4d

File tree

3 files changed

+60
-13
lines changed

3 files changed

+60
-13
lines changed

relays/lib-substrate-relay/src/messages_lane.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ pub trait BatchCallBuilder<C: Chain> {
213213
impl<C: Chain> BatchCallBuilder<C> for () {
214214
const BATCH_CALL_SUPPORTED: bool = false;
215215

216-
fn build_batch_call(calls: Vec<CallOf<C>>) -> CallOf<C> {
216+
fn build_batch_call(_calls: Vec<CallOf<C>>) -> CallOf<C> {
217217
unreachable!(
218218
"only called if `BATCH_CALL_SUPPORTED` is true;\
219219
`BATCH_CALL_SUPPORTED` is false;\

relays/lib-substrate-relay/src/messages_source.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ where
418418
proof, false,
419419
),
420420
);
421-
422421
let batch_call = P::SourceBatchCallBuilder::build_batch_call(calls);
423422

424423
let (spec_version, transaction_version) =

relays/lib-substrate-relay/src/messages_target.rs

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use messages_relay::{
3939
message_lane_loop::{BatchTransaction, NoncesSubmitArtifacts, TargetClient, TargetClientState},
4040
};
4141
use relay_substrate_client::{
42-
AccountIdOf, AccountKeyPairOf, BalanceOf, Chain, ChainWithMessages, Client,
42+
AccountIdOf, AccountKeyPairOf, BalanceOf, CallOf, Chain, ChainWithMessages, Client,
4343
Error as SubstrateError, HashOf, HeaderIdOf, IndexOf, SignParam, TransactionEra,
4444
TransactionTracker, UnsignedTransaction,
4545
};
@@ -303,38 +303,86 @@ impl<P: SubstrateMessageLane>
303303
TransactionTracker<P::TargetChain, Client<P::TargetChain>>,
304304
SubstrateError,
305305
> for BatchDeliveryTransaction<P>
306+
where
307+
AccountIdOf<P::TargetChain>: From<<AccountKeyPairOf<P::TargetChain> as Pair>::Public>,
306308
{
307309
fn required_header_id(&self) -> SourceHeaderIdOf<MessageLaneAdapter<P>> {
308310
self.required_source_header_on_target.clone()
309311
}
310312

311313
async fn append_proof_and_send(
312314
self,
313-
_proof: <MessageLaneAdapter<P> as MessageLane>::MessagesProof,
315+
proof: <MessageLaneAdapter<P> as MessageLane>::MessagesProof,
314316
) -> Result<TransactionTracker<P::TargetChain, Client<P::TargetChain>>, SubstrateError> {
315-
unimplemented!("TODO")
317+
let mut calls = self
318+
.messages_target
319+
.source_to_target_headers_relay
320+
.as_ref()
321+
.expect("BatchDeliveryTransaction is only created when source_to_target_headers_relay is Some; qed")
322+
.prove_header(self.required_source_header_on_target.0)
323+
.await?;
324+
calls.push(make_messages_delivery_call::<P>(
325+
self.messages_target.relayer_id_at_source,
326+
proof.1.nonces_start..=proof.1.nonces_end,
327+
proof,
328+
false,
329+
));
330+
let batch_call = P::TargetBatchCallBuilder::build_batch_call(calls);
331+
332+
let (spec_version, transaction_version) =
333+
self.messages_target.target_client.simple_runtime_version().await?;
334+
self.messages_target
335+
.target_client
336+
.submit_and_watch_signed_extrinsic(
337+
self.messages_target.transaction_params.signer.public().into(),
338+
SignParam::<P::TargetChain> {
339+
spec_version,
340+
transaction_version,
341+
genesis_hash: *self.messages_target.target_client.genesis_hash(),
342+
signer: self.messages_target.transaction_params.signer.clone(),
343+
},
344+
move |best_block_id, transaction_nonce| {
345+
Ok(UnsignedTransaction::new(batch_call.into(), transaction_nonce).era(
346+
TransactionEra::new(
347+
best_block_id,
348+
self.messages_target.transaction_params.mortality,
349+
),
350+
))
351+
},
352+
)
353+
.await
316354
}
317355
}
318356

319-
/// Make messages delivery transaction from given proof.
320-
fn make_messages_delivery_transaction<P: SubstrateMessageLane>(
321-
target_transaction_params: &TransactionParams<AccountKeyPairOf<P::TargetChain>>,
322-
target_best_block_id: HeaderIdOf<P::TargetChain>,
323-
transaction_nonce: IndexOf<P::TargetChain>,
357+
/// Make messages delivery call from given proof.
358+
fn make_messages_delivery_call<P: SubstrateMessageLane>(
324359
relayer_id_at_source: AccountIdOf<P::SourceChain>,
325360
nonces: RangeInclusive<MessageNonce>,
326361
proof: SubstrateMessagesProof<P::SourceChain>,
327362
trace_call: bool,
328-
) -> Result<UnsignedTransaction<P::TargetChain>, SubstrateError> {
363+
) -> CallOf<P::TargetChain> {
329364
let messages_count = nonces.end() - nonces.start() + 1;
330365
let dispatch_weight = proof.0;
331-
let call = P::ReceiveMessagesProofCallBuilder::build_receive_messages_proof_call(
366+
P::ReceiveMessagesProofCallBuilder::build_receive_messages_proof_call(
332367
relayer_id_at_source,
333368
proof,
334369
messages_count as _,
335370
dispatch_weight,
336371
trace_call,
337-
);
372+
)
373+
}
374+
375+
/// Make messages delivery transaction from given proof.
376+
fn make_messages_delivery_transaction<P: SubstrateMessageLane>(
377+
target_transaction_params: &TransactionParams<AccountKeyPairOf<P::TargetChain>>,
378+
target_best_block_id: HeaderIdOf<P::TargetChain>,
379+
transaction_nonce: IndexOf<P::TargetChain>,
380+
relayer_id_at_source: AccountIdOf<P::SourceChain>,
381+
nonces: RangeInclusive<MessageNonce>,
382+
proof: SubstrateMessagesProof<P::SourceChain>,
383+
trace_call: bool,
384+
) -> Result<UnsignedTransaction<P::TargetChain>, SubstrateError> {
385+
let call = make_messages_delivery_call::<P>(relayer_id_at_source, nonces, proof, trace_call);
338386
Ok(UnsignedTransaction::new(call.into(), transaction_nonce)
339387
.era(TransactionEra::new(target_best_block_id, target_transaction_params.mortality)))
340388
}

0 commit comments

Comments
 (0)