Skip to content
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

Add entity type filtering in Token and Account kv states #9863

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

kselveliev
Copy link
Contributor

Description:
This PR adds filtering for entity type in the account and token readable kv states.

This PR modifies ... in order to support ...
TokenReadableKVState - return token only if the entity type return from entity table is of type token
AccountReadableKVState - return the account when the entity type is not token
Unit test for the new cases

Related issue(s):

Fixes #9862

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@kselveliev kselveliev added bug Type: Something isn't working web3 Area: Web3 API labels Dec 3, 2024
@kselveliev kselveliev added this to the 0.120.0 milestone Dec 3, 2024
@kselveliev kselveliev self-assigned this Dec 3, 2024
@kselveliev kselveliev requested a review from a team as a code owner December 3, 2024 09:35
@@ -92,6 +93,7 @@ protected Account readFromDataSource(@Nonnull AccountID key) {
final var timestamp = ContractCallContext.get().getTimestamp();
return commonEntityAccessor
.get(key, timestamp)
.filter(entity -> entity.getType() != TOKEN)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here if we use this filter .filter(entity -> entity.getType() == ACCOUNT) a couple of hundred tests start failing,
This is covering the case described in the issue that this pr fixes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may filter entities different than token directly in the DB. This optimisation can be added in additional PR.

Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.26%. Comparing base (c6145d4) to head (167f27e).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #9863   +/-   ##
=========================================
  Coverage     92.26%   92.26%           
- Complexity     7771     7774    +3     
=========================================
  Files           951      951           
  Lines         32472    32473    +1     
  Branches       4118     4118           
=========================================
+ Hits          29961    29962    +1     
  Misses         1546     1546           
  Partials        965      965           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Kristiyan Selveliev <[email protected]>
@@ -163,6 +167,14 @@ void setup() {
entity.setMaxAutomaticTokenAssociations(MAX_AUTOMATIC_TOKEN_ASSOCIATIONS);
entity.setType(EntityType.ACCOUNT);

token = new Entity();
token.setId(TOKEN_NUM);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be precise we should use EntityIdUtils to construct the ID based on SHARD, REALM, TOKEN_NUM and aggregate their values. The result will equal TOKEN_NUM but once we have shards and realms the values will differ.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment addressed

@@ -70,6 +70,8 @@ class TokenReadableKVStateTest {

private static final TokenID TOKEN_ID =
TokenID.newBuilder().shardNum(0L).realmNum(0L).tokenNum(1252L).build();
private static final TokenID TOKEN_ID_ACCOUNT =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just name it like TOKEN_ID_FOR_NEGATIVE_TEST or TOKEN_ID_SECOND or something like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment addressed

steven-sheehy
steven-sheehy previously approved these changes Dec 3, 2024
Signed-off-by: Kristiyan Selveliev <[email protected]>
Signed-off-by: Kristiyan Selveliev <[email protected]>
Copy link

sonarcloud bot commented Dec 3, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Type: Something isn't working web3 Area: Web3 API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calls to HTS contracts are not properly propagated in reusable services
3 participants