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

Silence RocksDBStore.GetBlockDigest() for non-existent block hashes & release 0.28.2 #1852

Merged
merged 5 commits into from
Mar 15, 2022
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
14 changes: 11 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ Libplanet changelog
Version 0.28.2
--------------

To be released.
Released on March 15, 2022.

- (Libplanet.RocksDBStore) `RocksDBStore.GetBlockDigest()` became to silently
return `null` with no misleading error log when it's asked a non-existent
block hash. [[#1500], [#1852]]

[[#1500]]: https://github.com/planetarium/libplanet/issues/1500
[[#1852]]: https://github.com/planetarium/libplanet/pull/1852


Version 0.28.1
Expand All @@ -14,8 +21,9 @@ Released on March 3, 2022.

- Fixed an evaluation log to output `IPreEvaluationBlock<T>.PreEvaluationHash`
as a hex formatted string. [[#1835], [#1837]]
- Fixed a bug where some messages could not be sent using `NetMQTransport`
due to premature `DealerSocket` disposal. [[#1836], [#1839]]
- (Libplanet.Net) Fixed a bug where some messages could not be sent using
`NetMQTransport` due to premature `DealerSocket` disposal.
[[#1836], [#1839]]

[#1835]: https://github.com/planetarium/libplanet/issues/1835
[#1836]: https://github.com/planetarium/libplanet/issues/1836
Expand Down
5 changes: 4 additions & 1 deletion Libplanet.RocksDBStore/RocksDBStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,10 @@ public override IEnumerable<BlockHash> IterateBlockHashes()
}
}

byte[] blockBytes = blockDb.Get(key);
if (!(blockDb.Get(key) is byte[] blockBytes))
{
return null;
}

BlockDigest blockDigest = BlockDigest.Deserialize(blockBytes);

Expand Down
10 changes: 9 additions & 1 deletion Libplanet/Store/BlockDigest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Numerics;
Expand Down Expand Up @@ -135,11 +136,18 @@ public static BlockDigest FromBlock<T>(Block<T> block)
/// </summary>
/// <param name="bytes">Serialized <see cref="BlockDigest"/>.</param>
/// <returns>Deserialized <see cref="BlockDigest"/>.</returns>
/// <exception cref="ArgumentNullException">Thrown when the passed <paramref name="bytes"/>
/// is <see langword="null"/>.</exception>
/// <exception cref="DecodingException">Thrown when decoded value is not
/// <see cref="Bencodex.Types.Dictionary"/> type.</exception>
public static BlockDigest Deserialize(byte[] bytes)
{
IValue value = new Codec().Decode(bytes);
if (!(bytes is byte[] bytesArray))
{
throw new ArgumentNullException(nameof(bytes));
}

IValue value = new Codec().Decode(bytesArray);
if (!(value is Bencodex.Types.Dictionary dict))
{
throw new DecodingException(
Expand Down
10 changes: 1 addition & 9 deletions Libplanet/Store/DefaultStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,7 @@ public override IEnumerable<BlockHash> IterateBlockHashes()
BlockDigest blockDigest;
try
{
IValue value = Codec.Decode(_blocks.ReadAllBytes(path));
if (!(value is Bencodex.Types.Dictionary dict))
{
throw new DecodingException(
$"Expected {typeof(Bencodex.Types.Dictionary)} but " +
$"{value.GetType()}");
}

blockDigest = new BlockDigest(dict);
blockDigest = BlockDigest.Deserialize(_blocks.ReadAllBytes(path));
}
catch (FileNotFoundException)
{
Expand Down