Skip to content

Commit de936b0

Browse files
committed
feat: execute states by condition
1 parent c1a1c5e commit de936b0

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ To be released.
3131

3232
### Added APIs
3333

34+
- Added `DetermineNextBlockStateRootHash()` method to `BlockChain`.
35+
[[#3977], [#3978]]
36+
3437
### Behavioral changes
3538

3639
### Bug fixes
@@ -41,6 +44,8 @@ To be released.
4144

4245
[#3912]: https://github.com/planetarium/libplanet/pull/3912
4346
[#3974]: https://github.com/planetarium/libplanet/pull/3974
47+
[#3977]: https://github.com/planetarium/libplanet/issue/3977
48+
[#3978]: https://github.com/planetarium/libplanet/pull/3978
4449

4550

4651
Version 5.3.1

src/Libplanet/Blockchain/BlockChain.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace Libplanet.Blockchain
3333
/// <para>
3434
/// In order to watch its state changes, implement <see cref="IRenderer"/> interface
3535
/// and pass it to the
36-
/// <see cref="BlockChain(IBlockPolicy, IStagePolicy, IStore, IStateStore, Block, IBlockChainStates, IActionEvaluator, IEnumerable{IRenderer})"/>
36+
/// <see cref="BlockChain(IBlockPolicy, IStagePolicy, IStore, IStateStore, Block, IBlockChainStates, IActionEvaluator, IEnumerable{IRenderer}, bool)"/>
3737
/// constructor.
3838
/// </para>
3939
/// </summary>
@@ -90,6 +90,9 @@ public partial class BlockChain : IBlockChainStates
9090
/// by default or if it is <see langword="null"/>. Note that action renderers receive
9191
/// events made by unsuccessful transactions as well.</param>
9292
/// <param name="stateStore"><see cref="IStateStore"/> to store states.</param>
93+
/// <param name="determineNextBlockStateRootHash">
94+
/// Whether to determine the next block's state root hash when the chain is instantiated.
95+
/// </param>
9396
/// <exception cref="ArgumentException">Thrown when <paramref name="store"/> does not
9497
/// have canonical chain id set, i.e. <see cref="IStore.GetCanonicalChainId()"/> is
9598
/// <see langword="null"/>.</exception>
@@ -106,7 +109,8 @@ public BlockChain(
106109
Block genesisBlock,
107110
IBlockChainStates blockChainStates,
108111
IActionEvaluator actionEvaluator,
109-
IEnumerable<IRenderer> renderers = null)
112+
IEnumerable<IRenderer> renderers = null,
113+
bool determineNextBlockStateRootHash = true)
110114
#pragma warning disable SA1118 // The parameter spans multiple lines
111115
: this(
112116
policy,
@@ -120,7 +124,8 @@ public BlockChain(
120124
genesisBlock,
121125
blockChainStates,
122126
actionEvaluator,
123-
renderers)
127+
renderers,
128+
determineNextBlockStateRootHash)
124129
{
125130
}
126131

@@ -133,7 +138,8 @@ private BlockChain(
133138
Block genesisBlock,
134139
IBlockChainStates blockChainStates,
135140
IActionEvaluator actionEvaluator,
136-
IEnumerable<IRenderer> renderers)
141+
IEnumerable<IRenderer> renderers,
142+
bool determineNextBlockStateRootHash)
137143
{
138144
if (store is null)
139145
{
@@ -190,7 +196,7 @@ private BlockChain(
190196
{
191197
_nextStateRootHash = Tip.StateRootHash;
192198
}
193-
else
199+
else if (determineNextBlockStateRootHash)
194200
{
195201
_nextStateRootHash =
196202
DetermineNextBlockStateRootHash(Tip, out var actionEvaluations);
@@ -224,7 +230,7 @@ private BlockChain(
224230
/// <remarks>
225231
/// Since this value is immutable, renderers cannot be registered after once a <see
226232
/// cref="BlockChain"/> object is instantiated; use <c>renderers</c> option of
227-
/// <see cref="BlockChain(IBlockPolicy, IStagePolicy, IStore, IStateStore, Block, IBlockChainStates, IActionEvaluator, IEnumerable{IRenderer})"/>
233+
/// <see cref="BlockChain(IBlockPolicy, IStagePolicy, IStore, IStateStore, Block, IBlockChainStates, IActionEvaluator, IEnumerable{IRenderer}, bool)"/>
228234
/// constructor instead.
229235
/// </remarks>
230236
#pragma warning restore MEN002
@@ -441,7 +447,8 @@ public static BlockChain Create(
441447
genesisBlock,
442448
blockChainStates,
443449
actionEvaluator,
444-
renderers);
450+
renderers,
451+
true);
445452
}
446453

447454
/// <summary>

0 commit comments

Comments
 (0)