diff --git a/framework/libra-framework/sources/block.move b/framework/libra-framework/sources/block.move index 8df83ea52..bd8f10bff 100644 --- a/framework/libra-framework/sources/block.move +++ b/framework/libra-framework/sources/block.move @@ -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, diff --git a/framework/libra-framework/sources/ol_sources/config/ol_features.move b/framework/libra-framework/sources/ol_sources/config/ol_features.move new file mode 100644 index 000000000..27dc0a2a1 --- /dev/null +++ b/framework/libra-framework/sources/ol_sources/config/ol_features.move @@ -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) + } +} diff --git a/framework/libra-framework/sources/ol_sources/tests/boundary.test.move b/framework/libra-framework/sources/ol_sources/tests/boundary.test.move index 659f207d1..3f997878f 100644 --- a/framework/libra-framework/sources/ol_sources/tests/boundary.test.move +++ b/framework/libra-framework/sources/ol_sources/tests/boundary.test.move @@ -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; @@ -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); @@ -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); } - - } diff --git a/framework/libra-framework/sources/ol_sources/tests/governance.test.move b/framework/libra-framework/sources/ol_sources/tests/governance.test.move index f22017e90..cd5c702a8 100644 --- a/framework/libra-framework/sources/ol_sources/tests/governance.test.move +++ b/framework/libra-framework/sources/ol_sources/tests/governance.test.move @@ -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)] @@ -63,4 +65,14 @@ module ol_framework::test_governance { let (can_resolve, _err) = voting::check_resolvable_ex_hash(@ol_framework, prop_id); assert!(can_resolve, 73570007); } -} \ No newline at end of file + + + #[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); + } +} diff --git a/framework/libra-framework/sources/reconfiguration.move b/framework/libra-framework/sources/reconfiguration.move index 908bc2099..1c921123f 100644 --- a/framework/libra-framework/sources/reconfiguration.move +++ b/framework/libra-framework/sources/reconfiguration.move @@ -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; diff --git a/framework/libra-framework/sources/transaction_validation.move b/framework/libra-framework/sources/transaction_validation.move index 10ffa0a71..4538bb7fd 100644 --- a/framework/libra-framework/sources/transaction_validation.move +++ b/framework/libra-framework/sources/transaction_validation.move @@ -1,6 +1,5 @@ module diem_framework::transaction_validation { use std::error; - // use std::features; use std::signer; use std::vector; diff --git a/framework/move-stdlib/sources/configs/features.move b/framework/move-stdlib/sources/configs/features.move index 8fda2ab06..05785d56e 100644 --- a/framework/move-stdlib/sources/configs/features.move +++ b/framework/move-stdlib/sources/configs/features.move @@ -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 @@ -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(@std) && contains(&borrow_global(@std).features, feature) }