From 3901aabccb65d1e8d311e867ec227481f554a181 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Wed, 6 Dec 2023 13:38:09 +0900 Subject: [PATCH 01/15] Bump lib9c --- Lib9c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib9c b/Lib9c index c8247aaa0..25b6250f4 160000 --- a/Lib9c +++ b/Lib9c @@ -1 +1 @@ -Subproject commit c8247aaa03dd1d009c430e701a6c0aa020de3e52 +Subproject commit 25b6250f467c2b40a2bdcf38b74a8be7b2bb220e From 6351a7ec3efb0fa2583cd21cfadd6e9ff8290f88 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Thu, 7 Dec 2023 10:11:38 +0900 Subject: [PATCH 02/15] Bump lib9c --- Lib9c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib9c b/Lib9c index 25b6250f4..51794f64c 160000 --- a/Lib9c +++ b/Lib9c @@ -1 +1 @@ -Subproject commit 25b6250f467c2b40a2bdcf38b74a8be7b2bb220e +Subproject commit 51794f64c642e247a15ce2d084faab377db09dc2 From 4d3171daff5442958127d586224d96602a20c89d Mon Sep 17 00:00:00 2001 From: Suho Lee Date: Thu, 7 Dec 2023 16:07:21 +0900 Subject: [PATCH 03/15] fix: add action loader for `Forkable` and `Plugged` --- .../ForkableActionEvaluator.cs | 8 ++++++-- .../PluggedActionEvaluator.cs | 8 ++++++-- Libplanet.Headless/Hosting/LibplanetNodeService.cs | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Libplanet.Extensions.ForkableActionEvaluator/ForkableActionEvaluator.cs b/Libplanet.Extensions.ForkableActionEvaluator/ForkableActionEvaluator.cs index 651794876..bf067c6ca 100644 --- a/Libplanet.Extensions.ForkableActionEvaluator/ForkableActionEvaluator.cs +++ b/Libplanet.Extensions.ForkableActionEvaluator/ForkableActionEvaluator.cs @@ -10,12 +10,16 @@ public class ForkableActionEvaluator : IActionEvaluator { private readonly HardForkRouter _router; - public ForkableActionEvaluator(IEnumerable<((long StartIndex, long EndIndex) Range, IActionEvaluator ActionEvaluator)> pairs) + public ForkableActionEvaluator(IEnumerable<((long StartIndex, long EndIndex) Range, IActionEvaluator ActionEvaluator)> pairs, IActionLoader actionLoader) { _router = new HardForkRouter(pairs); + ActionLoader = actionLoader; } - public IActionLoader ActionLoader => throw new NotSupportedException(); + public IActionLoader ActionLoader + { + get; + } public IReadOnlyList Evaluate( IPreEvaluationBlock block, HashDigest? baseStateRootHash) diff --git a/Libplanet.Extensions.PluggedActionEvaluator/PluggedActionEvaluator.cs b/Libplanet.Extensions.PluggedActionEvaluator/PluggedActionEvaluator.cs index c2ee18264..e97732f96 100644 --- a/Libplanet.Extensions.PluggedActionEvaluator/PluggedActionEvaluator.cs +++ b/Libplanet.Extensions.PluggedActionEvaluator/PluggedActionEvaluator.cs @@ -14,11 +14,15 @@ public class PluggedActionEvaluator : IActionEvaluator { private readonly IPluginActionEvaluator _pluginActionEvaluator; - public IActionLoader ActionLoader => throw new NotImplementedException(); + public IActionLoader ActionLoader + { + get; + } - public PluggedActionEvaluator(string pluginPath, string typeName, IKeyValueStore keyValueStore) + public PluggedActionEvaluator(string pluginPath, string typeName, IKeyValueStore keyValueStore, IActionLoader actionLoader) { _pluginActionEvaluator = CreateActionEvaluator(pluginPath, typeName, keyValueStore); + ActionLoader = actionLoader; } public static Assembly LoadPlugin(string absolutePath) diff --git a/Libplanet.Headless/Hosting/LibplanetNodeService.cs b/Libplanet.Headless/Hosting/LibplanetNodeService.cs index 11ecc161b..4e0f063ce 100644 --- a/Libplanet.Headless/Hosting/LibplanetNodeService.cs +++ b/Libplanet.Headless/Hosting/LibplanetNodeService.cs @@ -125,7 +125,8 @@ IActionEvaluator BuildActionEvaluator(IActionEvaluatorConfiguration actionEvalua new PluggedActionEvaluator( ResolvePluginPath(pluginActionEvaluatorConfiguration.PluginPath), pluginActionEvaluatorConfiguration.TypeName, - keyValueStore), + keyValueStore, + actionLoader), DefaultActionEvaluatorConfiguration _ => new ActionEvaluator( _ => blockPolicy.BlockAction, @@ -134,7 +135,10 @@ IActionEvaluator BuildActionEvaluator(IActionEvaluatorConfiguration actionEvalua ForkableActionEvaluatorConfiguration forkableActionEvaluatorConfiguration => new ForkableActionEvaluator( forkableActionEvaluatorConfiguration.Pairs.Select( - pair => ((pair.Item1.Start, pair.Item1.End), BuildActionEvaluator(pair.Item2)))), + pair => ( + (pair.Item1.Start, pair.Item1.End), + BuildActionEvaluator(pair.Item2))), + actionLoader), _ => throw new InvalidOperationException("Unexpected type."), }; } From 1b8738f4cbaaeac4ef67424d1b8db31f49027d70 Mon Sep 17 00:00:00 2001 From: Suho Lee Date: Thu, 7 Dec 2023 16:07:44 +0900 Subject: [PATCH 04/15] test: add `SingleActionLoader` to `ForkableActionEvaluator` --- .../ForkableActionEvaluatorTest.cs | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Libplanet.Extensions.ForkableActionEvaluator.Tests/ForkableActionEvaluatorTest.cs b/Libplanet.Extensions.ForkableActionEvaluator.Tests/ForkableActionEvaluatorTest.cs index 6549e728c..73ea081fa 100644 --- a/Libplanet.Extensions.ForkableActionEvaluator.Tests/ForkableActionEvaluatorTest.cs +++ b/Libplanet.Extensions.ForkableActionEvaluator.Tests/ForkableActionEvaluatorTest.cs @@ -2,6 +2,7 @@ using Bencodex.Types; using Libplanet.Action; using Libplanet.Action.Loader; +using Libplanet.Action.State; using Libplanet.Types.Blocks; using Libplanet.Common; using Libplanet.Crypto; @@ -19,7 +20,7 @@ public void ForkEvaluation() { ((0L, 100L), new PreActionEvaluator()), ((101L, long.MaxValue), new PostActionEvaluator()), - }); + }, new SingleActionLoader(typeof(MockAction))); Assert.Equal((Text)"PRE", Assert.Single(evaluator.Evaluate(new MockBlock(0), null)).Action); Assert.Equal((Text)"PRE", Assert.Single(evaluator.Evaluate(new MockBlock(99), null)).Action); @@ -36,25 +37,25 @@ public void CheckPairs() { ((0L, 100L), new PreActionEvaluator()), ((99L, long.MaxValue), new PostActionEvaluator()), - })); + }, new SingleActionLoader(typeof(MockAction)))); Assert.Throws(() => new ForkableActionEvaluator( new ((long, long), IActionEvaluator)[] { ((0L, 100L), new PreActionEvaluator()), ((100L, long.MaxValue), new PostActionEvaluator()), - })); + }, new SingleActionLoader(typeof(MockAction)))); Assert.Throws(() => new ForkableActionEvaluator( new ((long, long), IActionEvaluator)[] { ((50L, 100L), new PreActionEvaluator()), ((101L, long.MaxValue), new PostActionEvaluator()), - })); + }, new SingleActionLoader(typeof(MockAction)))); Assert.Throws(() => new ForkableActionEvaluator( new ((long, long), IActionEvaluator)[] { ((0L, 100L), new PreActionEvaluator()), ((101L, long.MaxValue - 1), new PostActionEvaluator()), - })); + }, new SingleActionLoader(typeof(MockAction)))); } } @@ -104,6 +105,17 @@ public IReadOnlyList Evaluate(IPreEvaluationBlock bl } } +class MockAction : IAction +{ + public IValue PlainValue => default(Null); + + public void LoadPlainValue(IValue plainValue) + { + } + + public IAccount Execute(IActionContext context) => context.PreviousState; +} + class MockBlock : IPreEvaluationBlock { public MockBlock(long blockIndex) From 80336a9e44f6f6cefdb38b1bab20784ddba392d7 Mon Sep 17 00:00:00 2001 From: Suho Lee Date: Thu, 7 Dec 2023 19:48:12 +0900 Subject: [PATCH 05/15] bump: lib9c --- Lib9c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib9c b/Lib9c index 51794f64c..e68759875 160000 --- a/Lib9c +++ b/Lib9c @@ -1 +1 @@ -Subproject commit 51794f64c642e247a15ce2d084faab377db09dc2 +Subproject commit e6875987540e8a4acbfe63026009148239a57f01 From f8576a465b41ccf436573cb619d1bbfeec7c0de4 Mon Sep 17 00:00:00 2001 From: area363 Date: Thu, 7 Dec 2023 22:47:05 +0900 Subject: [PATCH 06/15] add rocksdb-related dependencies --- Dockerfile.amd64 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile.amd64 b/Dockerfile.amd64 index 71e8fe2cb..6956759fd 100644 --- a/Dockerfile.amd64 +++ b/Dockerfile.amd64 @@ -26,13 +26,13 @@ RUN dotnet publish NineChronicles.Headless.Executable/NineChronicles.Headless.Ex # Build runtime image FROM --platform=linux/amd64 mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim WORKDIR /app -RUN apt-get update && apt-get install -y libc6-dev +RUN apt-get update && apt-get install -y libc6-dev liblz4-dev zlib1g-dev libsnappy-dev libzstd-dev COPY --from=build-env /app/out . # Install native deps & utilities for production RUN apt-get update \ && apt-get install -y --allow-unauthenticated \ - libc6-dev jq curl \ + libc6-dev liblz4-dev zlib1g-dev libsnappy-dev libzstd-dev jq curl \ && rm -rf /var/lib/apt/lists/* VOLUME /data From 5351eb7631367b94e8b27d105240c219e1f0d281 Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Fri, 8 Dec 2023 13:24:48 +0900 Subject: [PATCH 07/15] Bump lib9c to support TxStatus.INCLUDED --- Lib9c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib9c b/Lib9c index e68759875..e4a163ade 160000 --- a/Lib9c +++ b/Lib9c @@ -1 +1 @@ -Subproject commit e6875987540e8a4acbfe63026009148239a57f01 +Subproject commit e4a163ade34479f7b885c4bb40bff9a2a3ef5d2b From efa18c8e79dbe088c5778802680eb16438f760f3 Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Fri, 8 Dec 2023 13:52:53 +0900 Subject: [PATCH 08/15] Update TxResult query to allow TxStatus.INCLUDED --- .../GraphTypes/TransactionHeadlessQuery.cs | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs b/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs index 557a0a12b..ea137a1d2 100644 --- a/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs +++ b/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs @@ -306,28 +306,42 @@ public TransactionHeadlessQuery(StandaloneContext standaloneContext) $"{nameof(StandaloneContext)}.{nameof(StandaloneContext.Store)} was not set yet!"); } - if (!(store.GetFirstTxIdBlockHashIndex(txId) is { } txExecutedBlockHash)) - { - return blockChain.GetStagedTransactionIds().Contains(txId) - ? new TxResult(TxStatus.STAGING, null, null, null, null, null) - : new TxResult(TxStatus.INVALID, null, null, null, null, null); - } + List blockHashCandidates = store + .IterateTxIdBlockHashIndex(txId) + .Where(bhc => blockChain.ContainsBlock(bhc)) + .ToList(); + Block? blockContainingTx = blockHashCandidates.Any() + ? blockChain[blockHashCandidates.First()] + : null; - try + if (blockContainingTx is { } block) { - TxExecution execution = blockChain.GetTxExecution(txExecutedBlockHash, txId); - Block txExecutedBlock = blockChain[txExecutedBlockHash]; - return new TxResult( - execution.Fail ? TxStatus.FAILURE : TxStatus.SUCCESS, - txExecutedBlock.Index, - txExecutedBlock.Hash.ToString(), - execution.InputState, - execution.OutputState, - execution.ExceptionNames); + if (blockChain.GetTxExecution(block.Hash, txId) is { } execution) + { + return new TxResult( + execution.Fail ? TxStatus.FAILURE : TxStatus.SUCCESS, + block.Index, + block.Hash.ToString(), + execution.InputState, + execution.OutputState, + execution.ExceptionNames); + } + else + { + return new TxResult( + TxStatus.INCLUDED, + block.Index, + block.Hash.ToString(), + null, + null, + null); + } } - catch (Exception) + else { - return new TxResult(TxStatus.INVALID, null, null, null, null, null); + return blockChain.GetStagedTransactionIds().Contains(txId) + ? new TxResult(TxStatus.STAGING, null, null, null, null, null) + : new TxResult(TxStatus.INVALID, null, null, null, null, null); } } From 3ea637151cb47c839edb673a34f9c71a4b85ede2 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Thu, 7 Dec 2023 13:27:01 +0900 Subject: [PATCH 09/15] Add worker enable arguments --- NineChronicles.Headless.Executable/Program.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/NineChronicles.Headless.Executable/Program.cs b/NineChronicles.Headless.Executable/Program.cs index 48391e338..378a984b5 100644 --- a/NineChronicles.Headless.Executable/Program.cs +++ b/NineChronicles.Headless.Executable/Program.cs @@ -211,6 +211,8 @@ public async Task Run( double? sentryTraceSampleRate = null, [Option(Description = "arena participants list sync interval time")] int? arenaParticipantsSyncInterval = null, + [Option(Description = "arena participants list sync enable")] + bool arenaParticipantsSync = true, [Ignore] CancellationToken? cancellationToken = null ) { @@ -464,7 +466,10 @@ IActionLoader MakeSingleActionLoader() .AddPrometheusExporter()); // worker - services.AddHostedService(_ => new ArenaParticipantsWorker(arenaMemoryCache, standaloneContext, headlessConfig.ArenaParticipantsSyncInterval)); + if (arenaParticipantsSync) + { + services.AddHostedService(_ => new ArenaParticipantsWorker(arenaMemoryCache, standaloneContext, headlessConfig.ArenaParticipantsSyncInterval)); + } services.AddSingleton(arenaMemoryCache); }); From 850bf4dcb3e2703a5d4a4dbd49d11e05c291e158 Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Fri, 8 Dec 2023 14:59:23 +0900 Subject: [PATCH 10/15] Roll back lock to include try statement for safety --- .../GraphTypes/TransactionHeadlessQuery.cs | 68 +++++++++++-------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs b/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs index ea137a1d2..b07e3f720 100644 --- a/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs +++ b/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs @@ -23,6 +23,7 @@ using Libplanet.Crypto; using Libplanet.Store; using Nekoyume.Action; +using Serilog; namespace NineChronicles.Headless.GraphTypes { @@ -306,42 +307,53 @@ public TransactionHeadlessQuery(StandaloneContext standaloneContext) $"{nameof(StandaloneContext)}.{nameof(StandaloneContext.Store)} was not set yet!"); } - List blockHashCandidates = store - .IterateTxIdBlockHashIndex(txId) - .Where(bhc => blockChain.ContainsBlock(bhc)) - .ToList(); - Block? blockContainingTx = blockHashCandidates.Any() - ? blockChain[blockHashCandidates.First()] - : null; - - if (blockContainingTx is { } block) + try { - if (blockChain.GetTxExecution(block.Hash, txId) is { } execution) + List blockHashCandidates = store + .IterateTxIdBlockHashIndex(txId) + .Where(bhc => blockChain.ContainsBlock(bhc)) + .ToList(); + Block? blockContainingTx = blockHashCandidates.Any() + ? blockChain[blockHashCandidates.First()] + : null; + + if (blockContainingTx is { } block) { - return new TxResult( - execution.Fail ? TxStatus.FAILURE : TxStatus.SUCCESS, - block.Index, - block.Hash.ToString(), - execution.InputState, - execution.OutputState, - execution.ExceptionNames); + if (blockChain.GetTxExecution(block.Hash, txId) is { } execution) + { + return new TxResult( + execution.Fail ? TxStatus.FAILURE : TxStatus.SUCCESS, + block.Index, + block.Hash.ToString(), + execution.InputState, + execution.OutputState, + execution.ExceptionNames); + } + else + { + return new TxResult( + TxStatus.INCLUDED, + block.Index, + block.Hash.ToString(), + null, + null, + null); + } } else { - return new TxResult( - TxStatus.INCLUDED, - block.Index, - block.Hash.ToString(), - null, - null, - null); + return blockChain.GetStagedTransactionIds().Contains(txId) + ? new TxResult(TxStatus.STAGING, null, null, null, null, null) + : new TxResult(TxStatus.INVALID, null, null, null, null, null); } } - else + catch (Exception e) { - return blockChain.GetStagedTransactionIds().Contains(txId) - ? new TxResult(TxStatus.STAGING, null, null, null, null, null) - : new TxResult(TxStatus.INVALID, null, null, null, null, null); + // FIXME: Try statement here is probably redundant. + // This part should not be run under normal circumstances. + // Should be removed when possible. + Log.Debug("Failed to properly fetch TxResult {Excetion}", e); + return new TxResult(TxStatus.INVALID, null, null, null, null, null); } } From 548d553731cef11d0ec9304da5da08f91b2806f2 Mon Sep 17 00:00:00 2001 From: Say Cheong Date: Fri, 8 Dec 2023 15:02:30 +0900 Subject: [PATCH 11/15] Typo/linting --- NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs b/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs index b07e3f720..3741b39bb 100644 --- a/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs +++ b/NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs @@ -352,7 +352,7 @@ public TransactionHeadlessQuery(StandaloneContext standaloneContext) // FIXME: Try statement here is probably redundant. // This part should not be run under normal circumstances. // Should be removed when possible. - Log.Debug("Failed to properly fetch TxResult {Excetion}", e); + Log.Debug("Failed to properly fetch TxResult {Exception}.", e); return new TxResult(TxStatus.INVALID, null, null, null, null, null); } } From 476f86dbc6204992155c682578ddd2f68763f4ab Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Mon, 11 Dec 2023 19:37:46 +0900 Subject: [PATCH 12/15] bump lib9c to 4ffef6(head of lib9c:release/1.6.0) --- Lib9c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib9c b/Lib9c index e4a163ade..4ffef6295 160000 --- a/Lib9c +++ b/Lib9c @@ -1 +1 @@ -Subproject commit e4a163ade34479f7b885c4bb40bff9a2a3ef5d2b +Subproject commit 4ffef6295b1f618ba24a345818394eb02614502c From d8f5f48366022d0f5f7c34b76aed14c6e555f9fb Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Mon, 11 Dec 2023 20:53:03 +0900 Subject: [PATCH 13/15] bump lib9c to main --- Lib9c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib9c b/Lib9c index 4ffef6295..06ccead46 160000 --- a/Lib9c +++ b/Lib9c @@ -1 +1 @@ -Subproject commit 4ffef6295b1f618ba24a345818394eb02614502c +Subproject commit 06ccead46d51b2868942a0996e10e21b99c1726f From 0a407d28395af44783ec2746e32a23b5c4188c82 Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Tue, 12 Dec 2023 15:34:14 +0900 Subject: [PATCH 14/15] bump lib9c to development(5c11d80), is merged commit hash by main release --- Lib9c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib9c b/Lib9c index 06ccead46..5c11d8044 160000 --- a/Lib9c +++ b/Lib9c @@ -1 +1 @@ -Subproject commit 06ccead46d51b2868942a0996e10e21b99c1726f +Subproject commit 5c11d8044a93616ee7f34d49f2517241d7a5a6f6 From 999f9ab51800aea52720e4583c8fc67718e430d9 Mon Sep 17 00:00:00 2001 From: moreal Date: Thu, 14 Dec 2023 18:57:35 +0900 Subject: [PATCH 15/15] Remove Buy5 type usage --- .../Commands/MarketCommand.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/NineChronicles.Headless.Executable/Commands/MarketCommand.cs b/NineChronicles.Headless.Executable/Commands/MarketCommand.cs index 8aaa5f649..21fd70b8c 100644 --- a/NineChronicles.Headless.Executable/Commands/MarketCommand.cs +++ b/NineChronicles.Headless.Executable/Commands/MarketCommand.cs @@ -50,10 +50,9 @@ public void Query( [Option( 'T', Description = "Filter by item type. This implicitly filters out transactions " + - "made with " + nameof(Buy) + " action version prior to " + nameof(Buy5) + - ". This can be applied multiple times (meaning: match any of them). " + - "The list of available types can be found in " + nameof(ItemSubType) + - " enum declared in Lib9c/Model/Item/ItemType.cs file.")] + "made with " + nameof(Buy) + ". This can be applied multiple times " + + "(meaning: match any of them). The list of available types can be found in " + + nameof(ItemSubType) + " enum declared in Lib9c/Model/Item/ItemType.cs file.")] string[]? itemType = null, [Option('c', Description = "Optional chain ID. Default is the canonical chain ID.")] Guid? chainId = null