Skip to content

Commit

Permalink
fix!(general): rename micros to nanos (#1866)
Browse files Browse the repository at this point in the history
* fix!(general): rename micros to nanos

* Fix comment

* Undo format changes

* refactor mock gas coin value

---------

Co-authored-by: Thibault Martinez <[email protected]>
  • Loading branch information
Thoralf-M and thibault-martinez authored Aug 22, 2024
1 parent 33dee04 commit 509609d
Show file tree
Hide file tree
Showing 34 changed files with 306 additions and 308 deletions.
4 changes: 2 additions & 2 deletions crates/iota-benchmark/src/drivers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ impl BenchmarkStats {
"latency (min)",
"latency (p50)",
"latency (p99)",
"gas used (MICROS total)",
"gas used/hr (MICROS approx.)",
"gas used (NANOS total)",
"gas used/hr (NANOS approx.)",
]);
let mut row = Row::new();
row.add_cell(Cell::new(self.duration.as_secs()));
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-benchmark/src/workloads/transfer_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{
};

/// TODO: This should be the amount that is being transferred instead of
/// MAX_GAS. Number of micros sent to each address on each batch transfer
/// MAX_GAS. Number of nanos sent to each address on each batch transfer
const _TRANSFER_AMOUNT: u64 = 1;

#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-config/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::{
// Default max number of concurrent requests served
pub const DEFAULT_GRPC_CONCURRENCY_LIMIT: usize = 20000000000;

/// Default gas price of 100 Micros
/// Default gas price of 1000 Nanos
pub const DEFAULT_VALIDATOR_GAS_PRICE: u64 = iota_types::transaction::DEFAULT_VALIDATOR_GAS_PRICE;

/// Default commission rate of 2%
Expand Down
8 changes: 3 additions & 5 deletions crates/iota-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1711,13 +1711,11 @@ impl AuthorityState {
let mut gas_object_refs = transaction.gas().to_vec();
let ((gas_status, checked_input_objects), mock_gas) = if transaction.gas().is_empty() {
let sender = transaction.sender();
// use a 1B iota coin
const MICROS_TO_IOTA: u64 = 1_000_000_000;
const DRY_RUN_IOTA: u64 = 1_000_000_000;
let max_coin_value = MICROS_TO_IOTA * DRY_RUN_IOTA;
// use a 1B iota coin, which should be enough to cover all cases
const MOCK_GAS_COIN_VALUE: u64 = 1_000_000_000_000_000_000;
let gas_object_id = ObjectID::random();
let gas_object = Object::new_move(
MoveObject::new_gas_coin(OBJECT_START_VERSION, gas_object_id, max_coin_value),
MoveObject::new_gas_coin(OBJECT_START_VERSION, gas_object_id, MOCK_GAS_COIN_VALUE),
Owner::AddressOwner(sender),
TransactionDigest::genesis_marker(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module iota::royalty_policy_tests {
// 1% royalty
royalty_policy::set(&mut policy, &cap, 100);

// Requires 1_000 MICROS, coin has only 999
// Requires 1_000 NANOS, coin has only 999
let mut request = policy::new_request(test::fresh_id(ctx), 100_000, test::fresh_id(ctx));
let mut payment = coin::mint_for_testing<IOTA>(999, ctx);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module iota_system::validator {
const MAX_VALIDATOR_METADATA_LENGTH: u64 = 256;

// TODO: Move this to onchain config when we have a good way to do it.
/// Max gas price a validator can set is 100K MICROS.
/// Max gas price a validator can set is 100K NANOS.
const MAX_VALIDATOR_GAS_PRICE: u64 = 100_000;

public struct ValidatorMetadata has store {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module iota_system::stake_tests {
// Generated using [fn test_proof_of_possession]
const NEW_VALIDATOR_POP: vector<u8> = x"8b93fc1b33379e2796d361c4056f0f04ad5aea7f4a8c02eaac57340ff09b6dc158eb1945eece103319167f420daf0cb3";

const MICROS_PER_IOTA: u64 = 1_000_000_000;
const NANOS_PER_IOTA: u64 = 1_000_000_000;

#[test]
fun test_split_join_staked_iota() {
Expand All @@ -55,7 +55,7 @@ module iota_system::stake_tests {
{
let mut staked_iota = scenario.take_from_sender<StakedIota>();
let ctx = scenario.ctx();
staked_iota.split_to_sender(20 * MICROS_PER_IOTA, ctx);
staked_iota.split_to_sender(20 * NANOS_PER_IOTA, ctx);
scenario.return_to_sender(staked_iota);
};

Expand All @@ -70,12 +70,12 @@ module iota_system::stake_tests {

let amount1 = part1.amount();
let amount2 = part2.amount();
assert!(amount1 == 20 * MICROS_PER_IOTA || amount1 == 40 * MICROS_PER_IOTA, 102);
assert!(amount2 == 20 * MICROS_PER_IOTA || amount2 == 40 * MICROS_PER_IOTA, 103);
assert!(amount1 + amount2 == 60 * MICROS_PER_IOTA, 104);
assert!(amount1 == 20 * NANOS_PER_IOTA || amount1 == 40 * NANOS_PER_IOTA, 102);
assert!(amount2 == 20 * NANOS_PER_IOTA || amount2 == 40 * NANOS_PER_IOTA, 103);
assert!(amount1 + amount2 == 60 * NANOS_PER_IOTA, 104);

part1.join(part2);
assert!(part1.amount() == 60 * MICROS_PER_IOTA, 105);
assert!(part1.amount() == 60 * NANOS_PER_IOTA, 105);
scenario.return_to_sender(part1);
};
scenario_val.end();
Expand Down Expand Up @@ -120,7 +120,7 @@ module iota_system::stake_tests {
let mut staked_iota = scenario.take_from_sender<StakedIota>();
let ctx = scenario.ctx();
// The remaining amount after splitting is below the threshold so this should fail.
staked_iota.split_to_sender(1 * MICROS_PER_IOTA + 1, ctx);
staked_iota.split_to_sender(1 * NANOS_PER_IOTA + 1, ctx);
scenario.return_to_sender(staked_iota);
};
scenario_val.end();
Expand All @@ -140,7 +140,7 @@ module iota_system::stake_tests {
let mut staked_iota = scenario.take_from_sender<StakedIota>();
let ctx = scenario.ctx();
// The remaining amount after splitting is below the threshold so this should fail.
let stake = staked_iota.split(1 * MICROS_PER_IOTA + 1, ctx);
let stake = staked_iota.split(1 * NANOS_PER_IOTA + 1, ctx);
test_utils::destroy(stake);
scenario.return_to_sender(staked_iota);
};
Expand All @@ -162,11 +162,11 @@ module iota_system::stake_tests {

// Create a stake to VALIDATOR_ADDR_1.
system_state_mut_ref.request_add_stake(
coin::mint_for_testing(60 * MICROS_PER_IOTA, ctx), VALIDATOR_ADDR_1, ctx
coin::mint_for_testing(60 * NANOS_PER_IOTA, ctx), VALIDATOR_ADDR_1, ctx
);

assert!(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_1) == 100 * MICROS_PER_IOTA, 101);
assert!(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_2) == 100 * MICROS_PER_IOTA, 102);
assert!(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_1) == 100 * NANOS_PER_IOTA, 101);
assert!(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_2) == 100 * NANOS_PER_IOTA, 102);

test_scenario::return_shared(system_state);
};
Expand All @@ -177,21 +177,21 @@ module iota_system::stake_tests {
{

let staked_iota = scenario.take_from_sender<StakedIota>();
assert!(staked_iota.amount() == 60 * MICROS_PER_IOTA, 105);
assert!(staked_iota.amount() == 60 * NANOS_PER_IOTA, 105);


let mut system_state = scenario.take_shared<IotaSystemState>();
let system_state_mut_ref = &mut system_state;

assert!(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_1) == 160 * MICROS_PER_IOTA, 103);
assert!(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_2) == 100 * MICROS_PER_IOTA, 104);
assert!(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_1) == 160 * NANOS_PER_IOTA, 103);
assert!(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_2) == 100 * NANOS_PER_IOTA, 104);

let ctx = scenario.ctx();

// Unstake from VALIDATOR_ADDR_1
system_state_mut_ref.request_withdraw_stake(staked_iota, ctx);

assert!(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_1) == 160 * MICROS_PER_IOTA, 107);
assert!(system_state_mut_ref.validator_stake_amount(VALIDATOR_ADDR_1) == 160 * NANOS_PER_IOTA, 107);
test_scenario::return_shared(system_state);
};

Expand All @@ -200,7 +200,7 @@ module iota_system::stake_tests {
scenario.next_tx(STAKER_ADDR_1);
{
let mut system_state = scenario.take_shared<IotaSystemState>();
assert!(system_state.validator_stake_amount(VALIDATOR_ADDR_1) == 100 * MICROS_PER_IOTA, 107);
assert!(system_state.validator_stake_amount(VALIDATOR_ADDR_1) == 100 * NANOS_PER_IOTA, 107);
test_scenario::return_shared(system_state);
};
scenario_val.end();
Expand All @@ -227,7 +227,7 @@ module iota_system::stake_tests {

assert_validator_total_stake_amounts(
vector[VALIDATOR_ADDR_1, VALIDATOR_ADDR_2],
vector[200 * MICROS_PER_IOTA, 100 * MICROS_PER_IOTA],
vector[200 * NANOS_PER_IOTA, 100 * NANOS_PER_IOTA],
scenario
);

Expand All @@ -242,7 +242,7 @@ module iota_system::stake_tests {

advance_epoch(scenario);

let reward_amt = if (should_distribute_rewards) 20 * MICROS_PER_IOTA else 0;
let reward_amt = if (should_distribute_rewards) 20 * NANOS_PER_IOTA else 0;

// Make sure stake withdrawal happens
scenario.next_tx(STAKER_ADDR_1);
Expand All @@ -253,15 +253,15 @@ module iota_system::stake_tests {
assert!(!system_state_mut_ref.validators().is_active_validator_by_iota_address(VALIDATOR_ADDR_1), 0);

let staked_iota = scenario.take_from_sender<StakedIota>();
assert_eq(staked_iota.amount(), 100 * MICROS_PER_IOTA);
assert_eq(staked_iota.amount(), 100 * NANOS_PER_IOTA);

// Unstake from VALIDATOR_ADDR_1
assert_eq(total_iota_balance(STAKER_ADDR_1, scenario), 0);
let ctx = scenario.ctx();
system_state_mut_ref.request_withdraw_stake(staked_iota, ctx);

// Make sure they have all of their stake.
assert_eq(total_iota_balance(STAKER_ADDR_1, scenario), 100 * MICROS_PER_IOTA + reward_amt);
assert_eq(total_iota_balance(STAKER_ADDR_1, scenario), 100 * NANOS_PER_IOTA + reward_amt);

test_scenario::return_shared(system_state);
};
Expand All @@ -271,7 +271,7 @@ module iota_system::stake_tests {
unstake(VALIDATOR_ADDR_1, 0, scenario);

// Make sure have all of their stake. NB there is no epoch change. This is immediate.
assert_eq(total_iota_balance(VALIDATOR_ADDR_1, scenario), 100 * MICROS_PER_IOTA + reward_amt);
assert_eq(total_iota_balance(VALIDATOR_ADDR_1, scenario), 100 * NANOS_PER_IOTA + reward_amt);

scenario_val.end();
}
Expand All @@ -293,7 +293,7 @@ module iota_system::stake_tests {
advance_epoch_with_reward_amounts(0, 80, scenario);

// Each validator pool gets 40 IOTA.
let reward_amt = 20 * MICROS_PER_IOTA;
let reward_amt = 20 * NANOS_PER_IOTA;

// Make sure stake withdrawal happens
scenario.next_tx(STAKER_ADDR_1);
Expand All @@ -302,15 +302,15 @@ module iota_system::stake_tests {
let system_state_mut_ref = &mut system_state;

let staked_iota = scenario.take_from_sender<StakedIota>();
assert_eq(staked_iota.amount(), 100 * MICROS_PER_IOTA);
assert_eq(staked_iota.amount(), 100 * NANOS_PER_IOTA);

// Unstake from VALIDATOR_ADDR_1
assert_eq(total_iota_balance(STAKER_ADDR_1, scenario), 0);
let ctx = scenario.ctx();
system_state_mut_ref.request_withdraw_stake(staked_iota, ctx);

// Make sure they have all of their stake.
assert_eq(total_iota_balance(STAKER_ADDR_1, scenario), 100 * MICROS_PER_IOTA + reward_amt);
assert_eq(total_iota_balance(STAKER_ADDR_1, scenario), 100 * NANOS_PER_IOTA + reward_amt);

test_scenario::return_shared(system_state);
};
Expand All @@ -320,7 +320,7 @@ module iota_system::stake_tests {
unstake(VALIDATOR_ADDR_1, 0, scenario);

// Make sure have all of their stake. NB there is no epoch change. This is immediate.
assert_eq(total_iota_balance(VALIDATOR_ADDR_1, scenario), 100 * MICROS_PER_IOTA + reward_amt);
assert_eq(total_iota_balance(VALIDATOR_ADDR_1, scenario), 100 * NANOS_PER_IOTA + reward_amt);

scenario_val.end();
}
Expand Down Expand Up @@ -365,7 +365,7 @@ module iota_system::stake_tests {

add_validator_candidate(NEW_VALIDATOR_ADDR, b"name5", b"/ip4/127.0.0.1/udp/85", NEW_VALIDATOR_PUBKEY, NEW_VALIDATOR_POP, scenario);

// Delegate 100 MICROS to the preactive validator
// Delegate 100 NANOS to the preactive validator
stake_with(STAKER_ADDR_1, NEW_VALIDATOR_ADDR, 100, scenario);

// Advance epoch twice with some rewards
Expand All @@ -374,7 +374,7 @@ module iota_system::stake_tests {

// Unstake from the preactive validator. There should be no rewards earned.
unstake(STAKER_ADDR_1, 0, scenario);
assert_eq(total_iota_balance(STAKER_ADDR_1, scenario), 100 * MICROS_PER_IOTA);
assert_eq(total_iota_balance(STAKER_ADDR_1, scenario), 100 * NANOS_PER_IOTA);

scenario_val.end();
}
Expand Down Expand Up @@ -486,7 +486,7 @@ module iota_system::stake_tests {

add_validator_candidate(NEW_VALIDATOR_ADDR, b"name2", b"/ip4/127.0.0.1/udp/82", NEW_VALIDATOR_PUBKEY, NEW_VALIDATOR_POP, scenario);

// Delegate 100 MICROS to the preactive validator
// Delegate 100 NANOS to the preactive validator
stake_with(STAKER_ADDR_1, NEW_VALIDATOR_ADDR, 100, scenario);

// Advance epoch and give out some rewards. The candidate should get nothing, of course.
Expand All @@ -502,7 +502,7 @@ module iota_system::stake_tests {

// Unstake now and the staker should get no rewards.
unstake(STAKER_ADDR_1, 0, scenario);
assert_eq(total_iota_balance(STAKER_ADDR_1, scenario), 100 * MICROS_PER_IOTA);
assert_eq(total_iota_balance(STAKER_ADDR_1, scenario), 100 * NANOS_PER_IOTA);

scenario_val.end();
}
Expand Down Expand Up @@ -534,8 +534,8 @@ module iota_system::stake_tests {
rates: &Table<u64, PoolTokenExchangeRate>, epoch: u64, iota_amount: u64, pool_token_amount: u64
) {
let rate = &rates[epoch];
assert_eq(rate.iota_amount(), iota_amount * MICROS_PER_IOTA);
assert_eq(rate.pool_token_amount(), pool_token_amount * MICROS_PER_IOTA);
assert_eq(rate.iota_amount(), iota_amount * NANOS_PER_IOTA);
assert_eq(rate.pool_token_amount(), pool_token_amount * NANOS_PER_IOTA);
}

fun set_up_iota_system_state() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module iota_system::governance_test_utils {
use iota::balance::Balance;
use iota::timelock;

const MICROS_PER_IOTA: u64 = 1_000_000_000;
const NANOS_PER_IOTA: u64 = 1_000_000_000;

public fun create_validator_for_testing(
addr: address, init_stake_amount_in_iota: u64, ctx: &mut TxContext
Expand All @@ -37,7 +37,7 @@ module iota_system::governance_test_utils {
b"/ip4/127.0.0.1/udp/80",
b"/ip4/127.0.0.1/udp/80",
b"/ip4/127.0.0.1/udp/80",
option::some(balance::create_for_testing<IOTA>(init_stake_amount_in_iota * MICROS_PER_IOTA)),
option::some(balance::create_for_testing<IOTA>(init_stake_amount_in_iota * NANOS_PER_IOTA)),
1,
0,
true,
Expand Down Expand Up @@ -77,13 +77,13 @@ module iota_system::governance_test_utils {
// We mint the given amount so the system appears to have a total supply of iota_supply_amount,
// but we burn it since we cannot put it anywhere.
let iota_total_supply_balance = iota_treasury_cap.mint_balance(
iota_supply_amount * MICROS_PER_IOTA,
iota_supply_amount * NANOS_PER_IOTA,
ctx,
);
iota_total_supply_balance.destroy_for_testing();

let storage_fund = iota_treasury_cap.mint_balance(
storage_fund_amount * MICROS_PER_IOTA,
storage_fund_amount * NANOS_PER_IOTA,
ctx,
);

Expand Down Expand Up @@ -147,7 +147,7 @@ module iota_system::governance_test_utils {
public fun advance_epoch_with_target_reward_amounts(
validator_target_reward: u64, storage_charge: u64, computation_charge: u64, scenario: &mut Scenario
) {
let storage_rebate = advance_epoch_with_reward_amounts_return_rebate(validator_target_reward * MICROS_PER_IOTA, storage_charge * MICROS_PER_IOTA, computation_charge * MICROS_PER_IOTA, 0, 0, scenario);
let storage_rebate = advance_epoch_with_reward_amounts_return_rebate(validator_target_reward * NANOS_PER_IOTA, storage_charge * NANOS_PER_IOTA, computation_charge * NANOS_PER_IOTA, 0, 0, scenario);
test_utils::destroy(storage_rebate)
}

Expand All @@ -165,7 +165,7 @@ module iota_system::governance_test_utils {

let validator_target_reward = computation_charge;
let storage_rebate = system_state.advance_epoch_for_testing(
new_epoch, 1, validator_target_reward * MICROS_PER_IOTA, storage_charge * MICROS_PER_IOTA, computation_charge * MICROS_PER_IOTA, 0, 0, reward_slashing_rate, 0, ctx
new_epoch, 1, validator_target_reward * NANOS_PER_IOTA, storage_charge * NANOS_PER_IOTA, computation_charge * NANOS_PER_IOTA, 0, 0, reward_slashing_rate, 0, ctx
);
test_utils::destroy(storage_rebate);
test_scenario::return_shared(system_state);
Expand All @@ -180,7 +180,7 @@ module iota_system::governance_test_utils {

let ctx = scenario.ctx();

system_state.request_add_stake(coin::mint_for_testing(amount * MICROS_PER_IOTA, ctx), validator, ctx);
system_state.request_add_stake(coin::mint_for_testing(amount * NANOS_PER_IOTA, ctx), validator, ctx);
test_scenario::return_shared(system_state);
}

Expand Down Expand Up @@ -219,7 +219,7 @@ module iota_system::governance_test_utils {
0,
ctx
);
system_state.request_add_stake(coin::mint_for_testing<IOTA>(init_stake_amount * MICROS_PER_IOTA, ctx), validator, ctx);
system_state.request_add_stake(coin::mint_for_testing<IOTA>(init_stake_amount * NANOS_PER_IOTA, ctx), validator, ctx);
system_state.request_add_validator_for_testing(0, ctx);
test_scenario::return_shared(system_state);
}
Expand Down
Loading

0 comments on commit 509609d

Please sign in to comment.