diff --git a/Lib9c b/Lib9c index 7575c9a65..dced32aaa 160000 --- a/Lib9c +++ b/Lib9c @@ -1 +1 @@ -Subproject commit 7575c9a657bcc3a43360de823568ee3b9f0219c9 +Subproject commit dced32aaa8fb1c9ddb6bdcc822b52c163c4230ad diff --git a/NineChronicles.Headless.Executable.Tests/Commands/ChainCommandTest.cs b/NineChronicles.Headless.Executable.Tests/Commands/ChainCommandTest.cs index bc5a62233..637bafecc 100644 --- a/NineChronicles.Headless.Executable.Tests/Commands/ChainCommandTest.cs +++ b/NineChronicles.Headless.Executable.Tests/Commands/ChainCommandTest.cs @@ -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, @@ -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, diff --git a/NineChronicles.Headless.Executable/Configuration.cs b/NineChronicles.Headless.Executable/Configuration.cs index d94805550..edf895785 100644 --- a/NineChronicles.Headless.Executable/Configuration.cs +++ b/NineChronicles.Headless.Executable/Configuration.cs @@ -1,6 +1,7 @@ using System; using System.IO; using Libplanet.Headless; +using Nekoyume; using NineChronicles.Headless.Properties; namespace NineChronicles.Headless.Executable @@ -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; } @@ -107,7 +109,7 @@ public void Overwrite( int? minerCount, string? minerPrivateKeyString, int? minerBlockIntervalMilliseconds, - NetworkType? networkType, + Planet? planet, string[]? iceServerStrings, string[]? peerStrings, bool? rpcServer, @@ -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; diff --git a/NineChronicles.Headless.Executable/Program.cs b/NineChronicles.Headless.Executable/Program.cs index 378a984b5..ee45f18fb 100644 --- a/NineChronicles.Headless.Executable/Program.cs +++ b/NineChronicles.Headless.Executable/Program.cs @@ -40,6 +40,7 @@ using Nekoyume.Action.Loader; using OpenTelemetry; using OpenTelemetry.Metrics; +using Nekoyume; namespace NineChronicles.Headless.Executable { @@ -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, @@ -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("Type") is { } actionEvaluatorType)) @@ -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, @@ -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, diff --git a/NineChronicles.Headless.Executable/appsettings.internal.json b/NineChronicles.Headless.Executable/appsettings.internal.json index c40f43ffe..2a2bafadb 100644 --- a/NineChronicles.Headless.Executable/appsettings.internal.json +++ b/NineChronicles.Headless.Executable/appsettings.internal.json @@ -90,6 +90,6 @@ "NoCors": true, "Confirmations": 0, "ChainTipStaleBehaviorType": "reboot", - "NetworkType": "Internal" + "Planet": "OdinInternal" } } diff --git a/NineChronicles.Headless.Tests/Common/ServiceBuilder.cs b/NineChronicles.Headless.Tests/Common/ServiceBuilder.cs index 8cc51ac04..49e69fe0f 100644 --- a/NineChronicles.Headless.Tests/Common/ServiceBuilder.cs +++ b/NineChronicles.Headless.Tests/Common/ServiceBuilder.cs @@ -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 { @@ -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, @@ -52,7 +54,7 @@ public static NineChroniclesNodeService CreateNineChroniclesNodeService( privateKey, properties, BlockPolicy, - NetworkType.Test, + Planet.Odin, StaticActionLoaderSingleton.Instance); } } diff --git a/NineChronicles.Headless.Tests/GraphTypes/StandaloneQueryTest.cs b/NineChronicles.Headless.Tests/GraphTypes/StandaloneQueryTest.cs index c9f5e06b3..4b36b5309 100644 --- a/NineChronicles.Headless.Tests/GraphTypes/StandaloneQueryTest.cs +++ b/NineChronicles.Headless.Tests/GraphTypes/StandaloneQueryTest.cs @@ -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; @@ -512,10 +513,10 @@ public async Task ActivationStatus(bool existsActivatedAccounts) ConsensusSeeds = ImmutableList.Empty, ConsensusPeers = ImmutableList.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; @@ -896,8 +897,8 @@ public async Task ActivationKeyNonce(bool trim) ConsensusPeers = ImmutableList.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; @@ -983,9 +984,9 @@ public async Task ActivationKeyNonce_Throw_ExecutionError(string code, string ms ConsensusSeeds = ImmutableList.Empty, ConsensusPeers = ImmutableList.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; @@ -1061,9 +1062,9 @@ public async Task Balance() ConsensusSeeds = ImmutableList.Empty, ConsensusPeers = ImmutableList.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; @@ -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), @@ -1172,7 +1173,7 @@ private NineChroniclesNodeService MakeNineChroniclesNodeService(PrivateKey priva ConsensusPeers = ImmutableList.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() diff --git a/NineChronicles.Headless.Tests/GraphTypes/TransactionHeadlessQueryTest.cs b/NineChronicles.Headless.Tests/GraphTypes/TransactionHeadlessQueryTest.cs index 822579659..62e3d68bf 100644 --- a/NineChronicles.Headless.Tests/GraphTypes/TransactionHeadlessQueryTest.cs +++ b/NineChronicles.Headless.Tests/GraphTypes/TransactionHeadlessQueryTest.cs @@ -27,6 +27,7 @@ using NineChronicles.Headless.Utils; using Xunit; using static NineChronicles.Headless.NCActionUtils; +using Nekoyume.Blockchain.Policy; namespace NineChronicles.Headless.Tests.GraphTypes { @@ -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, diff --git a/NineChronicles.Headless/NineChroniclesNodeService.cs b/NineChronicles.Headless/NineChroniclesNodeService.cs index 96dbec06d..24956e28e 100644 --- a/NineChronicles.Headless/NineChroniclesNodeService.cs +++ b/NineChronicles.Headless/NineChroniclesNodeService.cs @@ -25,6 +25,7 @@ using Serilog; using Serilog.Events; using StrictRenderer = Libplanet.Blockchain.Renderers.Debug.ValidatingActionRenderer; +using Nekoyume; namespace NineChronicles.Headless { @@ -71,7 +72,7 @@ public NineChroniclesNodeService( PrivateKey? minerPrivateKey, LibplanetNodeServiceProperties properties, IBlockPolicy blockPolicy, - NetworkType networkType, + Planet planet, IActionLoader actionLoader, Progress? preloadProgress = null, bool ignoreBootstrapFailure = false, @@ -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, @@ -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 CheckPeer(string addr) => NodeService?.CheckPeer(addr) ?? throw new InvalidOperationException(); diff --git a/NineChronicles.Headless/Properties/NetworkType.cs b/NineChronicles.Headless/Properties/NetworkType.cs deleted file mode 100644 index eb6e60e94..000000000 --- a/NineChronicles.Headless/Properties/NetworkType.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace NineChronicles.Headless.Properties -{ - public enum NetworkType - { - Main, - Internal, - Permanent, - Test, - Default, - } -} diff --git a/NineChronicles.Headless/Properties/NineChroniclesNodeServiceProperties.cs b/NineChronicles.Headless/Properties/NineChroniclesNodeServiceProperties.cs index b69914881..5121e961b 100644 --- a/NineChronicles.Headless/Properties/NineChroniclesNodeServiceProperties.cs +++ b/NineChronicles.Headless/Properties/NineChroniclesNodeServiceProperties.cs @@ -7,6 +7,7 @@ using Libplanet.Net; using Libplanet.Headless.Hosting; using Libplanet.Headless; +using Nekoyume; namespace NineChronicles.Headless.Properties { @@ -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; }