From 63f1d2a68b2b5c48625bae2380a44902eb5204e2 Mon Sep 17 00:00:00 2001 From: Aaron Gao Date: Fri, 25 Oct 2024 16:55:22 -0700 Subject: [PATCH] fix upgrade --- ...st_get_events_by_account_event_handle.json | 15 ++++++++++- .../aptos-framework/doc/reconfiguration.md | 26 +++++++++---------- .../framework/aptos-framework/doc/stake.md | 3 ++- .../sources/reconfiguration.move | 26 +++++++++---------- .../aptos-framework/sources/stake.spec.move | 2 +- aptos-move/vm-genesis/src/lib.rs | 14 +++++----- .../executor/tests/internal_indexer_test.rs | 2 +- types/src/account_config/events/new_epoch.rs | 5 ++++ 8 files changed, 53 insertions(+), 40 deletions(-) diff --git a/api/goldens/aptos_api__tests__events_test__test_get_events_by_account_event_handle.json b/api/goldens/aptos_api__tests__events_test__test_get_events_by_account_event_handle.json index fe51488c7066f..71f9f4fa4ce52 100644 --- a/api/goldens/aptos_api__tests__events_test__test_get_events_by_account_event_handle.json +++ b/api/goldens/aptos_api__tests__events_test__test_get_events_by_account_event_handle.json @@ -1 +1,14 @@ -[] +[ + { + "version": "0", + "guid": { + "creation_number": "2", + "account_address": "0x1" + }, + "sequence_number": "0", + "type": "0x1::reconfiguration::NewEpochEvent", + "data": { + "epoch": "1" + } + } +] diff --git a/aptos-move/framework/aptos-framework/doc/reconfiguration.md b/aptos-move/framework/aptos-framework/doc/reconfiguration.md index afb72878844c8..216bf3e672a58 100644 --- a/aptos-move/framework/aptos-framework/doc/reconfiguration.md +++ b/aptos-move/framework/aptos-framework/doc/reconfiguration.md @@ -412,14 +412,13 @@ Signal validators to start using new configuration. Must be called from friend c epoch: config_ref.epoch, }, ); - } else { - event::emit_event<NewEpochEvent>( - &mut config_ref.events, - NewEpochEvent { - epoch: config_ref.epoch, - }, - ); }; + event::emit_event<NewEpochEvent>( + &mut config_ref.events, + NewEpochEvent { + epoch: config_ref.epoch, + }, + ); reconfiguration_state::on_reconfig_finish(); } @@ -505,14 +504,13 @@ reconfiguration event. epoch: config_ref.epoch, }, ); - } else { - event::emit_event<NewEpochEvent>( - &mut config_ref.events, - NewEpochEvent { - epoch: config_ref.epoch, - }, - ); }; + event::emit_event<NewEpochEvent>( + &mut config_ref.events, + NewEpochEvent { + epoch: config_ref.epoch, + }, + ); } diff --git a/aptos-move/framework/aptos-framework/doc/stake.md b/aptos-move/framework/aptos-framework/doc/stake.md index 8ada8989d7e3d..a1b918e9a8984 100644 --- a/aptos-move/framework/aptos-framework/doc/stake.md +++ b/aptos-move/framework/aptos-framework/doc/stake.md @@ -5198,7 +5198,8 @@ Returns validator's next epoch voting power, including pending_active, active, a -
pragma disable_invariants_in_body;
+
pragma verify_duration_estimate = 60;
+pragma disable_invariants_in_body;
 aborts_if !staking_config::get_allow_validator_set_change(staking_config::get());
 aborts_if !exists<StakePool>(pool_address);
 aborts_if !exists<ValidatorConfig>(pool_address);
diff --git a/aptos-move/framework/aptos-framework/sources/reconfiguration.move b/aptos-move/framework/aptos-framework/sources/reconfiguration.move
index 9a9c7bbb61e89..6bf02a1d1b0f5 100644
--- a/aptos-move/framework/aptos-framework/sources/reconfiguration.move
+++ b/aptos-move/framework/aptos-framework/sources/reconfiguration.move
@@ -147,14 +147,13 @@ module aptos_framework::reconfiguration {
                     epoch: config_ref.epoch,
                 },
             );
-        } else {
-            event::emit_event(
-                &mut config_ref.events,
-                NewEpochEvent {
-                    epoch: config_ref.epoch,
-                },
-            );
         };
+        event::emit_event(
+            &mut config_ref.events,
+            NewEpochEvent {
+                epoch: config_ref.epoch,
+            },
+        );
 
         reconfiguration_state::on_reconfig_finish();
     }
@@ -180,14 +179,13 @@ module aptos_framework::reconfiguration {
                     epoch: config_ref.epoch,
                 },
             );
-        } else {
-            event::emit_event(
-                &mut config_ref.events,
-                NewEpochEvent {
-                    epoch: config_ref.epoch,
-                },
-            );
         };
+        event::emit_event(
+            &mut config_ref.events,
+            NewEpochEvent {
+                epoch: config_ref.epoch,
+            },
+        );
     }
 
     // For tests, skips the guid validation.
diff --git a/aptos-move/framework/aptos-framework/sources/stake.spec.move b/aptos-move/framework/aptos-framework/sources/stake.spec.move
index 747c8212a3fa4..975f77bd14b1f 100644
--- a/aptos-move/framework/aptos-framework/sources/stake.spec.move
+++ b/aptos-move/framework/aptos-framework/sources/stake.spec.move
@@ -168,7 +168,7 @@ spec aptos_framework::stake {
     )
     {
         // This function casue timeout (property proved)
-        // pragma verify_duration_estimate = 120;
+        pragma verify_duration_estimate = 60;
         pragma disable_invariants_in_body;
         aborts_if !staking_config::get_allow_validator_set_change(staking_config::get());
         aborts_if !exists(pool_address);
diff --git a/aptos-move/vm-genesis/src/lib.rs b/aptos-move/vm-genesis/src/lib.rs
index cc314d0255d39..aa36b820ada63 100644
--- a/aptos-move/vm-genesis/src/lib.rs
+++ b/aptos-move/vm-genesis/src/lib.rs
@@ -17,9 +17,9 @@ use aptos_gas_schedule::{
     AptosGasParameters, InitialGasSchedule, ToOnChainGasSchedule, LATEST_GAS_FEATURE_VERSION,
 };
 use aptos_types::{
-    account_config::{self, aptos_test_root_address, CORE_CODE_ADDRESS},
+    account_config::{self, aptos_test_root_address, events::NewEpochEvent, CORE_CODE_ADDRESS},
     chain_id::ChainId,
-    contract_event::ContractEvent,
+    contract_event::{ContractEvent, ContractEventV1},
     jwks::{
         patch::{PatchJWKMoveStruct, PatchUpsertJWK},
         secure_test_rsa_jwk,
@@ -804,11 +804,11 @@ fn emit_new_block_and_epoch_event(session: &mut SessionExt) {
 
 /// Verify the consistency of the genesis `WriteSet`
 fn verify_genesis_write_set(events: &[(ContractEvent, Option)]) {
-    let new_epoch_events: Vec<&ContractEvent> = events
+    let new_epoch_events: Vec<&ContractEventV1> = events
         .iter()
         .filter_map(|(e, _)| {
-            if e.is_new_epoch_event() {
-                Some(e)
+            if e.event_key() == Some(&NewEpochEvent::event_key()) {
+                Some(e.v1().unwrap())
             } else {
                 None
             }
@@ -819,9 +819,7 @@ fn verify_genesis_write_set(events: &[(ContractEvent, Option)])
         1,
         "There should only be exactly one NewEpochEvent"
     );
-    if let Ok(e) = new_epoch_events[0].v1() {
-        assert_eq!(e.sequence_number(), 0);
-    }
+    assert_eq!(new_epoch_events[0].sequence_number(), 0);
 }
 
 /// An enum specifying whether the compiled stdlib/scripts should be used or freshly built versions
diff --git a/execution/executor/tests/internal_indexer_test.rs b/execution/executor/tests/internal_indexer_test.rs
index 9a01ac7a093e8..64526d56d4617 100644
--- a/execution/executor/tests/internal_indexer_test.rs
+++ b/execution/executor/tests/internal_indexer_test.rs
@@ -174,7 +174,7 @@ fn test_db_indexer_data() {
 
     let x = internal_indexer_db.get_event_by_key_iter().unwrap();
     let res: Vec<_> = x.collect();
-    assert_eq!(res.len(), 2);
+    assert_eq!(res.len(), 4);
 
     let core_kv_iter = db_indexer
         .get_prefixed_state_value_iterator(
diff --git a/types/src/account_config/events/new_epoch.rs b/types/src/account_config/events/new_epoch.rs
index fb6c855ad35df..b9b422f3105c7 100644
--- a/types/src/account_config/events/new_epoch.rs
+++ b/types/src/account_config/events/new_epoch.rs
@@ -2,6 +2,7 @@
 // Parts of the project are originally copyright © Meta Platforms, Inc.
 // SPDX-License-Identifier: Apache-2.0
 
+use crate::event::EventKey;
 use anyhow::Result;
 use move_core_types::{
     ident_str, identifier::IdentStr, language_storage::TypeTag, move_resource::MoveStructType,
@@ -29,6 +30,10 @@ impl NewEpochEvent {
     pub fn try_from_bytes(bytes: &[u8]) -> Result {
         bcs::from_bytes(bytes).map_err(Into::into)
     }
+
+    pub fn event_key() -> EventKey {
+        crate::on_chain_config::new_epoch_event_key()
+    }
 }
 
 impl MoveStructType for NewEpochEvent {