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 implementation for AccountReadableKVState #9414

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

Conversation

IvanKavaldzhiev
Copy link
Contributor

Description:
This PR adds AccountReadableKVState implementation needed for building the read only state layer in mirror node, that will be utilized by the reusable services components.

Related issue(s):

Fixes #9251

Notes for reviewer:

Checklist

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

@IvanKavaldzhiev IvanKavaldzhiev added enhancement Type: New feature web3 Area: Web3 API labels Sep 19, 2024
@IvanKavaldzhiev IvanKavaldzhiev requested a review from a team September 19, 2024 15:25
@IvanKavaldzhiev IvanKavaldzhiev self-assigned this Sep 19, 2024
@steven-sheehy steven-sheehy added this to the 0.115.0 milestone Sep 19, 2024
Comment on lines 118 to 121
return new Account(
new AccountID(
entity.getShard(),
entity.getRealm(),
Copy link
Member

Choose a reason for hiding this comment

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

Are there setters or a builder that can be used here? This is not maintainable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there is a builder. I will adapt it.

Copy link
Member

Choose a reason for hiding this comment

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

Same comment for all complex pbj types. For simple types with 1-3 like AccountID can probably skip builder.

Base automatically changed from 09249-add-hedera-app-dependency to main September 19, 2024 21:53
* limitations under the License.
*/

package com.hedera.modularized.state;
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't have a modularized package and everything should be inside mirror web3 package.

Suggested change
package com.hedera.modularized.state;
package com.hedera.mirror.web3.state;

Comment on lines 118 to 121
return new Account(
new AccountID(
entity.getShard(),
entity.getRealm(),
Copy link
Member

Choose a reason for hiding this comment

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

Same comment for all complex pbj types. For simple types with 1-3 like AccountID can probably skip builder.

Comment on lines 224 to 229
private List<AccountApprovalForAllAllowance> getApproveForAllNfts(Long ownerId, final Optional<Long> timestamp) {
final var nftAllowances = timestamp.isPresent()
? nftAllowanceRepository.findByOwnerAndTimestampAndApprovedForAllIsTrue(ownerId, timestamp.get())
: nftAllowanceRepository.findByOwnerAndApprovedForAllIsTrue(ownerId);

return nftAllowances.stream().map(this::convertNftAllowance).collect(Collectors.toList());
Copy link
Member

Choose a reason for hiding this comment

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

A lot of work was put into AccountDatabaseAccessor to cache nested calls with Suppliers.memoize() to reduce repository calls. Why was this not carried over? This class should basically be a copy of AccountDatabaseAccessor with transformations swapped out with pbj types.

Copy link
Contributor Author

@IvanKavaldzhiev IvanKavaldzhiev Sep 20, 2024

Choose a reason for hiding this comment

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

I also wanted to keep the Suppliers.memoize() strategy. The problem is - in the current approach we use modified copied DTO models, where we added Supplier type for some of the arguments, so that we can pass our Suppliers. Now using the PBJ types we don't have any control - those are generated DTOs based on the protobuf definitions. The whole set or arguments are concrete types and should be eagerly provided.

I'd be happy to hear an alternative approach, keeping the performance benefits, but now using directly the reusable services we must strictly comply with all of the definitions, without having much control.

import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import lombok.extern.java.Log;
import org.jetbrains.annotations.NotNull;
Copy link
Member

Choose a reason for hiding this comment

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

We should not use jetbrains annotations. It looks like services uses the findbugs annotations so not sure why jetbrains is coming. In mirror node, we prefer the standard jakarta annotations jakarta.annotation.Nonnull.

Comment on lines 97 to 98
final var timestampValue = ContractCallContext.get().getTimestamp();
final Optional<Long> timestamp = timestampValue != 0 ? Optional.of(timestampValue) : Optional.empty();
Copy link
Member

Choose a reason for hiding this comment

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

It's weird that the two uses of the context timestamp in the codebase is to wrap it into an optional. Hence we should wrap this into an optional once directly in ContractCallContext.setTimestamp().

Suggested change
final var timestampValue = ContractCallContext.get().getTimestamp();
final Optional<Long> timestamp = timestampValue != 0 ? Optional.of(timestampValue) : Optional.empty();
final var timestamp = ContractCallContext.get().getTimestamp();

Copy link

codecov bot commented Sep 20, 2024

Codecov Report

Attention: Patch coverage is 91.80328% with 10 lines in your changes missing coverage. Please review.

Project coverage is 92.56%. Comparing base (5d00263) to head (0650e5d).

Files with missing lines Patch % Lines
...dera/mirror/web3/state/AccountReadableKVState.java 90.74% 6 Missing and 4 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #9414      +/-   ##
============================================
- Coverage     92.56%   92.56%   -0.01%     
- Complexity     7047     7084      +37     
============================================
  Files           914      916       +2     
  Lines         29810    29929     +119     
  Branches       3767     3776       +9     
============================================
+ Hits          27595    27704     +109     
- Misses         1445     1451       +6     
- Partials        770      774       +4     

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

Signed-off-by: IvanKavaldzhiev <[email protected]>
Signed-off-by: IvanKavaldzhiev <[email protected]>
Signed-off-by: IvanKavaldzhiev <[email protected]>
Copy link

sonarcloud bot commented Sep 20, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type: New feature web3 Area: Web3 API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement AccountDatabaseReadableKVState
2 participants