Skip to content

Commit 3696973

Browse files
authored
Submit the unsigned extrinsics synchronously (#720)
* Do not submit unsigned extrinsics in a background task for gossiped handler The backpressure is no longer an issue when submitting them synchronously, see more info at #695 (comment) * Do not submit frauf prood in a background back in bundles processor and add a TODO * Inline the helper functions to submit unsigned extrinsics and fix cargo doc It's not equivolent as before, but it's fine to return an error in my opinion.
1 parent 9c69b3a commit 3696973

File tree

2 files changed

+28
-123
lines changed

2 files changed

+28
-123
lines changed

cumulus/client/cirrus-executor/src/bundle_processor.rs

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::{ExecutionReceiptFor, SignedExecutionReceiptFor, TransactionFor};
33
use cirrus_block_builder::{BlockBuilder, BuiltBlock, RecordProof};
44
use cirrus_primitives::{AccountId, SecondaryApi};
55
use codec::{Decode, Encode};
6-
use futures::FutureExt;
76
use rand::seq::SliceRandom;
87
use rand::SeedableRng;
98
use rand_chacha::ChaCha8Rng;
@@ -19,7 +18,7 @@ use sp_consensus::BlockOrigin;
1918
use sp_core::traits::{CodeExecutor, SpawnNamed};
2019
use sp_core::ByteArray;
2120
use sp_executor::{
22-
ExecutionReceipt, ExecutorApi, ExecutorId, ExecutorSignature, FraudProof, OpaqueBundle,
21+
ExecutionReceipt, ExecutorApi, ExecutorId, ExecutorSignature, OpaqueBundle,
2322
SignedExecutionReceipt,
2423
};
2524
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
@@ -178,6 +177,7 @@ where
178177
}
179178
}
180179

180+
// TODO: Handle the returned error properly, ref to https://github.com/subspace/subspace/pull/695#discussion_r926721185
181181
pub(crate) async fn process_bundles(
182182
self,
183183
(primary_hash, primary_number): (PBlock::Hash, NumberFor<PBlock>),
@@ -619,41 +619,17 @@ where
619619
)))
620620
})?;
621621

622-
self.submit_fraud_proof(fraud_proof);
622+
self.primary_chain_client
623+
.runtime_api()
624+
.submit_fraud_proof_unsigned(
625+
&BlockId::Hash(self.primary_chain_client.info().best_hash),
626+
fraud_proof,
627+
)?;
623628
}
624629

625630
Ok(())
626631
}
627632

628-
fn submit_fraud_proof(&self, fraud_proof: FraudProof) {
629-
let primary_chain_client = self.primary_chain_client.clone();
630-
// TODO: No backpressure
631-
self.spawner.spawn_blocking(
632-
"cirrus-submit-fraud-proof",
633-
None,
634-
async move {
635-
tracing::debug!(
636-
target: LOG_TARGET,
637-
"Submitting fraud proof in a background task..."
638-
);
639-
if let Err(error) = primary_chain_client
640-
.runtime_api()
641-
.submit_fraud_proof_unsigned(
642-
&BlockId::Hash(primary_chain_client.info().best_hash),
643-
fraud_proof,
644-
)
645-
{
646-
tracing::error!(
647-
target: LOG_TARGET,
648-
error = ?error,
649-
"Failed to submit fraud proof"
650-
);
651-
}
652-
}
653-
.boxed(),
654-
);
655-
}
656-
657633
fn try_sign_and_send_receipt(
658634
&self,
659635
primary_hash: PBlock::Hash,

cumulus/client/cirrus-executor/src/lib.rs

Lines changed: 20 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
//!
5757
//! [Computation section]: https://subspace.network/news/subspace-network-whitepaper
5858
//! [`BlockBuilder`]: ../cirrus_block_builder/struct.BlockBuilder.html
59+
//! [`FraudProof`]: ../sp_executor/struct.FraudProof.html
5960
6061
#![feature(drain_filter)]
6162

@@ -85,7 +86,7 @@ use sp_consensus::{BlockStatus, SelectChain};
8586
use sp_consensus_slots::Slot;
8687
use sp_core::traits::{CodeExecutor, SpawnEssentialNamed, SpawnNamed};
8788
use sp_executor::{
88-
Bundle, BundleEquivocationProof, ExecutionReceipt, ExecutorApi, ExecutorId, FraudProof,
89+
Bundle, BundleEquivocationProof, ExecutionReceipt, ExecutorApi, ExecutorId,
8990
InvalidTransactionProof, OpaqueBundle, SignedBundle, SignedExecutionReceipt,
9091
};
9192
use sp_keystore::SyncCryptoStorePtr;
@@ -323,93 +324,6 @@ where
323324
}
324325
}
325326

326-
fn submit_bundle_equivocation_proof(&self, bundle_equivocation_proof: BundleEquivocationProof) {
327-
let primary_chain_client = self.primary_chain_client.clone();
328-
// TODO: No backpressure
329-
self.spawner.spawn_blocking(
330-
"cirrus-submit-bundle-equivocation-proof",
331-
None,
332-
async move {
333-
tracing::debug!(
334-
target: LOG_TARGET,
335-
"Submitting bundle equivocation proof in a background task..."
336-
);
337-
if let Err(error) = primary_chain_client
338-
.runtime_api()
339-
.submit_bundle_equivocation_proof_unsigned(
340-
&BlockId::Hash(primary_chain_client.info().best_hash),
341-
bundle_equivocation_proof,
342-
)
343-
{
344-
tracing::error!(
345-
target: LOG_TARGET,
346-
error = ?error,
347-
"Failed to submit bundle equivocation proof"
348-
);
349-
}
350-
}
351-
.boxed(),
352-
);
353-
}
354-
355-
fn submit_fraud_proof(&self, fraud_proof: FraudProof) {
356-
let primary_chain_client = self.primary_chain_client.clone();
357-
// TODO: No backpressure
358-
self.spawner.spawn_blocking(
359-
"cirrus-submit-fraud-proof",
360-
None,
361-
async move {
362-
tracing::debug!(
363-
target: LOG_TARGET,
364-
"Submitting fraud proof in a background task..."
365-
);
366-
if let Err(error) = primary_chain_client
367-
.runtime_api()
368-
.submit_fraud_proof_unsigned(
369-
&BlockId::Hash(primary_chain_client.info().best_hash),
370-
fraud_proof,
371-
)
372-
{
373-
tracing::error!(
374-
target: LOG_TARGET,
375-
error = ?error,
376-
"Failed to submit fraud proof"
377-
);
378-
}
379-
}
380-
.boxed(),
381-
);
382-
}
383-
384-
fn submit_invalid_transaction_proof(&self, invalid_transaction_proof: InvalidTransactionProof) {
385-
let primary_chain_client = self.primary_chain_client.clone();
386-
// TODO: No backpressure
387-
self.spawner.spawn_blocking(
388-
"cirrus-submit-invalid-transaction-proof",
389-
None,
390-
async move {
391-
tracing::debug!(
392-
target: LOG_TARGET,
393-
"Submitting invalid transaction proof in a background task..."
394-
);
395-
if let Err(error) = primary_chain_client
396-
.runtime_api()
397-
.submit_invalid_transaction_proof_unsigned(
398-
&BlockId::Hash(primary_chain_client.info().best_hash),
399-
invalid_transaction_proof,
400-
)
401-
{
402-
tracing::error!(
403-
target: LOG_TARGET,
404-
error = ?error,
405-
"Failed to submit invalid transaction proof"
406-
);
407-
}
408-
}
409-
.boxed(),
410-
);
411-
}
412-
413327
/// The background is that a receipt received from the network points to a future block
414328
/// from the local view, so we need to wait for the receipt for the block at the same
415329
/// height to be produced locally in order to check the validity of the external receipt.
@@ -581,7 +495,12 @@ where
581495

582496
// A bundle equivocation occurs.
583497
if let Some(equivocation_proof) = check_equivocation(bundle) {
584-
self.submit_bundle_equivocation_proof(equivocation_proof);
498+
self.primary_chain_client
499+
.runtime_api()
500+
.submit_bundle_equivocation_proof_unsigned(
501+
&BlockId::Hash(self.primary_chain_client.info().best_hash),
502+
equivocation_proof,
503+
)?;
585504
return Err(GossipMessageError::BundleEquivocation);
586505
}
587506

@@ -622,7 +541,12 @@ where
622541
// if illegal => illegal tx proof
623542
let invalid_transaction_proof = InvalidTransactionProof;
624543

625-
self.submit_invalid_transaction_proof(invalid_transaction_proof);
544+
self.primary_chain_client
545+
.runtime_api()
546+
.submit_invalid_transaction_proof_unsigned(
547+
&BlockId::Hash(self.primary_chain_client.info().best_hash),
548+
invalid_transaction_proof,
549+
)?;
626550
}
627551
}
628552

@@ -726,7 +650,12 @@ where
726650
signed_receipt_hash,
727651
)?;
728652

729-
self.submit_fraud_proof(fraud_proof);
653+
self.primary_chain_client
654+
.runtime_api()
655+
.submit_fraud_proof_unsigned(
656+
&BlockId::Hash(self.primary_chain_client.info().best_hash),
657+
fraud_proof,
658+
)?;
730659

731660
Ok(Action::Empty)
732661
} else {

0 commit comments

Comments
 (0)