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

✨ New state querying scheme #3570

Merged

Conversation

greymistcube
Copy link
Contributor

@greymistcube greymistcube commented Dec 26, 2023

Adds more modular and reusable AccountStateType to GraphQL queries.

As seen in its implementation, this is pretty lousy. I tried to remove Currency/FungibleAssetValue context from state query, but this has resulted in severe API inconsistency. 😥

This issue is mainly due to IAccount having two roles:

  • Knowing the data model stored in the database: Where to retrieve the data by using an "appropriate" key-conversion.
  • Interpreting the retrieved data: Implicitly converting null to zero-amount FungibleAssetValue for given Currency.

As it stands, there is no possible way to know (although whether this is necessary might be debatable) how Currency related data is stored within the storage entirely from the library side (libplanet) or the client side (lib9c).

  • When retrieving a FungibleAssetValue from an Address and a Currency pair, one cannot actually know whether the underlying data is 0 or null. Considering how it is treated, Currency is inherently a client-side provided context. This itself isn't much of a problem, if we think of IAccount as an interface to obfuscate the underlying data (or logic).
  • On the other hand, libplanet's current API is built in such a way that it is not even possible to retrieve the underlying Currency's raw value (in IValue) without the information of Currency being provided in its entirety, even though what is only needed is Currency.Hash.

Further examples of API inconsistency among across different types of queries are:

  • Even though the basic unit of GetState() is getting a single IValue from an address, we only have states and is missing state. Furthermore, an IValue is returned implicitly as base64 format.
  • On the other hand, Currency related queries require an actual instance of Currency as stated above, and returns an interpreted FungibleAssetValue instance. Again, as stated above, there is no way to actually know its raw value (Integer).
  • As for ValidatorSet, again, it is returned as a ValidatorSetType instance.

The purpose of this new AccountStateType is to provide a way to query raw underlying data in a consistent manner reflecting the underlying data structure so that the interpretation can be done at another layer by post processing the result.

Seems like maintaining cost of improper mock/fixture has surpassed creating a proper one from scratch. If it wasn't for pending 4.0 release, I would've created a new one, but had to scrap it. 😕

@greymistcube greymistcube changed the title ✨ Feature/account query ✨ New state querying scheme Jan 2, 2024
@greymistcube greymistcube marked this pull request as ready for review January 2, 2024 13:20
limebell
limebell previously approved these changes Jan 3, 2024

This PR has 437 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Extra Large
Size       : +434 -3
Percentile : 81.23%

Total files changed: 4

Change summary by file extension:
.md : +4 -0
.cs : +430 -3

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

Copy link

codecov bot commented Jan 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5b49b75) 76.62% compared to head (e9e8b05) 79.15%.

Additional details and impacted files
@@                 Coverage Diff                 @@
##           3.9-maintenance    #3570      +/-   ##
===================================================
+ Coverage            76.62%   79.15%   +2.53%     
===================================================
  Files                  339      339              
  Lines                11842    11842              
===================================================
+ Hits                  9074     9374     +300     
+ Misses                2768     2468     -300     

see 59 files with indirect coverage changes

@greymistcube greymistcube merged commit 2c8158d into planetarium:3.9-maintenance Jan 3, 2024
20 checks passed
@greymistcube greymistcube deleted the feature/account-query branch January 4, 2024 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants