Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Module 0x1::execution_config

Maintains the execution config for the blockchain. The config is stored in a Reconfiguration, and may be updated by root.

use 0x1::chain_status;
use 0x1::config_buffer;
use 0x1::error;
use 0x1::reconfiguration;
use 0x1::system_addresses;

Resource ExecutionConfig

struct ExecutionConfig has drop, store, key
Fields
config: vector<u8>

Constants

The provided on chain config bytes are empty or invalid

const EINVALID_CONFIG: u64 = 1;

Function set

Deprecated by set_for_next_epoch().

WARNING: calling this while randomness is enabled will trigger a new epoch without randomness!

TODO: update all the tests that reference this function, then disable this function.

public fun set(account: &signer, config: vector<u8>)
Implementation
public fun set(account: &signer, config: vector<u8>) acquires ExecutionConfig {
    system_addresses::assert_aptos_framework(account);
    chain_status::assert_genesis();

    assert!(config.length() > 0, error::invalid_argument(EINVALID_CONFIG));

    if (exists<ExecutionConfig>(@aptos_framework)) {
        let config_ref = &mut borrow_global_mut<ExecutionConfig>(@aptos_framework).config;
        *config_ref = config;
    } else {
        move_to(account, ExecutionConfig { config });
    };
    // Need to trigger reconfiguration so validator nodes can sync on the updated configs.
    reconfiguration::reconfigure();
}

Function set_for_next_epoch

This can be called by on-chain governance to update on-chain execution configs for the next epoch. Example usage:

aptos_framework::execution_config::set_for_next_epoch(&framework_signer, some_config_bytes);
aptos_framework::aptos_governance::reconfigure(&framework_signer);
public fun set_for_next_epoch(account: &signer, config: vector<u8>)
Implementation
public fun set_for_next_epoch(account: &signer, config: vector<u8>) {
    system_addresses::assert_aptos_framework(account);
    assert!(config.length() > 0, error::invalid_argument(EINVALID_CONFIG));
    config_buffer::upsert(ExecutionConfig { config });
}

Function on_new_epoch

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

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

Specification

pragma verify = true;
pragma aborts_if_is_strict;

Function set

public fun set(account: &signer, config: vector<u8>)

Ensure the caller is admin When setting now time must be later than last_reconfiguration_time.

pragma verify_duration_estimate = 600;
let addr = signer::address_of(account);
requires chain_status::is_genesis();
requires exists<staking_config::StakingRewardsConfig>(@aptos_framework);
requires len(config) > 0;
include features::spec_periodical_reward_rate_decrease_enabled() ==> staking_config::StakingRewardsConfigEnabledRequirement;
include aptos_coin::ExistsAptosCoin;
requires system_addresses::is_aptos_framework_address(addr);
requires timestamp::spec_now_microseconds() >= reconfiguration::last_reconfiguration_time();
ensures exists<ExecutionConfig>(@aptos_framework);

Function set_for_next_epoch

public fun set_for_next_epoch(account: &signer, config: vector<u8>)
include config_buffer::SetForNextEpochAbortsIf;

Function on_new_epoch

public(friend) fun on_new_epoch(framework: &signer)
requires @aptos_framework == std::signer::address_of(framework);
include config_buffer::OnNewEpochRequirement<ExecutionConfig>;
aborts_if false;