Skip to content

Commit

Permalink
[block] ensure height equal to event counter
Browse files Browse the repository at this point in the history
  • Loading branch information
zekun000 committed Aug 1, 2022
1 parent b7a69a4 commit fe44ecf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
3 changes: 2 additions & 1 deletion aptos-move/framework/aptos-framework/sources/block.move
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ module aptos_framework::block {
);

let block_metadata_ref = borrow_global_mut<BlockMetadata>(@aptos_framework);
block_metadata_ref.height = block_metadata_ref.height + 1;
block_metadata_ref.height = event::counter(&block_metadata_ref.new_block_events);

let new_block_event = NewBlockEvent {
epoch,
Expand Down Expand Up @@ -122,6 +122,7 @@ module aptos_framework::block {
/// Emit the event and update height and global timestamp
fun emit_new_block_event(vm: &signer, event_handle: &mut EventHandle<NewBlockEvent>, new_block_event: NewBlockEvent) {
timestamp::update_global_time(vm, new_block_event.proposer, new_block_event.time_microseconds);
assert!(event::counter(event_handle) == new_block_event.height, error::invalid_argument(EBLOCK_METADATA));
event::emit_event<NewBlockEvent>(event_handle, new_block_event);
}

Expand Down
13 changes: 6 additions & 7 deletions aptos-move/framework/aptos-stdlib/sources/event.move
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ module aptos_std::event {
handle_ref.counter = handle_ref.counter + 1;
}

/// Return the GUIID associated with this EventHandle
/// Return the GUID associated with this EventHandle
public fun guid<T: drop + store>(handle_ref: &EventHandle<T>): &GUID {
&handle_ref.guid
}

/// Return the current counter associated with this EventHandle
public fun counter<T: drop + store>(handle_ref: &EventHandle<T>): u64 {
handle_ref.counter
}

/// Log `msg` as the `count`th event associated with the event stream identified by `guid`
native fun write_to_event_store<T: drop + store>(guid: vector<u8>, count: u64, msg: T);

Expand All @@ -58,12 +63,6 @@ module aptos_std::event {
guid
}

#[test_only]
public fun get_event_handle_counter<T: drop + store>(handle : &EventHandle<T>): u64 {
let counter = handle.counter;
counter
}

// ****************** SPECIFICATIONS *******************
spec module {} // switch documentation context to module

Expand Down
2 changes: 1 addition & 1 deletion aptos-move/framework/aptos-token/sources/token.move
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ module aptos_token::token {
fun test_create_events_generation(creator: signer) acquires Collections, TokenStore {
create_collection_and_token(&creator, 1, 2, 1);
let collections = borrow_global<Collections>(signer::address_of(&creator));
assert!(event::get_event_handle_counter(&collections.create_collection_events) == 1, 1);
assert!(event::counter(&collections.create_collection_events) == 1, 1);
}

#[test(creator = @0xAF)]
Expand Down

0 comments on commit fe44ecf

Please sign in to comment.