Skip to content

Commit

Permalink
[fix] revert commits causing 6.9.6 backwards compatibility errors (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xzoz authored Feb 17, 2024
1 parent d41e872 commit 7bbbfc4
Show file tree
Hide file tree
Showing 25 changed files with 13,224 additions and 13,218 deletions.
10 changes: 3 additions & 7 deletions framework/libra-framework/sources/block.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module diem_framework::block {
use std::error;
use std::vector;
use std::option;
use std::features;
use std::string;
use diem_framework::account;
use diem_framework::event::{Self, EventHandle};
Expand All @@ -16,7 +17,6 @@ module diem_framework::block {

//////// 0L ////////
use ol_framework::epoch_boundary;
use ol_framework::ol_features;

friend diem_framework::genesis;

Expand Down Expand Up @@ -233,12 +233,8 @@ module diem_framework::block {
return
};

if (timestamp - reconfiguration::last_reconfiguration_time() >=
block_metadata_ref.epoch_interval) {
// do automatic epochs in testnet.
// in main or stage, check if the feature flag is enabled for
// manual epochs
if (!ol_features::epoch_trigger_enabled() || testnet::is_testnet()) {
if (timestamp - reconfiguration::last_reconfiguration_time() >= block_metadata_ref.epoch_interval) {
if (!features::epoch_trigger_enabled() || testnet::is_not_mainnet()) {
epoch_boundary::epoch_boundary(
vm,
reconfiguration::get_current_epoch(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ module diem_framework::genesis {
let sig = create_signer(validator.validator_config.owner_address);
proof_of_fee::set_bid(&sig, 0900, 1000); // make the genesis

if (testnet::is_testnet()) {
if (testnet::is_not_mainnet()) {
// TODO: this is for testnet purposes only
// unlock some of the genesis validators coins so they can issue
// transactions from epoch 0 in test runners.
Expand Down
11 changes: 8 additions & 3 deletions framework/libra-framework/sources/multisig_account.move
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ module diem_framework::multisig_account {
metadata_keys: vector<String>,
metadata_values: vector<vector<u8>>,
) acquires MultisigAccount {
// commit note: multisig accounts enabled permanently
assert!(features::multisig_accounts_enabled(), error::unavailable(EMULTISIG_ACCOUNTS_NOT_ENABLED_YET));
assert!(
num_signatures_required > 0 && num_signatures_required <= vector::length(&owners),
error::invalid_argument(EINVALID_SIGNATURES_REQUIRED),
Expand Down Expand Up @@ -957,7 +957,6 @@ module diem_framework::multisig_account {
use diem_std::multi_ed25519;
#[test_only]
use std::string::utf8;
#[test_only]
use std::features;

#[test_only]
Expand Down Expand Up @@ -1097,7 +1096,13 @@ module diem_framework::multisig_account {
vector[]);
}

// commit note: not a relevant test, now that it is enabled permanently
#[test(owner = @0x123)]
#[expected_failure(abort_code = 0xD000E, location = Self)]
public entry fun test_create_with_without_feature_flag_enabled_should_fail(
owner: &signer) acquires MultisigAccount {
create_account(address_of(owner));
create(owner, 2, vector[], vector[]);
}

#[test(owner_1 = @0x123, owner_2 = @0x124, owner_3 = @0x125)]
#[expected_failure(abort_code = 0x10001, location = Self)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ module diem_framework::epoch_boundary {
/// by a user, would not cause a halt.
public(friend) fun trigger_epoch(framework_signer: &signer) acquires BoundaryBit,
BoundaryStatus {
// must be mainnet or stage
assert!(!testnet::is_testnet(), ETRIGGER_EPOCH_MAINNET);
// must be mainnet
assert!(!testnet::is_not_mainnet(), ETRIGGER_EPOCH_MAINNET);
// must get root permission from governance.move
system_addresses::assert_ol(framework_signer);
let _ = can_trigger(); // will abort if false
Expand Down
84 changes: 47 additions & 37 deletions framework/libra-framework/sources/ol_sources/globals.move
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ module ol_framework::globals {
struct GlobalConstants has drop {
// For validator set.
epoch_length: u64,
val_set_at_genesis: u64,// deprecated?
subsidy_ceiling_gas: u64, // deprecated?
val_set_at_genesis: u64,
subsidy_ceiling_gas: u64,
vdf_difficulty_baseline: u64,
vdf_security_baseline: u64,
epoch_mining_thres_lower: u64,
epoch_mining_thres_upper: u64,
epoch_slow_wallet_unlock: u64,
min_blocks_per_epoch: u64, // deprecated?
min_blocks_per_epoch: u64,
validator_vouch_threshold: u64,
signing_threshold_pct: u64,
}
Expand Down Expand Up @@ -95,9 +95,32 @@ module ol_framework::globals {
get_constants().signing_threshold_pct
}

fun get_mainnet(): GlobalConstants {
/// Get the constants for the current network
fun get_constants(): GlobalConstants {

if (testnet::is_testnet()) {
return GlobalConstants {
epoch_length: 60, // seconds
val_set_at_genesis: 10,
subsidy_ceiling_gas: 296 * get_coin_scaling_factor(),
vdf_difficulty_baseline: 100,
vdf_security_baseline: 512,
epoch_mining_thres_lower: 2, // many tests depend on two proofs because
// the test harness already gives one at
// genesis to validators
epoch_mining_thres_upper: 1000, // upper bound unlimited
epoch_slow_wallet_unlock: 10,
min_blocks_per_epoch: 0,
validator_vouch_threshold: 0,
signing_threshold_pct: 3,
}
};

if (testnet::is_staging_net()) {
// All numbers like MAINNET except shorter epochs of 30 mins
// and minimum mining of 1 proof
return GlobalConstants {
epoch_length: 60 * 60 * 24, // approx 24 hours
epoch_length: 60 * 30, // 30 mins, enough for a hard miner proof.
val_set_at_genesis: 100, // max expected for BFT limits.
// See DiemVMConfig for gas constants:
// Target max gas units per transaction 100000000
Expand All @@ -108,46 +131,33 @@ module ol_framework::globals {
vdf_difficulty_baseline: 120000000, // wesolowski proof, new parameters. Benchmark available in docs/delay_tower/benchmarking
vdf_security_baseline: 512,
// NOTE Reviewers: this goes back to v5 params since the VDF cryptograpy will actually not be changed
epoch_mining_thres_lower: 7, // lower bound, allows for some operator error
epoch_mining_thres_lower: 1, // lower bound, allows for some operator error
epoch_mining_thres_upper: 72, // upper bound enforced at 20 mins per proof
epoch_slow_wallet_unlock: 1000 * get_coin_scaling_factor(), // approx 10 years for largest accounts in genesis.
min_blocks_per_epoch: 10000,
validator_vouch_threshold: 2, // Production must be more than 1 vouch validator (at least 2)
signing_threshold_pct: 3,
}
}

fun get_testnet(): GlobalConstants {
} else {
return GlobalConstants {
epoch_length: 60, // seconds
val_set_at_genesis: 10,
subsidy_ceiling_gas: 296 * get_coin_scaling_factor(),
vdf_difficulty_baseline: 100,
epoch_length: 60 * 60 * 24, // approx 24 hours at 1.4 vdf_proofs/sec
val_set_at_genesis: 100, // max expected for BFT limits.
// See DiemVMConfig for gas constants:
// Target max gas units per transaction 100000000
// target max block time: 2 secs
// target transaction per sec max gas: 20
// uses "scaled representation", since there are no decimals.
subsidy_ceiling_gas: 8640000 * get_coin_scaling_factor(), // subsidy amount assumes 24 hour epoch lengths. Also needs to be adjusted for coin_scale the onchain representation of human readable value.
vdf_difficulty_baseline: 120000000, // wesolowski proof, new parameters. Benchmark available in docs/delay_tower/benchmarking
vdf_security_baseline: 512,
epoch_mining_thres_lower: 2, // many tests depend on two proofs because
// the test harness already gives one at
// genesis to validators
epoch_mining_thres_upper: 1000, // upper bound unlimited
epoch_slow_wallet_unlock: 10,
min_blocks_per_epoch: 0,
validator_vouch_threshold: 0,
// NOTE Reviewers: this goes back to v5 params since the VDF cryptograpy will actually not be changed
epoch_mining_thres_lower: 7, // lower bound, allows for some operator error
epoch_mining_thres_upper: 72, // upper bound enforced at 20 mins per proof
epoch_slow_wallet_unlock: 1000 * get_coin_scaling_factor(), // approx 10 years for largest accounts in genesis.
min_blocks_per_epoch: 10000,
validator_vouch_threshold: 2, // Production must be more than 1 vouch validator (at least 2)
signing_threshold_pct: 3,
}
}
}

/// Get the constants for the current network
fun get_constants(): GlobalConstants {
if (testnet::is_testnet()) {
return get_testnet()
};
// staging net is for upgrade verification.
// we want check epoch boundary behavior without waiting 24h
if (testnet::is_staging_net()) {
let c = get_mainnet();
c.epoch_length = 60 * 15; // 15 mins
return c
};

get_mainnet()
}
}
}
25 changes: 0 additions & 25 deletions framework/libra-framework/sources/ol_sources/ol_features.move

This file was deleted.

7 changes: 4 additions & 3 deletions framework/libra-framework/sources/ol_sources/testnet.move
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ module ol_framework::testnet {
chain_id::get() == 4
}

//commit note: confusing is_not_mainnet
public fun is_not_mainnet(): bool {
chain_id::get() != 1
}

public fun assert_testnet(root: &signer): bool {
system_addresses::assert_ol(root);
Expand All @@ -25,8 +27,7 @@ module ol_framework::testnet {
}

public fun is_staging_net(): bool {
// NOTE: confusingly in vendor's rust code chain=2 is called TESTNET
chain_id::get() == 2
chain_id::get() == 2 // TESTNET named chain
}

#[test_only]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#[test_only]
module ol_framework::test_boundary {
use std::vector;
use std::features;
use diem_std::bls12381;
use ol_framework::mock;
use ol_framework::proof_of_fee;
Expand All @@ -11,17 +12,15 @@ module ol_framework::test_boundary {
use ol_framework::testnet;
use ol_framework::validator_universe;
use ol_framework::epoch_boundary;
use ol_framework::block;
use ol_framework::block;
use ol_framework::ol_account;
use diem_framework::stake;
use diem_framework::reconfiguration;
use diem_framework::timestamp;
use diem_framework::diem_governance;
use ol_framework::ol_features;


// use diem_std::debug::print;

// TODO: let's make these consts all caps
const Alice: address = @0x1000a;
const Bob: address = @0x1000b;
const Carol: address = @0x1000c;
Expand Down Expand Up @@ -220,22 +219,22 @@ module ol_framework::test_boundary {
// testing mainnet, so change the chainid
testnet::unset(root);

//verify trigger is not enabled
assert!(!ol_features::epoch_trigger_enabled(), 7357001);
//verify trigger is not enabled
assert!(!features::epoch_trigger_enabled(), 101);

// test setup advances to epoch #2
let epoch = reconfiguration::get_current_epoch();
assert!(epoch == 2, 7357002);
assert!(epoch == 2, 7357001);
epoch_boundary::test_set_boundary_ready(root, epoch);


// case: trigger not set and flipped
timestamp::fast_forward_seconds(1); // needed for reconfig
block::test_maybe_advance_epoch(root, 602000001, 602000000);

// test epoch advances
let epoch = reconfiguration::get_current_epoch();
assert!(epoch == 3, 7357003);
assert!(epoch == 3, 7357002);

}

Expand All @@ -250,7 +249,7 @@ module ol_framework::test_boundary {
epoch_boundary::test_set_boundary_ready(root, epoch);

// case: epoch trigger set
ol_features::change_feature_flags(root, vector[ol_features::get_epoch_trigger()], vector[]);
features::change_feature_flags(root, vector[features::get_epoch_trigger()], vector[]);
timestamp::fast_forward_seconds(1); // needed for reconfig
block::test_maybe_advance_epoch(root, 603000001, 602000000);

Expand Down
34 changes: 32 additions & 2 deletions framework/libra-framework/sources/ol_sources/tower_state.move
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ module ol_framework::tower_state {
diff.prev_sec = diff.security; // NOTE: this shouldn't change unless in testing

// VDF proofs must be even numbers.
let rando = if (testnet::is_testnet()) { toy_rng(0, 1, 0) }
let rando = if (testnet::is_not_mainnet()) { toy_rng(0, 1, 0) }
else { toy_rng(3, 2, 10) };
if (rando > 0) {
rando = rando * 2;
Expand Down Expand Up @@ -585,7 +585,7 @@ module ol_framework::tower_state {
// pick the next miner
// make sure we get an n smaller than list of miners

// Current case: if miner_index = count_miners could lead to overflow
// Current case: if miner_index = count_miners could lead to overflow

// let k = 0; // k keeps track of this loop, abort if loops too much
// while (this_miner_index >= count_miners) {
Expand Down Expand Up @@ -678,6 +678,36 @@ module ol_framework::tower_state {
};
}

// // Returns if the miner is above the account creation rate-limit
// // Permissions: PUBLIC, ANYONE
// public fun can_create_val_account(node_addr: address): bool acquires TowerProofHistory {
// if(testnet::is_testnet() || testnet::is_staging_net()) return true;
// // check if rate limited, needs 7 epochs of validating.
// if (exists<TowerProofHistory>(node_addr)) {
// return
// borrow_global<TowerProofHistory>(node_addr).epochs_since_last_account_creation
// >= EPOCHS_UNTIL_ACCOUNT_CREATION
// };
// false
// }

// #[view]
// ///
// public fun get_validator_proofs_in_epoch(): u64 acquires TowerCounter{
// let state = borrow_global<TowerCounter>(@ol_framework);
// state.validator_proofs_in_epoch
// }

// public fun get_fullnode_proofs_in_epoch(): u64 acquires TowerCounter{
// let state = borrow_global<TowerCounter>(@ol_framework);
// state.fullnode_proofs_in_epoch
// }

// public fun get_fullnode_proofs_in_epoch_above_thresh(): u64 acquires TowerCounter{
// let state = borrow_global<TowerCounter>(@ol_framework);
// state.fullnode_proofs_in_epoch_above_thresh
// }

#[view]
/// number of proof submitted over lifetime of chain
public fun get_lifetime_proof_count(): u64 acquires TowerCounter{
Expand Down
12 changes: 9 additions & 3 deletions framework/move-stdlib/sources/configs/features.move
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ module std::features {
is_enabled(DIEM_UNIQUE_IDENTIFIERS)
}

/// Whether the new epoch trigger logic is enabled.
/// Lifetime: transient
const EPOCH_TRIGGER_ENABLED: u64 = 24;
public fun get_epoch_trigger(): u64 { EPOCH_TRIGGER_ENABLED }
public fun epoch_trigger_enabled(): bool acquires Features {
is_enabled(EPOCH_TRIGGER_ENABLED)
}

// ============================================================================================
// Feature Flag Implementation

Expand Down Expand Up @@ -236,10 +244,8 @@ module std::features {
});
}

// commit note: breaking change to ABI because of visibility
#[view]
/// Check whether the feature is enabled.
public fun is_enabled(feature: u64): bool acquires Features {
fun is_enabled(feature: u64): bool acquires Features {
exists<Features>(@std) &&
contains(&borrow_global<Features>(@std).features, feature)
}
Expand Down
Loading

0 comments on commit 7bbbfc4

Please sign in to comment.