Skip to content

feat(sequencer): implement transaction fee query#1196

Merged
noot merged 11 commits intomainfrom
noot/estimate-fee
Jul 5, 2024
Merged

feat(sequencer): implement transaction fee query#1196
noot merged 11 commits intomainfrom
noot/estimate-fee

Conversation

@noot
Copy link
Contributor

@noot noot commented Jun 19, 2024

Summary

implement transaction fee ABCI query method. calculates the fee for the transaction based on the current state.

Background

useful for UX and fee estimation.

Changes

  • implement transaction fee ABCI query method which calculates the fee for the transaction based on the current state
  • update sequencer-client respectively

Testing

unit tests

Related Issues

closes #1071

@noot noot requested review from a team as code owners June 19, 2024 16:37
@noot noot requested a review from SuperFluffy June 19, 2024 16:37
@github-actions github-actions bot added proto pertaining to the Astria Protobuf spec sequencer pertaining to the astria-sequencer crate labels Jun 19, 2024
Copy link
Contributor

@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 left comments looking to understand why various code was updated (updating fees etc), even the PR just aims to read (not write)?

8 => "the requested value was not found".into(),
9 => "the transaction expired in the app's mempool".into(),
10 => "the transaction failed to execute in prepare_proposal()".into(),
11 => "the request was malformed".into(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe "the request body" or "request payload"?

enum TransactionFeeResponseErrorKind {
#[error("`fee` field is unset")]
UnsetFee,
#[error("failed to parse asset denom")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add the field, i.e. failed to parse ok asset listed in the ``.assets`` field

#[error("`fee` field is unset")]
UnsetFee,
#[error("failed to parse asset denom")]
Asset(#[from] asset::ParseDenomError),
Copy link
Contributor

Choose a reason for hiding this comment

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

Better just #[source] because I think we don't use the from conversion ever

from: Address,
state: &S,
) -> anyhow::Result<()> {
) -> anyhow::Result<HashMap<asset::IbcPrefixed, u128>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Fine for doing this in a follow-up: cant we request all the data bits in this method concurrently instead of one after the other?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes - can make an issue

}
}

for (asset, total_fee) in cost_by_asset {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could fire these up concurrently too


// Response to a transaction fee ABCI query.
message TransactionFeeResponse {
uint64 height = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Index from 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should probably change all of the response types if we want to index from 1, maybe we can do that when we move them to their own package?

@@ -164,16 +205,10 @@ pub(crate) async fn check_balance_for_total_fees<S: StateReadExt + 'static>(
}

fn transfer_update_fees(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this body updated? Probably missing something, but from a cursory glance this looks orthogonal to the new functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the function checking "fees" before was actually checking the total value used by the transaction, so it was summing fees and value transfers. however, the fees endpoint wants to return only fees used by the tx, so i had to separate these

}

fn ics20_withdrawal_updates_fees(
asset: &asset::Denom,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here - is this functionality no longer necessary or wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above

state: &S,
bridge_address: Address,
amount: u128,
fn bridge_unlock_update_fees(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here - why all that change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor

@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.

approve for API.

few comments on missing error context

let signer_address = crate::address::base_prefixed(tx.verification_key().address_bytes());
check_balance_for_total_fees(tx.unsigned_transaction(), signer_address, state).await?;
check_balance_for_total_fees_and_transfers(tx.unsigned_transaction(), signer_address, state)
.await?;
Copy link
Contributor

Choose a reason for hiding this comment

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

context

from: Address,
state: &S,
) -> anyhow::Result<()> {
let mut cost_by_asset = get_fees_for_transaction(tx, state).await?;
Copy link
Contributor

Choose a reason for hiding this comment

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

context


// Should have enough balance to cover all actions.
check_balance_for_total_fees(self, from, state).await?;
check_balance_for_total_fees_and_transfers(self, from, state).await?;
Copy link
Contributor

Choose a reason for hiding this comment

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

context

@noot noot added this pull request to the merge queue Jul 5, 2024
Merged via the queue into main with commit fc4e76b Jul 5, 2024
@noot noot deleted the noot/estimate-fee branch July 5, 2024 18:23
steezeburger added a commit that referenced this pull request Jul 11, 2024
* main: (27 commits)
  refactor(sequencer): fix prepare proposal metrics (#1211)
  refactor(bridge-withdrawer): move generated contract bindings to crate (#1237)
  fix(sequencer) fix wrong metric and remove unused metric (#1240)
  feat(sequencer): implement transaction fee query (#1196)
  chore(cli)!: remove unmaintained rollup subcommand (#1235)
  release(sequencer): 0.14.1 patch release (#1233)
  feat(sequencer-utils): generate example genesis state (#1224)
  feat(sequencer): implement abci query for bridge account info (#1189)
  feat(charts): bridge-withdrawer, smoke test, various chart improvements (#1141)
  chore(charts): update for new geth update (#1226)
  chore(chart)!: dusk-8 chart version updates (#1223)
  release(conductor): fix conductor release version (#1222)
  release: dusk-8 versions (#1219)
  fix(core): revert `From` ed25519_consensus types for crypto mod (#1220)
  Refactor(chart, sequencer): restructure sequencer chart, adjust configs (#1193)
  refactor(withdrawer): read from block subscription stream and get events on each block (#1207)
  feat(core): implement with verification key for address builder and crypto improvements (#1218)
  feat(proto, sequencer)!: use full IBC ICS20 denoms instead of IDs (#1209)
  chore(chart): update evm chart for new prefix field (#1214)
  chore: bump penumbra deps (#1216)
  ...
bharath-123 pushed a commit that referenced this pull request Jul 25, 2024
## Summary
implement transaction fee ABCI query method. calculates the fee for the
transaction based on the current state.

## Background
useful for UX and fee estimation.

## Changes
- implement transaction fee ABCI query method which calculates the fee
for the transaction based on the current state
- update sequencer-client respectively

## Testing
unit tests

## Related Issues

closes #1071
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

proto pertaining to the Astria Protobuf spec sequencer pertaining to the astria-sequencer crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sequencer: estimate_fee api endpoint

3 participants