From aad67771b1d4b948a3d0d15801657f00aa52a240 Mon Sep 17 00:00:00 2001 From: Lukasz Rozmej Date: Wed, 17 Jul 2024 13:47:28 +0200 Subject: [PATCH] Load local key if MiningConfig.Enabled is true (#7267) --- src/Nethermind/Nethermind.Consensus/IMiningConfig.cs | 2 +- src/Nethermind/Nethermind.Consensus/MiningConfig.cs | 2 +- src/Nethermind/Nethermind.Init/Steps/SetupKeyStore.cs | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/IMiningConfig.cs b/src/Nethermind/Nethermind.Consensus/IMiningConfig.cs index 4562ab03327..c3a2389af05 100644 --- a/src/Nethermind/Nethermind.Consensus/IMiningConfig.cs +++ b/src/Nethermind/Nethermind.Consensus/IMiningConfig.cs @@ -56,5 +56,5 @@ public interface IMiningConfig : IConfig Description = "Url for an external signer like clef: https://github.com/ethereum/go-ethereum/blob/master/cmd/clef/tutorial.md", HiddenFromDocs = false, DefaultValue = "null")] - string Signer { get; set; } + string? Signer { get; set; } } diff --git a/src/Nethermind/Nethermind.Consensus/MiningConfig.cs b/src/Nethermind/Nethermind.Consensus/MiningConfig.cs index 25677828cae..76471d68f37 100644 --- a/src/Nethermind/Nethermind.Consensus/MiningConfig.cs +++ b/src/Nethermind/Nethermind.Consensus/MiningConfig.cs @@ -71,5 +71,5 @@ public IBlocksConfig? BlocksConfig } } - public string Signer { get; set; } + public string? Signer { get; set; } } diff --git a/src/Nethermind/Nethermind.Init/Steps/SetupKeyStore.cs b/src/Nethermind/Nethermind.Init/Steps/SetupKeyStore.cs index cd181ef667b..1d5a14b2b56 100644 --- a/src/Nethermind/Nethermind.Init/Steps/SetupKeyStore.cs +++ b/src/Nethermind/Nethermind.Init/Steps/SetupKeyStore.cs @@ -46,8 +46,8 @@ await Task.Run(() => set.Wallet = get.Config() switch { - var config when config.EnableUnsecuredDevWallet && config.KeepDevWalletInMemory => new DevWallet(get.Config(), get.LogManager), - var config when config.EnableUnsecuredDevWallet && !config.KeepDevWalletInMemory => new DevKeyStoreWallet(get.KeyStore, get.LogManager), + { EnableUnsecuredDevWallet: true, KeepDevWalletInMemory: true } => new DevWallet(get.Config(), get.LogManager), + { EnableUnsecuredDevWallet: true, KeepDevWalletInMemory: false } => new DevKeyStoreWallet(get.KeyStore, get.LogManager), _ => new ProtectedKeyStoreWallet(keyStore, new ProtectedPrivateKeyFactory(get.CryptoRandom, get.Timestamper, keyStoreConfig.KeyStoreDirectory), get.Timestamper, get.LogManager), }; @@ -62,9 +62,11 @@ await Task.Run(() => ProtectedPrivateKey? nodeKey = set.NodeKey = nodeKeyManager.LoadNodeKey(); IMiningConfig miningConfig = get.Config(); - //Don't load the local key if an external signer is configured - if (!miningConfig.Enabled && string.IsNullOrEmpty(miningConfig.Signer)) + //Don't load the local key if an external signer is configured + if (string.IsNullOrEmpty(miningConfig.Signer)) + { set.OriginalSignerKey = nodeKeyManager.LoadSignerKey(); + } IPAddress ipAddress = networkConfig.ExternalIp is not null ? IPAddress.Parse(networkConfig.ExternalIp) : IPAddress.Loopback; IEnode enode = set.Enode = new Enode(nodeKey.PublicKey, ipAddress, networkConfig.P2PPort);