Skip to content

Commit 7284f29

Browse files
committed
improve logging
1 parent 49acc65 commit 7284f29

File tree

5 files changed

+130
-50
lines changed

5 files changed

+130
-50
lines changed

consensus/core/src/commit_observer.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl CommitObserver {
215215
.recover_commits_to_write(unsent_commits.clone());
216216

217217
info!(
218-
"Recovered {} unsent commits in range [{start_index}..={end_index}]",
218+
"Recovering {} unsent commits in range [{start_index}..={end_index}]",
219219
unsent_commits.len()
220220
);
221221

@@ -245,9 +245,13 @@ impl CommitObserver {
245245
reputation_scores,
246246
);
247247

248-
if !committed_sub_dag.recovered_rejected_transactions {
248+
if !committed_sub_dag.recovered_rejected_transactions && !seen_unfinalized_commit {
249+
info!(
250+
"Starting to recover unfinalized commit from {}",
251+
committed_sub_dag.commit_ref
252+
);
249253
// When the commit has no associated storage entry for rejected transactions,
250-
// even if an empty set, the commit is unfinalized.
254+
// not even an empty set, the commit is unfinalized.
251255
seen_unfinalized_commit = true;
252256
}
253257

crates/sui-core/src/checkpoints/mod.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::execution_cache::TransactionCacheRead;
2222
use crate::execution_scheduler::balance_withdraw_scheduler::BalanceSettlement;
2323
use crate::global_state_hasher::GlobalStateHasher;
2424
use crate::stake_aggregator::{InsertResult, MultiStakeAggregator};
25+
use consensus_core::CommitRef;
2526
use diffy::create_patch;
2627
use itertools::Itertools;
2728
use mysten_common::random::get_rng;
@@ -61,7 +62,9 @@ use sui_protocol_config::ProtocolVersion;
6162
use sui_types::base_types::{AuthorityName, EpochId, TransactionDigest};
6263
use sui_types::committee::StakeUnit;
6364
use sui_types::crypto::AuthorityStrongQuorumSignInfo;
64-
use sui_types::digests::{CheckpointContentsDigest, CheckpointDigest, TransactionEffectsDigest};
65+
use sui_types::digests::{
66+
CheckpointContentsDigest, CheckpointDigest, Digest, TransactionEffectsDigest,
67+
};
6568
use sui_types::effects::{TransactionEffects, TransactionEffectsAPI};
6669
use sui_types::error::{SuiErrorKind, SuiResult};
6770
use sui_types::gas::GasCostSummary;
@@ -105,6 +108,9 @@ pub struct PendingCheckpointInfo {
105108
// Computed in calculate_pending_checkpoint_height() from consensus round,
106109
// there is no guarantee that this is increasing per checkpoint, because of checkpoint splitting.
107110
pub checkpoint_height: CheckpointHeight,
111+
// Consensus commit ref and rejected transactions digest which corresponds to this checkpoint.
112+
pub consensus_commit_ref: CommitRef,
113+
pub rejected_transactions_digest: Digest,
108114
}
109115

110116
#[derive(Clone, Debug)]
@@ -1392,6 +1398,18 @@ impl CheckpointBuilder {
13921398
pendings: Vec<PendingCheckpoint>,
13931399
) -> CheckpointBuilderResult<CheckpointSequenceNumber> {
13941400
let _scope = monitored_scope("CheckpointBuilder::make_checkpoint");
1401+
1402+
let pending_ckpt_str = pendings
1403+
.iter()
1404+
.map(|p| {
1405+
format!(
1406+
"height={}, commit={}",
1407+
p.details().checkpoint_height,
1408+
p.details().consensus_commit_ref
1409+
)
1410+
})
1411+
.join("; ");
1412+
13951413
let last_details = pendings.last().unwrap().details().clone();
13961414

13971415
// Stores the transactions that should be included in the checkpoint. Transactions will be recorded in the checkpoint
@@ -1419,8 +1437,18 @@ impl CheckpointBuilder {
14191437
);
14201438
}
14211439

1440+
let new_ckpt_str = new_checkpoints
1441+
.iter()
1442+
.map(|(ckpt, _)| format!("seq={}, digest={}", ckpt.sequence_number(), ckpt.digest()))
1443+
.join("; ");
1444+
14221445
self.write_checkpoints(last_details.checkpoint_height, new_checkpoints)
14231446
.await?;
1447+
info!(
1448+
"Made new checkpoint {} from pending checkpoint {}",
1449+
new_ckpt_str, pending_ckpt_str
1450+
);
1451+
14241452
Ok(highest_sequence)
14251453
}
14261454

@@ -3795,6 +3823,8 @@ mod tests {
37953823
timestamp_ms,
37963824
last_of_epoch: false,
37973825
checkpoint_height: i,
3826+
consensus_commit_ref: CommitRef::default(),
3827+
rejected_transactions_digest: Digest::default(),
37983828
},
37993829
}
38003830
}

crates/sui-core/src/consensus_handler.rs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ impl ConsensusHandlerInitializer {
169169
mod additional_consensus_state {
170170
use std::marker::PhantomData;
171171

172+
use consensus_core::CommitRef;
172173
use fastcrypto::hash::HashFunction as _;
173-
use sui_types::crypto::DefaultHash;
174+
use sui_types::{crypto::DefaultHash, digests::Digest};
174175

175176
use super::*;
176177
/// AdditionalConsensusState tracks any in-memory state that is retained by ConsensusHandler
@@ -216,7 +217,6 @@ mod additional_consensus_state {
216217

217218
self.commit_info_impl(
218219
epoch_start_time,
219-
protocol_config,
220220
consensus_commit,
221221
Some(estimated_commit_period),
222222
)
@@ -225,7 +225,6 @@ mod additional_consensus_state {
225225
fn commit_info_impl(
226226
&self,
227227
epoch_start_time: u64,
228-
protocol_config: &ProtocolConfig,
229228
consensus_commit: &impl ConsensusCommitAPI,
230229
estimated_commit_period: Option<Duration>,
231230
) -> ConsensusCommitInfo {
@@ -246,8 +245,8 @@ mod additional_consensus_state {
246245
round: consensus_commit.leader_round(),
247246
timestamp,
248247
leader_author,
249-
sub_dag_index: consensus_commit.commit_sub_dag_index(),
250-
consensus_commit_digest: consensus_commit.consensus_digest(protocol_config),
248+
consensus_commit_ref: consensus_commit.commit_ref(),
249+
rejected_transactions_digest: consensus_commit.rejected_transactions_digest(),
251250
additional_state_digest: Some(self.digest()),
252251
estimated_commit_period,
253252
skip_consensus_commit_prologue_in_test: false,
@@ -269,8 +268,8 @@ mod additional_consensus_state {
269268
pub round: u64,
270269
pub timestamp: u64,
271270
pub leader_author: AuthorityIndex,
272-
pub sub_dag_index: u64,
273-
pub consensus_commit_digest: ConsensusCommitDigest,
271+
pub consensus_commit_ref: CommitRef,
272+
pub rejected_transactions_digest: Digest,
274273

275274
additional_state_digest: Option<AdditionalConsensusStateDigest>,
276275
estimated_commit_period: Option<Duration>,
@@ -290,8 +289,8 @@ mod additional_consensus_state {
290289
round: commit_round,
291290
timestamp: commit_timestamp,
292291
leader_author: 0,
293-
sub_dag_index: 0,
294-
consensus_commit_digest: ConsensusCommitDigest::default(),
292+
consensus_commit_ref: CommitRef::default(),
293+
rejected_transactions_digest: Digest::default(),
295294
additional_state_digest: Some(AdditionalConsensusStateDigest::ZERO),
296295
estimated_commit_period,
297296
skip_consensus_commit_prologue_in_test,
@@ -323,6 +322,10 @@ mod additional_consensus_state {
323322
.expect("estimated commit period is not available")
324323
}
325324

325+
fn consensus_commit_digest(&self) -> ConsensusCommitDigest {
326+
ConsensusCommitDigest::new(self.consensus_commit_ref.digest.into_inner())
327+
}
328+
326329
fn consensus_commit_prologue_transaction(
327330
&self,
328331
epoch: u64,
@@ -343,7 +346,7 @@ mod additional_consensus_state {
343346
epoch,
344347
self.round,
345348
self.timestamp,
346-
self.consensus_commit_digest,
349+
self.consensus_commit_digest(),
347350
);
348351
VerifiedExecutableTransaction::new_system(transaction, epoch)
349352
}
@@ -357,7 +360,7 @@ mod additional_consensus_state {
357360
epoch,
358361
self.round,
359362
self.timestamp,
360-
self.consensus_commit_digest,
363+
self.consensus_commit_digest(),
361364
consensus_determined_version_assignments,
362365
);
363366
VerifiedExecutableTransaction::new_system(transaction, epoch)
@@ -373,7 +376,7 @@ mod additional_consensus_state {
373376
epoch,
374377
self.round,
375378
self.timestamp,
376-
self.consensus_commit_digest,
379+
self.consensus_commit_digest(),
377380
consensus_determined_version_assignments,
378381
additional_state_digest,
379382
);
@@ -801,7 +804,8 @@ impl<C: CheckpointServiceNotify + Send + Sync> ConsensusHandler<C> {
801804

802805
info!(
803806
%consensus_commit,
804-
"Received consensus output"
807+
"Received consensus output. Rejected transactions: {}",
808+
consensus_commit.rejected_transactions_debug_string(),
805809
);
806810

807811
self.last_consensus_stats.index = ExecutionIndices {
@@ -1049,19 +1053,28 @@ impl<C: CheckpointServiceNotify + Send + Sync> ConsensusHandler<C> {
10491053
timestamp_ms: commit_info.timestamp,
10501054
last_of_epoch: final_round && !should_write_random_checkpoint,
10511055
checkpoint_height,
1056+
consensus_commit_ref: commit_info.consensus_commit_ref,
1057+
rejected_transactions_digest: commit_info.rejected_transactions_digest,
10521058
},
10531059
};
10541060
self.epoch_store
10551061
.write_pending_checkpoint(&mut state.output, &pending_checkpoint)
10561062
.expect("failed to write pending checkpoint");
10571063

1064+
info!(
1065+
"Written pending checkpoint: {:?}",
1066+
pending_checkpoint.details,
1067+
);
1068+
10581069
if should_write_random_checkpoint {
10591070
let pending_checkpoint = PendingCheckpoint {
10601071
roots: randomness_schedulables.iter().map(|s| s.key()).collect(),
10611072
details: PendingCheckpointInfo {
10621073
timestamp_ms: commit_info.timestamp,
10631074
last_of_epoch: final_round,
10641075
checkpoint_height: checkpoint_height + 1,
1076+
consensus_commit_ref: commit_info.consensus_commit_ref,
1077+
rejected_transactions_digest: commit_info.rejected_transactions_digest,
10651078
},
10661079
};
10671080
self.epoch_store
@@ -2147,7 +2160,7 @@ impl<C: CheckpointServiceNotify + Send + Sync> ConsensusHandler<C> {
21472160
// Therefore, the transaction sequence number starts from 1 here.
21482161
let current_tx_index = ExecutionIndices {
21492162
last_committed_round: commit_info.round,
2150-
sub_dag_index: commit_info.sub_dag_index,
2163+
sub_dag_index: commit_info.consensus_commit_ref.index.into(),
21512164
transaction_index: (seq + 1) as u64,
21522165
};
21532166

crates/sui-core/src/consensus_types/consensus_output_api.rs

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// Copyright (c) Mysten Labs, Inc.
22
// SPDX-License-Identifier: Apache-2.0
3+
34
use std::{cmp::Ordering, fmt::Display};
45

5-
use consensus_core::{BlockAPI, CommitDigest, VerifiedBlock};
6+
use consensus_core::{BlockAPI, CommitRef, VerifiedBlock};
67
use consensus_types::block::{BlockRef, TransactionIndex};
7-
use sui_protocol_config::ProtocolConfig;
8+
use fastcrypto::hash::HashFunction as _;
9+
use itertools::Itertools as _;
810
use sui_types::{
9-
digests::ConsensusCommitDigest,
11+
digests::Digest,
1012
messages_consensus::{AuthorityIndex, ConsensusTransaction},
1113
};
1214

@@ -20,6 +22,9 @@ pub(crate) struct ParsedTransaction {
2022
}
2123

2224
pub(crate) trait ConsensusCommitAPI: Display {
25+
/// Returns the ref of consensus output.
26+
fn commit_ref(&self) -> CommitRef;
27+
2328
fn reputation_score_sorted_desc(&self) -> Option<Vec<(AuthorityIndex, u64)>>;
2429
fn leader_round(&self) -> u64;
2530
fn leader_author_index(&self) -> AuthorityIndex;
@@ -33,11 +38,16 @@ pub(crate) trait ConsensusCommitAPI: Display {
3338
/// Returns all accepted and rejected transactions per block in the commit in deterministic order.
3439
fn transactions(&self) -> Vec<(BlockRef, Vec<ParsedTransaction>)>;
3540

36-
/// Returns the digest of consensus output.
37-
fn consensus_digest(&self, protocol_config: &ProtocolConfig) -> ConsensusCommitDigest;
41+
/// Returns a debug string of all rejected transactions.
42+
fn rejected_transactions_digest(&self) -> Digest;
43+
fn rejected_transactions_debug_string(&self) -> String;
3844
}
3945

4046
impl ConsensusCommitAPI for consensus_core::CommittedSubDag {
47+
fn commit_ref(&self) -> CommitRef {
48+
self.commit_ref
49+
}
50+
4151
fn reputation_score_sorted_desc(&self) -> Option<Vec<(AuthorityIndex, u64)>> {
4252
if !self.reputation_scores_desc.is_empty() {
4353
Some(
@@ -85,15 +95,29 @@ impl ConsensusCommitAPI for consensus_core::CommittedSubDag {
8595
.collect()
8696
}
8797

88-
fn consensus_digest(&self, protocol_config: &ProtocolConfig) -> ConsensusCommitDigest {
89-
if protocol_config.mysticeti_use_committed_subdag_digest() {
90-
// We port CommitDigest, a consensus space object, into ConsensusCommitDigest, a sui-core space object.
91-
// We assume they always have the same format.
92-
static_assertions::assert_eq_size!(ConsensusCommitDigest, CommitDigest);
93-
ConsensusCommitDigest::new(self.commit_ref.digest.into_inner())
94-
} else {
95-
ConsensusCommitDigest::default()
96-
}
98+
fn rejected_transactions_digest(&self) -> Digest {
99+
let bytes = bcs::to_bytes(&self.rejected_transactions_by_block).unwrap();
100+
let mut hasher = sui_types::crypto::DefaultHash::new();
101+
hasher.update(bytes);
102+
hasher.finalize().digest.into()
103+
}
104+
105+
fn rejected_transactions_debug_string(&self) -> String {
106+
let str = self
107+
.rejected_transactions_by_block
108+
.iter()
109+
.map(|(block_ref, rejected_transactions)| {
110+
format!(
111+
"{block_ref}: [{}]",
112+
rejected_transactions
113+
.iter()
114+
.map(|tx| tx.to_string())
115+
.join(",")
116+
)
117+
})
118+
.join(", ");
119+
let digest = self.rejected_transactions_digest();
120+
format!("{str}; digest: {digest}")
97121
}
98122
}
99123

0 commit comments

Comments
 (0)