Skip to content

Commit

Permalink
Replace NetworkType to Planet
Browse files Browse the repository at this point in the history
  • Loading branch information
longfin committed Feb 2, 2024
1 parent f992ad3 commit d10c1f4
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 37 deletions.
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("networkType 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"
}
}
3 changes: 2 additions & 1 deletion NineChronicles.Headless.Tests/Common/ServiceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Libplanet.Blockchain.Policies;
using NineChronicles.Headless.Properties;
using Nekoyume.Blockchain.Policy;
using Nekoyume;

namespace NineChronicles.Headless.Tests.Common
{
Expand Down Expand Up @@ -53,7 +54,7 @@ public static NineChroniclesNodeService CreateNineChroniclesNodeService(
privateKey,
properties,
BlockPolicy,
NetworkType.Main,
Planet.Odin,
StaticActionLoaderSingleton.Instance);
}
}
Expand Down
12 changes: 6 additions & 6 deletions NineChronicles.Headless.Tests/GraphTypes/StandaloneQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ public async Task ActivationStatus(bool existsActivatedAccounts)
var blockPolicy = new BlockPolicySource().GetPolicy();

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

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

var blockPolicy = NineChroniclesNodeService.GetBlockPolicy(NetworkType.Main, StaticActionLoaderSingleton.Instance);
var service = new NineChroniclesNodeService(userPrivateKey, properties, blockPolicy, NetworkType.Main, 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 @@ -986,7 +986,7 @@ public async Task ActivationKeyNonce_Throw_ExecutionError(string code, string ms
};
var blockPolicy = new BlockPolicySource().GetPolicy();

var service = new NineChroniclesNodeService(userPrivateKey, properties, blockPolicy, NetworkType.Main, 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 @@ -1064,7 +1064,7 @@ public async Task Balance()
};
var blockPolicy = new BlockPolicySource().GetPolicy();

var service = new NineChroniclesNodeService(userPrivateKey, properties, blockPolicy, NetworkType.Main, 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 @@ -1173,7 +1173,7 @@ private NineChroniclesNodeService MakeNineChroniclesNodeService(PrivateKey priva
ConsensusPeers = ImmutableList<BoundPeer>.Empty,
};

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

private (ProtectedPrivateKey, string) CreateProtectedPrivateKey()
Expand Down
26 changes: 15 additions & 11 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,15 +256,17 @@ StandaloneContext context
return service;
}

internal static IBlockPolicy GetBlockPolicy(NetworkType networkType, IActionLoader actionLoader)
internal static IBlockPolicy GetBlockPolicy(Planet planet, IActionLoader actionLoader)
{
var source = new BlockPolicySource(actionLoader);
return networkType switch
return planet switch
{
NetworkType.Main => source.GetPolicy(),
NetworkType.Internal => source.GetInternalPolicy(),
NetworkType.Default => source.GetDefaultPolicy(),
_ => throw new ArgumentOutOfRangeException(nameof(networkType), networkType, null),
Planet.Odin => source.GetPolicy(),
Planet.OdinInternal => source.GetInternalPolicy(),
_ => throw new ArgumentException(
$"Can't retrieve policy for given planet ({planet})",
nameof(planet)
),
};
}

Expand Down
9 changes: 0 additions & 9 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 d10c1f4

Please sign in to comment.