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

Inject ActionEvaluator and BlockChainStates explicitly #2507

Conversation

longfin
Copy link
Member

@longfin longfin commented Nov 2, 2022

This PR aims to extract ActionEvaluator<T> creation, from BlockChain<T> constructor to outside. to achieve that, we need to solve the dependency chain as below.

  1. ActionEvaluator<T> depends BlockChain<T> as IBlockChainStates<T>.
  2. To perform as IBlockChainStates<T>, BlockChain<T> depends IStore, IStateStore, and itself. (due to state completion).

In other words, if we can implement IBlockChainState<T> without the whole BlockChain<T>, extracting ActionEvaluator<T> creation from BlockChain<T> constructor seems possible.

  • At first, I introduced a new BlockChainStates<T> implementing IBlockChainStates<T>, instead of BlockChain<T>.
  • Moved GetBlances(), GetStates() and GetTotalSupply() from BlockChain<T> to BlockChainStates<T>.
    • I think that we have a rough consensus about obsoleting the state completion feature, but it can be another long story. so I deferred it to later PR.
    • To keep current behavior using StateCompleter<T>s, I introduced BlockChainStates<T>.Bind(). it takes BlockChain<T> to support previous methods.

@longfin longfin self-assigned this Nov 2, 2022
@longfin longfin force-pushed the feature/extract-action-evaluator-and-block-chain-states branch 4 times, most recently from dcc375e to f94411e Compare November 6, 2022 09:18
@longfin longfin marked this pull request as ready for review November 6, 2022 09:18
@longfin longfin force-pushed the feature/extract-action-evaluator-and-block-chain-states branch from f94411e to 67408e5 Compare November 7, 2022 12:59
dahlia
dahlia previously approved these changes Nov 8, 2022
tkiapril
tkiapril previously approved these changes Nov 8, 2022
Copy link
Contributor

@tkiapril tkiapril left a comment

Choose a reason for hiding this comment

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

Just a little question, but what would happen if Store and StateStore objects passed to BlockChain constructor is different from what was passed to BlockChainStates constructor that is passed to the BlockChain constructor?

Libplanet/Blockchain/BlockChain.cs Outdated Show resolved Hide resolved
@pull-request-quantifier-deprecated

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


Quantification details

Label      : Large
Size       : +171 -50
Percentile : 62.1%

Total files changed: 4

Change summary by file extension:
.md : +4 -0
.cs : +167 -50

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.

@longfin
Copy link
Member Author

longfin commented Nov 8, 2022

Just a little question, but what would happen if Store and StateStore objects passed to BlockChain constructor is different from what was passed to BlockChainStates constructor that is passed to the BlockChain constructor?

Basically, I believe the responsibility for the chain state and its calculation in Blockchain<T> should be lesser than now. but at least for now, it may cause errors or unintended behaviors. therefore a kind of check or guard would be good too.

@longfin
Copy link
Member Author

longfin commented Nov 8, 2022

therefore a kind of check or guard would be good too.

On second thought, adding a guard for IStore and IStateStore can be tricky since it's hard to suppose a proper way to do an equivalence check. 🤔

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

3 participants