Skip to content

Commit

Permalink
[movevm] improve automatic creation of account for sponsored txn
Browse files Browse the repository at this point in the history
* If an account is created during sponsored transaction and the txn aborts.
* The transaction is now kept but aborted.
* The state associated with account creation is wiped and The account is no longer created.
* During epilogue, we then hit a invariant violation, because the sequence number for the account cannot be incremented.

This ensures that we create an account even on transaction failure in the epilogue:

* during validation, sponsored transactions on sequence number 0, must
  have sufficient gas to create an account
* if the transaction aborts, call create account and charge gas appropriately
  • Loading branch information
davidiw committed Dec 13, 2023
1 parent 243ceda commit f817de8
Show file tree
Hide file tree
Showing 10 changed files with 449 additions and 126 deletions.
7 changes: 5 additions & 2 deletions api/src/tests/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ async fn test_multi_agent_signed_transaction() {
async fn test_fee_payer_signed_transaction() {
let mut context = new_test_context(current_function_name!());
let account = context.gen_account();
let fee_payer = context.gen_account();
let fee_payer = context.create_account().await;
let factory = context.transaction_factory();
let mut root_account = context.root_account().await;

Expand Down Expand Up @@ -324,7 +324,10 @@ async fn test_fee_payer_signed_transaction() {
.sign_fee_payer_with_transaction_builder(
vec![],
&fee_payer,
factory.create_user_account(yet_another_account.public_key()),
factory
.create_user_account(yet_another_account.public_key())
.max_gas_amount(200_000)
.gas_unit_price(1),
)
.into_raw_transaction();
let another_txn = another_raw_txn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl From<FeatureFlag> for AptosFeatureFlag {
FeatureFlag::SaferMetadata => AptosFeatureFlag::SAFER_METADATA,
FeatureFlag::SingleSenderAuthenticator => AptosFeatureFlag::SINGLE_SENDER_AUTHENTICATOR,
FeatureFlag::SponsoredAutomaticAccountCreation => {
AptosFeatureFlag::SPONSORED_AUTOMATIC_ACCOUNT_CREATION
AptosFeatureFlag::SPONSORED_AUTOMATIC_ACCOUNT_V1_CREATION
},
FeatureFlag::FeePayerAccountOptional => AptosFeatureFlag::FEE_PAYER_ACCOUNT_OPTIONAL,
FeatureFlag::AggregatorV2DelayedFields => {
Expand Down Expand Up @@ -304,7 +304,7 @@ impl From<AptosFeatureFlag> for FeatureFlag {
AptosFeatureFlag::SAFER_RESOURCE_GROUPS => FeatureFlag::SaferResourceGroups,
AptosFeatureFlag::SAFER_METADATA => FeatureFlag::SaferMetadata,
AptosFeatureFlag::SINGLE_SENDER_AUTHENTICATOR => FeatureFlag::SingleSenderAuthenticator,
AptosFeatureFlag::SPONSORED_AUTOMATIC_ACCOUNT_CREATION => {
AptosFeatureFlag::SPONSORED_AUTOMATIC_ACCOUNT_V1_CREATION => {
FeatureFlag::SponsoredAutomaticAccountCreation
},
AptosFeatureFlag::FEE_PAYER_ACCOUNT_OPTIONAL => FeatureFlag::FeePayerAccountOptional,
Expand Down
Loading

0 comments on commit f817de8

Please sign in to comment.