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

Calculate state when evaluating an action if the block state doesn't exist #645

Merged
merged 1 commit into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ To be released.
not related with [Kademlia protocol][Kademlia]. [[#594], [#627]]
- `Swarm<T>` became not to check least recently used peer every time when
new peer is fetched. [[#627]]
- `IAction` became guaranteed that the given
`IActionContext.PreviousStates.GetState()` never throws
`IncompleteBlockStatesException`. Instead, now it may calculate the
incomplete states from the beginning if necessary. [[#645]]
- `IStore.PutBlock<T>()` became to do nothing when it takes
the `Block<T>` more than once. [[#647]]

Expand Down Expand Up @@ -154,6 +158,8 @@ To be released.
[#637]: https://github.com/planetarium/libplanet/pull/637
[#641]: https://github.com/planetarium/libplanet/pull/641
[#644]: https://github.com/planetarium/libplanet/pull/644
[#645]: https://github.com/planetarium/libplanet/pull/645
[#647]: https://github.com/planetarium/libplanet/pull/647


Version 0.6.0
Expand Down
28 changes: 4 additions & 24 deletions Libplanet/Blockchain/BlockChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,19 +384,7 @@ public AddressStateMap GetState(
continue;
}

List<ActionEvaluation> evaluations =
b.Evaluate(
DateTimeOffset.UtcNow,
a => GetState(
a,
b.PreviousHash
).GetValueOrDefault(a)
).ToList();

if (Policy.BlockAction is IAction)
{
evaluations.Add(EvaluateBlockAction(b, evaluations));
}
IReadOnlyList<ActionEvaluation> evaluations = EvaluateActions(b);

_rwlock.EnterWriteLock();

Expand Down Expand Up @@ -845,7 +833,7 @@ internal IReadOnlyList<ActionEvaluation> EvaluateActions(Block<T> block)
}
else
{
stateGetter = a => GetState(a, block.PreviousHash).GetValueOrDefault(a);
stateGetter = a => GetState(a, block.PreviousHash, true).GetValueOrDefault(a);
}

ImmutableList<ActionEvaluation> txEvaluations = block
Expand Down Expand Up @@ -881,7 +869,7 @@ internal ActionEvaluation EvaluateBlockAction(
if (lastStates is null)
{
lastStates = new AccountStateDeltaImpl(
a => GetState(a, block.PreviousHash).GetValueOrDefault(a));
a => GetState(a, block.PreviousHash, true).GetValueOrDefault(a));
}

return ActionEvaluation.EvaluateActionsGradually(
Expand Down Expand Up @@ -1136,15 +1124,7 @@ t.PreviousHash is HashDigest<SHA256> tp &&
b = this[ph]
)
{
List<ActionEvaluation> evaluations = b.EvaluateActionsPerTx(a =>
GetState(a, b.PreviousHash).GetValueOrDefault(a))
.Select(te => te.Item2).ToList();

if (Policy.BlockAction is IAction)
{
evaluations.Add(EvaluateBlockAction(b, evaluations));
}

List<ActionEvaluation> evaluations = EvaluateActions(b).ToList();
evaluations.Reverse();

foreach (var evaluation in evaluations)
Expand Down