Skip to content

Commit 2e245e3

Browse files
committed
Rename to id()
1 parent 2fa0fed commit 2e245e3

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

ledger/narwhal/batch-certificate/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<N: Network> Hash for BatchCertificate<N> {
138138

139139
impl<N: Network> BatchCertificate<N> {
140140
/// Returns the certificate ID.
141-
pub const fn certificate_id(&self) -> Field<N> {
141+
pub const fn id(&self) -> Field<N> {
142142
match self {
143143
Self::V1 { certificate_id, .. } => *certificate_id,
144144
Self::V2 { batch_header, .. } => batch_header.batch_id(),
@@ -279,7 +279,7 @@ pub mod test_helpers {
279279
sample_batch_certificate_for_round(previous_round, rng),
280280
];
281281
// Construct the previous certificate IDs.
282-
let previous_certificate_ids: IndexSet<_> = previous_certificates.iter().map(|c| c.certificate_id()).collect();
282+
let previous_certificate_ids: IndexSet<_> = previous_certificates.iter().map(|c| c.id()).collect();
283283
// Sample the leader certificate.
284284
let certificate = sample_batch_certificate_for_round_with_previous_certificate_ids(
285285
current_round,

ledger/narwhal/subdag/src/lib.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ fn sanity_check_subdag_with_dfs<N: Network>(subdag: &BTreeMap<u64, IndexSet<Batc
5757
commit.entry(certificate.round()).or_default().insert(certificate.clone());
5858
// Iterate over the previous certificate IDs.
5959
for previous_certificate_id in certificate.previous_certificate_ids() {
60-
let Some(previous_certificate) = subdag.get(&(certificate.round() - 1)).and_then(|map| {
61-
map.iter().find(|certificate| certificate.certificate_id() == *previous_certificate_id)
62-
}) else {
60+
let Some(previous_certificate) = subdag
61+
.get(&(certificate.round() - 1))
62+
.and_then(|map| map.iter().find(|certificate| certificate.id() == *previous_certificate_id))
63+
else {
6364
// It is either ordered or below the GC round.
6465
continue;
6566
};
6667
// Insert the previous certificate into the set of already ordered certificates.
67-
if !already_ordered.insert(previous_certificate.certificate_id()) {
68+
if !already_ordered.insert(previous_certificate.id()) {
6869
// If the previous certificate is already ordered, continue.
6970
continue;
7071
}
@@ -108,7 +109,7 @@ impl<N: Network> Subdag<N> {
108109

109110
/// Returns the certificate IDs of the subdag (from earliest round to latest round).
110111
pub fn certificate_ids(&self) -> impl Iterator<Item = Field<N>> + '_ {
111-
self.values().flatten().map(BatchCertificate::certificate_id)
112+
self.values().flatten().map(BatchCertificate::id)
112113
}
113114

114115
/// Returns the leader certificate.
@@ -157,10 +158,7 @@ impl<N: Network> Subdag<N> {
157158
// Prepare the leaves.
158159
let leaves = cfg_iter!(self.subdag)
159160
.map(|(_, certificates)| {
160-
certificates
161-
.iter()
162-
.flat_map(|certificate| certificate.certificate_id().to_bits_le())
163-
.collect::<Vec<_>>()
161+
certificates.iter().flat_map(|certificate| certificate.id().to_bits_le()).collect::<Vec<_>>()
164162
})
165163
.collect::<Vec<_>>();
166164

@@ -213,7 +211,7 @@ pub mod test_helpers {
213211
for _ in 0..AVAILABILITY_THRESHOLD {
214212
let certificate =
215213
narwhal_batch_certificate::test_helpers::sample_batch_certificate_for_round(starting_round, rng);
216-
previous_certificate_ids.insert(certificate.certificate_id());
214+
previous_certificate_ids.insert(certificate.id());
217215
subdag.entry(starting_round).or_default().insert(certificate);
218216
}
219217

@@ -222,7 +220,7 @@ pub mod test_helpers {
222220
for _ in 0..QUORUM_THRESHOLD {
223221
let certificate =
224222
narwhal_batch_certificate::test_helpers::sample_batch_certificate_for_round_with_previous_certificate_ids(starting_round + 1, previous_certificate_ids.clone(), rng);
225-
previous_certificate_ids_2.insert(certificate.certificate_id());
223+
previous_certificate_ids_2.insert(certificate.id());
226224
subdag.entry(starting_round + 1).or_default().insert(certificate);
227225
}
228226

ledger/store/src/block/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,9 @@ pub trait BlockStorage<N: Network>: 'static + Clone + Send + Sync {
405405
// Retrieve the certificate IDs to store.
406406
let certificates_to_store = match block.authority() {
407407
Authority::Beacon(_) => Vec::new(),
408-
Authority::Quorum(subdag) => subdag
409-
.iter()
410-
.flat_map(|(round, certificates)| certificates.iter().map(|c| (c.certificate_id(), *round)))
411-
.collect(),
408+
Authority::Quorum(subdag) => {
409+
subdag.iter().flat_map(|(round, certificates)| certificates.iter().map(|c| (c.id(), *round))).collect()
410+
}
412411
};
413412

414413
// Prepare the rejected transaction IDs and their corresponding unconfirmed transaction IDs.
@@ -529,7 +528,7 @@ pub trait BlockStorage<N: Network>: 'static + Clone + Send + Sync {
529528
Some(authority) => match authority {
530529
Cow::Owned(Authority::Beacon(_)) | Cow::Borrowed(Authority::Beacon(_)) => Vec::new(),
531530
Cow::Owned(Authority::Quorum(ref subdag)) | Cow::Borrowed(Authority::Quorum(ref subdag)) => {
532-
subdag.values().flatten().map(|c| c.certificate_id()).collect()
531+
subdag.values().flatten().map(|c| c.id()).collect()
533532
}
534533
},
535534
None => bail!("Failed to remove block: missing authority for block '{block_height}' ('{block_hash}')"),
@@ -798,7 +797,7 @@ pub trait BlockStorage<N: Network>: 'static + Clone + Send + Sync {
798797
match subdag.get(&round) {
799798
Some(certificates) => {
800799
// Retrieve the certificate for the given certificate ID.
801-
match certificates.iter().find(|certificate| &certificate.certificate_id() == certificate_id) {
800+
match certificates.iter().find(|certificate| &certificate.id() == certificate_id) {
802801
Some(certificate) => Ok(Some(certificate.clone())),
803802
None => bail!("The certificate '{certificate_id}' is missing in block storage"),
804803
}

0 commit comments

Comments
 (0)