use tokio reactor to execute jsonrpsee futures (#1061)

This commit is contained in:
Svyatoslav Nikolsky
2021-07-20 15:18:51 +03:00
committed by Bastian Köcher
parent 08fd53adef
commit 63d6fc436a
13 changed files with 337 additions and 168 deletions
@@ -176,10 +176,11 @@ impl SendMessage {
fee,
})?;
let source_genesis_hash = *source_client.genesis_hash();
source_client
.submit_signed_extrinsic(source_sign.public().into(), |transaction_nonce| {
.submit_signed_extrinsic(source_sign.public().into(), move |transaction_nonce| {
let signed_source_call = Source::sign_transaction(
*source_client.genesis_hash(),
source_genesis_hash,
&source_sign,
transaction_nonce,
send_message_call,
@@ -80,10 +80,11 @@ where
}
async fn submit_finality_proof(&self, header: P::Header, proof: P::FinalityProof) -> Result<(), SubstrateError> {
let transactions_author = self.pipeline.transactions_author();
let pipeline = self.pipeline.clone();
self.client
.submit_signed_extrinsic(self.pipeline.transactions_author(), move |transaction_nonce| {
self.pipeline
.make_submit_finality_proof_transaction(transaction_nonce, header, proof)
.submit_signed_extrinsic(transactions_author, move |transaction_nonce| {
pipeline.make_submit_finality_proof_transaction(transaction_nonce, header, proof)
})
.await
.map(drop)
@@ -39,7 +39,9 @@ pub async fn initialize<SourceChain: Chain, TargetChain: Chain>(
source_client: Client<SourceChain>,
target_client: Client<TargetChain>,
target_transactions_signer: TargetChain::AccountId,
prepare_initialize_transaction: impl FnOnce(TargetChain::Index, InitializationData<SourceChain::Header>) -> Bytes,
prepare_initialize_transaction: impl FnOnce(TargetChain::Index, InitializationData<SourceChain::Header>) -> Bytes
+ Send
+ 'static,
) {
let result = do_initialize(
source_client,
@@ -72,7 +74,9 @@ async fn do_initialize<SourceChain: Chain, TargetChain: Chain>(
source_client: Client<SourceChain>,
target_client: Client<TargetChain>,
target_transactions_signer: TargetChain::AccountId,
prepare_initialize_transaction: impl FnOnce(TargetChain::Index, InitializationData<SourceChain::Header>) -> Bytes,
prepare_initialize_transaction: impl FnOnce(TargetChain::Index, InitializationData<SourceChain::Header>) -> Bytes
+ Send
+ 'static,
) -> Result<TargetChain::Hash, String> {
let initialization_data = prepare_initialization_data(source_client).await?;
log::info!(
@@ -102,7 +106,7 @@ async fn prepare_initialization_data<SourceChain: Chain>(
// But now there are problems with this approach - `CurrentSetId` may return invalid value. So here
// we're waiting for the next justification, read the authorities set and then try to figure out
// the set id with bruteforce.
let mut justifications = source_client
let justifications = source_client
.subscribe_justifications()
.await
.map_err(|err| format!("Failed to subscribe to {} justifications: {:?}", SourceChain::NAME, err))?;
@@ -233,10 +233,10 @@ where
generated_at_block: TargetHeaderIdOf<P>,
proof: P::MessagesReceivingProof,
) -> Result<(), SubstrateError> {
let lane = self.lane.clone();
self.client
.submit_signed_extrinsic(self.lane.source_transactions_author(), move |transaction_nonce| {
self.lane
.make_messages_receiving_proof_transaction(transaction_nonce, generated_at_block, proof)
lane.make_messages_receiving_proof_transaction(transaction_nonce, generated_at_block, proof)
})
.await?;
Ok(())
@@ -219,14 +219,11 @@ where
nonces: RangeInclusive<MessageNonce>,
proof: P::MessagesProof,
) -> Result<RangeInclusive<MessageNonce>, SubstrateError> {
let lane = self.lane.clone();
let nonces_clone = nonces.clone();
self.client
.submit_signed_extrinsic(self.lane.target_transactions_author(), |transaction_nonce| {
self.lane.make_messages_delivery_transaction(
transaction_nonce,
generated_at_header,
nonces.clone(),
proof,
)
.submit_signed_extrinsic(self.lane.target_transactions_author(), move |transaction_nonce| {
lane.make_messages_delivery_transaction(transaction_nonce, generated_at_header, nonces_clone, proof)
})
.await?;
Ok(nonces)