-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[framework] Change docs about the usage of FA::transfer, change PFS balance function #14980
Conversation
⏱️ 4h 5m total CI duration on this PR
🚨 1 job on the last run was significantly faster/slower than expected
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Thanks for @tyshko5 @mpsc0x @matchv @meng-xu-cs @StErMi for the suggestions! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #14980 +/- ##
========================================
Coverage 60.0% 60.1%
========================================
Files 856 856
Lines 210625 211110 +485
========================================
+ Hits 126555 126962 +407
- Misses 84070 84148 +78 ☔ View full report in Codecov by Sentry. |
@@ -137,7 +137,7 @@ module aptos_framework::primary_fungible_store { | |||
#[view] | |||
public fun is_balance_at_least<T: key>(account: address, metadata: Object<T>, amount: u64): bool { | |||
if (primary_store_exists(account, metadata)) { | |||
fungible_asset::is_balance_at_least(primary_store(account, metadata), amount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changed the optimization @igor-aptos wrote.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be curious to see how much optimization it would change here? Seems like they should be the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does dispatchable balance means?
It sounds incompatible with concurrent balance (i.e. being able to do += , -= or >= on balance, without revealing balance itself).
Does that mean that any dispatchable asset cannot be made concurrent?
For assets that don't have registered dispatchable functions, we cannot be revealing balance (in order to keep concurrency), so we would need to have dispatchable_fungible_asset::is_derived_balance_at_least, and use fungible_asset::is_balance_at_least if no dispatchable functions are registered.
we should also confirm APT gas charging (as APT is guaranteed to be non-dispatchable) is still efficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @georgemitenkov , @gelash for thoughts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@runtian-zhou to clarify:
in fungible_asset.move
, is_balance_at_least
does:
aggregator_v2::is_at_least(&balance_resource.balance, amount)
and balance
does:
aggregator_v2::read(&balance_resource.balance)
aggregator_v2::is_at_least
is fully parallel. aggregator_v2::read
is fully sequential.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the code there I think we might not want to change this. I reverted the relevant lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, if you revert, does that mean that is_balance_at_least
does a wrong thing for dispatchable assets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
back to original question, what does "dispatchable_derived_balance" and "dispatchable_derived_supply" mean? is there an AIP with explanation of those functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There wasn't. That was mostly added as a feature request from our partners.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, the dispatchable token is_greater_than function won't be parallelizable because we didn't register the hook, so we have to use the balance function to read out the u64 first.
@@ -137,7 +137,7 @@ module aptos_framework::primary_fungible_store { | |||
#[view] | |||
public fun is_balance_at_least<T: key>(account: address, metadata: Object<T>, amount: u64): bool { | |||
if (primary_store_exists(account, metadata)) { | |||
fungible_asset::is_balance_at_least(primary_store(account, metadata), amount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @georgemitenkov , @gelash for thoughts
32005d1
to
dd0e76c
Compare
The tricky thing is the following: Assets can register a dispatchable function to derive the balance in a coin store. However, what should the pfs::balance show? IMHO the balance derivation is a helpful yet confusing feature because the user will see the raw value anyway from the indexer and onchain explorer, but if they query the dispatched derived balance they will get a different result. Right now the pfs::balance/is_balance_at_least always checks for the underlying balance rather than the derived balance. |
I would incline to keep the current semantics:
|
Chiming in here from a user / builder perspective: It is seriously confusing to see inconsistent behaviors when a Dispatchable Fungible Asset (DFA) is involved. To be specific:
This inconsistency is likely to cause confusion to users, wallets, DeFi protocol builders, etc, hurts potential composability of DeFi contracts, and such confusion and incompatibility will be bad for the ecosystem. IMHO, such inconsistency is always better to be resolved earlier than later. |
For withdraw/deposit, I don't really see a clean, safe path for us to get rid of the current constraints. This is mainly because of the following:
For the balance function, it is indeed very confusing. The overloaded balance is added just cuz we thought it could be an interesting use case and could be used to implement features like inflationary coins over time. With that said, the indexer will always show the underlying "balance" stored on chain which will align with what's shown in the |
Thanks for the clarification @runtian-zhou. I understand the background and complications. In fact, the comment from me above is NOT about fixing fungible_asset.move, but just to push for a fix on the inconsistency between 'withdraw' and 'balance'. |
dd0e76c
to
15a9cb8
Compare
Gas charging uses |
This looks good to me now. Two questions: should fungible_asset::balance abort if dispatchable hooks are registered? Will the changes in this PR break any existing code? they change the semantics of some of the functions - that users might have realized to not do the right thing - and then applied workarounds on top of them? specifically the PFS functions |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
4d6bea8
to
ebf98dc
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ Forge suite
|
✅ Forge suite
|
Description
The change also adds documentation notes to several functions in the
fungible_asset
module, indicating that they can be replaced by their dispatchable counterparts. Additionally, it updates thesimple_dispatchable_token
test module to include new balance and supply functions.Change the semantics for pfs::balance to invoke the derived balance function if that's registered.
How Has This Been Tested?
Added tests
Key Areas to Review
Gas, performance
Type of Change
Which Components or Systems Does This Change Impact?
Checklist