Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aptos gas payer #8773

Merged
merged 19 commits into from
Jun 23, 2023
Merged

Aptos gas payer #8773

merged 19 commits into from
Jun 23, 2023

Conversation

gerben-stavenga
Copy link
Contributor

@gerben-stavenga gerben-stavenga commented Jun 21, 2023

Description

Implement alternate gas payer support to aptos-blockchain. This pr reuses the already existing multi-agent framework, as a separate gas payer "is" a special case of a multi-agent transaction. However the existing multi-agent framework requires
a entry function that takes all [sender, secondary_signer...] as the first parameters, a gas payer is typically not a parameter to an entry function, but just a signature to pay for the tx.

This PR uses the MSB (high bit) of the sequence number as a boolean to indicate a gas payer in case of a multi-agent tx.
If this is set the last entry in the list of secondary signer is the "gas payer" and does not participate as signer in the
tx parameters. This is safe as 64bits is large enough for the high bit never to be reached.

Test Plan

@gerben-stavenga gerben-stavenga marked this pull request as ready for review June 21, 2023 20:48
aptos-move/aptos-vm/src/aptos_vm.rs Show resolved Hide resolved
@@ -80,3 +81,74 @@ fn read_coin(h: &MoveHarness, account: &AccountAddress) -> u64 {
.unwrap()
.coin()
}

#[test]
fn test_two_to_two_transfer_gas_payer() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some more tests around cases such as:

  1. Feature flag is not enabled.
  2. Gas payer doesn't have enough gas
  3. Extra senders without gas payer bit set.
  4. etc. Any other edge cases? Let's be as thorough as possible here to make sure there are no unforeseen issues

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still missing some failure cases:

  1. Gas payer doesn't have sufficient balances.
  2. Invalid gas payer signature
  3. Etc.
    I'll leave it to you to determine what can be covered with unit vs move e2e tests. We'll also have a more concise integration test later in TS as well for a true e2e.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this code is just using multi-agent signing and reusing the epilogue. Most of these flows are tested by regular tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tests that cover (scripts/entry functions)/(no signer/single signer/multiple signers)/(gas bit/no-gas bit)(feature/no feature)

aptos-move/aptos-vm/src/aptos_vm_impl.rs Show resolved Hide resolved
Copy link
Contributor

@wrwg wrwg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me from the code perspective, wo/ understanding the design goals. More tests would be good.

aptos-move/aptos-vm/src/aptos_vm.rs Show resolved Hide resolved
Copy link
Contributor

@zekun000 zekun000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

aptos-move/aptos-vm/src/aptos_vm_impl.rs Show resolved Hide resolved
} else {
// Gas payer tx
let gas_payer = *txn_data.secondary_signers.last().ok_or_else(|| {
PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't use UNKNOWN_INVARIANT_VIOLATION_ERROR here as this case can happen if user sets the gas payer bit for a normal tx with no secondary signers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's invariant error, as we shouldn't even get to the epilogue if the gas payer account is missing. Was tempted to do unwrap but decided invariant error is better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a proper abort code in the multi_agent prologue to verify this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're being a bit strict and trying to avoid invariant violation as much as possible. cc @runtian-zhou regarding whether this is a legit case

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

✅ Forge suite compat success on aptos-node-v1.4.4 ==> cbcab072cd84a8e12f44beb937c96488e0f7abb8

Compatibility test results for aptos-node-v1.4.4 ==> cbcab072cd84a8e12f44beb937c96488e0f7abb8 (PR)
1. Check liveness of validators at old version: aptos-node-v1.4.4
compatibility::simple-validator-upgrade::liveness-check : committed: 7169 txn/s, latency: 4627 ms, (p50: 4500 ms, p90: 6800 ms, p99: 8400 ms), latency samples: 258100
2. Upgrading first Validator to new version: cbcab072cd84a8e12f44beb937c96488e0f7abb8
compatibility::simple-validator-upgrade::single-validator-upgrade : committed: 3691 txn/s, latency: 8629 ms, (p50: 9400 ms, p90: 11000 ms, p99: 11500 ms), latency samples: 147660
3. Upgrading rest of first batch to new version: cbcab072cd84a8e12f44beb937c96488e0f7abb8
compatibility::simple-validator-upgrade::half-validator-upgrade : committed: 4347 txn/s, latency: 7344 ms, (p50: 8200 ms, p90: 10300 ms, p99: 11000 ms), latency samples: 165220
4. upgrading second batch to new version: cbcab072cd84a8e12f44beb937c96488e0f7abb8
compatibility::simple-validator-upgrade::rest-validator-upgrade : committed: 6523 txn/s, latency: 4941 ms, (p50: 4900 ms, p90: 6900 ms, p99: 8100 ms), latency samples: 234840
5. check swarm health
Compatibility test for aptos-node-v1.4.4 ==> cbcab072cd84a8e12f44beb937c96488e0f7abb8 passed
Test Ok

@github-actions
Copy link
Contributor

✅ Forge suite land_blocking success on cbcab072cd84a8e12f44beb937c96488e0f7abb8

performance benchmark : committed: 5588 txn/s, submitted: 5589 txn/s, expired: 1 txn/s, latency: 7091 ms, (p50: 5100 ms, p90: 13200 ms, p99: 27400 ms), latency samples: 2386092
Max round gap was 1 [limit 4] at version 724436. Max no progress secs was 3.96412 [limit 10] at version 1514058.
Test Ok

@github-actions
Copy link
Contributor

✅ Forge suite framework_upgrade success on aptos-node-v1.4.4 ==> cbcab072cd84a8e12f44beb937c96488e0f7abb8

Compatibility test results for aptos-node-v1.4.4 ==> cbcab072cd84a8e12f44beb937c96488e0f7abb8 (PR)
Upgrade the nodes to version: cbcab072cd84a8e12f44beb937c96488e0f7abb8
framework_upgrade::framework-upgrade::full-framework-upgrade : committed: 3175 txn/s, latency: 7118 ms, (p50: 8000 ms, p90: 9500 ms, p99: 12000 ms), latency samples: 171500
5. check swarm health
Compatibility test for aptos-node-v1.4.4 ==> cbcab072cd84a8e12f44beb937c96488e0f7abb8 passed
Test Ok

@gerben-stavenga gerben-stavenga merged commit 6d4b495 into main Jun 23, 2023
@gerben-stavenga gerben-stavenga deleted the aptos-gas-payer branch June 23, 2023 21:19
xbtmatt pushed a commit to xbtmatt/aptos-core that referenced this pull request Jul 25, 2023
* initial commit

* Support gas payer

* Remove relics

* Fix

* Make verification know about gas payer bit

* update comments

* Remove merge conflict

* Give MSB a good name

* Reformat

* improve

* add comment

* Fix spec
xbtmatt pushed a commit to xbtmatt/aptos-core that referenced this pull request Jul 25, 2023
* initial commit

* Support gas payer

* Remove relics

* Fix

* Make verification know about gas payer bit

* update comments

* Remove merge conflict

* Give MSB a good name

* Reformat

* improve

* add comment

* Fix spec
gedigi pushed a commit that referenced this pull request Aug 2, 2023
* initial commit

* Support gas payer

* Remove relics

* Fix

* Make verification know about gas payer bit

* update comments

* Remove merge conflict

* Give MSB a good name

* Reformat

* improve

* add comment

* Fix spec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants