Skip to content

Commit

Permalink
Merge pull request #2355 from planetarium/merge/80-into-development
Browse files Browse the repository at this point in the history
merge release/80 into development
  • Loading branch information
sonohoshi authored Dec 14, 2023
2 parents dfd777c + 999f9ab commit 5bbece9
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Dockerfile.amd64
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Lib9c
Submodule Lib9c updated 100 files
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -36,25 +37,25 @@ public void CheckPairs()
{
((0L, 100L), new PreActionEvaluator()),
((99L, long.MaxValue), new PostActionEvaluator()),
}));
}, new SingleActionLoader(typeof(MockAction))));
Assert.Throws<ArgumentOutOfRangeException>(() => new ForkableActionEvaluator(
new ((long, long), IActionEvaluator)[]
{
((0L, 100L), new PreActionEvaluator()),
((100L, long.MaxValue), new PostActionEvaluator()),
}));
}, new SingleActionLoader(typeof(MockAction))));
Assert.Throws<ArgumentOutOfRangeException>(() => new ForkableActionEvaluator(
new ((long, long), IActionEvaluator)[]
{
((50L, 100L), new PreActionEvaluator()),
((101L, long.MaxValue), new PostActionEvaluator()),
}));
}, new SingleActionLoader(typeof(MockAction))));
Assert.Throws<ArgumentOutOfRangeException>(() => new ForkableActionEvaluator(
new ((long, long), IActionEvaluator)[]
{
((0L, 100L), new PreActionEvaluator()),
((101L, long.MaxValue - 1), new PostActionEvaluator()),
}));
}, new SingleActionLoader(typeof(MockAction))));
}
}

Expand Down Expand Up @@ -104,6 +105,17 @@ public IReadOnlyList<ICommittedActionEvaluation> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ICommittedActionEvaluation> Evaluate(
IPreEvaluationBlock block, HashDigest<SHA256>? baseStateRootHash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions Libplanet.Headless/Hosting/LibplanetNodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ IActionEvaluator BuildActionEvaluator(IActionEvaluatorConfiguration actionEvalua
new PluggedActionEvaluator(
ResolvePluginPath(pluginActionEvaluatorConfiguration.PluginPath),
pluginActionEvaluatorConfiguration.TypeName,
keyValueStore),
keyValueStore,
actionLoader),
DefaultActionEvaluatorConfiguration _ =>
new ActionEvaluator(
_ => blockPolicy.BlockAction,
Expand All @@ -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."),
};
}
Expand Down
7 changes: 3 additions & 4 deletions NineChronicles.Headless.Executable/Commands/MarketCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion NineChronicles.Headless.Executable/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
{
Expand Down Expand Up @@ -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);
});

Expand Down
60 changes: 43 additions & 17 deletions NineChronicles.Headless/GraphTypes/TransactionHeadlessQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Libplanet.Crypto;
using Libplanet.Store;
using Nekoyume.Action;
using Serilog;

namespace NineChronicles.Headless.GraphTypes
{
Expand Down Expand Up @@ -306,27 +307,52 @@ 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);
}

try
{
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);
List<BlockHash> blockHashCandidates = store
.IterateTxIdBlockHashIndex(txId)
.Where(bhc => blockChain.ContainsBlock(bhc))
.ToList();
Block? blockContainingTx = blockHashCandidates.Any()
? blockChain[blockHashCandidates.First()]
: null;

if (blockContainingTx is { } block)
{
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 blockChain.GetStagedTransactionIds().Contains(txId)
? new TxResult(TxStatus.STAGING, null, null, null, null, null)
: new TxResult(TxStatus.INVALID, null, null, null, null, null);
}
}
catch (Exception)
catch (Exception e)
{
// 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 {Exception}.", e);
return new TxResult(TxStatus.INVALID, null, null, null, null, null);
}
}
Expand Down

0 comments on commit 5bbece9

Please sign in to comment.