-
Notifications
You must be signed in to change notification settings - Fork 139
/
InvalidBlockStateRootHashException.cs
64 lines (58 loc) · 2.35 KB
/
InvalidBlockStateRootHashException.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Diagnostics.Contracts;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using Libplanet.Serialization;
namespace Libplanet.Blocks
{
/// <summary>
/// The exception that is thrown when the state root hash in the block has
/// mismatches to the state root hash of the trie on the block executed in local.
/// </summary>
[Serializable]
public class InvalidBlockStateRootHashException : InvalidBlockException
{
/// <summary>
/// Initializes a new instance of the
/// <see cref="InvalidBlockStateRootHashException"/> class.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="expectedStateRootHash">The hash recorded as
/// <see cref="Block{T}.StateRootHash"/>>.</param>
/// <param name="actualStateRootHash">The hash of state trie on the block executed.</param>
public InvalidBlockStateRootHashException(
string message,
HashDigest<SHA256> expectedStateRootHash,
HashDigest<SHA256> actualStateRootHash)
: base(message)
{
ActualStateRootHash = actualStateRootHash;
ExpectedStateRootHash = expectedStateRootHash;
}
private InvalidBlockStateRootHashException(
SerializationInfo info, StreamingContext context)
: base(info, context)
{
ActualStateRootHash =
info.GetValue<HashDigest<SHA256>>(nameof(ActualStateRootHash));
ExpectedStateRootHash =
info.GetValue<HashDigest<SHA256>>(nameof(ExpectedStateRootHash));
}
/// <summary>
/// The hash of state trie on the block executed.
/// </summary>
[Pure]
public HashDigest<SHA256> ActualStateRootHash { get; }
/// <summary>
/// The hash recorded as <see cref="Block{T}.StateRootHash"/>>.
/// </summary>
[Pure]
public HashDigest<SHA256> ExpectedStateRootHash { get; }
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue(nameof(ActualStateRootHash), ActualStateRootHash);
info.AddValue(nameof(ExpectedStateRootHash), ExpectedStateRootHash);
}
}
}