Skip to content

Commit

Permalink
Merge pull request #2483 from planetarium/release/140
Browse files Browse the repository at this point in the history
merge `release/140` to `main`
  • Loading branch information
ipdae authored Jun 7, 2024
2 parents b131eec + 4026561 commit a11565e
Show file tree
Hide file tree
Showing 40 changed files with 789 additions and 248 deletions.
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug NineChronicles.Headless",
"type": "coreclr",
"request": "launch",
"program": "${workspaceFolder}/NineChronicles.Headless.Executable/bin/Debug/net6/NineChronicles.Headless.Executable.dll",
"cwd": "${workspaceFolder}/NineChronicles.Headless.Executable",
"stopAtEntry": false,
"console": "integratedTerminal",
"preLaunchTask": "build",
"args": [
"--config",
"appsettings.local.json"
]
}
]
}
41 changes: 41 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/NineChronicles.Headless.Executable/NineChronicles.Headless.Executable.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/NineChronicles.Headless.Executable/NineChronicles.Headless.Executable.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/NineChronicles.Headless.Executable/NineChronicles.Headless.Executable.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
2 changes: 1 addition & 1 deletion Lib9c
Submodule Lib9c updated 243 files
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static void CheckCollision(
{
throw new ArgumentOutOfRangeException(
nameof(pairs),
"The pairs must cover all range over blockchain. Its last element's start index wasn't 0.");
$"The pairs must cover all range over blockchain. Its last element's end index wasn't long.MaxValue({long.MaxValue}).");
}

if (pairs.Length == 1)
Expand Down
5 changes: 5 additions & 0 deletions Libplanet.Headless/Hosting/LibplanetNodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class LibplanetNodeService : BackgroundService, IDisposable

public readonly IStateStore StateStore;

public readonly IKeyValueStore StateKeyValueStore;

public readonly BlockChain BlockChain;

public readonly Swarm Swarm;
Expand Down Expand Up @@ -174,6 +176,8 @@ IActionEvaluator BuildActionEvaluator(IActionEvaluatorConfiguration actionEvalua
);
}

StateKeyValueStore = keyValueStore;

_obsoletedChainIds = chainIds.Where(chainId => chainId != BlockChain.Id).ToList();

_exceptionHandlerAction = exceptionHandlerAction;
Expand Down Expand Up @@ -235,6 +239,7 @@ IActionEvaluator BuildActionEvaluator(IActionEvaluatorConfiguration actionEvalua
ConsensusPrivateKey = Properties.ConsensusPrivateKey,
ConsensusWorkers = 500,
TargetBlockInterval = TimeSpan.FromMilliseconds(Properties.ConsensusTargetBlockIntervalMilliseconds ?? 7000),
ContextTimeoutOptions = Properties.ContextTimeoutOption,
};
}

Expand Down
3 changes: 3 additions & 0 deletions Libplanet.Headless/Hosting/LibplanetNodeServiceProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Libplanet.Types.Blocks;
using Libplanet.Crypto;
using Libplanet.Net;
using Libplanet.Net.Consensus;

namespace Libplanet.Headless.Hosting
{
Expand Down Expand Up @@ -67,6 +68,8 @@ public class LibplanetNodeServiceProperties

public TimeSpan TipTimeout { get; set; } = TimeSpan.FromSeconds(60);

public ContextTimeoutOption ContextTimeoutOption { get; set; }

public int DemandBuffer { get; set; } = 1150;

public ImmutableList<BoundPeer> ConsensusSeeds { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public AccessControlServiceController(IMutableAccessControlService accessControl
[HttpGet("entries/{address}")]
public ActionResult<int?> GetTxQuota(string address)
{
var result = _accessControlService.GetTxQuota(new Address(address));
var result = _accessControlService.GetTxQuotaAsync(new Address(address)).Result;

return result != null ? result : NotFound();
}
Expand Down
60 changes: 40 additions & 20 deletions NineChronicles.Headless.Executable.sln
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Crypto", "Lib9c\.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Extensions.ActionEvaluatorCommonComponents", "Lib9c\.Libplanet.Extensions.ActionEvaluatorCommonComponents\Libplanet.Extensions.ActionEvaluatorCommonComponents.csproj", "{A6922395-36E5-4B0A-BEBD-9BCE34D08722}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Extensions.RemoteBlockChainStates", "Lib9c\.Libplanet.Extensions.RemoteBlockChainStates\Libplanet.Extensions.RemoteBlockChainStates.csproj", "{8F9E5505-C157-4DF3-A419-FF0108731397}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NineChronicles.Headless.AccessControlCenter", "NineChronicles.Headless.AccessControlCenter\NineChronicles.Headless.AccessControlCenter.csproj", "{162C0F4B-A1D9-4132-BC34-31F1247BC26B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Libplanet.Extensions.PluggedActionEvaluator", "Libplanet.Extensions.PluggedActionEvaluator\Libplanet.Extensions.PluggedActionEvaluator.csproj", "{DE91C36D-3999-47B6-A0BD-848C8EBA2A76}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lib9c.Plugin.Shared", "Lib9c\.Lib9c.Plugin.Shared\Lib9c.Plugin.Shared.csproj", "{3D32DA34-E619-429F-8421-848FF4F14417}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libplanet.Mocks", "Lib9c\.Libplanet\Libplanet.Mocks\Libplanet.Mocks.csproj", "{F79B695B-6FCC-43F5-AEE4-88E484382B9B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Libplanet.Store.Remote", "Lib9c\.Libplanet\Libplanet.Store.Remote\Libplanet.Store.Remote.csproj", "{D1E15F81-8765-4DCA-9299-675415686C23}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -651,24 +653,6 @@ Global
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Release|x64.Build.0 = Release|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Release|x86.ActiveCfg = Release|Any CPU
{A6922395-36E5-4B0A-BEBD-9BCE34D08722}.Release|x86.Build.0 = Release|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.Debug|x64.ActiveCfg = Debug|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.Debug|x64.Build.0 = Debug|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.Debug|x86.ActiveCfg = Debug|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.Debug|x86.Build.0 = Debug|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.DevEx|Any CPU.ActiveCfg = Debug|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.DevEx|Any CPU.Build.0 = Debug|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.DevEx|x64.ActiveCfg = Debug|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.DevEx|x64.Build.0 = Debug|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.DevEx|x86.ActiveCfg = Debug|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.DevEx|x86.Build.0 = Debug|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.Release|Any CPU.Build.0 = Release|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.Release|x64.ActiveCfg = Release|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.Release|x64.Build.0 = Release|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.Release|x86.ActiveCfg = Release|Any CPU
{8F9E5505-C157-4DF3-A419-FF0108731397}.Release|x86.Build.0 = Release|Any CPU
{162C0F4B-A1D9-4132-BC34-31F1247BC26B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{162C0F4B-A1D9-4132-BC34-31F1247BC26B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{162C0F4B-A1D9-4132-BC34-31F1247BC26B}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -723,6 +707,42 @@ Global
{3D32DA34-E619-429F-8421-848FF4F14417}.Release|x64.Build.0 = Release|Any CPU
{3D32DA34-E619-429F-8421-848FF4F14417}.Release|x86.ActiveCfg = Release|Any CPU
{3D32DA34-E619-429F-8421-848FF4F14417}.Release|x86.Build.0 = Release|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.Debug|x64.ActiveCfg = Debug|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.Debug|x64.Build.0 = Debug|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.Debug|x86.ActiveCfg = Debug|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.Debug|x86.Build.0 = Debug|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.DevEx|Any CPU.ActiveCfg = Debug|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.DevEx|Any CPU.Build.0 = Debug|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.DevEx|x64.ActiveCfg = Debug|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.DevEx|x64.Build.0 = Debug|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.DevEx|x86.ActiveCfg = Debug|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.DevEx|x86.Build.0 = Debug|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.Release|Any CPU.Build.0 = Release|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.Release|x64.ActiveCfg = Release|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.Release|x64.Build.0 = Release|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.Release|x86.ActiveCfg = Release|Any CPU
{F79B695B-6FCC-43F5-AEE4-88E484382B9B}.Release|x86.Build.0 = Release|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.Debug|x64.ActiveCfg = Debug|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.Debug|x64.Build.0 = Debug|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.Debug|x86.ActiveCfg = Debug|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.Debug|x86.Build.0 = Debug|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.DevEx|Any CPU.ActiveCfg = Debug|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.DevEx|Any CPU.Build.0 = Debug|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.DevEx|x64.ActiveCfg = Debug|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.DevEx|x64.Build.0 = Debug|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.DevEx|x86.ActiveCfg = Debug|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.DevEx|x86.Build.0 = Debug|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.Release|Any CPU.Build.0 = Release|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.Release|x64.ActiveCfg = Release|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.Release|x64.Build.0 = Release|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.Release|x86.ActiveCfg = Release|Any CPU
{D1E15F81-8765-4DCA-9299-675415686C23}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ query GetBlockData($hash: ID!)
preEvaluationHash
previousBlock {
hash
stateRootHash
}
stateRootHash
}
}}
}
Expand Down Expand Up @@ -87,6 +89,7 @@ private sealed class BlockType
public string? Miner { get; set; }
public string? PreEvaluationHash { get; set; }
public BlockType? PreviousBlock { get; set; }
public string? StateRootHash { get; set; }
}

private sealed class TransactionQueryType
Expand Down
42 changes: 34 additions & 8 deletions NineChronicles.Headless.Executable/Commands/ReplayCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@
using Cocona.Help;
using GraphQL.Client.Http;
using GraphQL.Client.Serializer.SystemTextJson;
using Grpc.Net.Client;
using Libplanet.Action;
using Libplanet.Action.Loader;
using Libplanet.Blockchain;
using Libplanet.Blockchain.Policies;
using Libplanet.Extensions.RemoteBlockChainStates;
using Libplanet.Types.Blocks;
using Libplanet.RocksDBStore;
using Libplanet.Action.State;
using Libplanet.Common;
using Libplanet.Crypto;
using Libplanet.Store;
using Libplanet.Store.Remote;
using Libplanet.Store.Remote.Client;
using Libplanet.Types.Tx;
using Nekoyume.Action;
using Nekoyume.Action.Loader;
Expand Down Expand Up @@ -353,8 +355,10 @@ public int Blocks(
public int RemoteTx(
[Option("tx", new[] { 't' }, Description = "The transaction id")]
string transactionId,
[Option("endpoint", new[] { 'e' }, Description = "GraphQL endpoint to get remote state")]
string endpoint)
[Option("endpoint", new[] { 'e' }, Description = "GraphQL endpoint to get block data.")]
string endpoint,
[Option("grpc-endpoint", new []{ 'g' }, Description = "gRPC endpoint to get remote states.")]
string grpcEndpoint)
{
var graphQlClient = new GraphQLHttpClient(new Uri(endpoint), new SystemTextJsonSerializer());
var transactionResponse = GetTransactionData(graphQlClient, transactionId);
Expand All @@ -378,19 +382,41 @@ public int RemoteTx(

var block = GetBlockData(graphQlClient, transactionResult.BlockHash)?.ChainQuery?.BlockQuery?.Block;
var previousBlockHashValue = block?.PreviousBlock?.Hash;
var previousBlockHashStateRootHash = block?.PreviousBlock?.StateRootHash;
var preEvaluationHashValue = block?.PreEvaluationHash;
var minerValue = block?.Miner;
if (previousBlockHashValue is null || preEvaluationHashValue is null || minerValue is null)
if (previousBlockHashValue is null || preEvaluationHashValue is null || minerValue is null || previousBlockHashStateRootHash is null)
{
throw new CommandExitedException("Failed to get block from query", -1);
}
var miner = new Address(minerValue);

var explorerEndpoint = $"{endpoint}/explorer";
var blockChainStates = new RemoteBlockChainStates(new Uri(explorerEndpoint));
var channel = GrpcChannel.ForAddress(grpcEndpoint);
var keyValueServiceClient = new KeyValueStore.KeyValueStoreClient(channel);
var cacheKeyValueStore =
new RocksDBKeyValueStore(Path.Combine(Path.GetTempPath(), "9c-headless-replay-remotetx"));
var keyValueStore = new ReplicableKeyValueStore(
new RemoteKeyValueStore(keyValueServiceClient),
cacheKeyValueStore);
var store = new AnonymousStore
{
GetBlockDigest = hash =>
{
var stateRootHash = HashDigest<SHA256>.FromString(block!.StateRootHash!);
var privateKey = new PrivateKey();
var blockMetadata = new BlockMetadata(
0, DateTimeOffset.Now, privateKey.PublicKey, null, null, null);
var blockContent = new BlockContent(blockMetadata);
var preEvaluationBlock = blockContent.Propose();
var b = preEvaluationBlock.Sign(privateKey, stateRootHash);
return new BlockDigest(b.Header, ImmutableArray<ImmutableArray<byte>>.Empty);
}
};

var previousStateRootHash = HashDigest<SHA256>.FromString(previousBlockHashStateRootHash);
var blockChainStates = new BlockChainStates(store, new TrieStateStore(keyValueStore));

var previousBlockHash = BlockHash.FromString(previousBlockHashValue);
var previousStates = new World(blockChainStates.GetWorldState(previousBlockHash));
var previousStates = new World(blockChainStates.GetWorldState(previousStateRootHash));

var actions = transaction.Actions
.Select(ToAction)
Expand Down
28 changes: 0 additions & 28 deletions NineChronicles.Headless.Executable/Commands/TxCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,34 +190,6 @@ public void MigrationActivatedAccountsState()
_console.Out.WriteLine(ByteUtil.Hex(raw));
}

[Command(Description = "Create MigrationAvatarState action and dump it.")]
public void MigrationAvatarState(
[Argument("directory-path", Description = "path of the directory contained hex-encoded avatar states.")]
string directoryPath,
[Argument("output-path", Description = "path of the output file dumped action.")]
string outputPath
)
{
var files = Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories);
var avatarStates = files.Select(a =>
{
var raw = File.ReadAllText(a);
return (Dictionary)_codec.Decode(ByteUtil.ParseHex(raw));
}).ToList();
var action = new MigrationAvatarState()
{
avatarStates = avatarStates
};

var encoded = new List(
(Text)nameof(Nekoyume.Action.MigrationAvatarState),
action.PlainValue
);

byte[] raw = _codec.Encode(encoded);
File.WriteAllText(outputPath, ByteUtil.Hex(raw));
}

[Command(Description = "Create AddRedeemCode action and dump it.")]
public void AddRedeemCode(
[Argument("TABLE-PATH", Description = "A table file path for RedeemCodeListSheet")]
Expand Down
Loading

0 comments on commit a11565e

Please sign in to comment.