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

[FA] s/withdraw/gasburn/ event & s/deposit/gasrefunded/ event #15357

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lightmark
Copy link
Contributor

@lightmark lightmark commented Nov 21, 2024

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 and GasRefunded event in both cases instead.

How Has This Been Tested?

simple refactoring.

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)

Copy link

trunk-io bot commented Nov 21, 2024

⏱️ 27m total CI duration on this PR
Job Cumulative Duration Recent Runs
rust-move-tests 13m 🟩
rust-move-tests 7m 🟥
rust-cargo-deny 3m 🟩🟩
check-dynamic-deps 1m 🟩🟩
general-lints 1m 🟩🟩
semgrep/ci 43s 🟩🟩
file_change_determinator 23s 🟩🟩
permission-check 6s 🟩🟩
permission-check 4s 🟩🟩

settingsfeedbackdocs ⋅ learn more about trunk.io

@@ -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(
Copy link
Contributor

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;
};

Copy link
Contributor

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

Copy link
Contributor Author

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.

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 seems mint_and_refund also has a deposit event... I am not sure whether we should have this PR now.

Copy link
Contributor

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

Copy link
Contributor Author

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.

@lightmark lightmark force-pushed the lightmark/no_withdraw_event_from_burn_fa branch from 4760bba to ab06352 Compare November 21, 2024 22:55
@lightmark lightmark changed the title [FA] no withdraw event for burn [FA] s/withdraw/gasburn/ event & s/deposit/gasrefunded/ event Nov 21, 2024
@lightmark
Copy link
Contributor Author

I create two events to presents gas burnt and gas refunded.

Copy link
Contributor

@igor-aptos igor-aptos left a 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.
Copy link
Contributor

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(
Copy link
Contributor

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 {
Copy link
Contributor

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.

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.

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) {
Copy link
Contributor

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.

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 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(
Copy link
Contributor

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(
Copy link
Contributor

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?

@davidiw
Copy link
Contributor

davidiw commented Nov 22, 2024

looks like this could be very expensive perf wise -- are we unable to compute this? why do we need this?

@lightmark
Copy link
Contributor Author

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

it will have signers. I will refactor a little bit after AA code.

@lightmark
Copy link
Contributor Author

lightmark commented Nov 28, 2024

looks like this could be very expensive perf wise -- are we unable to compute this? why do we need this?
which is expensive? if you're referring to event, the status quo is we emit an event when burn gas. This PR just replace it with another event.

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.

@lightmark lightmark force-pushed the lightmark/no_withdraw_event_from_burn_fa branch from ab06352 to a8d769c Compare December 2, 2024 04:09
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.

4 participants