-
Notifications
You must be signed in to change notification settings - Fork 158
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
Update fee calculation logic #50
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not feel qualified to do a proper review here as I have minimal experience with javascript or even typescript. So take my comments with a grain of salt.
Someone also needs to check if all calculations are done saturating rather than overflowing. I would assume that the plain mul
and add
functions have overflowing semantics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code lgtm overall, added questions/nits here and there
ba3646d
to
8b4a95d
Compare
ed16438
to
f238657
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm 👍
I have some doubts on this line:
substrate-api-sidecar/src/ApiHandler.ts
Line 143 in 7d1465e
const targetedFeeAdjustment = (await api.query.transactionPayment.nextFeeMultiplier.at(parentHash)).div(perBill); // FIXME This might round the number |
To convert multiplier
(a Fixed128) into Perbill, we do .div(1e9)
. But this conversion might come with precision loss.
src/ApiHandler.ts
Outdated
const extrinsicBaseWeight = api.consts.system.extrinsicBaseWeight; | ||
// Here we assume that `weightToFee` Vec only has 1 element, which is of | ||
// degree 1. FIXME Implement polynomial. | ||
const coefficients = api.consts.transactionPayment.weightToFee[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting Internal Error: TypeError: Cannot read property '0' of undefined
here. Not latest binary, but latest block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field is a recent addition. You need to update your node.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@athei still having the same issue on stable Kusama 0.7.33 release, fully synced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change is not tagged yet. You need to build master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still has issues. Our naive javascript PerBill
and Fixed128
implementations do not exactly match the rust implementation.
For that reason we will delegate the actual computation to a wasm blob that uses the real Rust types for arithmetic. sidecar just calls into that blob and supplies all data.
I take over that PR if that is ok @danforbes .
Also substrate is currently buggy and does not apply negative fee adjustments: paritytech/substrate#6145
Is there a reason why we cannot do the calculations with BNs? |
You can do that sure. But just look at the Doing that in wasm is just way easier. |
Riot is acting up and it seems I can't join channels. WASM is fine by me. |
@athei makes sense. Note that https://github.com/polkadot-js/wasm exists, the idea was to have one repo for wasm so that we don't replicate rust->wasm+js_glue_code tooling. If this is something not-sidecar-specific, it might be a good idea to put it there. |
I cannot accept nor decline your DM invitation. Something is seriously wrong. Try restarting :D
How would I include the wasm blob into the sidecar then? Via npm.js? |
Yes. |
Not yet functional. Some rounding differences are still present.
This also removes the contraint that only one term of the weight to fee polynomial is used.
I added the code that uses a rust module to calculate the fees. It works for me and yields the correct result. I also rebased it onto the current master. CI is currently failing because it does not build the rust package nor does it has the required toolchain installed. I will fix this soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI is fixed. It builds the rust project now. Let me just approve my own changes :D.
We should still wait for more tests and approvals before merging this.
serde_derive = { version = "1", default_features = false } | ||
serde = { version = "1", default_features = false } | ||
console_error_panic_hook = { version = "0.1", optional = true } | ||
sp-arithmetic = { git = "https://github.com/paritytech/substrate", default_features = false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should replace that by a released version as soon as that is possible. The current release on crates.io (2.0.0-rc2) has a broken Fixed128 impl that does not work with negative coefficients on unsigned Balances.
This reverts commit d098672.
Closes #45