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

fix(sequencer)!: fix block fees #1343

Merged
merged 24 commits into from
Aug 21, 2024
Merged

Conversation

ethanoroshiba
Copy link
Contributor

@ethanoroshiba ethanoroshiba commented Aug 2, 2024

Summary

Corrected block fee reporting so that proposer is paid the correct fees.

Background

Previously, only TransferAction and SequenceAction called get_and_increase_block_fees(), the method for increasing the running fees for the block. In end_block, this was used for calculating how much to increase the proposer's balance meaning that they were only paid the fees for Transfer and Sequence actions.

Changes

  • Implemented get_and_increase_block_fees() in all actions which charge fees.

Testing

Added unit tests for each action, with the exception of Ics20Withdrawal. This test should be implemented, but will require a more in-depth configuration.

Breaking Changelist

  • App hash changed, snapshot has been regenerated.

Related Issues

closes #1333

@github-actions github-actions bot added the sequencer pertaining to the astria-sequencer crate label Aug 2, 2024
@ethanoroshiba ethanoroshiba marked this pull request as ready for review August 2, 2024 16:19
ethanoroshiba and others added 4 commits August 2, 2024 11:35
## Summary
Implemented the `Protobuf` trait for all TX `Action`s and variants.

## Background
`Action` and variants are refined types from generated Protobuf code,
but did not implement the `Protobuf` trait. This change is to
standardize the types `Error` and `Raw` across `Action`, as well as the
methods `to_raw()`, `into_raw()`, `try_from_raw()`, and
`try_from_raw_ref()`.

## Changes
- Implemented `Protobuf` trait, types, and necessary functions for
`Action` and all of its variants.
- Deleted redundant functions which took ownership, but kept those which
prioritized cost over their `ref` counterparts.

## Testing
Passing all tests.

## Related Issues
closes #1307

---------

Co-authored-by: Fraser Hutchison <[email protected]>
@ethanoroshiba ethanoroshiba force-pushed the ENG-680/correct_block_fees branch from 6ed81d1 to 1cd5609 Compare August 2, 2024 16:54
@ethanoroshiba ethanoroshiba changed the base branch from main to gh-1318 August 2, 2024 16:58
Copy link
Member

@SuperFluffy SuperFluffy left a comment

Choose a reason for hiding this comment

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

I'd like to take this PR into a different direction:

Instead of implementing fee-payments on a per-action basis, I would fee payments to happen at a higher level in <SignedTransaction as ActionHandler>::check_and_execute.

I am thinking of something like this:

  1. define a trait ActionFee with a trait method ActionFee::action_fee
  2. implement this for every action and the enum Actions collection.
  3. define a calculate_fees method on SignedTransaction (note that this is a foreign type, so you might either need to make a free-standing function or create a trait just for that); calculate_fees just runs over all actions and sums up their fees.
  4. pay the fee right before SignedTransaction::check_and_execute starts processing the individual transactions.

I know that fee calculations right now require access to the state. Ideally the fee calculations on an individual action can do without access to state.

EDIT: Having had a second look at how fees are calculated, we use a base fee (that's fine) but across potentially many different fee_assets (not fine).

IMO this makes my suggestion above untenable, so that fees indeed must be paid on a per-action basis.

Note that the reason why this cannot be done prior to execution is the same as what required to fix #1318: fees cannot be paid before execution begins. Following scenario:

  1. action A adds a new fee asset
  2. action B adds funds to an account for that fee asset
  3. action C uses the fee asset for that account to pay for the transaction.

@SuperFluffy SuperFluffy dismissed their stale review August 2, 2024 18:40

Suggestion made no sense. Wait to review until 1318 is merged (or wait for other reviewers)

assert_eq!(total_block_fees, 1);
}

// TODO: Add test to ensure correct block fees for ICS20 withdrawal
Copy link
Collaborator

@noot noot Aug 19, 2024

Choose a reason for hiding this comment

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

will you add that in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I attempted to do so but ran into a lot of difficulty setting up the IBC channel/ports, which is required for check_and_execute(). It looks like Janis ran into the same issue in #1345 because Penumbra doesn't make the StateWriteExt traits public. I may be missing something, though. If you have any suggestions it would be greatly appreciated! Also, thanks for the quick review and welcome back!

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, gotta make a PR against penumbra.

Copy link
Member

Choose a reason for hiding this comment

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

If we are leaving a TODO in after merge, create a follow up issue and link in code please :) ie

// TODO(https://github.com/astriaorg/astria/issues/<issue num>): add test for correct block fees

Base automatically changed from gh-1318 to main August 20, 2024 11:42
Copy link
Member

@SuperFluffy SuperFluffy left a comment

Choose a reason for hiding this comment

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

Looks great. We should restructure the tests so we don't end up with a plethora of tests_* but rather create a module structure. But that can be done in a followup.

@ethanoroshiba ethanoroshiba added this pull request to the merge queue Aug 21, 2024
Merged via the queue into main with commit 781c4c5 Aug 21, 2024
42 checks passed
@ethanoroshiba ethanoroshiba deleted the ENG-680/correct_block_fees branch August 21, 2024 13:14
steezeburger added a commit that referenced this pull request Aug 22, 2024
* main:
  refactor(core, proto)!: define app genesis state in proto (#1346)
  fix(sequencer): bump penumbra dep to fix ibc state access bug (#1389)
  feat(conductor)!: support disabled celestia auth (#1372)
  fix(sequencer)!: fix block fees (#1343)
  perf(sequencer): add benchmark for prepare_proposal (ENG-660) (#1337)
  fix(proto): fix import name mismatch (#1380)
  fix(ci): enable bridge withdrawer building with tag (#1374)
  feat(sequencer): rewrite memool to have per-account transaction storage and maintenance  (#1323)
  refactor(core, sequencer)!: require that bridge unlock address always be set (#1339)
  fix(sequencer)!: take funds from bridge in ics20 withdrawals (#1344)
  fix(sequencer)!: fix TOCTOU issues by merging check and execution (#1332)
  fix: abci error code (#1280)
  refactor(core): shorten `try_from_block_info_and_data()` (#1371)
  fix(relayer): change `reqwest` for `isahc` in relayer blackbox tests (ENG-699) (#1366)
  fix(conductor): update for celestia-node v0.15.0 (#1367)
  Chore: Upgrade celestia-node to v0.14.1 (#1360)
  chore(charts): fix charts production templates (#1359)
  chore(core, proto): migrate byte slices from Vec to Bytes (#1319)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sequencer pertaining to the astria-sequencer crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposer is not paid correct block fees
4 participants