-
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
[FA] s/withdraw/gasburn/ event & s/deposit/gasrefunded/ event #15357
base: main
Are you sure you want to change the base?
Conversation
⏱️ 27m total CI duration on this PR
|
@@ -898,7 +899,7 @@ module aptos_framework::fungible_asset { | |||
amount: u64 | |||
) acquires FungibleStore, Supply, ConcurrentSupply, ConcurrentFungibleBalance { | |||
// ref metadata match is checked in burn() call | |||
burn(ref, withdraw_internal(object::object_address(&store), amount)); | |||
burn(ref, raw_withdraw_internal(object::object_address(&store), amount)); | |||
} | |||
|
|||
public(friend) fun address_burn_from( |
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.
I wanted to this irrespective, but since you are making it even more different - let's rename this to address_burn_from_for_gas
so it's clear this shouldn't be used anywhere else
@@ -1057,8 +1069,6 @@ module aptos_framework::fungible_asset { | |||
assert!(store.balance >= amount, error::invalid_argument(EINSUFFICIENT_BALANCE)); | |||
store.balance = store.balance - 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.
weren't folks complaining that there wasn't a Withdraw before? after migration now it is consistently to be always there?
also changing this after migration has started seems even more confusing? maybe we should create WithdrawForGas event and emit that one instead, so callers can choose what to do with it?
@movekevin 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.
Part of the reason I break so many tests is due to this new event.
I don't know who complained there was not a withdraw before.
cc @kent-white @gregnazario for your thoughts as well.
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.
It seems mint_and_refund also has a deposit event... I am not sure whether we should have this PR now.
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.
can the caller know when (or how much) of the gas fee has been paid by coin (as so has no event) vs fa (and so has this event).
If that cannot be distinguished, then users cannot appropriately adjust the balances. so we should try to address that, in the cleanest way possible
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.
coin gas fee is implicit. I think we can only know from FeeStatement
.
4760bba
to
ab06352
Compare
I create two events to presents gas burnt and gas refunded. |
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 @runtian-zhou for thoughts here, as you are changing these files for permissions as well
separation here also makes a permission checks more clearer - _for_gas methods have a different permission check (all the way in transaction_validation), and other methods have permission check here. And events here also then distinguish the permission needed, which is cool
cc @movekevin and @davidiw for thoughts on this, as this is pretty big change logically
@@ -265,7 +265,7 @@ module aptos_framework::aptos_account { | |||
// Skip burning if amount is zero. This shouldn't error out as it's called as part of transaction fee burning. |
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.
rename burn_from_fungible_store
to burn_from_fungible_store_for_gas
then
@@ -779,9 +779,12 @@ module aptos_framework::coin { | |||
burn(coin_to_burn, burn_cap); | |||
}; | |||
if (fa_amount_to_burn > 0) { | |||
fungible_asset::burn_from( | |||
fungible_asset::address_burn_from_for_gas( |
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.
burn_from is a public function that might be called from anywhere? we would need separate public(friend) for_gas variant and leave the public to emit regular events?
@@ -215,6 +215,18 @@ module aptos_framework::fungible_asset { | |||
frozen: bool, | |||
} | |||
|
|||
#[event] | |||
struct GasBurnt has drop, store { |
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.
we are not replacing Burn event, we are replacing Withdraw event, so this should be GasWithdraw
or WithdrawForGas
, similar below.
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.
I don't think this would help the permissions? As there were no signers involved at all. Seems to me a purely functional change for FA
let FungibleAsset { metadata, amount } = fa; | ||
assert!(exists<FungibleStore>(store_addr), error::not_found(EFUNGIBLE_STORE_EXISTENCE)); | ||
let store = borrow_global_mut<FungibleStore>(store_addr); | ||
assert!(metadata == store.metadata, error::invalid_argument(EFUNGIBLE_ASSET_AND_STORE_MISMATCH)); | ||
|
||
if (amount == 0) return; | ||
if (amount != 0) { |
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.
can keep amount==0
to save for one indentation.
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.
it's inline.
@@ -1019,26 +1032,54 @@ module aptos_framework::fungible_asset { | |||
assert!(amount == 0, error::invalid_argument(EAMOUNT_IS_NOT_ZERO)); | |||
} | |||
|
|||
public(friend) fun deposit_internal(store_addr: address, fa: FungibleAsset) acquires FungibleStore, ConcurrentFungibleBalance { | |||
inline fun raw_deposit_internal( |
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.
Naming here seems pretty bad. Both raw
and internal
imply the same thing? I think what we are really referring here is unchecked_deposit_with_no_events
?
/// Extract `amount` of the fungible asset from `store`. | ||
public(friend) fun withdraw_internal( | ||
/// Extract `amount` of the fungible asset from `store` emitting event. | ||
public(friend) fun raw_withdraw( |
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.
Same for raw_withdraw
. I think this is more like unchecked_withdraw
?
looks like this could be very expensive perf wise -- are we unable to compute this? why do we need this? |
it will have signers. I will refactor a little bit after AA code. |
Also, an exchange asked us how they can tell the difference between migration txn depositing FA or transfer depositing FA. I think this PR can solve their issue. |
ab06352
to
a8d769c
Compare
Description
We don't emit event when burn APT coin, neither should APT FA.
Now each txn burn gas fee from APT FA, we see a withdraw event for this.
We issue
GasBurnt
event andGasRefunded
event in both cases instead.How Has This Been Tested?
simple refactoring.
Type of Change
Which Components or Systems Does This Change Impact?