-
Notifications
You must be signed in to change notification settings - Fork 56
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
Do we miss some balance changes? #77
Comments
@frol some questions:
|
Total supply did not change while the query was computed, I kept querying the
It gets the snapshot of the The query essentially pulls the latest available state change about each individual account and sums up those latest balances. |
That doesn't really work. For a given block, it is possible that there is a nonzero amount of transfer receipts. This means that the sender account has been debited but the receiver account hasn't been credited yet. If you sum up all account changes, it will be smaller than the total supply. Also how do you handle accounts that have been deleted? |
Ok, I expected that, but as you can see, the sum is greater than the total supply. I guess, we need to [query] every single account state on a fixed block through JSON RPC and see the result, and then next step would be to investigate if something is wrong with the state changes (whether the latest in the
Their latest near-indexer-for-explorer/src/models/account_changes.rs Lines 62 to 78 in de02eed
|
What could get into the play, though, is when an account gets touched in the same block, and currently, my query will select a who-knows-which state. This could probably be the case. We need to craft the query that accurately selects the latest among the receipts in the same transaction based on the |
The answer to the original question: no, we don't miss anything. I took a snapshot of the system on a block By snapshot, I mean that I asked RPC for the balance of each and every account in the system and I summed up all these numbers.
The numbers are equal, even with broken account that was found during collecting of data. Read about it here. I will continue the research in this ticket, you could find more details there. |
I understood that I checked the whole system (by RPC), but not our DB. Want to check additionally that sum is correct by collecting data only from |
Right select should look this way
All the data is for the block 33039470 (1616680365158678037 from the query is the corresponding timestamp)
My difference is smaller, but it still exists: 435k tokens extra. Fortunately, it's easier to understand where do we have difference. @bowenwang1996 do you have ideas what could we do wrong? |
@frol how is |
@bowenwang1996 we collect local receipts, and included chunk receipts and enumerate that list to assign the @telezhnaya we need to take a closer look into |
@frol while investigating this, found another problem. Case with
Case with
(join -> left join, join clause is changed also) |
@telezhnaya The order of the from Bowen:
To the best of my knowledge, we don't have documentation on the order anywhere, but we can recover the order from the code if we search for the Let's document it to the nomicon. @bowenwang1996 @evgenykuzyakov What would be the best place to document the execution order? |
@frol thank you! So, actually, we can just
We are much much closer to the truth now, but we still have some issues.
We have 51109700000000000000 more than we should have. (1) We have issues with
Let's imagine we have same numbers there. In such case, we have
Oops, diff becomes bigger. (2) We also have
Let's also assume that we fix that issue
🥳 (2) is known issue. |
I researched it a little bit more
Then Then there was a transfer, If we omit creating the keys (we do not want to count fees right now), that's all movements with |
Inside runtime spec. I created near/NEPs#191 |
Well, not really 😖 The id just happens to represent a correct order there for now, but it is not guaranteed, so we need to get back to the problem in a more systematic way. We introduced |
@frol Previous solution (it works fine, but we use id)
We can use Let's try to dig deeper into the real data.
Let's check which of them are really used
I changed the order of lines as I want. (*) Oh, that simplifies the task a little. New solution (also working, without using id)
It gives I don't think it's a good idea to look at the resulting query as to the working solution. The blockchain is growing, at any moment it can stop working. I think we need to add the column with the order, or maybe to give the guarantee that id gives the correct order. |
@telezhnaya Reading your analysis I realized that it seems that we may just need We should also consider dropping cc @khorolets |
@frol are you sure we want to have composite primary key? Using natural PKs means that we depend on the data that comes to the DB, and it could give us the problems as we have now in the Using composite PKs makes it harder to create FKs in other tables, we should put there both columns.
The ideal solution for me is to make the process of giving the id stricter, and rename it to |
Yeah, that absolute indexing is impossible.
@telezhnaya Let's add this new column and keep the |
I sum up non-staking and staking-balances based on the latest state changes per account:
And here are the values:
The problem here is that this exceeds the total supply. Note, there are three accounts created in genesis (
bo.near
,registrar
,wallet.pulse.near
), which have never been touched, so they are not in theaccount_changes
table (they hold just 60 NEAR)The difference is 602.5k NEAR
Any ideas? @telezhnaya @bowenwang1996
The text was updated successfully, but these errors were encountered: