Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

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

15 changes: 13 additions & 2 deletions rs/consensus/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ DEV_DEPENDENCIES = [
"//rs/types/types_test_utils",
"@crate_index//:assert_matches",
"@crate_index//:criterion",
"@crate_index//:hex",
"@crate_index//:mockall",
"@crate_index//:proptest",
"@crate_index//:prost",
"@crate_index//:rstest",
"@crate_index//:serde_cbor",
Expand Down Expand Up @@ -134,11 +134,22 @@ rust_test(
crate = ":malicious_consensus",
crate_features = [
"malicious_code",
"proptest",
],
deps = DEPENDENCIES + DEV_DEPENDENCIES + MALICIOUS_DEPENDENCIES,
)

rust_test(
name = "consensus_prop_test",
crate = ":malicious_consensus",
crate_features = [
"malicious_code",
"proptest",
],
deps = DEPENDENCIES + DEV_DEPENDENCIES + MALICIOUS_DEPENDENCIES + [
"@crate_index//:proptest",
],
)

rust_test(
name = "integration_test",
srcs = glob(["tests/**"]),
Expand Down
1 change: 1 addition & 0 deletions rs/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ strum_macros = { workspace = true }
[dev-dependencies]
assert_matches = { workspace = true }
criterion = { workspace = true }
hex = { workspace = true }
ic-artifact-pool = { path = "../artifact_pool" }
ic-btc-replica-types = { path = "../bitcoin/replica_types" }
ic-config = { path = "../config" }
Expand Down
1 change: 1 addition & 0 deletions rs/consensus/cup_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ mod tests {
registry_store_uri: None,
ecdsa_initializations: vec![],
chain_key_initializations: vec![],
cup_type: None,
};

// Encode the cup to protobuf
Expand Down
57 changes: 56 additions & 1 deletion rs/consensus/dkg/src/payload_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use ic_types::{
batch::ValidationContext,
consensus::{
Block,
dkg::{DkgDataPayload, DkgPayload, DkgPayloadCreationError, DkgSummary},
dkg::{
DkgDataPayload, DkgPayload, DkgPayloadCreationError, DkgSummary, SubnetSplittingStatus,
},
get_faults_tolerated,
},
crypto::threshold_sig::ni_dkg::{
Expand Down Expand Up @@ -280,6 +282,8 @@ pub(super) fn create_summary_payload(
next_interval_length,
height,
initial_dkg_attempts,
// TODO(kpop): start populating this
/*subnet_splitting_status=*/ None,
))
}

Expand Down Expand Up @@ -453,6 +457,22 @@ pub fn get_dkg_summary_from_cup_contents(
subnet_id: SubnetId,
registry: &dyn RegistryClient,
registry_version: RegistryVersion,
) -> Result<DkgSummary, String> {
get_dkg_summary_from_cup_contents_with_subnet_splitting(
cup_contents,
subnet_id,
registry,
registry_version,
/*subnet_splitting_status=*/ None,
)
}

fn get_dkg_summary_from_cup_contents_with_subnet_splitting(
cup_contents: CatchUpPackageContents,
subnet_id: SubnetId,
registry: &dyn RegistryClient,
registry_version: RegistryVersion,
subnet_splitting_status: Option<SubnetSplittingStatus>,
) -> Result<DkgSummary, String> {
// If we're in a NNS subnet recovery case with failover nodes, we extract the registry of the
// NNS we're recovering.
Expand Down Expand Up @@ -555,6 +575,7 @@ pub fn get_dkg_summary_from_cup_contents(
next_interval_length,
height,
BTreeMap::new(), // initial_dkg_attempts
subnet_splitting_status,
))
}

Expand Down Expand Up @@ -985,6 +1006,40 @@ fn create_remote_dkg_config(
})
}

/// Creates a DKG summary for the summary block right after the subnet has been split.
pub fn get_post_split_dkg_summary(
new_subnet_id: SubnetId,
registry: &dyn RegistryClient,
last_summary_block: &Block,
) -> Result<DkgSummary, String> {
let last_summary = &last_summary_block.payload.as_ref().as_summary().dkg;
debug_assert!(matches!(
last_summary.subnet_splitting_status,
Some(SubnetSplittingStatus::Scheduled { .. })
));
let registry_version = last_summary_block.context.registry_version;

let mut cup_contents = registry
.get_cup_contents(new_subnet_id, registry_version)
.map_err(|err| {
format!("Failed to get the cup contents at registry version {registry_version}: {err}")
})?
.value
.ok_or_else(|| format!("Empty cup contents at registry version {registry_version}"))?;

// Skip one dkg interval
cup_contents.height = last_summary.get_next_start_height().get();

get_dkg_summary_from_cup_contents_with_subnet_splitting(
cup_contents,
new_subnet_id,
registry,
registry_version,
Some(SubnetSplittingStatus::Done { new_subnet_id }),
)
.map_err(|err| format!("Failed to create post-split dkg summary from contents: {err}"))
}

#[cfg(test)]
mod tests {
use crate::tests::test_vet_key_config;
Expand Down
1 change: 1 addition & 0 deletions rs/consensus/idkg/src/payload_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ mod tests {
Height::from(100),
height,
BTreeMap::new(),
/*subnet_splitting_status=*/ None,
),
idkg: Some(idkg_summary),
})
Expand Down
Loading
Loading