Skip to content

Commit

Permalink
fixup! deal with NewEpochEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
lightmark committed Oct 22, 2024
1 parent 4319b1f commit fc7fcdc
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 75 deletions.
21 changes: 5 additions & 16 deletions aptos-move/e2e-move-tests/src/tests/rotate_auth_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use aptos_crypto::{
use aptos_language_e2e_tests::account::Account;
use aptos_types::{
account_address::AccountAddress,
account_config::{AccountResource, RotationProofChallenge, CORE_CODE_ADDRESS},
account_config::{RotationProofChallenge, CORE_CODE_ADDRESS},
state_store::{state_key::StateKey, table::TableHandle},
transaction::{authenticator::AuthenticationKey, TransactionStatus},
};
Expand All @@ -40,7 +40,7 @@ fn rotate_auth_key_ed25519_to_ed25519() {
);

// verify that we can still get to account1's originating address
verify_originating_address(&mut harness, account2.auth_key(), *account1.address(), 1);
verify_originating_address(&mut harness, account2.auth_key(), *account1.address());
}

#[test]
Expand All @@ -64,7 +64,7 @@ fn rotate_auth_key_ed25519_to_multi_ed25519() {
);

// verify that we can still get to account1's originating address
verify_originating_address(&mut harness, auth_key.to_vec(), *account1.address(), 1);
verify_originating_address(&mut harness, auth_key.to_vec(), *account1.address());
}

#[test]
Expand All @@ -87,7 +87,7 @@ fn rotate_auth_key_twice() {
// rotate account1's keypair to account2
account1.rotate_key(account2.privkey, account2.pubkey.as_ed25519().unwrap());
// verify that we can still get to account1's originating address
verify_originating_address(&mut harness, account1.auth_key(), *account1.address(), 1);
verify_originating_address(&mut harness, account1.auth_key(), *account1.address());

let account3 = harness.new_account_with_key_pair();
assert_successful_key_rotation_transaction(
Expand All @@ -101,7 +101,7 @@ fn rotate_auth_key_twice() {
account3.pubkey.to_bytes(),
);
account1.rotate_key(account3.privkey, account3.pubkey.as_ed25519().unwrap());
verify_originating_address(&mut harness, account1.auth_key(), *account1.address(), 2);
verify_originating_address(&mut harness, account1.auth_key(), *account1.address());
}

#[test]
Expand All @@ -125,7 +125,6 @@ fn rotate_auth_key_with_rotation_capability_e2e() {
&mut harness,
offerer_account.auth_key(),
*offerer_account.address(),
1,
);

revoke_rotation_capability(&mut harness, &offerer_account, *delegate_account.address());
Expand Down Expand Up @@ -221,7 +220,6 @@ pub fn verify_originating_address(
harness: &mut MoveHarness,
auth_key: Vec<u8>,
expected_address: AccountAddress,
expected_num_of_events: u64,
) {
// Get the address redirection table
let originating_address_handle = harness
Expand All @@ -234,13 +232,4 @@ pub fn verify_originating_address(
// Verify that the value in the address redirection table is expected
let result = harness.read_state_value_bytes(state_key).unwrap();
assert_eq!(result, expected_address.to_vec());

let account_resource = parse_struct_tag("0x1::account::Account").unwrap();
let key_rotation_events = harness
.read_resource::<AccountResource>(&expected_address, account_resource)
.unwrap()
.key_rotation_events()
.clone();

assert_eq!(key_rotation_events.count(), expected_num_of_events);
}
2 changes: 1 addition & 1 deletion aptos-move/e2e-move-tests/src/tests/token_event_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn test_token_creation_with_token_events_store() {
let _event = events.pop().unwrap();
let event = events.pop().unwrap();
assert_eq!(
"0x3::token_event_store::OptInTransferEvent".to_string(),
"0x3::token_event_store::OptInTransfer".to_string(),
event.type_tag().to_string()
);
}
6 changes: 5 additions & 1 deletion aptos-move/e2e-tests/src/executor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Copyright (c) Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

// Copyright © Aptos Foundation

// Parts of the project are originally copyright © Meta Platforms, Inc.
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -887,7 +891,7 @@ impl FakeExecutor {
.expect("Must execute transactions");

// Check if we emit the expected event for block metadata, there might be more events for transaction fees.
let event = outputs[0].events()[1]
let event = outputs[0].events()[0]
.v1()
.expect("The first event must be a block metadata v0 event")
.clone();
Expand Down
44 changes: 4 additions & 40 deletions aptos-move/framework/aptos-framework/doc/block.md
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@ Return epoch interval in seconds.
<b>let</b> block_metadata_ref = <b>borrow_global_mut</b>&lt;<a href="block.md#0x1_block_BlockResource">BlockResource</a>&gt;(@aptos_framework);
block_metadata_ref.height = <a href="event.md#0x1_event_counter">event::counter</a>(&block_metadata_ref.new_block_events);

// Emit both <a href="event.md#0x1_event">event</a> v1 and v2 for compatibility. Eventually only <b>module</b> events will be kept.
<b>let</b> new_block_event = <a href="block.md#0x1_block_NewBlockEvent">NewBlockEvent</a> {
<a href="../../aptos-stdlib/../move-stdlib/doc/hash.md#0x1_hash">hash</a>,
epoch,
Expand All @@ -605,17 +604,7 @@ Return epoch interval in seconds.
failed_proposer_indices,
time_microseconds: <a href="timestamp.md#0x1_timestamp">timestamp</a>,
};
<b>let</b> new_block_event_v2 = <a href="block.md#0x1_block_NewBlock">NewBlock</a> {
<a href="../../aptos-stdlib/../move-stdlib/doc/hash.md#0x1_hash">hash</a>,
epoch,
round,
height: block_metadata_ref.height,
previous_block_votes_bitvec,
proposer,
failed_proposer_indices,
time_microseconds: <a href="timestamp.md#0x1_timestamp">timestamp</a>,
};
<a href="block.md#0x1_block_emit_new_block_event">emit_new_block_event</a>(vm, &<b>mut</b> block_metadata_ref.new_block_events, new_block_event, new_block_event_v2);
<a href="block.md#0x1_block_emit_new_block_event">emit_new_block_event</a>(vm, &<b>mut</b> block_metadata_ref.new_block_events, new_block_event);

<b>if</b> (<a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_collect_and_distribute_gas_fees">features::collect_and_distribute_gas_fees</a>()) {
// Assign the fees collected from the previous <a href="block.md#0x1_block">block</a> <b>to</b> the previous <a href="block.md#0x1_block">block</a> proposer.
Expand Down Expand Up @@ -760,7 +749,7 @@ Get the current block height
Emit the event and update height and global timestamp


<pre><code><b>fun</b> <a href="block.md#0x1_block_emit_new_block_event">emit_new_block_event</a>(vm: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, event_handle: &<b>mut</b> <a href="event.md#0x1_event_EventHandle">event::EventHandle</a>&lt;<a href="block.md#0x1_block_NewBlockEvent">block::NewBlockEvent</a>&gt;, new_block_event: <a href="block.md#0x1_block_NewBlockEvent">block::NewBlockEvent</a>, new_block_event_v2: <a href="block.md#0x1_block_NewBlock">block::NewBlock</a>)
<pre><code><b>fun</b> <a href="block.md#0x1_block_emit_new_block_event">emit_new_block_event</a>(vm: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, event_handle: &<b>mut</b> <a href="event.md#0x1_event_EventHandle">event::EventHandle</a>&lt;<a href="block.md#0x1_block_NewBlockEvent">block::NewBlockEvent</a>&gt;, new_block_event: <a href="block.md#0x1_block_NewBlockEvent">block::NewBlockEvent</a>)
</code></pre>


Expand All @@ -773,7 +762,6 @@ Emit the event and update height and global timestamp
vm: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>,
event_handle: &<b>mut</b> EventHandle&lt;<a href="block.md#0x1_block_NewBlockEvent">NewBlockEvent</a>&gt;,
new_block_event: <a href="block.md#0x1_block_NewBlockEvent">NewBlockEvent</a>,
new_block_event_v2: <a href="block.md#0x1_block_NewBlock">NewBlock</a>
) <b>acquires</b> <a href="block.md#0x1_block_CommitHistory">CommitHistory</a> {
<b>if</b> (<b>exists</b>&lt;<a href="block.md#0x1_block_CommitHistory">CommitHistory</a>&gt;(@aptos_framework)) {
<b>let</b> commit_history_ref = <b>borrow_global_mut</b>&lt;<a href="block.md#0x1_block_CommitHistory">CommitHistory</a>&gt;(@aptos_framework);
Expand All @@ -792,11 +780,7 @@ Emit the event and update height and global timestamp
<a href="event.md#0x1_event_counter">event::counter</a>(event_handle) == new_block_event.height,
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="block.md#0x1_block_ENUM_NEW_BLOCK_EVENTS_DOES_NOT_MATCH_BLOCK_HEIGHT">ENUM_NEW_BLOCK_EVENTS_DOES_NOT_MATCH_BLOCK_HEIGHT</a>),
);
<b>if</b> (std::features::module_event_migration_enabled()) {
<a href="event.md#0x1_event_emit">event::emit</a>(new_block_event_v2);
} <b>else</b> {
<a href="event.md#0x1_event_emit_event">event::emit_event</a>&lt;<a href="block.md#0x1_block_NewBlockEvent">NewBlockEvent</a>&gt;(event_handle, new_block_event);
};
<a href="event.md#0x1_event_emit_event">event::emit_event</a>&lt;<a href="block.md#0x1_block_NewBlockEvent">NewBlockEvent</a>&gt;(event_handle, new_block_event);
}
</code></pre>

Expand Down Expand Up @@ -837,16 +821,6 @@ reconfiguration event.
failed_proposer_indices: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector_empty">vector::empty</a>(),
time_microseconds: 0,
},
<a href="block.md#0x1_block_NewBlock">NewBlock</a> {
<a href="../../aptos-stdlib/../move-stdlib/doc/hash.md#0x1_hash">hash</a>: genesis_id,
epoch: 0,
round: 0,
height: 0,
previous_block_votes_bitvec: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector_empty">vector::empty</a>(),
proposer: @vm_reserved,
failed_proposer_indices: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector_empty">vector::empty</a>(),
time_microseconds: 0,
}
);
}
</code></pre>
Expand Down Expand Up @@ -890,16 +864,6 @@ new block event for WriteSetPayload.
failed_proposer_indices: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector_empty">vector::empty</a>(),
time_microseconds: <a href="timestamp.md#0x1_timestamp_now_microseconds">timestamp::now_microseconds</a>(),
},
<a href="block.md#0x1_block_NewBlock">NewBlock</a> {
<a href="../../aptos-stdlib/../move-stdlib/doc/hash.md#0x1_hash">hash</a>: fake_block_hash,
epoch: <a href="reconfiguration.md#0x1_reconfiguration_current_epoch">reconfiguration::current_epoch</a>(),
round: <a href="block.md#0x1_block_MAX_U64">MAX_U64</a>,
height: block_metadata_ref.height,
previous_block_votes_bitvec: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector_empty">vector::empty</a>(),
proposer: @vm_reserved,
failed_proposer_indices: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector_empty">vector::empty</a>(),
time_microseconds: <a href="timestamp.md#0x1_timestamp_now_microseconds">timestamp::now_microseconds</a>(),
}
);
}
</code></pre>
Expand Down Expand Up @@ -1290,7 +1254,7 @@ The BlockResource existed under the @aptos_framework.
### Function `emit_new_block_event`


<pre><code><b>fun</b> <a href="block.md#0x1_block_emit_new_block_event">emit_new_block_event</a>(vm: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, event_handle: &<b>mut</b> <a href="event.md#0x1_event_EventHandle">event::EventHandle</a>&lt;<a href="block.md#0x1_block_NewBlockEvent">block::NewBlockEvent</a>&gt;, new_block_event: <a href="block.md#0x1_block_NewBlockEvent">block::NewBlockEvent</a>, new_block_event_v2: <a href="block.md#0x1_block_NewBlock">block::NewBlock</a>)
<pre><code><b>fun</b> <a href="block.md#0x1_block_emit_new_block_event">emit_new_block_event</a>(vm: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, event_handle: &<b>mut</b> <a href="event.md#0x1_event_EventHandle">event::EventHandle</a>&lt;<a href="block.md#0x1_block_NewBlockEvent">block::NewBlockEvent</a>&gt;, new_block_event: <a href="block.md#0x1_block_NewBlockEvent">block::NewBlockEvent</a>)
</code></pre>


Expand Down
10 changes: 5 additions & 5 deletions aptos-move/framework/aptos-framework/sources/account.move
Original file line number Diff line number Diff line change
Expand Up @@ -1536,14 +1536,14 @@ module aptos_framework::account {
register_coin<FakeCoin>(addr);

let eventhandle = &borrow_global<Account>(addr).coin_register_events;
let event = CoinRegisterEvent { type_info: type_info::type_of<FakeCoin>() };
let event = CoinRegister { account: addr, type_info: type_info::type_of<FakeCoin>() };

let events = event::emitted_events_by_handle(eventhandle);
let events = event::emitted_events<CoinRegister>();
assert!(vector::length(&events) == 1, 0);
assert!(vector::borrow(&events, 0) == &event, 1);
assert!(event::was_event_emitted_by_handle(eventhandle, &event), 2);
assert!(event::was_event_emitted(&event), 2);

let event = CoinRegisterEvent { type_info: type_info::type_of<SadFakeCoin>() };
assert!(!event::was_event_emitted_by_handle(eventhandle, &event), 3);
let event = CoinRegister { account: addr, type_info: type_info::type_of<SadFakeCoin>() };
assert!(!event::was_event_emitted(&event), 3);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ spec aptos_framework::aptos_governance {
let post new_governance_config = global<GovernanceConfig>(@aptos_framework);
aborts_if addr != @aptos_framework;
aborts_if !exists<GovernanceConfig>(@aptos_framework);
aborts_if !exists<GovernanceEvents>(@aptos_framework);
aborts_if !features::spec_is_enabled(features::MODULE_EVENT_MIGRATION) && !exists<GovernanceEvents>(
@aptos_framework
);
modifies global<GovernanceConfig>(addr);

ensures new_governance_config.voting_duration_secs == voting_duration_secs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ module aptos_token_objects::collection {
use aptos_framework::object::{Self, ConstructorRef, ExtendRef, Object};

use aptos_token_objects::royalty::{Self, Royalty};
#[test_only]
use std::vector;

friend aptos_token_objects::token;

Expand Down Expand Up @@ -798,10 +800,10 @@ module aptos_token_objects::collection {
assert!(count(collection) == option::some(0), 0);
let cid = aggregator_v2::read_snapshot(&option::destroy_some(increment_supply(&collection, creator_address)));
assert!(count(collection) == option::some(1), 0);
assert!(event::counter(&borrow_global<FixedSupply>(collection_address).mint_events) == 1, 0);
assert!(vector::length(&event::emitted_events<Mint>()) == 1, 0);
decrement_supply(&collection, creator_address, option::some(cid), creator_address);
assert!(count(collection) == option::some(0), 0);
assert!(event::counter(&borrow_global<FixedSupply>(collection_address).burn_events) == 1, 0);
assert!(vector::length(&event::emitted_events<Burn>()) == 1, 0);
}

#[test(creator = @0x123)]
Expand Down
7 changes: 6 additions & 1 deletion aptos-move/framework/aptos-token/sources/token.move
Original file line number Diff line number Diff line change
Expand Up @@ -2063,7 +2063,12 @@ module aptos_token::token {
vector<bool>[false, false, false, false, false],
);
let collections = borrow_global<Collections>(signer::address_of(&creator));
assert!(event::counter(&collections.create_collection_events) == 1, 1);
assert!(
vector::length(&event::emitted_events<CreateCollection>()) == 1 || vector::length(
&event::emitted_events<CreateCollectionEvent>()
) == 1,
1
);
}

#[test(creator = @0xAF)]
Expand Down
2 changes: 0 additions & 2 deletions aptos-move/vm-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

mod genesis_context;

use std::ops::Deref;
use crate::genesis_context::GenesisStateView;
use aptos_crypto::{
bls12381,
Expand Down Expand Up @@ -55,7 +54,6 @@ use move_vm_types::gas::UnmeteredGasMeter;
use once_cell::sync::Lazy;
use rand::prelude::*;
use serde::{Deserialize, Serialize};
use aptos_types::account_config::{NEW_EPOCH_EVENT_MOVE_TYPE_TAG, NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG};

// The seed is arbitrarily picked to produce a consistent key. XXX make this more formal?
const GENESIS_SEED: [u8; 32] = [42; 32];
Expand Down
5 changes: 1 addition & 4 deletions execution/executor-types/src/parsed_transaction_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@

use aptos_types::{
contract_event::ContractEvent,
event::EventKey,
on_chain_config,
transaction::{
Transaction, TransactionAuxiliaryData, TransactionOutput, TransactionOutputProvider,
TransactionStatus,
},
write_set::WriteSet,
};
use itertools::zip_eq;
use once_cell::sync::Lazy;
use std::ops::Deref;

#[derive(Clone)]
Expand All @@ -23,7 +20,7 @@ pub struct ParsedTransactionOutput {

impl ParsedTransactionOutput {
pub fn parse_reconfig_events(events: &[ContractEvent]) -> impl Iterator<Item = &ContractEvent> {
events.iter().filter(ContractEvent::is_new_epoch_event)
events.iter().filter(|e| e.is_new_epoch_event())
}
}

Expand Down
1 change: 0 additions & 1 deletion types/src/account_config/events/new_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use move_core_types::{
identifier::IdentStr,
move_resource::{MoveResource, MoveStructType},
};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};

/// Struct that represents a NewBlockEvent.
Expand Down
2 changes: 1 addition & 1 deletion types/src/contract_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl TryFrom<&ContractEvent> for NewEpochEvent {

fn try_from(event: &ContractEvent) -> Result<Self> {
if event.is_new_epoch_event() {
Self::try_from_bytes(&event.event_data())
Self::try_from_bytes(event.event_data())
} else {
bail!("Expected NewEpochEvent")
}
Expand Down

0 comments on commit fc7fcdc

Please sign in to comment.