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

fungible asset improvements for concurrent balance #15836

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

igor-aptos
Copy link
Contributor

  • add function to get fungible balance concurrently - as a snapshot. not providing for dispatchable, as there it cannot help anyways
  • add entry function to primary_fungible_store to upgrade to concurrent (and don't require any type args for it)
  • automatically convert gas payer into concurrent balance - as it is more likely it will be used concurrently than not.

Description

How Has This Been Tested?

Key Areas to Review

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Performance improvement
  • Refactoring
  • Dependency update
  • Documentation update
  • Tests

Which Components or Systems Does This Change Impact?

  • Validator Node
  • Full Node (API, Indexer, etc.)
  • Move/Aptos Virtual Machine
  • Aptos Framework
  • Aptos CLI/SDK
  • Developer Infrastructure
  • Move Compiler
  • Other (specify)

Checklist

  • I have read and followed the CONTRIBUTING doc
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I identified and added all stakeholders and component owners affected by this change as reviewers
  • I tested both happy and unhappy path of the functionality
  • I have made corresponding changes to the documentation

Copy link

trunk-io bot commented Jan 28, 2025

⏱️ 4h 10m total CI duration on this PR
Job Cumulative Duration Recent Runs
execution-performance / single-node-performance 3h 15m 🟥🟥🟥🟥
execution-performance / test-target-determinator 20m 🟩🟩🟩🟩
check-dynamic-deps 14m 🟩🟩🟩🟩🟩 (+1 more)
test-target-determinator 10m 🟩🟩
rust-cargo-deny 5m 🟩🟩🟩
semgrep/ci 3m 🟩🟩🟩🟩🟩 (+1 more)
general-lints 1m 🟩🟩🟩
file_change_determinator 45s 🟩🟩🟩🟩
file_change_determinator 29s 🟩🟩🟩
permission-check 17s 🟩🟩🟩🟩🟩 (+1 more)
permission-check 16s 🟩🟩🟩🟩🟩 (+1 more)
permission-check 9s 🟩🟩🟩
determine-docker-build-metadata 6s 🟩🟩🟩

🚨 1 job on the last run was significantly faster/slower than expected

Job Duration vs 7d avg Delta
execution-performance / single-node-performance 49m 21m +136%

settingsfeedbackdocs ⋅ learn more about trunk.io

Base automatically changed from igor/fix_gas_withdraw_event to main January 29, 2025 01:17
@igor-aptos igor-aptos force-pushed the igor/fungible_asset_improvement branch from a75a3a7 to 06546cf Compare January 31, 2025 16:54
@igor-aptos igor-aptos added CICD:run-execution-performance-test Run execution performance test CICD:run-execution-performance-full-test Run execution performance test (full version) labels Jan 31, 2025
@igor-aptos igor-aptos changed the title fungible asset improvements fungible asset improvements for concurrent balance Jan 31, 2025
///
/// Note: This function will abort on FAs with `derived_balance` hook set up.
/// Use `dispatchable_fungible_asset::balance` instead if you intend to work with those FAs.
public fun balance_snapshot<T: key>(store: Object<T>): AggregatorSnapshot<u64> acquires FungibleStore, ConcurrentFungibleBalance, DispatchFunctionStore {
Copy link
Contributor

Choose a reason for hiding this comment

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

why we need this function?

Copy link
Contributor

Choose a reason for hiding this comment

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

The existing balance function already takes a snapshot right?

Copy link
Contributor

Choose a reason for hiding this comment

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

So that it can be emitted to event?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

both balance and balance_snapshot will return the same value (irrespective of whether store is concurrent or not).

but if balance is concurrent, then balance_snapshot will not create a conflict - and callers can freely store it in another resource, or emit as an event, with keeping things parallel. In the future we will allow formulas to be applied to them as well.

Copy link
Contributor

@lightmark lightmark left a comment

Choose a reason for hiding this comment

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

lgtm

Comment on lines 570 to 574
transaction_fee::burn_fee(gas_payer, burn_amount);
transaction_fee::burn_fee(gas_payer, burn_amount, account_addr != gas_payer);
} else if (transaction_fee_amount < storage_fee_refunded) {
let mint_amount = storage_fee_refunded - transaction_fee_amount;
transaction_fee::mint_and_refund(gas_payer, mint_amount);
transaction_fee::mint_and_refund(gas_payer, mint_amount, account_addr != 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.

This would change any gas payer. So, it could change accounts that you don't necessarily want to change to concurrent.

This should be feature flagged.

Copy link
Contributor

@gregnazario gregnazario left a comment

Choose a reason for hiding this comment

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

I don't think there needs to be a snapshot function, does the existing view function not work? If so, it needs to be made to work normally. Asking people to figure out which view function to make is a bad experience.

Force migrating people to concurrent balance should be feature gated or opt in. I fear this will break more than we expect

Copy link
Contributor

@runtian-zhou runtian-zhou left a comment

Choose a reason for hiding this comment

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

In the current impl, we are automatically changing fee payer's account into a concurrent one right? From the fee payer account perspective I do share the same concern as Greg, yet I don't necessary see how a feature flag would change the situation here. However, I do think it's to the interest of everyone that gas fee payer should be using a concurrent balance store which could justify for the changes here.

@gregnazario
Copy link
Contributor

In the current impl, we are automatically changing fee payer's account into a concurrent one right? From the fee payer account perspective I do share the same concern as Greg, yet I don't necessary see how a feature flag would change the situation here. However, I do think it's to the interest of everyone that gas fee payer should be using a concurrent balance store which could justify for the changes here.

The purpose of the feature flag is control when it goes through, so it doesn't roll through with other changes, though it's not reversible.

@igor-aptos
Copy link
Contributor Author

should've given more context, sorry.

replied inline for balance_snapshot usecase - of storing it in a resource/emitting an event, while keeping usage parallel.

It is frameworks internal implementation detail which FungibleStore is concurrent and which is not - and it should be free to switch between them.
and all smart contracts, exchanges, etc should handle both the same - our documentation calls that out explicitly - https://aptos.dev/en/build/smart-contracts/fungible-asset#off-chain-migration

I can add a feature flag to decouple framework release, from this change - but let me know if there are concerns about the actual change - of defaulting users (here fee-payers) to ConcurrentFungibleStore. In the future, if we improve ResourceGroups performance, we might switch everyone to ConcurrentFungibleStore.

@igor-aptos igor-aptos force-pushed the igor/fungible_asset_improvement branch from af00b05 to c6dc8c9 Compare February 3, 2025 05:58
@lightmark
Copy link
Contributor

I think it is better to use an opt-out model. If concurrent is default for gas payer and there are some people who do not this, we need another flag indicating that in the same RG.

@igor-aptos
Copy link
Contributor Author

I've added the feature flag here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CICD:run-execution-performance-full-test Run execution performance test (full version) CICD:run-execution-performance-test Run execution performance test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants