Skip to content

Commit

Permalink
Add CertificateV2
Browse files Browse the repository at this point in the history
... Includes new AggregateSignatureState
  • Loading branch information
arun-koshy committed Sep 14, 2023
1 parent 1fd3837 commit f61e882
Show file tree
Hide file tree
Showing 30 changed files with 684 additions and 203 deletions.
2 changes: 1 addition & 1 deletion crates/sui-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ narwhal-crypto.workspace = true
narwhal-executor.workspace = true
narwhal-network.workspace = true
narwhal-node.workspace = true
narwhal-test-utils.workspace = true
narwhal-types.workspace = true
narwhal-worker.workspace = true
shared-crypto.workspace = true
Expand Down Expand Up @@ -93,7 +94,6 @@ serde_yaml.workspace = true

move-symbol-pool.workspace = true

narwhal-test-utils.workspace = true
sui-test-transaction-builder.workspace = true
sui-types = { workspace = true, features = ["test-utils"] }

Expand Down
14 changes: 10 additions & 4 deletions crates/sui-core/src/consensus_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use lru::LruCache;
use mysten_metrics::{monitored_scope, spawn_monitored_task};
use narwhal_config::Committee;
use narwhal_executor::{ExecutionIndices, ExecutionState};
use narwhal_types::{BatchAPI, CertificateAPI, ConsensusOutput, HeaderAPI};
use narwhal_test_utils::latest_protocol_version;
use narwhal_types::{BatchAPI, Certificate, CertificateAPI, ConsensusOutput, HeaderAPI};
use serde::{Deserialize, Serialize};
use std::collections::hash_map::DefaultHasher;
use std::collections::{BTreeSet, HashMap, HashSet};
Expand Down Expand Up @@ -643,7 +644,7 @@ impl SequencedConsensusTransaction {
pub fn new_test(transaction: ConsensusTransaction) -> Self {
Self {
transaction: SequencedConsensusTransactionKind::External(transaction),
certificate: Default::default(),
certificate: Arc::new(Certificate::default(&latest_protocol_version())),
certificate_author: AuthorityName::ZERO,
consensus_index: Default::default(),
}
Expand Down Expand Up @@ -733,8 +734,13 @@ mod tests {
.build()
.unwrap();

let certificate =
Certificate::new_unsigned(&committee, Header::V1(header), vec![]).unwrap();
let certificate = Certificate::new_unsigned(
latest_protocol_config,
&committee,
Header::V1(header),
vec![],
)
.unwrap();

certificates.push(certificate);
}
Expand Down
39 changes: 0 additions & 39 deletions crates/sui-framework/docs/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Sui object identifiers
- [Function `id_from_address`](#0x2_object_id_from_address)
- [Function `sui_system_state`](#0x2_object_sui_system_state)
- [Function `clock`](#0x2_object_clock)
- [Function `authenticator_state`](#0x2_object_authenticator_state)
- [Function `uid_as_inner`](#0x2_object_uid_as_inner)
- [Function `uid_to_inner`](#0x2_object_uid_to_inner)
- [Function `uid_to_bytes`](#0x2_object_uid_to_bytes)
Expand Down Expand Up @@ -185,16 +184,6 @@ Sender is not @0x0 the system address.



<a name="0x2_object_SUI_AUTHENTICATOR_STATE_ID"></a>

The hardcoded ID for the singleton AuthenticatorState Object.


<pre><code><b>const</b> <a href="object.md#0x2_object_SUI_AUTHENTICATOR_STATE_ID">SUI_AUTHENTICATOR_STATE_ID</a>: <b>address</b> = 7;
</code></pre>



<a name="0x2_object_SUI_CLOCK_OBJECT_ID"></a>

The hardcoded ID for the singleton Clock Object.
Expand Down Expand Up @@ -370,34 +359,6 @@ This should only be called once from <code><a href="clock.md#0x2_clock">clock</a



</details>

<a name="0x2_object_authenticator_state"></a>

## Function `authenticator_state`

Create the <code><a href="object.md#0x2_object_UID">UID</a></code> for the singleton <code>AuthenticatorState</code> object.
This should only be called once from <code><a href="authenticator_state.md#0x2_authenticator_state">authenticator_state</a></code>.


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="authenticator_state.md#0x2_authenticator_state">authenticator_state</a>(): <a href="object.md#0x2_object_UID">object::UID</a>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="authenticator_state.md#0x2_authenticator_state">authenticator_state</a>(): <a href="object.md#0x2_object_UID">UID</a> {
<a href="object.md#0x2_object_UID">UID</a> {
id: <a href="object.md#0x2_object_ID">ID</a> { bytes: <a href="object.md#0x2_object_SUI_AUTHENTICATOR_STATE_ID">SUI_AUTHENTICATOR_STATE_ID</a> }
}
}
</code></pre>



</details>

<a name="0x2_object_uid_as_inner"></a>
Expand Down
1 change: 1 addition & 0 deletions crates/sui-open-rpc/spec/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,7 @@
"loaded_child_object_format_type": false,
"loaded_child_objects_fixed": true,
"missing_type_is_compatibility_error": true,
"narwhal_certificate_v2": false,
"narwhal_new_leader_election_schedule": false,
"narwhal_versioned_metadata": false,
"no_extraneous_module_bytes": false,
Expand Down
8 changes: 8 additions & 0 deletions crates/sui-protocol-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ struct FeatureFlags {
// If true, use the new child object format type logging
#[serde(skip_serializing_if = "is_false")]
loaded_child_object_format_type: bool,

// If true, then use CertificateV2 in narwhal.
#[serde(skip_serializing_if = "is_false")]
narwhal_certificate_v2: bool,
}

fn is_false(b: &bool) -> bool {
Expand Down Expand Up @@ -922,6 +926,10 @@ impl ProtocolConfig {
pub fn create_authenticator_state_in_genesis(&self) -> bool {
self.enable_jwk_consensus_updates()
}

pub fn narwhal_certificate_v2(&self) -> bool {
self.feature_flags.narwhal_certificate_v2
}
}

#[cfg(not(msim))]
Expand Down
2 changes: 1 addition & 1 deletion narwhal/consensus/benches/process_certificates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn process_certificates(c: &mut Criterion) {
let rounds: Round = *size;

// process certificates for rounds, check we don't grow the dag too much
let genesis = Certificate::genesis(&committee)
let genesis = Certificate::genesis(&latest_protocol_version(), &committee)
.iter()
.map(|x| x.digest())
.collect::<BTreeSet<_>>();
Expand Down
32 changes: 16 additions & 16 deletions narwhal/consensus/src/tests/bullshark_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn order_leaders() {
let committee = fixture.committee();
// Make certificates for rounds 1 to 7.
let ids: Vec<_> = fixture.authorities().map(|a| a.id()).collect();
let genesis = Certificate::genesis(&committee)
let genesis = Certificate::genesis(&latest_protocol_version(), &committee)
.iter()
.map(|x| x.digest())
.collect::<BTreeSet<_>>();
Expand Down Expand Up @@ -127,7 +127,7 @@ async fn commit_one_with_leader_schedule_change() {
let committee = fixture.committee();
// Make certificates for rounds 1 to 9.
let ids: Vec<_> = fixture.authorities().map(|a| a.id()).collect();
let genesis = Certificate::genesis(&committee)
let genesis = Certificate::genesis(&latest_protocol_version(), &committee)
.iter()
.map(|x| x.digest())
.collect::<BTreeSet<_>>();
Expand Down Expand Up @@ -188,7 +188,7 @@ async fn not_enough_support_with_leader_schedule_change() {
let committee = fixture.committee();

let ids: Vec<_> = fixture.authorities().map(|a| a.id()).collect();
let genesis = Certificate::genesis(&committee)
let genesis = Certificate::genesis(&latest_protocol_version(), &committee)
.iter()
.map(|x| x.digest())
.collect::<BTreeSet<_>>();
Expand Down Expand Up @@ -336,7 +336,7 @@ async fn test_long_period_of_asynchrony_for_leader_schedule_change() {
let committee = fixture.committee();

let ids: Vec<_> = fixture.authorities().map(|a| a.id()).collect();
let genesis = Certificate::genesis(&committee)
let genesis = Certificate::genesis(&latest_protocol_version(), &committee)
.iter()
.map(|x| x.digest())
.collect::<BTreeSet<_>>();
Expand Down Expand Up @@ -455,7 +455,7 @@ async fn commit_one() {
let committee = fixture.committee();
// Make certificates for rounds 1 and 2.
let ids: Vec<_> = fixture.authorities().map(|a| a.id()).collect();
let genesis = Certificate::genesis(&committee)
let genesis = Certificate::genesis(&latest_protocol_version(), &committee)
.iter()
.map(|x| x.digest())
.collect::<BTreeSet<_>>();
Expand Down Expand Up @@ -559,7 +559,7 @@ async fn dead_node() {
// remove the last authority - 4
let dead_node = ids.pop().unwrap();

let genesis = Certificate::genesis(&committee)
let genesis = Certificate::genesis(&latest_protocol_version(), &committee)
.iter()
.map(|x| x.digest())
.collect::<BTreeSet<_>>();
Expand Down Expand Up @@ -670,7 +670,7 @@ async fn not_enough_support() {
let mut ids: Vec<_> = fixture.authorities().map(|a| a.id()).collect();
ids.sort();

let genesis = Certificate::genesis(&committee)
let genesis = Certificate::genesis(&latest_protocol_version(), &committee)
.iter()
.map(|x| x.digest())
.collect::<BTreeSet<_>>();
Expand Down Expand Up @@ -870,7 +870,7 @@ async fn missing_leader() {
let mut ids: Vec<_> = fixture.authorities().map(|a| a.id()).collect();
ids.sort();

let genesis = Certificate::genesis(&committee)
let genesis = Certificate::genesis(&latest_protocol_version(), &committee)
.iter()
.map(|x| x.digest())
.collect::<BTreeSet<_>>();
Expand Down Expand Up @@ -986,7 +986,7 @@ async fn committed_round_after_restart() {
let epoch = committee.epoch();

// Make certificates for rounds 1 to 11.
let genesis = Certificate::genesis(&committee)
let genesis = Certificate::genesis(&latest_protocol_version(), &committee)
.iter()
.map(|x| x.digest())
.collect::<BTreeSet<_>>();
Expand Down Expand Up @@ -1092,7 +1092,7 @@ async fn delayed_certificates_are_rejected() {
let gc_depth = 10;

// Make certificates for rounds 1 to 11.
let genesis = Certificate::genesis(&committee)
let genesis = Certificate::genesis(&latest_protocol_version(), &committee)
.iter()
.map(|x| x.digest())
.collect::<BTreeSet<_>>();
Expand Down Expand Up @@ -1151,7 +1151,7 @@ async fn submitting_equivocating_certificate_should_error() {
let gc_depth = 10;

// Make certificates for rounds 1 to 11.
let genesis = Certificate::genesis(&committee)
let genesis = Certificate::genesis(&latest_protocol_version(), &committee)
.iter()
.map(|x| x.digest())
.collect::<BTreeSet<_>>();
Expand Down Expand Up @@ -1227,7 +1227,7 @@ async fn reset_consensus_scores_on_every_schedule_change() {
let gc_depth = 10;

// Make certificates for rounds 1 to 50.
let genesis = Certificate::genesis(&committee)
let genesis = Certificate::genesis(&latest_protocol_version(), &committee)
.iter()
.map(|x| x.digest())
.collect::<BTreeSet<_>>();
Expand Down Expand Up @@ -1341,7 +1341,7 @@ async fn restart_with_new_committee() {
tokio::spawn(async move { while rx_primary.recv().await.is_some() {} });

// Make certificates for rounds 1 and 2.
let genesis = Certificate::genesis(&committee)
let genesis = Certificate::genesis(&latest_protocol_version(), &committee)
.iter()
.map(|x| x.digest())
.collect::<BTreeSet<_>>();
Expand Down Expand Up @@ -1426,7 +1426,7 @@ async fn garbage_collection_basic() {
.map(|authority| authority.id())
.collect();
let slow_node = ids[3];
let genesis = Certificate::genesis(&committee);
let genesis = Certificate::genesis(&latest_protocol_version(), &committee);

let slow_nodes = vec![(slow_node, 0.0_f64)];
let (certificates, _round_5_certificates) = test_utils::make_certificates_with_slow_nodes(
Expand Down Expand Up @@ -1522,7 +1522,7 @@ async fn slow_node() {
.map(|authority| authority.id())
.collect();
let slow_node = ids[3];
let genesis = Certificate::genesis(&committee);
let genesis = Certificate::genesis(&latest_protocol_version(), &committee);

let slow_nodes = vec![(slow_node, 0.0_f64)];
let (certificates, round_8_certificates) = test_utils::make_certificates_with_slow_nodes(
Expand Down Expand Up @@ -1662,7 +1662,7 @@ async fn not_enough_support_and_missing_leaders_and_gc() {
let keys_with_dead_node = ids[0..=2].to_vec();
let slow_node = ids[3];
let slow_nodes = vec![(slow_node, 0.0_f64)];
let genesis = Certificate::genesis(&committee);
let genesis = Certificate::genesis(&latest_protocol_version(), &committee);

let (mut certificates, round_2_certificates) = test_utils::make_certificates_with_slow_nodes(
&committee,
Expand Down
10 changes: 8 additions & 2 deletions narwhal/consensus/src/tests/consensus_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async fn test_consensus_recovery_with_bullshark_with_config(config: ProtocolConf

// AND make certificates for rounds 1 to 7 (inclusive)
let ids: Vec<_> = fixture.authorities().map(|a| a.id()).collect();
let genesis = Certificate::genesis(&committee)
let genesis = Certificate::genesis(&latest_protocol_version(), &committee)
.iter()
.map(|x| x.digest())
.collect::<BTreeSet<_>>();
Expand Down Expand Up @@ -507,7 +507,13 @@ async fn test_leader_schedule_from_store() {
scores.add_score(id, score as u64);
}

let sub_dag = CommittedSubDag::new(vec![], Certificate::default(), 0, scores, None);
let sub_dag = CommittedSubDag::new(
vec![],
Certificate::default(&latest_protocol_version()),
0,
scores,
None,
);

store
.write_consensus_state(&HashMap::new(), &sub_dag)
Expand Down
2 changes: 1 addition & 1 deletion narwhal/consensus/src/tests/randomized_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn generate_randomised_dag(
.rng(rand)
.build();
let committee: Committee = fixture.committee();
let genesis = Certificate::genesis(&committee);
let genesis = Certificate::genesis(&latest_protocol_version(), &committee);

// Create a known DAG
let (original_certificates, _last_round) = make_certificates_with_parameters(
Expand Down
2 changes: 1 addition & 1 deletion narwhal/executor/tests/consensus_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn test_recovery() {

// Make certificates for rounds 1 and 2.
let ids: Vec<_> = fixture.authorities().map(|a| a.id()).collect();
let genesis = Certificate::genesis(&committee)
let genesis = Certificate::genesis(&latest_protocol_version(), &committee)
.iter()
.map(|x| x.digest())
.collect::<BTreeSet<_>>();
Expand Down
14 changes: 11 additions & 3 deletions narwhal/node/src/generate_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use mysten_network::Multiaddr;
use rand::{prelude::StdRng, SeedableRng};
use serde_reflection::{Registry, Result, Samples, Tracer, TracerConfig};
use std::{fs::File, io::Write};
use test_utils::latest_protocol_version;
use types::{
Batch, BatchDigest, Certificate, CertificateDigest, Header, HeaderDigest, HeaderV1Builder,
MetadataV1, VersionedMetadata, WorkerOthersBatchMessage, WorkerOwnBatchMessage,
Expand Down Expand Up @@ -61,7 +62,8 @@ fn get_registry() -> Result<Registry> {

let committee = committee_builder.build();

let certificates: Vec<Certificate> = Certificate::genesis(&committee);
let certificates: Vec<Certificate> =
Certificate::genesis(&latest_protocol_version(), &committee);

// Find the author id inside the committee
let authority = committee.authority_by_key(kp.public()).unwrap();
Expand All @@ -83,10 +85,16 @@ fn get_registry() -> Result<Registry> {
.unwrap();

let worker_pk = network_keys[0].public().clone();
let certificate =
Certificate::new_unsigned(&committee, Header::V1(header.clone()), vec![]).unwrap();
let certificate = Certificate::new_unsigned(
&latest_protocol_version(),
&committee,
Header::V1(header.clone()),
vec![],
)
.unwrap();
let signature = keys[0].sign(certificate.digest().as_ref());
let certificate = Certificate::new_unsigned(
&latest_protocol_version(),
&committee,
Header::V1(header.clone()),
vec![(authority.id(), signature)],
Expand Down
Loading

0 comments on commit f61e882

Please sign in to comment.