chunky_dkg - [testnet]
Chunky DKG on-chain states and helper functions.
use 0x1::chunky_dkg_config;use 0x1::event;use 0x1::option;use 0x1::system_addresses;use 0x1::timestamp;use 0x1::validator_consensus_info;Constants
const ECHUNKY_DKG_IN_PROGRESS: u64 = 1;const ECHUNKY_DKG_NOT_IN_PROGRESS: u64 = 2;Structs
ChunkyDKGSessionMetadata
This can be considered as the public input of Chunky DKG.
struct ChunkyDKGSessionMetadata has copy, drop, storeFields
-
dealer_epoch: u64 -
chunky_dkg_config: chunky_dkg_config::ChunkyDKGConfig -
dealer_validator_set: vector<validator_consensus_info::ValidatorConsensusInfo> -
target_validator_set: vector<validator_consensus_info::ValidatorConsensusInfo>
ChunkyDKGStartEvent
#[event]struct ChunkyDKGStartEvent has drop, storeFields
-
session_metadata: chunky_dkg::ChunkyDKGSessionMetadata -
start_time_us: u64
ChunkyDKGSessionState
The input and output of a Chunky DKG session.
The validator set of epoch x works together for a Chunky DKG output for the target validator set of epoch x+1.
struct ChunkyDKGSessionState has copy, drop, storeFields
-
metadata: chunky_dkg::ChunkyDKGSessionMetadata -
start_time_us: u64 -
aggregated_subtranscript: vector<u8>
Resources
ChunkyDKGState
The completed and in-progress Chunky DKG sessions.
struct ChunkyDKGState has keyFields
-
last_completed: option::Option<chunky_dkg::ChunkyDKGSessionState> -
in_progress: option::Option<chunky_dkg::ChunkyDKGSessionState>
Functions
initialize
Called in genesis to initialize on-chain states.
public fun initialize(aptos_framework: &signer)Implementation
public fun initialize(aptos_framework: &signer) { system_addresses::assert_aptos_framework(aptos_framework); if (!exists<ChunkyDKGState>(@aptos_framework)) { move_to<ChunkyDKGState>( aptos_framework, ChunkyDKGState { last_completed: std::option::none(), in_progress: std::option::none() } ); }}start
Mark on-chain Chunky DKG state as in-progress. Notify validators to start Chunky DKG.
public(friend) fun start(dealer_epoch: u64, chunky_dkg_config: chunky_dkg_config::ChunkyDKGConfig, dealer_validator_set: vector<validator_consensus_info::ValidatorConsensusInfo>, target_validator_set: vector<validator_consensus_info::ValidatorConsensusInfo>)Implementation
public(friend) fun start( dealer_epoch: u64, chunky_dkg_config: ChunkyDKGConfig, dealer_validator_set: vector<ValidatorConsensusInfo>, target_validator_set: vector<ValidatorConsensusInfo>) acquires ChunkyDKGState { let chunky_dkg_state = borrow_global_mut<ChunkyDKGState>(@aptos_framework); let new_session_metadata = ChunkyDKGSessionMetadata { dealer_epoch, chunky_dkg_config, dealer_validator_set, target_validator_set }; let start_time_us = timestamp::now_microseconds(); chunky_dkg_state.in_progress = std::option::some( ChunkyDKGSessionState { metadata: new_session_metadata, start_time_us, aggregated_subtranscript: vector[] } );
emit( ChunkyDKGStartEvent { start_time_us, session_metadata: new_session_metadata } );}finish
Put a transcript into the currently incomplete Chunky DKG session, then mark it completed.
Abort if Chunky DKG is not in progress.
public(friend) fun finish(aggregated_subtranscript: vector<u8>)Implementation
public(friend) fun finish(aggregated_subtranscript: vector<u8>) acquires ChunkyDKGState { let chunky_dkg_state = borrow_global_mut<ChunkyDKGState>(@aptos_framework); assert!( chunky_dkg_state.in_progress.is_some(), error::invalid_state(ECHUNKY_DKG_NOT_IN_PROGRESS) ); let session = chunky_dkg_state.in_progress.extract(); session.aggregated_subtranscript = aggregated_subtranscript; chunky_dkg_state.last_completed = option::some(session); chunky_dkg_state.in_progress = option::none();}try_clear_incomplete_session
Delete the currently incomplete session, if it exists.
public fun try_clear_incomplete_session(fx: &signer)Implementation
public fun try_clear_incomplete_session(fx: &signer) acquires ChunkyDKGState { system_addresses::assert_aptos_framework(fx); if (exists<ChunkyDKGState>(@aptos_framework)) { let chunky_dkg_state = borrow_global_mut<ChunkyDKGState>(@aptos_framework); chunky_dkg_state.in_progress = option::none(); }}incomplete_session
Return the incomplete Chunky DKG session state, if it exists.
public fun incomplete_session(): option::Option<chunky_dkg::ChunkyDKGSessionState>Implementation
public fun incomplete_session(): Option<ChunkyDKGSessionState> acquires ChunkyDKGState { if (exists<ChunkyDKGState>(@aptos_framework)) { borrow_global<ChunkyDKGState>(@aptos_framework).in_progress } else { option::none() }}session_dealer_epoch
Return the dealer epoch of a ChunkyDKGSessionState.
public fun session_dealer_epoch(session: &chunky_dkg::ChunkyDKGSessionState): u64Implementation
public fun session_dealer_epoch(session: &ChunkyDKGSessionState): u64 { session.metadata.dealer_epoch}Specification
initialize
public fun initialize(aptos_framework: &signer)let aptos_framework_addr = signer::address_of(aptos_framework);aborts_if aptos_framework_addr != @aptos_framework;start
public(friend) fun start(dealer_epoch: u64, chunky_dkg_config: chunky_dkg_config::ChunkyDKGConfig, dealer_validator_set: vector<validator_consensus_info::ValidatorConsensusInfo>, target_validator_set: vector<validator_consensus_info::ValidatorConsensusInfo>)aborts_if !exists<ChunkyDKGState>(@aptos_framework);aborts_if !exists<timestamp::CurrentTimeMicroseconds>(@aptos_framework);finish
public(friend) fun finish(aggregated_subtranscript: vector<u8>)requires exists<ChunkyDKGState>(@aptos_framework);requires option::is_some(global<ChunkyDKGState>(@aptos_framework).in_progress);aborts_if false;try_clear_incomplete_session
public fun try_clear_incomplete_session(fx: &signer)let addr = signer::address_of(fx);aborts_if addr != @aptos_framework;incomplete_session
public fun incomplete_session(): option::Option<chunky_dkg::ChunkyDKGSessionState>aborts_if false;session_dealer_epoch
public fun session_dealer_epoch(session: &chunky_dkg::ChunkyDKGSessionState): u64aborts_if false;