Skip to content

Commit

Permalink
Use checkpoint sigs from batches without waiting for a commit (Mysten…
Browse files Browse the repository at this point in the history
…Labs#12880)

On a local cluster this appears to reduce checkpoint_summary_age_ms p50
from ~2000ms to ~600ms
  • Loading branch information
mystenmark authored Jul 7, 2023
1 parent 60320db commit 2dfd307
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions crates/sui-core/src/authority/authority_per_epoch_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,9 @@ impl AuthorityPerEpochStore {
kind: ConsensusTransactionKind::CheckpointSignature(info),
..
}) => {
// We usually call notify_checkpoint_signature in SuiTxValidator, but that step can
// be skipped when a batch is already part of a certificate, so we must also
// notify here.
checkpoint_service.notify_checkpoint_signature(self, info)?;
self.record_consensus_transaction_processed(batch, transaction, consensus_index)?;
Ok(ConsensusCertificateResult::ConsensusMessage)
Expand Down
3 changes: 2 additions & 1 deletion crates/sui-core/src/checkpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,8 @@ impl CheckpointSignatureAggregator {
let their_digest = *data.summary.digest();
let (_, signature) = data.summary.into_data_and_sig();
let author = signature.authority;
// consensus ensures that authority == narwhal_cert.author
// It is not guaranteed that signature.authority == narwhal_cert.author, but we do verify
// the signature so we know that the author signed the message at some point.
if their_digest != self.digest {
self.metrics.remote_checkpoint_forks.inc();
warn!(
Expand Down
18 changes: 17 additions & 1 deletion crates/sui-core/src/consensus_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::sync::Arc;
use sui_protocol_config::ProtocolConfig;

use crate::authority::authority_per_epoch_store::AuthorityPerEpochStore;
use crate::checkpoints::CheckpointServiceNotify;
use crate::transaction_manager::TransactionManager;
use async_trait::async_trait;
use narwhal_types::{validate_batch_version, BatchAPI};
Expand All @@ -21,13 +22,15 @@ use tracing::{info, warn};
#[derive(Clone)]
pub struct SuiTxValidator {
epoch_store: Arc<AuthorityPerEpochStore>,
checkpoint_service: Arc<dyn CheckpointServiceNotify + Send + Sync>,
_transaction_manager: Arc<TransactionManager>,
metrics: Arc<SuiTxValidatorMetrics>,
}

impl SuiTxValidator {
pub fn new(
epoch_store: Arc<AuthorityPerEpochStore>,
checkpoint_service: Arc<dyn CheckpointServiceNotify + Send + Sync>,
transaction_manager: Arc<TransactionManager>,
metrics: Arc<SuiTxValidatorMetrics>,
) -> Self {
Expand All @@ -37,6 +40,7 @@ impl SuiTxValidator {
);
Self {
epoch_store,
checkpoint_service,
_transaction_manager: transaction_manager,
metrics,
}
Expand Down Expand Up @@ -75,6 +79,7 @@ impl TransactionValidator for SuiTxValidator {
.collect::<Result<Vec<_>, _>>()?;

let mut cert_batch = Vec::new();
let mut ckpt_messages = Vec::new();
let mut ckpt_batch = Vec::new();
for tx in txs.into_iter() {
match tx.kind {
Expand All @@ -88,7 +93,8 @@ impl TransactionValidator for SuiTxValidator {
// }
}
ConsensusTransactionKind::CheckpointSignature(signature) => {
ckpt_batch.push(signature.summary)
ckpt_messages.push(signature.clone());
ckpt_batch.push(signature.summary);
}
ConsensusTransactionKind::EndOfPublish(_)
| ConsensusTransactionKind::CapabilityNotification(_) => {}
Expand All @@ -108,6 +114,13 @@ impl TransactionValidator for SuiTxValidator {
.wrap_err("Malformed batch (failed to verify)")
})
.await??;

// All checkpoint sigs have been verified, forward them to the checkpoint service
for ckpt in ckpt_messages {
self.checkpoint_service
.notify_checkpoint_signature(&self.epoch_store, &ckpt)?;
}

self.metrics
.certificate_signatures_verified
.inc_by(cert_count as u64);
Expand Down Expand Up @@ -154,6 +167,7 @@ impl SuiTxValidatorMetrics {
#[cfg(test)]
mod tests {
use crate::{
checkpoints::CheckpointServiceNoop,
consensus_adapter::consensus_tests::{test_certificates, test_gas_objects},
consensus_validator::{SuiTxValidator, SuiTxValidatorMetrics},
};
Expand All @@ -164,6 +178,7 @@ mod tests {
use sui_types::signature::GenericSignature;

use crate::authority::test_authority_builder::TestAuthorityBuilder;
use std::sync::Arc;
use sui_macros::sim_test;
use sui_types::crypto::Ed25519SuiSignature;
use sui_types::messages_consensus::ConsensusTransaction;
Expand Down Expand Up @@ -199,6 +214,7 @@ mod tests {
let metrics = SuiTxValidatorMetrics::new(&Default::default());
let validator = SuiTxValidator::new(
state.epoch_store_for_testing().clone(),
Arc::new(CheckpointServiceNoop {}),
state.transaction_manager().clone(),
metrics,
);
Expand Down
1 change: 1 addition & 0 deletions crates/sui-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ impl SuiNode {
consensus_handler,
SuiTxValidator::new(
epoch_store,
checkpoint_service.clone(),
state.transaction_manager().clone(),
sui_tx_validator_metrics.clone(),
),
Expand Down

0 comments on commit 2dfd307

Please sign in to comment.