Skip to content

Commit afe23cd

Browse files
authored
[errormap] Move error maps into bytecode metadata. (aptos-labs#3220)
This moves the error explanation map (that info which allows to display reasons like `ESOME_REASON` and the related comment on Move Abort) into the metadata section of the Move bytecode and let it be interpreted by the Aptos VM. This is necessary as when we upgrade the framework, the error map compiled into the binary becomes outdated. Also, this enables the same mechanism for user code. There is now an optional `AbortInfo` embedded into an `ExecutionStatus` which the VM populates from the metadata. The overhead this creates should be marginal, and the deserialized metadata is cached on VM level. A test in `e2e-move-tests/tests/error_map.rs` shows that it works. As a consequence, explicit representation of errors maps in package metadata or elsewhere is not longer needed and has been removed. Also the existing `error_explain` is not longer needed. This made the `sdk/aptos_transaction_builder` crate empty, and so I removed it. The crate served to re-export `cached-packages`, which let to some cascading changes. In general we should avoiding re-exports in our internal code base because it makes refactoring and reasoning about code harder. (It's ok to re-export for external APIs. If we need `aptos-transaction-builder` for this purpose we can re-introduce it, but it should not be used by our internal code.)
1 parent e86a127 commit afe23cd

File tree

77 files changed

+378
-286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+378
-286
lines changed

Diff for: Cargo.lock

+7-29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ members = [
8585
"network/peer-monitoring-service/server",
8686
"network/peer-monitoring-service/types",
8787
"sdk",
88-
"sdk/transaction-builder",
8988
"secure/net",
9089
"secure/push-metrics",
9190
"secure/storage",

Diff for: api/goldens/aptos_api__tests__state_test__test_get_account_module.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"bytecode": "0xa11ceb0b050000000a010004020410031446055a2f0789018202088b032006ab030a0ab503170ccc03ba020d8606080000000100020e000003060000040800000507000006000100000702030000080401000009050100000a060700000b060400000c080900000d000a00000e040700000f06030000100b070000110b04000012000c00011500040001060c01080102050301080301050205060800010608010103020608010608030101010800010608030002030708020467756964067369676e6572104372656174654361706162696c69747904475549440947656e657261746f7202494406637265617465096372656174655f69640b6372656174655f696d706c166372656174655f776974685f6361706162696c6974790c6372656174696f6e5f6e756d0f63726561746f725f616464726573730565715f69641567656e5f6372656174655f6361706162696c697479156765745f6e6578745f6372656174696f6e5f6e756d0269640f69645f6372656174696f6e5f6e756d1269645f63726561746f725f61646472657373117075626c6973685f67656e657261746f72046164647207636f756e7465720a616464726573735f6f6600000000000000000000000000000000000000000000000000000000000000010308000000000000000000020113050102010f080302020114030302020a031305000100010204120a00110d0c010a012902200308050d0b0006000000000000000012022d02050f0b00010b01110202010100000c040b010b0012030202000001020d120a002a020c020a021000140c010a01060100000000000000160b020f00150b010b00120312010203010001020c080a00290203050700270b00110202040100000c050b00100110021402050100000c050b00100110031402060100000c050b0010010b0121020701000004120a00110d0c010a012902200308050d0b0006000000000000000012022d02050f0b00010b011200020801000102070f0a00290220030505080600000000000000000c01050d0b002b021000140c010b0102090100000c040b00100114020a0100000c040b00100214020b0100000c040b00100314020c0100000c050b0006000000000000000012022d0202020001000300030100",
2+
"bytecode": "0xa11ceb0b050000000b010004020410031446055a2f0789018202088b032006ab030a10b50398010acd04170ce404ba020d9e07080000000100020e000003060000040800000507000006000100000702030000080401000009050100000a060700000b060400000c080900000d000a00000e040700000f06030000100b070000110b04000012000c00011500040001060c01080102050301080301050205060800010608010103020608010608030101010800010608030002030708020467756964067369676e6572104372656174654361706162696c69747904475549440947656e657261746f7202494406637265617465096372656174655f69640b6372656174655f696d706c166372656174655f776974685f6361706162696c6974790c6372656174696f6e5f6e756d0f63726561746f725f616464726573730565715f69641567656e5f6372656174655f6361706162696c697479156765745f6e6578745f6372656174696f6e5f6e756d0269640f69645f6372656174696f6e5f6e756d1269645f63726561746f725f61646472657373117075626c6973685f67656e657261746f72046164647207636f756e7465720a616464726573735f6f66000000000000000000000000000000000000000000000000000000000000000103080000000000000000126170746f733a3a6d657461646174615f763083010100000000000000001d45475549445f47454e455241544f525f4e4f545f5055424c49534845445b475549442067656e657261746f72206d757374206265207075626c6973686564206168656164206f66206669727374207573616765206f6620606372656174655f776974685f6361706162696c697479602066756e6374696f6e2e00020113050102010f080302020114030302020a031305000100010204120a00110d0c010a012902200308050d0b0006000000000000000012022d02050f0b00010b01110202010100000c040b010b0012030202000001020d120a002a020c020a021000140c010a01060100000000000000160b020f00150b010b00120312010203010001020c080a00290203050700270b00110202040100000c050b00100110021402050100000c050b00100110031402060100000c050b0010010b0121020701000004120a00110d0c010a012902200308050d0b0006000000000000000012022d02050f0b00010b011200020801000102070f0a00290220030505080600000000000000000c01050d0b002b021000140c010b0102090100000c040b00100114020a0100000c040b00100214020b0100000c040b00100314020c0100000c050b0006000000000000000012022d0202020001000300030100",
33
"abi": {
44
"address": "0x1",
55
"name": "guid",

Diff for: api/goldens/aptos_api__tests__transactions_test__test_get_transactions_output_user_transaction_with_entry_function_payload.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"data": {
5454
"type": "0x1::state_storage::StateStorageUsage",
5555
"data": {
56-
"bytes": "301027",
56+
"bytes": "295717",
5757
"epoch": "1",
5858
"items": "100"
5959
}

Diff for: api/types/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ aptos-config = { path = "../../config" }
2525
aptos-crypto = { path = "../../crates/aptos-crypto" }
2626
aptos-openapi = { path = "../../crates/aptos-openapi" }
2727
aptos-state-view = { path = "../../storage/state-view" }
28-
aptos-transaction-builder = { path = "../../sdk/transaction-builder" }
2928
aptos-types = { path = "../../types" }
3029
aptos-vm = { path = "../../aptos-move/aptos-vm" }
3130

Diff for: api/types/src/convert.rs

+9-20
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::{
1515
};
1616
use anyhow::{bail, ensure, format_err, Context as AnyhowContext, Result};
1717
use aptos_crypto::{hash::CryptoHash, HashValue};
18-
use aptos_transaction_builder::error_explain;
1918
use aptos_types::state_store::table::TableHandle;
2019
use aptos_types::{
2120
access_path::{AccessPath, Path},
@@ -678,23 +677,13 @@ impl<'a, R: MoveResolverExt + ?Sized> MoveConverter<'a, R> {
678677

679678
fn explain_vm_status(&self, status: &ExecutionStatus) -> String {
680679
match status {
681-
ExecutionStatus::MoveAbort { location, code} => match &location {
682-
AbortLocation::Module(module_id) => {
683-
let explanation = error_explain::get_explanation(module_id, *code);
684-
explanation
685-
.map(|ec| {
686-
// TODO(wrwg): category and reason where removed from Move apis,
687-
// instead we have only single code_name/description. Need to
688-
// verify whether error reporting in the api is still reasonable.
689-
format!(
690-
"Move abort by {}\n{}",
691-
ec.code_name,
692-
ec.code_description,
693-
)
694-
})
695-
.unwrap_or_else(|| {
696-
format!("Move abort: code {:#x} at {}", code, location)
697-
})
680+
ExecutionStatus::MoveAbort { location, code, info } => match &location {
681+
AbortLocation::Module(_) => {
682+
info.as_ref().map(|i| {
683+
format!("Move abort by {}\n{}", i.reason_name, i.description)
684+
}).unwrap_or_else(|| {
685+
format!("Move abort: code {:#x} at {}", code, location)
686+
})
698687
}
699688
AbortLocation::Script => format!("Move abort: code {:#x}", code),
700689
},
@@ -717,12 +706,12 @@ impl<'a, R: MoveResolverExt + ?Sized> MoveConverter<'a, R> {
717706
func_name, code_offset
718707
)
719708
}
720-
ExecutionStatus::MiscellaneousError( code ) => {
709+
ExecutionStatus::MiscellaneousError(code) => {
721710
code.map_or(
722711
"Move bytecode deserialization / verification failed, including entry function not found or invalid arguments".to_owned(),
723712
|e| format!(
724713
"Transaction Executed and Committed with Error {:#?}", e
725-
)
714+
),
726715
)
727716
}
728717
}

Diff for: aptos-move/aptos-transactional-test-harness/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ vm-genesis = { path = "../vm-genesis" }
3434
# Other Aptos dependencies
3535
aptos-crypto = { path = "../../crates/aptos-crypto" }
3636
aptos-state-view = { path = "../../storage/state-view" }
37-
aptos-transaction-builder = { path = "../../sdk/transaction-builder" }
3837
aptos-types = { path = "../../types", features = ["fuzzing"] }
3938
storage-interface = { path = "../../storage/storage-interface" }
4039

Diff for: aptos-move/aptos-transactional-test-harness/src/aptos_test_harness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ impl<'a> AptosTestAdapter<'a> {
501501
let txn = RawTransaction::new(
502502
aptos_test_root_address(),
503503
parameters.sequence_number,
504-
aptos_transaction_builder::aptos_stdlib::account_create_account(account_addr),
504+
cached_packages::aptos_stdlib::account_create_account(account_addr),
505505
parameters.max_gas_amount,
506506
parameters.gas_unit_price,
507507
parameters.expiration_timestamp_secs,
@@ -517,7 +517,7 @@ impl<'a> AptosTestAdapter<'a> {
517517
let txn = RawTransaction::new(
518518
aptos_test_root_address(),
519519
parameters.sequence_number + 1,
520-
aptos_transaction_builder::aptos_stdlib::aptos_coin_mint(account_addr, amount),
520+
cached_packages::aptos_stdlib::aptos_coin_mint(account_addr, amount),
521521
parameters.max_gas_amount,
522522
parameters.gas_unit_price,
523523
parameters.expiration_timestamp_secs,

Diff for: aptos-move/aptos-vm/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ anyhow = "1.0.57"
1414
aptos-crypto = { path = "../../crates/aptos-crypto" }
1515
aptos-crypto-derive = { path = "../../crates/aptos-crypto-derive" }
1616
bcs = "0.1.3"
17+
dashmap = "5.2.0"
1718
fail = "0.5.0"
1819
mirai-annotations = "1.12.0"
1920
num_cpus = "1.13.1"

Diff for: aptos-move/aptos-vm/src/aptos_vm.rs

+18
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use aptos_logger::prelude::*;
2929
use aptos_module_verifier::module_init::verify_module_init_function;
3030
use aptos_state_view::StateView;
3131
use aptos_types::account_config::new_block_event_key;
32+
use aptos_types::vm_status::AbortLocation;
3233
use aptos_types::{
3334
account_config,
3435
block_metadata::BlockMetadata,
@@ -168,8 +169,25 @@ impl AptosVM {
168169
log_context: &AdapterLogSchema,
169170
) -> (VMStatus, TransactionOutputExt) {
170171
let mut session = self.0.new_session(storage, SessionId::txn_meta(txn_data));
172+
// DNS HERE
171173
match TransactionStatus::from(error_code.clone()) {
172174
TransactionStatus::Keep(status) => {
175+
// Inject abort info if available.
176+
let status = match status {
177+
ExecutionStatus::MoveAbort {
178+
location: AbortLocation::Module(module),
179+
code,
180+
..
181+
} => {
182+
let info = self.0.extract_abort_info(&module, code);
183+
ExecutionStatus::MoveAbort {
184+
location: AbortLocation::Module(module),
185+
code,
186+
info,
187+
}
188+
}
189+
_ => status,
190+
};
173191
// The transaction should be charged for gas, so run the epilogue to do that.
174192
// This is running in a new session that drops any side effects from the
175193
// attempted transaction (e.g., spending funds that were needed to pay for gas),

0 commit comments

Comments
 (0)