Skip to content

Commit

Permalink
Merge branch 'main' into add-cjs-support
Browse files Browse the repository at this point in the history
  • Loading branch information
XxshiftxX authored Oct 23, 2023
2 parents 7fbea94 + 559eafd commit 62b1822
Show file tree
Hide file tree
Showing 89 changed files with 2,518 additions and 1,674 deletions.
139 changes: 138 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Libplanet changelog
===================

Version 3.4.0
Version 3.7.0
-------------

To be released.
Expand All @@ -18,12 +18,149 @@ To be released.

### Behavioral changes

- Slightly optimized `BlockMarshaler`. [[#3454]]

### Bug fixes

### Dependencies

### CLI tools

[#3454]: https://github.com/planetarium/libplanet/pull/3454


Version 3.6.0
-------------

Released on October 6, 2023.

### Backward-incompatible API changes

- Changed `IActionEvaluator.Evaluate()`'s return type to
`IReadOnlyList<ICommittedActionEvaluation>` from
`IReadOnlyList<IActionEvaluation>`. [[#3445]]
- Changed `BlockChain.DetermineStateRootHash(IActionEvaluator,
IPreEvaluationBlock, out IReadOnlyList<IActionEvaluation>)` to
`BlockChain.DetermineStateRootHash(IActionEvaluator,
IPreEvaluationBlock, out IReadOnlyList<ICommittedActionEvaluation>)`.
[[#3445]]
- Changed `BlockChain.EvaluateGenesis()`'s return type to
`IReadOnlyList<ICommittedActionEvaluation>` from
`IReadOnlyList<IActionEvaluation>`. [[#3445]]
- Changed `BlockChain.EvaluateBlock()`'s return type to
`IReadOnlyList<ICommittedActionEvaluation>` from
`IReadOnlyList<IActionEvaluation>`. [[#3445]]
- Removed `StateStoreExtensions` class. [[#3323], [#3450]]

### Added APIs

- (Libplanet.Explorer) Added `TxResult.InputState` of type
`HashDigest<SHA256>?`. [[#3446], [#3447]]
- (Libplanet.Explorer) Added `TxResult.OutputState` of type
`HashDigest<SHA256>?`. [[#3446], [#3447]]
- (Libplanet.Explorer) Added `offsetStateRootHash` of type
`HashDigest<SHA256>?` argument for `StateQuery.states` field.
[[#3448], [#3449]]
- (Libplanet.Explorer) Added `offsetStateRootHash` of type
`HashDigest<SHA256>?` argument for `StateQuery.balance` field.
[[#3448], [#3449]]
- (Libplanet.Explorer) Added `offsetStateRootHash` of type
`HashDigest<SHA256>?` argument for `StateQuery.totalSupply` field.
[[#3448], [#3449]]
- (Libplanet.Explorer) Added `offsetStateRootHash` of type
`HashDigest<SHA256>?` argument for `StateQuery.validators` field.
[[#3448], [#3449]]

### Behavioral changes

- `IActionEvaluator.Evaluate()`, `BlockChain.EvaluateGenesis()`,
and `BlockChain.EvaluateBlock()` have a side-effect of storing
data to `IStateStore` when called. [[#3445]]

[#3323]: https://github.com/planetarium/libplanet/issues/3323
[#3445]: https://github.com/planetarium/libplanet/pull/3445
[#3446]: https://github.com/planetarium/libplanet/issues/3446
[#3447]: https://github.com/planetarium/libplanet/pull/3447
[#3448]: https://github.com/planetarium/libplanet/issues/3448
[#3449]: https://github.com/planetarium/libplanet/pull/3449
[#3450]: https://github.com/planetarium/libplanet/pull/3450


Version 3.5.0
-------------

Released on October 4, 2023.

### Backward-incompatible API changes

- Removed `IActionContext.Random` property. Use `IActionContext.GetRandom()`
instead. [[#3437]]
- Added `IActionContext.RandomSeed` property. [[#3437]]
- Added `IActionContext.GetRandom()` method. [[#3437]]
- Changed `IActionEvaluator.Evaluate(IPreEvaluationBlock)` to
`IActionEvaluator.Evaluate(IPreEvaluationBlock, HashDigest<SHA256>)`.
[[#3438]]
- Changed `ActionEvaluator` to accept `IStateStore` instead of
`IBlockChainStates` [[#3439]]

[#3437]: https://github.com/planetarium/libplanet/pull/3437
[#3438]: https://github.com/planetarium/libplanet/pull/3438
[#3439]: https://github.com/planetarium/libplanet/pull/3439


Version 3.4.0
-------------

Released on September 25, 2023.

### Backward-incompatible API changes

- Added `IBlockChainStates.GetAccountState(HashDigest<SHA256>?)`
interface method. [[#3425]]
- Removed `TxFailure.ExceptionMetadata` property. [[#3428]]
- Removed `ISerializable` interface from `TxExecution`, `TxSuccess`,
and `TxFailure`. [[#3428]]
- Removed `TxSuccess` and `TxFailure` class. [[#3429]]
- Changed `TxExecution` class as `sealed` from `abstract.` [[#3429]]
- All properties of `TxExecution` except `BlockHash` and `TxId` were
overhauled. [[#3429]]
- (Libplanet.Store) Removed `IStore.PutTxExecution(TxSuccess)` and
`IStore.PutTxExecution(TxFailure)`;
added `IStore.PutTxExecution(TxExecution)`. [[#3429]]
- (Libplanet.Explorer) Removed `TxResult.ExceptionName` of type `string?`
and added `TxResult.ExceptionNames` of type `List<string?>?`. [[#3429]]
- (Libplanet.Explorer) Removed `TxResult.UpdatedStates` and
`TxResult.UpdatedFungibleAssets`. [[#3429]]
- Changed `IActionRenderer.RenderAction(IValue, IActionContext, IAccount)`
to `IActionRenderer.RenderAction(IValue, ICommittedActionContext,
HashDigest<SHA256>)`. [[#3431]]
- Changed `IActionRenderer.RenderActionError(IValue, IActionContext,
Exception)` to `IActionRenderer.RenderActionError(IValue,
ICommittedActionContext, Exception)`. [[#3431]]

### Added APIs

- Added `AccountDiff` class. [[#3424]]
- Added `ICommittedActionContext` interface. [[#3431]]
- Added `ICommittedActionEvaluation` interface. [[#3431]]

[#3424]: https://github.com/planetarium/libplanet/pull/3424
[#3425]: https://github.com/planetarium/libplanet/pull/3425
[#3428]: https://github.com/planetarium/libplanet/pull/3428
[#3429]: https://github.com/planetarium/libplanet/pull/3429
[#3431]: https://github.com/planetarium/libplanet/pull/3431


Version 3.3.1
-------------

Released on September 8, 2023.

- (Libplanet.Store) Fixed a bug where `ITrie.Get()` could wrongly retrieve
an `IValue` from a non-existent path. [[#3420]]

[#3420]: https://github.com/planetarium/libplanet/pull/3420


Version 3.3.0
-------------
Expand Down
41 changes: 8 additions & 33 deletions Libplanet.Action.Tests/ActionContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void RandomShouldBeDeterministic()
randomSeed: seed,
gasLimit: 0
);
IRandom random = context.Random;
IRandom random = context.GetRandom();
Assert.Equal(expected, random.Next());
}
}
Expand Down Expand Up @@ -93,11 +93,14 @@ public void GuidShouldBeDeterministic()
),
};

var rand1 = context1.GetRandom();
var rand2 = context2.GetRandom();
var rand3 = context3.GetRandom();
foreach (var (expected, diff) in testCases)
{
Assert.Equal(expected, context1.Random.GenerateRandomGuid());
Assert.Equal(expected, context2.Random.GenerateRandomGuid());
Assert.Equal(diff, context3.Random.GenerateRandomGuid());
Assert.Equal(expected, rand1.GenerateRandomGuid());
Assert.Equal(expected, rand2.GenerateRandomGuid());
Assert.Equal(diff, rand3.GenerateRandomGuid());
}
}

Expand All @@ -116,39 +119,11 @@ public void GuidVersionAndVariant()
randomSeed: i,
gasLimit: 0
);
var guid = context.Random.GenerateRandomGuid().ToString();
var guid = context.GetRandom().GenerateRandomGuid().ToString();

Assert.Equal('4', guid[14]);
Assert.True(guid[19] >= '8' && guid[19] <= 'b');
}
}

[Fact]
public void GetUnconsumedContext()
{
var original = new ActionContext(
signer: _address,
txid: _txid,
miner: _address,
blockIndex: 1,
blockProtocolVersion: Block.CurrentProtocolVersion,
previousState: new Account(MockAccountState.Empty),
randomSeed: _random.Next(),
gasLimit: 0);

// Consume original's random state...
int[] values =
{
original.Random.Next(),
original.Random.Next(),
original.Random.Next(),
};

IActionContext clone = original.GetUnconsumedContext();
Assert.Equal(
values,
new[] { clone.Random.Next(), clone.Random.Next(), clone.Random.Next() }
);
}
}
}
2 changes: 1 addition & 1 deletion Libplanet.Action.Tests/Common/DumbAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public IAccount Execute(IActionContext context)
{
states = states.SetState(
RandomRecordsAddress,
(Integer)context.Random.Next()
(Integer)context.GetRandom().Next()
);
}

Expand Down
2 changes: 1 addition & 1 deletion Libplanet.Action.Tests/Common/RandomAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public IAccount Execute(IActionContext context)
return states.SetState(Address, Null.Value);
}

return states.SetState(Address, (Integer)context.Random.Next());
return states.SetState(Address, (Integer)context.GetRandom().Next());
}
}
}
6 changes: 3 additions & 3 deletions Libplanet.Action.Tests/Sys/InitializeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public void Execute()
validatorSet: _validatorSet
);

var nextStates = initialize.Execute(context);
var nextState = initialize.Execute(context);

Assert.Equal(_validatorSet, nextStates.GetValidatorSet());
Assert.Equal(_states[default], nextStates.GetState(default));
Assert.Equal(_validatorSet, nextState.GetValidatorSet());
Assert.Equal(_states[default], nextState.GetState(default));
}

[Fact]
Expand Down
22 changes: 5 additions & 17 deletions Libplanet.Action/ActionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ internal class ActionContext : IActionContext
{
public static readonly AsyncLocal<GasMeter> GetGasMeter = new AsyncLocal<GasMeter>();

private readonly int _randomSeed;
private readonly long _gasLimit;

public ActionContext(
Expand All @@ -32,8 +31,7 @@ public ActionContext(
BlockProtocolVersion = blockProtocolVersion;
Rehearsal = rehearsal;
PreviousState = previousState;
Random = new Random(randomSeed);
_randomSeed = randomSeed;
RandomSeed = randomSeed;
_gasLimit = gasLimit;

GetGasMeter.Value = new GasMeter(_gasLimit);
Expand All @@ -60,27 +58,17 @@ public ActionContext(
/// <inheritdoc cref="IActionContext.PreviousState"/>
public IAccount PreviousState { get; }

/// <inheritdoc cref="IActionContext.Random"/>
public IRandom Random { get; }
/// <inheritdoc cref="IActionContext.RandomSeed"/>
public int RandomSeed { get; }

/// <inheritdoc cref="IActionContext.BlockAction"/>
public bool BlockAction => TxId is null;

/// <inheritdoc cref="IActionContext.UseGas(long)"/>
public void UseGas(long gas) => GetGasMeter.Value?.UseGas(gas);

[Pure]
public IActionContext GetUnconsumedContext() =>
new ActionContext(
Signer,
TxId,
Miner,
BlockIndex,
BlockProtocolVersion,
PreviousState,
_randomSeed,
_gasLimit,
Rehearsal);
/// <inheritdoc cref="IActionContext.GetRandom"/>
public IRandom GetRandom() => new Random(RandomSeed);

/// <summary>
/// Returns the elapsed gas of the current action.
Expand Down
Loading

1 comment on commit 62b1822

@github-actions
Copy link

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Benchmark.Net Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 62b1822 Previous: 559eafd Ratio
Libplanet.Benchmarks.Store.PutFirstEmptyBlock 649930.1648351648 ns (± 189070.6629070061) 307083.23913043475 ns (± 29466.81047293179) 2.12

This comment was automatically generated by workflow using github-action-benchmark.

CC: @libplanet

Please sign in to comment.