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

Validate state root hash #986

Merged
merged 15 commits into from
Sep 11, 2020
Merged

Conversation

moreal
Copy link
Contributor

@moreal moreal commented Sep 4, 2020

  • Require and validate Block<T>.StateRootHash field when using TrieStateStore.
  • Remove evaluationDigest (aka actionsHash)

@moreal moreal self-assigned this Sep 4, 2020
@moreal moreal changed the title Introduce state root hash property in block WIP: Apply MPT properly Sep 4, 2020
@moreal moreal force-pushed the feature/state-root-hash branch 3 times, most recently from 8cf6863 to a683a81 Compare September 7, 2020 12:39
@moreal moreal changed the title WIP: Apply MPT properly WIP: Validate state root hash Sep 7, 2020
@codecov
Copy link

codecov bot commented Sep 7, 2020

Codecov Report

Merging #986 into main will decrease coverage by 0.19%.
The diff coverage is 84.89%.

@@            Coverage Diff             @@
##             main     #986      +/-   ##
==========================================
- Coverage   89.16%   88.97%   -0.20%     
==========================================
  Files         324      328       +4     
  Lines       29370    29465      +95     
==========================================
+ Hits        26189    26216      +27     
- Misses       1625     1696      +71     
+ Partials     1556     1553       -3     
Impacted Files Coverage Δ
Libplanet.Tests/Net/SwarmTest.Preload.cs 99.22% <ø> (-0.03%) ⬇️
Libplanet/Blocks/InvalidBlockException.cs 50.00% <0.00%> (-50.00%) ⬇️
...lanet/Blocks/InvalidBlockStateRootHashException.cs 26.31% <26.31%> (ø)
Libplanet/Blocks/BlockHeader.cs 90.34% <71.42%> (-1.71%) ⬇️
Libplanet/Action/ActionEvaluationsExtensions.cs 74.07% <74.07%> (ø)
Libplanet.Tests/Blocks/BlockHeaderTest.cs 72.02% <75.00%> (ø)
Libplanet/Blockchain/Policies/BlockPolicy.cs 85.27% <80.00%> (-0.70%) ⬇️
Libplanet/Blocks/Block.cs 84.74% <81.81%> (-0.68%) ⬇️
Libplanet/Blockchain/BlockChain.cs 90.63% <82.75%> (-0.47%) ⬇️
Libplanet/Blockchain/BlockEvaluator.cs 83.11% <83.11%> (ø)
... and 25 more

@moreal moreal added the consensus Related to blockchain consensus label Sep 7, 2020
@moreal moreal marked this pull request as ready for review September 7, 2020 13:48
@moreal moreal changed the title WIP: Validate state root hash Validate state root hash Sep 7, 2020
@moreal moreal changed the title Validate state root hash WIP: Validate state root hash Sep 8, 2020
@moreal moreal force-pushed the feature/state-root-hash branch 2 times, most recently from 753c27a to c809550 Compare September 8, 2020 04:45
@longfin
Copy link
Member

longfin commented Sep 9, 2020

It seems conflicting.

@moreal moreal changed the title WIP: Validate state root hash Validate state root hash Sep 9, 2020
@moreal
Copy link
Contributor Author

moreal commented Sep 9, 2020

It seems conflicting.

@longfin I resolved. You can review them 😀

Comment on lines +235 to +238
- `BlockPolicy<T>` became to validate `Block<T>.StateRootHash` property
of a `Block<T>`. [[#986]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary despite we've never released Block<T>.StateRootHash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason why I added the line, was the behavior of BlockPolicy<T>. As you said, Block<T>.StateRootHash is had never released yet, but BlockPolicy<T> does. Then isn't it right to log the change or is it unnecessary?

where T : IAction, new()
{
private readonly ILogger _logger;
private readonly IAction _blockAction;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private readonly IAction _blockAction;
private readonly IAction? _blockAction;

_balanceGetter;

internal BlockEvaluator(
IAction blockAction,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
IAction blockAction,
IAction? blockAction,

internal HashDigest<SHA256>? SetStates<T>(
Block<T> block,
IImmutableDictionary<string, IValue> states,
bool rehearsal)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this rehearsal option? This seems to be only used when making the genesis block. Since the MakeGenesisBlock method uses an in-memory DefaultKeyValueStore, wouldn't it be okay without this option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I will remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed it in 68090f7. Please check your intention was applied well.

earlbread
earlbread previously approved these changes Sep 11, 2020
@moreal
Copy link
Contributor Author

moreal commented Sep 11, 2020

/rebase

limebell
limebell previously approved these changes Sep 11, 2020
@moreal
Copy link
Contributor Author

moreal commented Sep 11, 2020

/rebase

riemannulus
riemannulus previously approved these changes Sep 11, 2020
moreal and others added 15 commits September 11, 2020 15:28
Originally, it was hard to evaluate blocks properly because blockchain
contained the logic to evaluate and block action (i.e., block policy).
BlockChain required a genesis block but it require logic to evaluate
block and block action. This fixes the interdependence issue.
 - Remove code duplication
 - Remove useless comment
`ExecuteActionsBetweenTrieStateStoreAndBlockStatesStore` is not correct
anymore because `TrieStateStore` and `IBlockStatesStore` doesn't share
 same block layout
 - `InvalidBlockStateRootHashException`

[skip changelog]
Co-Authored-By: Seunghun Lee <waydi1@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consensus Related to blockchain consensus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants