Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Changed behavior of the balances.Deposit events with kusama runtime 9122 #4230

Closed
TheGoldenEye opened this issue Nov 5, 2021 · 10 comments
Closed

Comments

@TheGoldenEye
Copy link

In my tool (https://github.com/TheGoldenEye/polka-store) so far I've calculated the fee paid by the extrinsic sender (signer) from balances.Deposit and treasury.Deposit events (feePaid=balances.Deposit+treasury.Deposit)
This was working good until kusama runtine 9111. See example https://kusama.subscan.io/event?extrinsic=9866349-4
Starting with runtime 9122 there are now much more balances.Deposit events. Seems (for payout_stakers calls) each staking.Rewarded event has a corresponding balances.Deposit event now. So my fee calulation breaks.
See example https://kusama.subscan.io/event?extrinsic=9874887-2. My calculated fee is 3.75 KSM (same is shown in subscan as fee for Extrinsic#9874887-2), but this cannot be right)
I saw the new balances.withdraw event, how to interpret this? Maybe this is (part of) the fee (paid by the sender) I'm looking for?

@apopiak
Copy link
Contributor

apopiak commented Nov 5, 2021

This was introduced by paritytech/substrate#9425 (duplicate events will be addressed by #4180)
Withdraw events represent fund movement out of an account (e.g. for fee payment). So a transaction will have a balances.Withdraw for the fee payment as well as balances.Deposit for the treasury and block author.

@bkchr
Copy link
Member

bkchr commented Nov 8, 2021

So, can this be closed @TheGoldenEye ?

@freehere107
Copy link

freehere107 commented Nov 9, 2021

@apopiak @bkchr paritytech/substrate#9425 Can replace it with another event? After this pr merge, I cannot simply use treasury.deposit + balances.deposit to calculate the handling fee
https://polkadot.subscan.io/extrinsic/0x4832d65fb36f0dd2be9cfdc2ca31beda2f81ee69503a7f3acbaffb2b576fd3a0?event=7563119-17

@TheGoldenEye
Copy link
Author

I've found the following solution:
I now use the last balances.Deposit (goes to block creator) and treasury.Deposit for fee calculation.
With #4180 the duplicate balances.Deposit (red) should disappear, but what about the (in my opinion unnecessary) events (blue in the picture)?
image

@TheGoldenEye
Copy link
Author

btw, additional I check the accountId of balances.Deposit event, should be the id of block author

@apopiak
Copy link
Contributor

apopiak commented Nov 9, 2021

So to recap, right now, there are:

To get the full fees of a block I would suggest you:

  • deduplicate the balances.Deposit Events
  • for each transaction: add the two balances.Deposit events going to the block author and the treasury respectively

You should be able to match this amount against the corresponding amount withdrawn from the account sending the transaction (there is a corresponding balances.Withdraw now).

@apopiak
Copy link
Contributor

apopiak commented Nov 9, 2021

I've found the following solution: I now use the last balances.Deposit (goes to block creator) and treasury.Deposit for fee calculation.

This will only work for one transaction, FYI.

With #4180 the duplicate balances.Deposit (red) should disappear, but what about the (in my opinion unnecessary) events (blue in the picture)?

The blue events are created by the balance movements induced by the staking rewards.
With the new events, all balance movements have a corresponding balances event.

@TheGoldenEye
Copy link
Author

TheGoldenEye commented Nov 9, 2021

only balances.Deposit is duplicated, not the one for treasury

I've found the following solution: I now use the last balances.Deposit (goes to block creator) and treasury.Deposit for fee calculation.

This will only work for one transaction, FYI.

we consider the events of one transaction, so no problem

I have picked out all the relevant events for Extrinsic 9874887-2
image
Therew are 2 ways for fee calculation I see:

  1. The fee paid by the sender is 9874887-173 + 9874887-174 = 115666534
  2. This is same as 9874887-12 - 9874887-171 = 115666534

What is the reason for event 9874887-171? Without this the amount of event 9874887-12 should be 115666534. (the fee paid)
Btw, both variants of the fee calculation are prone to errors. If there is an additional balance.Deposit (e.g. staking payout) for the signer account (2) or the block author account (1), then the calculation goes wrong.

@apopiak
Copy link
Contributor

apopiak commented Nov 9, 2021

[...] There are 2 ways for fee calculation I see:

1. The fee paid by the sender is `9874887-173 + 9874887-174 = 115666534`

2. This is same as `9874887-12 - 9874887-171 = 115666534`

Both of those are correct and should give the same result.

  1. the first is the combination of the treasury and the block author payout.
  2. is the initial fee minus the refund

**What is the reason for event 9874887-171?

It is a refund to the sender of the transaction because the final fee is lower than the initial fee.

Btw, both variants of the fee calculation are prone to errors. If there is an additional balance.Deposit (e.g. staking payout) for the signer account (2) or the block author account (1), then the calculation goes wrong.

Yes, filtering might get complicated in edge cases; should be possible, though.
Feel free to open a new issue for this. I don't think it's very likely more events will be added, though.

My sense is that we've covered the changed behavior. Good to close?

@TheGoldenEye
Copy link
Author

Yep, good to close. Thx @apopiak

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants