From 7a1aad60934005bd3a857df75859726a4157a124 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Thu, 8 Feb 2024 09:33:58 +0800 Subject: [PATCH 1/3] fix the store crash issue --- src/Neo.CLI/CLI/MainService.cs | 3 +-- src/Neo/NeoSystem.cs | 16 ++++++++++++++-- src/Neo/Persistence/StoreFactory.cs | 2 -- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Neo.CLI/CLI/MainService.cs b/src/Neo.CLI/CLI/MainService.cs index abd23121f7..4b0fccb343 100644 --- a/src/Neo.CLI/CLI/MainService.cs +++ b/src/Neo.CLI/CLI/MainService.cs @@ -377,8 +377,7 @@ public async void Start(CommandLineOptions options) ProtocolSettings protocol = ProtocolSettings.Load("config.json"); CustomProtocolSettings(options, protocol); CustomApplicationSettings(options, Settings.Default); - var store = StoreFactory.GetStore(Settings.Default.Storage.Engine, string.Format(Settings.Default.Storage.Path, protocol.Network.ToString("X8"))); - NeoSystem = new NeoSystem(protocol, store); + NeoSystem = new NeoSystem(protocol, Settings.Default.Storage.Engine, string.Format(Settings.Default.Storage.Path, protocol.Network.ToString("X8"))); NeoSystem.AddService(this); LocalNode = NeoSystem.LocalNode.Ask(new LocalNode.GetInstance()).Result; diff --git a/src/Neo/NeoSystem.cs b/src/Neo/NeoSystem.cs index 4713c284ff..2989a6e840 100644 --- a/src/Neo/NeoSystem.cs +++ b/src/Neo/NeoSystem.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; @@ -109,6 +110,16 @@ static NeoSystem() Plugin.LoadPlugins(); } + /// + /// Initializes a new instance of the class. + /// + /// The protocol settings of the . + /// The storage engine used to create the objects. If this parameter is , a default in-memory storage engine will be used. + /// The path of the storage. If is the default in-memory storage engine, this parameter is ignored. + public NeoSystem(ProtocolSettings settings, string? storageEngine = null, string? storagePath = null) : this(settings, LoadStore(storageEngine ?? nameof(MemoryStore), storagePath)) + { + } + /// /// Initializes a new instance of the class. /// @@ -211,11 +222,12 @@ public void EnsureStopped(IActorRef actor) /// /// Loads an at the specified path. /// + /// The storage engine used to create the objects. /// The path of the storage. /// The loaded . - public IStore LoadStore(string path) + public static IStore LoadStore([NotNull] string storageEngine, string path) { - return StoreFactory.GetStore(store.GetType().Name, path); + return StoreFactory.GetStore(storageEngine, path); } /// diff --git a/src/Neo/Persistence/StoreFactory.cs b/src/Neo/Persistence/StoreFactory.cs index 622c152acf..d24e94960c 100644 --- a/src/Neo/Persistence/StoreFactory.cs +++ b/src/Neo/Persistence/StoreFactory.cs @@ -29,9 +29,7 @@ static StoreFactory() RegisterProvider(memProvider); // Default cases - providers.Add("", memProvider); - providers.Add(null, memProvider); } public static void RegisterProvider(IStoreProvider provider) From 38d9e358bd4c5a51b2382f2af44df68113ce6625 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Thu, 8 Feb 2024 16:57:24 +0800 Subject: [PATCH 2/3] remove loadstore --- src/Neo.CLI/CLI/MainService.cs | 4 ++-- src/Neo/NeoSystem.cs | 13 +------------ 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/Neo.CLI/CLI/MainService.cs b/src/Neo.CLI/CLI/MainService.cs index 4b0fccb343..868a82d8ef 100644 --- a/src/Neo.CLI/CLI/MainService.cs +++ b/src/Neo.CLI/CLI/MainService.cs @@ -371,7 +371,7 @@ public void OpenWallet(string path, string password) public async void Start(CommandLineOptions options) { - if (NeoSystem != null) return; + if (_neoSystem != null) return; bool verifyImport = !(options.NoVerify ?? false); ProtocolSettings protocol = ProtocolSettings.Load("config.json"); @@ -411,7 +411,7 @@ public async void Start(CommandLineOptions options) Blocks = blocksToImport, Verify = verifyImport }); - if (NeoSystem is null) return; + if (_neoSystem is null) return; } } NeoSystem.StartNode(new ChannelsConfig diff --git a/src/Neo/NeoSystem.cs b/src/Neo/NeoSystem.cs index 2989a6e840..5c9ff8bbf4 100644 --- a/src/Neo/NeoSystem.cs +++ b/src/Neo/NeoSystem.cs @@ -116,7 +116,7 @@ static NeoSystem() /// The protocol settings of the . /// The storage engine used to create the objects. If this parameter is , a default in-memory storage engine will be used. /// The path of the storage. If is the default in-memory storage engine, this parameter is ignored. - public NeoSystem(ProtocolSettings settings, string? storageEngine = null, string? storagePath = null) : this(settings, LoadStore(storageEngine ?? nameof(MemoryStore), storagePath)) + public NeoSystem(ProtocolSettings settings, string? storageEngine = null, string? storagePath = null) : this(settings, StoreFactory.GetStore(storageEngine ?? nameof(MemoryStore), storagePath)) { } @@ -219,17 +219,6 @@ public void EnsureStopped(IActorRef actor) inbox.Receive(TimeSpan.FromMinutes(5)); } - /// - /// Loads an at the specified path. - /// - /// The storage engine used to create the objects. - /// The path of the storage. - /// The loaded . - public static IStore LoadStore([NotNull] string storageEngine, string path) - { - return StoreFactory.GetStore(storageEngine, path); - } - /// /// Resumes the startup process of . /// From 96acbc259c2903f23058286067ff94f1fa709c5c Mon Sep 17 00:00:00 2001 From: Fernando Diaz Toledano Date: Thu, 8 Feb 2024 12:06:55 +0100 Subject: [PATCH 3/3] Clean changes --- src/Neo.CLI/CLI/MainService.cs | 4 ++-- src/Neo/NeoSystem.cs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Neo.CLI/CLI/MainService.cs b/src/Neo.CLI/CLI/MainService.cs index 868a82d8ef..4b0fccb343 100644 --- a/src/Neo.CLI/CLI/MainService.cs +++ b/src/Neo.CLI/CLI/MainService.cs @@ -371,7 +371,7 @@ public void OpenWallet(string path, string password) public async void Start(CommandLineOptions options) { - if (_neoSystem != null) return; + if (NeoSystem != null) return; bool verifyImport = !(options.NoVerify ?? false); ProtocolSettings protocol = ProtocolSettings.Load("config.json"); @@ -411,7 +411,7 @@ public async void Start(CommandLineOptions options) Blocks = blocksToImport, Verify = verifyImport }); - if (_neoSystem is null) return; + if (NeoSystem is null) return; } } NeoSystem.StartNode(new ChannelsConfig diff --git a/src/Neo/NeoSystem.cs b/src/Neo/NeoSystem.cs index 5c9ff8bbf4..77b982f0d4 100644 --- a/src/Neo/NeoSystem.cs +++ b/src/Neo/NeoSystem.cs @@ -22,7 +22,6 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading;