Skip to content

Commit

Permalink
make SubmitToConsensus trait non-async
Browse files Browse the repository at this point in the history
  • Loading branch information
aschran committed Jan 30, 2025
1 parent b0e76cc commit 58b21d6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
3 changes: 1 addition & 2 deletions crates/sui-core/src/checkpoints/checkpoint_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ impl<T: SubmitToConsensus + ReconfigurationInitiator> CheckpointOutput
let message = CheckpointSignatureMessage { summary };
let transaction = ConsensusTransaction::new_checkpoint_signature_message(message);
self.sender
.submit_to_consensus(&vec![transaction], epoch_store)
.await?;
.submit_to_consensus(&vec![transaction], epoch_store)?;
self.metrics
.last_sent_checkpoint_signature
.set(checkpoint_seq as i64);
Expand Down
6 changes: 2 additions & 4 deletions crates/sui-core/src/consensus_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ pub trait ConsensusOverloadChecker: Sync + Send + 'static {
pub type BlockStatusReceiver = oneshot::Receiver<BlockStatus>;

#[mockall::automock]
#[async_trait::async_trait]
pub trait SubmitToConsensus: Sync + Send + 'static {
async fn submit_to_consensus(
fn submit_to_consensus(
&self,
transactions: &[ConsensusTransaction],
epoch_store: &Arc<AuthorityPerEpochStore>,
Expand Down Expand Up @@ -1278,9 +1277,8 @@ impl<'a> Drop for InflightDropGuard<'a> {
}
}

#[async_trait::async_trait]
impl SubmitToConsensus for Arc<ConsensusAdapter> {
async fn submit_to_consensus(
fn submit_to_consensus(
&self,
transactions: &[ConsensusTransaction],
epoch_store: &Arc<AuthorityPerEpochStore>,
Expand Down
6 changes: 2 additions & 4 deletions crates/sui-core/src/epoch/randomness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ impl RandomnessManager {
});
if !fail_point_skip_sending {
self.consensus_adapter
.submit_to_consensus(&[transaction], &epoch_store)
.await?;
.submit_to_consensus(&[transaction], &epoch_store)?;
}

epoch_store
Expand Down Expand Up @@ -495,8 +494,7 @@ impl RandomnessManager {
});
if !fail_point_skip_sending {
self.consensus_adapter
.submit_to_consensus(&[transaction], &epoch_store)
.await?;
.submit_to_consensus(&[transaction], &epoch_store)?;
}

let elapsed = self.dkg_start_time.get().map(|t| t.elapsed().as_millis());
Expand Down
34 changes: 17 additions & 17 deletions crates/sui-core/src/mock_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::consensus_handler::SequencedConsensusTransaction;
use consensus_core::BlockRef;
use prometheus::Registry;
use std::sync::{Arc, Weak};
use sui_types::error::{SuiError, SuiResult};
use sui_types::error::SuiResult;
use sui_types::executable_transaction::VerifiedExecutableTransaction;
use sui_types::messages_consensus::{ConsensusTransaction, ConsensusTransactionKind};
use sui_types::transaction::{VerifiedCertificate, VerifiedTransaction};
Expand Down Expand Up @@ -96,18 +96,27 @@ impl MockConsensusClient {
}
}
}

fn submit_impl(&self, transactions: &[ConsensusTransaction]) -> SuiResult<BlockStatusReceiver> {
// TODO: maybe support multi-transactions and remove this check
assert!(transactions.len() == 1);
let transaction = &transactions[0];
self.tx_sender
.try_send(transaction.clone())
.expect("MockConsensusClient channel should not overflow");
Ok(with_block_status(consensus_core::BlockStatus::Sequenced(
BlockRef::MIN,
)))
}
}

#[async_trait::async_trait]
impl SubmitToConsensus for MockConsensusClient {
async fn submit_to_consensus(
fn submit_to_consensus(
&self,
transactions: &[ConsensusTransaction],
epoch_store: &Arc<AuthorityPerEpochStore>,
_epoch_store: &Arc<AuthorityPerEpochStore>,
) -> SuiResult {
self.submit(transactions, epoch_store)
.await
.map(|_response| ())
self.submit_impl(transactions).map(|_response| ())
}
}

Expand All @@ -118,16 +127,7 @@ impl ConsensusClient for MockConsensusClient {
transactions: &[ConsensusTransaction],
_epoch_store: &Arc<AuthorityPerEpochStore>,
) -> SuiResult<BlockStatusReceiver> {
// TODO: maybe support multi-transactions and remove this check
assert!(transactions.len() == 1);
let transaction = &transactions[0];
self.tx_sender
.send(transaction.clone())
.await
.map_err(|e| SuiError::Unknown(e.to_string()))?;
Ok(with_block_status(consensus_core::BlockStatus::Sequenced(
BlockRef::MIN,
)))
self.submit_impl(transactions)
}
}

Expand Down

0 comments on commit 58b21d6

Please sign in to comment.