Skip to content

Commit

Permalink
separate feature flag definitions from evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Jan 13, 2025
1 parent 8c7fc88 commit b5158ab
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 44 deletions.
2 changes: 0 additions & 2 deletions framework/libra-framework/sources/block.move
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ module diem_framework::block {
};

if (timestamp - reconfiguration::last_reconfiguration_time() >= block_metadata_ref.epoch_interval) {
// if (!features::epoch_trigger_enabled() ||
// testnet::is_testnet()) {
if (testnet::is_testnet()) {
epoch_boundary::epoch_boundary(
vm,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

module ol_framework::ol_features_constants {
use std::features;
/// 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 {
features::is_enabled(EPOCH_TRIGGER_ENABLED)
}


//////// TEST HELPERS ////////
#[test_only]
const TEST_DUMMY_FLAG: u64 = 8675309;
#[test_only]
public fun test_get_dummy_flag(): u64 { TEST_DUMMY_FLAG }
#[test_only]
public fun test_dummy_flag_enabled(): bool {
features::is_enabled(TEST_DUMMY_FLAG)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module ol_framework::test_boundary {
use ol_framework::epoch_boundary;
use ol_framework::block;
use ol_framework::ol_account;
use ol_framework::ol_features_constants;

use diem_std::debug::print;

Expand Down Expand Up @@ -368,31 +369,6 @@ module ol_framework::test_boundary {
}


// #[test(root = @ol_framework, alice = @0x1000a, marlon = @0x12345)]
// fun test_epoch_trigger_disabled(root: &signer) {
// common_test_setup(root);
// // testing mainnet, so change the chainid
// testnet::unset(root);

// //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, 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, 7357002);

// }

#[test(root = @ol_framework, alice = @0x1000a, marlon = @0x12345)]
fun test_epoch_trigger_enabled(root: &signer) {
common_test_setup(root);
Expand All @@ -404,19 +380,18 @@ module ol_framework::test_boundary {
epoch_boundary::test_set_boundary_ready(root, epoch);

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

// test epoch did not advance and needs to be triggered
let epoch = reconfiguration::get_current_epoch();
assert!(epoch == 2, 7357002);
assert!(epoch == 2, 7357003);

// test epoch can be triggered and advances
epoch_boundary::test_trigger(root);
let epoch = reconfiguration::get_current_epoch();
assert!(epoch == 3, 7357002);
assert!(epoch == 3, 7357004);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module ol_framework::test_governance {
use diem_framework::governance_proposal::GovernanceProposal;
use diem_framework::voting;
use diem_framework::timestamp;
use ol_framework::ol_features_constants;
use std::features;
// use diem_std::debug::print;

#[test(root = @ol_framework, alice = @0x1000a, bob = @0x1000b)]
Expand Down Expand Up @@ -63,4 +65,14 @@ module ol_framework::test_governance {
let (can_resolve, _err) = voting::check_resolvable_ex_hash<GovernanceProposal>(@ol_framework, prop_id);
assert!(can_resolve, 73570007);
}
}


#[test(root = @ol_framework, alice = @0x1000a, marlon = @0x12345)]
fun test_enable_ol_features(root: &signer) {
let _vals = mock::genesis_n_vals(root, 2);
// case: set a dummy feature flag
features::change_feature_flags(root, vector[ol_features_constants::test_get_dummy_flag()], vector[]);
assert!(features::is_enabled(ol_features_constants::test_get_dummy_flag()), 7357002);
assert!(ol_features_constants::test_dummy_flag_enabled(), 7357003);
}
}
1 change: 0 additions & 1 deletion framework/libra-framework/sources/reconfiguration.move
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/// to synchronize configuration changes for the validators.
module diem_framework::reconfiguration {
use std::error;
// use std::features;
use std::signer;

use diem_framework::account;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module diem_framework::transaction_validation {
use std::error;
// use std::features;
use std::signer;
use std::vector;

Expand Down
11 changes: 2 additions & 9 deletions framework/move-stdlib/sources/configs/features.move
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,6 @@ 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 @@ -244,8 +236,9 @@ module std::features {
});
}

#[view]
/// Check whether the feature is enabled.
fun is_enabled(feature: u64): bool acquires Features {
public fun is_enabled(feature: u64): bool acquires Features {
exists<Features>(@std) &&
contains(&borrow_global<Features>(@std).features, feature)
}
Expand Down

0 comments on commit b5158ab

Please sign in to comment.