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

feat: execute states by condition #3978

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ To be released.

### Behavioral changes

- Added `DetermineNextBlockStateRootHash` property to `BlockChain.BlockChain`.
[[#3977], [#3978]]

### Bug fixes

### Dependencies
Expand All @@ -41,6 +44,8 @@ To be released.

[#3912]: https://github.com/planetarium/libplanet/pull/3912
[#3974]: https://github.com/planetarium/libplanet/pull/3974
[#3977]: https://github.com/planetarium/libplanet/issue/3977
[#3978]: https://github.com/planetarium/libplanet/pull/3978


Version 5.3.1
Expand Down
21 changes: 14 additions & 7 deletions src/Libplanet/Blockchain/BlockChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Libplanet.Blockchain
/// <para>
/// In order to watch its state changes, implement <see cref="IRenderer"/> interface
/// and pass it to the
/// <see cref="BlockChain(IBlockPolicy, IStagePolicy, IStore, IStateStore, Block, IBlockChainStates, IActionEvaluator, IEnumerable{IRenderer})"/>
/// <see cref="BlockChain(IBlockPolicy, IStagePolicy, IStore, IStateStore, Block, IBlockChainStates, IActionEvaluator, IEnumerable{IRenderer}, bool)"/>
/// constructor.
/// </para>
/// </summary>
Expand Down Expand Up @@ -90,6 +90,9 @@ public partial class BlockChain : IBlockChainStates
/// by default or if it is <see langword="null"/>. Note that action renderers receive
/// events made by unsuccessful transactions as well.</param>
/// <param name="stateStore"><see cref="IStateStore"/> to store states.</param>
/// <param name="determineNextBlockStateRootHash">
/// Whether to determine the next block's state root hash when the chain is instantiated.
/// </param>
/// <exception cref="ArgumentException">Thrown when <paramref name="store"/> does not
/// have canonical chain id set, i.e. <see cref="IStore.GetCanonicalChainId()"/> is
/// <see langword="null"/>.</exception>
Expand All @@ -106,7 +109,8 @@ public BlockChain(
Block genesisBlock,
IBlockChainStates blockChainStates,
IActionEvaluator actionEvaluator,
IEnumerable<IRenderer> renderers = null)
IEnumerable<IRenderer> renderers = null,
bool determineNextBlockStateRootHash = true)
#pragma warning disable SA1118 // The parameter spans multiple lines
: this(
policy,
Expand All @@ -120,7 +124,8 @@ public BlockChain(
genesisBlock,
blockChainStates,
actionEvaluator,
renderers)
renderers,
determineNextBlockStateRootHash)
{
}

Expand All @@ -133,7 +138,8 @@ private BlockChain(
Block genesisBlock,
IBlockChainStates blockChainStates,
IActionEvaluator actionEvaluator,
IEnumerable<IRenderer> renderers)
IEnumerable<IRenderer> renderers,
bool determineNextBlockStateRootHash)
{
if (store is null)
{
Expand Down Expand Up @@ -190,7 +196,7 @@ private BlockChain(
{
_nextStateRootHash = Tip.StateRootHash;
}
else
else if (determineNextBlockStateRootHash)
{
_nextStateRootHash =
DetermineNextBlockStateRootHash(Tip, out var actionEvaluations);
Expand Down Expand Up @@ -224,7 +230,7 @@ private BlockChain(
/// <remarks>
/// Since this value is immutable, renderers cannot be registered after once a <see
/// cref="BlockChain"/> object is instantiated; use <c>renderers</c> option of
/// <see cref="BlockChain(IBlockPolicy, IStagePolicy, IStore, IStateStore, Block, IBlockChainStates, IActionEvaluator, IEnumerable{IRenderer})"/>
/// <see cref="BlockChain(IBlockPolicy, IStagePolicy, IStore, IStateStore, Block, IBlockChainStates, IActionEvaluator, IEnumerable{IRenderer}, bool)"/>
/// constructor instead.
/// </remarks>
#pragma warning restore MEN002
Expand Down Expand Up @@ -441,7 +447,8 @@ public static BlockChain Create(
genesisBlock,
blockChainStates,
actionEvaluator,
renderers);
renderers,
true);
}

/// <summary>
Expand Down
Loading