Skip to content

chunky_dkg_config - [testnet]

Structs and functions for on-chain chunky DKG configurations.

use 0x1::config_buffer;
use 0x1::copyable_any;
use 0x1::fixed_point64;
use 0x1::string;
use 0x1::system_addresses;

Structs

ConfigOff

A chunky DKG config variant indicating the feature is disabled.

struct ConfigOff has copy, drop, store
Fields
dummy_field: bool

ConfigV1

A chunky DKG config variant indicating the feature is enabled.

struct ConfigV1 has copy, drop, store
Fields
secrecy_threshold: fixed_point64::FixedPoint64
Any validator subset should not be able to reconstruct randomness if subset_power / total_power <= secrecy_threshold,
reconstruction_threshold: fixed_point64::FixedPoint64
Any validator subset should be able to reconstruct randomness if subset_power / total_power > reconstruction_threshold.

Resources

ChunkyDKGConfig

The configuration of the on-chain chunky DKG feature.

struct ChunkyDKGConfig has copy, drop, store, key
Fields
variant: copyable_any::Any
A config variant packed as an Any. Currently the variant type is one of the following. - ConfigOff - ConfigV1

Functions

initialize

Initialize the configuration. Used in genesis or governance.

public fun initialize(framework: &signer, config: chunky_dkg_config::ChunkyDKGConfig)
Implementation
public fun initialize(framework: &signer, config: ChunkyDKGConfig) {
system_addresses::assert_aptos_framework(framework);
if (!exists<ChunkyDKGConfig>(@aptos_framework)) {
move_to(framework, config)
}
}

set_for_next_epoch

This can be called by on-chain governance to update on-chain consensus configs for the next epoch.

public fun set_for_next_epoch(framework: &signer, new_config: chunky_dkg_config::ChunkyDKGConfig)
Implementation
public fun set_for_next_epoch(
framework: &signer, new_config: ChunkyDKGConfig
) {
system_addresses::assert_aptos_framework(framework);
config_buffer::upsert(new_config);
}

on_new_epoch

Only used in reconfigurations to apply the pending ChunkyDKGConfig, if there is any.

public(friend) fun on_new_epoch(framework: &signer)
Implementation
public(friend) fun on_new_epoch(framework: &signer) acquires ChunkyDKGConfig {
system_addresses::assert_aptos_framework(framework);
if (config_buffer::does_exist<ChunkyDKGConfig>()) {
let new_config = config_buffer::extract_v2<ChunkyDKGConfig>();
if (exists<ChunkyDKGConfig>(@aptos_framework)) {
*borrow_global_mut<ChunkyDKGConfig>(@aptos_framework) = new_config;
} else {
move_to(framework, new_config);
}
}
}

enabled

Check whether on-chain chunky DKG main logic is enabled.

NOTE: this returning true does not mean chunky DKG will run. The feature works if and only if consensus_config::validator_txn_enabled() && chunky_dkg_config::enabled().

public fun enabled(): bool
Implementation
public fun enabled(): bool acquires ChunkyDKGConfig {
if (exists<ChunkyDKGConfig>(@aptos_framework)) {
let config = borrow_global<ChunkyDKGConfig>(@aptos_framework);
let variant_type_name = *config.variant.type_name().bytes();
variant_type_name != b"0x1::chunky_dkg_config::ConfigOff"
} else { false }
}

new_off

Create a ConfigOff variant.

public fun new_off(): chunky_dkg_config::ChunkyDKGConfig
Implementation
public fun new_off(): ChunkyDKGConfig {
ChunkyDKGConfig {
variant: copyable_any::pack(ConfigOff {})
}
}

new_v1

Create a ConfigV1 variant.

public fun new_v1(secrecy_threshold: fixed_point64::FixedPoint64, reconstruction_threshold: fixed_point64::FixedPoint64): chunky_dkg_config::ChunkyDKGConfig
Implementation
public fun new_v1(
secrecy_threshold: FixedPoint64, reconstruction_threshold: FixedPoint64
): ChunkyDKGConfig {
ChunkyDKGConfig {
variant: copyable_any::pack(
ConfigV1 { secrecy_threshold, reconstruction_threshold }
)
}
}

current

Get the currently effective chunky DKG configuration object.

public fun current(): chunky_dkg_config::ChunkyDKGConfig
Implementation
public fun current(): ChunkyDKGConfig acquires ChunkyDKGConfig {
if (exists<ChunkyDKGConfig>(@aptos_framework)) {
*borrow_global<ChunkyDKGConfig>(@aptos_framework)
} else {
new_off()
}
}