/// Construcs a genesis/recovery CUP from the CUP contents associated with the
/// given subnet
Construcs a genesis/recovery CUP from the CUP contents associated with the
given subnet
Construcs a genesis / recovery CUP from the CUP contents associated with the given subnet
pub fn make_registry_cup(
    registry: &dyn RegistryClient,
    subnet_id: SubnetId,
    logger: Option<&ReplicaLogger>,
) -> Option<CatchUpPackage> {
    let versioned_record = match registry.get_cup_contents(subnet_id, registry.get_latest_version())
    {
        Ok(versioned_record) => versioned_record,
        Err(e) => {
            if let Some(logger) = logger {
                warn!(
                    logger,
                    "Failed to retrieve versioned record from the registry {:?}", e,
                );
            }
            return None;
        }
    };
    let cup_contents = versioned_record.value.expect("Missing CUP contents");
    let registry_version = if let Some(registry_info) = cup_contents.registry_store_uri {
        RegistryVersion::from(registry_info.registry_version)
    } else {
        versioned_record.version
    };
    // We do not use `registry_version` here because doing so would cause issues
    // for full NNS (4b) subnet recovery. When we are calling
    // make_registry_cup, our notion of the the NNS registry is still that of
    // the temporary NNS that is used to spawn the recovered NNS. However the
    // registry version store in `registry_store_uri` is a registry version from
    // the original/restored NNS, and so we can not use that version here.
    let replica_version = match registry.get_replica_version(subnet_id, versioned_record.version) {
        Ok(Some(replica_version)) => replica_version,
        err => {
            if let Some(logger) = logger {
                warn!(
                    logger,
                    "Failed to retrieve subnet replica version at registry version {:?}: {:?}",
                    registry_version,
                    err
                );
            }
            return None;
        }
    };
    let dkg_summary = make_genesis_summary(registry, subnet_id, Some(registry_version));
    let ecdsa_summary = None;
    let cup_height = Height::new(cup_contents.height);
    let low_dkg_id = dkg_summary
        .current_transcript(&NiDkgTag::LowThreshold)
        .dkg_id;
    let high_dkg_id = dkg_summary
        .current_transcript(&NiDkgTag::HighThreshold)
        .dkg_id;
    let block = Block::new_with_replica_version(
        replica_version.clone(),
        Id::from(CryptoHash(Vec::new())),
        Payload::new(crypto_hash, (dkg_summary, ecdsa_summary).into()),
        cup_height,
        Rank(0),
        ValidationContext {
            certified_height: cup_height,
            registry_version,
            time: Time::from_nanos_since_unix_epoch(cup_contents.time),
        },
    );
    let random_beacon = Signed {
        content: RandomBeaconContent::new_with_replica_version(
            replica_version,
            cup_height,
            Id::from(CryptoHash(Vec::new())),
        ),
        signature: ThresholdSignature {
            signer: low_dkg_id,
            signature: CombinedThresholdSigOf::new(CombinedThresholdSig(vec![])),
        },
    };
    Some(CatchUpPackage {
        content: CatchUpContent::new(
            HashedBlock::new(crypto_hash, block),
            HashedRandomBeacon::new(crypto_hash, random_beacon),
            Id::from(CryptoHash(cup_contents.state_hash)),
        ),
        signature: ThresholdSignature {
            signer: high_dkg_id,
            signature: CombinedThresholdSigOf::new(CombinedThresholdSig(vec![])),
        },
    })
}
pub fn make_registry_cup ( registry : & dyn RegistryClient , subnet_id : SubnetId , logger : Option < & ReplicaLogger > , ) -> Option < CatchUpPackage > { let versioned_record = match registry . get_cup_contents ( subnet_id , registry . get_latest_version ( ) ) { Ok ( versioned_record ) => versioned_record , Err ( e ) => { if let Some ( logger ) = logger { warn ! ( logger " " e ) ; } return None ; } } ; let cup_contents = versioned_record . value . expect ( " " ) ; let registry_version = if let Some ( registry_info ) = cup_contents . registry_store_uri { RegistryVersion :: from ( registry_info . registry_version ) } else { versioned_record . version } ; // We do not use `registry_version` here because doing so would cause issues // for full NNS (4b) subnet recovery. When we are calling // make_registry_cup, our notion of the the NNS registry is still that of // the temporary NNS that is used to spawn the recovered NNS. However the // registry version store in `registry_store_uri` is a registry version from // the original/restored NNS, and so we can not use that version here. let replica_version = match registry . get_replica_version ( subnet_id , versioned_record . version ) { Ok ( Some ( replica_version ) ) => replica_version , err => { if let Some ( logger ) = logger { warn ! ( logger " " registry_version err ) ; } return None ; } } ; let dkg_summary = make_genesis_summary ( registry , subnet_id , Some ( registry_version ) ) ; let ecdsa_summary = None ; let cup_height = Height :: new ( cup_contents . height ) ; let low_dkg_id = dkg_summary . current_transcript ( & NiDkgTag :: LowThreshold ) . dkg_id ; let high_dkg_id = dkg_summary . current_transcript ( & NiDkgTag :: HighThreshold ) . dkg_id ; let block = Block :: new_with_replica_version ( replica_version . clone ( ) , Id :: from ( CryptoHash ( Vec :: new ( ) ) ) , Payload :: new ( crypto_hash , ( dkg_summary , ecdsa_summary ) . into ( ) ) , cup_height , Rank ( 0 ) , ValidationContext { certified_height : cup_height , registry_version , time : Time :: from_nanos_since_unix_epoch ( cup_contents . time ) , } , ) ; let random_beacon = Signed { content : RandomBeaconContent :: new_with_replica_version ( replica_version , cup_height , Id :: from ( CryptoHash ( Vec :: new ( ) ) ) , ) , signature : ThresholdSignature { signer : low_dkg_id , signature : CombinedThresholdSigOf :: new ( CombinedThresholdSig ( vec ! [ ] ) ) , } , } ; Some ( CatchUpPackage { content : CatchUpContent :: new ( HashedBlock :: new ( crypto_hash , block ) , HashedRandomBeacon :: new ( crypto_hash , random_beacon ) , Id :: from ( CryptoHash ( cup_contents . state_hash ) ) , ) , signature : ThresholdSignature { signer : high_dkg_id , signature : CombinedThresholdSigOf :: new ( CombinedThresholdSig ( vec ! [ ] ) ) , } , } ) }
Construcs a genesis/recovery CUP from the CUP contents associated with the
given subnet
Construcs a genesis / recovery CUP from the CUP contents associated with the given subnet
registry
&dyn RegistryClient
subnet_id
SubnetId
logger
Option<&ReplicaLogger>