From bdfdf4ef49a1e688eb69c6def3c8995048641b72 Mon Sep 17 00:00:00 2001 From: s2quake Date: Fri, 30 Aug 2024 13:37:24 +0900 Subject: [PATCH 1/4] fix: Fix an issue where the SwarmService instance was created twice. --- .../NodeBuilder/LibplanetNodeBuilder.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sdk/node/Libplanet.Node.Extensions/NodeBuilder/LibplanetNodeBuilder.cs b/sdk/node/Libplanet.Node.Extensions/NodeBuilder/LibplanetNodeBuilder.cs index 0a0613774c2..51b3a7687fb 100644 --- a/sdk/node/Libplanet.Node.Extensions/NodeBuilder/LibplanetNodeBuilder.cs +++ b/sdk/node/Libplanet.Node.Extensions/NodeBuilder/LibplanetNodeBuilder.cs @@ -1,5 +1,6 @@ using Libplanet.Node.Services; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; namespace Libplanet.Node.Extensions.NodeBuilder; @@ -25,8 +26,9 @@ public ILibplanetNodeBuilder WithSolo() public ILibplanetNodeBuilder WithSwarm() { - Services.AddSingleton(); - Services.AddHostedService(); + Services.AddSingleton(); + Services.AddSingleton(s => (ISwarmService)s.GetRequiredService()); + Services.AddSingleton(s => (IHostedService)s.GetRequiredService()); _scopeList.Add("Swarm"); return this; } From d1bbbf6f22477868bb82c6f967401b58007deb6b Mon Sep 17 00:00:00 2001 From: s2quake Date: Fri, 30 Aug 2024 13:38:34 +0900 Subject: [PATCH 2/4] refactor: Rename StoreType's member --- sdk/node/Libplanet.Node/Options/StoreOptions.cs | 2 +- .../Libplanet.Node/Options/StoreOptionsConfigurator.cs | 8 ++++---- sdk/node/Libplanet.Node/Options/StoreType.cs | 6 ++---- sdk/node/Libplanet.Node/Services/BlockChainService.cs | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/sdk/node/Libplanet.Node/Options/StoreOptions.cs b/sdk/node/Libplanet.Node/Options/StoreOptions.cs index 8bc5991cddd..aefbba11b6d 100644 --- a/sdk/node/Libplanet.Node/Options/StoreOptions.cs +++ b/sdk/node/Libplanet.Node/Options/StoreOptions.cs @@ -15,7 +15,7 @@ public sealed class StoreOptions : OptionsBase /// The type of the store. /// [Description("The type of the store.")] - public StoreType Type { get; set; } = StoreType.Memory; + public StoreType Type { get; set; } = StoreType.InMemory; /// /// The root directory path of the store. diff --git a/sdk/node/Libplanet.Node/Options/StoreOptionsConfigurator.cs b/sdk/node/Libplanet.Node/Options/StoreOptionsConfigurator.cs index a44822c449e..84757786019 100644 --- a/sdk/node/Libplanet.Node/Options/StoreOptionsConfigurator.cs +++ b/sdk/node/Libplanet.Node/Options/StoreOptionsConfigurator.cs @@ -7,27 +7,27 @@ internal sealed class StoreOptionsConfigurator(ILogger { protected override void OnConfigure(StoreOptions options) { - if (options.Type == StoreType.Memory) + if (options.Type == StoreType.InMemory) { if (options.RootPath != string.Empty) { options.RootPath = string.Empty; logger.LogWarning( - "RootPath is ignored because StoreType is {Memory}.", StoreType.Memory); + "RootPath is ignored because StoreType is {Memory}.", StoreType.InMemory); } if (options.StoreName != string.Empty) { options.StoreName = string.Empty; logger.LogWarning( - "StorePath is ignored because StoreType is {Memory}.", StoreType.Memory); + "StorePath is ignored because StoreType is {Memory}.", StoreType.InMemory); } if (options.StateStoreName != string.Empty) { options.StateStoreName = string.Empty; logger.LogWarning( - "StateStorePath is ignored because StoreType is {Memory}.", StoreType.Memory); + "StateStorePath is ignored because StoreType is {Memory}.", StoreType.InMemory); } } else diff --git a/sdk/node/Libplanet.Node/Options/StoreType.cs b/sdk/node/Libplanet.Node/Options/StoreType.cs index 7a58d125ce6..86427f3eda2 100644 --- a/sdk/node/Libplanet.Node/Options/StoreType.cs +++ b/sdk/node/Libplanet.Node/Options/StoreType.cs @@ -1,5 +1,3 @@ -using System.ComponentModel; - namespace Libplanet.Node.Options; public enum StoreType @@ -7,10 +5,10 @@ public enum StoreType /// /// Store data in disk. /// - Disk, + RocksDB, /// /// Store data in memory. /// - Memory, + InMemory, } diff --git a/sdk/node/Libplanet.Node/Services/BlockChainService.cs b/sdk/node/Libplanet.Node/Services/BlockChainService.cs index 2f528bce875..49c4e1c6a49 100644 --- a/sdk/node/Libplanet.Node/Services/BlockChainService.cs +++ b/sdk/node/Libplanet.Node/Services/BlockChainService.cs @@ -137,8 +137,8 @@ private static (IStore, IStateStore) CreateStore(StoreOptions storeOptions) { return storeOptions.Type switch { - StoreType.Disk => CreateDiskStore(), - StoreType.Memory => CreateMemoryStore(), + StoreType.RocksDB => CreateDiskStore(), + StoreType.InMemory => CreateMemoryStore(), _ => throw new NotSupportedException($"Unsupported store type: {storeOptions.Type}"), }; From 119cf4db33ae1149d08ad5e4aea50077f340aef5 Mon Sep 17 00:00:00 2001 From: s2quake Date: Mon, 2 Sep 2024 10:12:25 +0900 Subject: [PATCH 3/4] refactor: Change C to c in BlockChain in BlockChainGrpcServiceV1 --- .../Libplanet.Node.Executable/Explorer/BlockChainContext.cs | 3 ++- sdk/node/Libplanet.Node.Executable/Program.cs | 2 +- sdk/node/Libplanet.Node.Executable/Protos/blockchain.proto | 2 +- .../{BlockChainGrpcServiceV1.cs => BlockchainGrpcServiceV0.cs} | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) rename sdk/node/Libplanet.Node.Executable/Services/{BlockChainGrpcServiceV1.cs => BlockchainGrpcServiceV0.cs} (95%) diff --git a/sdk/node/Libplanet.Node.Executable/Explorer/BlockChainContext.cs b/sdk/node/Libplanet.Node.Executable/Explorer/BlockChainContext.cs index 7923448a4b1..40b79fbc5fc 100644 --- a/sdk/node/Libplanet.Node.Executable/Explorer/BlockChainContext.cs +++ b/sdk/node/Libplanet.Node.Executable/Explorer/BlockChainContext.cs @@ -1,4 +1,5 @@ using System.Reflection; +using Libplanet.Blockchain; using Libplanet.Explorer.Indexing; using Libplanet.Explorer.Interfaces; using Libplanet.Net; @@ -12,7 +13,7 @@ internal sealed class BlockChainContext( { public bool Preloaded => false; - public Blockchain.BlockChain BlockChain => blockChainService.BlockChain; + public BlockChain BlockChain => blockChainService.BlockChain; #pragma warning disable S3011 // Reflection should not be used to increase accessibility ... public IStore Store diff --git a/sdk/node/Libplanet.Node.Executable/Program.cs b/sdk/node/Libplanet.Node.Executable/Program.cs index fa3c5761fc4..a50e30a2821 100644 --- a/sdk/node/Libplanet.Node.Executable/Program.cs +++ b/sdk/node/Libplanet.Node.Executable/Program.cs @@ -37,7 +37,7 @@ Communication with gRPC endpoints must be made through a gRPC client. To learn h """; using var app = builder.Build(); -app.MapGrpcService(); +app.MapGrpcService(); app.MapGrpcService(); app.MapGet("/", () => handlerMessage); if (builder.Environment.IsDevelopment()) diff --git a/sdk/node/Libplanet.Node.Executable/Protos/blockchain.proto b/sdk/node/Libplanet.Node.Executable/Protos/blockchain.proto index 08d868c9f77..fa061f70270 100644 --- a/sdk/node/Libplanet.Node.Executable/Protos/blockchain.proto +++ b/sdk/node/Libplanet.Node.Executable/Protos/blockchain.proto @@ -4,7 +4,7 @@ option csharp_namespace = "Libplanet.Node.API"; package node.blockchain.v1; -service BlockChain { +service Blockchain { rpc GetGenesisBlock (GetGenesisBlockRequest) returns (GetGenesisBlockReply); rpc GetTip(Empty) returns (GetTipReply); rpc GetBlock(GetBlockRequest) returns (GetBlockReply); diff --git a/sdk/node/Libplanet.Node.Executable/Services/BlockChainGrpcServiceV1.cs b/sdk/node/Libplanet.Node.Executable/Services/BlockchainGrpcServiceV0.cs similarity index 95% rename from sdk/node/Libplanet.Node.Executable/Services/BlockChainGrpcServiceV1.cs rename to sdk/node/Libplanet.Node.Executable/Services/BlockchainGrpcServiceV0.cs index 878926ce3c6..1ea0e4a22f3 100644 --- a/sdk/node/Libplanet.Node.Executable/Services/BlockChainGrpcServiceV1.cs +++ b/sdk/node/Libplanet.Node.Executable/Services/BlockchainGrpcServiceV0.cs @@ -5,7 +5,7 @@ namespace Libplanet.Node.API.Services; -public class BlockChainGrpcServiceV1(IReadChainService blockChain) : BlockChain.BlockChainBase +public class BlockchainGrpcServiceV1(IReadChainService blockChain) : Blockchain.BlockchainBase { private readonly IReadChainService _blockChain = blockChain; From 801224bd8d0cdbd382d24733ec3665f07a54bc21 Mon Sep 17 00:00:00 2001 From: s2quake Date: Mon, 2 Sep 2024 10:12:41 +0900 Subject: [PATCH 4/4] chore: Rename file --- .../{BlockchainGrpcServiceV0.cs => BlockchainGrpcServiceV1.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename sdk/node/Libplanet.Node.Executable/Services/{BlockchainGrpcServiceV0.cs => BlockchainGrpcServiceV1.cs} (100%) diff --git a/sdk/node/Libplanet.Node.Executable/Services/BlockchainGrpcServiceV0.cs b/sdk/node/Libplanet.Node.Executable/Services/BlockchainGrpcServiceV1.cs similarity index 100% rename from sdk/node/Libplanet.Node.Executable/Services/BlockchainGrpcServiceV0.cs rename to sdk/node/Libplanet.Node.Executable/Services/BlockchainGrpcServiceV1.cs