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

feat: support for feeByEvent query param which will abstract the fees by events #970

Merged
merged 18 commits into from
Jul 7, 2022

Conversation

TarikGul
Copy link
Member

@TarikGul TarikGul commented Jun 24, 2022

Feature:

Query Parameter: feeByEvent -> Defaults to false. When true it will collect the partialFee by the events of each extrinsic.

How?

  1. Call rpc::payment::query_info in order to retrieve an estimated partialFee
  2. We search through the events per extrinsic looking for 3 specific events (This list of events are subject to grow as Event::TransactionPaidFee is added).
    a) Look through the Balances::Event::Withdraw event. We than compare the value given in the data to the estimated partialFee to confirm that there is some commonality. In this case we look for a less than 00.00001 difference in atomic value. (This is a very arguable approach, and I don't think it holds any real mathematical integrity, i Just used that abritrary value as a way to get this working).
    b) If the above isn't satisfied we do the same for Treasury::Event::Deposit, and do the same comparison.
    c) If the above isnt satisfied we then add up all the Balances::Event::Deposit values and compare that to the esimated partialFee.
    d) if none of those values are satisfied we return an error to log into the info field for the extrinsic.

Todo

  • Documentation
  • Tests

closes: #969 #756

Note: This PR will be followed by another PR to add support for Event::TransactionPaidFee

@TarikGul TarikGul requested a review from a team as a code owner June 24, 2022 21:55
@TarikGul TarikGul changed the title feat!: support for feeByEvent query param which will abstract the fees by events feat: support for feeByEvent query param which will abstract the fees by events Jun 24, 2022

return {
partialFee: partialFee.toString(),
error: 'Could not find a reliable fee within the events data.',
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know I suggested returning an error at some point, but I am wondering whether, especially called from the /blocks endpoint, it makes sense or not? I'm not sure how often we'll find the fee in events vs having to use the queryInfo result?

We could choose to acknowledge that we'll use events if possible, but if no events are available, it's not an error. We should tell the user whether we managed to use an event or not, so I wonder about a return type here that is just string | undefined (either we found the fee in events or not), and then in getPartialFeeInfo a return type like:

{
    partialFee: string,
    partialFeeFromEvent?: boolean
    error,
    dispatchClass
}

Just a thought tho!

Copy link
Member Author

Choose a reason for hiding this comment

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

In regards to the error, we are following our pattern for extrinsics where the error doesn't stop block querying execution, but instead sets the info field to have an error key with the relevant information. I think the thought of having a partialFeeFromEvent is a good one, but probably not applicable here, as it might confuse users, and clutters the API response a bit.

In regards to pattern I mentioned above, we already return an error whenever there is an issue or one of the cases for receiving fees aren't satisfied, so IMO it makes sense to keep the error and not return a fee.

it makes sense or not? I'm not sure how often we'll find the fee in events vs having to use the queryInfo result?

I'll scrap the chain a bit and see after 100,000 blocks if there is an issue.

Comment on lines +526 to +540
// Check Event:Withdraw event for the balances pallet
const withdrawEvent = this.findEvent(events, 'balances', Event.withdraw);
if (withdrawEvent.length > 0 && withdrawEvent[0].data) {
const dataArr = withdrawEvent[0].data.toJSON();
if (Array.isArray(dataArr)) {
const fee = (dataArr as Array<number>)[dataArr.length - 1];

// The difference between values is 00.00001% or less so they are alike.
if (this.areFeesSimilar(new BN(fee), partialFee)) {
return {
partialFee: fee.toString(),
};
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Def looks tidier now; I like it!

Copy link
Collaborator

@jsdw jsdw left a comment

Choose a reason for hiding this comment

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

LGTM; just a thought about returning an error vs some partialFeefromEvent for when we get the fee from events vs don't manage to :)

@TarikGul TarikGul added the A0 - Please Review PR is ready for review label Jul 5, 2022
@TarikGul TarikGul merged commit 92c155d into master Jul 7, 2022
@TarikGul TarikGul deleted the tarik-event-fee branch July 7, 2022 14:47
@LXHLeaner
Copy link

Is it now reading the estimated fee amount instead of the actual fee?

@TarikGul
Copy link
Member Author

Is it now reading the estimated fee amount instead of the actual fee?

No so nothing changes with the /blocks/* endpoint other than if you would like to retrieve the fees via the events instead of rpc::payment::queryInfo you can attach a feesByEvent query param.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A0 - Please Review PR is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mismatched fee amount for Acala
4 participants