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

chore(sequencer): further refactor of fees #1794

Closed

Conversation

Fraser999
Copy link
Contributor

Summary

This reduces a lot of boilerplate around fees.

Background

The boilerplate code is very prone to copy-paste errors. Changing the 14 different (but structurally identical) FeeComponent structs into a single one with a generic arg reduces a lot of the boilerplate code.

Changes

  • In core, replaced fee component structs with a new FeeComponents<T> where T will be some action type.
  • In sequencer, changed the FeeHandler trait fairly radically to support the new form of fees.

Testing

Existing tests are sufficient - there should be no changed functionality to the business logic.

Changelogs

No updates required.

@Fraser999 Fraser999 requested review from a team and joroshiba as code owners November 7, 2024 17:54
@github-actions github-actions bot added the sequencer pertaining to the astria-sequencer crate label Nov 7, 2024
Copy link
Contributor

@ethanoroshiba ethanoroshiba left a comment

Choose a reason for hiding this comment

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

Thanks for making these changes! I think these are extremely helpful. I left a few comments, mostly nits, and a couple other ideas as well.

crates/astria-sequencer/src/fees/action.rs Show resolved Hide resolved
crates/astria-sequencer/src/fees/mod.rs Show resolved Hide resolved
crates/astria-sequencer/src/fees/mod.rs Show resolved Hide resolved
crates/astria-sequencer/src/fees/query.rs Show resolved Hide resolved
crates/astria-core/src/protocol/fees/v1.rs Show resolved Hide resolved
Comment on lines +172 to +185
pub type TransferFeeComponents = FeeComponents<Transfer>;
pub type RollupDataSubmissionFeeComponents = FeeComponents<RollupDataSubmission>;
pub type Ics20WithdrawalFeeComponents = FeeComponents<Ics20Withdrawal>;
pub type InitBridgeAccountFeeComponents = FeeComponents<InitBridgeAccount>;
pub type BridgeLockFeeComponents = FeeComponents<BridgeLock>;
pub type BridgeUnlockFeeComponents = FeeComponents<BridgeUnlock>;
pub type BridgeSudoChangeFeeComponents = FeeComponents<BridgeSudoChange>;
pub type IbcRelayFeeComponents = FeeComponents<IbcRelay>;
pub type ValidatorUpdateFeeComponents = FeeComponents<ValidatorUpdate>;
pub type FeeAssetChangeFeeComponents = FeeComponents<FeeAssetChange>;
pub type FeeChangeFeeComponents = FeeComponents<FeeChange>;
pub type IbcRelayerChangeFeeComponents = FeeComponents<IbcRelayerChange>;
pub type SudoAddressChangeFeeComponents = FeeComponents<SudoAddressChange>;
pub type IbcSudoChangeFeeComponents = FeeComponents<IbcSudoChange>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit torn with these type aliases. While they do keep with our current naming and that may be reason enough to have them, I think it may be more representative of the new generic structure to continue using FeeComponents<ACTION_NAME> where the aliases are used. There are still many places in the refactor (such as fees/state_ext) where we do not use the aliases, both by necessity and not, so I think it could be helpful to outside readers to eliminate the indirection and keep it consistent across the code base.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah - I was mainly trying to reduce churn by providing these aliases, but I was 50-50 myself on adding them :) Given that you have enough of an opinion on this to have added a comment (even if your opinion is weakly held) I've gone with removing them in 1316e07 of #1811. It's a standalone commit, so if others disagree, it can be reverted easily enough.

Comment on lines +83 to +93
/// The Pascal-case type name, e.g. `RollupDataSubmission`.
// NOTE: We only require this function due to `IbcRelay` not implementing `Protobuf`.
fn name() -> &'static str;

/// The full name including the protobuf package, e.g.
/// `astria.protocol.transaction.v1.RollupDataSubmission`.
// NOTE: We only require this function due to `IbcRelay` not implementing `Protobuf`.
fn full_name() -> String;

/// The snake-case type name, e.g. `rollup_data_submission`.
fn snake_case_name() -> &'static str;
Copy link
Contributor

Choose a reason for hiding this comment

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

While it makes perfect sense that we need this functionality for the IbcRelay action, I think it is a bit odd to include this in FeeHandler, especially when these methods are applicable to many other things than fees. Perhaps we could do something like make a new trait ProstNameExt or NameExt, implement it for all actions which implement protobuf and add our own implementation for IbcRelay, then require it for FeeHandler? Just a thought, and may also be out of the scope of 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 guess I'd rather keep this functionality as restricted as possible until we have a concrete use-case for adding it more widely. The core lib is already pretty busy, and I'd rather avoid adding another trait there for it to only be consumed in one specific place in the sequencer.

@Fraser999
Copy link
Contributor Author

Closed in favour of #1811.

@Fraser999 Fraser999 closed this Nov 13, 2024
@Fraser999 Fraser999 deleted the fraser/ENG-944/refactor_fees branch November 13, 2024 15:38
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.

2 participants