Add OnFeeCharged trait in fee modules.#1924
Add OnFeeCharged trait in fee modules.#1924shaunxw wants to merge 9 commits intoparitytech:masterfrom
OnFeeCharged trait in fee modules.#1924Conversation
|
It looks like @shaopengw signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
1 similar comment
|
It looks like @shaopengw signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
srml/fees/src/lib.rs
Outdated
| fn on_fee_charged(_: &Amount) {} | ||
| } | ||
|
|
||
| impl< |
There was a problem hiding this comment.
Could you do this implementation please like seen here.
srml/fees/src/lib.rs
Outdated
|
|
||
| fn on_finalise() { | ||
| let extrinsic_count = <system::Module<T>>::extrinsic_count(); | ||
| let block_fee = (0..extrinsic_count).fold(<AssetOf<T>>::sa(0), |total, index| { |
There was a problem hiding this comment.
Can we not combine this with the loop below? To have this loop just once?
bkchr
left a comment
There was a problem hiding this comment.
Looks good so far, but still some stuff need to be improved.
|
Could you please add a test for this as well? Maybe just extend the |
| @@ -47,13 +72,17 @@ decl_module! { | |||
|
|
|||
| fn on_finalise() { | |||
There was a problem hiding this comment.
This could be done more cleanly by adding an event hook OnTransactionFeePaid into executive (or, probably better, system::Trait which would be called from executive) which could then be hooked in to fees::Trait::OnFeeChanged. This way you can avoid a second loop over all the transactions at the end of the block and writes into storage needed for CurrentTransactionFee.
There was a problem hiding this comment.
I believe that is basically the ChargeFee trait. Storage write (or some in memory write) is necessary to combine multiple fees together and emit a single event with the accumulated fee (#1815). I don't think there is other way to achieve that in the current substrate.
There was a problem hiding this comment.
In-memory write is way faster than storage round-trip, so I would prefer it to be donee thtat way, especially since it will affect all chains, even those with no use for this fee mechanism.
There was a problem hiding this comment.
Make sense. Is there existing in memory store can be used? Or need to crate this new mechanism? which will be out of scope of this PR and shouldn’t prevent this PR from been merged.
|
@bkchr Could you please suggest a clean way(or existing example in srml) to check if The one I could come up with is a mock implementing |
|
Create some type in substrate/srml/fees/src/tests.rs Line 172 in c4ca27f |
|
@bkchr Test added. :) |
|
I'm happy now, but we still need to integrate the requested changes by @gavofyork. |
|
There would be no need for any storage used. Basically, you just call the transaction-fee-paid hook right at the point that it is paid (in executive) rather than putting it all in storage and then re-looping in |
|
That's one possible way to do it but one of the goal of this fees module is to provide accumulated tx fees. Take balances transfer for example, it should charge fee twice (after #1815 is merged), and I don't want it emit |
|
That's not going to fly: Chains that don't care about this (e.g. Polkadot) should not have to pay the extra storage i/o just because other chains decide they wants to amalgamate all this info. If you have a callback based solution then your chain has the information is needs and can mutate it, store it and act upon it as desired, all without impacting on the performance of other chains that don't care. |
|
superceded in #2048 |
PR for issue #1923
This is an improvement to fees module. The
OnFeeChargedtrait gives a chance to deal with accumulated fees.