-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3432 from planetarium/migrate/iaccount-to-itrie
Migrate to `ITrie`
- Loading branch information
Showing
53 changed files
with
1,618 additions
and
1,121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System.Diagnostics.Contracts; | ||
using System.Security.Cryptography; | ||
using Libplanet.Common; | ||
using Libplanet.Crypto; | ||
using Libplanet.Types.Tx; | ||
|
||
namespace Libplanet.Action | ||
{ | ||
public class CommittedActionContext : ICommittedActionContext | ||
{ | ||
public CommittedActionContext(IActionContext context) | ||
: this( | ||
signer: context.Signer, | ||
txId: context.TxId, | ||
miner: context.Miner, | ||
blockIndex: context.BlockIndex, | ||
blockProtocolVersion: context.BlockProtocolVersion, | ||
rehearsal: context.Rehearsal, | ||
previousState: context.PreviousState.Trie.Hash, | ||
random: context.Random, | ||
blockAction: context.BlockAction) | ||
{ | ||
} | ||
|
||
public CommittedActionContext( | ||
Address signer, | ||
TxId? txId, | ||
Address miner, | ||
long blockIndex, | ||
int blockProtocolVersion, | ||
bool rehearsal, | ||
HashDigest<SHA256> previousState, | ||
IRandom random, | ||
bool blockAction) | ||
{ | ||
Signer = signer; | ||
TxId = txId; | ||
Miner = miner; | ||
BlockIndex = blockIndex; | ||
BlockProtocolVersion = blockProtocolVersion; | ||
Rehearsal = rehearsal; | ||
PreviousState = previousState; | ||
Random = random; | ||
BlockAction = blockAction; | ||
} | ||
|
||
/// <inheritdoc cref="ICommittedActionContext.Signer"/> | ||
[Pure] | ||
public Address Signer { get; } | ||
|
||
/// <inheritdoc cref="ICommittedActionContext.TxId"/> | ||
[Pure] | ||
public TxId? TxId { get; } | ||
|
||
/// <inheritdoc cref="ICommittedActionContext.Miner"/> | ||
[Pure] | ||
public Address Miner { get; } | ||
|
||
/// <inheritdoc cref="ICommittedActionContext.BlockIndex"/> | ||
[Pure] | ||
public long BlockIndex { get; } | ||
|
||
/// <inheritdoc cref="ICommittedActionContext.BlockProtocolVersion"/> | ||
[Pure] | ||
public int BlockProtocolVersion { get; } | ||
|
||
/// <inheritdoc cref="ICommittedActionContext.Rehearsal"/> | ||
[Pure] | ||
public bool Rehearsal { get; } | ||
|
||
/// <inheritdoc cref="ICommittedActionContext.PreviousState"/> | ||
[Pure] | ||
public HashDigest<SHA256> PreviousState { get; } | ||
|
||
/// <inheritdoc cref="ICommittedActionContext.Random"/> | ||
public IRandom Random { get; } | ||
|
||
/// <inheritdoc cref="ICommittedActionContext.BlockAction"/> | ||
[Pure] | ||
public bool BlockAction { get; } | ||
|
||
/// <inheritdoc cref="ICommittedActionContext.Copy"/> | ||
[Pure] | ||
public ICommittedActionContext Copy() => | ||
new CommittedActionContext( | ||
Signer, | ||
TxId, | ||
Miner, | ||
BlockIndex, | ||
BlockProtocolVersion, | ||
Rehearsal, | ||
PreviousState, | ||
new Random(Random.Seed), | ||
BlockAction); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Security.Cryptography; | ||
using Bencodex.Types; | ||
using Libplanet.Common; | ||
|
||
namespace Libplanet.Action | ||
{ | ||
/// <summary> | ||
/// A record type to represent an evaluation plan and result of | ||
/// a single action. | ||
/// </summary> | ||
public class CommittedActionEvaluation : ICommittedActionEvaluation | ||
{ | ||
/// <summary> | ||
/// Creates an <see cref="CommittedActionEvaluation"/> instance | ||
/// with filling properties. | ||
/// </summary> | ||
/// <param name="action">An action to evaluate.</param> | ||
/// <param name="inputContext">An input <see cref="IActionContext"/> to | ||
/// evaluate <paramref name="action"/>.</param> | ||
/// <param name="outputState">The result states that | ||
/// <paramref name="action"/> makes.</param> | ||
/// <param name="exception">An exception that has risen during evaluating a given | ||
/// <paramref name="action"/>.</param> | ||
public CommittedActionEvaluation( | ||
IValue action, | ||
ICommittedActionContext inputContext, | ||
HashDigest<SHA256> outputState, | ||
Exception? exception = null) | ||
{ | ||
Action = action; | ||
InputContext = inputContext; | ||
OutputState = outputState; | ||
Exception = exception; | ||
} | ||
|
||
/// <summary> | ||
/// An action to evaluate. | ||
/// </summary> | ||
public IValue Action { get; } | ||
|
||
/// <summary> | ||
/// An input <see cref="ICommittedActionContext"/> to evaluate | ||
/// <see cref="Action"/>. | ||
/// </summary> | ||
/// <remarks>Its <see cref="ICommittedActionContext.Random"/> property | ||
/// is not consumed yet.</remarks> | ||
public ICommittedActionContext InputContext { get; } | ||
|
||
/// <summary> | ||
/// The result states that <see cref="Action"/> makes. | ||
/// </summary> | ||
public HashDigest<SHA256> OutputState { get; } | ||
|
||
/// <summary> | ||
/// An exception that had risen during evaluation. | ||
/// </summary> | ||
public Exception? Exception { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System.Diagnostics.Contracts; | ||
using System.Security.Cryptography; | ||
using Libplanet.Common; | ||
using Libplanet.Crypto; | ||
using Libplanet.Types.Blocks; | ||
using Libplanet.Types.Tx; | ||
|
||
namespace Libplanet.Action | ||
{ | ||
/// <summary> | ||
/// Contextual data determined by a transaction and a block for rendering. | ||
/// </summary> | ||
public interface ICommittedActionContext | ||
{ | ||
/// <summary> | ||
/// The <see cref="Transaction.Signer"/> of the <see cref="Transaction"/> that contains | ||
/// the <see cref="IAction"/> to be executed. If the <see cref="IAction"/> is | ||
/// not part of a <see cref="Transaction"/>, e.g. <see cref="IBlockPolicy.BlockAction"/>, | ||
/// this is set to <see cref="Block.Miner"/> instead. | ||
/// </summary> | ||
[Pure] | ||
Address Signer { get; } | ||
|
||
/// <summary> | ||
/// The <see cref="Transaction.Id"/> of the <see cref="Transaction"/> that contains | ||
/// the <see cref="IAction"/>. If the <see cref="IAction"/> is not part of | ||
/// a <see cref="Transaction"/>, e.g. <see cref="IBlockPolicy.BlockAction"/>, | ||
/// this is set to <see langword="null"/>. | ||
/// </summary> | ||
[Pure] | ||
TxId? TxId { get; } | ||
|
||
/// <summary> | ||
/// The <see cref="Block.Miner"/> of the <see cref="Block"/> that contains | ||
/// the <see cref="IAction"/>. | ||
/// </summary> | ||
[Pure] | ||
Address Miner { get; } | ||
|
||
/// <summary> | ||
/// The <see cref="Block.Index"/> of the <see cref="Block"/> that contains | ||
/// the <see cref="IAction"/>. | ||
/// </summary> | ||
[Pure] | ||
long BlockIndex { get; } | ||
|
||
/// <summary> | ||
/// The <see cref="Block.ProtocolVersion"/> of the <see cref="Block"/> that contains | ||
/// the <see cref="IAction"/>. | ||
/// </summary> | ||
[Pure] | ||
int BlockProtocolVersion { get; } | ||
|
||
/// <summary> | ||
/// Whether an <see cref="IAction"/> is being executed during | ||
/// “rehearsal mode”, that there is nothing | ||
/// in <see cref="PreviousState"/>. | ||
/// </summary> | ||
[Pure] | ||
bool Rehearsal { get; } | ||
|
||
/// <summary> | ||
/// The state root hash of the previous state. | ||
/// </summary> | ||
[Pure] | ||
HashDigest<SHA256> PreviousState { get; } | ||
|
||
/// <summary> | ||
/// An initialized pseudorandom number generator. Its seed (state) | ||
/// is determined by a block and a transaction, which is | ||
/// deterministic so that every node can replay the same action and | ||
/// then reproduce the same result, while neither a single block miner | ||
/// nor a single transaction signer can predict the result and cheat. | ||
/// </summary> | ||
/// <returns>A random object that shares interface mostly equivalent | ||
/// to <see cref="System.Random"/>.</returns> | ||
IRandom Random { get; } | ||
|
||
/// <summary> | ||
/// Whether this action is executed as a block action. | ||
/// <see langword="false"/> if it belongs to a transaction. | ||
/// </summary> | ||
[Pure] | ||
bool BlockAction { get; } | ||
|
||
ICommittedActionContext Copy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Security.Cryptography; | ||
using Bencodex.Types; | ||
using Libplanet.Common; | ||
|
||
namespace Libplanet.Action | ||
{ | ||
public interface ICommittedActionEvaluation | ||
{ | ||
/// <summary> | ||
/// An action data to evaluate. When the | ||
/// <see cref="InputContext"/>.<see cref="IActionContext.BlockAction"/> is true, | ||
/// use <see cref="IBlockPolicy.BlockAction"/> instead of trying deserialization. | ||
/// </summary> | ||
public IValue Action { get; } | ||
|
||
/// <summary> | ||
/// An input <see cref="IActionContext"/> to evaluate | ||
/// <see cref="Action"/>. | ||
/// </summary> | ||
/// <remarks>Its <see cref="IActionContext.Random"/> property | ||
/// is not consumed yet.</remarks> | ||
public ICommittedActionContext InputContext { get; } | ||
|
||
/// <summary> | ||
/// The result states that <see cref="Action"/> makes. | ||
/// </summary> | ||
public HashDigest<SHA256> OutputState { get; } | ||
|
||
/// <summary> | ||
/// An exception that had risen during evaluation. | ||
/// </summary> | ||
public Exception? Exception { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
#nullable disable | ||
using System; | ||
|
||
namespace Libplanet.Action | ||
{ | ||
internal class Random : System.Random, IRandom | ||
|
Oops, something went wrong.