Skip to content

Commit

Permalink
feat: execute states by condition
Browse files Browse the repository at this point in the history
  • Loading branch information
riemannulus committed Oct 28, 2024
1 parent c1a1c5e commit de936b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ To be released.

### Added APIs

- Added `DetermineNextBlockStateRootHash()` method to `BlockChain`.
[[#3977], [#3978]]

### Behavioral changes

### Bug fixes
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

0 comments on commit de936b0

Please sign in to comment.