Skip to content

Commit

Permalink
[Narwhal] remove Narwhal crypto usages from Sui (#19205)
Browse files Browse the repository at this point in the history
## Description 

This is another step in removing Narwhal integration with Sui. Narwhal
crypto types used in Sui are replaced with the corresponding Sui types.
There should be no difference in logic or serialized formats.

## Test plan 

CI

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
mwtian authored Sep 4, 2024
1 parent 6a0adb5 commit bf8a3ae
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 280 deletions.
4 changes: 0 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions crates/sui-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ telemetry-subscribers.workspace = true
typed-store.workspace = true

mysten-metrics.workspace = true
narwhal-config.workspace = true
narwhal-crypto.workspace = true
narwhal-types.workspace = true
shared-crypto.workspace = true
sui-archival.workspace = true
Expand Down
47 changes: 24 additions & 23 deletions crates/sui-core/src/consensus_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use std::{
};

use arc_swap::ArcSwap;
use consensus_config::Committee as ConsensusCommittee;
use consensus_core::CommitConsumerMonitor;
use lru::LruCache;
use mysten_metrics::{monitored_mpsc::UnboundedReceiver, monitored_scope, spawn_monitored_task};
use narwhal_config::Committee;
use serde::{Deserialize, Serialize};
use sui_macros::{fail_point_async, fail_point_if};
use sui_protocol_config::ProtocolConfig;
Expand All @@ -38,9 +38,7 @@ use crate::{
},
checkpoints::{CheckpointService, CheckpointServiceNotify},
consensus_throughput_calculator::ConsensusThroughputCalculator,
consensus_types::{
committee_api::CommitteeAPI, consensus_output_api::ConsensusOutputAPI, AuthorityIndex,
},
consensus_types::{consensus_output_api::ConsensusOutputAPI, AuthorityIndex},
execution_cache::ObjectCacheRead,
scoring_decision::update_low_scoring_authorities,
transaction_manager::TransactionManager,
Expand Down Expand Up @@ -86,17 +84,18 @@ impl ConsensusHandlerInitializer {
)),
}
}

pub fn new_consensus_handler(&self) -> ConsensusHandler<CheckpointService> {
let new_epoch_start_state = self.epoch_store.epoch_start_state();
let committee = new_epoch_start_state.get_narwhal_committee();
let consensus_committee = new_epoch_start_state.get_consensus_committee();

ConsensusHandler::new(
self.epoch_store.clone(),
self.checkpoint_service.clone(),
self.state.transaction_manager().clone(),
self.state.get_object_cache_reader().clone(),
self.low_scoring_authorities.clone(),
committee,
consensus_committee,
self.state.metrics.clone(),
self.throughput_calculator.clone(),
)
Expand All @@ -116,8 +115,8 @@ pub struct ConsensusHandler<C> {
cache_reader: Arc<dyn ObjectCacheRead>,
/// Reputation scores used by consensus adapter that we update, forwarded from consensus
low_scoring_authorities: Arc<ArcSwap<HashMap<AuthorityName, u64>>>,
/// The narwhal committee used to do stake computations for deciding set of low scoring authorities
committee: Committee,
/// The consensus committee used to do stake computations for deciding set of low scoring authorities
committee: ConsensusCommittee,
// TODO: ConsensusHandler doesn't really share metrics with AuthorityState. We could define
// a new metrics type here if we want to.
metrics: Arc<AuthorityMetrics>,
Expand All @@ -137,7 +136,7 @@ impl<C> ConsensusHandler<C> {
transaction_manager: Arc<TransactionManager>,
cache_reader: Arc<dyn ObjectCacheRead>,
low_scoring_authorities: Arc<ArcSwap<HashMap<AuthorityName, u64>>>,
committee: Committee,
committee: ConsensusCommittee,
metrics: Arc<AuthorityMetrics>,
throughput_calculator: Arc<ConsensusThroughputCalculator>,
) -> Self {
Expand Down Expand Up @@ -299,6 +298,7 @@ impl<C: CheckpointServiceNotify + Send + Sync> ConsensusHandler<C> {

update_low_scoring_authorities(
self.low_scoring_authorities.clone(),
self.epoch_store.committee(),
&self.committee,
consensus_output.reputation_score_sorted_desc(),
&self.metrics,
Expand Down Expand Up @@ -344,19 +344,20 @@ impl<C: CheckpointServiceNotify + Send + Sync> ConsensusHandler<C> {
}
}

for i in 0..self.committee.size() {
let hostname = self
.committee
.authority_hostname_by_index(i as AuthorityIndex)
.unwrap_or_default();
for (i, authority) in self.committee.authorities() {
let hostname = &authority.hostname;
self.metrics
.consensus_committed_messages
.with_label_values(&[hostname])
.set(self.last_consensus_stats.stats.get_num_messages(i) as i64);
.set(self.last_consensus_stats.stats.get_num_messages(i.value()) as i64);
self.metrics
.consensus_committed_user_transactions
.with_label_values(&[hostname])
.set(self.last_consensus_stats.stats.get_num_user_transactions(i) as i64);
.set(
self.last_consensus_stats
.stats
.get_num_user_transactions(i.value()) as i64,
);
}

let mut all_transactions = Vec::new();
Expand All @@ -379,9 +380,10 @@ impl<C: CheckpointServiceNotify + Send + Sync> ConsensusHandler<C> {

self.update_index_and_hash(current_tx_index, serialized);

let certificate_author = self
.committee
.authority_pubkey_by_index(cert_origin)
let certificate_author = *self
.epoch_store
.committee()
.authority_by_index(cert_origin)
.unwrap();

let sequenced_transaction = SequencedConsensusTransaction {
Expand Down Expand Up @@ -859,7 +861,6 @@ mod tests {
AuthorityCapabilitiesV1, ConsensusTransaction, ConsensusTransactionKind,
},
object::Object,
sui_system_state::epoch_start_sui_system_state::EpochStartSystemStateTrait,
supported_protocol_versions::SupportedProtocolVersions,
transaction::{
CertifiedTransaction, SenderSignedData, TransactionData, TransactionDataAPI,
Expand Down Expand Up @@ -896,7 +897,7 @@ mod tests {

let epoch_store = state.epoch_store_for_testing().clone();
let new_epoch_start_state = epoch_store.epoch_start_state();
let committee = new_epoch_start_state.get_narwhal_committee();
let consensus_committee = new_epoch_start_state.get_consensus_committee();

let metrics = Arc::new(AuthorityMetrics::new(&Registry::new()));

Expand All @@ -908,7 +909,7 @@ mod tests {
state.transaction_manager().clone(),
state.get_object_cache_reader().clone(),
Arc::new(ArcSwap::default()),
committee.clone(),
consensus_committee.clone(),
metrics,
Arc::new(throughput_calculator),
);
Expand All @@ -926,7 +927,7 @@ mod tests {

// AND create block for each transaction
let block = VerifiedBlock::new_for_test(
TestBlock::new(100 + i as u32, (i % committee.size()) as u32)
TestBlock::new(100 + i as u32, (i % consensus_committee.size()) as u32)
.set_transactions(vec![Transaction::new(transaction_bytes)])
.build(),
);
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-core/src/consensus_manager/mysticeti_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl ConsensusManagerTrait for MysticetiManager {
tx_validator: SuiTxValidator,
) {
let system_state = epoch_store.epoch_start_state();
let committee: Committee = system_state.get_mysticeti_committee();
let committee: Committee = system_state.get_consensus_committee();
let epoch = epoch_store.epoch();
let protocol_config = epoch_store.protocol_config();
let network_type = self.pick_network(&epoch_store);
Expand Down
40 changes: 0 additions & 40 deletions crates/sui-core/src/consensus_types/committee_api.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/sui-core/src/consensus_types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

pub(crate) mod committee_api;
pub(crate) mod consensus_output_api;

/// An unique integer ID for a validator used by consensus.
Expand Down
Loading

0 comments on commit bf8a3ae

Please sign in to comment.