Batch transactions in complex relays (#1669)

* batch transactions in message relay: API prototype

* get rid of Box<dyn BatchTransaction> and actually submit it

* test batch transactions

* message_lane_loop_works_with_batch_transactions

* removed logger

* BatchConfirmationTransaction + BatchDeliveryTransaction

* more prototyping

* fmt

* continue with batch calls

* impl BatchCallBuilder for ()

* BatchDeliveryTransaction impl

* BundledBatchCallBuilder

* proper impl of BundledBatchCallBuilder + use it in RialtoParachain -> Millau

* impl prove_header in OnDemandHeadersRelay

* impl OnDemandParachainsRelay::prove_header (needs extensive tests)

* added a couple of TODOs

* return Result<Option<BatchTx>> when asking for more headers

* prove headers when reauire_* is called && return proper headers from required_header_id

* split parachains::prove_header and test select_headers_to_prove

* more traces and leave TODOs

* use finality stream in SubstrateFinalitySource::prove_block_finality

* prove parachain head at block, selected by headers relay

* const ANCIENT_BLOCK_THRESHOLD

* TODO -> proof

* clippy and spelling

* BatchCallBuilder::build_batch_call() returns Result

* read first proof from two streams

* FailedToFindFinalityProof -> FinalityProofNotFound

* changed select_headers_to_prove to version from PR review
This commit is contained in:
Svyatoslav Nikolsky
2022-12-16 15:04:36 +03:00
committed by Bastian Köcher
parent a732a04ed4
commit be27bd5e97
28 changed files with 1190 additions and 152 deletions
@@ -18,6 +18,9 @@
#![warn(missing_docs)]
use relay_substrate_client::Error as SubstrateError;
use std::marker::PhantomData;
pub mod error;
pub mod finality;
pub mod messages_lane;
@@ -96,3 +99,52 @@ impl<AccountId> TaggedAccount<AccountId> {
}
}
}
/// Batch call builder.
pub trait BatchCallBuilder<Call> {
/// Associated error type.
type Error;
/// If `true`, then batch calls are supported at the chain.
const BATCH_CALL_SUPPORTED: bool;
/// Create batch call from given calls vector.
fn build_batch_call(_calls: Vec<Call>) -> Result<Call, Self::Error>;
}
impl<Call> BatchCallBuilder<Call> for () {
type Error = SubstrateError;
const BATCH_CALL_SUPPORTED: bool = false;
fn build_batch_call(_calls: Vec<Call>) -> Result<Call, SubstrateError> {
debug_assert!(
false,
"only called if `BATCH_CALL_SUPPORTED` is true;\
`BATCH_CALL_SUPPORTED` is false;\
qed"
);
Err(SubstrateError::Custom("<() as BatchCallBuilder>::build_batch_call() is called".into()))
}
}
/// Batch call builder for bundled runtimes.
pub struct BundledBatchCallBuilder<R>(PhantomData<R>);
impl<R> BatchCallBuilder<<R as frame_system::Config>::RuntimeCall> for BundledBatchCallBuilder<R>
where
R: pallet_utility::Config<RuntimeCall = <R as frame_system::Config>::RuntimeCall>,
<R as frame_system::Config>::RuntimeCall: From<pallet_utility::Call<R>>,
{
type Error = SubstrateError;
const BATCH_CALL_SUPPORTED: bool = true;
fn build_batch_call(
mut calls: Vec<<R as frame_system::Config>::RuntimeCall>,
) -> Result<<R as frame_system::Config>::RuntimeCall, SubstrateError> {
Ok(if calls.len() == 1 {
calls.remove(0)
} else {
pallet_utility::Call::batch_all { calls }.into()
})
}
}