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

[gas] introduce new mechanism to charge storage fees based on fixed APT prices & per-category gas/fee limits #6683

Merged
merged 2 commits into from
Feb 24, 2023

Conversation

vgao1996
Copy link
Contributor

@vgao1996 vgao1996 commented Feb 17, 2023

This makes a few additions to the gas metering system:

  1. This introduces a new mechanism to charge storage-related fees based on flat APT prices that doesn't fluctuate according to the gas fee market, which would eventually allow us to decouple the execution costs and the storage costs and lower the execution costs greatly.
  2. This adds a few per-category gas/fee limits, which would allow us to increase the total amount of gas allowed without necessarily resulting in long execution time.

Note that I'm still waiting for @msmouse to come up with the correct prices. Should also mention that it might look like we're double charging (intrinsic, write set gas for io v.s. storage fees) but that is not the case. Going forward, the former group will cover transient costs only, leaving the more permanent portion to the latter. We will adjust the gas parameters to make sure we make transactions significantly cheaper, NOT more expensive.

Some of the storage fees will be replaced by deposits in the future: #6514

},
},
),
),
events: [],
gas_used: 650,
gas_used: 50841,
Copy link
Contributor Author

@vgao1996 vgao1996 Feb 17, 2023

Choose a reason for hiding this comment

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

This is expected because we set the gas unit price to 1 in this test. Shall we change it to 100 so that it looks more similar to the range of numbers we had?

@vgao1996 vgao1996 changed the title [gas] introduce new machanism to charge for storage fees based on fixed APT costs [gas] introduce new machanism to charge storage fees based on fixed APT costs Feb 17, 2023
@vgao1996 vgao1996 changed the title [gas] introduce new machanism to charge storage fees based on fixed APT costs [gas] introduce new machanism to charge storage fees based on fixed APT prices Feb 17, 2023
);
let gas_consumed_internal = InternalGas::new(
if gas_consumed_internal > u64::MAX as u128 {
u64::MAX
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm.... shall we put in a error!()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless we put in some really crazy numbers in the gas schedule, this should not happen at all...

I can try to put in an error!, but I bet we'll run into some nasty cyclic dependency issues so I won't push it hard this time.

let mut fee = Fee::zero();
let mut new_slots = NumSlots::zero();

for (key, op) in ops {
Copy link
Contributor

Choose a reason for hiding this comment

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

This loop is fairly similar to calculate_write_set_gas(), can we combine them? -- let calculate_write_set_gas() return (io_gas, storage_fee) -- I think it's better that way because it'll be very obvious for what we charge both the io and the storage and for what we charge io only, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried. That didn't work well.

  1. charge_write_set_gas and charge_storage_fee use different contexts (StorageGas vs TransactionGasParameters), so combining them would require you to create a function that takes in both, which seems unnecessarily complicated.
  2. It would also make the versioning logic more messy.

types/src/contract_event.rs Show resolved Hide resolved
types/src/event.rs Show resolved Hide resolved
@msmouse
Copy link
Contributor

msmouse commented Feb 18, 2023

The storage fees will be replaced by deposits in the future: #6514

Not exactly :-P
The deletion refund will be on top of this: The storage_fee_per_slot_create fee will be collected to the global storage deposit and subject to refund, but other fees will still go with other parts of the gas and be burned or redistributed as we see proper.

@vgao1996
Copy link
Contributor Author

vgao1996 commented Feb 18, 2023

@msmouse man you are dead serious about this. I've updated the description to say that only some of the fees will be replaced by deposits.

@vgao1996 vgao1996 changed the title [gas] introduce new machanism to charge storage fees based on fixed APT prices [gas] introduce new machanism to charge storage fees based on fixed APT prices & per-category gas/fee limits Feb 21, 2023
@@ -265,7 +265,13 @@ impl AptosVM {
.finish(&mut (), gas_meter.change_set_configs())
.map_err(|e| e.into_vm_status())?;
// Charge gas for write set
gas_meter.charge_write_set_gas(user_txn_change_set_ext.write_set().iter())?;
gas_meter.charge_write_set_gas_for_io(user_txn_change_set_ext.write_set().iter())?;
gas_meter.charge_storage_fee(
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be gated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's gated inside charge_write_set_gas_for_io and charge_storage_fee.

self.charge(amount)?;

self.io_gas_used += amount;
if self.feature_version >= 7 && self.io_gas_used > self.gas_params.txn.max_io_gas {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this break upgradability of aptos-framework package? We already have to add a mechanism to bypass tx size limit. Now that there's an io gas limit, how much headroom do we have before we need to bypass that limit as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a great question but conceptually, I don't think this is going to break framework upgrades. Our goal here is to reduce transaction costs, not increasing them. Having separate limits for each individual limits will likely result in more transactions being allowed -- old transactions should be able to pass as long as we configure the new limits no stricter than the old one.

[
storage_fee_per_state_slot_create: FeePerSlot,
{ 7.. => "storage_fee_per_state_slot_create" },
50000,
Copy link
Contributor

Choose a reason for hiding this comment

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

How did you come up with these numbers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@msmouse has a doc that explains the logic.

Copy link
Contributor

Choose a reason for hiding this comment

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

This appears to be a significant change. How should we update our docs to reflect it? Please let me help. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@clay-aptos thank you so much for helping! We're still in the process of figuring out the actual value changes, but I anticipate the doc work to cover the following:

  1. Explaining the new system to our users, especially how the flat-APT prices are converted back to gas units to maintain compatibility
  2. Making it clear that this is part of the effort to reduce cost (certainly not increasing it)
  3. What would come in the future (deposits)

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding the release-notes tag so we consider highlighting this.

Copy link
Contributor

@movekevin movekevin left a comment

Choose a reason for hiding this comment

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

Can we do benchmarking here? I'd also suggest a replay/analysis of past testnet/mainnet txs to understand how many txs would hit these limit.

@vgao1996 vgao1996 force-pushed the storage-gas-fees branch 2 times, most recently from 5e459af to 6eb71e7 Compare February 22, 2023 20:02
@@ -104,7 +104,7 @@ crate::natives::define_gas_parameters_for_natives!(GasParameters, "aptos_framewo
[.code.request_publish.per_byte, "code.request_publish.per_byte", 2 * MUL],

// Note(Gas): These are storage operations so the values should not be multiplied.
[.event.write_to_event_store.base, "event.write_to_event_store.base", 500_000],
[.event.write_to_event_store.base, "event.write_to_event_store.base", 300_000],
Copy link
Contributor

Choose a reason for hiding this comment

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

is this intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is set according to Alden's doc. Although it should be clear that we still haven't finalized those values and they are subject to change

@@ -41,7 +41,7 @@ use std::{
use tokio::{runtime::Handle, task::JoinHandle, time};

// Max is 100k TPS for a full day.
const MAX_TXNS: u64 = 10_000_000_000;
const MAX_TXNS: u64 = 100_000_000;
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems unnecessary change after updating the MAX_GAS_AMOUNT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted.

Copy link
Contributor

@davidiw davidiw left a comment

Choose a reason for hiding this comment

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

can we do a quick cleanup of the numbers? so that we're roughly back at the same state we were before?

@@ -45,7 +53,7 @@ crate::params::define_gas_parameters!(
[
maximum_number_of_gas_units: Gas,
"maximum_number_of_gas_units",
2_000_000
200_000_000
Copy link
Contributor

Choose a reason for hiding this comment

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

why did we increase this? where is the maximum execution units? I thought we were focusing on max execution units and then max gas units would be the additional available for storage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, it looks like I forgot to replace this with MAX_GAS_AMOUNT, which is now gated by a cargo feature flag.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

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.

awesome work!

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@vgao1996 vgao1996 merged commit 0a2aba9 into aptos-labs:main Feb 24, 2023
@clay-aptos clay-aptos added the release-notes This tag indicates the associated change should be documented in the Aptos Release Notes. label Mar 1, 2023
@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

github-actions bot commented Mar 1, 2023

✅ Forge suite land_blocking success on efd350b507d4a690c6ee1c341dfc534ff5550a4e

performance benchmark with full nodes : 5932 TPS, 6681 ms latency, 13500 ms p99 latency,(!) expired 20 out of 2533140 txns
Test Ok

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2023

✅ Forge suite compat success on testnet_2d8b1b57553d869190f61df1aaf7f31a8fc19a7b ==> efd350b507d4a690c6ee1c341dfc534ff5550a4e

Compatibility test results for testnet_2d8b1b57553d869190f61df1aaf7f31a8fc19a7b ==> efd350b507d4a690c6ee1c341dfc534ff5550a4e (PR)
1. Check liveness of validators at old version: testnet_2d8b1b57553d869190f61df1aaf7f31a8fc19a7b
compatibility::simple-validator-upgrade::liveness-check : 7670 TPS, 5011 ms latency, 6700 ms p99 latency,no expired txns
2. Upgrading first Validator to new version: efd350b507d4a690c6ee1c341dfc534ff5550a4e
compatibility::simple-validator-upgrade::single-validator-upgrade : 4919 TPS, 8390 ms latency, 11800 ms p99 latency,no expired txns
3. Upgrading rest of first batch to new version: efd350b507d4a690c6ee1c341dfc534ff5550a4e
compatibility::simple-validator-upgrade::half-validator-upgrade : 4633 TPS, 8654 ms latency, 11800 ms p99 latency,no expired txns
4. upgrading second batch to new version: efd350b507d4a690c6ee1c341dfc534ff5550a4e
compatibility::simple-validator-upgrade::rest-validator-upgrade : 6886 TPS, 5638 ms latency, 9400 ms p99 latency,no expired txns
5. check swarm health
Compatibility test for testnet_2d8b1b57553d869190f61df1aaf7f31a8fc19a7b ==> efd350b507d4a690c6ee1c341dfc534ff5550a4e passed
Test Ok

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2023

❌ Forge suite framework_upgrade failure on cb4ba0a57c998c60cbab65af31a64875d2588ca5 ==> efd350b507d4a690c6ee1c341dfc534ff5550a4e

Forge test runner terminated:
Trailing Log Lines:
Compiling, may take a little while to download git dependencies...
FETCHING GIT DEPENDENCY https://github.com/aptos-labs/aptos-core.git
INCLUDING DEPENDENCY AptosFramework
INCLUDING DEPENDENCY AptosStdlib
INCLUDING DEPENDENCY MoveStdlib
BUILDING RunScript
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Loading or casting u16, u32, u256 integers not supported in bytecode version 5', /usr/local/cargo/git/checkouts/move-0639dd674f581c30/5fcfb4e/language/move-compiler/src/compiled_unit.rs:202:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
{"level":"INFO","source":{"package":"aptos_forge","file":"testsuite/forge/src/backend/k8s/cluster_helper.rs:281"},"thread_name":"main","hostname":"forge-framework-upgrade-pr-6683-1677696501-cb4ba0a57c998c60cbab","timestamp":"2023-03-01T19:08:56.845591Z","message":"Deleting namespace forge-framework-upgrade-pr-6683: Some(NamespaceStatus { phase: Some(\"Terminating\") })"}
{"level":"INFO","source":{"package":"aptos_forge","file":"testsuite/forge/src/backend/k8s/cluster_helper.rs:389"},"thread_name":"main","hostname":"forge-framework-upgrade-pr-6683-1677696501-cb4ba0a57c998c60cbab","timestamp":"2023-03-01T19:08:56.845615Z","message":"aptos-node resources for Forge removed in namespace: forge-framework-upgrade-pr-6683"}
Debugging output:
NAME                                    READY   STATUS      RESTARTS   AGE
aptos-node-0-validator-0                1/1     Running     0          10m
aptos-node-1-validator-0                1/1     Running     0          8m51s
aptos-node-2-validator-0                1/1     Running     0          7m1s
aptos-node-3-validator-0                1/1     Running     0          5m11s
aptos-node-4-validator-0                1/1     Running     0          3m20s
genesis-aptos-genesis-eforge108-nptp6   0/1     Completed   0          18m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CICD:run-e2e-tests when this label is present github actions will run all land-blocking e2e tests from the PR release-notes This tag indicates the associated change should be documented in the Aptos Release Notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants