From 50104947083b7c6b3eee9f764f411d3031334a9a Mon Sep 17 00:00:00 2001 From: Aaron Date: Sat, 26 Oct 2024 00:24:36 -0700 Subject: [PATCH] [module events] update token events and switch v1 with v2 (#14432) * DropHelper: fix num_tasks gauge (#15048) * [module events] update token events * [event v2] add coin register event * switch instead of double emitting * deal with NewEpochEvent * fixup! deal with NewEpochEvent * fixup! fixup! deal with NewEpochEvent --------- Co-authored-by: Alden Hu --- Cargo.lock | 1 - ...__tests__events_test__test_get_events.json | 19 +- ...state_test__test_get_account_resource.json | 2 +- ...est_get_account_resource_with_version.json | 2 +- ...ansaction_with_entry_function_payload.json | 27 +- ...e_when_start_version_is_not_specified.json | 216 ++------ ...e_failed_by_entry_function_validation.json | 2 +- ...led_by_invalid_entry_function_address.json | 2 +- ...d_by_invalid_entry_function_arguments.json | 2 +- ...by_invalid_entry_function_module_name.json | 2 +- ...failed_by_invalid_entry_function_name.json | 2 +- ...ed_by_invalid_script_payload_bytecode.json | 2 +- ...d_by_missing_entry_function_arguments.json | 2 +- ..._simulation_failure_with_detail_error.json | 2 +- ...ilure_with_move_abort_error_rendering.json | 2 +- api/src/tests/multisig_transactions_test.rs | 59 -- api/src/tests/objects.rs | 37 +- .../aptos-debugger/src/aptos_debugger.rs | 4 +- .../aptos_test_harness/execute_script.exp | 2 +- .../tests/aptos_test_harness/table.exp | 86 +-- aptos-move/aptos-vm/src/aptos_vm.rs | 13 +- aptos-move/e2e-benchmark/src/main.rs | 4 +- .../src/tests/rotate_auth_key.rs | 21 +- .../src/tests/token_event_store.rs | 2 +- ..._tests__create_account__create_account.exp | 6 +- aptos-move/e2e-tests/src/executor.rs | 6 +- .../e2e-testsuite/src/tests/peer_to_peer.rs | 7 - .../framework/aptos-framework/doc/account.md | 71 ++- .../aptos-framework/doc/aptos_account.md | 14 +- .../aptos-framework/doc/aptos_governance.md | 69 +-- .../framework/aptos-framework/doc/block.md | 50 +- .../framework/aptos-framework/doc/coin.md | 18 +- .../aptos-framework/doc/delegation_pool.md | 126 ++--- .../aptos-framework/doc/multisig_account.md | 150 ++--- .../framework/aptos-framework/doc/object.md | 88 +-- .../framework/aptos-framework/doc/stake.md | 406 +++++++------- .../aptos-framework/doc/staking_contract.md | 85 +-- .../framework/aptos-framework/doc/vesting.md | 181 +++--- .../framework/aptos-framework/doc/voting.md | 87 +-- .../aptos-framework/sources/account.move | 52 +- .../sources/aptos_account.move | 14 +- .../sources/aptos_governance.move | 65 +-- .../sources/aptos_governance.spec.move | 4 +- .../aptos-framework/sources/block.move | 46 +- .../aptos-framework/sources/coin.move | 18 +- .../sources/delegation_pool.move | 126 ++--- .../sources/multisig_account.move | 150 ++--- .../aptos-framework/sources/object.move | 34 +- .../aptos-framework/sources/stake.move | 175 +++--- .../aptos-framework/sources/stake.spec.move | 2 +- .../sources/staking_contract.move | 85 +-- .../aptos-framework/sources/vesting.move | 181 +++--- .../aptos-framework/sources/voting.move | 87 +-- .../aptos-token-objects/doc/collection.md | 80 +-- .../aptos-token-objects/doc/token.md | 51 +- .../sources/collection.move | 90 +-- .../aptos-token-objects/sources/token.move | 51 +- aptos-move/framework/aptos-token/doc/token.md | 522 +++++++++++++++--- .../aptos-token/doc/token_event_store.md | 85 +-- .../aptos-token/doc/token_transfers.md | 272 +++++++-- .../framework/aptos-token/sources/token.move | 257 ++++++--- .../sources/token_event_store.move | 85 +-- .../aptos-token/sources/token_transfers.move | 98 ++-- crates/aptos-rosetta/src/types/objects.rs | 48 +- .../src/integration_test_impl.rs | 159 +----- execution/executor-types/Cargo.toml | 1 - execution/executor-types/src/lib.rs | 3 +- .../src/parsed_transaction_output.rs | 9 +- execution/executor/src/tests/mock_vm/mod.rs | 9 +- .../executor/tests/db_bootstrapper_test.rs | 10 +- .../executor/tests/internal_indexer_test.rs | 2 +- .../event-notifications/src/tests.rs | 24 +- .../state-sync-driver/src/tests/driver.rs | 20 +- .../state-sync-driver/src/tests/utils.rs | 8 + types/src/account_config/events/new_block.rs | 9 - types/src/account_config/events/new_epoch.rs | 13 +- types/src/account_config/events/withdraw.rs | 22 +- types/src/contract_event.rs | 37 +- types/src/on_chain_config/mod.rs | 8 +- 79 files changed, 2591 insertions(+), 2298 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5cae6e303294f..33a3c058497a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1558,7 +1558,6 @@ dependencies = [ "criterion", "derive_more", "itertools 0.13.0", - "once_cell", "serde", "thiserror", ] diff --git a/api/goldens/aptos_api__tests__events_test__test_get_events.json b/api/goldens/aptos_api__tests__events_test__test_get_events.json index ae7ac2a2ff1c3..fe51488c7066f 100644 --- a/api/goldens/aptos_api__tests__events_test__test_get_events.json +++ b/api/goldens/aptos_api__tests__events_test__test_get_events.json @@ -1,18 +1 @@ -[ - { - "version": "0", - "guid": { - "creation_number": "0", - "account_address": "0xa550c18" - }, - "sequence_number": "0", - "type": "0x1::account::CoinRegisterEvent", - "data": { - "type_info": { - "account_address": "0x1", - "module_name": "0x6170746f735f636f696e", - "struct_name": "0x4170746f73436f696e" - } - } - } -] +[] diff --git a/api/goldens/aptos_api__tests__state_test__test_get_account_resource.json b/api/goldens/aptos_api__tests__state_test__test_get_account_resource.json index c99ce553c49a4..8732244e4acd4 100644 --- a/api/goldens/aptos_api__tests__state_test__test_get_account_resource.json +++ b/api/goldens/aptos_api__tests__state_test__test_get_account_resource.json @@ -3,7 +3,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", diff --git a/api/goldens/aptos_api__tests__state_test__test_get_account_resource_with_version.json b/api/goldens/aptos_api__tests__state_test__test_get_account_resource_with_version.json index c99ce553c49a4..8732244e4acd4 100644 --- a/api/goldens/aptos_api__tests__state_test__test_get_account_resource_with_version.json +++ b/api/goldens/aptos_api__tests__state_test__test_get_account_resource_with_version.json @@ -3,7 +3,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", diff --git a/api/goldens/aptos_api__tests__transactions_test__test_get_transactions_output_user_transaction_with_entry_function_payload.json b/api/goldens/aptos_api__tests__transactions_test__test_get_transactions_output_user_transaction_with_entry_function_payload.json index 7fc3db306a6b3..35d08eff3c5cc 100644 --- a/api/goldens/aptos_api__tests__transactions_test__test_get_transactions_output_user_transaction_with_entry_function_payload.json +++ b/api/goldens/aptos_api__tests__transactions_test__test_get_transactions_output_user_transaction_with_entry_function_payload.json @@ -124,24 +124,6 @@ "epoch": "1", "round": "1", "events": [ - { - "guid": { - "creation_number": "0", - "account_address": "0x0" - }, - "sequence_number": "0", - "type": "0x1::block::NewBlock", - "data": { - "epoch": "1", - "failed_proposer_indices": [], - "hash": "", - "height": "1", - "previous_block_votes_bitvec": "0x00", - "proposer": "0x66b22b7465af92a9dc8d07d2878716d9dffbbb280830a7d8cf80334b5da812ef", - "round": "1", - "time_microseconds": "500000" - } - }, { "guid": { "creation_number": "3", @@ -188,7 +170,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", @@ -261,7 +243,7 @@ "data": { "authentication_key": "0x34bf7e2d17674feb234371a7ea58efd715f0e56ba20ebf13789480d9d643afaf", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0x34bf7e2d17674feb234371a7ea58efd715f0e56ba20ebf13789480d9d643afaf", @@ -317,11 +299,12 @@ { "guid": { "creation_number": "0", - "account_address": "0x34bf7e2d17674feb234371a7ea58efd715f0e56ba20ebf13789480d9d643afaf" + "account_address": "0x0" }, "sequence_number": "0", - "type": "0x1::account::CoinRegisterEvent", + "type": "0x1::account::CoinRegister", "data": { + "account": "0x34bf7e2d17674feb234371a7ea58efd715f0e56ba20ebf13789480d9d643afaf", "type_info": { "account_address": "0x1", "module_name": "0x6170746f735f636f696e", diff --git a/api/goldens/aptos_api__tests__transactions_test__test_get_transactions_returns_last_page_when_start_version_is_not_specified.json b/api/goldens/aptos_api__tests__transactions_test__test_get_transactions_returns_last_page_when_start_version_is_not_specified.json index 6f63dcad7ca41..589b23e197e10 100644 --- a/api/goldens/aptos_api__tests__transactions_test__test_get_transactions_returns_last_page_when_start_version_is_not_specified.json +++ b/api/goldens/aptos_api__tests__transactions_test__test_get_transactions_returns_last_page_when_start_version_is_not_specified.json @@ -129,24 +129,6 @@ "epoch": "1", "round": "1", "events": [ - { - "guid": { - "creation_number": "0", - "account_address": "0x0" - }, - "sequence_number": "0", - "type": "0x1::block::NewBlock", - "data": { - "epoch": "1", - "failed_proposer_indices": [], - "hash": "", - "height": "13", - "previous_block_votes_bitvec": "0x00", - "proposer": "0x66b22b7465af92a9dc8d07d2878716d9dffbbb280830a7d8cf80334b5da812ef", - "round": "1", - "time_microseconds": "6500000" - } - }, { "guid": { "creation_number": "3", @@ -193,7 +175,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", @@ -266,7 +248,7 @@ "data": { "authentication_key": "0x48a951fe0ed12b29517867e00a3a09da55fcf859497b3f04bbed911cb75669c9", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0x48a951fe0ed12b29517867e00a3a09da55fcf859497b3f04bbed911cb75669c9", @@ -322,11 +304,12 @@ { "guid": { "creation_number": "0", - "account_address": "0x48a951fe0ed12b29517867e00a3a09da55fcf859497b3f04bbed911cb75669c9" + "account_address": "0x0" }, "sequence_number": "0", - "type": "0x1::account::CoinRegisterEvent", + "type": "0x1::account::CoinRegister", "data": { + "account": "0x48a951fe0ed12b29517867e00a3a09da55fcf859497b3f04bbed911cb75669c9", "type_info": { "account_address": "0x1", "module_name": "0x6170746f735f636f696e", @@ -483,24 +466,6 @@ "epoch": "1", "round": "1", "events": [ - { - "guid": { - "creation_number": "0", - "account_address": "0x0" - }, - "sequence_number": "0", - "type": "0x1::block::NewBlock", - "data": { - "epoch": "1", - "failed_proposer_indices": [], - "hash": "", - "height": "14", - "previous_block_votes_bitvec": "0x00", - "proposer": "0x66b22b7465af92a9dc8d07d2878716d9dffbbb280830a7d8cf80334b5da812ef", - "round": "1", - "time_microseconds": "7000000" - } - }, { "guid": { "creation_number": "3", @@ -547,7 +512,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", @@ -620,7 +585,7 @@ "data": { "authentication_key": "0x095f70f0272707f73ce63f9b09497324a7b2c9118d5d5fb22cb373efd916a681", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0x95f70f0272707f73ce63f9b09497324a7b2c9118d5d5fb22cb373efd916a681", @@ -676,11 +641,12 @@ { "guid": { "creation_number": "0", - "account_address": "0x95f70f0272707f73ce63f9b09497324a7b2c9118d5d5fb22cb373efd916a681" + "account_address": "0x0" }, "sequence_number": "0", - "type": "0x1::account::CoinRegisterEvent", + "type": "0x1::account::CoinRegister", "data": { + "account": "0x95f70f0272707f73ce63f9b09497324a7b2c9118d5d5fb22cb373efd916a681", "type_info": { "account_address": "0x1", "module_name": "0x6170746f735f636f696e", @@ -837,24 +803,6 @@ "epoch": "1", "round": "1", "events": [ - { - "guid": { - "creation_number": "0", - "account_address": "0x0" - }, - "sequence_number": "0", - "type": "0x1::block::NewBlock", - "data": { - "epoch": "1", - "failed_proposer_indices": [], - "hash": "", - "height": "15", - "previous_block_votes_bitvec": "0x00", - "proposer": "0x66b22b7465af92a9dc8d07d2878716d9dffbbb280830a7d8cf80334b5da812ef", - "round": "1", - "time_microseconds": "7500000" - } - }, { "guid": { "creation_number": "3", @@ -901,7 +849,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", @@ -974,7 +922,7 @@ "data": { "authentication_key": "0x4c989e245d6ce3f3735edb8ef9f84c34d5e6f0991bea502b05cd1ea74d327a22", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0x4c989e245d6ce3f3735edb8ef9f84c34d5e6f0991bea502b05cd1ea74d327a22", @@ -1030,11 +978,12 @@ { "guid": { "creation_number": "0", - "account_address": "0x4c989e245d6ce3f3735edb8ef9f84c34d5e6f0991bea502b05cd1ea74d327a22" + "account_address": "0x0" }, "sequence_number": "0", - "type": "0x1::account::CoinRegisterEvent", + "type": "0x1::account::CoinRegister", "data": { + "account": "0x4c989e245d6ce3f3735edb8ef9f84c34d5e6f0991bea502b05cd1ea74d327a22", "type_info": { "account_address": "0x1", "module_name": "0x6170746f735f636f696e", @@ -1191,24 +1140,6 @@ "epoch": "1", "round": "1", "events": [ - { - "guid": { - "creation_number": "0", - "account_address": "0x0" - }, - "sequence_number": "0", - "type": "0x1::block::NewBlock", - "data": { - "epoch": "1", - "failed_proposer_indices": [], - "hash": "", - "height": "16", - "previous_block_votes_bitvec": "0x00", - "proposer": "0x66b22b7465af92a9dc8d07d2878716d9dffbbb280830a7d8cf80334b5da812ef", - "round": "1", - "time_microseconds": "8000000" - } - }, { "guid": { "creation_number": "3", @@ -1255,7 +1186,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", @@ -1328,7 +1259,7 @@ "data": { "authentication_key": "0x46925daed0a8767bb9437ccccfdf31a1d349a05659710ca0ebe6205d0e5d737e", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0x46925daed0a8767bb9437ccccfdf31a1d349a05659710ca0ebe6205d0e5d737e", @@ -1384,11 +1315,12 @@ { "guid": { "creation_number": "0", - "account_address": "0x46925daed0a8767bb9437ccccfdf31a1d349a05659710ca0ebe6205d0e5d737e" + "account_address": "0x0" }, "sequence_number": "0", - "type": "0x1::account::CoinRegisterEvent", + "type": "0x1::account::CoinRegister", "data": { + "account": "0x46925daed0a8767bb9437ccccfdf31a1d349a05659710ca0ebe6205d0e5d737e", "type_info": { "account_address": "0x1", "module_name": "0x6170746f735f636f696e", @@ -1545,24 +1477,6 @@ "epoch": "1", "round": "1", "events": [ - { - "guid": { - "creation_number": "0", - "account_address": "0x0" - }, - "sequence_number": "0", - "type": "0x1::block::NewBlock", - "data": { - "epoch": "1", - "failed_proposer_indices": [], - "hash": "", - "height": "17", - "previous_block_votes_bitvec": "0x00", - "proposer": "0x66b22b7465af92a9dc8d07d2878716d9dffbbb280830a7d8cf80334b5da812ef", - "round": "1", - "time_microseconds": "8500000" - } - }, { "guid": { "creation_number": "3", @@ -1609,7 +1523,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", @@ -1682,7 +1596,7 @@ "data": { "authentication_key": "0xfcad780f86d4ee8a3a200bb9289f77eb824bf1d6c155c8d007fc128bfbc33e06", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xfcad780f86d4ee8a3a200bb9289f77eb824bf1d6c155c8d007fc128bfbc33e06", @@ -1738,11 +1652,12 @@ { "guid": { "creation_number": "0", - "account_address": "0xfcad780f86d4ee8a3a200bb9289f77eb824bf1d6c155c8d007fc128bfbc33e06" + "account_address": "0x0" }, "sequence_number": "0", - "type": "0x1::account::CoinRegisterEvent", + "type": "0x1::account::CoinRegister", "data": { + "account": "0xfcad780f86d4ee8a3a200bb9289f77eb824bf1d6c155c8d007fc128bfbc33e06", "type_info": { "account_address": "0x1", "module_name": "0x6170746f735f636f696e", @@ -1899,24 +1814,6 @@ "epoch": "1", "round": "1", "events": [ - { - "guid": { - "creation_number": "0", - "account_address": "0x0" - }, - "sequence_number": "0", - "type": "0x1::block::NewBlock", - "data": { - "epoch": "1", - "failed_proposer_indices": [], - "hash": "", - "height": "18", - "previous_block_votes_bitvec": "0x00", - "proposer": "0x66b22b7465af92a9dc8d07d2878716d9dffbbb280830a7d8cf80334b5da812ef", - "round": "1", - "time_microseconds": "9000000" - } - }, { "guid": { "creation_number": "3", @@ -1963,7 +1860,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", @@ -2036,7 +1933,7 @@ "data": { "authentication_key": "0x099acce340661e0c847ca95ff58ced5f474bc30ca7972106e6a90055c1bdeb26", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0x99acce340661e0c847ca95ff58ced5f474bc30ca7972106e6a90055c1bdeb26", @@ -2092,11 +1989,12 @@ { "guid": { "creation_number": "0", - "account_address": "0x99acce340661e0c847ca95ff58ced5f474bc30ca7972106e6a90055c1bdeb26" + "account_address": "0x0" }, "sequence_number": "0", - "type": "0x1::account::CoinRegisterEvent", + "type": "0x1::account::CoinRegister", "data": { + "account": "0x99acce340661e0c847ca95ff58ced5f474bc30ca7972106e6a90055c1bdeb26", "type_info": { "account_address": "0x1", "module_name": "0x6170746f735f636f696e", @@ -2253,24 +2151,6 @@ "epoch": "1", "round": "1", "events": [ - { - "guid": { - "creation_number": "0", - "account_address": "0x0" - }, - "sequence_number": "0", - "type": "0x1::block::NewBlock", - "data": { - "epoch": "1", - "failed_proposer_indices": [], - "hash": "", - "height": "19", - "previous_block_votes_bitvec": "0x00", - "proposer": "0x66b22b7465af92a9dc8d07d2878716d9dffbbb280830a7d8cf80334b5da812ef", - "round": "1", - "time_microseconds": "9500000" - } - }, { "guid": { "creation_number": "3", @@ -2317,7 +2197,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", @@ -2390,7 +2270,7 @@ "data": { "authentication_key": "0xe9be740413c5f028e58ca77e0540355874c210b49bcd8a75db8880a7ac3273cd", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xe9be740413c5f028e58ca77e0540355874c210b49bcd8a75db8880a7ac3273cd", @@ -2446,11 +2326,12 @@ { "guid": { "creation_number": "0", - "account_address": "0xe9be740413c5f028e58ca77e0540355874c210b49bcd8a75db8880a7ac3273cd" + "account_address": "0x0" }, "sequence_number": "0", - "type": "0x1::account::CoinRegisterEvent", + "type": "0x1::account::CoinRegister", "data": { + "account": "0xe9be740413c5f028e58ca77e0540355874c210b49bcd8a75db8880a7ac3273cd", "type_info": { "account_address": "0x1", "module_name": "0x6170746f735f636f696e", @@ -2607,24 +2488,6 @@ "epoch": "1", "round": "1", "events": [ - { - "guid": { - "creation_number": "0", - "account_address": "0x0" - }, - "sequence_number": "0", - "type": "0x1::block::NewBlock", - "data": { - "epoch": "1", - "failed_proposer_indices": [], - "hash": "", - "height": "20", - "previous_block_votes_bitvec": "0x00", - "proposer": "0x66b22b7465af92a9dc8d07d2878716d9dffbbb280830a7d8cf80334b5da812ef", - "round": "1", - "time_microseconds": "10000000" - } - }, { "guid": { "creation_number": "3", @@ -2671,7 +2534,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", @@ -2744,7 +2607,7 @@ "data": { "authentication_key": "0x626d590a97d6b59c93711a3cdc7aea92eca7fc5c3615084f43394791f1d6d300", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0x626d590a97d6b59c93711a3cdc7aea92eca7fc5c3615084f43394791f1d6d300", @@ -2800,11 +2663,12 @@ { "guid": { "creation_number": "0", - "account_address": "0x626d590a97d6b59c93711a3cdc7aea92eca7fc5c3615084f43394791f1d6d300" + "account_address": "0x0" }, "sequence_number": "0", - "type": "0x1::account::CoinRegisterEvent", + "type": "0x1::account::CoinRegister", "data": { + "account": "0x626d590a97d6b59c93711a3cdc7aea92eca7fc5c3615084f43394791f1d6d300", "type_info": { "account_address": "0x1", "module_name": "0x6170746f735f636f696e", diff --git a/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_entry_function_validation.json b/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_entry_function_validation.json index 93beeb4db70a5..c1338f97a5df3 100644 --- a/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_entry_function_validation.json +++ b/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_entry_function_validation.json @@ -17,7 +17,7 @@ "data": { "authentication_key": "0x34bf7e2d17674feb234371a7ea58efd715f0e56ba20ebf13789480d9d643afaf", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0x34bf7e2d17674feb234371a7ea58efd715f0e56ba20ebf13789480d9d643afaf", diff --git a/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_entry_function_address.json b/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_entry_function_address.json index 3082d1e22cef9..4a29015980099 100644 --- a/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_entry_function_address.json +++ b/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_entry_function_address.json @@ -17,7 +17,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", diff --git a/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_entry_function_arguments.json b/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_entry_function_arguments.json index d2b952813a503..6551d53d02831 100644 --- a/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_entry_function_arguments.json +++ b/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_entry_function_arguments.json @@ -17,7 +17,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", diff --git a/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_entry_function_module_name.json b/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_entry_function_module_name.json index e388e216f6260..61bc16c903da0 100644 --- a/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_entry_function_module_name.json +++ b/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_entry_function_module_name.json @@ -17,7 +17,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", diff --git a/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_entry_function_name.json b/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_entry_function_name.json index 9ad080732738d..aac914cf8165f 100644 --- a/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_entry_function_name.json +++ b/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_entry_function_name.json @@ -17,7 +17,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", diff --git a/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_script_payload_bytecode.json b/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_script_payload_bytecode.json index f05d01ae112e0..ec0a9b2f8cbaf 100644 --- a/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_script_payload_bytecode.json +++ b/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_invalid_script_payload_bytecode.json @@ -17,7 +17,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", diff --git a/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_missing_entry_function_arguments.json b/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_missing_entry_function_arguments.json index a957b9e50ce6c..ce0fc67d753ce 100644 --- a/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_missing_entry_function_arguments.json +++ b/api/goldens/aptos_api__tests__transactions_test__test_get_txn_execute_failed_by_missing_entry_function_arguments.json @@ -17,7 +17,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", diff --git a/api/goldens/aptos_api__tests__transactions_test__test_simulation_failure_with_detail_error.json b/api/goldens/aptos_api__tests__transactions_test__test_simulation_failure_with_detail_error.json index 0e9929fbdde81..3cbe096bca17f 100644 --- a/api/goldens/aptos_api__tests__transactions_test__test_simulation_failure_with_detail_error.json +++ b/api/goldens/aptos_api__tests__transactions_test__test_simulation_failure_with_detail_error.json @@ -18,7 +18,7 @@ "data": { "authentication_key": "0xcef8ffd1ab9017e96132df8a56b22de39a8155e1c3fc32affbbf93eb624b532a", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0xa550c18", diff --git a/api/goldens/aptos_api__tests__transactions_test__test_simulation_failure_with_move_abort_error_rendering.json b/api/goldens/aptos_api__tests__transactions_test__test_simulation_failure_with_move_abort_error_rendering.json index 836779403fc98..a895768361f5f 100644 --- a/api/goldens/aptos_api__tests__transactions_test__test_simulation_failure_with_move_abort_error_rendering.json +++ b/api/goldens/aptos_api__tests__transactions_test__test_simulation_failure_with_move_abort_error_rendering.json @@ -18,7 +18,7 @@ "data": { "authentication_key": "0x34bf7e2d17674feb234371a7ea58efd715f0e56ba20ebf13789480d9d643afaf", "coin_register_events": { - "counter": "1", + "counter": "0", "guid": { "id": { "addr": "0x34bf7e2d17674feb234371a7ea58efd715f0e56ba20ebf13789480d9d643afaf", diff --git a/api/src/tests/multisig_transactions_test.rs b/api/src/tests/multisig_transactions_test.rs index a716b9d0091b7..e25a06506a6db 100644 --- a/api/src/tests/multisig_transactions_test.rs +++ b/api/src/tests/multisig_transactions_test.rs @@ -46,7 +46,6 @@ async fn test_multisig_transaction_with_payload_succeeds() { .await; // The multisig tx that transfers away 1000 APT should have succeeded. - assert_multisig_tx_executed(&mut context, multisig_account, multisig_payload, 1).await; assert_eq!(0, context.get_apt_balance(multisig_account).await); } @@ -93,13 +92,6 @@ async fn test_multisig_transaction_with_existing_account() { .await; // The multisig tx that transfers away 1000 APT should have succeeded. - assert_multisig_tx_executed( - &mut context, - multisig_account.address(), - multisig_payload, - 1, - ) - .await; assert_eq!( org_multisig_balance - 1000, context.get_apt_balance(multisig_account.address()).await @@ -155,7 +147,6 @@ async fn test_multisig_transaction_to_update_owners() { .await; // There should be 4 owners now. - assert_multisig_tx_executed(&mut context, multisig_account, add_owners_payload, 1).await; assert_owners(&context, multisig_account, vec![ owner_account_1.address(), owner_account_2.address(), @@ -189,7 +180,6 @@ async fn test_multisig_transaction_to_update_owners() { .execute_multisig_transaction(owner_account_1, multisig_account, 202) .await; // There should be 3 owners now that owner 4 has been kicked out. - assert_multisig_tx_executed(&mut context, multisig_account, remove_owners_payload, 2).await; assert_owners(&context, multisig_account, vec![ owner_account_1.address(), owner_account_2.address(), @@ -237,13 +227,6 @@ async fn test_multisig_transaction_update_signature_threshold() { .await; // The signature threshold should be 1-of-2 now. - assert_multisig_tx_executed( - &mut context, - multisig_account, - signature_threshold_payload, - 1, - ) - .await; assert_signature_threshold(&context, multisig_account, 1).await; } @@ -292,7 +275,6 @@ async fn test_multisig_transaction_with_payload_and_failing_execution() { .await; // Balance didn't change since the target transaction failed. - assert_multisig_tx_execution_failed(&mut context, multisig_account, multisig_payload, 1).await; assert_eq!(1000, context.get_apt_balance(multisig_account).await); } @@ -324,7 +306,6 @@ async fn test_multisig_transaction_with_payload_hash() { .await; // The multisig tx that transfers away 1000 APT should have succeeded. - assert_multisig_tx_executed(&mut context, multisig_account, multisig_payload, 1).await; assert_eq!(0, context.get_apt_balance(multisig_account).await); } @@ -358,7 +339,6 @@ async fn test_multisig_transaction_with_payload_hash_and_failing_execution() { 202, ) .await; - assert_multisig_tx_execution_failed(&mut context, multisig_account, multisig_payload, 1).await; // Balance didn't change since the target transaction failed. assert_eq!(1000, context.get_apt_balance(multisig_account).await); } @@ -417,7 +397,6 @@ async fn test_multisig_transaction_with_matching_payload() { .await; // The multisig tx that transfers away 1000 APT should have succeeded. - assert_multisig_tx_executed(&mut context, multisig_account, multisig_payload, 1).await; assert_eq!(0, context.get_apt_balance(multisig_account).await); } @@ -737,41 +716,3 @@ fn construct_multisig_txn_transfer_payload(recipient: AccountAddress, amount: u6 )) .unwrap() } - -async fn assert_multisig_tx_executed( - context: &mut TestContext, - multisig_account: AccountAddress, - payload: Vec, - sequence_number: usize, -) { - let transaction_execution_events = context - .get(format!("/accounts/{}/events/0x1::multisig_account::MultisigAccount/execute_transaction_events", multisig_account).as_str()) - .await; - let transaction_execution_events = transaction_execution_events.as_array().unwrap(); - assert_eq!(sequence_number, transaction_execution_events.len()); - let expected_payload = format!("0x{}", hex::encode(payload)); - assert_eq!( - expected_payload, - transaction_execution_events[sequence_number - 1]["data"]["transaction_payload"] - .as_str() - .unwrap() - ); -} - -async fn assert_multisig_tx_execution_failed( - context: &mut TestContext, - multisig_account: AccountAddress, - payload: Vec, - sequence_number: usize, -) { - let transaction_execution_failed_events = context - .get(format!("/accounts/{}/events/0x1::multisig_account::MultisigAccount/transaction_execution_failed_events", multisig_account).as_str()) - .await; - let transaction_execution_failed_events = - transaction_execution_failed_events.as_array().unwrap(); - assert_eq!(1, transaction_execution_failed_events.len()); - let event_data = &transaction_execution_failed_events[sequence_number - 1]["data"]; - assert_eq!("65542", event_data["execution_error"]["error_code"]); - let expected_payload = format!("0x{}", hex::encode(payload)); - assert_eq!(expected_payload, event_data["transaction_payload"],); -} diff --git a/api/src/tests/objects.rs b/api/src/tests/objects.rs index b13a0f1a3795f..3fca5229f6a04 100644 --- a/api/src/tests/objects.rs +++ b/api/src/tests/objects.rs @@ -3,10 +3,7 @@ use super::new_test_context; use aptos_api_test_context::{current_function_name, TestContext}; -use aptos_types::{ - account_address::{self, AccountAddress}, - event::EventKey, -}; +use aptos_types::account_address::{self, AccountAddress}; use serde_json::{json, Value}; use std::{collections::BTreeMap, path::PathBuf}; @@ -74,8 +71,6 @@ async fn test_gen_object() { .unwrap(); assert_eq!(owner, user_addr); - let (before_event_key, before_event_seq) = transfer_events(&hero_map); - context .api_execute_entry_function( &mut user, @@ -94,19 +89,6 @@ async fn test_gen_object() { .parse() .unwrap(); assert_eq!(owner, token_addr); - - let (after_event_key, after_event_seq) = transfer_events(&hero_map); - assert_eq!(after_event_key, before_event_key); - assert_eq!(after_event_seq, before_event_seq + 1); - - let handle = context - .gen_events_by_handle(&token_addr, object_resource, "transfer_events") - .await; - let creation_num = context - .gen_events_by_creation_num(&token_addr, after_event_key.get_creation_number()) - .await; - assert_eq!(handle, creation_num); - assert_eq!(handle.as_array().unwrap().len(), 1); } fn to_object(value: Value) -> BTreeMap { @@ -122,20 +104,3 @@ fn to_object(value: Value) -> BTreeMap { }) .collect() } - -fn transfer_events(object: &BTreeMap) -> (EventKey, u64) { - let transfer_events = object["0x1::object::ObjectCore"].as_object().unwrap()["transfer_events"] - .as_object() - .unwrap(); - let counter = transfer_events["counter"] - .as_str() - .unwrap() - .parse() - .unwrap(); - let guid = transfer_events["guid"].as_object().unwrap()["id"] - .as_object() - .unwrap(); - let creation_num = guid["creation_num"].as_str().unwrap().parse().unwrap(); - let addr = guid["addr"].as_str().unwrap().parse().unwrap(); - (EventKey::new(creation_num, addr), counter) -} diff --git a/aptos-move/aptos-debugger/src/aptos_debugger.rs b/aptos-move/aptos-debugger/src/aptos_debugger.rs index 8a8c1409dec54..8477fec29497b 100644 --- a/aptos-move/aptos-debugger/src/aptos_debugger.rs +++ b/aptos-move/aptos-debugger/src/aptos_debugger.rs @@ -10,6 +10,7 @@ use aptos_types::{ block_executor::config::{ BlockExecutorConfig, BlockExecutorConfigFromOnchain, BlockExecutorLocalConfig, }, + contract_event::ContractEvent, state_store::TStateView, transaction::{ signature_verified_transaction::SignatureVerifiedTransaction, BlockOutput, @@ -412,11 +413,10 @@ fn print_transaction_stats(sig_verified_txns: &[SignatureVerifiedTransaction], v } fn is_reconfiguration(vm_output: &TransactionOutput) -> bool { - let new_epoch_event_key = aptos_types::on_chain_config::new_epoch_event_key(); vm_output .events() .iter() - .any(|event| event.event_key() == Some(&new_epoch_event_key)) + .any(ContractEvent::is_new_epoch_event) } fn execute_block_no_limit( diff --git a/aptos-move/aptos-transactional-test-harness/tests/aptos_test_harness/execute_script.exp b/aptos-move/aptos-transactional-test-harness/tests/aptos_test_harness/execute_script.exp index 9ad667b2d127d..4e4c52a41593d 100644 --- a/aptos-move/aptos-transactional-test-harness/tests/aptos_test_harness/execute_script.exp +++ b/aptos-move/aptos-transactional-test-harness/tests/aptos_test_harness/execute_script.exp @@ -7,7 +7,7 @@ key 0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin> { } frozen: false deposit_events: store 0x1::event::EventHandle<0x1::coin::DepositEvent> { - counter: 2 + counter: 0 guid: drop store 0x1::guid::GUID { id: copy drop store 0x1::guid::ID { creation_num: 2 diff --git a/aptos-move/aptos-transactional-test-harness/tests/aptos_test_harness/table.exp b/aptos-move/aptos-transactional-test-harness/tests/aptos_test_harness/table.exp index b0352e4c59288..b825359162a65 100644 --- a/aptos-move/aptos-transactional-test-harness/tests/aptos_test_harness/table.exp +++ b/aptos-move/aptos-transactional-test-harness/tests/aptos_test_harness/table.exp @@ -6,12 +6,6 @@ Events: type: 0x3::token::CreateCollection data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b7300006400000000000000" } -{ - key: 0400000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6 - seq_num: 0 - type: 0x3::token::CreateCollectionEvent - data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b7300006400000000000000" -} { type: 0x1::transaction_fee::FeeStatement data: "65000000000000000400000000000000030000000000000028720100000000000000000000000000" @@ -21,38 +15,20 @@ return values: 0 task 2 'run'. lines 9-9: Events: { - type: 0x3::token::CreateTokenData - data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00640000000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6010000000000000000000000000000000a6765656b5f746f6b656e0000000000000000" -} -{ - key: 0500000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6 - seq_num: 0 - type: 0x3::token::CreateTokenDataEvent - data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00640000000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6010000000000000000000000000000000a6765656b5f746f6b656e0000000000000000" + type: 0x3::token::TokenDataCreation + data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00640000000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6010000000000000000000000000000000a6765656b5f746f6b656e0000000000000000" } { - type: 0x3::token::MintToken - data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e0a00000000000000" + type: 0x3::token::Mint + data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e0a00000000000000" } { - key: 0600000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6 - seq_num: 0 - type: 0x3::token::MintTokenEvent - data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e0a00000000000000" -} -{ - type: 0x3::token::Deposit - data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000a00000000000000" -} -{ - key: 0700000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6 - seq_num: 0 - type: 0x3::token::DepositEvent - data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000a00000000000000" + type: 0x3::token::TokenDeposit + data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000a00000000000000" } { type: 0x1::transaction_fee::FeeStatement - data: "9c0000000000000007000000000000000400000000000000c83a0200000000000000000000000000" + data: "9c0000000000000006000000000000000400000000000000c83a0200000000000000000000000000" }mutable inputs after call: local#0: 0 return values: 0 @@ -65,7 +41,7 @@ key 0x3::token::Collections { handle: 630c3a2b1a1f2a5a9d112eb98bfe1b35265a16f1482e6224950abd8ad4c76d52 } create_collection_events: store 0x1::event::EventHandle<0x3::token::CreateCollectionEvent> { - counter: 1 + counter: 0 guid: drop store 0x1::guid::GUID { id: copy drop store 0x1::guid::ID { creation_num: 4 @@ -74,7 +50,7 @@ key 0x3::token::Collections { } } create_token_data_events: store 0x1::event::EventHandle<0x3::token::CreateTokenDataEvent> { - counter: 1 + counter: 0 guid: drop store 0x1::guid::GUID { id: copy drop store 0x1::guid::ID { creation_num: 5 @@ -83,7 +59,7 @@ key 0x3::token::Collections { } } mint_token_events: store 0x1::event::EventHandle<0x3::token::MintTokenEvent> { - counter: 1 + counter: 0 guid: drop store 0x1::guid::GUID { id: copy drop store 0x1::guid::ID { creation_num: 6 @@ -99,56 +75,32 @@ task 4 'view_table'. lines 13-15: task 5 'run'. lines 16-18: Events: { - type: 0x3::token::Withdraw - data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000100000000000000" -} -{ - key: 0800000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6 - seq_num: 0 - type: 0x3::token::WithdrawEvent - data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000100000000000000" + type: 0x3::token::TokenWithdraw + data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000100000000000000" } { - type: 0x3::token_transfers::TokenOffer - data: "9c3b634ac05d0af393e0f93b9b19b61e7cac1c519f566276aa0c6fd15dac12aaf75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000100000000000000" -} -{ - key: 0b00000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6 - seq_num: 0 - type: 0x3::token_transfers::TokenOfferEvent - data: "9c3b634ac05d0af393e0f93b9b19b61e7cac1c519f566276aa0c6fd15dac12aaf75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000100000000000000" + type: 0x3::token_transfers::Offer + data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb69c3b634ac05d0af393e0f93b9b19b61e7cac1c519f566276aa0c6fd15dac12aaf75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000100000000000000" } { type: 0x1::transaction_fee::FeeStatement - data: "6c000000000000000600000000000000040000000000000018820100000000000000000000000000" + data: "6c000000000000000500000000000000040000000000000018820100000000000000000000000000" }mutable inputs after call: local#0: 0 return values: 0 task 6 'run'. lines 19-19: Events: { - type: 0x3::token::Deposit - data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000100000000000000" -} -{ - key: 04000000000000009c3b634ac05d0af393e0f93b9b19b61e7cac1c519f566276aa0c6fd15dac12aa - seq_num: 0 - type: 0x3::token::DepositEvent - data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000100000000000000" -} -{ - type: 0x3::token_transfers::TokenClaim + type: 0x3::token::TokenDeposit data: "9c3b634ac05d0af393e0f93b9b19b61e7cac1c519f566276aa0c6fd15dac12aaf75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000100000000000000" } { - key: 0d00000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6 - seq_num: 0 - type: 0x3::token_transfers::TokenClaimEvent - data: "9c3b634ac05d0af393e0f93b9b19b61e7cac1c519f566276aa0c6fd15dac12aaf75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000100000000000000" + type: 0x3::token_transfers::Claim + data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb69c3b634ac05d0af393e0f93b9b19b61e7cac1c519f566276aa0c6fd15dac12aaf75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000100000000000000" } { type: 0x1::transaction_fee::FeeStatement - data: "6c0000000000000006000000000000000400000000000000b88201000000000058bb000000000000" + data: "6c0000000000000005000000000000000400000000000000b88201000000000058bb000000000000" }mutable inputs after call: local#0: 0 return values: 0 diff --git a/aptos-move/aptos-vm/src/aptos_vm.rs b/aptos-move/aptos-vm/src/aptos_vm.rs index 0fd1831d88d6b..125146a15ba8b 100644 --- a/aptos-move/aptos-vm/src/aptos_vm.rs +++ b/aptos-move/aptos-vm/src/aptos_vm.rs @@ -53,8 +53,8 @@ use aptos_types::{ fee_statement::FeeStatement, move_utils::as_move_value::AsMoveValue, on_chain_config::{ - new_epoch_event_key, ApprovedExecutionHashes, ConfigStorage, FeatureFlag, Features, - OnChainConfig, TimedFeatureFlag, TimedFeatures, + ApprovedExecutionHashes, ConfigStorage, FeatureFlag, Features, OnChainConfig, + TimedFeatureFlag, TimedFeatures, }, randomness::Randomness, state_store::{state_key::StateKey, StateView, TStateView}, @@ -2060,9 +2060,7 @@ impl AptosVM { let has_new_block_event = events .iter() .any(|(e, _)| e.event_key() == Some(&new_block_event_key())); - let has_new_epoch_event = events - .iter() - .any(|(e, _)| e.event_key() == Some(&new_epoch_event_key())); + let has_new_epoch_event = events.iter().any(|(e, _)| e.is_new_epoch_event()); if has_new_block_event && has_new_epoch_event { Ok(()) } else { @@ -2406,10 +2404,7 @@ impl AptosVM { } pub fn should_restart_execution(events: &[(ContractEvent, Option)]) -> bool { - let new_epoch_event_key = new_epoch_event_key(); - events - .iter() - .any(|(event, _)| event.event_key() == Some(&new_epoch_event_key)) + events.iter().any(|(event, _)| event.is_new_epoch_event()) } /// Executes a single transaction (including user transactions, block diff --git a/aptos-move/e2e-benchmark/src/main.rs b/aptos-move/e2e-benchmark/src/main.rs index a00e511eaea89..1d3872f346afc 100644 --- a/aptos-move/e2e-benchmark/src/main.rs +++ b/aptos-move/e2e-benchmark/src/main.rs @@ -139,8 +139,8 @@ fn main() { (26, EntryPoints::ResourceGroupsSenderMultiChange { string_length: 1024, }), - (350, EntryPoints::TokenV1MintAndTransferFT), - (536, EntryPoints::TokenV1MintAndTransferNFTSequential), + (281, EntryPoints::TokenV1MintAndTransferFT), + (474, EntryPoints::TokenV1MintAndTransferNFTSequential), (401, EntryPoints::TokenV2AmbassadorMint { numbered: true }), (467, EntryPoints::LiquidityPoolSwap { is_stable: true }), (415, EntryPoints::LiquidityPoolSwap { is_stable: false }), diff --git a/aptos-move/e2e-move-tests/src/tests/rotate_auth_key.rs b/aptos-move/e2e-move-tests/src/tests/rotate_auth_key.rs index ed8e14c4e0e60..209d9c960778f 100644 --- a/aptos-move/e2e-move-tests/src/tests/rotate_auth_key.rs +++ b/aptos-move/e2e-move-tests/src/tests/rotate_auth_key.rs @@ -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}, }; @@ -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] @@ -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] @@ -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( @@ -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] @@ -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()); @@ -221,7 +220,6 @@ pub fn verify_originating_address( harness: &mut MoveHarness, auth_key: Vec, expected_address: AccountAddress, - expected_num_of_events: u64, ) { // Get the address redirection table let originating_address_handle = harness @@ -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::(&expected_address, account_resource) - .unwrap() - .key_rotation_events() - .clone(); - - assert_eq!(key_rotation_events.count(), expected_num_of_events); } diff --git a/aptos-move/e2e-move-tests/src/tests/token_event_store.rs b/aptos-move/e2e-move-tests/src/tests/token_event_store.rs index e24230a3d299e..2aa48699eb2be 100644 --- a/aptos-move/e2e-move-tests/src/tests/token_event_store.rs +++ b/aptos-move/e2e-move-tests/src/tests/token_event_store.rs @@ -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() ); } diff --git a/aptos-move/e2e-tests/goldens/language_e2e_testsuite__tests__create_account__create_account.exp b/aptos-move/e2e-tests/goldens/language_e2e_testsuite__tests__create_account__create_account.exp index 29304ed89b3d2..a9ae7e898afc4 100644 --- a/aptos-move/e2e-tests/goldens/language_e2e_testsuite__tests__create_account__create_account.exp +++ b/aptos-move/e2e-tests/goldens/language_e2e_testsuite__tests__create_account__create_account.exp @@ -5,15 +5,15 @@ Ok( WriteSetV0( WriteSetMut { write_set: { - StateKey::AccessPath { address: 0xa550c18, path: "Resource(0x1::account::Account)" }: Modification(201304972f9242cbc3528a1e286323471ab891baa37e0053b85651693a79854a000100000000000000040000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a550c1800000000000000000100000000000000000000000000000000000000000000000000000000000000000000000a550c180000, metadata:StateValueMetadata { inner: None }), + StateKey::AccessPath { address: 0xa550c18, path: "Resource(0x1::account::Account)" }: Modification(201304972f9242cbc3528a1e286323471ab891baa37e0053b85651693a79854a000100000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a550c1800000000000000000100000000000000000000000000000000000000000000000000000000000000000000000a550c180000, metadata:StateValueMetadata { inner: None }), StateKey::AccessPath { address: 0xf5b9d6f01a99e74c790e2f330c092fa05455a8193f1dfc1b113ecc54d067afe1, path: "Resource(0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>)" }: Creation(00000000000000000000000000000000000200000000000000f5b9d6f01a99e74c790e2f330c092fa05455a8193f1dfc1b113ecc54d067afe100000000000000000300000000000000f5b9d6f01a99e74c790e2f330c092fa05455a8193f1dfc1b113ecc54d067afe1, metadata:StateValueMetadata { inner: Some(StateValueMetadataInner { slot_deposit: 0, bytes_deposit: 0, creation_time_usecs: 0 }) }), - StateKey::AccessPath { address: 0xf5b9d6f01a99e74c790e2f330c092fa05455a8193f1dfc1b113ecc54d067afe1, path: "Resource(0x1::account::Account)" }: Creation(20f5b9d6f01a99e74c790e2f330c092fa05455a8193f1dfc1b113ecc54d067afe10000000000000000040000000000000001000000000000000000000000000000f5b9d6f01a99e74c790e2f330c092fa05455a8193f1dfc1b113ecc54d067afe100000000000000000100000000000000f5b9d6f01a99e74c790e2f330c092fa05455a8193f1dfc1b113ecc54d067afe10000, metadata:StateValueMetadata { inner: Some(StateValueMetadataInner { slot_deposit: 0, bytes_deposit: 0, creation_time_usecs: 0 }) }), + StateKey::AccessPath { address: 0xf5b9d6f01a99e74c790e2f330c092fa05455a8193f1dfc1b113ecc54d067afe1, path: "Resource(0x1::account::Account)" }: Creation(20f5b9d6f01a99e74c790e2f330c092fa05455a8193f1dfc1b113ecc54d067afe10000000000000000040000000000000000000000000000000000000000000000f5b9d6f01a99e74c790e2f330c092fa05455a8193f1dfc1b113ecc54d067afe100000000000000000100000000000000f5b9d6f01a99e74c790e2f330c092fa05455a8193f1dfc1b113ecc54d067afe10000, metadata:StateValueMetadata { inner: Some(StateValueMetadataInner { slot_deposit: 0, bytes_deposit: 0, creation_time_usecs: 0 }) }), }, }, ), ), events: [ - ContractEvent { key: EventKey { creation_number: 0, account_address: f5b9d6f01a99e74c790e2f330c092fa05455a8193f1dfc1b113ecc54d067afe1 }, index: 0, type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("account"), name: Identifier("CoinRegisterEvent"), type_args: [] }), event_data: "00000000000000000000000000000000000000000000000000000000000000010a6170746f735f636f696e094170746f73436f696e" }, + ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("account"), name: Identifier("CoinRegister"), type_args: [] }), event_data: "f5b9d6f01a99e74c790e2f330c092fa05455a8193f1dfc1b113ecc54d067afe100000000000000000000000000000000000000000000000000000000000000010a6170746f735f636f696e094170746f73436f696e" }, ModuleEvent { type: Struct(StructTag { address: 0000000000000000000000000000000000000000000000000000000000000001, module: Identifier("transaction_fee"), name: Identifier("FeeStatement"), type_args: [] }), event_data: "09000000000000000500000000000000040000000000000000000000000000000000000000000000" }, ], gas_used: 9, diff --git a/aptos-move/e2e-tests/src/executor.rs b/aptos-move/e2e-tests/src/executor.rs index 018472fe9a9ea..ea473cc7549d5 100644 --- a/aptos-move/e2e-tests/src/executor.rs +++ b/aptos-move/e2e-tests/src/executor.rs @@ -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 @@ -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(); diff --git a/aptos-move/e2e-testsuite/src/tests/peer_to_peer.rs b/aptos-move/e2e-testsuite/src/tests/peer_to_peer.rs index bee9a68986d47..764fe63f91cbc 100644 --- a/aptos-move/e2e-testsuite/src/tests/peer_to_peer.rs +++ b/aptos-move/e2e-testsuite/src/tests/peer_to_peer.rs @@ -48,8 +48,6 @@ fn single_peer_to_peer_with_event() { assert_eq!(receiver_balance, updated_receiver_balance.coin()); assert_eq!(sender_balance, updated_sender_balance.coin()); assert_eq!(11, updated_sender.sequence_number()); - assert_eq!(0, updated_sender_balance.deposit_events().count(),); - assert_eq!(1, updated_receiver_balance.deposit_events().count()); let rec_ev_path = receiver.received_events_key(); let sent_ev_path = sender.sent_events_key(); @@ -124,11 +122,6 @@ fn few_peer_to_peer_with_event() { assert_eq!(receiver_balance, updated_receiver_balance.coin()); assert_eq!(sender_balance, updated_sender_balance.coin()); assert_eq!(11 + idx as u64, updated_sender.sequence_number()); - assert_eq!(0, updated_sender_balance.deposit_events().count()); - assert_eq!( - idx as u64 + 1, - updated_receiver_balance.deposit_events().count() - ); } } diff --git a/aptos-move/framework/aptos-framework/doc/account.md b/aptos-move/framework/aptos-framework/doc/account.md index ce49d6226cc6f..8d5e5f8e1cf7a 100644 --- a/aptos-move/framework/aptos-framework/doc/account.md +++ b/aptos-move/framework/aptos-framework/doc/account.md @@ -9,6 +9,7 @@ - [Resource `Account`](#0x1_account_Account) - [Struct `KeyRotationEvent`](#0x1_account_KeyRotationEvent) - [Struct `CoinRegisterEvent`](#0x1_account_CoinRegisterEvent) +- [Struct `CoinRegister`](#0x1_account_CoinRegister) - [Struct `CapabilityOffer`](#0x1_account_CapabilityOffer) - [Struct `RotationCapability`](#0x1_account_RotationCapability) - [Struct `SignerCapability`](#0x1_account_SignerCapability) @@ -276,6 +277,40 @@ Resource representing an account. + + + + +## Struct `CoinRegister` + + + +
#[event]
+struct CoinRegister has drop, store
+
+ + + +
+Fields + + +
+
+account: address +
+
+ +
+
+type_info: type_info::TypeInfo +
+
+ +
+
+ +
@@ -1889,14 +1924,15 @@ in the event of key recovery. old_authentication_key: account_resource.authentication_key, new_authentication_key: new_auth_key_vector, }); + } else { + event::emit_event<KeyRotationEvent>( + &mut account_resource.key_rotation_events, + KeyRotationEvent { + old_authentication_key: account_resource.authentication_key, + new_authentication_key: new_auth_key_vector, + } + ); }; - event::emit_event<KeyRotationEvent>( - &mut account_resource.key_rotation_events, - KeyRotationEvent { - old_authentication_key: account_resource.authentication_key, - new_authentication_key: new_auth_key_vector, - } - ); // Update the account resource's authentication key. account_resource.authentication_key = new_auth_key_vector; @@ -2109,12 +2145,21 @@ Coin management methods.
public(friend) fun register_coin<CoinType>(account_addr: address) acquires Account {
     let account = borrow_global_mut<Account>(account_addr);
-    event::emit_event<CoinRegisterEvent>(
-        &mut account.coin_register_events,
-        CoinRegisterEvent {
-            type_info: type_info::type_of<CoinType>(),
-        },
-    );
+    if (std::features::module_event_migration_enabled()) {
+        event::emit(
+            CoinRegister {
+                account: account_addr,
+                type_info: type_info::type_of<CoinType>(),
+            },
+        );
+    } else {
+        event::emit_event<CoinRegisterEvent>(
+            &mut account.coin_register_events,
+            CoinRegisterEvent {
+                type_info: type_info::type_of<CoinType>(),
+            },
+        );
+    }
 }
 
diff --git a/aptos-move/framework/aptos-framework/doc/aptos_account.md b/aptos-move/framework/aptos-framework/doc/aptos_account.md index 82fd7df7b7f16..5ae53dbe92683 100644 --- a/aptos-move/framework/aptos-framework/doc/aptos_account.md +++ b/aptos-move/framework/aptos-framework/doc/aptos_account.md @@ -491,10 +491,11 @@ Set whether account can receiv if (std::features::module_event_migration_enabled()) { emit(DirectCoinTransferConfigUpdated { account: addr, new_allow_direct_transfers: allow }); + } else { + emit_event( + &mut direct_transfer_config.update_coin_transfer_events, + DirectCoinTransferConfigUpdatedEvent { new_allow_direct_transfers: allow }); }; - emit_event( - &mut direct_transfer_config.update_coin_transfer_events, - DirectCoinTransferConfigUpdatedEvent { new_allow_direct_transfers: allow }); } else { let direct_transfer_config = DirectTransferConfig { allow_arbitrary_coin_transfers: allow, @@ -502,10 +503,11 @@ Set whether account can receiv }; if (std::features::module_event_migration_enabled()) { emit(DirectCoinTransferConfigUpdated { account: addr, new_allow_direct_transfers: allow }); + } else { + emit_event( + &mut direct_transfer_config.update_coin_transfer_events, + DirectCoinTransferConfigUpdatedEvent { new_allow_direct_transfers: allow }); }; - emit_event( - &mut direct_transfer_config.update_coin_transfer_events, - DirectCoinTransferConfigUpdatedEvent { new_allow_direct_transfers: allow }); move_to(account, direct_transfer_config); }; } diff --git a/aptos-move/framework/aptos-framework/doc/aptos_governance.md b/aptos-move/framework/aptos-framework/doc/aptos_governance.md index bc58738f59e8a..c90cc82da7e23 100644 --- a/aptos-move/framework/aptos-framework/doc/aptos_governance.md +++ b/aptos-move/framework/aptos-framework/doc/aptos_governance.md @@ -946,16 +946,17 @@ AptosGovernance. voting_duration_secs }, ) + } else { + let events = borrow_global_mut<GovernanceEvents>(@aptos_framework); + event::emit_event<UpdateConfigEvent>( + &mut events.update_config_events, + UpdateConfigEvent { + min_voting_threshold, + required_proposer_stake, + voting_duration_secs + }, + ); }; - let events = borrow_global_mut<GovernanceEvents>(@aptos_framework); - event::emit_event<UpdateConfigEvent>( - &mut events.update_config_events, - UpdateConfigEvent { - min_voting_threshold, - required_proposer_stake, - voting_duration_secs - }, - ); } @@ -1320,18 +1321,19 @@ Return proposal_id when a proposal is successfully created. proposal_metadata, }, ); + } else { + let events = borrow_global_mut<GovernanceEvents>(@aptos_framework); + event::emit_event<CreateProposalEvent>( + &mut events.create_proposal_events, + CreateProposalEvent { + proposal_id, + proposer: proposer_address, + stake_pool, + execution_hash, + proposal_metadata, + }, + ); }; - let events = borrow_global_mut<GovernanceEvents>(@aptos_framework); - event::emit_event<CreateProposalEvent>( - &mut events.create_proposal_events, - CreateProposalEvent { - proposal_id, - proposer: proposer_address, - stake_pool, - execution_hash, - proposal_metadata, - }, - ); proposal_id } @@ -1548,18 +1550,19 @@ cannot vote on the proposal even after partial governance voting is enabled. should_pass, }, ); + } else { + let events = borrow_global_mut<GovernanceEvents>(@aptos_framework); + event::emit_event<VoteEvent>( + &mut events.vote_events, + VoteEvent { + proposal_id, + voter: voter_address, + stake_pool, + num_votes: voting_power, + should_pass, + }, + ); }; - let events = borrow_global_mut<GovernanceEvents>(@aptos_framework); - event::emit_event<VoteEvent>( - &mut events.vote_events, - VoteEvent { - proposal_id, - voter: voter_address, - stake_pool, - num_votes: voting_power, - should_pass, - }, - ); let proposal_state = voting::get_proposal_state<GovernanceProposal>(@aptos_framework, proposal_id); if (proposal_state == PROPOSAL_STATE_SUCCEEDED) { @@ -2183,7 +2186,9 @@ Address @aptos_framework must exist GovernanceConfig and GovernanceEvents. 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; ensures new_governance_config.min_voting_threshold == min_voting_threshold; diff --git a/aptos-move/framework/aptos-framework/doc/block.md b/aptos-move/framework/aptos-framework/doc/block.md index 630da13126859..233e672b8dcb5 100644 --- a/aptos-move/framework/aptos-framework/doc/block.md +++ b/aptos-move/framework/aptos-framework/doc/block.md @@ -512,11 +512,12 @@ Can only be called as part of the Aptos governance proposal process established event::emit( UpdateEpochInterval { old_epoch_interval, new_epoch_interval }, ); + } else { + event::emit_event<UpdateEpochIntervalEvent>( + &mut block_resource.update_epoch_interval_events, + UpdateEpochIntervalEvent { old_epoch_interval, new_epoch_interval }, + ); }; - event::emit_event<UpdateEpochIntervalEvent>( - &mut block_resource.update_epoch_interval_events, - UpdateEpochIntervalEvent { old_epoch_interval, new_epoch_interval }, - ); } @@ -592,7 +593,6 @@ Return epoch interval in seconds. let block_metadata_ref = borrow_global_mut<BlockResource>(@aptos_framework); block_metadata_ref.height = event::counter(&block_metadata_ref.new_block_events); - // Emit both event v1 and v2 for compatibility. Eventually only module events will be kept. let new_block_event = NewBlockEvent { hash, epoch, @@ -603,17 +603,7 @@ Return epoch interval in seconds. failed_proposer_indices, time_microseconds: timestamp, }; - let new_block_event_v2 = NewBlock { - hash, - epoch, - round, - height: block_metadata_ref.height, - previous_block_votes_bitvec, - proposer, - failed_proposer_indices, - time_microseconds: timestamp, - }; - emit_new_block_event(vm, &mut block_metadata_ref.new_block_events, new_block_event, new_block_event_v2); + emit_new_block_event(vm, &mut block_metadata_ref.new_block_events, new_block_event); // Performance scores have to be updated before the epoch transition as the transaction that triggers the // transition is the last block in the previous epoch. @@ -749,7 +739,7 @@ Get the current block height Emit the event and update height and global timestamp -
fun emit_new_block_event(vm: &signer, event_handle: &mut event::EventHandle<block::NewBlockEvent>, new_block_event: block::NewBlockEvent, new_block_event_v2: block::NewBlock)
+
fun emit_new_block_event(vm: &signer, event_handle: &mut event::EventHandle<block::NewBlockEvent>, new_block_event: block::NewBlockEvent)
 
@@ -762,7 +752,6 @@ Emit the event and update height and global timestamp vm: &signer, event_handle: &mut EventHandle<NewBlockEvent>, new_block_event: NewBlockEvent, - new_block_event_v2: NewBlock ) acquires CommitHistory { if (exists<CommitHistory>(@aptos_framework)) { let commit_history_ref = borrow_global_mut<CommitHistory>(@aptos_framework); @@ -781,9 +770,6 @@ Emit the event and update height and global timestamp event::counter(event_handle) == new_block_event.height, error::invalid_argument(ENUM_NEW_BLOCK_EVENTS_DOES_NOT_MATCH_BLOCK_HEIGHT), ); - if (std::features::module_event_migration_enabled()) { - event::emit(new_block_event_v2); - }; event::emit_event<NewBlockEvent>(event_handle, new_block_event); }
@@ -825,16 +811,6 @@ reconfiguration event. failed_proposer_indices: vector::empty(), time_microseconds: 0, }, - NewBlock { - hash: genesis_id, - epoch: 0, - round: 0, - height: 0, - previous_block_votes_bitvec: vector::empty(), - proposer: @vm_reserved, - failed_proposer_indices: vector::empty(), - time_microseconds: 0, - } ); } @@ -878,16 +854,6 @@ new block event for WriteSetPayload. failed_proposer_indices: vector::empty(), time_microseconds: timestamp::now_microseconds(), }, - NewBlock { - hash: fake_block_hash, - epoch: reconfiguration::current_epoch(), - round: MAX_U64, - height: block_metadata_ref.height, - previous_block_votes_bitvec: vector::empty(), - proposer: @vm_reserved, - failed_proposer_indices: vector::empty(), - time_microseconds: timestamp::now_microseconds(), - } ); } @@ -1276,7 +1242,7 @@ The BlockResource existed under the @aptos_framework. ### Function `emit_new_block_event` -
fun emit_new_block_event(vm: &signer, event_handle: &mut event::EventHandle<block::NewBlockEvent>, new_block_event: block::NewBlockEvent, new_block_event_v2: block::NewBlock)
+
fun emit_new_block_event(vm: &signer, event_handle: &mut event::EventHandle<block::NewBlockEvent>, new_block_event: block::NewBlockEvent)
 
diff --git a/aptos-move/framework/aptos-framework/doc/coin.md b/aptos-move/framework/aptos-framework/doc/coin.md index 623f1dcb690b7..1754c634bec8a 100644 --- a/aptos-move/framework/aptos-framework/doc/coin.md +++ b/aptos-move/framework/aptos-framework/doc/coin.md @@ -2620,11 +2620,12 @@ Deposit the coin balance into the recipient's account and emit an event. event::emit( CoinDeposit { coin_type: type_name<CoinType>(), account: account_addr, amount: coin.value } ); + } else { + event::emit_event<DepositEvent>( + &mut coin_store.deposit_events, + DepositEvent { amount: coin.value }, + ); }; - event::emit_event<DepositEvent>( - &mut coin_store.deposit_events, - DepositEvent { amount: coin.value }, - ); merge(&mut coin_store.coin, coin); } else { let metadata = paired_metadata<CoinType>(); @@ -3244,11 +3245,12 @@ Withdraw specified amount of coin CoinType from the si coin_type: type_name<CoinType>(), account: account_addr, amount: coin_amount_to_withdraw } ); + } else { + event::emit_event<WithdrawEvent>( + &mut coin_store.withdraw_events, + WithdrawEvent { amount: coin_amount_to_withdraw }, + ); }; - event::emit_event<WithdrawEvent>( - &mut coin_store.withdraw_events, - WithdrawEvent { amount: coin_amount_to_withdraw }, - ); extract(&mut coin_store.coin, coin_amount_to_withdraw) } else { zero() diff --git a/aptos-move/framework/aptos-framework/doc/delegation_pool.md b/aptos-move/framework/aptos-framework/doc/delegation_pool.md index 9ce29ab22430e..268d0618fb722 100644 --- a/aptos-move/framework/aptos-framework/doc/delegation_pool.md +++ b/aptos-move/framework/aptos-framework/doc/delegation_pool.md @@ -2976,18 +2976,18 @@ Vote on a proposal with a voter's voting power. To successfully vote, the follow should_pass, } ); + } else { + event::emit_event( + &mut governance_records.vote_events, + VoteEvent { + voter: voter_address, + proposal_id, + delegation_pool: pool_address, + num_votes: voting_power, + should_pass, + } + ); }; - - event::emit_event( - &mut governance_records.vote_events, - VoteEvent { - voter: voter_address, - proposal_id, - delegation_pool: pool_address, - num_votes: voting_power, - should_pass, - } - ); }
@@ -3053,16 +3053,16 @@ voting power in THIS delegation pool must be not less than the minimum required delegation_pool: pool_address, } ); + } else { + event::emit_event( + &mut governance_records.create_proposal_events, + CreateProposalEvent { + proposal_id, + voter: voter_addr, + delegation_pool: pool_address, + } + ); }; - - event::emit_event( - &mut governance_records.create_proposal_events, - CreateProposalEvent { - proposal_id, - voter: voter_addr, - delegation_pool: pool_address, - } - ); } @@ -4020,13 +4020,13 @@ this change won't take effects until the next lockup period. delegator: delegator_address, voter: new_voter, }) + } else { + event::emit_event(&mut governance_records.delegate_voting_power_events, DelegateVotingPowerEvent { + pool_address, + delegator: delegator_address, + voter: new_voter, + }); }; - - event::emit_event(&mut governance_records.delegate_voting_power_events, DelegateVotingPowerEvent { - pool_address, - delegator: delegator_address, - voter: new_voter, - }); } @@ -4277,17 +4277,17 @@ Add amount of coins to the delegation pool pool_addresselse { + event::emit_event( + &mut pool.add_stake_events, + AddStakeEvent { + pool_address, + delegator_address, + amount_added: amount, + add_stake_fee, + }, + ); }; - - event::emit_event( - &mut pool.add_stake_events, - AddStakeEvent { - pool_address, - delegator_address, - amount_added: amount, - add_stake_fee, - }, - ); } @@ -4380,16 +4380,16 @@ at most how much active stake there is on the stake pool. amount_unlocked: amount, }, ); + } else { + event::emit_event( + &mut pool.unlock_stake_events, + UnlockStakeEvent { + pool_address, + delegator_address, + amount_unlocked: amount, + }, + ); }; - - event::emit_event( - &mut pool.unlock_stake_events, - UnlockStakeEvent { - pool_address, - delegator_address, - amount_unlocked: amount, - }, - ); } @@ -4450,16 +4450,16 @@ Move amount of coins from pending_inactive to active. amount_reactivated: amount, }, ); + } else { + event::emit_event( + &mut pool.reactivate_stake_events, + ReactivateStakeEvent { + pool_address, + delegator_address, + amount_reactivated: amount, + }, + ); }; - - event::emit_event( - &mut pool.reactivate_stake_events, - ReactivateStakeEvent { - pool_address, - delegator_address, - amount_reactivated: amount, - }, - ); } @@ -4575,16 +4575,16 @@ Withdraw amount of owned inactive stake from the delegation pool at amount_withdrawn: amount, }, ); + } else { + event::emit_event( + &mut pool.withdraw_stake_events, + WithdrawStakeEvent { + pool_address, + delegator_address, + amount_withdrawn: amount, + }, + ); }; - - event::emit_event( - &mut pool.withdraw_stake_events, - WithdrawStakeEvent { - pool_address, - delegator_address, - amount_withdrawn: amount, - }, - ); } diff --git a/aptos-move/framework/aptos-framework/doc/multisig_account.md b/aptos-move/framework/aptos-framework/doc/multisig_account.md index 74dca99c66d88..4117c18c99106 100644 --- a/aptos-move/framework/aptos-framework/doc/multisig_account.md +++ b/aptos-move/framework/aptos-framework/doc/multisig_account.md @@ -2748,14 +2748,15 @@ maliciously alter the number of signatures required. new_metadata: multisig_account_resource.metadata, } ) + } else { + emit_event( + &mut multisig_account_resource.metadata_updated_events, + MetadataUpdatedEvent { + old_metadata, + new_metadata: multisig_account_resource.metadata, + } + ); }; - emit_event( - &mut multisig_account_resource.metadata_updated_events, - MetadataUpdatedEvent { - old_metadata, - new_metadata: multisig_account_resource.metadata, - } - ); }; } @@ -2950,15 +2951,16 @@ will continue to be an accessible entry point. approved, } ); + } else { + emit_event( + &mut multisig_account_resource.vote_events, + VoteEvent { + owner: owner_addr, + sequence_number, + approved, + } + ); }; - emit_event( - &mut multisig_account_resource.vote_events, - VoteEvent { - owner: owner_addr, - sequence_number, - approved, - } - ); } @@ -3072,15 +3074,16 @@ Remove the next transaction if it has sufficient owner rejections. executor: address_of(owner), } ); + } else { + emit_event( + &mut multisig_account_resource.execute_rejected_transaction_events, + ExecuteRejectedTransactionEvent { + sequence_number, + num_rejections, + executor: owner_addr, + } + ); }; - emit_event( - &mut multisig_account_resource.execute_rejected_transaction_events, - ExecuteRejectedTransactionEvent { - sequence_number, - num_rejections, - executor: owner_addr, - } - ); } @@ -3226,16 +3229,17 @@ This function is private so no other code can call this beside the VM itself as executor, } ); + } else { + emit_event( + &mut multisig_account_resource.execute_transaction_events, + TransactionExecutionSucceededEvent { + sequence_number: multisig_account_resource.last_executed_sequence_number, + transaction_payload, + num_approvals, + executor, + } + ); }; - emit_event( - &mut multisig_account_resource.execute_transaction_events, - TransactionExecutionSucceededEvent { - sequence_number: multisig_account_resource.last_executed_sequence_number, - transaction_payload, - num_approvals, - executor, - } - ); } @@ -3279,17 +3283,18 @@ This function is private so no other code can call this beside the VM itself as execution_error, } ); + } else { + emit_event( + &mut multisig_account_resource.transaction_execution_failed_events, + TransactionExecutionFailedEvent { + executor, + sequence_number: multisig_account_resource.last_executed_sequence_number, + transaction_payload, + num_approvals, + execution_error, + } + ); }; - emit_event( - &mut multisig_account_resource.transaction_execution_failed_events, - TransactionExecutionFailedEvent { - executor, - sequence_number: multisig_account_resource.last_executed_sequence_number, - transaction_payload, - num_approvals, - execution_error, - } - ); } @@ -3329,16 +3334,17 @@ This function is private so no other code can call this beside the VM itself as approved: true, } ); + } else { + emit_event( + &mut multisig_account_resource.vote_events, + VoteEvent { + owner: executor, + sequence_number, + approved: true, + } + ); }; num_approvals = num_approvals + 1; - emit_event( - &mut multisig_account_resource.vote_events, - VoteEvent { - owner: executor, - sequence_number, - approved: true, - } - ); }; num_approvals @@ -3415,11 +3421,12 @@ This function is private so no other code can call this beside the VM itself as emit( CreateTransaction { multisig_account: multisig_account, creator, sequence_number, transaction } ); + } else { + emit_event( + &mut multisig_account_resource.create_transaction_events, + CreateTransactionEvent { creator, sequence_number, transaction }, + ); }; - emit_event( - &mut multisig_account_resource.create_transaction_events, - CreateTransactionEvent { creator, sequence_number, transaction }, - ); } @@ -3807,11 +3814,12 @@ Add new owners, remove owners to remove, update signatures required. ); if (std::features::module_event_migration_enabled()) { emit(AddOwners { multisig_account: multisig_address, owners_added: new_owners }); + } else { + emit_event( + &mut multisig_account_ref_mut.add_owners_events, + AddOwnersEvent { owners_added: new_owners } + ); }; - emit_event( - &mut multisig_account_ref_mut.add_owners_events, - AddOwnersEvent { owners_added: new_owners } - ); }; // If owners to remove provided, try to remove them. if (vector::length(&owners_to_remove) > 0) { @@ -3833,11 +3841,12 @@ Add new owners, remove owners to remove, update signatures required. emit( RemoveOwners { multisig_account: multisig_address, owners_removed } ); + } else { + emit_event( + &mut multisig_account_ref_mut.remove_owners_events, + RemoveOwnersEvent { owners_removed } + ); }; - emit_event( - &mut multisig_account_ref_mut.remove_owners_events, - RemoveOwnersEvent { owners_removed } - ); } }; // If new signature count provided, try to update count. @@ -3862,14 +3871,15 @@ Add new owners, remove owners to remove, update signatures required. new_num_signatures_required, } ); - }; - emit_event( - &mut multisig_account_ref_mut.update_signature_required_events, - UpdateSignaturesRequiredEvent { - old_num_signatures_required, - new_num_signatures_required, - } - ); + } else { + emit_event( + &mut multisig_account_ref_mut.update_signature_required_events, + UpdateSignaturesRequiredEvent { + old_num_signatures_required, + new_num_signatures_required, + } + ); + } } }; // Verify number of owners. diff --git a/aptos-move/framework/aptos-framework/doc/object.md b/aptos-move/framework/aptos-framework/doc/object.md index f3dae60d94a88..cb633a173bf6c 100644 --- a/aptos-move/framework/aptos-framework/doc/object.md +++ b/aptos-move/framework/aptos-framework/doc/object.md @@ -1897,15 +1897,16 @@ Transfer to the destination address using a LinearTransferRef. to, }, ); + } else { + event::emit_event( + &mut object.transfer_events, + TransferEvent { + object: ref.self, + from: object.owner, + to, + }, + ); }; - event::emit_event( - &mut object.transfer_events, - TransferEvent { - object: ref.self, - from: object.owner, - to, - }, - ); object.owner = to; } @@ -2033,15 +2034,16 @@ hierarchy. to, }, ); + } else { + event::emit_event( + &mut object_core.transfer_events, + TransferEvent { + object, + from: object_core.owner, + to, + }, + ); }; - event::emit_event( - &mut object_core.transfer_events, - TransferEvent { - object, - from: object_core.owner, - to, - }, - ); object_core.owner = to; }; } @@ -2448,33 +2450,6 @@ to determine the identity of the starting point of ownership. - - - - -
fun spec_create_object_address(source: address, seed: vector<u8>): address;
-
- - - - - - - -
fun spec_create_user_derived_object_address(source: address, derive_from: address): address;
-
- - - - - - - -
fun spec_create_guid_object_address(source: address, creation_num: u64): address;
-
- - - ### Function `address_to_object` @@ -3399,4 +3374,31 @@ to determine the identity of the starting point of ownership. + + + + + +
fun spec_create_object_address(source: address, seed: vector<u8>): address;
+
+ + + + + + + +
fun spec_create_user_derived_object_address(source: address, derive_from: address): address;
+
+ + + + + + + +
fun spec_create_guid_object_address(source: address, creation_num: u64): address;
+
+ + [move-book]: https://aptos.dev/move/book/SUMMARY diff --git a/aptos-move/framework/aptos-framework/doc/stake.md b/aptos-move/framework/aptos-framework/doc/stake.md index b209d06483577..a1b918e9a8984 100644 --- a/aptos-move/framework/aptos-framework/doc/stake.md +++ b/aptos-move/framework/aptos-framework/doc/stake.md @@ -2646,16 +2646,16 @@ Allows an account with ownership capability to change the operator of the stake new_operator, }, ); + } else { + event::emit_event( + &mut stake_pool.set_operator_events, + SetOperatorEvent { + pool_address, + old_operator, + new_operator, + }, + ); }; - - event::emit_event( - &mut stake_pool.set_operator_events, - SetOperatorEvent { - pool_address, - old_operator, - new_operator, - }, - ); } @@ -2804,14 +2804,15 @@ Add coins into pool_address. this requires the corresp amount_added: amount, }, ); + } else { + event::emit_event( + &mut stake_pool.add_stake_events, + AddStakeEvent { + pool_address, + amount_added: amount, + }, + ); }; - event::emit_event( - &mut stake_pool.add_stake_events, - AddStakeEvent { - pool_address, - amount_added: amount, - }, - ); } @@ -2886,14 +2887,15 @@ Move amount of coins from pending_inactive to active. amount, }, ); + } else { + event::emit_event( + &mut stake_pool.reactivate_stake_events, + ReactivateStakeEvent { + pool_address, + amount, + }, + ); }; - event::emit_event( - &mut stake_pool.reactivate_stake_events, - ReactivateStakeEvent { - pool_address, - amount, - }, - ); } @@ -2948,15 +2950,16 @@ Rotate the consensus key of the validator, it'll take effect in next epoch. new_consensus_pubkey, }, ); + } else { + event::emit_event( + &mut stake_pool.rotate_consensus_key_events, + RotateConsensusKeyEvent { + pool_address, + old_consensus_pubkey, + new_consensus_pubkey, + }, + ); }; - event::emit_event( - &mut stake_pool.rotate_consensus_key_events, - RotateConsensusKeyEvent { - pool_address, - old_consensus_pubkey, - new_consensus_pubkey, - }, - ); } @@ -3007,18 +3010,18 @@ Update the network and full node addresses of the validator. This only takes eff new_fullnode_addresses, }, ); + } else { + event::emit_event( + &mut stake_pool.update_network_and_fullnode_addresses_events, + UpdateNetworkAndFullnodeAddressesEvent { + pool_address, + old_network_addresses, + new_network_addresses, + old_fullnode_addresses, + new_fullnode_addresses, + }, + ); }; - event::emit_event( - &mut stake_pool.update_network_and_fullnode_addresses_events, - UpdateNetworkAndFullnodeAddressesEvent { - pool_address, - old_network_addresses, - new_network_addresses, - old_fullnode_addresses, - new_fullnode_addresses, - }, - ); - } @@ -3090,15 +3093,16 @@ directly inactive if it's not from an active validator. new_locked_until_secs, }, ); - }; - event::emit_event( - &mut stake_pool.increase_lockup_events, - IncreaseLockupEvent { - pool_address, - old_locked_until_secs, - new_locked_until_secs, - }, - ); + } else { + event::emit_event( + &mut stake_pool.increase_lockup_events, + IncreaseLockupEvent { + pool_address, + old_locked_until_secs, + new_locked_until_secs, + }, + ); + } } @@ -3199,11 +3203,12 @@ This internal version can only be called by the Genesis module during Genesis. if (std::features::module_event_migration_enabled()) { event::emit(JoinValidatorSet { pool_address }); - }; - event::emit_event( - &mut stake_pool.join_validator_set_events, - JoinValidatorSetEvent { pool_address }, - ); + } else { + event::emit_event( + &mut stake_pool.join_validator_set_events, + JoinValidatorSetEvent { pool_address }, + ); + } } @@ -3280,14 +3285,15 @@ Unlock amount from the active stake. Only possible if the lockup ha amount_unlocked: amount, }, ); + } else { + event::emit_event( + &mut stake_pool.unlock_stake_events, + UnlockStakeEvent { + pool_address, + amount_unlocked: amount, + }, + ); }; - event::emit_event( - &mut stake_pool.unlock_stake_events, - UnlockStakeEvent { - pool_address, - amount_unlocked: amount, - }, - ); } @@ -3371,14 +3377,15 @@ Withdraw from pool_address's inactive stake with the corresponding amount_withdrawn: withdraw_amount, }, ); + } else { + event::emit_event( + &mut stake_pool.withdraw_stake_events, + WithdrawStakeEvent { + pool_address, + amount_withdrawn: withdraw_amount, + }, + ); }; - event::emit_event( - &mut stake_pool.withdraw_stake_events, - WithdrawStakeEvent { - pool_address, - amount_withdrawn: withdraw_amount, - }, - ); coin::extract(&mut stake_pool.inactive, withdraw_amount) } @@ -3455,13 +3462,14 @@ Can only be called by the operator of the validator/staking pool. if (std::features::module_event_migration_enabled()) { event::emit(LeaveValidatorSet { pool_address }); + } else { + event::emit_event( + &mut stake_pool.leave_validator_set_events, + LeaveValidatorSetEvent { + pool_address, + }, + ); }; - event::emit_event( - &mut stake_pool.leave_validator_set_events, - LeaveValidatorSetEvent { - pool_address, - }, - ); }; } @@ -4047,14 +4055,15 @@ This function shouldn't abort. if (std::features::module_event_migration_enabled()) { event::emit(DistributeRewards { pool_address, rewards_amount }); + } else { + event::emit_event( + &mut stake_pool.distribute_rewards_events, + DistributeRewardsEvent { + pool_address, + rewards_amount, + }, + ); }; - event::emit_event( - &mut stake_pool.distribute_rewards_events, - DistributeRewardsEvent { - pool_address, - rewards_amount, - }, - ); } @@ -4557,14 +4566,108 @@ Returns validator's next epoch voting power, including pending_active, active, a - + -
fun spec_get_reconfig_start_time_secs(): u64 {
-   if (exists<reconfiguration_state::State>(@aptos_framework)) {
-       reconfiguration_state::spec_start_time_secs()
+
fun spec_rewards_amount(
+   stake_amount: u64,
+   num_successful_proposals: u64,
+   num_total_proposals: u64,
+   rewards_rate: u64,
+   rewards_rate_denominator: u64,
+): u64;
+
+ + + + + + + +
fun spec_contains(validators: vector<ValidatorInfo>, addr: address): bool {
+   exists i in 0..len(validators): validators[i].addr == addr
+}
+
+ + + + + + + +
fun spec_is_current_epoch_validator(pool_address: address): bool {
+   let validator_set = global<ValidatorSet>(@aptos_framework);
+   !spec_contains(validator_set.pending_active, pool_address)
+       && (spec_contains(validator_set.active_validators, pool_address)
+       || spec_contains(validator_set.pending_inactive, pool_address))
+}
+
+ + + + + + + +
schema ResourceRequirement {
+    requires exists<AptosCoinCapabilities>(@aptos_framework);
+    requires exists<ValidatorPerformance>(@aptos_framework);
+    requires exists<ValidatorSet>(@aptos_framework);
+    requires exists<StakingConfig>(@aptos_framework);
+    requires exists<StakingRewardsConfig>(@aptos_framework) || !features::spec_periodical_reward_rate_decrease_enabled();
+    requires exists<timestamp::CurrentTimeMicroseconds>(@aptos_framework);
+}
+
+ + + + + + + +
fun spec_get_reward_rate_1(config: StakingConfig): num {
+   if (features::spec_periodical_reward_rate_decrease_enabled()) {
+       let epoch_rewards_rate = global<staking_config::StakingRewardsConfig>(@aptos_framework).rewards_rate;
+       if (epoch_rewards_rate.value == 0) {
+           0
+       } else {
+           let denominator_0 = aptos_std::fixed_point64::spec_divide_u128(staking_config::MAX_REWARDS_RATE, epoch_rewards_rate);
+           let denominator = if (denominator_0 > MAX_U64) {
+               MAX_U64
+           } else {
+               denominator_0
+           };
+           let nominator = aptos_std::fixed_point64::spec_multiply_u128(denominator, epoch_rewards_rate);
+           nominator
+       }
    } else {
-       timestamp::spec_now_seconds()
+           config.rewards_rate
+   }
+}
+
+ + + + + + + +
fun spec_get_reward_rate_2(config: StakingConfig): num {
+   if (features::spec_periodical_reward_rate_decrease_enabled()) {
+       let epoch_rewards_rate = global<staking_config::StakingRewardsConfig>(@aptos_framework).rewards_rate;
+       if (epoch_rewards_rate.value == 0) {
+           1
+       } else {
+           let denominator_0 = aptos_std::fixed_point64::spec_divide_u128(staking_config::MAX_REWARDS_RATE, epoch_rewards_rate);
+           let denominator = if (denominator_0 > MAX_U64) {
+               MAX_U64
+           } else {
+               denominator_0
+           };
+           denominator
+       }
+   } else {
+           config.rewards_rate_denominator
    }
 }
 
@@ -5095,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);
@@ -5540,115 +5644,6 @@ Returns validator's next epoch voting power, including pending_active, active, a
 
 
 
-
-
-
-
-
fun spec_rewards_amount(
-   stake_amount: u64,
-   num_successful_proposals: u64,
-   num_total_proposals: u64,
-   rewards_rate: u64,
-   rewards_rate_denominator: u64,
-): u64;
-
- - - - - - - -
fun spec_contains(validators: vector<ValidatorInfo>, addr: address): bool {
-   exists i in 0..len(validators): validators[i].addr == addr
-}
-
- - - - - - - -
fun spec_is_current_epoch_validator(pool_address: address): bool {
-   let validator_set = global<ValidatorSet>(@aptos_framework);
-   !spec_contains(validator_set.pending_active, pool_address)
-       && (spec_contains(validator_set.active_validators, pool_address)
-       || spec_contains(validator_set.pending_inactive, pool_address))
-}
-
- - - - - - - -
schema ResourceRequirement {
-    requires exists<AptosCoinCapabilities>(@aptos_framework);
-    requires exists<ValidatorPerformance>(@aptos_framework);
-    requires exists<ValidatorSet>(@aptos_framework);
-    requires exists<StakingConfig>(@aptos_framework);
-    requires exists<StakingRewardsConfig>(@aptos_framework) || !features::spec_periodical_reward_rate_decrease_enabled();
-    requires exists<timestamp::CurrentTimeMicroseconds>(@aptos_framework);
-}
-
- - - - - - - -
fun spec_get_reward_rate_1(config: StakingConfig): num {
-   if (features::spec_periodical_reward_rate_decrease_enabled()) {
-       let epoch_rewards_rate = global<staking_config::StakingRewardsConfig>(@aptos_framework).rewards_rate;
-       if (epoch_rewards_rate.value == 0) {
-           0
-       } else {
-           let denominator_0 = aptos_std::fixed_point64::spec_divide_u128(staking_config::MAX_REWARDS_RATE, epoch_rewards_rate);
-           let denominator = if (denominator_0 > MAX_U64) {
-               MAX_U64
-           } else {
-               denominator_0
-           };
-           let nominator = aptos_std::fixed_point64::spec_multiply_u128(denominator, epoch_rewards_rate);
-           nominator
-       }
-   } else {
-           config.rewards_rate
-   }
-}
-
- - - - - - - -
fun spec_get_reward_rate_2(config: StakingConfig): num {
-   if (features::spec_periodical_reward_rate_decrease_enabled()) {
-       let epoch_rewards_rate = global<staking_config::StakingRewardsConfig>(@aptos_framework).rewards_rate;
-       if (epoch_rewards_rate.value == 0) {
-           1
-       } else {
-           let denominator_0 = aptos_std::fixed_point64::spec_divide_u128(staking_config::MAX_REWARDS_RATE, epoch_rewards_rate);
-           let denominator = if (denominator_0 > MAX_U64) {
-               MAX_U64
-           } else {
-               denominator_0
-           };
-           denominator
-       }
-   } else {
-           config.rewards_rate_denominator
-   }
-}
-
- - - ### Function `update_stake_pool` @@ -5745,6 +5740,21 @@ Returns validator's next epoch voting power, including pending_active, active, a + + + + +
fun spec_get_reconfig_start_time_secs(): u64 {
+   if (exists<reconfiguration_state::State>(@aptos_framework)) {
+       reconfiguration_state::spec_start_time_secs()
+   } else {
+       timestamp::spec_now_seconds()
+   }
+}
+
+ + + ### Function `calculate_rewards_amount` diff --git a/aptos-move/framework/aptos-framework/doc/staking_contract.md b/aptos-move/framework/aptos-framework/doc/staking_contract.md index 9327ed0574444..09ecf20686f86 100644 --- a/aptos-move/framework/aptos-framework/doc/staking_contract.md +++ b/aptos-move/framework/aptos-framework/doc/staking_contract.md @@ -1734,11 +1734,12 @@ Staker can call this function to create a simple staking contract with a specifi if (std::features::module_event_migration_enabled()) { emit(CreateStakingContract { operator, voter, pool_address, principal, commission_percentage }); + } else { + emit_event( + &mut store.create_staking_contract_events, + CreateStakingContractEvent { operator, voter, pool_address, principal, commission_percentage }, + ); }; - emit_event( - &mut store.create_staking_contract_events, - CreateStakingContractEvent { operator, voter, pool_address, principal, commission_percentage }, - ); pool_address }
@@ -1778,11 +1779,12 @@ Add more stake to an existing staking contract. let pool_address = staking_contract.pool_address; if (std::features::module_event_migration_enabled()) { emit(AddStake { operator, pool_address, amount }); + } else { + emit_event( + &mut store.add_stake_events, + AddStakeEvent { operator, pool_address, amount }, + ); }; - emit_event( - &mut store.add_stake_events, - AddStakeEvent { operator, pool_address, amount }, - ); }
@@ -1818,12 +1820,12 @@ Convenient function to allow the staker to update the voter address in a staking if (std::features::module_event_migration_enabled()) { emit(UpdateVoter { operator, pool_address, old_voter, new_voter }); + } else { + emit_event( + &mut store.update_voter_events, + UpdateVoterEvent { operator, pool_address, old_voter, new_voter }, + ); }; - emit_event( - &mut store.update_voter_events, - UpdateVoterEvent { operator, pool_address, old_voter, new_voter }, - ); - }
@@ -1858,8 +1860,9 @@ Convenient function to allow the staker to reset their stake pool's lockup perio if (std::features::module_event_migration_enabled()) { emit(ResetLockup { operator, pool_address }); + } else { + emit_event(&mut store.reset_lockup_events, ResetLockupEvent { operator, pool_address }); }; - emit_event(&mut store.reset_lockup_events, ResetLockupEvent { operator, pool_address }); } @@ -1922,11 +1925,12 @@ TODO: fix the typo in function name. commision -> commission emit( UpdateCommission { staker: staker_address, operator, old_commission_percentage, new_commission_percentage } ); + } else { + emit_event( + &mut borrow_global_mut<StakingGroupUpdateCommissionEvent>(staker_address).update_commission_events, + UpdateCommissionEvent { staker: staker_address, operator, old_commission_percentage, new_commission_percentage } + ); }; - emit_event( - &mut borrow_global_mut<StakingGroupUpdateCommissionEvent>(staker_address).update_commission_events, - UpdateCommissionEvent { staker: staker_address, operator, old_commission_percentage, new_commission_percentage } - ); } @@ -2029,11 +2033,12 @@ Only staker, operator or beneficiary can call this. let pool_address = staking_contract.pool_address; if (std::features::module_event_migration_enabled()) { emit(RequestCommission { operator, pool_address, accumulated_rewards, commission_amount }); + } else { + emit_event( + request_commission_events, + RequestCommissionEvent { operator, pool_address, accumulated_rewards, commission_amount }, + ); }; - emit_event( - request_commission_events, - RequestCommissionEvent { operator, pool_address, accumulated_rewards, commission_amount }, - ); commission_amount } @@ -2104,11 +2109,12 @@ This also triggers paying commission to the operator for accounting simplicity. let pool_address = staking_contract.pool_address; if (std::features::module_event_migration_enabled()) { emit(UnlockStake { pool_address, operator, amount, commission_paid }); + } else { + emit_event( + &mut store.unlock_stake_events, + UnlockStakeEvent { pool_address, operator, amount, commission_paid }, + ); }; - emit_event( - &mut store.unlock_stake_events, - UnlockStakeEvent { pool_address, operator, amount, commission_paid }, - ); } @@ -2234,11 +2240,12 @@ Allows staker to switch operator without going through the lenghthy process to u simple_map::add(staking_contracts, new_operator, staking_contract); if (std::features::module_event_migration_enabled()) { emit(SwitchOperator { pool_address, old_operator, new_operator }); + } else { + emit_event( + &mut store.switch_operator_events, + SwitchOperatorEvent { pool_address, old_operator, new_operator } + ); }; - emit_event( - &mut store.switch_operator_events, - SwitchOperatorEvent { pool_address, old_operator, new_operator } - ); } @@ -2372,11 +2379,12 @@ Distribute all unlocked (inactive) funds according to distribution shares. if (std::features::module_event_migration_enabled()) { emit(Distribute { operator, pool_address, recipient, amount: amount_to_distribute }); + } else { + emit_event( + distribute_events, + DistributeEvent { operator, pool_address, recipient, amount: amount_to_distribute } + ); }; - emit_event( - distribute_events, - DistributeEvent { operator, pool_address, recipient, amount: amount_to_distribute } - ); }; // In case there's any dust left, send them all to the staker. @@ -2455,11 +2463,12 @@ Add a new distribution for recipient and amount to the let pool_address = staking_contract.pool_address; if (std::features::module_event_migration_enabled()) { emit(AddDistribution { operator, pool_address, amount: coins_amount }); + } else { + emit_event( + add_distribution_events, + AddDistributionEvent { operator, pool_address, amount: coins_amount } + ); }; - emit_event( - add_distribution_events, - AddDistributionEvent { operator, pool_address, amount: coins_amount } - ); } diff --git a/aptos-move/framework/aptos-framework/doc/vesting.md b/aptos-move/framework/aptos-framework/doc/vesting.md index 6f2d17e23f75f..95b80f3be991a 100644 --- a/aptos-move/framework/aptos-framework/doc/vesting.md +++ b/aptos-move/framework/aptos-framework/doc/vesting.md @@ -2223,19 +2223,20 @@ Create a vesting contract with a given configurations. commission_percentage, }, ); + } else { + emit_event( + &mut admin_store.create_events, + CreateVestingContractEvent { + operator, + voter, + withdrawal_address, + grant_amount, + vesting_contract_address: contract_address, + staking_pool_address: pool_address, + commission_percentage, + }, + ); }; - emit_event( - &mut admin_store.create_events, - CreateVestingContractEvent { - operator, - voter, - withdrawal_address, - grant_amount, - vesting_contract_address: contract_address, - staking_pool_address: pool_address, - commission_percentage, - }, - ); move_to(&contract_signer, VestingContract { state: VESTING_POOL_ACTIVE, @@ -2392,17 +2393,18 @@ Unlock any vested portion of the grant. amount: vested_amount, }, ); + } else { + emit_event( + &mut vesting_contract.vest_events, + VestEvent { + admin: vesting_contract.admin, + vesting_contract_address: contract_address, + staking_pool_address: vesting_contract.staking.pool_address, + period_vested: next_period_to_vest, + amount: vested_amount, + }, + ); }; - emit_event( - &mut vesting_contract.vest_events, - VestEvent { - admin: vesting_contract.admin, - vesting_contract_address: contract_address, - staking_pool_address: vesting_contract.staking.pool_address, - period_vested: next_period_to_vest, - amount: vested_amount, - }, - ); } @@ -2496,15 +2498,16 @@ Distribute any withdrawable stake from the stake pool. amount: total_distribution_amount, }, ); + } else { + emit_event( + &mut vesting_contract.distribute_events, + DistributeEvent { + admin: vesting_contract.admin, + vesting_contract_address: contract_address, + amount: total_distribution_amount, + }, + ); }; - emit_event( - &mut vesting_contract.distribute_events, - DistributeEvent { - admin: vesting_contract.admin, - vesting_contract_address: contract_address, - amount: total_distribution_amount, - }, - ); } @@ -2583,14 +2586,15 @@ Terminate the vesting contract and send all funds back to the withdrawal address vesting_contract_address: contract_address, }, ); + } else { + emit_event( + &mut vesting_contract.terminate_events, + TerminateEvent { + admin: vesting_contract.admin, + vesting_contract_address: contract_address, + }, + ); }; - emit_event( - &mut vesting_contract.terminate_events, - TerminateEvent { - admin: vesting_contract.admin, - vesting_contract_address: contract_address, - }, - ); } @@ -2640,15 +2644,16 @@ has already been terminated. amount, }, ); + } else { + emit_event( + &mut vesting_contract.admin_withdraw_events, + AdminWithdrawEvent { + admin: vesting_contract.admin, + vesting_contract_address: contract_address, + amount, + }, + ); }; - emit_event( - &mut vesting_contract.admin_withdraw_events, - AdminWithdrawEvent { - admin: vesting_contract.admin, - vesting_contract_address: contract_address, - amount, - }, - ); } @@ -2696,18 +2701,19 @@ has already been terminated. commission_percentage, }, ); + } else { + emit_event( + &mut vesting_contract.update_operator_events, + UpdateOperatorEvent { + admin: vesting_contract.admin, + vesting_contract_address: contract_address, + staking_pool_address: vesting_contract.staking.pool_address, + old_operator, + new_operator, + commission_percentage, + }, + ); }; - emit_event( - &mut vesting_contract.update_operator_events, - UpdateOperatorEvent { - admin: vesting_contract.admin, - vesting_contract_address: contract_address, - staking_pool_address: vesting_contract.staking.pool_address, - old_operator, - new_operator, - commission_percentage, - }, - ); } @@ -2816,17 +2822,18 @@ has already been terminated. new_voter, }, ); - }; - emit_event( - &mut vesting_contract.update_voter_events, - UpdateVoterEvent { - admin: vesting_contract.admin, - vesting_contract_address: contract_address, - staking_pool_address: vesting_contract.staking.pool_address, - old_voter, - new_voter, - }, - ); + } else { + emit_event( + &mut vesting_contract.update_voter_events, + UpdateVoterEvent { + admin: vesting_contract.admin, + vesting_contract_address: contract_address, + staking_pool_address: vesting_contract.staking.pool_address, + old_voter, + new_voter, + }, + ); + } } @@ -2867,16 +2874,17 @@ has already been terminated. new_lockup_expiration_secs: stake::get_lockup_secs(vesting_contract.staking.pool_address), }, ); + } else { + emit_event( + &mut vesting_contract.reset_lockup_events, + ResetLockupEvent { + admin: vesting_contract.admin, + vesting_contract_address: contract_address, + staking_pool_address: vesting_contract.staking.pool_address, + new_lockup_expiration_secs: stake::get_lockup_secs(vesting_contract.staking.pool_address), + }, + ); }; - emit_event( - &mut vesting_contract.reset_lockup_events, - ResetLockupEvent { - admin: vesting_contract.admin, - vesting_contract_address: contract_address, - staking_pool_address: vesting_contract.staking.pool_address, - new_lockup_expiration_secs: stake::get_lockup_secs(vesting_contract.staking.pool_address), - }, - ); } @@ -2931,17 +2939,18 @@ has already been terminated. new_beneficiary, }, ); + } else { + emit_event( + &mut vesting_contract.set_beneficiary_events, + SetBeneficiaryEvent { + admin: vesting_contract.admin, + vesting_contract_address: contract_address, + shareholder, + old_beneficiary, + new_beneficiary, + }, + ); }; - emit_event( - &mut vesting_contract.set_beneficiary_events, - SetBeneficiaryEvent { - admin: vesting_contract.admin, - vesting_contract_address: contract_address, - shareholder, - old_beneficiary, - new_beneficiary, - }, - ); } diff --git a/aptos-move/framework/aptos-framework/doc/voting.md b/aptos-move/framework/aptos-framework/doc/voting.md index 946e707b6e2b2..2a4cb6cb28387 100644 --- a/aptos-move/framework/aptos-framework/doc/voting.md +++ b/aptos-move/framework/aptos-framework/doc/voting.md @@ -817,14 +817,15 @@ Key used to track the resolvable time in the proposal's metadata. proposal_type_info: type_info::type_of<ProposalType>(), }, ); + } else { + event::emit_event<RegisterForumEvent>( + &mut voting_forum.events.register_forum_events, + RegisterForumEvent { + hosting_account: addr, + proposal_type_info: type_info::type_of<ProposalType>(), + }, + ); }; - event::emit_event<RegisterForumEvent>( - &mut voting_forum.events.register_forum_events, - RegisterForumEvent { - hosting_account: addr, - proposal_type_info: type_info::type_of<ProposalType>(), - }, - ); move_to(account, voting_forum); } @@ -982,19 +983,19 @@ resolve this proposal. min_vote_threshold, }, ); + } else { + event::emit_event<CreateProposalEvent>( + &mut voting_forum.events.create_proposal_events, + CreateProposalEvent { + proposal_id, + early_resolution_vote_threshold, + execution_hash, + expiration_secs, + metadata, + min_vote_threshold, + }, + ); }; - event::emit_event<CreateProposalEvent>( - &mut voting_forum.events.create_proposal_events, - CreateProposalEvent { - proposal_id, - early_resolution_vote_threshold, - execution_hash, - expiration_secs, - metadata, - min_vote_threshold, - }, - ); - proposal_id } @@ -1066,11 +1067,12 @@ This guarantees that voting eligibility and voting power are controlled by the r if (std::features::module_event_migration_enabled()) { event::emit(Vote { proposal_id, num_votes }); + } else { + event::emit_event<VoteEvent>( + &mut voting_forum.events.vote_events, + VoteEvent { proposal_id, num_votes }, + ); }; - event::emit_event<VoteEvent>( - &mut voting_forum.events.vote_events, - VoteEvent { proposal_id, num_votes }, - ); } @@ -1174,16 +1176,17 @@ there are more yes votes than no. If either of these conditions is not met, this resolved_early, }, ); + } else { + event::emit_event<ResolveProposal>( + &mut voting_forum.events.resolve_proposal_events, + ResolveProposal { + proposal_id, + yes_votes: proposal.yes_votes, + no_votes: proposal.no_votes, + resolved_early, + }, + ); }; - event::emit_event<ResolveProposal>( - &mut voting_forum.events.resolve_proposal_events, - ResolveProposal { - proposal_id, - yes_votes: proposal.yes_votes, - no_votes: proposal.no_votes, - resolved_early, - }, - ); option::extract(&mut proposal.execution_content) } @@ -1283,17 +1286,17 @@ there are more yes votes than no. If either of these conditions is not met, this resolved_early, }, ); + } else { + event::emit_event( + &mut voting_forum.events.resolve_proposal_events, + ResolveProposal { + proposal_id, + yes_votes: proposal.yes_votes, + no_votes: proposal.no_votes, + resolved_early, + }, + ); }; - event::emit_event( - &mut voting_forum.events.resolve_proposal_events, - ResolveProposal { - proposal_id, - yes_votes: proposal.yes_votes, - no_votes: proposal.no_votes, - resolved_early, - }, - ); - } diff --git a/aptos-move/framework/aptos-framework/sources/account.move b/aptos-move/framework/aptos-framework/sources/account.move index db1fed32ab6ce..f0737306a67c6 100644 --- a/aptos-move/framework/aptos-framework/sources/account.move +++ b/aptos-move/framework/aptos-framework/sources/account.move @@ -50,6 +50,12 @@ module aptos_framework::account { type_info: TypeInfo, } + #[event] + struct CoinRegister has drop, store { + account: address, + type_info: TypeInfo, + } + struct CapabilityOffer has store { for: Option
} struct RotationCapability has drop, store { account: address } @@ -686,14 +692,15 @@ module aptos_framework::account { old_authentication_key: account_resource.authentication_key, new_authentication_key: new_auth_key_vector, }); + } else { + event::emit_event( + &mut account_resource.key_rotation_events, + KeyRotationEvent { + old_authentication_key: account_resource.authentication_key, + new_authentication_key: new_auth_key_vector, + } + ); }; - event::emit_event( - &mut account_resource.key_rotation_events, - KeyRotationEvent { - old_authentication_key: account_resource.authentication_key, - new_authentication_key: new_auth_key_vector, - } - ); // Update the account resource's authentication key. account_resource.authentication_key = new_auth_key_vector; @@ -798,12 +805,21 @@ module aptos_framework::account { public(friend) fun register_coin(account_addr: address) acquires Account { let account = borrow_global_mut(account_addr); - event::emit_event( - &mut account.coin_register_events, - CoinRegisterEvent { - type_info: type_info::type_of(), - }, - ); + if (std::features::module_event_migration_enabled()) { + event::emit( + CoinRegister { + account: account_addr, + type_info: type_info::type_of(), + }, + ); + } else { + event::emit_event( + &mut account.coin_register_events, + CoinRegisterEvent { + type_info: type_info::type_of(), + }, + ); + } } /////////////////////////////////////////////////////////////////////////// @@ -1520,14 +1536,14 @@ module aptos_framework::account { register_coin(addr); let eventhandle = &borrow_global(addr).coin_register_events; - let event = CoinRegisterEvent { type_info: type_info::type_of() }; + let event = CoinRegister { account: addr, type_info: type_info::type_of() }; - let events = event::emitted_events_by_handle(eventhandle); + let events = event::emitted_events(); 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() }; - assert!(!event::was_event_emitted_by_handle(eventhandle, &event), 3); + let event = CoinRegister { account: addr, type_info: type_info::type_of() }; + assert!(!event::was_event_emitted(&event), 3); } } diff --git a/aptos-move/framework/aptos-framework/sources/aptos_account.move b/aptos-move/framework/aptos-framework/sources/aptos_account.move index 34addca77cf28..59679aada2903 100644 --- a/aptos-move/framework/aptos-framework/sources/aptos_account.move +++ b/aptos-move/framework/aptos-framework/sources/aptos_account.move @@ -155,10 +155,11 @@ module aptos_framework::aptos_account { if (std::features::module_event_migration_enabled()) { emit(DirectCoinTransferConfigUpdated { account: addr, new_allow_direct_transfers: allow }); + } else { + emit_event( + &mut direct_transfer_config.update_coin_transfer_events, + DirectCoinTransferConfigUpdatedEvent { new_allow_direct_transfers: allow }); }; - emit_event( - &mut direct_transfer_config.update_coin_transfer_events, - DirectCoinTransferConfigUpdatedEvent { new_allow_direct_transfers: allow }); } else { let direct_transfer_config = DirectTransferConfig { allow_arbitrary_coin_transfers: allow, @@ -166,10 +167,11 @@ module aptos_framework::aptos_account { }; if (std::features::module_event_migration_enabled()) { emit(DirectCoinTransferConfigUpdated { account: addr, new_allow_direct_transfers: allow }); + } else { + emit_event( + &mut direct_transfer_config.update_coin_transfer_events, + DirectCoinTransferConfigUpdatedEvent { new_allow_direct_transfers: allow }); }; - emit_event( - &mut direct_transfer_config.update_coin_transfer_events, - DirectCoinTransferConfigUpdatedEvent { new_allow_direct_transfers: allow }); move_to(account, direct_transfer_config); }; } diff --git a/aptos-move/framework/aptos-framework/sources/aptos_governance.move b/aptos-move/framework/aptos-framework/sources/aptos_governance.move index 19c8d45c92753..f44ba1b3239fc 100644 --- a/aptos-move/framework/aptos-framework/sources/aptos_governance.move +++ b/aptos-move/framework/aptos-framework/sources/aptos_governance.move @@ -240,16 +240,17 @@ module aptos_framework::aptos_governance { voting_duration_secs }, ) + } else { + let events = borrow_global_mut(@aptos_framework); + event::emit_event( + &mut events.update_config_events, + UpdateConfigEvent { + min_voting_threshold, + required_proposer_stake, + voting_duration_secs + }, + ); }; - let events = borrow_global_mut(@aptos_framework); - event::emit_event( - &mut events.update_config_events, - UpdateConfigEvent { - min_voting_threshold, - required_proposer_stake, - voting_duration_secs - }, - ); } /// Initializes the state for Aptos Governance partial voting. Can only be called through Aptos governance @@ -434,18 +435,19 @@ module aptos_framework::aptos_governance { proposal_metadata, }, ); + } else { + let events = borrow_global_mut(@aptos_framework); + event::emit_event( + &mut events.create_proposal_events, + CreateProposalEvent { + proposal_id, + proposer: proposer_address, + stake_pool, + execution_hash, + proposal_metadata, + }, + ); }; - let events = borrow_global_mut(@aptos_framework); - event::emit_event( - &mut events.create_proposal_events, - CreateProposalEvent { - proposal_id, - proposer: proposer_address, - stake_pool, - execution_hash, - proposal_metadata, - }, - ); proposal_id } @@ -562,18 +564,19 @@ module aptos_framework::aptos_governance { should_pass, }, ); + } else { + let events = borrow_global_mut(@aptos_framework); + event::emit_event( + &mut events.vote_events, + VoteEvent { + proposal_id, + voter: voter_address, + stake_pool, + num_votes: voting_power, + should_pass, + }, + ); }; - let events = borrow_global_mut(@aptos_framework); - event::emit_event( - &mut events.vote_events, - VoteEvent { - proposal_id, - voter: voter_address, - stake_pool, - num_votes: voting_power, - should_pass, - }, - ); let proposal_state = voting::get_proposal_state(@aptos_framework, proposal_id); if (proposal_state == PROPOSAL_STATE_SUCCEEDED) { diff --git a/aptos-move/framework/aptos-framework/sources/aptos_governance.spec.move b/aptos-move/framework/aptos-framework/sources/aptos_governance.spec.move index ab3c87c9b0c1e..41e31d566be6f 100644 --- a/aptos-move/framework/aptos-framework/sources/aptos_governance.spec.move +++ b/aptos-move/framework/aptos-framework/sources/aptos_governance.spec.move @@ -120,7 +120,9 @@ spec aptos_framework::aptos_governance { let post new_governance_config = global(@aptos_framework); aborts_if addr != @aptos_framework; aborts_if !exists(@aptos_framework); - aborts_if !exists(@aptos_framework); + aborts_if !features::spec_is_enabled(features::MODULE_EVENT_MIGRATION) && !exists( + @aptos_framework + ); modifies global(addr); ensures new_governance_config.voting_duration_secs == voting_duration_secs; diff --git a/aptos-move/framework/aptos-framework/sources/block.move b/aptos-move/framework/aptos-framework/sources/block.move index 0b8f96a5a1079..3dc18b06480eb 100644 --- a/aptos-move/framework/aptos-framework/sources/block.move +++ b/aptos-move/framework/aptos-framework/sources/block.move @@ -136,11 +136,12 @@ module aptos_framework::block { event::emit( UpdateEpochInterval { old_epoch_interval, new_epoch_interval }, ); + } else { + event::emit_event( + &mut block_resource.update_epoch_interval_events, + UpdateEpochIntervalEvent { old_epoch_interval, new_epoch_interval }, + ); }; - event::emit_event( - &mut block_resource.update_epoch_interval_events, - UpdateEpochIntervalEvent { old_epoch_interval, new_epoch_interval }, - ); } #[view] @@ -177,7 +178,6 @@ module aptos_framework::block { let block_metadata_ref = borrow_global_mut(@aptos_framework); block_metadata_ref.height = event::counter(&block_metadata_ref.new_block_events); - // Emit both event v1 and v2 for compatibility. Eventually only module events will be kept. let new_block_event = NewBlockEvent { hash, epoch, @@ -188,17 +188,7 @@ module aptos_framework::block { failed_proposer_indices, time_microseconds: timestamp, }; - let new_block_event_v2 = NewBlock { - hash, - epoch, - round, - height: block_metadata_ref.height, - previous_block_votes_bitvec, - proposer, - failed_proposer_indices, - time_microseconds: timestamp, - }; - emit_new_block_event(vm, &mut block_metadata_ref.new_block_events, new_block_event, new_block_event_v2); + emit_new_block_event(vm, &mut block_metadata_ref.new_block_events, new_block_event); // Performance scores have to be updated before the epoch transition as the transaction that triggers the // transition is the last block in the previous epoch. @@ -267,7 +257,6 @@ module aptos_framework::block { vm: &signer, event_handle: &mut EventHandle, new_block_event: NewBlockEvent, - new_block_event_v2: NewBlock ) acquires CommitHistory { if (exists(@aptos_framework)) { let commit_history_ref = borrow_global_mut(@aptos_framework); @@ -286,9 +275,6 @@ module aptos_framework::block { event::counter(event_handle) == new_block_event.height, error::invalid_argument(ENUM_NEW_BLOCK_EVENTS_DOES_NOT_MATCH_BLOCK_HEIGHT), ); - if (std::features::module_event_migration_enabled()) { - event::emit(new_block_event_v2); - }; event::emit_event(event_handle, new_block_event); } @@ -310,16 +296,6 @@ module aptos_framework::block { failed_proposer_indices: vector::empty(), time_microseconds: 0, }, - NewBlock { - hash: genesis_id, - epoch: 0, - round: 0, - height: 0, - previous_block_votes_bitvec: vector::empty(), - proposer: @vm_reserved, - failed_proposer_indices: vector::empty(), - time_microseconds: 0, - } ); } @@ -343,16 +319,6 @@ module aptos_framework::block { failed_proposer_indices: vector::empty(), time_microseconds: timestamp::now_microseconds(), }, - NewBlock { - hash: fake_block_hash, - epoch: reconfiguration::current_epoch(), - round: MAX_U64, - height: block_metadata_ref.height, - previous_block_votes_bitvec: vector::empty(), - proposer: @vm_reserved, - failed_proposer_indices: vector::empty(), - time_microseconds: timestamp::now_microseconds(), - } ); } diff --git a/aptos-move/framework/aptos-framework/sources/coin.move b/aptos-move/framework/aptos-framework/sources/coin.move index b2e9a6c8f3b19..ee4382be75e4e 100644 --- a/aptos-move/framework/aptos-framework/sources/coin.move +++ b/aptos-move/framework/aptos-framework/sources/coin.move @@ -812,11 +812,12 @@ module aptos_framework::coin { event::emit( CoinDeposit { coin_type: type_name(), account: account_addr, amount: coin.value } ); + } else { + event::emit_event( + &mut coin_store.deposit_events, + DepositEvent { amount: coin.value }, + ); }; - event::emit_event( - &mut coin_store.deposit_events, - DepositEvent { amount: coin.value }, - ); merge(&mut coin_store.coin, coin); } else { let metadata = paired_metadata(); @@ -1096,11 +1097,12 @@ module aptos_framework::coin { coin_type: type_name(), account: account_addr, amount: coin_amount_to_withdraw } ); + } else { + event::emit_event( + &mut coin_store.withdraw_events, + WithdrawEvent { amount: coin_amount_to_withdraw }, + ); }; - event::emit_event( - &mut coin_store.withdraw_events, - WithdrawEvent { amount: coin_amount_to_withdraw }, - ); extract(&mut coin_store.coin, coin_amount_to_withdraw) } else { zero() diff --git a/aptos-move/framework/aptos-framework/sources/delegation_pool.move b/aptos-move/framework/aptos-framework/sources/delegation_pool.move index be1643ca6b197..1db2438ed4241 100644 --- a/aptos-move/framework/aptos-framework/sources/delegation_pool.move +++ b/aptos-move/framework/aptos-framework/sources/delegation_pool.move @@ -975,18 +975,18 @@ module aptos_framework::delegation_pool { should_pass, } ); + } else { + event::emit_event( + &mut governance_records.vote_events, + VoteEvent { + voter: voter_address, + proposal_id, + delegation_pool: pool_address, + num_votes: voting_power, + should_pass, + } + ); }; - - event::emit_event( - &mut governance_records.vote_events, - VoteEvent { - voter: voter_address, - proposal_id, - delegation_pool: pool_address, - num_votes: voting_power, - should_pass, - } - ); } /// A voter could create a governance proposal by this function. To successfully create a proposal, the voter's @@ -1032,16 +1032,16 @@ module aptos_framework::delegation_pool { delegation_pool: pool_address, } ); + } else { + event::emit_event( + &mut governance_records.create_proposal_events, + CreateProposalEvent { + proposal_id, + voter: voter_addr, + delegation_pool: pool_address, + } + ); }; - - event::emit_event( - &mut governance_records.create_proposal_events, - CreateProposalEvent { - proposal_id, - voter: voter_addr, - delegation_pool: pool_address, - } - ); } fun assert_owner_cap_exists(owner: address) { @@ -1439,13 +1439,13 @@ module aptos_framework::delegation_pool { delegator: delegator_address, voter: new_voter, }) + } else { + event::emit_event(&mut governance_records.delegate_voting_power_events, DelegateVotingPowerEvent { + pool_address, + delegator: delegator_address, + voter: new_voter, + }); }; - - event::emit_event(&mut governance_records.delegate_voting_power_events, DelegateVotingPowerEvent { - pool_address, - delegator: delegator_address, - voter: new_voter, - }); } /// Enable delegators allowlisting as the pool owner. @@ -1576,17 +1576,17 @@ module aptos_framework::delegation_pool { add_stake_fee, }, ); + } else { + event::emit_event( + &mut pool.add_stake_events, + AddStakeEvent { + pool_address, + delegator_address, + amount_added: amount, + add_stake_fee, + }, + ); }; - - event::emit_event( - &mut pool.add_stake_events, - AddStakeEvent { - pool_address, - delegator_address, - amount_added: amount, - add_stake_fee, - }, - ); } /// Unlock `amount` from the active + pending_active stake of `delegator` or @@ -1639,16 +1639,16 @@ module aptos_framework::delegation_pool { amount_unlocked: amount, }, ); + } else { + event::emit_event( + &mut pool.unlock_stake_events, + UnlockStakeEvent { + pool_address, + delegator_address, + amount_unlocked: amount, + }, + ); }; - - event::emit_event( - &mut pool.unlock_stake_events, - UnlockStakeEvent { - pool_address, - delegator_address, - amount_unlocked: amount, - }, - ); } /// Move `amount` of coins from pending_inactive to active. @@ -1689,16 +1689,16 @@ module aptos_framework::delegation_pool { amount_reactivated: amount, }, ); + } else { + event::emit_event( + &mut pool.reactivate_stake_events, + ReactivateStakeEvent { + pool_address, + delegator_address, + amount_reactivated: amount, + }, + ); }; - - event::emit_event( - &mut pool.reactivate_stake_events, - ReactivateStakeEvent { - pool_address, - delegator_address, - amount_reactivated: amount, - }, - ); } /// Withdraw `amount` of owned inactive stake from the delegation pool at `pool_address`. @@ -1774,16 +1774,16 @@ module aptos_framework::delegation_pool { amount_withdrawn: amount, }, ); + } else { + event::emit_event( + &mut pool.withdraw_stake_events, + WithdrawStakeEvent { + pool_address, + delegator_address, + amount_withdrawn: amount, + }, + ); }; - - event::emit_event( - &mut pool.withdraw_stake_events, - WithdrawStakeEvent { - pool_address, - delegator_address, - amount_withdrawn: amount, - }, - ); } /// Return the unique observed lockup cycle where delegator `delegator_address` may have diff --git a/aptos-move/framework/aptos-framework/sources/multisig_account.move b/aptos-move/framework/aptos-framework/sources/multisig_account.move index 80fffd93ecd59..8e40a86664461 100644 --- a/aptos-move/framework/aptos-framework/sources/multisig_account.move +++ b/aptos-move/framework/aptos-framework/sources/multisig_account.move @@ -936,14 +936,15 @@ module aptos_framework::multisig_account { new_metadata: multisig_account_resource.metadata, } ) + } else { + emit_event( + &mut multisig_account_resource.metadata_updated_events, + MetadataUpdatedEvent { + old_metadata, + new_metadata: multisig_account_resource.metadata, + } + ); }; - emit_event( - &mut multisig_account_resource.metadata_updated_events, - MetadataUpdatedEvent { - old_metadata, - new_metadata: multisig_account_resource.metadata, - } - ); }; } @@ -1040,15 +1041,16 @@ module aptos_framework::multisig_account { approved, } ); + } else { + emit_event( + &mut multisig_account_resource.vote_events, + VoteEvent { + owner: owner_addr, + sequence_number, + approved, + } + ); }; - emit_event( - &mut multisig_account_resource.vote_events, - VoteEvent { - owner: owner_addr, - sequence_number, - approved, - } - ); } /// Generic function that can be used to either approve or reject a multisig transaction @@ -1102,15 +1104,16 @@ module aptos_framework::multisig_account { executor: address_of(owner), } ); + } else { + emit_event( + &mut multisig_account_resource.execute_rejected_transaction_events, + ExecuteRejectedTransactionEvent { + sequence_number, + num_rejections, + executor: owner_addr, + } + ); }; - emit_event( - &mut multisig_account_resource.execute_rejected_transaction_events, - ExecuteRejectedTransactionEvent { - sequence_number, - num_rejections, - executor: owner_addr, - } - ); } /// Remove the next transactions until the final_sequence_number if they have sufficient owner rejections. @@ -1198,16 +1201,17 @@ module aptos_framework::multisig_account { executor, } ); + } else { + emit_event( + &mut multisig_account_resource.execute_transaction_events, + TransactionExecutionSucceededEvent { + sequence_number: multisig_account_resource.last_executed_sequence_number, + transaction_payload, + num_approvals, + executor, + } + ); }; - emit_event( - &mut multisig_account_resource.execute_transaction_events, - TransactionExecutionSucceededEvent { - sequence_number: multisig_account_resource.last_executed_sequence_number, - transaction_payload, - num_approvals, - executor, - } - ); } /// Post-execution cleanup for a failed multisig transaction execution. @@ -1231,17 +1235,18 @@ module aptos_framework::multisig_account { execution_error, } ); + } else { + emit_event( + &mut multisig_account_resource.transaction_execution_failed_events, + TransactionExecutionFailedEvent { + executor, + sequence_number: multisig_account_resource.last_executed_sequence_number, + transaction_payload, + num_approvals, + execution_error, + } + ); }; - emit_event( - &mut multisig_account_resource.transaction_execution_failed_events, - TransactionExecutionFailedEvent { - executor, - sequence_number: multisig_account_resource.last_executed_sequence_number, - transaction_payload, - num_approvals, - execution_error, - } - ); } ////////////////////////// Private functions /////////////////////////////// @@ -1263,16 +1268,17 @@ module aptos_framework::multisig_account { approved: true, } ); + } else { + emit_event( + &mut multisig_account_resource.vote_events, + VoteEvent { + owner: executor, + sequence_number, + approved: true, + } + ); }; num_approvals = num_approvals + 1; - emit_event( - &mut multisig_account_resource.vote_events, - VoteEvent { - owner: executor, - sequence_number, - approved: true, - } - ); }; num_approvals @@ -1310,11 +1316,12 @@ module aptos_framework::multisig_account { emit( CreateTransaction { multisig_account: multisig_account, creator, sequence_number, transaction } ); + } else { + emit_event( + &mut multisig_account_resource.create_transaction_events, + CreateTransactionEvent { creator, sequence_number, transaction }, + ); }; - emit_event( - &mut multisig_account_resource.create_transaction_events, - CreateTransactionEvent { creator, sequence_number, transaction }, - ); } fun create_multisig_account(owner: &signer): (signer, SignerCapability) { @@ -1442,11 +1449,12 @@ module aptos_framework::multisig_account { ); if (std::features::module_event_migration_enabled()) { emit(AddOwners { multisig_account: multisig_address, owners_added: new_owners }); + } else { + emit_event( + &mut multisig_account_ref_mut.add_owners_events, + AddOwnersEvent { owners_added: new_owners } + ); }; - emit_event( - &mut multisig_account_ref_mut.add_owners_events, - AddOwnersEvent { owners_added: new_owners } - ); }; // If owners to remove provided, try to remove them. if (vector::length(&owners_to_remove) > 0) { @@ -1468,11 +1476,12 @@ module aptos_framework::multisig_account { emit( RemoveOwners { multisig_account: multisig_address, owners_removed } ); + } else { + emit_event( + &mut multisig_account_ref_mut.remove_owners_events, + RemoveOwnersEvent { owners_removed } + ); }; - emit_event( - &mut multisig_account_ref_mut.remove_owners_events, - RemoveOwnersEvent { owners_removed } - ); } }; // If new signature count provided, try to update count. @@ -1497,14 +1506,15 @@ module aptos_framework::multisig_account { new_num_signatures_required, } ); - }; - emit_event( - &mut multisig_account_ref_mut.update_signature_required_events, - UpdateSignaturesRequiredEvent { - old_num_signatures_required, - new_num_signatures_required, - } - ); + } else { + emit_event( + &mut multisig_account_ref_mut.update_signature_required_events, + UpdateSignaturesRequiredEvent { + old_num_signatures_required, + new_num_signatures_required, + } + ); + } } }; // Verify number of owners. diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index c03914fb7675c..abca67bb2451a 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -498,15 +498,16 @@ module aptos_framework::object { to, }, ); + } else { + event::emit_event( + &mut object.transfer_events, + TransferEvent { + object: ref.self, + from: object.owner, + to, + }, + ); }; - event::emit_event( - &mut object.transfer_events, - TransferEvent { - object: ref.self, - from: object.owner, - to, - }, - ); object.owner = to; } @@ -554,15 +555,16 @@ module aptos_framework::object { to, }, ); + } else { + event::emit_event( + &mut object_core.transfer_events, + TransferEvent { + object, + from: object_core.owner, + to, + }, + ); }; - event::emit_event( - &mut object_core.transfer_events, - TransferEvent { - object, - from: object_core.owner, - to, - }, - ); object_core.owner = to; }; } diff --git a/aptos-move/framework/aptos-framework/sources/stake.move b/aptos-move/framework/aptos-framework/sources/stake.move index ce3931842d776..9a4ae53bf4aa5 100644 --- a/aptos-move/framework/aptos-framework/sources/stake.move +++ b/aptos-move/framework/aptos-framework/sources/stake.move @@ -657,16 +657,16 @@ module aptos_framework::stake { new_operator, }, ); + } else { + event::emit_event( + &mut stake_pool.set_operator_events, + SetOperatorEvent { + pool_address, + old_operator, + new_operator, + }, + ); }; - - event::emit_event( - &mut stake_pool.set_operator_events, - SetOperatorEvent { - pool_address, - old_operator, - new_operator, - }, - ); } /// Allows an owner to change the delegated voter of the stake pool. @@ -735,14 +735,15 @@ module aptos_framework::stake { amount_added: amount, }, ); + } else { + event::emit_event( + &mut stake_pool.add_stake_events, + AddStakeEvent { + pool_address, + amount_added: amount, + }, + ); }; - event::emit_event( - &mut stake_pool.add_stake_events, - AddStakeEvent { - pool_address, - amount_added: amount, - }, - ); } /// Move `amount` of coins from pending_inactive to active. @@ -777,14 +778,15 @@ module aptos_framework::stake { amount, }, ); + } else { + event::emit_event( + &mut stake_pool.reactivate_stake_events, + ReactivateStakeEvent { + pool_address, + amount, + }, + ); }; - event::emit_event( - &mut stake_pool.reactivate_stake_events, - ReactivateStakeEvent { - pool_address, - amount, - }, - ); } /// Rotate the consensus key of the validator, it'll take effect in next epoch. @@ -819,15 +821,16 @@ module aptos_framework::stake { new_consensus_pubkey, }, ); + } else { + event::emit_event( + &mut stake_pool.rotate_consensus_key_events, + RotateConsensusKeyEvent { + pool_address, + old_consensus_pubkey, + new_consensus_pubkey, + }, + ); }; - event::emit_event( - &mut stake_pool.rotate_consensus_key_events, - RotateConsensusKeyEvent { - pool_address, - old_consensus_pubkey, - new_consensus_pubkey, - }, - ); } /// Update the network and full node addresses of the validator. This only takes effect in the next epoch. @@ -858,18 +861,18 @@ module aptos_framework::stake { new_fullnode_addresses, }, ); + } else { + event::emit_event( + &mut stake_pool.update_network_and_fullnode_addresses_events, + UpdateNetworkAndFullnodeAddressesEvent { + pool_address, + old_network_addresses, + new_network_addresses, + old_fullnode_addresses, + new_fullnode_addresses, + }, + ); }; - event::emit_event( - &mut stake_pool.update_network_and_fullnode_addresses_events, - UpdateNetworkAndFullnodeAddressesEvent { - pool_address, - old_network_addresses, - new_network_addresses, - old_fullnode_addresses, - new_fullnode_addresses, - }, - ); - } /// Similar to increase_lockup_with_cap but will use ownership capability from the signing account. @@ -901,15 +904,16 @@ module aptos_framework::stake { new_locked_until_secs, }, ); - }; - event::emit_event( - &mut stake_pool.increase_lockup_events, - IncreaseLockupEvent { - pool_address, - old_locked_until_secs, - new_locked_until_secs, - }, - ); + } else { + event::emit_event( + &mut stake_pool.increase_lockup_events, + IncreaseLockupEvent { + pool_address, + old_locked_until_secs, + new_locked_until_secs, + }, + ); + } } /// This can only called by the operator of the validator/staking pool. @@ -970,11 +974,12 @@ module aptos_framework::stake { if (std::features::module_event_migration_enabled()) { event::emit(JoinValidatorSet { pool_address }); - }; - event::emit_event( - &mut stake_pool.join_validator_set_events, - JoinValidatorSetEvent { pool_address }, - ); + } else { + event::emit_event( + &mut stake_pool.join_validator_set_events, + JoinValidatorSetEvent { pool_address }, + ); + } } /// Similar to unlock_with_cap but will use ownership capability from the signing account. @@ -1011,14 +1016,15 @@ module aptos_framework::stake { amount_unlocked: amount, }, ); + } else { + event::emit_event( + &mut stake_pool.unlock_stake_events, + UnlockStakeEvent { + pool_address, + amount_unlocked: amount, + }, + ); }; - event::emit_event( - &mut stake_pool.unlock_stake_events, - UnlockStakeEvent { - pool_address, - amount_unlocked: amount, - }, - ); } /// Withdraw from `account`'s inactive stake. @@ -1062,14 +1068,15 @@ module aptos_framework::stake { amount_withdrawn: withdraw_amount, }, ); + } else { + event::emit_event( + &mut stake_pool.withdraw_stake_events, + WithdrawStakeEvent { + pool_address, + amount_withdrawn: withdraw_amount, + }, + ); }; - event::emit_event( - &mut stake_pool.withdraw_stake_events, - WithdrawStakeEvent { - pool_address, - amount_withdrawn: withdraw_amount, - }, - ); coin::extract(&mut stake_pool.inactive, withdraw_amount) } @@ -1126,13 +1133,14 @@ module aptos_framework::stake { if (std::features::module_event_migration_enabled()) { event::emit(LeaveValidatorSet { pool_address }); + } else { + event::emit_event( + &mut stake_pool.leave_validator_set_events, + LeaveValidatorSetEvent { + pool_address, + }, + ); }; - event::emit_event( - &mut stake_pool.leave_validator_set_events, - LeaveValidatorSetEvent { - pool_address, - }, - ); }; } @@ -1559,14 +1567,15 @@ module aptos_framework::stake { if (std::features::module_event_migration_enabled()) { event::emit(DistributeRewards { pool_address, rewards_amount }); + } else { + event::emit_event( + &mut stake_pool.distribute_rewards_events, + DistributeRewardsEvent { + pool_address, + rewards_amount, + }, + ); }; - event::emit_event( - &mut stake_pool.distribute_rewards_events, - DistributeRewardsEvent { - pool_address, - rewards_amount, - }, - ); } /// Assuming we are in a middle of a reconfiguration (no matter it is immediate or async), get its start time. 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/framework/aptos-framework/sources/staking_contract.move b/aptos-move/framework/aptos-framework/sources/staking_contract.move index be247f59bd259..2e6232d798e6a 100644 --- a/aptos-move/framework/aptos-framework/sources/staking_contract.move +++ b/aptos-move/framework/aptos-framework/sources/staking_contract.move @@ -418,11 +418,12 @@ module aptos_framework::staking_contract { if (std::features::module_event_migration_enabled()) { emit(CreateStakingContract { operator, voter, pool_address, principal, commission_percentage }); + } else { + emit_event( + &mut store.create_staking_contract_events, + CreateStakingContractEvent { operator, voter, pool_address, principal, commission_percentage }, + ); }; - emit_event( - &mut store.create_staking_contract_events, - CreateStakingContractEvent { operator, voter, pool_address, principal, commission_percentage }, - ); pool_address } @@ -442,11 +443,12 @@ module aptos_framework::staking_contract { let pool_address = staking_contract.pool_address; if (std::features::module_event_migration_enabled()) { emit(AddStake { operator, pool_address, amount }); + } else { + emit_event( + &mut store.add_stake_events, + AddStakeEvent { operator, pool_address, amount }, + ); }; - emit_event( - &mut store.add_stake_events, - AddStakeEvent { operator, pool_address, amount }, - ); } /// Convenient function to allow the staker to update the voter address in a staking contract they made. @@ -462,12 +464,12 @@ module aptos_framework::staking_contract { if (std::features::module_event_migration_enabled()) { emit(UpdateVoter { operator, pool_address, old_voter, new_voter }); + } else { + emit_event( + &mut store.update_voter_events, + UpdateVoterEvent { operator, pool_address, old_voter, new_voter }, + ); }; - emit_event( - &mut store.update_voter_events, - UpdateVoterEvent { operator, pool_address, old_voter, new_voter }, - ); - } /// Convenient function to allow the staker to reset their stake pool's lockup period to start now. @@ -482,8 +484,9 @@ module aptos_framework::staking_contract { if (std::features::module_event_migration_enabled()) { emit(ResetLockup { operator, pool_address }); + } else { + emit_event(&mut store.reset_lockup_events, ResetLockupEvent { operator, pool_address }); }; - emit_event(&mut store.reset_lockup_events, ResetLockupEvent { operator, pool_address }); } /// Convenience function to allow a staker to update the commission percentage paid to the operator. @@ -526,11 +529,12 @@ module aptos_framework::staking_contract { emit( UpdateCommission { staker: staker_address, operator, old_commission_percentage, new_commission_percentage } ); + } else { + emit_event( + &mut borrow_global_mut(staker_address).update_commission_events, + UpdateCommissionEvent { staker: staker_address, operator, old_commission_percentage, new_commission_percentage } + ); }; - emit_event( - &mut borrow_global_mut(staker_address).update_commission_events, - UpdateCommissionEvent { staker: staker_address, operator, old_commission_percentage, new_commission_percentage } - ); } /// Unlock commission amount from the stake pool. Operator needs to wait for the amount to become withdrawable @@ -593,11 +597,12 @@ module aptos_framework::staking_contract { let pool_address = staking_contract.pool_address; if (std::features::module_event_migration_enabled()) { emit(RequestCommission { operator, pool_address, accumulated_rewards, commission_amount }); + } else { + emit_event( + request_commission_events, + RequestCommissionEvent { operator, pool_address, accumulated_rewards, commission_amount }, + ); }; - emit_event( - request_commission_events, - RequestCommissionEvent { operator, pool_address, accumulated_rewards, commission_amount }, - ); commission_amount } @@ -648,11 +653,12 @@ module aptos_framework::staking_contract { let pool_address = staking_contract.pool_address; if (std::features::module_event_migration_enabled()) { emit(UnlockStake { pool_address, operator, amount, commission_paid }); + } else { + emit_event( + &mut store.unlock_stake_events, + UnlockStakeEvent { pool_address, operator, amount, commission_paid }, + ); }; - emit_event( - &mut store.unlock_stake_events, - UnlockStakeEvent { pool_address, operator, amount, commission_paid }, - ); } /// Unlock all accumulated rewards since the last recorded principals. @@ -718,11 +724,12 @@ module aptos_framework::staking_contract { simple_map::add(staking_contracts, new_operator, staking_contract); if (std::features::module_event_migration_enabled()) { emit(SwitchOperator { pool_address, old_operator, new_operator }); + } else { + emit_event( + &mut store.switch_operator_events, + SwitchOperatorEvent { pool_address, old_operator, new_operator } + ); }; - emit_event( - &mut store.switch_operator_events, - SwitchOperatorEvent { pool_address, old_operator, new_operator } - ); } /// Allows an operator to change its beneficiary. Any existing unpaid commission rewards will be paid to the new @@ -796,11 +803,12 @@ module aptos_framework::staking_contract { if (std::features::module_event_migration_enabled()) { emit(Distribute { operator, pool_address, recipient, amount: amount_to_distribute }); + } else { + emit_event( + distribute_events, + DistributeEvent { operator, pool_address, recipient, amount: amount_to_distribute } + ); }; - emit_event( - distribute_events, - DistributeEvent { operator, pool_address, recipient, amount: amount_to_distribute } - ); }; // In case there's any dust left, send them all to the staker. @@ -839,11 +847,12 @@ module aptos_framework::staking_contract { let pool_address = staking_contract.pool_address; if (std::features::module_event_migration_enabled()) { emit(AddDistribution { operator, pool_address, amount: coins_amount }); + } else { + emit_event( + add_distribution_events, + AddDistributionEvent { operator, pool_address, amount: coins_amount } + ); }; - emit_event( - add_distribution_events, - AddDistributionEvent { operator, pool_address, amount: coins_amount } - ); } /// Calculate accumulated rewards and commissions since last update. diff --git a/aptos-move/framework/aptos-framework/sources/vesting.move b/aptos-move/framework/aptos-framework/sources/vesting.move index 9ede3acfa3d03..8c3ac239a874a 100644 --- a/aptos-move/framework/aptos-framework/sources/vesting.move +++ b/aptos-move/framework/aptos-framework/sources/vesting.move @@ -596,19 +596,20 @@ module aptos_framework::vesting { commission_percentage, }, ); + } else { + emit_event( + &mut admin_store.create_events, + CreateVestingContractEvent { + operator, + voter, + withdrawal_address, + grant_amount, + vesting_contract_address: contract_address, + staking_pool_address: pool_address, + commission_percentage, + }, + ); }; - emit_event( - &mut admin_store.create_events, - CreateVestingContractEvent { - operator, - voter, - withdrawal_address, - grant_amount, - vesting_contract_address: contract_address, - staking_pool_address: pool_address, - commission_percentage, - }, - ); move_to(&contract_signer, VestingContract { state: VESTING_POOL_ACTIVE, @@ -705,17 +706,18 @@ module aptos_framework::vesting { amount: vested_amount, }, ); + } else { + emit_event( + &mut vesting_contract.vest_events, + VestEvent { + admin: vesting_contract.admin, + vesting_contract_address: contract_address, + staking_pool_address: vesting_contract.staking.pool_address, + period_vested: next_period_to_vest, + amount: vested_amount, + }, + ); }; - emit_event( - &mut vesting_contract.vest_events, - VestEvent { - admin: vesting_contract.admin, - vesting_contract_address: contract_address, - staking_pool_address: vesting_contract.staking.pool_address, - period_vested: next_period_to_vest, - amount: vested_amount, - }, - ); } /// Call `vest` for many vesting contracts. @@ -769,15 +771,16 @@ module aptos_framework::vesting { amount: total_distribution_amount, }, ); + } else { + emit_event( + &mut vesting_contract.distribute_events, + DistributeEvent { + admin: vesting_contract.admin, + vesting_contract_address: contract_address, + amount: total_distribution_amount, + }, + ); }; - emit_event( - &mut vesting_contract.distribute_events, - DistributeEvent { - admin: vesting_contract.admin, - vesting_contract_address: contract_address, - amount: total_distribution_amount, - }, - ); } /// Call `distribute` for many vesting contracts. @@ -816,14 +819,15 @@ module aptos_framework::vesting { vesting_contract_address: contract_address, }, ); + } else { + emit_event( + &mut vesting_contract.terminate_events, + TerminateEvent { + admin: vesting_contract.admin, + vesting_contract_address: contract_address, + }, + ); }; - emit_event( - &mut vesting_contract.terminate_events, - TerminateEvent { - admin: vesting_contract.admin, - vesting_contract_address: contract_address, - }, - ); } /// Withdraw all funds to the preset vesting contract's withdrawal address. This can only be called if the contract @@ -853,15 +857,16 @@ module aptos_framework::vesting { amount, }, ); + } else { + emit_event( + &mut vesting_contract.admin_withdraw_events, + AdminWithdrawEvent { + admin: vesting_contract.admin, + vesting_contract_address: contract_address, + amount, + }, + ); }; - emit_event( - &mut vesting_contract.admin_withdraw_events, - AdminWithdrawEvent { - admin: vesting_contract.admin, - vesting_contract_address: contract_address, - amount, - }, - ); } public entry fun update_operator( @@ -889,18 +894,19 @@ module aptos_framework::vesting { commission_percentage, }, ); + } else { + emit_event( + &mut vesting_contract.update_operator_events, + UpdateOperatorEvent { + admin: vesting_contract.admin, + vesting_contract_address: contract_address, + staking_pool_address: vesting_contract.staking.pool_address, + old_operator, + new_operator, + commission_percentage, + }, + ); }; - emit_event( - &mut vesting_contract.update_operator_events, - UpdateOperatorEvent { - admin: vesting_contract.admin, - vesting_contract_address: contract_address, - staking_pool_address: vesting_contract.staking.pool_address, - old_operator, - new_operator, - commission_percentage, - }, - ); } public entry fun update_operator_with_same_commission( @@ -949,17 +955,18 @@ module aptos_framework::vesting { new_voter, }, ); - }; - emit_event( - &mut vesting_contract.update_voter_events, - UpdateVoterEvent { - admin: vesting_contract.admin, - vesting_contract_address: contract_address, - staking_pool_address: vesting_contract.staking.pool_address, - old_voter, - new_voter, - }, - ); + } else { + emit_event( + &mut vesting_contract.update_voter_events, + UpdateVoterEvent { + admin: vesting_contract.admin, + vesting_contract_address: contract_address, + staking_pool_address: vesting_contract.staking.pool_address, + old_voter, + new_voter, + }, + ); + } } public entry fun reset_lockup( @@ -980,16 +987,17 @@ module aptos_framework::vesting { new_lockup_expiration_secs: stake::get_lockup_secs(vesting_contract.staking.pool_address), }, ); + } else { + emit_event( + &mut vesting_contract.reset_lockup_events, + ResetLockupEvent { + admin: vesting_contract.admin, + vesting_contract_address: contract_address, + staking_pool_address: vesting_contract.staking.pool_address, + new_lockup_expiration_secs: stake::get_lockup_secs(vesting_contract.staking.pool_address), + }, + ); }; - emit_event( - &mut vesting_contract.reset_lockup_events, - ResetLockupEvent { - admin: vesting_contract.admin, - vesting_contract_address: contract_address, - staking_pool_address: vesting_contract.staking.pool_address, - new_lockup_expiration_secs: stake::get_lockup_secs(vesting_contract.staking.pool_address), - }, - ); } public entry fun set_beneficiary( @@ -1024,17 +1032,18 @@ module aptos_framework::vesting { new_beneficiary, }, ); + } else { + emit_event( + &mut vesting_contract.set_beneficiary_events, + SetBeneficiaryEvent { + admin: vesting_contract.admin, + vesting_contract_address: contract_address, + shareholder, + old_beneficiary, + new_beneficiary, + }, + ); }; - emit_event( - &mut vesting_contract.set_beneficiary_events, - SetBeneficiaryEvent { - admin: vesting_contract.admin, - vesting_contract_address: contract_address, - shareholder, - old_beneficiary, - new_beneficiary, - }, - ); } /// Remove the beneficiary for the given shareholder. All distributions will sent directly to the shareholder diff --git a/aptos-move/framework/aptos-framework/sources/voting.move b/aptos-move/framework/aptos-framework/sources/voting.move index a10e795b7369f..8312ac17b7619 100644 --- a/aptos-move/framework/aptos-framework/sources/voting.move +++ b/aptos-move/framework/aptos-framework/sources/voting.move @@ -210,14 +210,15 @@ module aptos_framework::voting { proposal_type_info: type_info::type_of(), }, ); + } else { + event::emit_event( + &mut voting_forum.events.register_forum_events, + RegisterForumEvent { + hosting_account: addr, + proposal_type_info: type_info::type_of(), + }, + ); }; - event::emit_event( - &mut voting_forum.events.register_forum_events, - RegisterForumEvent { - hosting_account: addr, - proposal_type_info: type_info::type_of(), - }, - ); move_to(account, voting_forum); } @@ -335,19 +336,19 @@ module aptos_framework::voting { min_vote_threshold, }, ); + } else { + event::emit_event( + &mut voting_forum.events.create_proposal_events, + CreateProposalEvent { + proposal_id, + early_resolution_vote_threshold, + execution_hash, + expiration_secs, + metadata, + min_vote_threshold, + }, + ); }; - event::emit_event( - &mut voting_forum.events.create_proposal_events, - CreateProposalEvent { - proposal_id, - early_resolution_vote_threshold, - execution_hash, - expiration_secs, - metadata, - min_vote_threshold, - }, - ); - proposal_id } @@ -399,11 +400,12 @@ module aptos_framework::voting { if (std::features::module_event_migration_enabled()) { event::emit(Vote { proposal_id, num_votes }); + } else { + event::emit_event( + &mut voting_forum.events.vote_events, + VoteEvent { proposal_id, num_votes }, + ); }; - event::emit_event( - &mut voting_forum.events.vote_events, - VoteEvent { proposal_id, num_votes }, - ); } /// Common checks on if a proposal is resolvable, regardless if the proposal is single-step or multi-step. @@ -467,16 +469,17 @@ module aptos_framework::voting { resolved_early, }, ); + } else { + event::emit_event( + &mut voting_forum.events.resolve_proposal_events, + ResolveProposal { + proposal_id, + yes_votes: proposal.yes_votes, + no_votes: proposal.no_votes, + resolved_early, + }, + ); }; - event::emit_event( - &mut voting_forum.events.resolve_proposal_events, - ResolveProposal { - proposal_id, - yes_votes: proposal.yes_votes, - no_votes: proposal.no_votes, - resolved_early, - }, - ); option::extract(&mut proposal.execution_content) } @@ -556,17 +559,17 @@ module aptos_framework::voting { resolved_early, }, ); + } else { + event::emit_event( + &mut voting_forum.events.resolve_proposal_events, + ResolveProposal { + proposal_id, + yes_votes: proposal.yes_votes, + no_votes: proposal.no_votes, + resolved_early, + }, + ); }; - event::emit_event( - &mut voting_forum.events.resolve_proposal_events, - ResolveProposal { - proposal_id, - yes_votes: proposal.yes_votes, - no_votes: proposal.no_votes, - resolved_early, - }, - ); - } #[view] diff --git a/aptos-move/framework/aptos-token-objects/doc/collection.md b/aptos-move/framework/aptos-token-objects/doc/collection.md index 0416df35f7d72..64e2839f4bdf5 100644 --- a/aptos-move/framework/aptos-token-objects/doc/collection.md +++ b/aptos-move/framework/aptos-token-objects/doc/collection.md @@ -1222,13 +1222,14 @@ Called by token on mint to increment supply if there's an appropriate Supply str token, }, ); + } else { + event::emit_event(&mut supply.mint_events, + MintEvent { + index: supply.total_minted, + token, + }, + ); }; - event::emit_event(&mut supply.mint_events, - MintEvent { - index: supply.total_minted, - token, - }, - ); option::some(aggregator_v2::create_snapshot<u64>(supply.total_minted)) } else if (exists<UnlimitedSupply>(collection_addr)) { let supply = borrow_global_mut<UnlimitedSupply>(collection_addr); @@ -1242,14 +1243,15 @@ Called by token on mint to increment supply if there's an appropriate Supply str token, }, ); + } else { + event::emit_event( + &mut supply.mint_events, + MintEvent { + index: supply.total_minted, + token, + }, + ); }; - event::emit_event( - &mut supply.mint_events, - MintEvent { - index: supply.total_minted, - token, - }, - ); option::some(aggregator_v2::create_snapshot<u64>(supply.total_minted)) } else { option::none() @@ -1308,14 +1310,15 @@ Called by token on burn to decrement supply if there's an appropriate Supply str previous_owner, }, ); + } else { + event::emit_event( + &mut supply.burn_events, + BurnEvent { + index: *option::borrow(&index), + token, + }, + ); }; - event::emit_event( - &mut supply.burn_events, - BurnEvent { - index: *option::borrow(&index), - token, - }, - ); } else if (exists<UnlimitedSupply>(collection_addr)) { let supply = borrow_global_mut<UnlimitedSupply>(collection_addr); supply.current_supply = supply.current_supply - 1; @@ -1328,14 +1331,15 @@ Called by token on burn to decrement supply if there's an appropriate Supply str previous_owner, }, ); + } else { + event::emit_event( + &mut supply.burn_events, + BurnEvent { + index: *option::borrow(&index), + token, + }, + ); }; - event::emit_event( - &mut supply.burn_events, - BurnEvent { - index: *option::borrow(&index), - token, - }, - ); } } @@ -1718,6 +1722,7 @@ After changing the collection's name, to create tokens - only call functions tha
public fun set_description(mutator_ref: &MutatorRef, description: String) acquires Collection {
     assert!(string::length(&description) <= MAX_DESCRIPTION_LENGTH, error::out_of_range(EDESCRIPTION_TOO_LONG));
     let collection = borrow_mut(mutator_ref);
+    collection.description = description;
     if (std::features::module_event_migration_enabled()) {
         event::emit(Mutation {
             mutated_field_name: string::utf8(b"description"),
@@ -1725,12 +1730,12 @@ After changing the collection's name, to create tokens - only call functions tha
             old_value: collection.description,
             new_value: description,
         });
+    } else {
+        event::emit_event(
+            &mut collection.mutation_events,
+            MutationEvent { mutated_field_name: string::utf8(b"description") },
+        );
     };
-    collection.description = description;
-    event::emit_event(
-        &mut collection.mutation_events,
-        MutationEvent { mutated_field_name: string::utf8(b"description") },
-    );
 }
 
@@ -1756,6 +1761,7 @@ After changing the collection's name, to create tokens - only call functions tha
public fun set_uri(mutator_ref: &MutatorRef, uri: String) acquires Collection {
     assert!(string::length(&uri) <= MAX_URI_LENGTH, error::out_of_range(EURI_TOO_LONG));
     let collection = borrow_mut(mutator_ref);
+    collection.uri = uri;
     if (std::features::module_event_migration_enabled()) {
         event::emit(Mutation {
             mutated_field_name: string::utf8(b"uri"),
@@ -1763,12 +1769,12 @@ After changing the collection's name, to create tokens - only call functions tha
             old_value: collection.uri,
             new_value: uri,
         });
+    } else {
+        event::emit_event(
+            &mut collection.mutation_events,
+            MutationEvent { mutated_field_name: string::utf8(b"uri") },
+        );
     };
-    collection.uri = uri;
-    event::emit_event(
-        &mut collection.mutation_events,
-        MutationEvent { mutated_field_name: string::utf8(b"uri") },
-    );
 }
 
diff --git a/aptos-move/framework/aptos-token-objects/doc/token.md b/aptos-move/framework/aptos-token-objects/doc/token.md index 11d56968b9188..f850767b9a17b 100644 --- a/aptos-move/framework/aptos-token-objects/doc/token.md +++ b/aptos-move/framework/aptos-token-objects/doc/token.md @@ -1824,15 +1824,16 @@ as that would prohibit transactions to be executed in parallel. old_value: token.description, new_value: description }) + } else { + event::emit_event( + &mut token.mutation_events, + MutationEvent { + mutated_field_name: string::utf8(b"description"), + old_value: token.description, + new_value: description + }, + ); }; - event::emit_event( - &mut token.mutation_events, - MutationEvent { - mutated_field_name: string::utf8(b"description"), - old_value: token.description, - new_value: description - }, - ); token.description = description; } @@ -1879,15 +1880,16 @@ as that would prohibit transactions to be executed in parallel. old_value: old_name, new_value: name }) + } else { + event::emit_event( + &mut token.mutation_events, + MutationEvent { + mutated_field_name: string::utf8(b"name"), + old_value: old_name, + new_value: name + }, + ); }; - event::emit_event( - &mut token.mutation_events, - MutationEvent { - mutated_field_name: string::utf8(b"name"), - old_value: old_name, - new_value: name - }, - ); } @@ -1920,15 +1922,16 @@ as that would prohibit transactions to be executed in parallel. old_value: token.uri, new_value: uri, }) + } else { + event::emit_event( + &mut token.mutation_events, + MutationEvent { + mutated_field_name: string::utf8(b"uri"), + old_value: token.uri, + new_value: uri, + }, + ); }; - event::emit_event( - &mut token.mutation_events, - MutationEvent { - mutated_field_name: string::utf8(b"uri"), - old_value: token.uri, - new_value: uri, - }, - ); token.uri = uri; } diff --git a/aptos-move/framework/aptos-token-objects/sources/collection.move b/aptos-move/framework/aptos-token-objects/sources/collection.move index ff81e64d1ea57..af334dd9c558f 100644 --- a/aptos-move/framework/aptos-token-objects/sources/collection.move +++ b/aptos-move/framework/aptos-token-objects/sources/collection.move @@ -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; @@ -406,13 +408,14 @@ module aptos_token_objects::collection { token, }, ); + } else { + event::emit_event(&mut supply.mint_events, + MintEvent { + index: supply.total_minted, + token, + }, + ); }; - event::emit_event(&mut supply.mint_events, - MintEvent { - index: supply.total_minted, - token, - }, - ); option::some(aggregator_v2::create_snapshot(supply.total_minted)) } else if (exists(collection_addr)) { let supply = borrow_global_mut(collection_addr); @@ -426,14 +429,15 @@ module aptos_token_objects::collection { token, }, ); + } else { + event::emit_event( + &mut supply.mint_events, + MintEvent { + index: supply.total_minted, + token, + }, + ); }; - event::emit_event( - &mut supply.mint_events, - MintEvent { - index: supply.total_minted, - token, - }, - ); option::some(aggregator_v2::create_snapshot(supply.total_minted)) } else { option::none() @@ -493,14 +497,15 @@ module aptos_token_objects::collection { previous_owner, }, ); + } else { + event::emit_event( + &mut supply.burn_events, + BurnEvent { + index: *option::borrow(&index), + token, + }, + ); }; - event::emit_event( - &mut supply.burn_events, - BurnEvent { - index: *option::borrow(&index), - token, - }, - ); } else if (exists(collection_addr)) { let supply = borrow_global_mut(collection_addr); supply.current_supply = supply.current_supply - 1; @@ -513,14 +518,15 @@ module aptos_token_objects::collection { previous_owner, }, ); + } else { + event::emit_event( + &mut supply.burn_events, + BurnEvent { + index: *option::borrow(&index), + token, + }, + ); }; - event::emit_event( - &mut supply.burn_events, - BurnEvent { - index: *option::borrow(&index), - token, - }, - ); } } @@ -667,6 +673,7 @@ module aptos_token_objects::collection { public fun set_description(mutator_ref: &MutatorRef, description: String) acquires Collection { assert!(string::length(&description) <= MAX_DESCRIPTION_LENGTH, error::out_of_range(EDESCRIPTION_TOO_LONG)); let collection = borrow_mut(mutator_ref); + collection.description = description; if (std::features::module_event_migration_enabled()) { event::emit(Mutation { mutated_field_name: string::utf8(b"description"), @@ -674,17 +681,18 @@ module aptos_token_objects::collection { old_value: collection.description, new_value: description, }); + } else { + event::emit_event( + &mut collection.mutation_events, + MutationEvent { mutated_field_name: string::utf8(b"description") }, + ); }; - collection.description = description; - event::emit_event( - &mut collection.mutation_events, - MutationEvent { mutated_field_name: string::utf8(b"description") }, - ); } public fun set_uri(mutator_ref: &MutatorRef, uri: String) acquires Collection { assert!(string::length(&uri) <= MAX_URI_LENGTH, error::out_of_range(EURI_TOO_LONG)); let collection = borrow_mut(mutator_ref); + collection.uri = uri; if (std::features::module_event_migration_enabled()) { event::emit(Mutation { mutated_field_name: string::utf8(b"uri"), @@ -692,12 +700,12 @@ module aptos_token_objects::collection { old_value: collection.uri, new_value: uri, }); + } else { + event::emit_event( + &mut collection.mutation_events, + MutationEvent { mutated_field_name: string::utf8(b"uri") }, + ); }; - collection.uri = uri; - event::emit_event( - &mut collection.mutation_events, - MutationEvent { mutated_field_name: string::utf8(b"uri") }, - ); } public fun set_max_supply(mutator_ref: &MutatorRef, max_supply: u64) acquires ConcurrentSupply, FixedSupply { @@ -774,10 +782,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(collection_address).mint_events) == 1, 0); + assert!(vector::length(&event::emitted_events()) == 1, 0); decrement_supply(&collection, creator_address, option::some(cid), creator_address); assert!(count(collection) == option::some(0), 0); - assert!(event::counter(&borrow_global(collection_address).burn_events) == 1, 0); + assert!(vector::length(&event::emitted_events()) == 1, 0); } #[test(creator = @0x123)] @@ -792,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(collection_address).mint_events) == 1, 0); + assert!(vector::length(&event::emitted_events()) == 1, 0); decrement_supply(&collection, creator_address, option::some(cid), creator_address); assert!(count(collection) == option::some(0), 0); - assert!(event::counter(&borrow_global(collection_address).burn_events) == 1, 0); + assert!(vector::length(&event::emitted_events()) == 1, 0); } #[test(creator = @0x123)] diff --git a/aptos-move/framework/aptos-token-objects/sources/token.move b/aptos-move/framework/aptos-token-objects/sources/token.move index bee0a4a2e15b7..1128114036aa5 100644 --- a/aptos-move/framework/aptos-token-objects/sources/token.move +++ b/aptos-move/framework/aptos-token-objects/sources/token.move @@ -785,15 +785,16 @@ module aptos_token_objects::token { old_value: token.description, new_value: description }) + } else { + event::emit_event( + &mut token.mutation_events, + MutationEvent { + mutated_field_name: string::utf8(b"description"), + old_value: token.description, + new_value: description + }, + ); }; - event::emit_event( - &mut token.mutation_events, - MutationEvent { - mutated_field_name: string::utf8(b"description"), - old_value: token.description, - new_value: description - }, - ); token.description = description; } @@ -820,15 +821,16 @@ module aptos_token_objects::token { old_value: old_name, new_value: name }) + } else { + event::emit_event( + &mut token.mutation_events, + MutationEvent { + mutated_field_name: string::utf8(b"name"), + old_value: old_name, + new_value: name + }, + ); }; - event::emit_event( - &mut token.mutation_events, - MutationEvent { - mutated_field_name: string::utf8(b"name"), - old_value: old_name, - new_value: name - }, - ); } public fun set_uri(mutator_ref: &MutatorRef, uri: String) acquires Token { @@ -841,15 +843,16 @@ module aptos_token_objects::token { old_value: token.uri, new_value: uri, }) + } else { + event::emit_event( + &mut token.mutation_events, + MutationEvent { + mutated_field_name: string::utf8(b"uri"), + old_value: token.uri, + new_value: uri, + }, + ); }; - event::emit_event( - &mut token.mutation_events, - MutationEvent { - mutated_field_name: string::utf8(b"uri"), - old_value: token.uri, - new_value: uri, - }, - ); token.uri = uri; } diff --git a/aptos-move/framework/aptos-token/doc/token.md b/aptos-move/framework/aptos-token/doc/token.md index af496bd937b73..e14e3e7d1161c 100644 --- a/aptos-move/framework/aptos-token/doc/token.md +++ b/aptos-move/framework/aptos-token/doc/token.md @@ -19,17 +19,23 @@ Checkout our developer doc on our token standard https://aptos.dev/standards - [Struct `CollectionData`](#0x3_token_CollectionData) - [Struct `WithdrawCapability`](#0x3_token_WithdrawCapability) - [Struct `DepositEvent`](#0x3_token_DepositEvent) +- [Struct `TokenDeposit`](#0x3_token_TokenDeposit) - [Struct `Deposit`](#0x3_token_Deposit) - [Struct `WithdrawEvent`](#0x3_token_WithdrawEvent) - [Struct `Withdraw`](#0x3_token_Withdraw) +- [Struct `TokenWithdraw`](#0x3_token_TokenWithdraw) - [Struct `CreateTokenDataEvent`](#0x3_token_CreateTokenDataEvent) - [Struct `CreateTokenData`](#0x3_token_CreateTokenData) +- [Struct `TokenDataCreation`](#0x3_token_TokenDataCreation) - [Struct `MintTokenEvent`](#0x3_token_MintTokenEvent) - [Struct `MintToken`](#0x3_token_MintToken) +- [Struct `Mint`](#0x3_token_Mint) - [Struct `BurnTokenEvent`](#0x3_token_BurnTokenEvent) - [Struct `BurnToken`](#0x3_token_BurnToken) +- [Struct `Burn`](#0x3_token_Burn) - [Struct `MutateTokenPropertyMapEvent`](#0x3_token_MutateTokenPropertyMapEvent) - [Struct `MutateTokenPropertyMap`](#0x3_token_MutateTokenPropertyMap) +- [Struct `MutatePropertyMap`](#0x3_token_MutatePropertyMap) - [Struct `CreateCollectionEvent`](#0x3_token_CreateCollectionEvent) - [Struct `CreateCollection`](#0x3_token_CreateCollection) - [Constants](#@Constants_0) @@ -768,6 +774,47 @@ Set of data sent to the event stream during a receive + + + + +## Struct `TokenDeposit` + +Set of data sent to the event stream during a receive + + +
#[event]
+struct TokenDeposit has drop, store
+
+ + + +
+Fields + + +
+
+account: address +
+
+ +
+
+id: token::TokenId +
+
+ +
+
+amount: u64 +
+
+ +
+
+ +
@@ -778,6 +825,7 @@ Set of data sent to the event stream during a receive
#[event]
+#[deprecated]
 struct Deposit has drop, store
 
@@ -847,6 +895,7 @@ Set of data sent to the event stream during a withdrawal
#[event]
+#[deprecated]
 struct Withdraw has drop, store
 
@@ -872,6 +921,47 @@ Set of data sent to the event stream during a withdrawal + + + + +## Struct `TokenWithdraw` + +Set of data sent to the event stream during a withdrawal + + +
#[event]
+struct TokenWithdraw has drop, store
+
+ + + +
+Fields + + +
+
+account: address +
+
+ +
+
+id: token::TokenId +
+
+ +
+
+amount: u64 +
+
+ +
+
+ +
@@ -975,6 +1065,7 @@ token creation event id of token created
#[event]
+#[deprecated]
 struct CreateTokenData has drop, store
 
@@ -1060,6 +1151,106 @@ token creation event id of token created + + + + +## Struct `TokenDataCreation` + + + +
#[event]
+struct TokenDataCreation has drop, store
+
+ + + +
+Fields + + +
+
+creator: address +
+
+ +
+
+id: token::TokenDataId +
+
+ +
+
+description: string::String +
+
+ +
+
+maximum: u64 +
+
+ +
+
+uri: string::String +
+
+ +
+
+royalty_payee_address: address +
+
+ +
+
+royalty_points_denominator: u64 +
+
+ +
+
+royalty_points_numerator: u64 +
+
+ +
+
+name: string::String +
+
+ +
+
+mutability_config: token::TokenMutabilityConfig +
+
+ +
+
+property_keys: vector<string::String> +
+
+ +
+
+property_values: vector<vector<u8>> +
+
+ +
+
+property_types: vector<string::String> +
+
+ +
+
+ +
@@ -1103,6 +1294,7 @@ mint token event. This event triggered when creator adds more supply to existing
#[event]
+#[deprecated]
 struct MintToken has drop, store
 
@@ -1128,6 +1320,46 @@ mint token event. This event triggered when creator adds more supply to existing + + + + +## Struct `Mint` + + + +
#[event]
+struct Mint has drop, store
+
+ + + +
+Fields + + +
+
+creator: address +
+
+ +
+
+id: token::TokenDataId +
+
+ +
+
+amount: u64 +
+
+ +
+
+ +
@@ -1170,6 +1402,7 @@ mint token event. This event triggered when creator adds more supply to existing
#[event]
+#[deprecated]
 struct BurnToken has drop, store
 
@@ -1195,6 +1428,46 @@ mint token event. This event triggered when creator adds more supply to existing + + + + +## Struct `Burn` + + + +
#[event]
+struct Burn has drop, store
+
+ + + +
+Fields + + +
+
+account: address +
+
+ +
+
+id: token::TokenId +
+
+ +
+
+amount: u64 +
+
+ +
+
+ +
@@ -1255,6 +1528,7 @@ mint token event. This event triggered when creator adds more supply to existing
#[event]
+#[deprecated]
 struct MutateTokenPropertyMap has drop, store
 
@@ -1298,6 +1572,64 @@ mint token event. This event triggered when creator adds more supply to existing + + + + +## Struct `MutatePropertyMap` + + + +
#[event]
+struct MutatePropertyMap has drop, store
+
+ + + +
+Fields + + +
+
+account: address +
+
+ +
+
+old_id: token::TokenId +
+
+ +
+
+new_id: token::TokenId +
+
+ +
+
+keys: vector<string::String> +
+
+ +
+
+values: vector<vector<u8>> +
+
+ +
+
+types: vector<string::String> +
+
+ +
+
+ +
@@ -2247,16 +2579,17 @@ The token is owned at address owner let burn_by_creator_flag = property_map::read_bool(&token_data.default_properties, &string::utf8(BURNABLE_BY_CREATOR)); assert!(burn_by_creator_flag, error::permission_denied(ECREATOR_CANNOT_BURN_TOKEN)); - // Burn the tokens. + // Burn the tokens. let Token { id: _, amount: burned_amount, token_properties: _ } = withdraw_with_event_internal(owner, token_id, amount); let token_store = borrow_global_mut<TokenStore>(owner); if (std::features::module_event_migration_enabled()) { - event::emit(BurnToken { id: token_id, amount: burned_amount }); + event::emit(Burn { account: owner, id: token_id, amount: burned_amount }); + } else { + event::emit_event<BurnTokenEvent>( + &mut token_store.burn_events, + BurnTokenEvent { id: token_id, amount: burned_amount } + ); }; - event::emit_event<BurnTokenEvent>( - &mut token_store.burn_events, - BurnTokenEvent { id: token_id, amount: burned_amount } - ); if (token_data.maximum > 0) { token_data.supply = token_data.supply - burned_amount; @@ -2336,16 +2669,17 @@ Burn a token by the token owner let burn_by_owner_flag = property_map::read_bool(&token_data.default_properties, &string::utf8(BURNABLE_BY_OWNER)); assert!(burn_by_owner_flag, error::permission_denied(EOWNER_CANNOT_BURN_TOKEN)); - // Burn the tokens. + // Burn the tokens. let Token { id: _, amount: burned_amount, token_properties: _ } = withdraw_token(owner, token_id, amount); let token_store = borrow_global_mut<TokenStore>(signer::address_of(owner)); if (std::features::module_event_migration_enabled()) { - event::emit(BurnToken { id: token_id, amount: burned_amount }); + event::emit(Burn { account: signer::address_of(owner), id: token_id, amount: burned_amount }); + } else { + event::emit_event<BurnTokenEvent>( + &mut token_store.burn_events, + BurnTokenEvent { id: token_id, amount: burned_amount } + ); }; - event::emit_event<BurnTokenEvent>( - &mut token_store.burn_events, - BurnTokenEvent { id: token_id, amount: burned_amount } - ); // Decrease the supply correspondingly by the amount of tokens burned. let token_data = table::borrow_mut( @@ -2737,24 +3071,26 @@ Mutate the token_properties of one token. direct_deposit(token_owner, new_token); update_token_property_internal(token_owner, new_token_id, keys, values, types); if (std::features::module_event_migration_enabled()) { - event::emit(MutateTokenPropertyMap { + event::emit(MutatePropertyMap { + account: token_owner, old_id: token_id, new_id: new_token_id, keys, values, types }); + } else { + event::emit_event<MutateTokenPropertyMapEvent>( + &mut borrow_global_mut<TokenStore>(token_owner).mutate_token_property_events, + MutateTokenPropertyMapEvent { + old_id: token_id, + new_id: new_token_id, + keys, + values, + types + }, + ); }; - event::emit_event<MutateTokenPropertyMapEvent>( - &mut borrow_global_mut<TokenStore>(token_owner).mutate_token_property_events, - MutateTokenPropertyMapEvent { - old_id: token_id, - new_id: new_token_id, - keys, - values, - types - }, - ); token_data.largest_property_version = cur_property_version; // burn the orignial property_version 0 token after mutation @@ -2764,24 +3100,26 @@ Mutate the token_properties of one token. // only 1 copy for the token with property verion bigger than 0 update_token_property_internal(token_owner, token_id, keys, values, types); if (std::features::module_event_migration_enabled()) { - event::emit(MutateTokenPropertyMap { + event::emit(MutatePropertyMap { + account: token_owner, old_id: token_id, new_id: token_id, keys, values, types }); + } else { + event::emit_event<MutateTokenPropertyMapEvent>( + &mut borrow_global_mut<TokenStore>(token_owner).mutate_token_property_events, + MutateTokenPropertyMapEvent { + old_id: token_id, + new_id: token_id, + keys, + values, + types + }, + ); }; - event::emit_event<MutateTokenPropertyMapEvent>( - &mut borrow_global_mut<TokenStore>(token_owner).mutate_token_property_events, - MutateTokenPropertyMapEvent { - old_id: token_id, - new_id: token_id, - keys, - values, - types - }, - ); token_id } } @@ -3277,17 +3615,18 @@ Create a new collection to hold tokens maximum, } ); + } else { + event::emit_event<CreateCollectionEvent>( + &mut collection_handle.create_collection_events, + CreateCollectionEvent { + creator: account_addr, + collection_name: name, + uri, + description, + maximum, + } + ); }; - event::emit_event<CreateCollectionEvent>( - &mut collection_handle.create_collection_events, - CreateCollectionEvent { - creator: account_addr, - collection_name: name, - uri, - description, - maximum, - } - ); } @@ -3436,7 +3775,8 @@ Create a new collection to hold tokens table::add(&mut collections.token_data, token_data_id, token_data); if (std::features::module_event_migration_enabled()) { event::emit( - CreateTokenData { + TokenDataCreation { + creator: account_addr, id: token_data_id, description, maximum, @@ -3451,25 +3791,26 @@ Create a new collection to hold tokens property_types, } ); + } else { + event::emit_event<CreateTokenDataEvent>( + &mut collections.create_token_data_events, + CreateTokenDataEvent { + id: token_data_id, + description, + maximum, + uri, + royalty_payee_address, + royalty_points_denominator, + royalty_points_numerator, + name, + mutability_config: token_mutate_config, + property_keys, + property_values, + property_types, + }, + ); }; - event::emit_event<CreateTokenDataEvent>( - &mut collections.create_token_data_events, - CreateTokenDataEvent { - id: token_data_id, - description, - maximum, - uri, - royalty_payee_address, - royalty_points_denominator, - royalty_points_numerator, - name, - mutability_config: token_mutate_config, - property_keys, - property_values, - property_types, - }, - ); token_data_id } @@ -3795,15 +4136,16 @@ return the TokenId for a given Token // we add more tokens with property_version 0 let token_id = create_token_id(token_data_id, 0); if (std::features::module_event_migration_enabled()) { - event::emit(MintToken { id: token_data_id, amount }) + event::emit(Mint { creator: creator_addr, id: token_data_id, amount }) + } else { + event::emit_event<MintTokenEvent>( + &mut borrow_global_mut<Collections>(creator_addr).mint_token_events, + MintTokenEvent { + id: token_data_id, + amount, + } + ); }; - event::emit_event<MintTokenEvent>( - &mut borrow_global_mut<Collections>(creator_addr).mint_token_events, - MintTokenEvent { - id: token_data_id, - amount, - } - ); deposit_token(account, Token { @@ -3862,15 +4204,16 @@ create tokens and directly deposite to receiver's address. The receiver should o let token_id = create_token_id(token_data_id, 0); if (std::features::module_event_migration_enabled()) { - event::emit(MintToken { id: token_data_id, amount }) + event::emit(Mint { creator: creator_addr, id: token_data_id, amount }) + } else { + event::emit_event<MintTokenEvent>( + &mut borrow_global_mut<Collections>(creator_addr).mint_token_events, + MintTokenEvent { + id: token_data_id, + amount, + } + ); }; - event::emit_event<MintTokenEvent>( - &mut borrow_global_mut<Collections>(creator_addr).mint_token_events, - MintTokenEvent { - id: token_data_id, - amount, - } - ); direct_deposit(receiver, Token { @@ -4750,12 +5093,14 @@ return if the collection maximum is mutable with collection mutability config let token_store = borrow_global_mut<TokenStore>(account_addr); if (std::features::module_event_migration_enabled()) { - event::emit(Withdraw { id, amount }) + event::emit(TokenWithdraw { account: account_addr, id, amount }) + } else { + event::emit_event<WithdrawEvent>( + &mut token_store.withdraw_events, + WithdrawEvent { id, amount } + ); }; - event::emit_event<WithdrawEvent>( - &mut token_store.withdraw_events, - WithdrawEvent { id, amount } - ); + let tokens = &mut borrow_global_mut<TokenStore>(account_addr).tokens; assert!( table::contains(tokens, id), @@ -4832,12 +5177,13 @@ Deposit the token balance into the recipients account and emit an event. let token_store = borrow_global_mut<TokenStore>(account_addr); if (std::features::module_event_migration_enabled()) { - event::emit(Deposit { id: token.id, amount: token.amount }); + event::emit(TokenDeposit { account: account_addr, id: token.id, amount: token.amount }); + } else { + event::emit_event<DepositEvent>( + &mut token_store.deposit_events, + DepositEvent { id: token.id, amount: token.amount }, + ); }; - event::emit_event<DepositEvent>( - &mut token_store.deposit_events, - DepositEvent { id: token.id, amount: token.amount }, - ); assert!( exists<TokenStore>(account_addr), diff --git a/aptos-move/framework/aptos-token/doc/token_event_store.md b/aptos-move/framework/aptos-token/doc/token_event_store.md index bc8bc9356b86d..f54e0f85b7344 100644 --- a/aptos-move/framework/aptos-token/doc/token_event_store.md +++ b/aptos-move/framework/aptos-token/doc/token_event_store.md @@ -1139,11 +1139,12 @@ Emit the collection uri mutation event new_uri, } ); + } else { + event::emit_event<CollectionUriMutateEvent>( + &mut token_event_store.collection_uri_mutate_events, + event, + ); }; - event::emit_event<CollectionUriMutateEvent>( - &mut token_event_store.collection_uri_mutate_events, - event, - ); } @@ -1185,11 +1186,12 @@ Emit the collection description mutation event new_description, } ); - }; - event::emit_event<CollectionDescriptionMutateEvent>( - &mut token_event_store.collection_description_mutate_events, - event, - ); + } else { + event::emit_event<CollectionDescriptionMutateEvent>( + &mut token_event_store.collection_description_mutate_events, + event, + ); + } } @@ -1231,11 +1233,12 @@ Emit the collection maximum mutation event new_maximum, } ); + } else { + event::emit_event<CollectionMaxiumMutateEvent>( + &mut token_event_store.collection_maximum_mutate_events, + event, + ); }; - event::emit_event<CollectionMaxiumMutateEvent>( - &mut token_event_store.collection_maximum_mutate_events, - event, - ); } @@ -1271,11 +1274,12 @@ Emit the direct opt-in event account_address: signer::address_of(account), opt_in, }); - }; - event::emit_event<OptInTransferEvent>( - &mut token_event_store.opt_in_events, - opt_in_event, - ); + } else { + event::emit_event<OptInTransferEvent>( + &mut token_event_store.opt_in_events, + opt_in_event, + ); + } } @@ -1327,11 +1331,12 @@ Emit URI mutation event old_uri, new_uri, }); + } else { + event::emit_event<UriMutationEvent>( + &mut token_event_store.uri_mutate_events, + event, + ); }; - event::emit_event<UriMutationEvent>( - &mut token_event_store.uri_mutate_events, - event, - ); } @@ -1386,11 +1391,12 @@ Emit tokendata property map mutation event old_values, new_values, }); + } else { + event::emit_event<DefaultPropertyMutateEvent>( + &mut token_event_store.default_property_mutate_events, + event, + ); }; - event::emit_event<DefaultPropertyMutateEvent>( - &mut token_event_store.default_property_mutate_events, - event, - ); } @@ -1442,11 +1448,12 @@ Emit description mutation event old_description, new_description, }); + } else { + event::emit_event<DescriptionMutateEvent>( + &mut token_event_store.description_mutate_events, + event, + ); }; - event::emit_event<DescriptionMutateEvent>( - &mut token_event_store.description_mutate_events, - event, - ); } @@ -1509,11 +1516,12 @@ Emit royalty mutation event new_royalty_denominator, new_royalty_payee_addr, }); + } else { + event::emit_event<RoyaltyMutateEvent>( + &mut token_event_store.royalty_mutate_events, + event, + ); }; - event::emit_event<RoyaltyMutateEvent>( - &mut token_event_store.royalty_mutate_events, - event, - ); } @@ -1565,11 +1573,12 @@ Emit maximum mutation event old_maximum, new_maximum, }); + } else { + event::emit_event<MaxiumMutateEvent>( + &mut token_event_store.maximum_mutate_events, + event, + ); }; - event::emit_event<MaxiumMutateEvent>( - &mut token_event_store.maximum_mutate_events, - event, - ); } diff --git a/aptos-move/framework/aptos-token/doc/token_transfers.md b/aptos-move/framework/aptos-token/doc/token_transfers.md index 960c9e0ce2094..10de76f61a861 100644 --- a/aptos-move/framework/aptos-token/doc/token_transfers.md +++ b/aptos-move/framework/aptos-token/doc/token_transfers.md @@ -9,10 +9,13 @@ This module provides the foundation for transferring of Tokens - [Resource `PendingClaims`](#0x3_token_transfers_PendingClaims) - [Struct `TokenOfferId`](#0x3_token_transfers_TokenOfferId) - [Struct `TokenOffer`](#0x3_token_transfers_TokenOffer) -- [Struct `TokenOfferEvent`](#0x3_token_transfers_TokenOfferEvent) +- [Struct `Offer`](#0x3_token_transfers_Offer) - [Struct `TokenCancelOfferEvent`](#0x3_token_transfers_TokenCancelOfferEvent) -- [Struct `TokenCancelOffer`](#0x3_token_transfers_TokenCancelOffer) +- [Struct `CancelOffer`](#0x3_token_transfers_CancelOffer) - [Struct `TokenClaimEvent`](#0x3_token_transfers_TokenClaimEvent) +- [Struct `Claim`](#0x3_token_transfers_Claim) +- [Struct `TokenOfferEvent`](#0x3_token_transfers_TokenOfferEvent) +- [Struct `TokenCancelOffer`](#0x3_token_transfers_TokenCancelOffer) - [Struct `TokenClaim`](#0x3_token_transfers_TokenClaim) - [Constants](#@Constants_0) - [Function `initialize_token_transfers`](#0x3_token_transfers_initialize_token_transfers) @@ -165,14 +168,14 @@ This module provides the foundation for transferring of Tokens - + -## Struct `TokenOfferEvent` +## Struct `Offer`
#[event]
-struct TokenOfferEvent has drop, store
+struct Offer has drop, store
 
@@ -183,6 +186,12 @@ This module provides the foundation for transferring of Tokens
+account: address +
+
+ +
+
to_address: address
@@ -245,14 +254,14 @@ This module provides the foundation for transferring of Tokens - + -## Struct `TokenCancelOffer` +## Struct `CancelOffer`
#[event]
-struct TokenCancelOffer has drop, store
+struct CancelOffer has drop, store
 
@@ -263,6 +272,12 @@ This module provides the foundation for transferring of Tokens
+account: address +
+
+ +
+
to_address: address
@@ -297,6 +312,134 @@ This module provides the foundation for transferring of Tokens +
+Fields + + +
+
+to_address: address +
+
+ +
+
+token_id: token::TokenId +
+
+ +
+
+amount: u64 +
+
+ +
+
+ + +
+ + + +## Struct `Claim` + + + +
#[event]
+struct Claim has drop, store
+
+ + + +
+Fields + + +
+
+account: address +
+
+ +
+
+to_address: address +
+
+ +
+
+token_id: token::TokenId +
+
+ +
+
+amount: u64 +
+
+ +
+
+ + +
+ + + +## Struct `TokenOfferEvent` + + + +
#[event]
+#[deprecated]
+struct TokenOfferEvent has drop, store
+
+ + + +
+Fields + + +
+
+to_address: address +
+
+ +
+
+token_id: token::TokenId +
+
+ +
+
+amount: u64 +
+
+ +
+
+ + +
+ + + +## Struct `TokenCancelOffer` + + + +
#[event]
+#[deprecated]
+struct TokenCancelOffer has drop, store
+
+ + +
Fields @@ -332,6 +475,7 @@ This module provides the foundation for transferring of Tokens
#[event]
+#[deprecated]
 struct TokenClaim has drop, store
 
@@ -511,21 +655,23 @@ Token offer doesn't exist if (std::features::module_event_migration_enabled()) { event::emit( - TokenOffer { + Offer { + account: sender_addr, to_address: receiver, token_id, amount, } ) - }; - event::emit_event<TokenOfferEvent>( - &mut borrow_global_mut<PendingClaims>(sender_addr).offer_events, - TokenOfferEvent { - to_address: receiver, - token_id, - amount, - }, - ); + } else { + event::emit_event<TokenOfferEvent>( + &mut borrow_global_mut<PendingClaims>(sender_addr).offer_events, + TokenOfferEvent { + to_address: receiver, + token_id, + amount, + }, + ); + } } @@ -596,21 +742,23 @@ Token offer doesn't exist if (std::features::module_event_migration_enabled()) { event::emit( - TokenClaim { + Claim { + account: sender, to_address: signer::address_of(receiver), token_id, amount, } ) + } else { + event::emit_event<TokenClaimEvent>( + &mut borrow_global_mut<PendingClaims>(sender).claim_events, + TokenClaimEvent { + to_address: signer::address_of(receiver), + token_id, + amount, + }, + ); }; - event::emit_event<TokenClaimEvent>( - &mut borrow_global_mut<PendingClaims>(sender).claim_events, - TokenClaimEvent { - to_address: signer::address_of(receiver), - token_id, - amount, - }, - ); } @@ -681,21 +829,23 @@ Token offer doesn't exist if (std::features::module_event_migration_enabled()) { event::emit( - TokenCancelOffer { + CancelOffer { + account: sender_addr, to_address: receiver, token_id, amount, }, ) - }; - event::emit_event<TokenCancelOfferEvent>( - &mut borrow_global_mut<PendingClaims>(sender_addr).cancel_offer_events, - TokenCancelOfferEvent { - to_address: receiver, - token_id, - amount, - }, - ); + } else { + event::emit_event<TokenCancelOfferEvent>( + &mut borrow_global_mut<PendingClaims>(sender_addr).cancel_offer_events, + TokenCancelOfferEvent { + to_address: receiver, + token_id, + amount, + }, + ); + } } @@ -714,6 +864,30 @@ Token offer doesn't exist +Get the amount from sender token + + + + + +
fun spce_get(
+   account_addr: address,
+   id: TokenId,
+   amount: u64
+): u64 {
+   use aptos_token::token::{TokenStore};
+   use aptos_std::table::{Self};
+   let tokens = global<TokenStore>(account_addr).tokens;
+   let balance = table::spec_get(tokens, id).amount;
+   if (balance > amount) {
+       amount
+   } else {
+       table::spec_get(tokens, id).amount
+   }
+}
+
+ + @@ -810,30 +984,6 @@ Abort according to the code -Get the amount from sender token - - - - - -
fun spce_get(
-   account_addr: address,
-   id: TokenId,
-   amount: u64
-): u64 {
-   use aptos_token::token::{TokenStore};
-   use aptos_std::table::{Self};
-   let tokens = global<TokenStore>(account_addr).tokens;
-   let balance = table::spec_get(tokens, id).amount;
-   if (balance > amount) {
-       amount
-   } else {
-       table::spec_get(tokens, id).amount
-   }
-}
-
- - diff --git a/aptos-move/framework/aptos-token/sources/token.move b/aptos-move/framework/aptos-token/sources/token.move index d11f69a379351..3a3122f1bc6c3 100644 --- a/aptos-move/framework/aptos-token/sources/token.move +++ b/aptos-move/framework/aptos-token/sources/token.move @@ -289,6 +289,15 @@ module aptos_token::token { amount: u64, } + #[event] + /// Set of data sent to the event stream during a receive + struct TokenDeposit has drop, store { + account: address, + id: TokenId, + amount: u64, + } + + #[deprecated] #[event] /// Set of data sent to the event stream during a receive struct Deposit has drop, store { @@ -302,6 +311,7 @@ module aptos_token::token { amount: u64, } + #[deprecated] #[event] /// Set of data sent to the event stream during a withdrawal struct Withdraw has drop, store { @@ -309,6 +319,14 @@ module aptos_token::token { amount: u64, } + #[event] + /// Set of data sent to the event stream during a withdrawal + struct TokenWithdraw has drop, store { + account: address, + id: TokenId, + amount: u64, + } + /// token creation event id of token created struct CreateTokenDataEvent has drop, store { id: TokenDataId, @@ -325,6 +343,7 @@ module aptos_token::token { property_types: vector, } + #[deprecated] #[event] struct CreateTokenData has drop, store { id: TokenDataId, @@ -341,30 +360,64 @@ module aptos_token::token { property_types: vector, } + #[event] + struct TokenDataCreation has drop, store { + creator: address, + id: TokenDataId, + description: String, + maximum: u64, + uri: String, + royalty_payee_address: address, + royalty_points_denominator: u64, + royalty_points_numerator: u64, + name: String, + mutability_config: TokenMutabilityConfig, + property_keys: vector, + property_values: vector>, + property_types: vector, + } + /// mint token event. This event triggered when creator adds more supply to existing token struct MintTokenEvent has drop, store { id: TokenDataId, amount: u64, } + #[deprecated] #[event] struct MintToken has drop, store { id: TokenDataId, amount: u64, } + #[event] + struct Mint has drop, store { + creator: address, + id: TokenDataId, + amount: u64, + } + /// struct BurnTokenEvent has drop, store { id: TokenId, amount: u64, } + #[deprecated] #[event] struct BurnToken has drop, store { id: TokenId, amount: u64, } + #[event] + struct Burn has drop, store { + account: address, + id: TokenId, + amount: u64, + } + + /// struct MutateTokenPropertyMapEvent has drop, store { old_id: TokenId, @@ -374,6 +427,7 @@ module aptos_token::token { types: vector, } + #[deprecated] #[event] struct MutateTokenPropertyMap has drop, store { old_id: TokenId, @@ -383,6 +437,16 @@ module aptos_token::token { types: vector, } + #[event] + struct MutatePropertyMap has drop, store { + account: address, + old_id: TokenId, + new_id: TokenId, + keys: vector, + values: vector>, + types: vector, + } + /// create collection event with creator address and collection name struct CreateCollectionEvent has drop, store { creator: address, @@ -600,12 +664,13 @@ module aptos_token::token { let Token { id: _, amount: burned_amount, token_properties: _ } = withdraw_with_event_internal(owner, token_id, amount); let token_store = borrow_global_mut(owner); if (std::features::module_event_migration_enabled()) { - event::emit(BurnToken { id: token_id, amount: burned_amount }); + event::emit(Burn { account: owner, id: token_id, amount: burned_amount }); + } else { + event::emit_event( + &mut token_store.burn_events, + BurnTokenEvent { id: token_id, amount: burned_amount } + ); }; - event::emit_event( - &mut token_store.burn_events, - BurnTokenEvent { id: token_id, amount: burned_amount } - ); if (token_data.maximum > 0) { token_data.supply = token_data.supply - burned_amount; @@ -669,12 +734,13 @@ module aptos_token::token { let Token { id: _, amount: burned_amount, token_properties: _ } = withdraw_token(owner, token_id, amount); let token_store = borrow_global_mut(signer::address_of(owner)); if (std::features::module_event_migration_enabled()) { - event::emit(BurnToken { id: token_id, amount: burned_amount }); + event::emit(Burn { account: signer::address_of(owner), id: token_id, amount: burned_amount }); + } else { + event::emit_event( + &mut token_store.burn_events, + BurnTokenEvent { id: token_id, amount: burned_amount } + ); }; - event::emit_event( - &mut token_store.burn_events, - BurnTokenEvent { id: token_id, amount: burned_amount } - ); // Decrease the supply correspondingly by the amount of tokens burned. let token_data = table::borrow_mut( @@ -892,24 +958,26 @@ module aptos_token::token { direct_deposit(token_owner, new_token); update_token_property_internal(token_owner, new_token_id, keys, values, types); if (std::features::module_event_migration_enabled()) { - event::emit(MutateTokenPropertyMap { + event::emit(MutatePropertyMap { + account: token_owner, old_id: token_id, new_id: new_token_id, keys, values, types }); + } else { + event::emit_event( + &mut borrow_global_mut(token_owner).mutate_token_property_events, + MutateTokenPropertyMapEvent { + old_id: token_id, + new_id: new_token_id, + keys, + values, + types + }, + ); }; - event::emit_event( - &mut borrow_global_mut(token_owner).mutate_token_property_events, - MutateTokenPropertyMapEvent { - old_id: token_id, - new_id: new_token_id, - keys, - values, - types - }, - ); token_data.largest_property_version = cur_property_version; // burn the orignial property_version 0 token after mutation @@ -919,24 +987,26 @@ module aptos_token::token { // only 1 copy for the token with property verion bigger than 0 update_token_property_internal(token_owner, token_id, keys, values, types); if (std::features::module_event_migration_enabled()) { - event::emit(MutateTokenPropertyMap { + event::emit(MutatePropertyMap { + account: token_owner, old_id: token_id, new_id: token_id, keys, values, types }); + } else { + event::emit_event( + &mut borrow_global_mut(token_owner).mutate_token_property_events, + MutateTokenPropertyMapEvent { + old_id: token_id, + new_id: token_id, + keys, + values, + types + }, + ); }; - event::emit_event( - &mut borrow_global_mut(token_owner).mutate_token_property_events, - MutateTokenPropertyMapEvent { - old_id: token_id, - new_id: token_id, - keys, - values, - types - }, - ); token_id } } @@ -1153,17 +1223,18 @@ module aptos_token::token { maximum, } ); + } else { + event::emit_event( + &mut collection_handle.create_collection_events, + CreateCollectionEvent { + creator: account_addr, + collection_name: name, + uri, + description, + maximum, + } + ); }; - event::emit_event( - &mut collection_handle.create_collection_events, - CreateCollectionEvent { - creator: account_addr, - collection_name: name, - uri, - description, - maximum, - } - ); } public fun check_collection_exists(creator: address, name: String): bool acquires Collections { @@ -1252,7 +1323,8 @@ module aptos_token::token { table::add(&mut collections.token_data, token_data_id, token_data); if (std::features::module_event_migration_enabled()) { event::emit( - CreateTokenData { + TokenDataCreation { + creator: account_addr, id: token_data_id, description, maximum, @@ -1267,25 +1339,26 @@ module aptos_token::token { property_types, } ); + } else { + event::emit_event( + &mut collections.create_token_data_events, + CreateTokenDataEvent { + id: token_data_id, + description, + maximum, + uri, + royalty_payee_address, + royalty_points_denominator, + royalty_points_numerator, + name, + mutability_config: token_mutate_config, + property_keys, + property_values, + property_types, + }, + ); }; - event::emit_event( - &mut collections.create_token_data_events, - CreateTokenDataEvent { - id: token_data_id, - description, - maximum, - uri, - royalty_payee_address, - royalty_points_denominator, - royalty_points_numerator, - name, - mutability_config: token_mutate_config, - property_keys, - property_values, - property_types, - }, - ); token_data_id } @@ -1391,15 +1464,16 @@ module aptos_token::token { // we add more tokens with property_version 0 let token_id = create_token_id(token_data_id, 0); if (std::features::module_event_migration_enabled()) { - event::emit(MintToken { id: token_data_id, amount }) + event::emit(Mint { creator: creator_addr, id: token_data_id, amount }) + } else { + event::emit_event( + &mut borrow_global_mut(creator_addr).mint_token_events, + MintTokenEvent { + id: token_data_id, + amount, + } + ); }; - event::emit_event( - &mut borrow_global_mut(creator_addr).mint_token_events, - MintTokenEvent { - id: token_data_id, - amount, - } - ); deposit_token(account, Token { @@ -1438,15 +1512,16 @@ module aptos_token::token { let token_id = create_token_id(token_data_id, 0); if (std::features::module_event_migration_enabled()) { - event::emit(MintToken { id: token_data_id, amount }) + event::emit(Mint { creator: creator_addr, id: token_data_id, amount }) + } else { + event::emit_event( + &mut borrow_global_mut(creator_addr).mint_token_events, + MintTokenEvent { + id: token_data_id, + amount, + } + ); }; - event::emit_event( - &mut borrow_global_mut(creator_addr).mint_token_events, - MintTokenEvent { - id: token_data_id, - amount, - } - ); direct_deposit(receiver, Token { @@ -1708,12 +1783,14 @@ module aptos_token::token { let token_store = borrow_global_mut(account_addr); if (std::features::module_event_migration_enabled()) { - event::emit(Withdraw { id, amount }) + event::emit(TokenWithdraw { account: account_addr, id, amount }) + } else { + event::emit_event( + &mut token_store.withdraw_events, + WithdrawEvent { id, amount } + ); }; - event::emit_event( - &mut token_store.withdraw_events, - WithdrawEvent { id, amount } - ); + let tokens = &mut borrow_global_mut(account_addr).tokens; assert!( table::contains(tokens, id), @@ -1750,12 +1827,13 @@ module aptos_token::token { let token_store = borrow_global_mut(account_addr); if (std::features::module_event_migration_enabled()) { - event::emit(Deposit { id: token.id, amount: token.amount }); + event::emit(TokenDeposit { account: account_addr, id: token.id, amount: token.amount }); + } else { + event::emit_event( + &mut token_store.deposit_events, + DepositEvent { id: token.id, amount: token.amount }, + ); }; - event::emit_event( - &mut token_store.deposit_events, - DepositEvent { id: token.id, amount: token.amount }, - ); assert!( exists(account_addr), @@ -1985,7 +2063,12 @@ module aptos_token::token { vector[false, false, false, false, false], ); let collections = borrow_global(signer::address_of(&creator)); - assert!(event::counter(&collections.create_collection_events) == 1, 1); + assert!( + vector::length(&event::emitted_events()) == 1 || vector::length( + &event::emitted_events() + ) == 1, + 1 + ); } #[test(creator = @0xAF)] diff --git a/aptos-move/framework/aptos-token/sources/token_event_store.move b/aptos-move/framework/aptos-token/sources/token_event_store.move index 0171e9cb9f88f..a114f955e0746 100644 --- a/aptos-move/framework/aptos-token/sources/token_event_store.move +++ b/aptos-move/framework/aptos-token/sources/token_event_store.move @@ -248,11 +248,12 @@ module aptos_token::token_event_store { new_uri, } ); + } else { + event::emit_event( + &mut token_event_store.collection_uri_mutate_events, + event, + ); }; - event::emit_event( - &mut token_event_store.collection_uri_mutate_events, - event, - ); } /// Emit the collection description mutation event @@ -274,11 +275,12 @@ module aptos_token::token_event_store { new_description, } ); - }; - event::emit_event( - &mut token_event_store.collection_description_mutate_events, - event, - ); + } else { + event::emit_event( + &mut token_event_store.collection_description_mutate_events, + event, + ); + } } /// Emit the collection maximum mutation event @@ -300,11 +302,12 @@ module aptos_token::token_event_store { new_maximum, } ); + } else { + event::emit_event( + &mut token_event_store.collection_maximum_mutate_events, + event, + ); }; - event::emit_event( - &mut token_event_store.collection_maximum_mutate_events, - event, - ); } /// Emit the direct opt-in event @@ -320,11 +323,12 @@ module aptos_token::token_event_store { account_address: signer::address_of(account), opt_in, }); - }; - event::emit_event( - &mut token_event_store.opt_in_events, - opt_in_event, - ); + } else { + event::emit_event( + &mut token_event_store.opt_in_events, + opt_in_event, + ); + } } /// Emit URI mutation event @@ -356,11 +360,12 @@ module aptos_token::token_event_store { old_uri, new_uri, }); + } else { + event::emit_event( + &mut token_event_store.uri_mutate_events, + event, + ); }; - event::emit_event( - &mut token_event_store.uri_mutate_events, - event, - ); } /// Emit tokendata property map mutation event @@ -395,11 +400,12 @@ module aptos_token::token_event_store { old_values, new_values, }); + } else { + event::emit_event( + &mut token_event_store.default_property_mutate_events, + event, + ); }; - event::emit_event( - &mut token_event_store.default_property_mutate_events, - event, - ); } /// Emit description mutation event @@ -431,11 +437,12 @@ module aptos_token::token_event_store { old_description, new_description, }); + } else { + event::emit_event( + &mut token_event_store.description_mutate_events, + event, + ); }; - event::emit_event( - &mut token_event_store.description_mutate_events, - event, - ); } /// Emit royalty mutation event @@ -478,11 +485,12 @@ module aptos_token::token_event_store { new_royalty_denominator, new_royalty_payee_addr, }); + } else { + event::emit_event( + &mut token_event_store.royalty_mutate_events, + event, + ); }; - event::emit_event( - &mut token_event_store.royalty_mutate_events, - event, - ); } /// Emit maximum mutation event @@ -514,10 +522,11 @@ module aptos_token::token_event_store { old_maximum, new_maximum, }); + } else { + event::emit_event( + &mut token_event_store.maximum_mutate_events, + event, + ); }; - event::emit_event( - &mut token_event_store.maximum_mutate_events, - event, - ); } } diff --git a/aptos-move/framework/aptos-token/sources/token_transfers.move b/aptos-move/framework/aptos-token/sources/token_transfers.move index 6a8ec33b5ae2b..5dc8a6d54434d 100644 --- a/aptos-move/framework/aptos-token/sources/token_transfers.move +++ b/aptos-move/framework/aptos-token/sources/token_transfers.move @@ -36,7 +36,8 @@ module aptos_token::token_transfers { } #[event] - struct TokenOfferEvent has drop, store { + struct Offer has drop, store { + account: address, to_address: address, token_id: TokenId, amount: u64, @@ -50,7 +51,8 @@ module aptos_token::token_transfers { } #[event] - struct TokenCancelOffer has drop, store { + struct CancelOffer has drop, store { + account: address, to_address: address, token_id: TokenId, amount: u64, @@ -64,7 +66,8 @@ module aptos_token::token_transfers { } #[event] - struct TokenClaim has drop, store { + struct Claim has drop, store { + account: address, to_address: address, token_id: TokenId, amount: u64, @@ -126,21 +129,23 @@ module aptos_token::token_transfers { if (std::features::module_event_migration_enabled()) { event::emit( - TokenOffer { + Offer { + account: sender_addr, to_address: receiver, token_id, amount, } ) - }; - event::emit_event( - &mut borrow_global_mut(sender_addr).offer_events, - TokenOfferEvent { - to_address: receiver, - token_id, - amount, - }, - ); + } else { + event::emit_event( + &mut borrow_global_mut(sender_addr).offer_events, + TokenOfferEvent { + to_address: receiver, + token_id, + amount, + }, + ); + } } public entry fun claim_script( @@ -171,21 +176,23 @@ module aptos_token::token_transfers { if (std::features::module_event_migration_enabled()) { event::emit( - TokenClaim { + Claim { + account: sender, to_address: signer::address_of(receiver), token_id, amount, } ) + } else { + event::emit_event( + &mut borrow_global_mut(sender).claim_events, + TokenClaimEvent { + to_address: signer::address_of(receiver), + token_id, + amount, + }, + ); }; - event::emit_event( - &mut borrow_global_mut(sender).claim_events, - TokenClaimEvent { - to_address: signer::address_of(receiver), - token_id, - amount, - }, - ); } public entry fun cancel_offer_script( @@ -217,21 +224,23 @@ module aptos_token::token_transfers { if (std::features::module_event_migration_enabled()) { event::emit( - TokenCancelOffer { + CancelOffer { + account: sender_addr, to_address: receiver, token_id, amount, }, ) - }; - event::emit_event( - &mut borrow_global_mut(sender_addr).cancel_offer_events, - TokenCancelOfferEvent { - to_address: receiver, - token_id, - amount, - }, - ); + } else { + event::emit_event( + &mut borrow_global_mut(sender_addr).cancel_offer_events, + TokenCancelOfferEvent { + to_address: receiver, + token_id, + amount, + }, + ); + } } #[test(creator = @0x1, owner = @0x2)] @@ -324,4 +333,29 @@ module aptos_token::token_transfers { 0 ) } + + #[deprecated] + #[event] + struct TokenOfferEvent has drop, store { + to_address: address, + token_id: TokenId, + amount: u64, + } + + #[deprecated] + #[event] + struct TokenCancelOffer has drop, store { + to_address: address, + token_id: TokenId, + amount: u64, + } + + #[deprecated] + #[event] + struct TokenClaim has drop, store { + to_address: address, + token_id: TokenId, + amount: u64, + } + } diff --git a/crates/aptos-rosetta/src/types/objects.rs b/crates/aptos-rosetta/src/types/objects.rs index 1109fa900eb98..7cfceb3bd4c99 100644 --- a/crates/aptos-rosetta/src/types/objects.rs +++ b/crates/aptos-rosetta/src/types/objects.rs @@ -31,7 +31,7 @@ use aptos_types::{ account_address::AccountAddress, account_config::{ fungible_store::FungibleStoreResource, AccountResource, CoinStoreResourceUntyped, - WithdrawEvent, + CoinWithdraw, WithdrawEvent, }, contract_event::{ContractEvent, ContractEventV2, FEE_STATEMENT_EVENT_TYPE}, event::EventKey, @@ -63,6 +63,11 @@ static WITHDRAW_TYPE_TAG: Lazy = static DEPOSIT_TYPE_TAG: Lazy = Lazy::new(|| parse_type_tag("0x1::fungible_asset::Deposit").unwrap()); +static COIN_WITHDRAW_TYPE_TAG: Lazy = + Lazy::new(|| parse_type_tag("0x1::coin::CoinWithdraw").unwrap()); +static COIN_DEPOSIT_TYPE_TAG: Lazy = + Lazy::new(|| parse_type_tag("0x1::coin::CoinDeposit").unwrap()); + /// A description of all types used by the Rosetta implementation. /// /// This is used to verify correctness of the implementation and to check things like @@ -1370,6 +1375,7 @@ async fn parse_operations_from_write_set( if let Some(currency) = maybe_currency { parse_coinstore_changes( currency.clone(), + type_tag.to_string(), version, address, data, @@ -2000,6 +2006,7 @@ async fn parse_delegation_pool_resource_changes( /// Parses coin store direct changes, for withdraws and deposits fn parse_coinstore_changes( currency: Currency, + coin_type: String, version: u64, address: AccountAddress, data: &[u8], @@ -2018,10 +2025,14 @@ fn parse_coinstore_changes( let mut operations = vec![]; - // TODO: Handle Event V2 here for migration from Event V1 - // Skip if there is no currency that can be found - let withdraw_amounts = get_amount_from_event(events, coin_store.withdraw_events().key()); + let mut withdraw_amounts = get_amount_from_event(events, coin_store.withdraw_events().key()); + withdraw_amounts.append(&mut get_amount_from_event_v2( + events, + &COIN_WITHDRAW_TYPE_TAG, + address, + &coin_type, + )); for amount in withdraw_amounts { operations.push(Operation::withdraw( operation_index, @@ -2033,7 +2044,13 @@ fn parse_coinstore_changes( operation_index += 1; } - let deposit_amounts = get_amount_from_event(events, coin_store.deposit_events().key()); + let mut deposit_amounts = get_amount_from_event(events, coin_store.deposit_events().key()); + deposit_amounts.append(&mut get_amount_from_event_v2( + events, + &COIN_DEPOSIT_TYPE_TAG, + address, + &coin_type, + )); for amount in deposit_amounts { operations.push(Operation::deposit( operation_index, @@ -2150,6 +2167,27 @@ fn get_amount_from_event(events: &[ContractEvent], event_key: &EventKey) -> Vec< }) } +fn get_amount_from_event_v2( + events: &[ContractEvent], + type_tag: &TypeTag, + account_address: AccountAddress, + coin_type: &String, +) -> Vec { + filter_v2_events(type_tag, events, |event| { + if let Ok(event) = bcs::from_bytes::(event.event_data()) { + if event.account == account_address && &event.coin_type == coin_type { + Some(event.amount) + } else { + None + } + } else { + // If we can't parse the withdraw event, then there's nothing + warn!("Failed to parse fungible store event! Skipping"); + None + } + }) +} + /// Pulls the balance change from a withdraw or deposit event fn get_amount_from_fa_event( events: &[ContractEvent], diff --git a/execution/executor-test-helpers/src/integration_test_impl.rs b/execution/executor-test-helpers/src/integration_test_impl.rs index 1d01b688de1ef..885c8be4e8a11 100644 --- a/execution/executor-test-helpers/src/integration_test_impl.rs +++ b/execution/executor-test-helpers/src/integration_test_impl.rs @@ -17,13 +17,12 @@ use aptos_sdk::{ }; use aptos_storage_interface::{ state_view::{DbStateViewAtVersion, VerifiedStateViewAtVersion}, - DbReaderWriter, Order, + DbReaderWriter, }; use aptos_types::{ account_config::{aptos_test_root_address, AccountResource, CoinStoreResource}, block_metadata::BlockMetadata, chain_id::ChainId, - event::EventKey, ledger_info::LedgerInfo, state_store::{MoveResourceExt, StateView}, test_helpers::transaction_test_helpers::{block, TEST_BLOCK_EXECUTOR_ONCHAIN_CONFIG}, @@ -234,7 +233,7 @@ pub fn test_execution_with_storage_impl_inner( .unwrap(); verify_committed_txn_status(latest_li, &t8, &block1[7]).unwrap(); // We requested the events to come back from this one, so verify that they did - assert_eq!(t8.events.unwrap().len(), 5); + assert_eq!(t8.events.unwrap().len(), 3); let t9 = db .reader @@ -285,98 +284,12 @@ pub fn test_execution_with_storage_impl_inner( // With sharding enabled, we won't have indices for event, skip the checks. if !force_sharding { - let account1_sent_events = db - .reader - .get_events( - &account1.sent_event_key(), - 0, - Order::Ascending, - 10, - current_version, - ) - .unwrap(); - assert_eq!(account1_sent_events.len(), 2); - - let account2_sent_events = db - .reader - .get_events( - &account2.sent_event_key(), - 0, - Order::Ascending, - 10, - current_version, - ) - .unwrap(); - assert_eq!(account2_sent_events.len(), 1); - - let account3_sent_events = db - .reader - .get_events( - &account3.sent_event_key(), - 0, - Order::Ascending, - 10, - current_version, - ) - .unwrap(); - assert_eq!(account3_sent_events.len(), 0); - - let account1_received_events = db - .reader - .get_events( - &account1.received_event_key(), - 0, - Order::Ascending, - 10, - current_version, - ) - .unwrap(); - // Account1 has one deposit event since AptosCoin was minted to it. - assert_eq!(account1_received_events.len(), 1); - - let account2_received_events = db - .reader - .get_events( - &account2.received_event_key(), - 0, - Order::Ascending, - 10, - current_version, - ) - .unwrap(); - // Account2 has two deposit events: from being minted to and from one transfer. - assert_eq!(account2_received_events.len(), 2); - - let account3_received_events = db - .reader - .get_events( - &account3.received_event_key(), - 0, - Order::Ascending, - 10, - current_version, - ) - .unwrap(); - // Account3 has three deposit events: from being minted to and from two transfers. - assert_eq!(account3_received_events.len(), 3); let view = db .reader .verified_state_view_at_version(Some(current_version), latest_li) .unwrap(); let account4_resource = AccountResource::fetch_move_resource(&view, &addr4).unwrap(); assert!(account4_resource.is_none()); - - let account4_sent_events = db - .reader - .get_events( - &account4.sent_event_key(), - 0, - Order::Ascending, - 10, - current_version, - ) - .unwrap(); - assert!(account4_sent_events.is_empty()); } // Execute block 2, 3, 4 @@ -454,74 +367,6 @@ pub fn test_execution_with_storage_impl_inner( let expected_txns: Vec = block3.iter().map(|t| t.expect_valid().clone()).collect(); verify_transactions(&transaction_list_with_proof, &expected_txns).unwrap(); - // With sharding enabled, we won't have indices for event, skip the checks. - if !force_sharding { - let account1_sent_events_batch1 = db - .reader - .get_events( - &EventKey::new(3, account1.address()), - 0, - Order::Ascending, - 10, - current_version, - ) - .unwrap(); - assert_eq!(account1_sent_events_batch1.len(), 10); - - let account1_sent_events_batch2 = db - .reader - .get_events( - &EventKey::new(3, account1.address()), - 10, - Order::Ascending, - 10, - current_version, - ) - .unwrap(); - assert_eq!(account1_sent_events_batch2.len(), 6); - - let account3_received_events_batch1 = db - .reader - .get_events( - &EventKey::new(2, account3.address()), - u64::MAX, - Order::Descending, - 10, - current_version, - ) - .unwrap(); - assert_eq!(account3_received_events_batch1.len(), 10); - // Account3 has one extra deposit event from being minted to. - assert_eq!( - account3_received_events_batch1[0] - .event - .v1() - .unwrap() - .sequence_number(), - 16 - ); - - let account3_received_events_batch2 = db - .reader - .get_events( - &EventKey::new(2, account3.address()), - 6, - Order::Descending, - 10, - current_version, - ) - .unwrap(); - assert_eq!(account3_received_events_batch2.len(), 7); - assert_eq!( - account3_received_events_batch2[0] - .event - .v1() - .unwrap() - .sequence_number(), - 6 - ); - } - aptos_db } diff --git a/execution/executor-types/Cargo.toml b/execution/executor-types/Cargo.toml index b27f6f09efbdc..9a449959bd01a 100644 --- a/execution/executor-types/Cargo.toml +++ b/execution/executor-types/Cargo.toml @@ -24,7 +24,6 @@ bcs = { workspace = true } criterion = { workspace = true } derive_more = { workspace = true } itertools = { workspace = true } -once_cell = { workspace = true } serde = { workspace = true } thiserror = { workspace = true } diff --git a/execution/executor-types/src/lib.rs b/execution/executor-types/src/lib.rs index 7f40557d14a90..8d5bf3cb8c1eb 100644 --- a/execution/executor-types/src/lib.rs +++ b/execution/executor-types/src/lib.rs @@ -8,7 +8,7 @@ use anyhow::Result; use aptos_crypto::HashValue; use aptos_scratchpad::{ProofRead, SparseMerkleTree}; use aptos_types::{ - account_config::NEW_EPOCH_EVENT_MOVE_TYPE_TAG, + account_config::{NEW_EPOCH_EVENT_MOVE_TYPE_TAG, NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG}, block_executor::{config::BlockExecutorConfigFromOnchain, partitioner::ExecutableBlock}, contract_event::ContractEvent, dkg::DKG_START_EVENT_MOVE_TYPE_TAG, @@ -294,6 +294,7 @@ pub fn should_forward_to_subscription_service(event: &ContractEvent) -> bool { type_tag == OBSERVED_JWK_UPDATED_MOVE_TYPE_TAG.deref() || type_tag == DKG_START_EVENT_MOVE_TYPE_TAG.deref() || type_tag == NEW_EPOCH_EVENT_MOVE_TYPE_TAG.deref() + || type_tag == NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG.deref() } #[cfg(feature = "bench")] diff --git a/execution/executor-types/src/parsed_transaction_output.rs b/execution/executor-types/src/parsed_transaction_output.rs index ddf81e5a2873f..ec1f9d3668c3e 100644 --- a/execution/executor-types/src/parsed_transaction_output.rs +++ b/execution/executor-types/src/parsed_transaction_output.rs @@ -3,8 +3,6 @@ use aptos_types::{ contract_event::ContractEvent, - event::EventKey, - on_chain_config, transaction::{ Transaction, TransactionAuxiliaryData, TransactionOutput, TransactionOutputProvider, TransactionStatus, @@ -12,11 +10,8 @@ use aptos_types::{ write_set::WriteSet, }; use itertools::zip_eq; -use once_cell::sync::Lazy; use std::ops::Deref; -pub static NEW_EPOCH_EVENT_KEY: Lazy = Lazy::new(on_chain_config::new_epoch_event_key); - #[derive(Clone)] pub struct ParsedTransactionOutput { output: TransactionOutput, @@ -25,9 +20,7 @@ pub struct ParsedTransactionOutput { impl ParsedTransactionOutput { pub fn parse_reconfig_events(events: &[ContractEvent]) -> impl Iterator { - events - .iter() - .filter(|e| e.event_key().cloned() == Some(*NEW_EPOCH_EVENT_KEY)) + events.iter().filter(|e| e.is_new_epoch_event()) } } diff --git a/execution/executor/src/tests/mock_vm/mod.rs b/execution/executor/src/tests/mock_vm/mod.rs index 552764e8f329e..b307a6029910c 100644 --- a/execution/executor/src/tests/mock_vm/mod.rs +++ b/execution/executor/src/tests/mock_vm/mod.rs @@ -15,6 +15,7 @@ use aptos_executor_types::execution_output::ExecutionOutput; use aptos_storage_interface::cached_state_view::CachedStateView; use aptos_types::{ account_address::AccountAddress, + account_config::NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG, block_executor::{ config::BlockExecutorConfigFromOnchain, partitioner::{ExecutableTransactions, PartitionedTransactions}, @@ -23,7 +24,7 @@ use aptos_types::{ chain_id::ChainId, contract_event::ContractEvent, event::EventKey, - on_chain_config::{new_epoch_event_key, ConfigurationResource, ValidatorSet}, + on_chain_config::{ConfigurationResource, ValidatorSet}, state_store::{state_key::StateKey, StateView}, transaction::{ signature_verified_transaction::SignatureVerifiedTransaction, BlockOutput, ChangeSet, @@ -115,10 +116,8 @@ impl VMExecutor for MockVM { // WriteSet cannot be empty so use genesis writeset only for testing. gen_genesis_writeset(), // mock the validator set event - vec![ContractEvent::new_v1( - new_epoch_event_key(), - 0, - TypeTag::Bool, + vec![ContractEvent::new_v2( + NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG.clone(), bcs::to_bytes(&0).unwrap(), )], 0, diff --git a/execution/executor/tests/db_bootstrapper_test.rs b/execution/executor/tests/db_bootstrapper_test.rs index 9aabe45843d26..ed3de49f3b499 100644 --- a/execution/executor/tests/db_bootstrapper_test.rs +++ b/execution/executor/tests/db_bootstrapper_test.rs @@ -21,6 +21,7 @@ use aptos_types::{ account_address::AccountAddress, account_config::{ aptos_test_root_address, new_block_event_key, CoinStoreResource, NewBlockEvent, + NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG, }, contract_event::ContractEvent, event::EventHandle, @@ -244,14 +245,7 @@ fn test_new_genesis() { .freeze() .unwrap(), vec![ - ContractEvent::new_v1( - *configuration.events().key(), - 0, - TypeTag::Struct(Box::new( - ::struct_tag(), - )), - vec![], - ), + ContractEvent::new_v2(NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG.clone(), vec![]), ContractEvent::new_v1( new_block_event_key(), 0, diff --git a/execution/executor/tests/internal_indexer_test.rs b/execution/executor/tests/internal_indexer_test.rs index ba6b004de55c9..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(), 27); + assert_eq!(res.len(), 4); let core_kv_iter = db_indexer .get_prefixed_state_value_iterator( diff --git a/state-sync/inter-component/event-notifications/src/tests.rs b/state-sync/inter-component/event-notifications/src/tests.rs index 3d66b026168cd..e145be54a60cc 100644 --- a/state-sync/inter-component/event-notifications/src/tests.rs +++ b/state-sync/inter-component/event-notifications/src/tests.rs @@ -14,6 +14,7 @@ use aptos_infallible::RwLock; use aptos_storage_interface::DbReaderWriter; use aptos_types::{ account_address::AccountAddress, + account_config::NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG, contract_event::ContractEvent, event::EventKey, on_chain_config, @@ -53,7 +54,7 @@ fn test_all_configs_returned() { // Notify the subscription service of 10 reconfiguration events and verify the // notifications contain all configs. - let reconfig_event = create_test_event(on_chain_config::new_epoch_event_key()); + let reconfig_event = create_test_reconfig_event(); for _ in 0..num_reconfigs { notify_events(&mut event_service, version, vec![reconfig_event.clone()]); verify_reconfig_notifications_received( @@ -74,7 +75,7 @@ fn test_reconfig_notification_no_queuing() { let mut listener_2 = event_service.subscribe_to_reconfigurations().unwrap(); // Notify the subscription service of 10 reconfiguration events - let reconfig_event = create_test_event(on_chain_config::new_epoch_event_key()); + let reconfig_event = create_test_reconfig_event(); let num_reconfigs = 10; for _ in 0..num_reconfigs { notify_events(&mut event_service, 0, vec![reconfig_event.clone()]); @@ -106,7 +107,6 @@ fn test_dynamic_subscribers() { // Create several event keys let event_key_1 = create_random_event_key(); - let reconfig_event_key = on_chain_config::new_epoch_event_key(); // Create a subscriber for event_key_1 and a reconfiguration subscriber let mut event_listener_1 = event_service @@ -121,11 +121,13 @@ fn test_dynamic_subscribers() { // Add another subscriber for event_key_1 and the reconfig_event_key let mut event_listener_2 = event_service - .subscribe_to_events(vec![event_key_1, reconfig_event_key], vec![]) + .subscribe_to_events(vec![event_key_1], vec![ + NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG.to_string() + ]) .unwrap(); // Notify the service of several events - let reconfig_event = create_test_event(reconfig_event_key); + let reconfig_event = create_test_reconfig_event(); notify_events(&mut event_service, 0, vec![ event_1.clone(), reconfig_event.clone(), @@ -159,7 +161,6 @@ fn test_event_and_reconfig_subscribers() { // Create several event keys let event_key_1 = create_random_event_key(); let event_key_2 = create_random_event_key(); - let reconfig_event_key = on_chain_config::new_epoch_event_key(); // Create subscribers for the various event keys let mut event_listener_1 = event_service @@ -169,7 +170,7 @@ fn test_event_and_reconfig_subscribers() { .subscribe_to_events(vec![event_key_1, event_key_2], vec![]) .unwrap(); let mut event_listener_3 = event_service - .subscribe_to_events(vec![reconfig_event_key], vec![]) + .subscribe_to_events(vec![], vec![NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG.to_string()]) .unwrap(); // Create reconfiguration subscribers @@ -190,7 +191,7 @@ fn test_event_and_reconfig_subscribers() { ]); // Notify the service of a reconfiguration event and verify correct notifications - let reconfig_event = create_test_event(reconfig_event_key); + let reconfig_event = create_test_reconfig_event(); notify_events(&mut event_service, 0, vec![reconfig_event.clone()]); verify_reconfig_notifications_received( vec![&mut reconfig_listener_1, &mut reconfig_listener_2], @@ -533,6 +534,13 @@ fn create_test_event(event_key: EventKey) -> ContractEvent { ContractEvent::new_v1(event_key, 0, TypeTag::Bool, bcs::to_bytes(&0).unwrap()) } +fn create_test_reconfig_event() -> ContractEvent { + ContractEvent::new_v2( + NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG.clone(), + bcs::to_bytes(&0).unwrap(), + ) +} + fn create_random_event_key() -> EventKey { EventKey::new(0, AccountAddress::random()) } diff --git a/state-sync/state-sync-driver/src/tests/driver.rs b/state-sync/state-sync-driver/src/tests/driver.rs index ea16b4e5c5820..938c8c0eb91ee 100644 --- a/state-sync/state-sync-driver/src/tests/driver.rs +++ b/state-sync/state-sync-driver/src/tests/driver.rs @@ -7,7 +7,8 @@ use crate::{ metadata_storage::PersistentMetadataStorage, notification_handlers::CommitNotification, tests::utils::{ - create_event, create_ledger_info_at_version, create_transaction, verify_commit_notification, + create_event, create_ledger_info_at_version, create_reconfig_event, create_transaction, + verify_commit_notification, }, }; use aptos_config::config::{NodeConfig, RoleType, StateSyncDriverConfig}; @@ -30,7 +31,6 @@ use aptos_storage_service_notifications::StorageServiceNotificationListener; use aptos_time_service::TimeService; use aptos_types::{ event::EventKey, - on_chain_config::new_epoch_event_key, transaction::{Transaction, WriteSetPayload}, waypoint::Waypoint, }; @@ -200,18 +200,18 @@ async fn test_reconfiguration_notifications() { // Wait for validator auto bootstrapping wait_for_auto_bootstrapping(validator_driver, time_service).await; + let reconfig_event = create_reconfig_event(); // Test different events - let reconfiguration_event = new_epoch_event_key(); - for event_key in [ - EventKey::random(), - reconfiguration_event, - EventKey::random(), - reconfiguration_event, + for event in [ + create_event(Some(EventKey::random())), + reconfig_event.clone(), + create_event(Some(EventKey::random())), + reconfig_event.clone(), ] { // Create commit data for testing let transactions = vec![create_transaction(), create_transaction()]; - let events = vec![create_event(Some(event_key))]; + let events = vec![event.clone()]; // Send a new consensus commit notification to the driver let committed_transactions = transactions.clone(); @@ -236,7 +236,7 @@ async fn test_reconfiguration_notifications() { .await; // Verify the reconfiguration listener is notified if a reconfiguration occurred - if event_key == reconfiguration_event { + if event == reconfig_event { let reconfig_notification = reconfig_listener.select_next_some().await; assert_eq!(reconfig_notification.version, 0); } else { diff --git a/state-sync/state-sync-driver/src/tests/utils.rs b/state-sync/state-sync-driver/src/tests/utils.rs index a9ca1460a0f25..e59e628430c8f 100644 --- a/state-sync/state-sync-driver/src/tests/utils.rs +++ b/state-sync/state-sync-driver/src/tests/utils.rs @@ -18,6 +18,7 @@ use aptos_storage_service_notifications::StorageServiceNotificationListener; use aptos_storage_service_types::responses::CompleteDataRange; use aptos_types::{ account_address::AccountAddress, + account_config::NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG, aggregate_signature::AggregateSignature, block_info::BlockInfo, chain_id::ChainId, @@ -82,6 +83,13 @@ pub fn create_event(event_key: Option) -> ContractEvent { ContractEvent::new_v1(event_key, 0, TypeTag::Bool, bcs::to_bytes(&0).unwrap()) } +pub fn create_reconfig_event() -> ContractEvent { + ContractEvent::new_v2( + NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG.clone(), + bcs::to_bytes(&0).unwrap(), + ) +} + /// Creates a test driver configuration for full nodes pub fn create_full_node_driver_configuration() -> DriverConfiguration { let config = StateSyncDriverConfig::default(); diff --git a/types/src/account_config/events/new_block.rs b/types/src/account_config/events/new_block.rs index 8e8de3b295a05..99303db4cb787 100644 --- a/types/src/account_config/events/new_block.rs +++ b/types/src/account_config/events/new_block.rs @@ -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. @@ -104,14 +103,6 @@ pub fn new_block_event_key() -> EventKey { EventKey::new(3, CORE_CODE_ADDRESS) } -/// The path to the new block event handle under a Block::BlockResource resource. -pub static NEW_BLOCK_EVENT_PATH: Lazy> = Lazy::new(|| { - let mut path = BlockResource::resource_path(); - // it can be anything as long as it's referenced in AccountState::get_event_handle_by_query_path - path.extend_from_slice(b"/new_block_event/"); - path -}); - /// Should be kept in-sync with BlockResource move struct in block.move. #[derive(Deserialize, Serialize)] pub struct BlockResource { diff --git a/types/src/account_config/events/new_epoch.rs b/types/src/account_config/events/new_epoch.rs index 413644e339db6..b9b422f3105c7 100644 --- a/types/src/account_config/events/new_epoch.rs +++ b/types/src/account_config/events/new_epoch.rs @@ -2,7 +2,7 @@ // Parts of the project are originally copyright © Meta Platforms, Inc. // SPDX-License-Identifier: Apache-2.0 -use crate::{contract_event::ContractEvent, event::EventKey, on_chain_config::new_epoch_event_key}; +use crate::event::EventKey; use anyhow::Result; use move_core_types::{ ident_str, identifier::IdentStr, language_storage::TypeTag, move_resource::MoveStructType, @@ -23,15 +23,6 @@ impl NewEpochEvent { Self { epoch: 0 } } - pub fn as_contract_event(&self, seq_num: u64) -> ContractEvent { - ContractEvent::new_v1( - new_epoch_event_key(), - seq_num, - TypeTag::from_str("0x1::reconfiguration::NewEpochEvent").unwrap(), - bcs::to_bytes(self).unwrap(), - ) - } - pub fn epoch(&self) -> u64 { self.epoch } @@ -52,3 +43,5 @@ impl MoveStructType for NewEpochEvent { pub static NEW_EPOCH_EVENT_MOVE_TYPE_TAG: Lazy = Lazy::new(|| TypeTag::Struct(Box::new(NewEpochEvent::struct_tag()))); +pub static NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG: Lazy = + Lazy::new(|| TypeTag::from_str("0x1::reconfiguration::NewEpoch").expect("Cannot fail")); diff --git a/types/src/account_config/events/withdraw.rs b/types/src/account_config/events/withdraw.rs index e2abceb8d83fa..da27bb19e7c02 100644 --- a/types/src/account_config/events/withdraw.rs +++ b/types/src/account_config/events/withdraw.rs @@ -2,7 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 use anyhow::Result; -use move_core_types::{ident_str, identifier::IdentStr, move_resource::MoveStructType}; +use move_core_types::{ + account_address::AccountAddress, ident_str, identifier::IdentStr, move_resource::MoveStructType, +}; use serde::{Deserialize, Serialize}; /// Struct that represents a SentPaymentEvent. @@ -26,3 +28,21 @@ impl MoveStructType for WithdrawEvent { const MODULE_NAME: &'static IdentStr = ident_str!("coin"); const STRUCT_NAME: &'static IdentStr = ident_str!("WithdrawEvent"); } + +#[derive(Debug, Serialize, Deserialize)] +pub struct CoinWithdraw { + pub coin_type: String, + pub account: AccountAddress, + pub amount: u64, +} + +impl CoinWithdraw { + pub fn try_from_bytes(bytes: &[u8]) -> Result { + bcs::from_bytes(bytes).map_err(Into::into) + } +} + +impl MoveStructType for CoinWithdraw { + const MODULE_NAME: &'static IdentStr = ident_str!("coin"); + const STRUCT_NAME: &'static IdentStr = ident_str!("CoinWithdraw"); +} diff --git a/types/src/contract_event.rs b/types/src/contract_event.rs index 59d9a27fae406..a89e3d88a9f26 100644 --- a/types/src/contract_event.rs +++ b/types/src/contract_event.rs @@ -3,11 +3,13 @@ // SPDX-License-Identifier: Apache-2.0 use crate::{ - account_config::{DepositEvent, NewBlockEvent, NewEpochEvent, WithdrawEvent}, + account_config::{ + DepositEvent, NewBlockEvent, NewEpochEvent, WithdrawEvent, NEW_EPOCH_EVENT_MOVE_TYPE_TAG, + NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG, + }, dkg::DKGStartEvent, event::EventKey, jwks::ObservedJWKsUpdated, - on_chain_config::new_epoch_event_key, transaction::Version, }; use anyhow::{bail, Error, Result}; @@ -21,7 +23,7 @@ use once_cell::sync::Lazy; #[cfg(any(test, feature = "fuzzing"))] use proptest_derive::Arbitrary; use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use std::{convert::TryFrom, str::FromStr}; +use std::{convert::TryFrom, ops::Deref, str::FromStr}; pub static FEE_STATEMENT_EVENT_TYPE: Lazy = Lazy::new(|| { TypeTag::Struct(Box::new(StructTag { @@ -156,10 +158,8 @@ impl ContractEvent { } pub fn is_new_epoch_event(&self) -> bool { - match self { - ContractEvent::V1(event) => *event.key() == new_epoch_event_key(), - ContractEvent::V2(_event) => false, - } + self.type_tag() == NEW_EPOCH_EVENT_MOVE_TYPE_TAG.deref() + || self.type_tag() == NEW_EPOCH_EVENT_V2_MOVE_TYPE_TAG.deref() } pub fn expect_new_block_event(&self) -> Result { @@ -288,17 +288,6 @@ impl TryFrom<&ContractEvent> for NewBlockEvent { } } -impl From<(u64, NewEpochEvent)> for ContractEvent { - fn from((seq_num, event): (u64, NewEpochEvent)) -> Self { - Self::new_v1( - new_epoch_event_key(), - seq_num, - TypeTag::from(NewEpochEvent::struct_tag()), - bcs::to_bytes(&event).unwrap(), - ) - } -} - impl TryFrom<&ContractEvent> for DKGStartEvent { type Error = Error; @@ -321,14 +310,10 @@ impl TryFrom<&ContractEvent> for NewEpochEvent { type Error = Error; fn try_from(event: &ContractEvent) -> Result { - match event { - ContractEvent::V1(event) => { - if event.type_tag != TypeTag::Struct(Box::new(Self::struct_tag())) { - bail!("Expected NewEpochEvent") - } - Self::try_from_bytes(&event.event_data) - }, - ContractEvent::V2(_) => bail!("This is a module event"), + if event.is_new_epoch_event() { + Self::try_from_bytes(event.event_data()) + } else { + bail!("Expected NewEpochEvent") } } } diff --git a/types/src/on_chain_config/mod.rs b/types/src/on_chain_config/mod.rs index 32692e9aec19a..d085c4745abe6 100644 --- a/types/src/on_chain_config/mod.rs +++ b/types/src/on_chain_config/mod.rs @@ -14,11 +14,11 @@ use move_core_types::{ account_address::AccountAddress, ident_str, identifier::{IdentStr, Identifier}, - language_storage::StructTag, + language_storage::{StructTag, TypeTag}, move_resource::{MoveResource, MoveStructType}, }; use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use std::{collections::HashMap, fmt, fmt::Debug, sync::Arc}; +use std::{collections::HashMap, fmt, fmt::Debug, str::FromStr, sync::Arc}; mod approved_execution_hashes; mod aptos_features; @@ -204,6 +204,10 @@ pub fn new_epoch_event_key() -> EventKey { EventKey::new(2, CORE_CODE_ADDRESS) } +pub fn new_epoch_event_type_tag() -> TypeTag { + TypeTag::from_str("0x1::reconfiguration::NewEpoch").expect("cannot fail") +} + pub fn access_path_for_config(config_id: ConfigID) -> anyhow::Result { let struct_tag = struct_tag_for_config(config_id); Ok(AccessPath::new(