From 9b19e86cbf72de8d744d36a21a5e7e070d99fd49 Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Mon, 16 Oct 2023 17:30:44 +0900 Subject: [PATCH 1/2] Bump lib9c to aa95dcff --- Lib9c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib9c b/Lib9c index 0bf659679..aa95dcffd 160000 --- a/Lib9c +++ b/Lib9c @@ -1 +1 @@ -Subproject commit 0bf659679f55122846691ed4fec4cfcb76d81cda +Subproject commit aa95dcffd5f6dac64da413aa1b67bbf6a61b0be9 From ea34b9caaeff30e88e8b94a425947e10226f0bf4 Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Wed, 11 Oct 2023 11:04:18 +0900 Subject: [PATCH 2/2] Accommodate API changes --- .../ForkableActionEvaluatorTest.cs | 33 +++++++------------ .../ForkableActionEvaluator.cs | 2 +- .../Hosting/LibplanetNodeService.cs | 2 +- .../Commands/ChainCommandTest.cs | 10 ++++++ .../Commands/ChainCommand.cs | 4 +-- .../GraphQLServiceExtensions.cs | 1 + .../GraphTypes/StandaloneSubscription.cs | 12 +++---- .../GraphTypes/TransactionHeadlessQuery.cs | 24 ++++++-------- 8 files changed, 41 insertions(+), 47 deletions(-) diff --git a/Libplanet.Extensions.ForkableActionEvaluator.Tests/ForkableActionEvaluatorTest.cs b/Libplanet.Extensions.ForkableActionEvaluator.Tests/ForkableActionEvaluatorTest.cs index a28045b56..3e40b03c0 100644 --- a/Libplanet.Extensions.ForkableActionEvaluator.Tests/ForkableActionEvaluatorTest.cs +++ b/Libplanet.Extensions.ForkableActionEvaluator.Tests/ForkableActionEvaluatorTest.cs @@ -5,11 +5,8 @@ using Libplanet.Types.Blocks; using Libplanet.Common; using Libplanet.Crypto; -using Libplanet.Extensions.ActionEvaluatorCommonComponents; using Libplanet.Types.Tx; -using ActionEvaluation = Libplanet.Extensions.ActionEvaluatorCommonComponents.ActionEvaluation; using ArgumentOutOfRangeException = System.ArgumentOutOfRangeException; -using Random = Libplanet.Extensions.ActionEvaluatorCommonComponents.Random; namespace Libplanet.Extensions.ForkableActionEvaluator.Tests; @@ -64,26 +61,23 @@ public void CheckPairs() class PostActionEvaluator : IActionEvaluator { public IActionLoader ActionLoader => throw new NotSupportedException(); - public IReadOnlyList Evaluate(IPreEvaluationBlock block, HashDigest? baseStateroothash) + public IReadOnlyList Evaluate(IPreEvaluationBlock block, HashDigest? baseStateroothash) { - return new IActionEvaluation[] + return new ICommittedActionEvaluation[] { - new ActionEvaluation( + new CommittedActionEvaluation( (Text)"POST", - new ActionContext( - null, + new CommittedActionContext( default, null, default, 0, 0, false, - new AccountStateDelta(), + default, 0, - null, false), - new AccountStateDelta(), - null) + default) }; } } @@ -91,26 +85,23 @@ public IReadOnlyList Evaluate(IPreEvaluationBlock block, Hash class PreActionEvaluator : IActionEvaluator { public IActionLoader ActionLoader => throw new NotSupportedException(); - public IReadOnlyList Evaluate(IPreEvaluationBlock block, HashDigest? baseStateRootHash) + public IReadOnlyList Evaluate(IPreEvaluationBlock block, HashDigest? baseStateRootHash) { - return new IActionEvaluation[] + return new ICommittedActionEvaluation[] { - new ActionEvaluation( + new CommittedActionEvaluation( (Text)"PRE", - new ActionContext( - null, + new CommittedActionContext( default, null, default, 0, 0, false, - new AccountStateDelta(), + default, 0, - null, false), - new AccountStateDelta(), - null) + default) }; } } diff --git a/Libplanet.Extensions.ForkableActionEvaluator/ForkableActionEvaluator.cs b/Libplanet.Extensions.ForkableActionEvaluator/ForkableActionEvaluator.cs index 1e5f47214..651794876 100644 --- a/Libplanet.Extensions.ForkableActionEvaluator/ForkableActionEvaluator.cs +++ b/Libplanet.Extensions.ForkableActionEvaluator/ForkableActionEvaluator.cs @@ -17,7 +17,7 @@ public ForkableActionEvaluator(IEnumerable<((long StartIndex, long EndIndex) Ran public IActionLoader ActionLoader => throw new NotSupportedException(); - public IReadOnlyList Evaluate( + public IReadOnlyList Evaluate( IPreEvaluationBlock block, HashDigest? baseStateRootHash) { var actionEvaluator = _router.GetEvaluator(block.Index); diff --git a/Libplanet.Headless/Hosting/LibplanetNodeService.cs b/Libplanet.Headless/Hosting/LibplanetNodeService.cs index 2b99920d1..cc5a3d55a 100644 --- a/Libplanet.Headless/Hosting/LibplanetNodeService.cs +++ b/Libplanet.Headless/Hosting/LibplanetNodeService.cs @@ -121,7 +121,7 @@ IActionEvaluator BuildActionEvaluator(IActionEvaluatorConfiguration actionEvalua return actionEvaluatorConfiguration switch { RemoteActionEvaluatorConfiguration remoteActionEvaluatorConfiguration => new RemoteActionEvaluator( - new Uri(remoteActionEvaluatorConfiguration.StateServiceEndpoint), blockChainStates), + new Uri(remoteActionEvaluatorConfiguration.StateServiceEndpoint)), DefaultActionEvaluatorConfiguration _ => new ActionEvaluator( _ => blockPolicy.BlockAction, stateStore: StateStore, diff --git a/NineChronicles.Headless.Executable.Tests/Commands/ChainCommandTest.cs b/NineChronicles.Headless.Executable.Tests/Commands/ChainCommandTest.cs index 36f7fbbd9..a14f5c529 100644 --- a/NineChronicles.Headless.Executable.Tests/Commands/ChainCommandTest.cs +++ b/NineChronicles.Headless.Executable.Tests/Commands/ChainCommandTest.cs @@ -242,7 +242,16 @@ public void PruneState(StoreType storeType) stateStore, genesisBlock, actionEvaluator); + + // Additional pruning is now required since in-between commits are made + store.Dispose(); + stateStore.Dispose(); + _command.PruneStates(storeType, _storePath); + store = storeType.CreateStore(_storePath); + stateKeyValueStore = new RocksDBKeyValueStore(statesPath); + stateStore = new TrieStateStore(stateKeyValueStore); int prevStatesCount = stateKeyValueStore.ListKeys().Count(); + stateKeyValueStore.Set( new KeyBytes("alpha"), ByteUtil.ParseHex("00")); @@ -250,6 +259,7 @@ public void PruneState(StoreType storeType) new KeyBytes("beta"), ByteUtil.ParseHex("00")); Assert.Equal(prevStatesCount + 2, stateKeyValueStore.ListKeys().Count()); + store.Dispose(); stateStore.Dispose(); _command.PruneStates(storeType, _storePath); diff --git a/NineChronicles.Headless.Executable/Commands/ChainCommand.cs b/NineChronicles.Headless.Executable/Commands/ChainCommand.cs index c5333094b..11184493a 100644 --- a/NineChronicles.Headless.Executable/Commands/ChainCommand.cs +++ b/NineChronicles.Headless.Executable/Commands/ChainCommand.cs @@ -284,7 +284,7 @@ public void Truncate( } snapshotTipHash = hash; - } while (!stateStore.ContainsStateRoot(store.GetBlock(snapshotTipHash).StateRootHash)); + } while (!stateStore.GetStateRoot(store.GetBlock(snapshotTipHash).StateRootHash).Recorded); var forkedId = Guid.NewGuid(); @@ -484,7 +484,7 @@ public void Snapshot( } snapshotTipHash = hash; - } while (!stateStore.ContainsStateRoot(store.GetBlock(snapshotTipHash).StateRootHash)); + } while (!stateStore.GetStateRoot(store.GetBlock(snapshotTipHash).StateRootHash).Recorded); var forkedId = Guid.NewGuid(); diff --git a/NineChronicles.Headless/GraphQLServiceExtensions.cs b/NineChronicles.Headless/GraphQLServiceExtensions.cs index cad7d67af..4679ef4e7 100644 --- a/NineChronicles.Headless/GraphQLServiceExtensions.cs +++ b/NineChronicles.Headless/GraphQLServiceExtensions.cs @@ -45,6 +45,7 @@ public static IServiceCollection AddLibplanetScalarTypes(this IServiceCollection services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); + services.TryAddSingleton(); return services; } diff --git a/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs b/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs index 8b249aebc..bf3c025b7 100644 --- a/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs +++ b/NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs @@ -322,16 +322,12 @@ private IObservable SubscribeTx(IResolveFieldContext context) } var txExecution = store.GetTxExecution(blockHash, transaction.Id); var txExecutedBlock = chain[blockHash]; - return txExecution.Fail - ? new TxResult( - TxStatus.FAILURE, - txExecutedBlock.Index, - txExecutedBlock.Hash.ToString(), - txExecution.ExceptionNames) - : new TxResult( - TxStatus.SUCCESS, + return new TxResult( + txExecution.Fail ? TxStatus.FAILURE : TxStatus.SUCCESS, txExecutedBlock.Index, txExecutedBlock.Hash.ToString(), + txExecution.InputState, + txExecution.OutputState, txExecution.ExceptionNames); } diff --git a/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs b/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs index a3cdad940..86f227fe0 100644 --- a/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs +++ b/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs @@ -208,29 +208,25 @@ public TransactionHeadlessQuery(StandaloneContext standaloneContext) if (!(store.GetFirstTxIdBlockHashIndex(txId) is { } txExecutedBlockHash)) { return blockChain.GetStagedTransactionIds().Contains(txId) - ? new TxResult(TxStatus.STAGING, null, null, null) - : new TxResult(TxStatus.INVALID, null, null, null); + ? new TxResult(TxStatus.STAGING, null, null, null, null, null) + : new TxResult(TxStatus.INVALID, null, null, null, null, null); } try { TxExecution execution = blockChain.GetTxExecution(txExecutedBlockHash, txId); Block txExecutedBlock = blockChain[txExecutedBlockHash]; - return execution.Fail - ? new TxResult( - TxStatus.FAILURE, - txExecutedBlock.Index, - txExecutedBlock.Hash.ToString(), - execution.ExceptionNames) - : new TxResult( - TxStatus.SUCCESS, - txExecutedBlock.Index, - txExecutedBlock.Hash.ToString(), - execution.ExceptionNames); + return new TxResult( + execution.Fail ? TxStatus.FAILURE : TxStatus.SUCCESS, + txExecutedBlock.Index, + txExecutedBlock.Hash.ToString(), + execution.InputState, + execution.OutputState, + execution.ExceptionNames); } catch (Exception) { - return new TxResult(TxStatus.INVALID, null, null, null); + return new TxResult(TxStatus.INVALID, null, null, null, null, null); } } );