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

Redistributing fees #4967

Merged
merged 30 commits into from
Dec 13, 2022
Merged

Redistributing fees #4967

merged 30 commits into from
Dec 13, 2022

Conversation

georgemitenkov
Copy link
Contributor

@georgemitenkov georgemitenkov commented Oct 11, 2022

First PR to enable transaction fees distribution. In particular, it adds:

  1. API for processing transaction fees, see transaction_fee.move
  2. API for aggregatable coin used to collect the fees, see coin.move
  3. API for distributing fees, see stake.move

Also, Move unit tests were added to simulate block execution.

Next PR: smoke and e2e tests, as this PR has quite a bit of changes already :)

@georgemitenkov
Copy link
Contributor Author

@junkil-park

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.

overall looks great!

@georgemitenkov georgemitenkov force-pushed the george/gas-redistribution branch from 1f72fd0 to 03c6175 Compare November 21, 2022 10:17
@georgemitenkov
Copy link
Contributor Author

cc @zekun000 @movekevin @junkil-park - this draft has now all the APIs (I hope). I am adding e2e tests at the moment, and in particular tests that include reconfigurations that remove validators.

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.

First pass. This is great so far and most comments are minor and more about code structuring. There's one edge case that we have discussed and still need to resolve: what happens if there are remaining undistributed fees because the proposer leaves the validator set in the same block that they propose. This can happen for blocks that contain governance proposal execution.

aptos-move/framework/aptos-framework/sources/stake.move Outdated Show resolved Hide resolved

/// Stores the transaction fee collected to the specified validator address.
public(friend) fun add_transaction_fee(validator_addr: address, fee: Coin<AptosCoin>) acquires ValidatorFees {
let fees_table = &mut borrow_global_mut<ValidatorFees>(@aptos_framework).fees_table;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a safeguard here in case the ValidatorFees resource has not been initialized?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then we would have a coin which we cannot drop (assuming we guard with if !exists<..>(..) return? Both CollectedFeesPerBlock and ValidatorFees are published at the same time, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm that's true that we can't drop or burn the coins here 🤔 It's fine not to have the safeguard then if those 2 resources are guaranteed to be published together. cc @junkil-park

aptos-move/framework/aptos-framework/sources/stake.move Outdated Show resolved Hide resolved
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.

I think this looks good now. There are 3 followups I think we should do:

  1. Add e2e (move tests) or smoke tests for fee distribution.
  2. Add an initialization script that will be used as the first step in the multistep proposal that would first initialize the required resources and then enable the feature flag
  3. Some manual testing in local network + devnet


/// Creates a new aggregatable coin with value overflowing on `limit`. Note that this function can
/// only be called by Aptos Framework (0x1) account for now becuase of `create_aggregator`.
public(friend) fun initialize_aggregatable_coin<CoinType>(aptos_framework: &signer): AggregatableCoin<CoinType> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need these functions here or can this be done directly in transaction_fee (with added friendship between transaction_fee and aggregatable coin)?

Copy link
Contributor Author

@georgemitenkov georgemitenkov Dec 9, 2022

Choose a reason for hiding this comment

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

initialize_aggregatable_coin and is_aggregatable_coin_zero can be moved to transaction_fee, but drain_aggregatable_coin, merge_aggregatable_coin and collect_from_into_aggregatable_coin have to stay in coin module to allow calling Coin constructor/destructor.

@georgemitenkov georgemitenkov marked this pull request as ready for review December 7, 2022 21:21
@georgemitenkov georgemitenkov changed the title [WIP] Redistributing fees Redistributing fees Dec 7, 2022
@georgemitenkov georgemitenkov added the CICD:run-e2e-tests when this label is present github actions will run all land-blocking e2e tests from the PR label Dec 12, 2022
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

✅ Forge suite land_blocking success on 70acfcdeb3e105c96bd556e690c52e1c86157954

performance benchmark with full nodes : 5834 TPS, 6733 ms latency, 13700 ms p99 latency,(!) expired 3320 out of 2494580 txns
Test Ok

@github-actions
Copy link
Contributor

✅ Forge suite compat success on testnet_2d8b1b57553d869190f61df1aaf7f31a8fc19a7b ==> 70acfcdeb3e105c96bd556e690c52e1c86157954

Compatibility test results for testnet_2d8b1b57553d869190f61df1aaf7f31a8fc19a7b ==> 70acfcdeb3e105c96bd556e690c52e1c86157954 (PR)
1. Check liveness of validators at old version: testnet_2d8b1b57553d869190f61df1aaf7f31a8fc19a7b
compatibility::simple-validator-upgrade::liveness-check : 7302 TPS, 5362 ms latency, 7600 ms p99 latency,no expired txns
2. Upgrading first Validator to new version: 70acfcdeb3e105c96bd556e690c52e1c86157954
compatibility::simple-validator-upgrade::single-validator-upgrade : 4577 TPS, 9006 ms latency, 12000 ms p99 latency,no expired txns
3. Upgrading rest of first batch to new version: 70acfcdeb3e105c96bd556e690c52e1c86157954
compatibility::simple-validator-upgrade::half-validator-upgrade : 4581 TPS, 8947 ms latency, 11200 ms p99 latency,no expired txns
4. upgrading second batch to new version: 70acfcdeb3e105c96bd556e690c52e1c86157954
compatibility::simple-validator-upgrade::rest-validator-upgrade : 6216 TPS, 6251 ms latency, 10200 ms p99 latency,no expired txns
5. check swarm health
Compatibility test for testnet_2d8b1b57553d869190f61df1aaf7f31a8fc19a7b ==> 70acfcdeb3e105c96bd556e690c52e1c86157954 passed
Test Ok

@georgemitenkov georgemitenkov merged commit 5738125 into main Dec 13, 2022
@georgemitenkov georgemitenkov deleted the george/gas-redistribution branch December 13, 2022 09:30
areshand pushed a commit to areshand/aptos-core-1 that referenced this pull request Dec 18, 2022
Enables transaction fees distribution. In particular, this adds:

1. API for processing transaction fees, see `transaction_fee.move`
2. API for aggregatable coin used to collect the fees, see `coin.move`
3. API for distributing fees, see `stake.move`

Also, Move unit tests are added to simulate the block execution.
@Markuze Markuze mentioned this pull request Dec 26, 2022
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants