Skip to content

Commit 4942c12

Browse files
authored
submit lane unblock transactions from relay (#2030)
* submit lane unblock transactions from relay * moved body of select_nonces_to_deliver to the separate select_race_action * extracted latest_confirmed_nonce_at_source method * return Option<RaceAction> from select_race_action * make required_source_header_at_target async * remove extra argument from required_source_header_at_target * small fixes in tests * Revert "return Option<RaceAction> from select_race_action" This reverts commit 9f13dbf. * implement required_source_header_at_target using what-if approach * fix compilation * fmt * clippy * moved some code to the can_submit_transaction_with
1 parent c0325d3 commit 4942c12

File tree

8 files changed

+429
-194
lines changed

8 files changed

+429
-194
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

relays/client-substrate/src/chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub trait Chain: ChainBase + Clone {
5555
/// Block type.
5656
type SignedBlock: Member + Serialize + DeserializeOwned + BlockWithJustification<Self::Header>;
5757
/// The aggregated `Call` type.
58-
type Call: Clone + Codec + Debug + Send;
58+
type Call: Clone + Codec + Debug + Send + Sync;
5959
}
6060

6161
/// Substrate-based relay chain that supports parachains.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<AccountId> TaggedAccount<AccountId> {
9191
}
9292

9393
/// Batch call builder.
94-
pub trait BatchCallBuilder<Call>: Clone + Send {
94+
pub trait BatchCallBuilder<Call>: Clone + Send + Sync {
9595
/// Create batch call from given calls vector.
9696
fn build_batch_call(&self, _calls: Vec<Call>) -> Call;
9797
}

relays/messages/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
88
[dependencies]
99
async-std = { version = "1.6.5", features = ["attributes"] }
1010
async-trait = "0.1"
11+
env_logger = "0.10"
1112
futures = "0.3.28"
1213
hex = "0.4"
1314
log = "0.4.17"

relays/messages/src/message_lane_loop.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub struct NoncesSubmitArtifacts<T> {
111111

112112
/// Batch transaction that already submit some headers and needs to be extended with
113113
/// messages/delivery proof before sending.
114-
pub trait BatchTransaction<HeaderId>: Debug + Send {
114+
pub trait BatchTransaction<HeaderId>: Debug + Send + Sync {
115115
/// Header that was required in the original call and which is bundled within this
116116
/// batch transaction.
117117
fn required_header_id(&self) -> HeaderId;
@@ -622,22 +622,38 @@ pub(crate) mod tests {
622622
}
623623

624624
impl TestClientData {
625-
fn receive_messages(&mut self, proof: TestMessagesProof) {
625+
fn receive_messages(
626+
&mut self,
627+
maybe_batch_tx: Option<TestMessagesBatchTransaction>,
628+
proof: TestMessagesProof,
629+
) {
626630
self.target_state.best_self =
627631
HeaderId(self.target_state.best_self.0 + 1, self.target_state.best_self.1 + 1);
628632
self.target_state.best_finalized_self = self.target_state.best_self;
629633
self.target_latest_received_nonce = *proof.0.end();
634+
if let Some(maybe_batch_tx) = maybe_batch_tx {
635+
self.target_state.best_finalized_peer_at_best_self =
636+
Some(maybe_batch_tx.required_header_id());
637+
}
630638
if let Some(target_latest_confirmed_received_nonce) = proof.1 {
631639
self.target_latest_confirmed_received_nonce =
632640
target_latest_confirmed_received_nonce;
633641
}
634642
self.submitted_messages_proofs.push(proof);
635643
}
636644

637-
fn receive_messages_delivery_proof(&mut self, proof: TestMessagesReceivingProof) {
645+
fn receive_messages_delivery_proof(
646+
&mut self,
647+
maybe_batch_tx: Option<TestConfirmationBatchTransaction>,
648+
proof: TestMessagesReceivingProof,
649+
) {
638650
self.source_state.best_self =
639651
HeaderId(self.source_state.best_self.0 + 1, self.source_state.best_self.1 + 1);
640652
self.source_state.best_finalized_self = self.source_state.best_self;
653+
if let Some(maybe_batch_tx) = maybe_batch_tx {
654+
self.source_state.best_finalized_peer_at_best_self =
655+
Some(maybe_batch_tx.required_header_id());
656+
}
641657
self.submitted_messages_receiving_proofs.push(proof);
642658
self.source_latest_confirmed_received_nonce = proof;
643659
}
@@ -760,13 +776,13 @@ pub(crate) mod tests {
760776

761777
async fn submit_messages_receiving_proof(
762778
&self,
763-
_maybe_batch_tx: Option<Self::BatchTransaction>,
779+
maybe_batch_tx: Option<Self::BatchTransaction>,
764780
_generated_at_block: TargetHeaderIdOf<TestMessageLane>,
765781
proof: TestMessagesReceivingProof,
766782
) -> Result<Self::TransactionTracker, TestError> {
767783
let mut data = self.data.lock();
768784
(self.tick)(&mut data);
769-
data.receive_messages_delivery_proof(proof);
785+
data.receive_messages_delivery_proof(maybe_batch_tx, proof);
770786
(self.post_tick)(&mut data);
771787
Ok(TestTransactionTracker(data.source_tracked_transaction_status))
772788
}
@@ -885,7 +901,7 @@ pub(crate) mod tests {
885901

886902
async fn submit_messages_proof(
887903
&self,
888-
_maybe_batch_tx: Option<Self::BatchTransaction>,
904+
maybe_batch_tx: Option<Self::BatchTransaction>,
889905
_generated_at_header: SourceHeaderIdOf<TestMessageLane>,
890906
nonces: RangeInclusive<MessageNonce>,
891907
proof: TestMessagesProof,
@@ -895,7 +911,7 @@ pub(crate) mod tests {
895911
if data.is_target_fails {
896912
return Err(TestError)
897913
}
898-
data.receive_messages(proof);
914+
data.receive_messages(maybe_batch_tx, proof);
899915
(self.post_tick)(&mut data);
900916
Ok(NoncesSubmitArtifacts {
901917
nonces,

0 commit comments

Comments
 (0)