-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HIP-584 Historical: Fix historical NFT/Fungible token balance (#7430)
This PR includes the following fixes: - get historical fungible token balance from `TokenBalanceRepository` - get historical NFT balance from `NftRepository`. Historical NFT balance should be obtained from `account.getOwnedNfts()`, as explained in the code comments - fix `findHistoricalTokenBalanceUpToTimestamp` in edge case where `balance_snapshot` and/or `base` queries do not match anything in the db. Currently reproducible in acceptance tests: 1. create account 2. make fungible token transfer +50 3. make fungible token transfer +50 4. make historical call with timestamp between the token transfers, expected balance is 50, but returns 0 I have observed that the state in db after these operations is the following: `account_balance` - no entry for this accountId `token_balance` - no entry for this accountId `token_transfers` - 2 entries for this accountId, one for first transfer (50) and one for the second transfer (50) `balance_snapshot` and `base` match nothing because there is no entry for this accountId before the given timestamp. This causes the statement `tt.consensus_timestamp > s.consensus_timestamp` to be false and cannot match any token transfers, always returning 0 due to the coalesce at the end of the query. NB. `token_balance` and `account_balance` entries get persisted in ~8 minute intervals so it is not certain that there is entry in the db after the first transfer. Current solution: If `balance_snapshot` and/or `base` do not match anything, find token transfers that occured after the account creation and before the given timestamp: ```sql tt.consensus_timestamp >= coalesce((select consensus_timestamp from base), accountCreatedTimestamp) ``` Changed `>` to `>=` ensures the inclusion of the token transfer that occurred when the account was created. --------- Signed-off-by: Ivan Ivanov <[email protected]>
- Loading branch information
Showing
14 changed files
with
423 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.