Skip to content

Commit

Permalink
Merge branch 'development' into release/100
Browse files Browse the repository at this point in the history
  • Loading branch information
U-lis committed Feb 19, 2024
2 parents 03c0b96 + d7f42c2 commit f102ef5
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void Inspect(StoreType storeType)
IStore store = storeType.CreateStore(_storePath);
IStateStore stateStore = new TrieStateStore(new RocksDBKeyValueStore(Path.Combine(_storePath, "states")));
IStagePolicy stagePolicy = new VolatileStagePolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetTestPolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy();
ActionEvaluator actionEvaluator = new ActionEvaluator(
_ => blockPolicy.BlockAction,
stateStore,
Expand Down Expand Up @@ -151,7 +151,7 @@ public void Truncate(StoreType storeType)
IStore store = storeType.CreateStore(_storePath);
IStateStore stateStore = new TrieStateStore(new RocksDBKeyValueStore(Path.Combine(_storePath, "states")));
IStagePolicy stagePolicy = new VolatileStagePolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetTestPolicy();
IBlockPolicy blockPolicy = new BlockPolicySource().GetPolicy();
ActionEvaluator actionEvaluator = new ActionEvaluator(
_ => blockPolicy.BlockAction,
stateStore,
Expand Down
8 changes: 5 additions & 3 deletions NineChronicles.Headless.Executable/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using Libplanet.Headless;
using Nekoyume;
using NineChronicles.Headless.Properties;

namespace NineChronicles.Headless.Executable
Expand Down Expand Up @@ -38,8 +39,9 @@ public class Configuration
public string? MinerPrivateKeyString { get; set; }
public int MinerBlockIntervalMilliseconds { get; set; }

public Planet Planet { get; set; } = Planet.Odin;

// Networking
public NetworkType NetworkType { get; set; } = NetworkType.Main;
public string[]? IceServerStrings { get; set; }
public string[]? PeerStrings { get; set; }

Expand Down Expand Up @@ -107,7 +109,7 @@ public void Overwrite(
int? minerCount,
string? minerPrivateKeyString,
int? minerBlockIntervalMilliseconds,
NetworkType? networkType,
Planet? planet,
string[]? iceServerStrings,
string[]? peerStrings,
bool? rpcServer,
Expand Down Expand Up @@ -158,7 +160,7 @@ public void Overwrite(
MinerCount = minerCount ?? MinerCount;
MinerPrivateKeyString = minerPrivateKeyString ?? MinerPrivateKeyString;
MinerBlockIntervalMilliseconds = minerBlockIntervalMilliseconds ?? MinerBlockIntervalMilliseconds;
NetworkType = networkType ?? NetworkType;
Planet = planet ?? Planet;
IceServerStrings = iceServerStrings ?? IceServerStrings;
PeerStrings = peerStrings ?? PeerStrings;
RpcServer = rpcServer ?? RpcServer;
Expand Down
16 changes: 12 additions & 4 deletions NineChronicles.Headless.Executable/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
using Nekoyume.Action.Loader;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using Nekoyume;

namespace NineChronicles.Headless.Executable
{
Expand Down Expand Up @@ -160,8 +161,10 @@ public async Task Run(
bool? strictRendering = null,
[Option(Description = "Log action renders besides block renders. --rpc-server implies this.")]
bool? logActionRenders = null,
[Option("network-type", Description = "Network type.")]
NetworkType? networkType = null,
[Option("network-type", Description = "(deprecated) Network type.")]
string? networkType = null,
[Option("planet", Description = "Planet")]
Planet? planet = null,
[Option(Description =
"The lifetime of each transaction, which uses minute as its unit.")]
int? txLifeTime = null,
Expand Down Expand Up @@ -250,6 +253,11 @@ public async Task Run(
var headlessConfig = new Configuration();
configuration.Bind("Headless", headlessConfig);

if (networkType is { })
{
Log.Warning("'--network-type' option has been deprecated and has no effect. please use `--planet` instead.");
}

IActionEvaluatorConfiguration? GetActionEvaluatorConfiguration(IConfiguration configuration)
{
if (!(configuration.GetValue<ActionEvaluatorType>("Type") is { } actionEvaluatorType))
Expand Down Expand Up @@ -287,7 +295,7 @@ public async Task Run(
headlessConfig.Overwrite(
appProtocolVersionToken, trustedAppProtocolVersionSigners, genesisBlockPath, host, port,
swarmPrivateKeyString, storeType, storePath, noReduceStore, noMiner, minerCount,
minerPrivateKeyString, minerBlockIntervalMilliseconds, networkType, iceServerStrings, peerStrings, rpcServer, rpcListenHost,
minerPrivateKeyString, minerBlockIntervalMilliseconds, planet, iceServerStrings, peerStrings, rpcServer, rpcListenHost,
rpcListenPort, rpcRemoteServer, rpcHttpServer, graphQLServer, graphQLHost, graphQLPort,
graphQLSecretTokenPath, noCors, nonblockRenderer, nonblockRendererQueue, strictRendering,
logActionRenders, confirmations,
Expand Down Expand Up @@ -445,7 +453,7 @@ IActionLoader MakeSingleActionLoader()
{
MinerPrivateKey = minerPrivateKey,
Libplanet = properties,
NetworkType = headlessConfig.NetworkType,
Planet = headlessConfig.Planet,
StrictRender = headlessConfig.StrictRendering,
TxLifeTime = TimeSpan.FromMinutes(headlessConfig.TxLifeTime),
MinerCount = headlessConfig.MinerCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@
"NoCors": true,
"Confirmations": 0,
"ChainTipStaleBehaviorType": "reboot",
"NetworkType": "Internal"
"Planet": "OdinInternal"
}
}
6 changes: 4 additions & 2 deletions NineChronicles.Headless.Tests/Common/ServiceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.IO;
using Libplanet.Blockchain.Policies;
using NineChronicles.Headless.Properties;
using Nekoyume.Blockchain.Policy;
using Nekoyume;

namespace NineChronicles.Headless.Tests.Common
{
Expand All @@ -17,7 +19,7 @@ public static class ServiceBuilder
public const int MaximumTransactions = 100;

public static IBlockPolicy BlockPolicy =>
NineChroniclesNodeService.GetTestBlockPolicy();
new BlockPolicySource().GetPolicy();

public static NineChroniclesNodeService CreateNineChroniclesNodeService(
Block genesis,
Expand Down Expand Up @@ -52,7 +54,7 @@ public static NineChroniclesNodeService CreateNineChroniclesNodeService(
privateKey,
properties,
BlockPolicy,
NetworkType.Test,
Planet.Odin,
StaticActionLoaderSingleton.Instance);
}
}
Expand Down
21 changes: 11 additions & 10 deletions NineChronicles.Headless.Tests/GraphTypes/StandaloneQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using Nekoyume;
using Nekoyume.Action;
using Nekoyume.Action.Loader;
using Nekoyume.Blockchain.Policy;
using Nekoyume.Helper;
using Nekoyume.Model;
using Nekoyume.Model.State;
Expand Down Expand Up @@ -512,10 +513,10 @@ public async Task ActivationStatus(bool existsActivatedAccounts)
ConsensusSeeds = ImmutableList<BoundPeer>.Empty,
ConsensusPeers = ImmutableList<BoundPeer>.Empty
};
var blockPolicy = NineChroniclesNodeService.GetTestBlockPolicy();
var blockPolicy = new BlockPolicySource().GetPolicy();

var service = new NineChroniclesNodeService(
userPrivateKey, properties, blockPolicy, NetworkType.Test, StaticActionLoaderSingleton.Instance);
userPrivateKey, properties, blockPolicy, Planet.Odin, StaticActionLoaderSingleton.Instance);
StandaloneContextFx.NineChroniclesNodeService = service;
StandaloneContextFx.BlockChain = service.Swarm?.BlockChain;

Expand Down Expand Up @@ -896,8 +897,8 @@ public async Task ActivationKeyNonce(bool trim)
ConsensusPeers = ImmutableList<BoundPeer>.Empty
};

var blockPolicy = NineChroniclesNodeService.GetBlockPolicy(NetworkType.Test, StaticActionLoaderSingleton.Instance);
var service = new NineChroniclesNodeService(userPrivateKey, properties, blockPolicy, NetworkType.Test, StaticActionLoaderSingleton.Instance);
var blockPolicy = NineChroniclesNodeService.GetBlockPolicy(Planet.Odin, StaticActionLoaderSingleton.Instance);
var service = new NineChroniclesNodeService(userPrivateKey, properties, blockPolicy, Planet.Odin, StaticActionLoaderSingleton.Instance);
StandaloneContextFx.NineChroniclesNodeService = service;
StandaloneContextFx.BlockChain = service.Swarm?.BlockChain;

Expand Down Expand Up @@ -983,9 +984,9 @@ public async Task ActivationKeyNonce_Throw_ExecutionError(string code, string ms
ConsensusSeeds = ImmutableList<BoundPeer>.Empty,
ConsensusPeers = ImmutableList<BoundPeer>.Empty
};
var blockPolicy = NineChroniclesNodeService.GetTestBlockPolicy();
var blockPolicy = new BlockPolicySource().GetPolicy();

var service = new NineChroniclesNodeService(userPrivateKey, properties, blockPolicy, NetworkType.Test, StaticActionLoaderSingleton.Instance);
var service = new NineChroniclesNodeService(userPrivateKey, properties, blockPolicy, Planet.Odin, StaticActionLoaderSingleton.Instance);
StandaloneContextFx.NineChroniclesNodeService = service;
StandaloneContextFx.BlockChain = service.Swarm?.BlockChain;

Expand Down Expand Up @@ -1061,9 +1062,9 @@ public async Task Balance()
ConsensusSeeds = ImmutableList<BoundPeer>.Empty,
ConsensusPeers = ImmutableList<BoundPeer>.Empty
};
var blockPolicy = NineChroniclesNodeService.GetTestBlockPolicy();
var blockPolicy = new BlockPolicySource().GetPolicy();

var service = new NineChroniclesNodeService(userPrivateKey, properties, blockPolicy, NetworkType.Test, StaticActionLoaderSingleton.Instance);
var service = new NineChroniclesNodeService(userPrivateKey, properties, blockPolicy, Planet.Odin, StaticActionLoaderSingleton.Instance);
StandaloneContextFx.NineChroniclesNodeService = service;
StandaloneContextFx.BlockChain = service.Swarm?.BlockChain;

Expand Down Expand Up @@ -1104,7 +1105,7 @@ private NineChroniclesNodeService MakeNineChroniclesNodeService(PrivateKey priva
var goldCurrency = Currency.Legacy("NCG", 2, null);
#pragma warning restore CS0618

var blockPolicy = NineChroniclesNodeService.GetTestBlockPolicy();
var blockPolicy = new BlockPolicySource().GetPolicy();
var validatorSetCandidate = new ValidatorSet(new[]
{
new Libplanet.Types.Consensus.Validator(ProposerPrivateKey.PublicKey, BigInteger.One),
Expand Down Expand Up @@ -1172,7 +1173,7 @@ private NineChroniclesNodeService MakeNineChroniclesNodeService(PrivateKey priva
ConsensusPeers = ImmutableList<BoundPeer>.Empty,
};

return new NineChroniclesNodeService(privateKey, properties, blockPolicy, NetworkType.Test, StaticActionLoaderSingleton.Instance);
return new NineChroniclesNodeService(privateKey, properties, blockPolicy, Planet.Odin, StaticActionLoaderSingleton.Instance);
}

private (ProtectedPrivateKey, string) CreateProtectedPrivateKey()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using NineChronicles.Headless.Utils;
using Xunit;
using static NineChronicles.Headless.NCActionUtils;
using Nekoyume.Blockchain.Policy;

namespace NineChronicles.Headless.Tests.GraphTypes
{
Expand All @@ -42,7 +43,7 @@ public TransactionHeadlessQueryTest()
{
_store = new DefaultStore(null);
_stateStore = new TrieStateStore(new DefaultKeyValueStore(null));
IBlockPolicy policy = NineChroniclesNodeService.GetTestBlockPolicy();
IBlockPolicy policy = new BlockPolicySource().GetPolicy();
var actionEvaluator = new ActionEvaluator(
_ => policy.BlockAction,
_stateStore,
Expand Down
30 changes: 9 additions & 21 deletions NineChronicles.Headless/NineChroniclesNodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using Serilog;
using Serilog.Events;
using StrictRenderer = Libplanet.Blockchain.Renderers.Debug.ValidatingActionRenderer;
using Nekoyume;

namespace NineChronicles.Headless
{
Expand Down Expand Up @@ -71,7 +72,7 @@ public NineChroniclesNodeService(
PrivateKey? minerPrivateKey,
LibplanetNodeServiceProperties properties,
IBlockPolicy blockPolicy,
NetworkType networkType,
Planet planet,
IActionLoader actionLoader,
Progress<BlockSyncState>? preloadProgress = null,
bool ignoreBootstrapFailure = false,
Expand Down Expand Up @@ -200,14 +201,15 @@ StandaloneContext context
);
};

var blockPolicy = NineChroniclesNodeService.GetBlockPolicy(
properties.NetworkType,
properties.ActionLoader);
IBlockPolicy blockPolicy = GetBlockPolicy(
properties.Planet,
properties.ActionLoader
);
var service = new NineChroniclesNodeService(
properties.MinerPrivateKey,
properties.Libplanet,
blockPolicy,
properties.NetworkType,
properties.Planet,
properties.ActionLoader,
preloadProgress: progress,
ignoreBootstrapFailure: properties.IgnoreBootstrapFailure,
Expand Down Expand Up @@ -254,22 +256,8 @@ StandaloneContext context
return service;
}

internal static IBlockPolicy GetBlockPolicy(NetworkType networkType, IActionLoader actionLoader)
{
var source = new BlockPolicySource(actionLoader);
return networkType switch
{
NetworkType.Main => source.GetPolicy(),
NetworkType.Internal => source.GetInternalPolicy(),
NetworkType.Permanent => source.GetPermanentPolicy(),
NetworkType.Test => source.GetTestPolicy(),
NetworkType.Default => source.GetDefaultPolicy(),
_ => throw new ArgumentOutOfRangeException(nameof(networkType), networkType, null),
};
}

internal static IBlockPolicy GetTestBlockPolicy() =>
new BlockPolicySource().GetTestPolicy();
internal static IBlockPolicy GetBlockPolicy(Planet planet, IActionLoader actionLoader)
=> new BlockPolicySource(actionLoader).GetPolicy(planet);

public Task<bool> CheckPeer(string addr) => NodeService?.CheckPeer(addr) ?? throw new InvalidOperationException();

Expand Down
11 changes: 0 additions & 11 deletions NineChronicles.Headless/Properties/NetworkType.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Libplanet.Net;
using Libplanet.Headless.Hosting;
using Libplanet.Headless;
using Nekoyume;

namespace NineChronicles.Headless.Properties
{
Expand All @@ -29,7 +30,7 @@ public NineChroniclesNodeServiceProperties(

public LibplanetNodeServiceProperties? Libplanet { get; set; }

public NetworkType NetworkType { get; set; } = NetworkType.Main;
public Planet Planet { get; set; } = Planet.Odin;

// FIXME: Replaced by NetworkType.Dev (not exist yet).
public bool Dev { get; set; }
Expand Down

0 comments on commit f102ef5

Please sign in to comment.