Skip to content

Commit

Permalink
Merge pull request #2290 from riemannulus/merge/70/into/main
Browse files Browse the repository at this point in the history
🔀 merge: release/70 into main
  • Loading branch information
riemannulus authored Nov 7, 2023
2 parents 29721b8 + ed3357d commit 256fa4c
Show file tree
Hide file tree
Showing 62 changed files with 1,086 additions and 668 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/deploy_gh_pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,20 @@ jobs:
-G "https://9c-dx.s3.ap-northeast-2.amazonaws.com/empty-genesis-block-20230511" &
sleep 60s
graphql-inspector introspect http://localhost:30000/graphql --write schema.graphql
- name: Build
- name: Build GraphQL Document
run: |
yarn global add spectaql
spectaql ./spectaql-config.yaml
spectaql --target-dir public/graphql ./spectaql-config.yaml
- name: Build CLI Document
run: |
mkdir -p public/cli
dotnet run --project NineChronicles.Headless.Executable -- \
docs \
public/cli
- name: Copy Landing Page to deploy
run: cp Docs/resources/landing.html public/index.html
- name: Copy GraphQL Schema to deploy
run: cp schema.graphql doc
run: cp schema.graphql public/schema.graphql
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/push_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
docker:
- repo: planetariumhq/ninechronicles-headless
dockerfile: Dockerfile
- repo: planetariumhq/access-control-center
dockerfile: Dockerfile.ACC
if: github.ref_type == 'branch'
runs-on: ubuntu-latest
steps:
Expand Down
37 changes: 37 additions & 0 deletions Dockerfile.ACC
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Use the SDK image to build the app
FROM mcr.microsoft.com/dotnet/sdk:6.0-jammy AS build-env
WORKDIR /app
ARG COMMIT

# Copy csproj and restore as distinct layers
COPY ./Lib9c/Lib9c/Lib9c.csproj ./Lib9c/
COPY ./NineChronicles.Headless/NineChronicles.Headless.csproj ./NineChronicles.Headless/
COPY ./NineChronicles.Headless.AccessControlCenter/NineChronicles.Headless.AccessControlCenter.csproj ./NineChronicles.Headless.AccessControlCenter/
RUN dotnet restore Lib9c
RUN dotnet restore NineChronicles.Headless
RUN dotnet restore NineChronicles.Headless.AccessControlCenter

# Copy everything else and build
COPY . ./
RUN dotnet publish NineChronicles.Headless.AccessControlCenter/NineChronicles.Headless.AccessControlCenter.csproj \
-c Release \
-r linux-x64 \
-o out \
--self-contained \
--version-suffix $COMMIT

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
RUN apt-get update && apt-get install -y libc6-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 \
&& rm -rf /var/lib/apt/lists/*

VOLUME /data

ENTRYPOINT ["dotnet", "NineChronicles.Headless.AccessControlCenter.dll"]
37 changes: 37 additions & 0 deletions Dockerfile.ACC.amd64
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Use the SDK image to build the app
FROM mcr.microsoft.com/dotnet/sdk:6.0-jammy AS build-env
WORKDIR /app
ARG COMMIT

# Copy csproj and restore as distinct layers
COPY ./Lib9c/Lib9c/Lib9c.csproj ./Lib9c/
COPY ./NineChronicles.Headless/NineChronicles.Headless.csproj ./NineChronicles.Headless/
COPY ./NineChronicles.Headless.AccessControlCenter/NineChronicles.Headless.AccessControlCenter.csproj ./NineChronicles.Headless.AccessControlCenter/
RUN dotnet restore Lib9c
RUN dotnet restore NineChronicles.Headless
RUN dotnet restore NineChronicles.Headless.AccessControlCenter

# Copy everything else and build
COPY . ./
RUN dotnet publish NineChronicles.Headless.AccessControlCenter/NineChronicles.Headless.AccessControlCenter.csproj \
-c Release \
-r linux-x64 \
-o out \
--self-contained \
--version-suffix $COMMIT

# 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
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 \
&& rm -rf /var/lib/apt/lists/*

VOLUME /data

ENTRYPOINT ["dotnet", "NineChronicles.Headless.AccessControlCenter.dll"]
37 changes: 37 additions & 0 deletions Dockerfile.ACC.arm64v8
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Use the SDK image to build the app
FROM mcr.microsoft.com/dotnet/sdk:6.0-jammy AS build-env
WORKDIR /app
ARG COMMIT

# Copy csproj and restore as distinct layers
COPY ./Lib9c/Lib9c/Lib9c.csproj ./Lib9c/
COPY ./NineChronicles.Headless/NineChronicles.Headless.csproj ./NineChronicles.Headless/
COPY ./NineChronicles.Headless.AccessControlCenter/NineChronicles.Headless.AccessControlCenter.csproj ./NineChronicles.Headless.AccessControlCenter/
RUN dotnet restore Lib9c
RUN dotnet restore NineChronicles.Headless
RUN dotnet restore NineChronicles.Headless.AccessControlCenter

# Copy everything else and build
COPY . ./
RUN dotnet publish NineChronicles.Headless.AccessControlCenter/NineChronicles.Headless.AccessControlCenter.csproj \
-c Release \
-r linux-arm64 \
-o out \
--self-contained \
--version-suffix $COMMIT

# Build runtime image
FROM --platform=linux/arm64 mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim-arm64v8
WORKDIR /app
RUN apt-get update && apt-get install -y libc6-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 \
&& rm -rf /var/lib/apt/lists/*

VOLUME /data

ENTRYPOINT ["dotnet", "NineChronicles.Headless.AccessControlCenter.dll"]
25 changes: 25 additions & 0 deletions Docs/resources/landing.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>NineChronicles Headless</title>
<meta charset="UTF-8"/>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div class="flex min-h-screen min-w-screen justify-center items-center">
<div class="flex flex-col justify-center items-center gap-5">
<p class="bg-gray-700 p-5 text-white text-4xl font-extrabold">NineChronicles.Headless</p>
<span>A headless node to validate, network, operate NineChronicles chain.</span>
<hr class="w-full" />
<div class="flex flex-row justify-center items-center gap-2">
<a href="https://github.com/planetarium/NineChronicles.Headless"><i class="fa fa-github"></i> Repository</a>
<span>|</span>
<a href="https://planetarium.github.io/NineChronicles.Headless/graphql">GraphQL Docs</a>
<span>|</span>
<a href="https://planetarium.github.io/NineChronicles.Headless/cli">CLI Docs</a>
</div>
</div>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion Lib9c
Submodule Lib9c updated 584 files
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -24,11 +21,11 @@ public void ForkEvaluation()
((101L, long.MaxValue), new PostActionEvaluator()),
});

Assert.Equal((Text)"PRE", Assert.Single(evaluator.Evaluate(new MockBlock(0))).Action);
Assert.Equal((Text)"PRE", Assert.Single(evaluator.Evaluate(new MockBlock(99))).Action);
Assert.Equal((Text)"PRE", Assert.Single(evaluator.Evaluate(new MockBlock(100))).Action);
Assert.Equal((Text)"POST", Assert.Single(evaluator.Evaluate(new MockBlock(101))).Action);
Assert.Equal((Text)"POST", Assert.Single(evaluator.Evaluate(new MockBlock(long.MaxValue))).Action);
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);
Assert.Equal((Text)"PRE", Assert.Single(evaluator.Evaluate(new MockBlock(100), null)).Action);
Assert.Equal((Text)"POST", Assert.Single(evaluator.Evaluate(new MockBlock(101), null)).Action);
Assert.Equal((Text)"POST", Assert.Single(evaluator.Evaluate(new MockBlock(long.MaxValue), null)).Action);
}

[Fact]
Expand Down Expand Up @@ -64,53 +61,47 @@ public void CheckPairs()
class PostActionEvaluator : IActionEvaluator
{
public IActionLoader ActionLoader => throw new NotSupportedException();
public IReadOnlyList<IActionEvaluation> Evaluate(IPreEvaluationBlock block)
public IReadOnlyList<ICommittedActionEvaluation> Evaluate(IPreEvaluationBlock block, HashDigest<SHA256>? 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(),
new Random(0),
null,
default,
0,
false),
new AccountStateDelta(),
null)
default)
};
}
}

class PreActionEvaluator : IActionEvaluator
{
public IActionLoader ActionLoader => throw new NotSupportedException();
public IReadOnlyList<IActionEvaluation> Evaluate(IPreEvaluationBlock block)
public IReadOnlyList<ICommittedActionEvaluation> Evaluate(IPreEvaluationBlock block, HashDigest<SHA256>? 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(),
new Random(0),
null,
default,
0,
false),
new AccountStateDelta(),
null)
default)
};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Security.Cryptography;
using Libplanet.Action;
using Libplanet.Action.Loader;
using Libplanet.Common;
using Libplanet.Types.Blocks;

namespace Libplanet.Extensions.ForkableActionEvaluator;
Expand All @@ -15,9 +17,10 @@ public ForkableActionEvaluator(IEnumerable<((long StartIndex, long EndIndex) Ran

public IActionLoader ActionLoader => throw new NotSupportedException();

public IReadOnlyList<IActionEvaluation> Evaluate(IPreEvaluationBlock block)
public IReadOnlyList<ICommittedActionEvaluation> Evaluate(
IPreEvaluationBlock block, HashDigest<SHA256>? baseStateRootHash)
{
var actionEvaluator = _router.GetEvaluator(block.Index);
return actionEvaluator.Evaluate(block);
return actionEvaluator.Evaluate(block, baseStateRootHash);
}
}
5 changes: 3 additions & 2 deletions Libplanet.Headless.Tests/Hosting/LibplanetNodeServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ public void Constructor()
{
var policy = new BlockPolicy();
var stagePolicy = new VolatileStagePolicy();
var stateStore = new TrieStateStore(new MemoryKeyValueStore());
var blockChainStates = new BlockChainStates(
new MemoryStore(),
new TrieStateStore(new MemoryKeyValueStore()));
stateStore);
var actionLoader = new SingleActionLoader(typeof(DummyAction));
var actionEvaluator = new ActionEvaluator(
_ => policy.BlockAction,
blockChainStates,
stateStore,
actionLoader);
var genesisBlock = BlockChain.ProposeGenesisBlock(actionEvaluator);
var service = new LibplanetNodeService(
Expand Down
13 changes: 4 additions & 9 deletions Libplanet.Headless/Hosting/LibplanetNodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ public LibplanetNodeService(
(Store, StateStore) = LoadStore(
Properties.StorePath,
Properties.StoreType,
Properties.StoreStatesCacheSize,
Properties.NoReduceStore);
Properties.StoreStatesCacheSize);

var chainIds = Store.ListChainIds().ToList();
Log.Debug($"Number of chain ids: {chainIds.Count()}");
Expand All @@ -122,10 +121,10 @@ 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,
blockChainStates: blockChainStates,
stateStore: StateStore,
actionTypeLoader: actionLoader
),
ForkableActionEvaluatorConfiguration forkableActionEvaluatorConfiguration => new
Expand Down Expand Up @@ -303,7 +302,7 @@ public override async Task StopAsync(CancellationToken cancellationToken)
}
}

protected (IStore, IStateStore) LoadStore(string path, string type, int statesCacheSize, bool noReduceStore = false)
protected (IStore, IStateStore) LoadStore(string path, string type, int statesCacheSize)
{
IStore store = null;
if (type == "rocksdb")
Expand Down Expand Up @@ -344,10 +343,6 @@ public override async Task StopAsync(CancellationToken cancellationToken)
}

store ??= new DefaultStore(path, flush: false);
if (!noReduceStore)
{
store = new ReducedStore(store);
}

IKeyValueStore stateKeyValueStore = new RocksDBKeyValueStore(Path.Combine(path, "states"));
IStateStore stateStore = new TrieStateStore(stateKeyValueStore);
Expand Down
Loading

0 comments on commit 256fa4c

Please sign in to comment.