aptos_global_constants_link/
lib.rs

1// Copyright (c) Aptos
2// SPDX-License-Identifier: Apache-2.0
3
4//! The purpose of this crate is to offer a single source of truth for the definitions of shared
5//! constants within the codebase. This is useful because many different components within
6//! Aptos often require access to global constant definitions (e.g., Safety Rules,
7//! Key Manager, and Secure Storage). To avoid duplicating these definitions across crates
8//! (and better allow these constants to be updated in a single location), we define them here.
9#![forbid(unsafe_code)]
10
11/// Definitions of global cryptographic keys (e.g., as held in secure storage)
12pub const APTOS_ROOT_KEY: &str = "aptos_root";
13pub const CONSENSUS_KEY: &str = "consensus";
14pub const FULLNODE_NETWORK_KEY: &str = "fullnode_network";
15pub const OPERATOR_ACCOUNT: &str = "operator_account";
16pub const OPERATOR_KEY: &str = "operator";
17pub const OWNER_ACCOUNT: &str = "owner_account";
18pub const OWNER_KEY: &str = "owner";
19pub const VALIDATOR_NETWORK_KEY: &str = "validator_network";
20
21/// Definitions of global data items (e.g., as held in secure storage)
22pub const SAFETY_DATA: &str = "safety_data";
23pub const WAYPOINT: &str = "waypoint";
24pub const GENESIS_WAYPOINT: &str = "genesis-waypoint";
25pub const MOVE_MODULES: &str = "move_modules";
26pub const MIN_PRICE_PER_GAS_UNIT: &str = "min_price_per_gas_unit";
27
28// TODO(Gas): double check if this right
29/// Definitions of global gas constants
30
31#[cfg(any(test, feature = "testing"))]
32pub const GAS_UNIT_PRICE: u64 = 0;
33#[cfg(not(any(test, feature = "testing")))]
34pub const GAS_UNIT_PRICE: u64 = 100;
35
36pub const MAX_GAS_AMOUNT: u64 = 1_000_000;
37pub const GAS_HEADROOM_NUMERATOR: u64 = 3;
38pub const GAS_HEADROOM_DENOMINATOR: u64 = 2;
39
40/// Gas costs are dynamic based on storage, so the simulation values need some headroom applied by
41/// the user if using it to estimate gas
42pub fn adjust_gas_headroom(gas_used: u64, max_possible_gas: u64) -> u64 {
43    std::cmp::min(
44        max_possible_gas,
45        (gas_used.saturating_mul(GAS_HEADROOM_NUMERATOR)).saturating_div(GAS_HEADROOM_DENOMINATOR),
46    )
47}