From 18e9182d0843154d28910e99b7f9dd923618a083 Mon Sep 17 00:00:00 2001 From: ak88 Date: Thu, 8 Feb 2024 13:25:12 +0100 Subject: [PATCH 01/27] external signer --- .../Nethermind.Consensus/ExternalSigner.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/Nethermind/Nethermind.Consensus/ExternalSigner.cs diff --git a/src/Nethermind/Nethermind.Consensus/ExternalSigner.cs b/src/Nethermind/Nethermind.Consensus/ExternalSigner.cs new file mode 100644 index 00000000000..12c85639c7b --- /dev/null +++ b/src/Nethermind/Nethermind.Consensus/ExternalSigner.cs @@ -0,0 +1,38 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using Nethermind.Core; +using Nethermind.Core.Crypto; +using Nethermind.Crypto; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Nethermind.Consensus; +public class ExternalSigner : ISigner +{ + private readonly string jsonRpcUrl; + + //public ExternalSigner(IJsonRpcClient rpcClient) + //{ + // this.jsonRpcUrl = jsonRpcUrl; + + //} + public PrivateKey? Key => throw new NotImplementedException(); + + public Address Address => throw new NotImplementedException(); + + public bool CanSign => throw new NotImplementedException(); + + public Signature Sign(Hash256 message) + { + throw new NotImplementedException(); + } + + public ValueTask Sign(Transaction tx) + { + throw new NotImplementedException(); + } +} From 8a812ffe6e75febb1f55a16b4132e066555c9d66 Mon Sep 17 00:00:00 2001 From: ak88 Date: Thu, 8 Feb 2024 13:47:13 +0100 Subject: [PATCH 02/27] moved rpc clients to light project --- .../Client/BasicJsonRpcClient.cs | 4 ---- .../Client/IJsonRpcClient.cs | 0 .../Client/JsonRpcResponse.cs | 0 .../Error.cs | 0 .../Nethermind.JsonRpc.Clients.csproj | 14 ++++++++++++++ .../Nethermind.JsonRpc/Nethermind.JsonRpc.csproj | 1 + src/Nethermind/Nethermind.sln | 6 ++++++ 7 files changed, 21 insertions(+), 4 deletions(-) rename src/Nethermind/{Nethermind.JsonRpc => Nethermind.JsonRpc.Connectors}/Client/BasicJsonRpcClient.cs (97%) rename src/Nethermind/{Nethermind.JsonRpc => Nethermind.JsonRpc.Connectors}/Client/IJsonRpcClient.cs (100%) rename src/Nethermind/{Nethermind.JsonRpc => Nethermind.JsonRpc.Connectors}/Client/JsonRpcResponse.cs (100%) rename src/Nethermind/{Nethermind.JsonRpc => Nethermind.JsonRpc.Connectors}/Error.cs (100%) create mode 100644 src/Nethermind/Nethermind.JsonRpc.Connectors/Nethermind.JsonRpc.Clients.csproj diff --git a/src/Nethermind/Nethermind.JsonRpc/Client/BasicJsonRpcClient.cs b/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs similarity index 97% rename from src/Nethermind/Nethermind.JsonRpc/Client/BasicJsonRpcClient.cs rename to src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs index 9570d9a4e2d..965b6e6b7b4 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Client/BasicJsonRpcClient.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs @@ -2,13 +2,9 @@ // SPDX-License-Identifier: LGPL-3.0-only using System; -using System.Collections.Generic; using System.Data; -using System.Linq; -using System.Net.Http; using System.Net.Http.Headers; using System.Text; -using System.Threading.Tasks; using Nethermind.Logging; using Nethermind.Serialization.Json; diff --git a/src/Nethermind/Nethermind.JsonRpc/Client/IJsonRpcClient.cs b/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/IJsonRpcClient.cs similarity index 100% rename from src/Nethermind/Nethermind.JsonRpc/Client/IJsonRpcClient.cs rename to src/Nethermind/Nethermind.JsonRpc.Connectors/Client/IJsonRpcClient.cs diff --git a/src/Nethermind/Nethermind.JsonRpc/Client/JsonRpcResponse.cs b/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/JsonRpcResponse.cs similarity index 100% rename from src/Nethermind/Nethermind.JsonRpc/Client/JsonRpcResponse.cs rename to src/Nethermind/Nethermind.JsonRpc.Connectors/Client/JsonRpcResponse.cs diff --git a/src/Nethermind/Nethermind.JsonRpc/Error.cs b/src/Nethermind/Nethermind.JsonRpc.Connectors/Error.cs similarity index 100% rename from src/Nethermind/Nethermind.JsonRpc/Error.cs rename to src/Nethermind/Nethermind.JsonRpc.Connectors/Error.cs diff --git a/src/Nethermind/Nethermind.JsonRpc.Connectors/Nethermind.JsonRpc.Clients.csproj b/src/Nethermind/Nethermind.JsonRpc.Connectors/Nethermind.JsonRpc.Clients.csproj new file mode 100644 index 00000000000..521306775f9 --- /dev/null +++ b/src/Nethermind/Nethermind.JsonRpc.Connectors/Nethermind.JsonRpc.Clients.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + annotations + + + + + + + + diff --git a/src/Nethermind/Nethermind.JsonRpc/Nethermind.JsonRpc.csproj b/src/Nethermind/Nethermind.JsonRpc/Nethermind.JsonRpc.csproj index a7900f361f1..7b0c0ba9d27 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Nethermind.JsonRpc.csproj +++ b/src/Nethermind/Nethermind.JsonRpc/Nethermind.JsonRpc.csproj @@ -16,6 +16,7 @@ + diff --git a/src/Nethermind/Nethermind.sln b/src/Nethermind/Nethermind.sln index 87f05329dfb..005f6c46d3f 100644 --- a/src/Nethermind/Nethermind.sln +++ b/src/Nethermind/Nethermind.sln @@ -224,6 +224,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution nuget.config = nuget.config EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nethermind.JsonRpc.Clients", "Nethermind.JsonRpc.Connectors\Nethermind.JsonRpc.Clients.csproj", "{513049F7-B0AD-4FB5-9223-C3B0237FD3B0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -614,6 +616,10 @@ Global {AD09FBCB-5496-499B-9129-B6D139A65B6F}.Debug|Any CPU.Build.0 = Debug|Any CPU {AD09FBCB-5496-499B-9129-B6D139A65B6F}.Release|Any CPU.ActiveCfg = Release|Any CPU {AD09FBCB-5496-499B-9129-B6D139A65B6F}.Release|Any CPU.Build.0 = Release|Any CPU + {513049F7-B0AD-4FB5-9223-C3B0237FD3B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {513049F7-B0AD-4FB5-9223-C3B0237FD3B0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {513049F7-B0AD-4FB5-9223-C3B0237FD3B0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {513049F7-B0AD-4FB5-9223-C3B0237FD3B0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 3f38c73b03d3f69eddde702d487d663e87a57929 Mon Sep 17 00:00:00 2001 From: ak88 Date: Thu, 8 Feb 2024 17:06:42 +0100 Subject: [PATCH 03/27] external signer --- .../Nethermind.Consensus/ExternalSigner.cs | 38 ++++++++++++++----- .../Nethermind.Consensus/ISignerAsync.cs | 18 +++++++++ 2 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 src/Nethermind/Nethermind.Consensus/ISignerAsync.cs diff --git a/src/Nethermind/Nethermind.Consensus/ExternalSigner.cs b/src/Nethermind/Nethermind.Consensus/ExternalSigner.cs index 12c85639c7b..1462f466f19 100644 --- a/src/Nethermind/Nethermind.Consensus/ExternalSigner.cs +++ b/src/Nethermind/Nethermind.Consensus/ExternalSigner.cs @@ -3,7 +3,10 @@ using Nethermind.Core; using Nethermind.Core.Crypto; +using Nethermind.Core.Extensions; using Nethermind.Crypto; +using Nethermind.JsonRpc.Client; +using Org.BouncyCastle.Utilities.Encoders; using System; using System.Collections.Generic; using System.Linq; @@ -13,26 +16,43 @@ namespace Nethermind.Consensus; public class ExternalSigner : ISigner { - private readonly string jsonRpcUrl; + private readonly IJsonRpcClient rpcClient; - //public ExternalSigner(IJsonRpcClient rpcClient) - //{ - // this.jsonRpcUrl = jsonRpcUrl; + private ExternalSigner(IJsonRpcClient rpcClient) + { + this.rpcClient = rpcClient; + CanSign = true; + } + + public static async Task Create(IJsonRpcClient jsonRpcClient) + { + ExternalSigner signer =new (jsonRpcClient); + await signer.SetSignerAddress(); + return signer; + } - //} - public PrivateKey? Key => throw new NotImplementedException(); + public Address Address { get; private set; } - public Address Address => throw new NotImplementedException(); + public bool CanSign { get; } - public bool CanSign => throw new NotImplementedException(); + public PrivateKey? Key => throw new InvalidOperationException("Private keys cannot be exposed."); public Signature Sign(Hash256 message) { - throw new NotImplementedException(); + //TODO handle async + var signed = rpcClient.Post("account_signData", "application/clique", Address.ToString(), message).GetAwaiter().GetResult(); + return new Signature(Bytes.FromHexString(signed)); } public ValueTask Sign(Transaction tx) { throw new NotImplementedException(); } + + private async Task SetSignerAddress() + { + //TODO sort the list and validate + var accounts = await rpcClient.Post("account_list"); + Address = new Address(accounts[0]); + } } diff --git a/src/Nethermind/Nethermind.Consensus/ISignerAsync.cs b/src/Nethermind/Nethermind.Consensus/ISignerAsync.cs new file mode 100644 index 00000000000..7aa4202ecb4 --- /dev/null +++ b/src/Nethermind/Nethermind.Consensus/ISignerAsync.cs @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using Nethermind.Core; +using Nethermind.Core.Crypto; +using Nethermind.Crypto; +using Nethermind.TxPool; +using System.Threading.Tasks; + +namespace Nethermind.Consensus +{ + public interface ISignerAsync : ITxSigner + { + Task Sign(Hash256 message); + Address Address { get; } + bool CanSign { get; } + } +} From 0fc08ed46169ea93a0d0a92f715439f47d06343f Mon Sep 17 00:00:00 2001 From: ak88 Date: Fri, 9 Feb 2024 08:30:19 +0100 Subject: [PATCH 04/27] clique test for joc --- src/Nethermind/Chains/clique-test.json | 941 ++++++++++++++++++ .../Consensus/ExternalSignerTests.cs | 43 + .../Nethermind.Consensus/ExternalSigner.cs | 1 + .../Nethermind.Consensus.csproj | 1 + .../Steps/InitializeBlockTree.cs | 11 +- .../Properties/launchSettings.json | 7 + .../Nethermind.Runner/configs/clique-test.cfg | 27 + 7 files changed, 1027 insertions(+), 4 deletions(-) create mode 100644 src/Nethermind/Chains/clique-test.json create mode 100644 src/Nethermind/Nethermind.Blockchain.Test/Consensus/ExternalSignerTests.cs create mode 100644 src/Nethermind/Nethermind.Runner/configs/clique-test.cfg diff --git a/src/Nethermind/Chains/clique-test.json b/src/Nethermind/Chains/clique-test.json new file mode 100644 index 00000000000..5f59628a921 --- /dev/null +++ b/src/Nethermind/Chains/clique-test.json @@ -0,0 +1,941 @@ +{ + "name": "Joc Testnet", + "dataDir": "joc", + "engine": { + "clique": { + "params": { + "period": 15, + "epoch": 30000 + } + } + }, + "params": { + "accountStartNonce": "0x0", + "chainID": "10081", + "eip140Transition": "0x0", + "eip145Transition": "0x0", + "eip150Transition": "0x0", + "eip155Transition": "0x0", + "eip160Transition": "0x0", + "eip161abcTransition": "0x0", + "eip161dTransition": "0x0", + "eip211Transition": "0x0", + "eip214Transition": "0x0", + "eip658Transition": "0x0", + "eip1014Transition": "0x0", + "eip1052Transition": "0x0", + "eip1283Transition": "0x0", + "eip1283DisableTransition": "0x0", + "eip152Transition": "0x17D433", + "eip1108Transition": "0x17D433", + "eip1344Transition": "0x17D433", + "eip1884Transition": "0x17D433", + "eip2028Transition": "0x17D433", + "eip2200Transition": "0x17D433", + "eip2565Transition": "0x441064", + "eip2929Transition": "0x441064", + "eip2930Transition": "0x441064", + "eip1559Transition": "0x4D3FCD", + "eip3198Transition": "0x4D3FCD", + "eip3529Transition": "0x4D3FCD", + "eip3541Transition": "0x4D3FCD", + "eip3651TransitionTimestamp": "0x6410F460", + "eip3855TransitionTimestamp": "0x6410F460", + "eip3860TransitionTimestamp": "0x6410F460", + "eip4895TransitionTimestamp": "0x6410F460", + "eip1153TransitionTimestamp": "0x65A77460", + "eip4788TransitionTimestamp": "0x65A77460", + "eip4844TransitionTimestamp": "0x65A77460", + "eip5656TransitionTimestamp": "0x65A77460", + "eip6780TransitionTimestamp": "0x65A77460", + "terminalTotalDifficulty": "ffffffA4A470", + "gasLimitBoundDivisor": "0x400", + "maxCodeSize": "0x6000", + "maxCodeSizeTransition": "0x0", + "maximumExtraDataSize": "0xffff", + "minGasLimit": "0x1388", + "networkID": "0x5" + }, + "genesis": { + "author": "0x0000000000000000000000000000000000000000", + "difficulty": "0x1", + "extraData": "0x22466c6578692069732061207468696e6722202d204166726900000000000000bab1b2527edb13aac27a3982a89a61b8007c5df10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "gasLimit": "0x1c03a180", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "seal": { + "ethereum": { + "nonce": "0x0000000000000000", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000" + } + }, + "timestamp": "0x5bfbe6b5" + }, + "nodes": [ + "enode://011f758e6552d105183b1761c5e2dea0111bc20fd5f6422bc7f91e0fabbec9a6595caf6239b37feb773dddd3f87240d99d859431891e4a642cf2a0a9e6cbb98a@51.141.78.53:30303", + "enode://176b9417f511d05b6b2cf3e34b756cf0a7096b3094572a8f6ef4cdcb9d1f9d00683bf0f83347eebdf3b81c3521c2332086d9592802230bf528eaf606a1d9677b@13.93.54.137:30303", + "enode://46add44b9f13965f7b9875ac6b85f016f341012d84f975377573800a863526f4da19ae2c620ec73d11591fa9510e992ecc03ad0751f53cc02f7c7ed6d55c7291@94.237.54.114:30313", + "enode://c1f8b7c2ac4453271fa07d8e9ecf9a2e8285aa0bd0c07df0131f47153306b0736fd3db8924e7a9bf0bed6b1d8d4f87362a71b033dc7c64547728d953e43e59b2@52.64.155.147:30303", + "enode://f4a9c6ee28586009fb5a96c8af13a58ed6d8315a9eee4772212c1d4d9cebe5a8b8a78ea4434f318726317d04a3f531a1ef0420cf9752605a562cfe858c46e263@213.186.16.82:30303", + "enode://a61215641fb8714a373c80edbfa0ea8878243193f57c96eeb44d0bc019ef295abd4e044fd619bfc4c59731a73fb79afe84e9ab6da0c743ceb479cbb6d263fa91@3.11.147.67:30303", + "enode://b5948a2d3e9d486c4d75bf32713221c2bd6cf86463302339299bd227dc2e276cd5a1c7ca4f43a0e9122fe9af884efed563bd2a1fd28661f3b5f5ad7bf1de5949@18.218.250.66:30303", + "enode://d2b720352e8216c9efc470091aa91ddafc53e222b32780f505c817ceef69e01d5b0b0797b69db254c586f493872352f5a022b4d8479a00fc92ec55f9ad46a27e@88.99.70.182:30303", + "enode://d4f764a48ec2a8ecf883735776fdefe0a3949eb0ca476bd7bc8d0954a9defe8fea15ae5da7d40b5d2d59ce9524a99daedadf6da6283fca492cc80b53689fb3b3@46.4.99.122:32109" + ], + "accounts": { + "0x0000000000000000000000000000000000000000": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000001": { + "balance": "0x1", + "builtin": { + "name": "ecrecover", + "pricing": { + "linear": { + "base": 3000, + "word": 0 + } + } + } + }, + "0x0000000000000000000000000000000000000002": { + "balance": "0x1", + "builtin": { + "name": "sha256", + "pricing": { + "linear": { + "base": 60, + "word": 12 + } + } + } + }, + "0x0000000000000000000000000000000000000003": { + "balance": "0x1", + "builtin": { + "name": "ripemd160", + "pricing": { + "linear": { + "base": 600, + "word": 120 + } + } + } + }, + "0x0000000000000000000000000000000000000004": { + "balance": "0x1", + "builtin": { + "name": "identity", + "pricing": { + "linear": { + "base": 15, + "word": 3 + } + } + } + }, + "0x0000000000000000000000000000000000000005": { + "balance": "0x1", + "builtin": { + "name": "modexp", + "activate_at": "0x0", + "pricing": { + "modexp": { + "divisor": 20 + } + } + } + }, + "0x0000000000000000000000000000000000000006": { + "balance": "0x1", + "builtin": { + "name": "alt_bn128_add", + "activate_at": "0x0", + "pricing": { + "linear": { + "base": 500, + "word": 0 + } + } + } + }, + "0x0000000000000000000000000000000000000007": { + "balance": "0x1", + "builtin": { + "name": "alt_bn128_mul", + "activate_at": "0x0", + "pricing": { + "linear": { + "base": 40000, + "word": 0 + } + } + } + }, + "0x0000000000000000000000000000000000000008": { + "balance": "0x1", + "builtin": { + "name": "alt_bn128_pairing", + "activate_at": "0x0", + "pricing": { + "alt_bn128_pairing": { + "base": 100000, + "pair": 80000 + } + } + } + }, + "0x0000000000000000000000000000000000000009": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000000a": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000000b": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000000c": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000000d": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000000e": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000000f": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000010": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000011": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000012": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000013": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000014": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000015": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000016": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000017": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000018": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000019": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000001a": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000001b": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000001c": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000001d": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000001e": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000001f": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000020": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000021": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000022": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000023": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000024": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000025": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000026": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000027": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000028": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000029": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000002a": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000002b": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000002c": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000002d": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000002e": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000002f": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000030": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000031": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000032": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000033": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000034": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000035": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000036": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000037": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000038": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000039": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000003a": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000003b": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000003c": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000003d": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000003e": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000003f": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000040": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000041": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000042": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000043": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000044": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000045": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000046": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000047": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000048": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000049": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000004a": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000004b": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000004c": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000004d": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000004e": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000004f": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000050": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000051": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000052": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000053": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000054": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000055": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000056": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000057": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000058": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000059": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000005a": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000005b": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000005c": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000005d": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000005e": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000005f": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000060": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000061": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000062": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000063": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000064": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000065": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000066": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000067": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000068": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000069": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000006a": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000006b": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000006c": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000006d": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000006e": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000006f": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000070": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000071": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000072": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000073": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000074": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000075": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000076": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000077": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000078": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000079": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000007a": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000007b": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000007c": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000007d": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000007e": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000007f": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000080": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000081": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000082": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000083": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000084": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000085": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000086": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000087": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000088": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000089": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000008a": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000008b": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000008c": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000008d": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000008e": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000008f": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000090": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000091": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000092": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000093": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000094": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000095": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000096": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000097": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000098": { + "balance": "0x1" + }, + "0x0000000000000000000000000000000000000099": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000009a": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000009b": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000009c": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000009d": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000009e": { + "balance": "0x1" + }, + "0x000000000000000000000000000000000000009f": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000a0": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000a1": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000a2": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000a3": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000a4": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000a5": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000a6": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000a7": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000a8": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000a9": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000aa": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000ab": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000ac": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000ad": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000ae": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000af": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000b0": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000b1": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000b2": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000b3": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000b4": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000b5": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000b6": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000b7": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000b8": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000b9": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000ba": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000bb": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000bc": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000bd": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000be": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000bf": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000c0": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000c1": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000c2": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000c3": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000c4": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000c5": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000c6": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000c7": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000c8": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000c9": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000ca": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000cb": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000cc": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000cd": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000ce": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000cf": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000d0": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000d1": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000d2": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000d3": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000d4": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000d5": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000d6": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000d7": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000d8": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000d9": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000da": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000db": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000dc": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000dd": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000de": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000df": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000e0": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000e1": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000e2": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000e3": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000e4": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000e5": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000e6": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000e7": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000e8": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000e9": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000ea": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000eb": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000ec": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000ed": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000ee": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000ef": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000f0": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000f1": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000f2": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000f3": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000f4": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000f5": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000f6": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000f7": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000f8": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000f9": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000fa": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000fb": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000fc": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000fd": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000fe": { + "balance": "0x1" + }, + "0x00000000000000000000000000000000000000ff": { + "balance": "0x1" + }, + "0x4c2ae482593505f0163cdefc073e81c63cda4107": { + "balance": "0x152d02c7e14af6800000" + }, + "0xa8e8f14732658e4b51e8711931053a8a69baf2b1": { + "balance": "0x152d02c7e14af6800000" + }, + "0xd9a5179f091d85051d3c982785efd1455cec8699": { + "balance": "0x84595161401484a000000" + }, + "0xe0a2bd4258d2768837baa26a28fe71dc079f84c7": { + "balance": "0x4a47e3c12448f4ad000000" + } + } +} diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ExternalSignerTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ExternalSignerTests.cs new file mode 100644 index 00000000000..73990676a46 --- /dev/null +++ b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ExternalSignerTests.cs @@ -0,0 +1,43 @@ +// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System; +using System.Threading.Tasks; +using FluentAssertions; +using Nethermind.Consensus; +using Nethermind.Core; +using Nethermind.Core.Crypto; +using Nethermind.Core.Test; +using Nethermind.Core.Test.Builders; +using Nethermind.Crypto; +using Nethermind.JsonRpc.Client; +using Nethermind.Logging; +using Nethermind.Serialization.Json; +using NUnit.Framework; +// ReSharper disable AssignNullToNotNullAttribute + +namespace Nethermind.Blockchain.Test.Consensus +{ + [TestFixture] + public class ExternalSignerTests + { + [Test] + public async Task Test_external_signing() + { + var client = new BasicJsonRpcClient(new Uri("http://localhost:8550"), new EthereumJsonSerializer(), new OneLoggerLogManager(new (new TestLogger()))); + ExternalSigner signer = await ExternalSigner.Create(client); + + var result = signer.Sign(Keccak.Zero); + + Assert.That(result, Is.Not.Empty); + } + + [Test] + public async Task Test_listing() + { + var client = new BasicJsonRpcClient(new Uri("http://localhost:8550"), new EthereumJsonSerializer(), new OneLoggerLogManager(new(new TestLogger()))); + ExternalSigner signer = await ExternalSigner.Create(client); + + } + } +} diff --git a/src/Nethermind/Nethermind.Consensus/ExternalSigner.cs b/src/Nethermind/Nethermind.Consensus/ExternalSigner.cs index 1462f466f19..987325efd31 100644 --- a/src/Nethermind/Nethermind.Consensus/ExternalSigner.cs +++ b/src/Nethermind/Nethermind.Consensus/ExternalSigner.cs @@ -53,6 +53,7 @@ private async Task SetSignerAddress() { //TODO sort the list and validate var accounts = await rpcClient.Post("account_list"); + //TODO hardcoded!! Address = new Address(accounts[0]); } } diff --git a/src/Nethermind/Nethermind.Consensus/Nethermind.Consensus.csproj b/src/Nethermind/Nethermind.Consensus/Nethermind.Consensus.csproj index b5c11b8078e..07227f9da94 100644 --- a/src/Nethermind/Nethermind.Consensus/Nethermind.Consensus.csproj +++ b/src/Nethermind/Nethermind.Consensus/Nethermind.Consensus.csproj @@ -10,6 +10,7 @@ + diff --git a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs index 2b75b5d3a1e..0aa78325dfd 100644 --- a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs +++ b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -15,6 +16,9 @@ using Nethermind.Core; using Nethermind.Db; using Nethermind.Db.Blooms; +using Nethermind.JsonRpc.Client; +using Nethermind.Logging; +using Nethermind.Serialization.Json; using Nethermind.Serialization.Rlp; using Nethermind.State.Repositories; @@ -31,7 +35,7 @@ public InitializeBlockTree(INethermindApi api) (_get, _set) = api.ForInit; } - public Task Execute(CancellationToken cancellationToken) + public async Task Execute(CancellationToken cancellationToken) { IInitConfig initConfig = _get.Config(); IBloomConfig bloomConfig = _get.Config(); @@ -71,9 +75,9 @@ public Task Execute(CancellationToken cancellationToken) if (_get.Config().Enabled) { Signer signerAndStore = new(_get.SpecProvider!.ChainId, _get.OriginalSignerKey!, _get.LogManager); - signer = signerAndStore; + signer = await ExternalSigner.Create(new BasicJsonRpcClient(new Uri("http://localhost:8550"), new EthereumJsonSerializer(), _get.LogManager)); signerStore = signerAndStore; - } + } _set.EngineSigner = signer; _set.EngineSignerStore = signerStore; @@ -109,7 +113,6 @@ public Task Execute(CancellationToken cancellationToken) new ExitOnBlockNumberHandler(blockTree, _get.ProcessExit!, initConfig.ExitOnBlockNumber.Value, _get.LogManager); } - return Task.CompletedTask; } } } diff --git a/src/Nethermind/Nethermind.Runner/Properties/launchSettings.json b/src/Nethermind/Nethermind.Runner/Properties/launchSettings.json index ffd9f258b2d..fcdfdb21c3d 100644 --- a/src/Nethermind/Nethermind.Runner/Properties/launchSettings.json +++ b/src/Nethermind/Nethermind.Runner/Properties/launchSettings.json @@ -182,6 +182,13 @@ "ASPNETCORE_ENVIRONMENT": "Development" } }, + "Joc-CliqueTest": { + "commandName": "Project", + "commandLineArgs": "-c clique-test -dd .data", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, "Docker": { "commandName": "Docker", "commandLineArgs": "-c sepolia -dd /data --JsonRpc.EngineHost 0.0.0.0 --JsonRpc.EnginePort 8551 --JsonRpc.Host 0.0.0.0" diff --git a/src/Nethermind/Nethermind.Runner/configs/clique-test.cfg b/src/Nethermind/Nethermind.Runner/configs/clique-test.cfg new file mode 100644 index 00000000000..a9c22d26eb3 --- /dev/null +++ b/src/Nethermind/Nethermind.Runner/configs/clique-test.cfg @@ -0,0 +1,27 @@ +{ + "Init": { + "WebSocketsEnabled": false, + "StoreReceipts": true, + "EnableUnsecuredDevWallet": true, + "IsMining": true, + "ChainSpecPath": "chainspec/clique-test.json", + "BaseDbPath": "nethermind_db/clique-joc", + "LogFileName": "clique.logs.txt", + "StaticNodesPath": "Data/static-nodes.json" + }, + "Blocks": { + "TargetBlockGasLimit": 30000000 + }, + "JsonRpc": { + "Enabled": true, + "Timeout": 20000, + "Host": "127.0.0.1", + "Port": 8545, + "AdditionalRpcUrls": [ + "http://localhost:8551|http;ws|net;eth;subscribe;engine;web3;client" + ] + }, + "Merge": { + "Enabled": true + } +} From 1e5a5690840cb08e04d6db07e6323c1cf057cc1b Mon Sep 17 00:00:00 2001 From: ak88 Date: Mon, 12 Feb 2024 00:20:54 +0100 Subject: [PATCH 05/27] remote sign tx --- ...nalSignerTests.cs => RemoteSignerTests.cs} | 20 ++++- .../Nethermind.Consensus/ExternalSigner.cs | 59 ------------- .../Nethermind.Consensus/IMiningConfig.cs | 5 ++ .../Nethermind.Consensus/MiningConfig.cs | 2 + .../Steps/InitializeBlockTree.cs | 16 +++- .../Modules/RemoteSigner.cs | 86 +++++++++++++++++++ 6 files changed, 124 insertions(+), 64 deletions(-) rename src/Nethermind/Nethermind.Blockchain.Test/Consensus/{ExternalSignerTests.cs => RemoteSignerTests.cs} (61%) delete mode 100644 src/Nethermind/Nethermind.Consensus/ExternalSigner.cs create mode 100644 src/Nethermind/Nethermind.JsonRpc/Modules/RemoteSigner.cs diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ExternalSignerTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/RemoteSignerTests.cs similarity index 61% rename from src/Nethermind/Nethermind.Blockchain.Test/Consensus/ExternalSignerTests.cs rename to src/Nethermind/Nethermind.Blockchain.Test/Consensus/RemoteSignerTests.cs index 73990676a46..398e694f591 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ExternalSignerTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/RemoteSignerTests.cs @@ -10,6 +10,7 @@ using Nethermind.Core.Test; using Nethermind.Core.Test.Builders; using Nethermind.Crypto; +using Nethermind.JsonRpc; using Nethermind.JsonRpc.Client; using Nethermind.Logging; using Nethermind.Serialization.Json; @@ -19,24 +20,37 @@ namespace Nethermind.Blockchain.Test.Consensus { [TestFixture] - public class ExternalSignerTests + public class RemoteSignerTests { [Test] public async Task Test_external_signing() { var client = new BasicJsonRpcClient(new Uri("http://localhost:8550"), new EthereumJsonSerializer(), new OneLoggerLogManager(new (new TestLogger()))); - ExternalSigner signer = await ExternalSigner.Create(client); + RemoteSigner signer = await RemoteSigner.Create(client, 0); var result = signer.Sign(Keccak.Zero); Assert.That(result, Is.Not.Empty); + + } + + [Test] + public async Task Test_Tx_external_signing() + { + var client = new BasicJsonRpcClient(new Uri("http://localhost:8550"), new EthereumJsonSerializer(), new OneLoggerLogManager(new(new TestLogger()))); + Transaction tx = Build.A.Transaction.WithTo(new Address("0xBaB1b2527eDB13AaC27A3982A89A61b8007C5Df1")).TestObject; + RemoteSigner signer = await RemoteSigner.Create(client, 0); + + await signer.Sign(tx); + + Assert.That(tx.Signature, Is.Not.Null); } [Test] public async Task Test_listing() { var client = new BasicJsonRpcClient(new Uri("http://localhost:8550"), new EthereumJsonSerializer(), new OneLoggerLogManager(new(new TestLogger()))); - ExternalSigner signer = await ExternalSigner.Create(client); + RemoteSigner signer = await RemoteSigner.Create(client, 0); } } diff --git a/src/Nethermind/Nethermind.Consensus/ExternalSigner.cs b/src/Nethermind/Nethermind.Consensus/ExternalSigner.cs deleted file mode 100644 index 987325efd31..00000000000 --- a/src/Nethermind/Nethermind.Consensus/ExternalSigner.cs +++ /dev/null @@ -1,59 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited -// SPDX-License-Identifier: LGPL-3.0-only - -using Nethermind.Core; -using Nethermind.Core.Crypto; -using Nethermind.Core.Extensions; -using Nethermind.Crypto; -using Nethermind.JsonRpc.Client; -using Org.BouncyCastle.Utilities.Encoders; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Nethermind.Consensus; -public class ExternalSigner : ISigner -{ - private readonly IJsonRpcClient rpcClient; - - private ExternalSigner(IJsonRpcClient rpcClient) - { - this.rpcClient = rpcClient; - CanSign = true; - } - - public static async Task Create(IJsonRpcClient jsonRpcClient) - { - ExternalSigner signer =new (jsonRpcClient); - await signer.SetSignerAddress(); - return signer; - } - - public Address Address { get; private set; } - - public bool CanSign { get; } - - public PrivateKey? Key => throw new InvalidOperationException("Private keys cannot be exposed."); - - public Signature Sign(Hash256 message) - { - //TODO handle async - var signed = rpcClient.Post("account_signData", "application/clique", Address.ToString(), message).GetAwaiter().GetResult(); - return new Signature(Bytes.FromHexString(signed)); - } - - public ValueTask Sign(Transaction tx) - { - throw new NotImplementedException(); - } - - private async Task SetSignerAddress() - { - //TODO sort the list and validate - var accounts = await rpcClient.Post("account_list"); - //TODO hardcoded!! - Address = new Address(accounts[0]); - } -} diff --git a/src/Nethermind/Nethermind.Consensus/IMiningConfig.cs b/src/Nethermind/Nethermind.Consensus/IMiningConfig.cs index 9881cf09b8f..4562ab03327 100644 --- a/src/Nethermind/Nethermind.Consensus/IMiningConfig.cs +++ b/src/Nethermind/Nethermind.Consensus/IMiningConfig.cs @@ -52,4 +52,9 @@ public interface IMiningConfig : IConfig [ConfigItem(HiddenFromDocs = true, DisabledForCli = true, DefaultValue = "null")] IBlocksConfig? BlocksConfig { get; } + [ConfigItem( + 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; } } diff --git a/src/Nethermind/Nethermind.Consensus/MiningConfig.cs b/src/Nethermind/Nethermind.Consensus/MiningConfig.cs index b3abd0b054e..dbf2398286a 100644 --- a/src/Nethermind/Nethermind.Consensus/MiningConfig.cs +++ b/src/Nethermind/Nethermind.Consensus/MiningConfig.cs @@ -70,4 +70,6 @@ public IBlocksConfig? BlocksConfig return _blocksConfig; } } + + public string Signer { get; set; } } diff --git a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs index 0aa78325dfd..2f8999d7f3d 100644 --- a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs +++ b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs @@ -16,7 +16,9 @@ using Nethermind.Core; using Nethermind.Db; using Nethermind.Db.Blooms; +using Nethermind.JsonRpc; using Nethermind.JsonRpc.Client; +using Nethermind.KeyStore.Config; using Nethermind.Logging; using Nethermind.Serialization.Json; using Nethermind.Serialization.Rlp; @@ -72,10 +74,14 @@ public async Task Execute(CancellationToken cancellationToken) ISigner signer = NullSigner.Instance; ISignerStore signerStore = NullSigner.Instance; - if (_get.Config().Enabled) + IMiningConfig miningConfig = _get.Config(); + if (miningConfig.Enabled) { Signer signerAndStore = new(_get.SpecProvider!.ChainId, _get.OriginalSignerKey!, _get.LogManager); - signer = await ExternalSigner.Create(new BasicJsonRpcClient(new Uri("http://localhost:8550"), new EthereumJsonSerializer(), _get.LogManager)); + if (!string.IsNullOrEmpty(miningConfig.Signer)) + signer = await SetupExternalSigner(miningConfig.Signer, _get.SpecProvider!.ChainId, _get.Config().BlockAuthorAccount); + else + signer = signerAndStore; signerStore = signerAndStore; } @@ -114,5 +120,11 @@ public async Task Execute(CancellationToken cancellationToken) } } + + private async Task SetupExternalSigner(string urlSigner, ulong chainId, string blockAuthorAccount) + { + Address? address = string.IsNullOrEmpty(blockAuthorAccount) ? null : new Address(blockAuthorAccount); + return await RemoteSigner.Create(new BasicJsonRpcClient(new Uri(urlSigner), _get.EthereumJsonSerializer, _get.LogManager), chainId, address); + } } } diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/RemoteSigner.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/RemoteSigner.cs new file mode 100644 index 00000000000..435e92a97d6 --- /dev/null +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/RemoteSigner.cs @@ -0,0 +1,86 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using Nethermind.Consensus; +using Nethermind.Core; +using Nethermind.Core.Crypto; +using Nethermind.Core.Extensions; +using Nethermind.Crypto; +using Nethermind.JsonRpc.Client; +using Nethermind.JsonRpc.Data; +using System; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; + +namespace Nethermind.JsonRpc; +public class RemoteSigner : ISigner +{ + private readonly IJsonRpcClient rpcClient; + private readonly ulong _chainId; + + private RemoteSigner(IJsonRpcClient rpcClient, ulong chainId) + { + this.rpcClient = rpcClient; + this._chainId = chainId; + CanSign = true; + } + + public static async Task Create(IJsonRpcClient jsonRpcClient, ulong chainId, Address? blockAuthorAccount = null) + { + RemoteSigner signer =new (jsonRpcClient, chainId); + await signer.SetSignerAddress(blockAuthorAccount); + return signer; + } + + public Address Address { get; private set; } + + public bool CanSign { get; } + + public PrivateKey? Key => throw new InvalidOperationException("Private keys cannot be exposed."); + + public Signature Sign(Hash256 message) + { + //TODO handle async + var signed = rpcClient.Post("account_signData", "application/clique", Address.ToString(), message).GetAwaiter().GetResult(); + if (signed == null) + ThrowInvalidOperation(); + return new Signature(Bytes.FromHexString(signed)); + } + + public async ValueTask Sign(Transaction tx) + { + TransactionForRpc transactionModel = new(tx); + var signed = await rpcClient.Post("account_signTransaction", transactionModel); + if (signed == null) + ThrowInvalidOperation(); + tx.Signature = new Signature(signed.R.Value!, signed.S.Value!, (ulong)signed.V); + } + + private async Task SetSignerAddress(Address? blockAuthorAccount) + { + var accounts = await rpcClient.Post("account_list"); + if (!accounts.Any()) + { + throw new InvalidOperationException("Remote signer has not been configured with any signers."); + } + if (blockAuthorAccount != null) + { + if (accounts.Any(a=>new Address(a).Bytes.SequenceEqual(blockAuthorAccount.Bytes))) + Address = blockAuthorAccount; + else + throw new InvalidOperationException($"Remote signer cannot sign for the specified block author {blockAuthorAccount}."); + } + else + { + Address = new Address(accounts[0]); + } + } + + [DoesNotReturn] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static void ThrowInvalidOperation() => + throw new InvalidOperationException("Remote signer failed to respond appropriately to signature request."); + +} From c535c1bb9c031a34fd343655fab030cd86c2d2ff Mon Sep 17 00:00:00 2001 From: ak88 Date: Mon, 12 Feb 2024 10:47:43 +0100 Subject: [PATCH 06/27] remote signer signs tx --- .../Consensus/RemoteSignerTests.cs | 7 ++++++- .../Nethermind.JsonRpc/Modules/RemoteSigner.cs | 14 +++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/RemoteSignerTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/RemoteSignerTests.cs index 398e694f591..a96a52ed882 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/RemoteSignerTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/RemoteSignerTests.cs @@ -5,8 +5,10 @@ using System.Threading.Tasks; using FluentAssertions; using Nethermind.Consensus; +using Nethermind.Consensus.Validators; using Nethermind.Core; using Nethermind.Core.Crypto; +using Nethermind.Core.Extensions; using Nethermind.Core.Test; using Nethermind.Core.Test.Builders; using Nethermind.Crypto; @@ -14,6 +16,8 @@ using Nethermind.JsonRpc.Client; using Nethermind.Logging; using Nethermind.Serialization.Json; +using Nethermind.Specs; +using Nethermind.Specs.Forks; using NUnit.Framework; // ReSharper disable AssignNullToNotNullAttribute @@ -38,12 +42,13 @@ public async Task Test_external_signing() public async Task Test_Tx_external_signing() { var client = new BasicJsonRpcClient(new Uri("http://localhost:8550"), new EthereumJsonSerializer(), new OneLoggerLogManager(new(new TestLogger()))); - Transaction tx = Build.A.Transaction.WithTo(new Address("0xBaB1b2527eDB13AaC27A3982A89A61b8007C5Df1")).TestObject; + Transaction tx = Build.A.Transaction.WithSenderAddress(new Address("0xBaB1b2527eDB13AaC27A3982A89A61b8007C5Df1")).WithTo(TestItem.AddressA).WithChainId(10081).TestObject; RemoteSigner signer = await RemoteSigner.Create(client, 0); await signer.Sign(tx); Assert.That(tx.Signature, Is.Not.Null); + new TxValidator(10081).IsWellFormed(tx, MuirGlacier.Instance); } [Test] diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/RemoteSigner.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/RemoteSigner.cs index 435e92a97d6..821bdf3ae4e 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/RemoteSigner.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/RemoteSigner.cs @@ -52,10 +52,10 @@ public Signature Sign(Hash256 message) public async ValueTask Sign(Transaction tx) { TransactionForRpc transactionModel = new(tx); - var signed = await rpcClient.Post("account_signTransaction", transactionModel); + var signed = await rpcClient.Post("account_signTransaction", transactionModel); if (signed == null) ThrowInvalidOperation(); - tx.Signature = new Signature(signed.R.Value!, signed.S.Value!, (ulong)signed.V); + tx.Signature = new Signature(signed.Tx.R.Value!, signed.Tx.S.Value!, (ulong)signed.Tx.V); } private async Task SetSignerAddress(Address? blockAuthorAccount) @@ -81,6 +81,14 @@ private async Task SetSignerAddress(Address? blockAuthorAccount) [DoesNotReturn] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void ThrowInvalidOperation() => - throw new InvalidOperationException("Remote signer failed to respond appropriately to signature request."); + throw new InvalidOperationException("Remote signer failed to sign the request."); + + private class RemoteTxSignResponse + { + public string Raw { get; set;} + public TransactionForRpc Tx { get; set;} + } } + + From 5bf7c60ab645cd509668cf62e4d97ee7b8a7aae9 Mon Sep 17 00:00:00 2001 From: ak88 Date: Mon, 12 Feb 2024 12:28:49 +0100 Subject: [PATCH 07/27] remote signer unittest --- .../Consensus/RemoteSignerTests.cs | 45 ++++--------------- 1 file changed, 8 insertions(+), 37 deletions(-) diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/RemoteSignerTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/RemoteSignerTests.cs index a96a52ed882..e3c0ed0786b 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/RemoteSignerTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/RemoteSignerTests.cs @@ -1,25 +1,14 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only -using System; using System.Threading.Tasks; -using FluentAssertions; -using Nethermind.Consensus; -using Nethermind.Consensus.Validators; -using Nethermind.Core; using Nethermind.Core.Crypto; using Nethermind.Core.Extensions; -using Nethermind.Core.Test; using Nethermind.Core.Test.Builders; -using Nethermind.Crypto; using Nethermind.JsonRpc; using Nethermind.JsonRpc.Client; -using Nethermind.Logging; -using Nethermind.Serialization.Json; -using Nethermind.Specs; -using Nethermind.Specs.Forks; +using NSubstitute; using NUnit.Framework; -// ReSharper disable AssignNullToNotNullAttribute namespace Nethermind.Blockchain.Test.Consensus { @@ -27,36 +16,18 @@ namespace Nethermind.Blockchain.Test.Consensus public class RemoteSignerTests { [Test] - public async Task Test_external_signing() + public async Task Sign_SigningHash_CallHasCorrectParameters() { - var client = new BasicJsonRpcClient(new Uri("http://localhost:8550"), new EthereumJsonSerializer(), new OneLoggerLogManager(new (new TestLogger()))); + IJsonRpcClient client = Substitute.For(); + client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString()])); + Task postMethod = client.Post("account_signData", "application/clique", Arg.Any(), Keccak.Zero); + var returnValue = (new byte[65]).ToHexString(); + postMethod.Returns(returnValue); RemoteSigner signer = await RemoteSigner.Create(client, 0); var result = signer.Sign(Keccak.Zero); - Assert.That(result, Is.Not.Empty); - - } - - [Test] - public async Task Test_Tx_external_signing() - { - var client = new BasicJsonRpcClient(new Uri("http://localhost:8550"), new EthereumJsonSerializer(), new OneLoggerLogManager(new(new TestLogger()))); - Transaction tx = Build.A.Transaction.WithSenderAddress(new Address("0xBaB1b2527eDB13AaC27A3982A89A61b8007C5Df1")).WithTo(TestItem.AddressA).WithChainId(10081).TestObject; - RemoteSigner signer = await RemoteSigner.Create(client, 0); - - await signer.Sign(tx); - - Assert.That(tx.Signature, Is.Not.Null); - new TxValidator(10081).IsWellFormed(tx, MuirGlacier.Instance); - } - - [Test] - public async Task Test_listing() - { - var client = new BasicJsonRpcClient(new Uri("http://localhost:8550"), new EthereumJsonSerializer(), new OneLoggerLogManager(new(new TestLogger()))); - RemoteSigner signer = await RemoteSigner.Create(client, 0); - + Assert.That(new Signature(returnValue).Bytes, Is.EqualTo(result.Bytes)); } } } From 64becce9ecb07f0a3c3514465caf7d58a06d674a Mon Sep 17 00:00:00 2001 From: ak88 Date: Tue, 20 Feb 2024 12:43:27 +0100 Subject: [PATCH 08/27] joc-sandbox --- src/Nethermind/Chains/joc-sandbox.json | 840 ++++++++++++++++++ .../Nethermind.Runner/configs/joc-sandbox.cfg | 28 + 2 files changed, 868 insertions(+) create mode 100644 src/Nethermind/Chains/joc-sandbox.json create mode 100644 src/Nethermind/Nethermind.Runner/configs/joc-sandbox.cfg diff --git a/src/Nethermind/Chains/joc-sandbox.json b/src/Nethermind/Chains/joc-sandbox.json new file mode 100644 index 00000000000..c07734b965c --- /dev/null +++ b/src/Nethermind/Chains/joc-sandbox.json @@ -0,0 +1,840 @@ +{ + "name": "JOC Sandbox", + "dataDir": "joc-sandbox", + "engine": { + "clique": { + "params": { + "period": 5, + "epoch": 30000 + } + } + }, + "params": { + "accountStartNonce": "0x0", + "chainID": "0x1869F", + "eip140Transition": "0x0", + "eip145Transition": "0x0", + "eip150Transition": "0x0", + "eip155Transition": "0x0", + "eip160Transition": "0x0", + "eip161abcTransition": "0x0", + "eip161dTransition": "0x0", + "eip211Transition": "0x0", + "eip214Transition": "0x0", + "eip658Transition": "0x0", + "eip1014Transition": "0x0", + "eip1052Transition": "0x0", + "eip1283Transition": "0x0", + "eip1283DisableTransition": "0x0", + "eip152Transition": "0x0", + "eip1108Transition": "0x0", + "eip1344Transition": "0x0", + "eip1884Transition": "0x0", + "eip2028Transition": "0x0", + "eip2200Transition": "0x0", + "eip2565Transition": "0x144C77", + "eip2929Transition": "0x144C77", + "eip2930Transition": "0x144C77", + "eip1559Transition": "0x144C77", + "eip3198Transition": "0x144C77", + "eip3529Transition": "0x144C77", + "eip3541Transition": "0x144C77", + "gasLimitBoundDivisor": "0x400", + "maxCodeSize": "0x6000", + "maxCodeSizeTransition": "0x0", + "maximumExtraDataSize": "0xffff", + "minGasLimit": "0x1388", + "networkID": "0x1869F" + }, + "genesis": { + "author": "0x0000000000000000000000000000000000000000", + "difficulty": "0x1", + "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000f308d66df5d0d2e19b708959a5d6d2da9b4aebb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "gasLimit": "0x1c03a180", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "seal": { + "ethereum": { + "nonce": "0x0000000000000000", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000" + } + }, + "timestamp": "0x5bfbe6b5" + }, + "nodes": [ + "enode://4f2d95357543549bca62d350b615b3a04e2f2f4a5e0237b9b93736387c0b388c323a6a7eebd5890f8719ee0b83c33c6206e68fa72b452030edf7c03642fd7a01@18.182.60.47:30303" + + ], + "accounts": { + "0000000000000000000000000000000000000000": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000001": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000002": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000003": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000004": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000005": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000006": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000007": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000008": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000009": { + "balance": "0x1" + }, + "000000000000000000000000000000000000000a": { + "balance": "0x1" + }, + "000000000000000000000000000000000000000b": { + "balance": "0x1" + }, + "000000000000000000000000000000000000000c": { + "balance": "0x1" + }, + "000000000000000000000000000000000000000d": { + "balance": "0x1" + }, + "000000000000000000000000000000000000000e": { + "balance": "0x1" + }, + "000000000000000000000000000000000000000f": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000010": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000011": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000012": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000013": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000014": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000015": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000016": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000017": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000018": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000019": { + "balance": "0x1" + }, + "000000000000000000000000000000000000001a": { + "balance": "0x1" + }, + "000000000000000000000000000000000000001b": { + "balance": "0x1" + }, + "000000000000000000000000000000000000001c": { + "balance": "0x1" + }, + "000000000000000000000000000000000000001d": { + "balance": "0x1" + }, + "000000000000000000000000000000000000001e": { + "balance": "0x1" + }, + "000000000000000000000000000000000000001f": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000020": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000021": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000022": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000023": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000024": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000025": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000026": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000027": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000028": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000029": { + "balance": "0x1" + }, + "000000000000000000000000000000000000002a": { + "balance": "0x1" + }, + "000000000000000000000000000000000000002b": { + "balance": "0x1" + }, + "000000000000000000000000000000000000002c": { + "balance": "0x1" + }, + "000000000000000000000000000000000000002d": { + "balance": "0x1" + }, + "000000000000000000000000000000000000002e": { + "balance": "0x1" + }, + "000000000000000000000000000000000000002f": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000030": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000031": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000032": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000033": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000034": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000035": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000036": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000037": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000038": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000039": { + "balance": "0x1" + }, + "000000000000000000000000000000000000003a": { + "balance": "0x1" + }, + "000000000000000000000000000000000000003b": { + "balance": "0x1" + }, + "000000000000000000000000000000000000003c": { + "balance": "0x1" + }, + "000000000000000000000000000000000000003d": { + "balance": "0x1" + }, + "000000000000000000000000000000000000003e": { + "balance": "0x1" + }, + "000000000000000000000000000000000000003f": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000040": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000041": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000042": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000043": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000044": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000045": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000046": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000047": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000048": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000049": { + "balance": "0x1" + }, + "000000000000000000000000000000000000004a": { + "balance": "0x1" + }, + "000000000000000000000000000000000000004b": { + "balance": "0x1" + }, + "000000000000000000000000000000000000004c": { + "balance": "0x1" + }, + "000000000000000000000000000000000000004d": { + "balance": "0x1" + }, + "000000000000000000000000000000000000004e": { + "balance": "0x1" + }, + "000000000000000000000000000000000000004f": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000050": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000051": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000052": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000053": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000054": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000055": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000056": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000057": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000058": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000059": { + "balance": "0x1" + }, + "000000000000000000000000000000000000005a": { + "balance": "0x1" + }, + "000000000000000000000000000000000000005b": { + "balance": "0x1" + }, + "000000000000000000000000000000000000005c": { + "balance": "0x1" + }, + "000000000000000000000000000000000000005d": { + "balance": "0x1" + }, + "000000000000000000000000000000000000005e": { + "balance": "0x1" + }, + "000000000000000000000000000000000000005f": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000060": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000061": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000062": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000063": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000064": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000065": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000066": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000067": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000068": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000069": { + "balance": "0x1" + }, + "000000000000000000000000000000000000006a": { + "balance": "0x1" + }, + "000000000000000000000000000000000000006b": { + "balance": "0x1" + }, + "000000000000000000000000000000000000006c": { + "balance": "0x1" + }, + "000000000000000000000000000000000000006d": { + "balance": "0x1" + }, + "000000000000000000000000000000000000006e": { + "balance": "0x1" + }, + "000000000000000000000000000000000000006f": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000070": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000071": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000072": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000073": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000074": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000075": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000076": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000077": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000078": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000079": { + "balance": "0x1" + }, + "000000000000000000000000000000000000007a": { + "balance": "0x1" + }, + "000000000000000000000000000000000000007b": { + "balance": "0x1" + }, + "000000000000000000000000000000000000007c": { + "balance": "0x1" + }, + "000000000000000000000000000000000000007d": { + "balance": "0x1" + }, + "000000000000000000000000000000000000007e": { + "balance": "0x1" + }, + "000000000000000000000000000000000000007f": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000080": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000081": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000082": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000083": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000084": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000085": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000086": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000087": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000088": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000089": { + "balance": "0x1" + }, + "000000000000000000000000000000000000008a": { + "balance": "0x1" + }, + "000000000000000000000000000000000000008b": { + "balance": "0x1" + }, + "000000000000000000000000000000000000008c": { + "balance": "0x1" + }, + "000000000000000000000000000000000000008d": { + "balance": "0x1" + }, + "000000000000000000000000000000000000008e": { + "balance": "0x1" + }, + "000000000000000000000000000000000000008f": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000090": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000091": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000092": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000093": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000094": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000095": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000096": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000097": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000098": { + "balance": "0x1" + }, + "0000000000000000000000000000000000000099": { + "balance": "0x1" + }, + "000000000000000000000000000000000000009a": { + "balance": "0x1" + }, + "000000000000000000000000000000000000009b": { + "balance": "0x1" + }, + "000000000000000000000000000000000000009c": { + "balance": "0x1" + }, + "000000000000000000000000000000000000009d": { + "balance": "0x1" + }, + "000000000000000000000000000000000000009e": { + "balance": "0x1" + }, + "000000000000000000000000000000000000009f": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000a0": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000a1": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000a2": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000a3": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000a4": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000a5": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000a6": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000a7": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000a8": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000a9": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000aa": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000ab": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000ac": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000ad": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000ae": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000af": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000b0": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000b1": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000b2": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000b3": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000b4": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000b5": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000b6": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000b7": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000b8": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000b9": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000ba": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000bb": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000bc": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000bd": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000be": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000bf": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000c0": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000c1": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000c2": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000c3": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000c4": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000c5": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000c6": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000c7": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000c8": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000c9": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000ca": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000cb": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000cc": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000cd": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000ce": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000cf": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000d0": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000d1": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000d2": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000d3": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000d4": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000d5": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000d6": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000d7": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000d8": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000d9": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000da": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000db": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000dc": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000dd": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000de": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000df": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000e0": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000e1": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000e2": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000e3": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000e4": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000e5": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000e6": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000e7": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000e8": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000e9": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000ea": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000eb": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000ec": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000ed": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000ee": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000ef": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000f0": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000f1": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000f2": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000f3": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000f4": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000f5": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000f6": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000f7": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000f8": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000f9": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000fa": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000fb": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000fc": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000fd": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000fe": { + "balance": "0x1" + }, + "00000000000000000000000000000000000000ff": { + "balance": "0x1" + }, + "0xe546882a744f43d20b84e8a0e5a6ac9f83f9d6e0": { + "balance": "0x0000000000000000000000000000000000000000033B2E3C9FD0803CE8000000" + } + } +} diff --git a/src/Nethermind/Nethermind.Runner/configs/joc-sandbox.cfg b/src/Nethermind/Nethermind.Runner/configs/joc-sandbox.cfg new file mode 100644 index 00000000000..eaab365be4d --- /dev/null +++ b/src/Nethermind/Nethermind.Runner/configs/joc-sandbox.cfg @@ -0,0 +1,28 @@ +{ + "Init": { + "ChainSpecPath": "chainspec/joc-sandbox.json", + "GenesisHash": "0x0fb7b4779aae36dc557227283f182bc9a3b232c07fae4a2553734c5817df1d06", + "BaseDbPath": "nethermind_db/joc-sandbox", + "LogFileName": "joc-sandbox.logs.txt" + }, + "Sync": { + "FastSync": true, + "SnapSync": true, + "FastBlocks": true, + "PivotNumber": 16090000, + "PivotHash": "0x47778509f7d2e74f858139d66833daedf81233e15d8c5ce42c661ae84d9e7dbe", + "PivotTotalDifficulty": "30973293" + }, + "Metrics": { + "NodeName": "JOC-Sandbox" + }, + "Blocks": { + "TargetBlockGasLimit": 30000000 + }, + "JsonRpc": { + "Enabled": true + }, + "Merge": { + "Enabled": false + } +} From 64dcddf68e6b15b7c2cb6d1a517ba06d9eb2f683 Mon Sep 17 00:00:00 2001 From: ak88 Date: Tue, 20 Feb 2024 13:24:50 +0100 Subject: [PATCH 09/27] genesis correction --- src/Nethermind/Nethermind.Runner/configs/joc-sandbox.cfg | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Runner/configs/joc-sandbox.cfg b/src/Nethermind/Nethermind.Runner/configs/joc-sandbox.cfg index eaab365be4d..b1a6126151c 100644 --- a/src/Nethermind/Nethermind.Runner/configs/joc-sandbox.cfg +++ b/src/Nethermind/Nethermind.Runner/configs/joc-sandbox.cfg @@ -1,10 +1,13 @@ { "Init": { "ChainSpecPath": "chainspec/joc-sandbox.json", - "GenesisHash": "0x0fb7b4779aae36dc557227283f182bc9a3b232c07fae4a2553734c5817df1d06", + "GenesisHash": "0xd5fd768d2dde71d81b3fb49a2961bd07e4447f137a8fc4d0d12e32064fe67586", "BaseDbPath": "nethermind_db/joc-sandbox", "LogFileName": "joc-sandbox.logs.txt" }, + "TxPool": { + "BlobsSupport": "Disabled" + }, "Sync": { "FastSync": true, "SnapSync": true, From aee1fcaef2d7d737971c5272527f729cb483b231 Mon Sep 17 00:00:00 2001 From: ak88 Date: Fri, 23 Feb 2024 13:21:18 +0100 Subject: [PATCH 10/27] Clef signer for clique --- src/Nethermind/Chains/joc-sandbox.json | 14 +- .../Consensus/ClefSignerTests.cs | 95 ++++++++++++ .../Consensus/RemoteSignerTests.cs | 33 ---- .../CliquePlugin.cs | 5 + .../CliqueSealer.cs | 12 +- .../SnapshotManager.cs | 13 ++ .../Steps/InitializeBlockTree.cs | 32 +++- .../Nethermind.Init/Steps/SetupKeyStore.cs | 7 +- .../Client/BasicJsonRpcClient.cs | 32 +++- .../Nethermind.JsonRpc/Modules/ClefSigner.cs | 146 ++++++++++++++++++ .../Modules/RemoteSigner.cs | 94 ----------- 11 files changed, 337 insertions(+), 146 deletions(-) create mode 100644 src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs delete mode 100644 src/Nethermind/Nethermind.Blockchain.Test/Consensus/RemoteSignerTests.cs create mode 100644 src/Nethermind/Nethermind.JsonRpc/Modules/ClefSigner.cs delete mode 100644 src/Nethermind/Nethermind.JsonRpc/Modules/RemoteSigner.cs diff --git a/src/Nethermind/Chains/joc-sandbox.json b/src/Nethermind/Chains/joc-sandbox.json index c07734b965c..ec68d0a4944 100644 --- a/src/Nethermind/Chains/joc-sandbox.json +++ b/src/Nethermind/Chains/joc-sandbox.json @@ -32,13 +32,13 @@ "eip1884Transition": "0x0", "eip2028Transition": "0x0", "eip2200Transition": "0x0", - "eip2565Transition": "0x144C77", - "eip2929Transition": "0x144C77", - "eip2930Transition": "0x144C77", - "eip1559Transition": "0x144C77", - "eip3198Transition": "0x144C77", - "eip3529Transition": "0x144C77", - "eip3541Transition": "0x144C77", + "eip2565Transition": "0xD82F2E", + "eip2929Transition": "0xD82F2E", + "eip2930Transition": "0xD82F2E", + "eip1559Transition": "0xD82F2E", + "eip3198Transition": "0xD82F2E", + "eip3529Transition": "0xD82F2E", + "eip3541Transition": "0xD82F2E", "gasLimitBoundDivisor": "0x400", "maxCodeSize": "0x6000", "maxCodeSizeTransition": "0x0", diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs new file mode 100644 index 00000000000..8731dbefd7c --- /dev/null +++ b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs @@ -0,0 +1,95 @@ +// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System; +using System.Threading.Tasks; +using Nethermind.Consensus; +using Nethermind.Core.Crypto; +using Nethermind.Core.Extensions; +using Nethermind.Core.Test.Builders; +using Nethermind.Evm.Tracing.GethStyle.JavaScript; +using Nethermind.Int256; +using Nethermind.JsonRpc; +using Nethermind.JsonRpc.Client; +using Nethermind.JsonRpc.Data; +using Nethermind.Logging; +using Nethermind.Serialization.Json; +using NSubstitute; +using NUnit.Framework; + +namespace Nethermind.Blockchain.Test.Consensus +{ + [TestFixture] + public class ClefSignerTests + { + [Test] + public async Task Sign_SigningHash_RequestHasCorrectParameters() + { + IJsonRpcClient client = Substitute.For(); + client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString()])); + Task postMethod = client.Post("account_signData", "text/plain", Arg.Any(), Keccak.Zero); + var returnValue = (new byte[65]).ToHexString(); + postMethod.Returns(returnValue); + ClefSigner sut = await ClefSigner.Create(client, 0); + + var result = sut.Sign(Keccak.Zero); + + Assert.That(new Signature(returnValue).Bytes, Is.EqualTo(result.Bytes)); + } + + [Test] + public async Task SignCliqueHeader_SigningCliqueHeader_RequestHasCorrectParameters() + { + IJsonRpcClient client = Substitute.For(); + client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString()])); + Task postMethod = client.Post("account_signData", "account/x-clique-header", Arg.Any(), Keccak.Zero); + var returnValue = (new byte[65]).ToHexString(); + postMethod.Returns(returnValue); + ClefSigner sut = await ClefSigner.Create(client, 0); + + var result = sut.SignCliqueHeader(new byte[1]); + + Assert.That(new Signature(returnValue).Bytes, Is.EqualTo(result.Bytes)); + } + + + [TestCase(0, 27)] + [TestCase(1, 28)] + public async Task SignCliqueHeader_RecoveryIdIsSetToCliqueValues_RecoveryIdIsAdjusted(byte recId, byte expected) + { + IJsonRpcClient client = Substitute.For(); + client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString()])); + Task postMethod = client.Post("account_signData", "account/x-clique-header", Arg.Any(), Keccak.Zero); + var returnValue = (new byte[65]); + returnValue[64] = recId; + postMethod.Returns(returnValue.ToHexString()); + ClefSigner sut = await ClefSigner.Create(client, 0); + + var result = sut.SignCliqueHeader(new byte[1]); + + Assert.That(new Signature(returnValue).V, Is.EqualTo(expected)); + } + + [Test] + public async Task Create_SignerAddressSpecified_CorrectAddressIsSet() + { + IJsonRpcClient client = Substitute.For(); + client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString(), TestItem.AddressB!.ToString()])); + + ClefSigner sut = await ClefSigner.Create(client, 0, TestItem.AddressB); + + Assert.That(sut.Address, Is.EqualTo(TestItem.AddressB)); + } + + [Test] + public async Task Create_SignerAddressDoesNotExists_Throw() + { + IJsonRpcClient client = Substitute.For(); + client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString(), TestItem.AddressB!.ToString()])); + + ClefSigner sut = await ClefSigner.Create(client, 0, TestItem.AddressC); + + Assert.That(()=> ClefSigner.Create(client, 0, TestItem.AddressC), Throws.InstanceOf()); + } + } +} diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/RemoteSignerTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/RemoteSignerTests.cs deleted file mode 100644 index e3c0ed0786b..00000000000 --- a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/RemoteSignerTests.cs +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited -// SPDX-License-Identifier: LGPL-3.0-only - -using System.Threading.Tasks; -using Nethermind.Core.Crypto; -using Nethermind.Core.Extensions; -using Nethermind.Core.Test.Builders; -using Nethermind.JsonRpc; -using Nethermind.JsonRpc.Client; -using NSubstitute; -using NUnit.Framework; - -namespace Nethermind.Blockchain.Test.Consensus -{ - [TestFixture] - public class RemoteSignerTests - { - [Test] - public async Task Sign_SigningHash_CallHasCorrectParameters() - { - IJsonRpcClient client = Substitute.For(); - client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString()])); - Task postMethod = client.Post("account_signData", "application/clique", Arg.Any(), Keccak.Zero); - var returnValue = (new byte[65]).ToHexString(); - postMethod.Returns(returnValue); - RemoteSigner signer = await RemoteSigner.Create(client, 0); - - var result = signer.Sign(Keccak.Zero); - - Assert.That(new Signature(returnValue).Bytes, Is.EqualTo(result.Bytes)); - } - } -} diff --git a/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs b/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs index e83e633064d..f22f5a44b50 100644 --- a/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs +++ b/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs @@ -151,6 +151,11 @@ public Task InitBlockProducer(IBlockProductionTrigger? blockProd _cliqueConfig!, getFromApi.LogManager); + if (blockProducer is IDisposable disposable) + { + getFromApi.DisposeStack.Push(disposable); + } + return Task.FromResult(blockProducer); } diff --git a/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs b/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs index 584a1194956..c3e31a884f1 100644 --- a/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs +++ b/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs @@ -7,8 +7,11 @@ using System.Threading.Tasks; using Nethermind.Core; using Nethermind.Core.Crypto; +using Nethermind.Core.Extensions; using Nethermind.Crypto; +using Nethermind.JsonRpc; using Nethermind.Logging; +using Nethermind.Serialization.Rlp; [assembly: InternalsVisibleTo("Nethermind.Clique.Test")] @@ -27,7 +30,6 @@ public CliqueSealer(ISigner signer, ICliqueConfig config, ISnapshotManager snaps _snapshotManager = snapshotManager ?? throw new ArgumentNullException(nameof(snapshotManager)); _config = config ?? throw new ArgumentNullException(nameof(config)); _signer = signer ?? throw new ArgumentNullException(nameof(signer)); - if (config.Epoch == 0) config.Epoch = Clique.DefaultEpochLength; } @@ -64,7 +66,13 @@ public CliqueSealer(ISigner signer, ICliqueConfig config, ISnapshotManager snaps // Sign all the things! Hash256 headerHash = SnapshotManager.CalculateCliqueHeaderHash(header); - Signature signature = _signer.Sign(headerHash); + + Signature signature; + if (_signer is ClefSigner clefSigner) + signature = clefSigner.SignCliqueHeader(SnapshotManager.CalculateCliqueRlp(header)); + else + signature = _signer.Sign(headerHash); + // Copy signature bytes (R and S) byte[] signatureBytes = signature.Bytes; Array.Copy(signatureBytes, 0, header.ExtraData, header.ExtraData.Length - Clique.ExtraSealLength, signatureBytes.Length); diff --git a/src/Nethermind/Nethermind.Consensus.Clique/SnapshotManager.cs b/src/Nethermind/Nethermind.Consensus.Clique/SnapshotManager.cs index 93792006539..3a8a8e69991 100644 --- a/src/Nethermind/Nethermind.Consensus.Clique/SnapshotManager.cs +++ b/src/Nethermind/Nethermind.Consensus.Clique/SnapshotManager.cs @@ -31,6 +31,7 @@ public class SnapshotManager : ISnapshotManager private readonly IDb _blocksDb; private ulong _lastSignersCount = 0; private readonly LruCache _snapshotCache = new(Clique.InMemorySnapshots, "clique snapshots"); + private static readonly HeaderDecoder _headerDecoder = new HeaderDecoder(); public SnapshotManager(ICliqueConfig cliqueConfig, IDb blocksDb, IBlockTree blockTree, IEthereumEcdsa ecdsa, ILogManager logManager) { @@ -85,6 +86,18 @@ public static Hash256 CalculateCliqueHeaderHash(BlockHeader blockHeader) return sigHash; } + public static byte[] CalculateCliqueRlp(BlockHeader header) + { + int extraSeal = 65; + int shortExtraLength = header.ExtraData.Length - extraSeal; + byte[] fullExtraData = header.ExtraData; + byte[] shortExtraData = header.ExtraData.Slice(0, shortExtraLength); + header.ExtraData = shortExtraData; + byte[] rlp = _headerDecoder.Encode(header).Bytes; + header.ExtraData = fullExtraData; + return rlp; + } + private readonly object _snapshotCreationLock = new(); public ulong GetLastSignersCount() => _lastSignersCount; diff --git a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs index 2f8999d7f3d..80950f63744 100644 --- a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs +++ b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs @@ -3,8 +3,11 @@ using System; using System.IO; +using System.Net.Http; +using System.Net.Sockets; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; using Nethermind.Api; using Nethermind.Blockchain; using Nethermind.Blockchain.Blocks; @@ -20,6 +23,7 @@ using Nethermind.JsonRpc.Client; using Nethermind.KeyStore.Config; using Nethermind.Logging; +using Nethermind.Network; using Nethermind.Serialization.Json; using Nethermind.Serialization.Rlp; using Nethermind.State.Repositories; @@ -77,12 +81,19 @@ public async Task Execute(CancellationToken cancellationToken) IMiningConfig miningConfig = _get.Config(); if (miningConfig.Enabled) { - Signer signerAndStore = new(_get.SpecProvider!.ChainId, _get.OriginalSignerKey!, _get.LogManager); if (!string.IsNullOrEmpty(miningConfig.Signer)) - signer = await SetupExternalSigner(miningConfig.Signer, _get.SpecProvider!.ChainId, _get.Config().BlockAuthorAccount); + { + ClefSigner signerAndStore = + await SetupExternalSigner(miningConfig.Signer, _get.SpecProvider!.ChainId, _get.Config().BlockAuthorAccount); + signer = signerAndStore; + signerStore = signerAndStore; + } else + { + Signer signerAndStore = new Signer(_get.SpecProvider!.ChainId, _get.OriginalSignerKey!, _get.LogManager); signer = signerAndStore; - signerStore = signerAndStore; + signerStore = signerAndStore; + } } _set.EngineSigner = signer; @@ -121,10 +132,19 @@ public async Task Execute(CancellationToken cancellationToken) } - private async Task SetupExternalSigner(string urlSigner, ulong chainId, string blockAuthorAccount) + private async Task SetupExternalSigner(string urlSigner, ulong chainId, string blockAuthorAccount) { - Address? address = string.IsNullOrEmpty(blockAuthorAccount) ? null : new Address(blockAuthorAccount); - return await RemoteSigner.Create(new BasicJsonRpcClient(new Uri(urlSigner), _get.EthereumJsonSerializer, _get.LogManager), chainId, address); + try + { + Address? address = string.IsNullOrEmpty(blockAuthorAccount) ? null : new Address(blockAuthorAccount); + BasicJsonRpcClient rpcClient = new(new Uri(urlSigner), _get.EthereumJsonSerializer, _get.LogManager, TimeSpan.FromSeconds(10)); + _get.DisposeStack.Push(rpcClient); + return await ClefSigner.Create(rpcClient, chainId, address); + } + catch (HttpRequestException e) + { + throw new NetworkingException($"Remote signer at {urlSigner} did not respond.", NetworkExceptionType.TargetUnreachable, e); + } } } } diff --git a/src/Nethermind/Nethermind.Init/Steps/SetupKeyStore.cs b/src/Nethermind/Nethermind.Init/Steps/SetupKeyStore.cs index 8250541cbe4..cd181ef667b 100644 --- a/src/Nethermind/Nethermind.Init/Steps/SetupKeyStore.cs +++ b/src/Nethermind/Nethermind.Init/Steps/SetupKeyStore.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Nethermind.Api; using Nethermind.Config; +using Nethermind.Consensus; using Nethermind.Crypto; using Nethermind.KeyStore; using Nethermind.KeyStore.Config; @@ -60,7 +61,11 @@ await Task.Run(() => INodeKeyManager nodeKeyManager = new NodeKeyManager(get.CryptoRandom, get.KeyStore, keyStoreConfig, get.LogManager, passwordProvider, get.FileSystem); ProtectedPrivateKey? nodeKey = set.NodeKey = nodeKeyManager.LoadNodeKey(); - set.OriginalSignerKey = nodeKeyManager.LoadSignerKey(); + IMiningConfig miningConfig = get.Config(); + //Don't load the local key if an external signer is configured + if (!miningConfig.Enabled && 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); diff --git a/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs b/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs index 965b6e6b7b4..7ff0aaae3fc 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs @@ -10,19 +10,23 @@ namespace Nethermind.JsonRpc.Client { - public class BasicJsonRpcClient : IJsonRpcClient + public class BasicJsonRpcClient : IJsonRpcClient, IDisposable { private readonly HttpClient _client; private readonly IJsonSerializer _jsonSerializer; private readonly ILogger _logger; + private bool disposedValue; - public BasicJsonRpcClient(Uri uri, IJsonSerializer jsonSerializer, ILogManager logManager) + public BasicJsonRpcClient(Uri uri, IJsonSerializer jsonSerializer, ILogManager logManager): + this(uri, jsonSerializer, logManager, /*support long block traces better, default 100s might be too small*/ TimeSpan.FromMinutes(5)) + {} + public BasicJsonRpcClient(Uri uri, IJsonSerializer jsonSerializer, ILogManager logManager, TimeSpan timeout) { _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager)); _jsonSerializer = jsonSerializer; _client = new HttpClient { BaseAddress = uri }; - _client.Timeout = TimeSpan.FromMinutes(5); // support long block traces better, default 100s might be too small + _client.Timeout = timeout; _client.DefaultRequestHeaders.Accept.Clear(); _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); AddAuthorizationHeader(); @@ -66,6 +70,10 @@ public async Task Post(string method, params object[] parameters) { throw; } + catch (TaskCanceledException) + { + throw; + } catch (Exception) { throw new DataException($"Cannot deserialize {responseString}"); @@ -101,5 +109,23 @@ private void AddAuthorizationHeader() private static string Base64Encode(string plainText) => Convert.ToBase64String(Encoding.UTF8.GetBytes(plainText)); + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + _client?.Dispose(); + } + disposedValue = true; + } + } + + public void Dispose() + { + Dispose(disposing: true); + GC.SuppressFinalize(this); + } } } diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/ClefSigner.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/ClefSigner.cs new file mode 100644 index 00000000000..8eb5db16761 --- /dev/null +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/ClefSigner.cs @@ -0,0 +1,146 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using Nethermind.Consensus; +using Nethermind.Core; +using Nethermind.Core.Crypto; +using Nethermind.Core.Extensions; +using Nethermind.Crypto; +using Nethermind.Evm.Tracing.GethStyle.JavaScript; +using Nethermind.JsonRpc.Client; +using Nethermind.JsonRpc.Data; +using Nethermind.Serialization.Rlp; +using System; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace Nethermind.JsonRpc; +public class ClefSigner : ISigner, ISignerStore +{ + private readonly IJsonRpcClient rpcClient; + private readonly ulong _chainId; + + private ClefSigner(IJsonRpcClient rpcClient, ulong chainId) + { + this.rpcClient = rpcClient; + this._chainId = chainId; + CanSign = true; + } + + public static async Task Create(IJsonRpcClient jsonRpcClient, ulong chainId, Address? blockAuthorAccount = null) + { + ClefSigner signer =new (jsonRpcClient, chainId); + await signer.SetSignerAddress(blockAuthorAccount); + return signer; + } + + public Address Address { get; private set; } + + public bool CanSign { get; } + + public PrivateKey? Key => throw new InvalidOperationException("Cannot get private keys from remote signer."); + + /// + /// Clef will not sign data directly, but will evaluate data and decide itself how to sign. + /// + /// Data to be signed. + /// of . + public Signature Sign(Hash256 message) + { + var signed = rpcClient.Post( + "account_signData", + "text/plain", + Address.ToString(), + message).GetAwaiter().GetResult(); + if (signed == null) + ThrowInvalidOperationSignFailed(); + var bytes = Bytes.FromHexString(signed); + return new Signature(bytes); + } + + /// + /// Used to sign a clique header. The full Rlp of the header has to be sent, + /// since clef does not sign data directly, but will parse and decide itself what to sign. + /// + /// Full Rlp of the clique header. + /// of the hash of the clique header. + public Signature SignCliqueHeader(byte[] rlpHeader) + { + var signed = rpcClient.Post( + "account_signData", + "application/x-clique-header", + Address.ToString(), + rlpHeader.ToHexString(true)).GetAwaiter().GetResult(); + if (signed == null) + ThrowInvalidOperationSignFailed(); + var bytes = Bytes.FromHexString(signed); + + //clef will set recid to 0/1, but we expect it to be 27/28 + if (bytes.Length == 65 && bytes[64] == 0 || bytes[64] == 1) + //We expect V to be 27/28 + bytes[64] += 27; + + return new Signature(bytes); + } + + public async ValueTask Sign(Transaction tx) + { + TransactionForRpc transactionModel = new(tx); + var signed = await rpcClient.Post("account_signTransaction", transactionModel); + if (signed == null) + ThrowInvalidOperationSignFailed(); + tx.Signature = new Signature(signed.Tx.R.Value!, signed.Tx.S.Value!, (ulong)signed.Tx.V); + } + + private async Task SetSignerAddress(Address? blockAuthorAccount) + { + var accounts = await rpcClient.Post("account_list"); + if (!accounts.Any()) + { + throw new InvalidOperationException("Remote signer has not been configured with any signers."); + } + if (blockAuthorAccount != null) + { + if (accounts.Any(a=>new Address(a).Bytes.SequenceEqual(blockAuthorAccount.Bytes))) + Address = blockAuthorAccount; + else + throw new InvalidOperationException($"Remote signer cannot sign for {blockAuthorAccount}."); + } + else + { + Address = new Address(accounts[0]); + } + } + + public void SetSigner(PrivateKey key) + { + ThrowInvalidOperationSetSigner(); + } + + public void SetSigner(ProtectedPrivateKey key) + { + ThrowInvalidOperationSetSigner(); + } + + [DoesNotReturn] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static void ThrowInvalidOperationSignFailed() => + throw new InvalidOperationException("Remote signer failed to sign the request."); + + [DoesNotReturn] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static void ThrowInvalidOperationSetSigner() => + throw new InvalidOperationException("Cannot set a signer when using a remote signer."); + + + private class RemoteTxSignResponse + { + public string Raw { get; set;} + public TransactionForRpc Tx { get; set;} + } +} + + diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/RemoteSigner.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/RemoteSigner.cs deleted file mode 100644 index 821bdf3ae4e..00000000000 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/RemoteSigner.cs +++ /dev/null @@ -1,94 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited -// SPDX-License-Identifier: LGPL-3.0-only - -using Nethermind.Consensus; -using Nethermind.Core; -using Nethermind.Core.Crypto; -using Nethermind.Core.Extensions; -using Nethermind.Crypto; -using Nethermind.JsonRpc.Client; -using Nethermind.JsonRpc.Data; -using System; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; - -namespace Nethermind.JsonRpc; -public class RemoteSigner : ISigner -{ - private readonly IJsonRpcClient rpcClient; - private readonly ulong _chainId; - - private RemoteSigner(IJsonRpcClient rpcClient, ulong chainId) - { - this.rpcClient = rpcClient; - this._chainId = chainId; - CanSign = true; - } - - public static async Task Create(IJsonRpcClient jsonRpcClient, ulong chainId, Address? blockAuthorAccount = null) - { - RemoteSigner signer =new (jsonRpcClient, chainId); - await signer.SetSignerAddress(blockAuthorAccount); - return signer; - } - - public Address Address { get; private set; } - - public bool CanSign { get; } - - public PrivateKey? Key => throw new InvalidOperationException("Private keys cannot be exposed."); - - public Signature Sign(Hash256 message) - { - //TODO handle async - var signed = rpcClient.Post("account_signData", "application/clique", Address.ToString(), message).GetAwaiter().GetResult(); - if (signed == null) - ThrowInvalidOperation(); - return new Signature(Bytes.FromHexString(signed)); - } - - public async ValueTask Sign(Transaction tx) - { - TransactionForRpc transactionModel = new(tx); - var signed = await rpcClient.Post("account_signTransaction", transactionModel); - if (signed == null) - ThrowInvalidOperation(); - tx.Signature = new Signature(signed.Tx.R.Value!, signed.Tx.S.Value!, (ulong)signed.Tx.V); - } - - private async Task SetSignerAddress(Address? blockAuthorAccount) - { - var accounts = await rpcClient.Post("account_list"); - if (!accounts.Any()) - { - throw new InvalidOperationException("Remote signer has not been configured with any signers."); - } - if (blockAuthorAccount != null) - { - if (accounts.Any(a=>new Address(a).Bytes.SequenceEqual(blockAuthorAccount.Bytes))) - Address = blockAuthorAccount; - else - throw new InvalidOperationException($"Remote signer cannot sign for the specified block author {blockAuthorAccount}."); - } - else - { - Address = new Address(accounts[0]); - } - } - - [DoesNotReturn] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static void ThrowInvalidOperation() => - throw new InvalidOperationException("Remote signer failed to sign the request."); - - private class RemoteTxSignResponse - { - public string Raw { get; set;} - public TransactionForRpc Tx { get; set;} - } - -} - - From 5b69110be36b95f2433fcd362f1a669c21984b0b Mon Sep 17 00:00:00 2001 From: ak88 Date: Wed, 21 Feb 2024 14:57:28 +0100 Subject: [PATCH 11/27] put clique producer on dispose stack --- src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs b/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs index e83e633064d..f22f5a44b50 100644 --- a/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs +++ b/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs @@ -151,6 +151,11 @@ public Task InitBlockProducer(IBlockProductionTrigger? blockProd _cliqueConfig!, getFromApi.LogManager); + if (blockProducer is IDisposable disposable) + { + getFromApi.DisposeStack.Push(disposable); + } + return Task.FromResult(blockProducer); } From 3294716989557811a12cfd93a8e094405e6b5b72 Mon Sep 17 00:00:00 2001 From: ak88 Date: Fri, 23 Feb 2024 13:38:38 +0100 Subject: [PATCH 12/27] change from review --- src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs b/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs index f22f5a44b50..e6ba3914fd0 100644 --- a/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs +++ b/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs @@ -137,7 +137,7 @@ public Task InitBlockProducer(IBlockProductionTrigger? blockProd IGasLimitCalculator gasLimitCalculator = setInApi.GasLimitCalculator = new TargetAdjustedGasLimitCalculator(getFromApi.SpecProvider, _blocksConfig); - IBlockProducer blockProducer = new CliqueBlockProducer( + CliqueBlockProducer blockProducer = new ( additionalTxSource.Then(txPoolTxSource), chainProcessor, producerEnv.StateProvider, @@ -151,10 +151,7 @@ public Task InitBlockProducer(IBlockProductionTrigger? blockProd _cliqueConfig!, getFromApi.LogManager); - if (blockProducer is IDisposable disposable) - { - getFromApi.DisposeStack.Push(disposable); - } + getFromApi.DisposeStack.Push(blockProducer); return Task.FromResult(blockProducer); } From 045a51520fd8aa13498ef65d925ed94369af0d02 Mon Sep 17 00:00:00 2001 From: ak88 Date: Fri, 23 Feb 2024 13:39:40 +0100 Subject: [PATCH 13/27] change from review --- src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs b/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs index e6ba3914fd0..a775453d8c5 100644 --- a/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs +++ b/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs @@ -153,7 +153,7 @@ public Task InitBlockProducer(IBlockProductionTrigger? blockProd getFromApi.DisposeStack.Push(blockProducer); - return Task.FromResult(blockProducer); + return Task.FromResult((IBlockProducer)blockProducer); } public Task InitNetworkProtocol() From a245145c6dfaf27131b45312271372c25d93a894 Mon Sep 17 00:00:00 2001 From: ak88 Date: Fri, 23 Feb 2024 13:41:22 +0100 Subject: [PATCH 14/27] format whitespace --- src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs b/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs index a775453d8c5..c416e75cea0 100644 --- a/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs +++ b/src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs @@ -137,7 +137,7 @@ public Task InitBlockProducer(IBlockProductionTrigger? blockProd IGasLimitCalculator gasLimitCalculator = setInApi.GasLimitCalculator = new TargetAdjustedGasLimitCalculator(getFromApi.SpecProvider, _blocksConfig); - CliqueBlockProducer blockProducer = new ( + CliqueBlockProducer blockProducer = new( additionalTxSource.Then(txPoolTxSource), chainProcessor, producerEnv.StateProvider, From 1c2f94f4589db4f12eab83f79a68af495fae7599 Mon Sep 17 00:00:00 2001 From: ak88 Date: Fri, 23 Feb 2024 15:38:21 +0100 Subject: [PATCH 15/27] remove tx sign --- .../Nethermind.JsonRpc/Modules/ClefSigner.cs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/ClefSigner.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/ClefSigner.cs index 8eb5db16761..4b0a275bba9 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/ClefSigner.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/ClefSigner.cs @@ -44,9 +44,10 @@ public static async Task Create(IJsonRpcClient jsonRpcClient, ulong public PrivateKey? Key => throw new InvalidOperationException("Cannot get private keys from remote signer."); /// - /// Clef will not sign data directly, but will evaluate data and decide itself how to sign. + /// Clef will not sign data directly, but will evaluate and sign data in the format: + /// keccak256("\x19Ethereum Signed Message:\n${message length}${message}") /// - /// Data to be signed. + /// Message to be signed. /// of . public Signature Sign(Hash256 message) { @@ -78,7 +79,7 @@ public Signature SignCliqueHeader(byte[] rlpHeader) ThrowInvalidOperationSignFailed(); var bytes = Bytes.FromHexString(signed); - //clef will set recid to 0/1, but we expect it to be 27/28 + //Clef will set recid to 0/1, but we expect it to be 27/28 if (bytes.Length == 65 && bytes[64] == 0 || bytes[64] == 1) //We expect V to be 27/28 bytes[64] += 27; @@ -86,14 +87,8 @@ public Signature SignCliqueHeader(byte[] rlpHeader) return new Signature(bytes); } - public async ValueTask Sign(Transaction tx) - { - TransactionForRpc transactionModel = new(tx); - var signed = await rpcClient.Post("account_signTransaction", transactionModel); - if (signed == null) - ThrowInvalidOperationSignFailed(); - tx.Signature = new Signature(signed.Tx.R.Value!, signed.Tx.S.Value!, (ulong)signed.Tx.V); - } + public ValueTask Sign(Transaction tx) => + throw new NotImplementedException("Remote signing of transactions is not supported."); private async Task SetSignerAddress(Address? blockAuthorAccount) { From 2fbf68eda944b738ef8cabb8c511f075084400fa Mon Sep 17 00:00:00 2001 From: ak88 Date: Mon, 26 Feb 2024 11:01:41 +0100 Subject: [PATCH 16/27] cleanup --- src/Nethermind/Chains/clique-test.json | 941 ------------------ .../Consensus/ClefSignerTests.cs | 17 +- .../CliqueSealer.cs | 2 - .../Nethermind.Consensus/ISignerAsync.cs | 18 - .../Steps/InitializeBlockTree.cs | 6 +- .../Nethermind.JsonRpc/Modules/ClefSigner.cs | 14 +- .../Nethermind.Runner/configs/joc-sandbox.cfg | 31 - 7 files changed, 22 insertions(+), 1007 deletions(-) delete mode 100644 src/Nethermind/Chains/clique-test.json delete mode 100644 src/Nethermind/Nethermind.Consensus/ISignerAsync.cs delete mode 100644 src/Nethermind/Nethermind.Runner/configs/joc-sandbox.cfg diff --git a/src/Nethermind/Chains/clique-test.json b/src/Nethermind/Chains/clique-test.json deleted file mode 100644 index 5f59628a921..00000000000 --- a/src/Nethermind/Chains/clique-test.json +++ /dev/null @@ -1,941 +0,0 @@ -{ - "name": "Joc Testnet", - "dataDir": "joc", - "engine": { - "clique": { - "params": { - "period": 15, - "epoch": 30000 - } - } - }, - "params": { - "accountStartNonce": "0x0", - "chainID": "10081", - "eip140Transition": "0x0", - "eip145Transition": "0x0", - "eip150Transition": "0x0", - "eip155Transition": "0x0", - "eip160Transition": "0x0", - "eip161abcTransition": "0x0", - "eip161dTransition": "0x0", - "eip211Transition": "0x0", - "eip214Transition": "0x0", - "eip658Transition": "0x0", - "eip1014Transition": "0x0", - "eip1052Transition": "0x0", - "eip1283Transition": "0x0", - "eip1283DisableTransition": "0x0", - "eip152Transition": "0x17D433", - "eip1108Transition": "0x17D433", - "eip1344Transition": "0x17D433", - "eip1884Transition": "0x17D433", - "eip2028Transition": "0x17D433", - "eip2200Transition": "0x17D433", - "eip2565Transition": "0x441064", - "eip2929Transition": "0x441064", - "eip2930Transition": "0x441064", - "eip1559Transition": "0x4D3FCD", - "eip3198Transition": "0x4D3FCD", - "eip3529Transition": "0x4D3FCD", - "eip3541Transition": "0x4D3FCD", - "eip3651TransitionTimestamp": "0x6410F460", - "eip3855TransitionTimestamp": "0x6410F460", - "eip3860TransitionTimestamp": "0x6410F460", - "eip4895TransitionTimestamp": "0x6410F460", - "eip1153TransitionTimestamp": "0x65A77460", - "eip4788TransitionTimestamp": "0x65A77460", - "eip4844TransitionTimestamp": "0x65A77460", - "eip5656TransitionTimestamp": "0x65A77460", - "eip6780TransitionTimestamp": "0x65A77460", - "terminalTotalDifficulty": "ffffffA4A470", - "gasLimitBoundDivisor": "0x400", - "maxCodeSize": "0x6000", - "maxCodeSizeTransition": "0x0", - "maximumExtraDataSize": "0xffff", - "minGasLimit": "0x1388", - "networkID": "0x5" - }, - "genesis": { - "author": "0x0000000000000000000000000000000000000000", - "difficulty": "0x1", - "extraData": "0x22466c6578692069732061207468696e6722202d204166726900000000000000bab1b2527edb13aac27a3982a89a61b8007c5df10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "gasLimit": "0x1c03a180", - "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "seal": { - "ethereum": { - "nonce": "0x0000000000000000", - "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000" - } - }, - "timestamp": "0x5bfbe6b5" - }, - "nodes": [ - "enode://011f758e6552d105183b1761c5e2dea0111bc20fd5f6422bc7f91e0fabbec9a6595caf6239b37feb773dddd3f87240d99d859431891e4a642cf2a0a9e6cbb98a@51.141.78.53:30303", - "enode://176b9417f511d05b6b2cf3e34b756cf0a7096b3094572a8f6ef4cdcb9d1f9d00683bf0f83347eebdf3b81c3521c2332086d9592802230bf528eaf606a1d9677b@13.93.54.137:30303", - "enode://46add44b9f13965f7b9875ac6b85f016f341012d84f975377573800a863526f4da19ae2c620ec73d11591fa9510e992ecc03ad0751f53cc02f7c7ed6d55c7291@94.237.54.114:30313", - "enode://c1f8b7c2ac4453271fa07d8e9ecf9a2e8285aa0bd0c07df0131f47153306b0736fd3db8924e7a9bf0bed6b1d8d4f87362a71b033dc7c64547728d953e43e59b2@52.64.155.147:30303", - "enode://f4a9c6ee28586009fb5a96c8af13a58ed6d8315a9eee4772212c1d4d9cebe5a8b8a78ea4434f318726317d04a3f531a1ef0420cf9752605a562cfe858c46e263@213.186.16.82:30303", - "enode://a61215641fb8714a373c80edbfa0ea8878243193f57c96eeb44d0bc019ef295abd4e044fd619bfc4c59731a73fb79afe84e9ab6da0c743ceb479cbb6d263fa91@3.11.147.67:30303", - "enode://b5948a2d3e9d486c4d75bf32713221c2bd6cf86463302339299bd227dc2e276cd5a1c7ca4f43a0e9122fe9af884efed563bd2a1fd28661f3b5f5ad7bf1de5949@18.218.250.66:30303", - "enode://d2b720352e8216c9efc470091aa91ddafc53e222b32780f505c817ceef69e01d5b0b0797b69db254c586f493872352f5a022b4d8479a00fc92ec55f9ad46a27e@88.99.70.182:30303", - "enode://d4f764a48ec2a8ecf883735776fdefe0a3949eb0ca476bd7bc8d0954a9defe8fea15ae5da7d40b5d2d59ce9524a99daedadf6da6283fca492cc80b53689fb3b3@46.4.99.122:32109" - ], - "accounts": { - "0x0000000000000000000000000000000000000000": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000001": { - "balance": "0x1", - "builtin": { - "name": "ecrecover", - "pricing": { - "linear": { - "base": 3000, - "word": 0 - } - } - } - }, - "0x0000000000000000000000000000000000000002": { - "balance": "0x1", - "builtin": { - "name": "sha256", - "pricing": { - "linear": { - "base": 60, - "word": 12 - } - } - } - }, - "0x0000000000000000000000000000000000000003": { - "balance": "0x1", - "builtin": { - "name": "ripemd160", - "pricing": { - "linear": { - "base": 600, - "word": 120 - } - } - } - }, - "0x0000000000000000000000000000000000000004": { - "balance": "0x1", - "builtin": { - "name": "identity", - "pricing": { - "linear": { - "base": 15, - "word": 3 - } - } - } - }, - "0x0000000000000000000000000000000000000005": { - "balance": "0x1", - "builtin": { - "name": "modexp", - "activate_at": "0x0", - "pricing": { - "modexp": { - "divisor": 20 - } - } - } - }, - "0x0000000000000000000000000000000000000006": { - "balance": "0x1", - "builtin": { - "name": "alt_bn128_add", - "activate_at": "0x0", - "pricing": { - "linear": { - "base": 500, - "word": 0 - } - } - } - }, - "0x0000000000000000000000000000000000000007": { - "balance": "0x1", - "builtin": { - "name": "alt_bn128_mul", - "activate_at": "0x0", - "pricing": { - "linear": { - "base": 40000, - "word": 0 - } - } - } - }, - "0x0000000000000000000000000000000000000008": { - "balance": "0x1", - "builtin": { - "name": "alt_bn128_pairing", - "activate_at": "0x0", - "pricing": { - "alt_bn128_pairing": { - "base": 100000, - "pair": 80000 - } - } - } - }, - "0x0000000000000000000000000000000000000009": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000000a": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000000b": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000000c": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000000d": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000000e": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000000f": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000010": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000011": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000012": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000013": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000014": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000015": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000016": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000017": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000018": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000019": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000001a": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000001b": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000001c": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000001d": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000001e": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000001f": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000020": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000021": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000022": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000023": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000024": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000025": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000026": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000027": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000028": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000029": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000002a": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000002b": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000002c": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000002d": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000002e": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000002f": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000030": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000031": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000032": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000033": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000034": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000035": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000036": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000037": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000038": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000039": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000003a": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000003b": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000003c": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000003d": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000003e": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000003f": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000040": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000041": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000042": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000043": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000044": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000045": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000046": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000047": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000048": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000049": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000004a": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000004b": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000004c": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000004d": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000004e": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000004f": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000050": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000051": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000052": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000053": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000054": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000055": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000056": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000057": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000058": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000059": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000005a": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000005b": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000005c": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000005d": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000005e": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000005f": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000060": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000061": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000062": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000063": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000064": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000065": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000066": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000067": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000068": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000069": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000006a": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000006b": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000006c": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000006d": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000006e": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000006f": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000070": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000071": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000072": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000073": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000074": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000075": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000076": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000077": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000078": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000079": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000007a": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000007b": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000007c": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000007d": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000007e": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000007f": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000080": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000081": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000082": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000083": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000084": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000085": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000086": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000087": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000088": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000089": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000008a": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000008b": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000008c": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000008d": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000008e": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000008f": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000090": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000091": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000092": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000093": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000094": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000095": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000096": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000097": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000098": { - "balance": "0x1" - }, - "0x0000000000000000000000000000000000000099": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000009a": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000009b": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000009c": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000009d": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000009e": { - "balance": "0x1" - }, - "0x000000000000000000000000000000000000009f": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000a0": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000a1": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000a2": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000a3": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000a4": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000a5": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000a6": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000a7": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000a8": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000a9": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000aa": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000ab": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000ac": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000ad": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000ae": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000af": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000b0": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000b1": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000b2": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000b3": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000b4": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000b5": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000b6": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000b7": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000b8": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000b9": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000ba": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000bb": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000bc": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000bd": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000be": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000bf": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000c0": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000c1": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000c2": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000c3": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000c4": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000c5": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000c6": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000c7": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000c8": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000c9": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000ca": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000cb": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000cc": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000cd": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000ce": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000cf": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000d0": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000d1": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000d2": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000d3": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000d4": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000d5": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000d6": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000d7": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000d8": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000d9": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000da": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000db": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000dc": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000dd": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000de": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000df": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000e0": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000e1": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000e2": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000e3": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000e4": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000e5": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000e6": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000e7": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000e8": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000e9": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000ea": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000eb": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000ec": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000ed": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000ee": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000ef": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000f0": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000f1": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000f2": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000f3": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000f4": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000f5": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000f6": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000f7": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000f8": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000f9": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000fa": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000fb": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000fc": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000fd": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000fe": { - "balance": "0x1" - }, - "0x00000000000000000000000000000000000000ff": { - "balance": "0x1" - }, - "0x4c2ae482593505f0163cdefc073e81c63cda4107": { - "balance": "0x152d02c7e14af6800000" - }, - "0xa8e8f14732658e4b51e8711931053a8a69baf2b1": { - "balance": "0x152d02c7e14af6800000" - }, - "0xd9a5179f091d85051d3c982785efd1455cec8699": { - "balance": "0x84595161401484a000000" - }, - "0xe0a2bd4258d2768837baa26a28fe71dc079f84c7": { - "balance": "0x4a47e3c12448f4ad000000" - } - } -} diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs index 8731dbefd7c..a078c0b0f74 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs @@ -7,6 +7,7 @@ using Nethermind.Core.Crypto; using Nethermind.Core.Extensions; using Nethermind.Core.Test.Builders; +using Nethermind.Crypto; using Nethermind.Evm.Tracing.GethStyle.JavaScript; using Nethermind.Int256; using Nethermind.JsonRpc; @@ -75,21 +76,31 @@ public async Task Create_SignerAddressSpecified_CorrectAddressIsSet() { IJsonRpcClient client = Substitute.For(); client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString(), TestItem.AddressB!.ToString()])); - + ClefSigner sut = await ClefSigner.Create(client, 0, TestItem.AddressB); Assert.That(sut.Address, Is.EqualTo(TestItem.AddressB)); } [Test] - public async Task Create_SignerAddressDoesNotExists_Throw() + public async Task Create_SignerAddressDoesNotExists_ThrowInvalidOperationException() { IJsonRpcClient client = Substitute.For(); client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString(), TestItem.AddressB!.ToString()])); ClefSigner sut = await ClefSigner.Create(client, 0, TestItem.AddressC); - Assert.That(()=> ClefSigner.Create(client, 0, TestItem.AddressC), Throws.InstanceOf()); + Assert.That(() => ClefSigner.Create(client, 0, TestItem.AddressC), Throws.InstanceOf()); + } + + [Test] + public async Task SetSigner_TryingToASigner_ThrowInvalidOperationException() + { + IJsonRpcClient client = Substitute.For(); + client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString()])); + ClefSigner sut = await ClefSigner.Create(client, 0); + + Assert.That(() => sut.SetSigner(Build.A.PrivateKey.TestObject), Throws.InstanceOf()); } } } diff --git a/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs b/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs index c3e31a884f1..08804ed317a 100644 --- a/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs +++ b/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs @@ -7,11 +7,9 @@ using System.Threading.Tasks; using Nethermind.Core; using Nethermind.Core.Crypto; -using Nethermind.Core.Extensions; using Nethermind.Crypto; using Nethermind.JsonRpc; using Nethermind.Logging; -using Nethermind.Serialization.Rlp; [assembly: InternalsVisibleTo("Nethermind.Clique.Test")] diff --git a/src/Nethermind/Nethermind.Consensus/ISignerAsync.cs b/src/Nethermind/Nethermind.Consensus/ISignerAsync.cs deleted file mode 100644 index 7aa4202ecb4..00000000000 --- a/src/Nethermind/Nethermind.Consensus/ISignerAsync.cs +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited -// SPDX-License-Identifier: LGPL-3.0-only - -using Nethermind.Core; -using Nethermind.Core.Crypto; -using Nethermind.Crypto; -using Nethermind.TxPool; -using System.Threading.Tasks; - -namespace Nethermind.Consensus -{ - public interface ISignerAsync : ITxSigner - { - Task Sign(Hash256 message); - Address Address { get; } - bool CanSign { get; } - } -} diff --git a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs index 0e315c60175..de527c7dec0 100644 --- a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs +++ b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs @@ -4,10 +4,8 @@ using System; using System.IO; using System.Net.Http; -using System.Net.Sockets; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; using Nethermind.Api; using Nethermind.Blockchain; using Nethermind.Blockchain.Blocks; @@ -22,9 +20,7 @@ using Nethermind.JsonRpc; using Nethermind.JsonRpc.Client; using Nethermind.KeyStore.Config; -using Nethermind.Logging; using Nethermind.Network; -using Nethermind.Serialization.Json; using Nethermind.Serialization.Rlp; using Nethermind.State.Repositories; @@ -94,7 +90,7 @@ public async Task Execute(CancellationToken cancellationToken) signer = signerAndStore; signerStore = signerAndStore; } - } + } _set.EngineSigner = signer; _set.EngineSignerStore = signerStore; diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/ClefSigner.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/ClefSigner.cs index 4b0a275bba9..2554a32ec54 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/ClefSigner.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/ClefSigner.cs @@ -18,7 +18,7 @@ using System.Threading.Tasks; namespace Nethermind.JsonRpc; -public class ClefSigner : ISigner, ISignerStore +public class ClefSigner : ISigner, ISignerStore { private readonly IJsonRpcClient rpcClient; private readonly ulong _chainId; @@ -32,7 +32,7 @@ private ClefSigner(IJsonRpcClient rpcClient, ulong chainId) public static async Task Create(IJsonRpcClient jsonRpcClient, ulong chainId, Address? blockAuthorAccount = null) { - ClefSigner signer =new (jsonRpcClient, chainId); + ClefSigner signer = new(jsonRpcClient, chainId); await signer.SetSignerAddress(blockAuthorAccount); return signer; } @@ -44,7 +44,7 @@ public static async Task Create(IJsonRpcClient jsonRpcClient, ulong public PrivateKey? Key => throw new InvalidOperationException("Cannot get private keys from remote signer."); /// - /// Clef will not sign data directly, but will evaluate and sign data in the format: + /// Clef will not sign data directly, but will parse and sign data in the format: /// keccak256("\x19Ethereum Signed Message:\n${message length}${message}") /// /// Message to be signed. @@ -82,7 +82,7 @@ public Signature SignCliqueHeader(byte[] rlpHeader) //Clef will set recid to 0/1, but we expect it to be 27/28 if (bytes.Length == 65 && bytes[64] == 0 || bytes[64] == 1) //We expect V to be 27/28 - bytes[64] += 27; + bytes[64] += 27; return new Signature(bytes); } @@ -99,7 +99,7 @@ private async Task SetSignerAddress(Address? blockAuthorAccount) } if (blockAuthorAccount != null) { - if (accounts.Any(a=>new Address(a).Bytes.SequenceEqual(blockAuthorAccount.Bytes))) + if (accounts.Any(a => new Address(a).Bytes.SequenceEqual(blockAuthorAccount.Bytes))) Address = blockAuthorAccount; else throw new InvalidOperationException($"Remote signer cannot sign for {blockAuthorAccount}."); @@ -133,8 +133,8 @@ private static void ThrowInvalidOperationSetSigner() => private class RemoteTxSignResponse { - public string Raw { get; set;} - public TransactionForRpc Tx { get; set;} + public string Raw { get; set; } + public TransactionForRpc Tx { get; set; } } } diff --git a/src/Nethermind/Nethermind.Runner/configs/joc-sandbox.cfg b/src/Nethermind/Nethermind.Runner/configs/joc-sandbox.cfg deleted file mode 100644 index b1a6126151c..00000000000 --- a/src/Nethermind/Nethermind.Runner/configs/joc-sandbox.cfg +++ /dev/null @@ -1,31 +0,0 @@ -{ - "Init": { - "ChainSpecPath": "chainspec/joc-sandbox.json", - "GenesisHash": "0xd5fd768d2dde71d81b3fb49a2961bd07e4447f137a8fc4d0d12e32064fe67586", - "BaseDbPath": "nethermind_db/joc-sandbox", - "LogFileName": "joc-sandbox.logs.txt" - }, - "TxPool": { - "BlobsSupport": "Disabled" - }, - "Sync": { - "FastSync": true, - "SnapSync": true, - "FastBlocks": true, - "PivotNumber": 16090000, - "PivotHash": "0x47778509f7d2e74f858139d66833daedf81233e15d8c5ce42c661ae84d9e7dbe", - "PivotTotalDifficulty": "30973293" - }, - "Metrics": { - "NodeName": "JOC-Sandbox" - }, - "Blocks": { - "TargetBlockGasLimit": 30000000 - }, - "JsonRpc": { - "Enabled": true - }, - "Merge": { - "Enabled": false - } -} From bb05c1be7bc9a2cd17766aeae85e26096a6150e7 Mon Sep 17 00:00:00 2001 From: ak88 Date: Mon, 26 Feb 2024 11:02:07 +0100 Subject: [PATCH 17/27] format whitespace --- .../Client/BasicJsonRpcClient.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs b/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs index 7ff0aaae3fc..cb1f19e16e0 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs @@ -17,16 +17,16 @@ public class BasicJsonRpcClient : IJsonRpcClient, IDisposable private readonly ILogger _logger; private bool disposedValue; - public BasicJsonRpcClient(Uri uri, IJsonSerializer jsonSerializer, ILogManager logManager): + public BasicJsonRpcClient(Uri uri, IJsonSerializer jsonSerializer, ILogManager logManager) : this(uri, jsonSerializer, logManager, /*support long block traces better, default 100s might be too small*/ TimeSpan.FromMinutes(5)) - {} + { } public BasicJsonRpcClient(Uri uri, IJsonSerializer jsonSerializer, ILogManager logManager, TimeSpan timeout) { _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager)); _jsonSerializer = jsonSerializer; _client = new HttpClient { BaseAddress = uri }; - _client.Timeout = timeout; + _client.Timeout = timeout; _client.DefaultRequestHeaders.Accept.Clear(); _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); AddAuthorizationHeader(); From 1012dd3e336cc62fc46a904bb94b3fede76214fa Mon Sep 17 00:00:00 2001 From: ak88 Date: Mon, 26 Feb 2024 11:31:53 +0100 Subject: [PATCH 18/27] remove test cfg --- .../Properties/launchSettings.json | 7 ----- .../Nethermind.Runner/configs/clique-test.cfg | 27 ------------------- 2 files changed, 34 deletions(-) delete mode 100644 src/Nethermind/Nethermind.Runner/configs/clique-test.cfg diff --git a/src/Nethermind/Nethermind.Runner/Properties/launchSettings.json b/src/Nethermind/Nethermind.Runner/Properties/launchSettings.json index fcdfdb21c3d..ffd9f258b2d 100644 --- a/src/Nethermind/Nethermind.Runner/Properties/launchSettings.json +++ b/src/Nethermind/Nethermind.Runner/Properties/launchSettings.json @@ -182,13 +182,6 @@ "ASPNETCORE_ENVIRONMENT": "Development" } }, - "Joc-CliqueTest": { - "commandName": "Project", - "commandLineArgs": "-c clique-test -dd .data", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, "Docker": { "commandName": "Docker", "commandLineArgs": "-c sepolia -dd /data --JsonRpc.EngineHost 0.0.0.0 --JsonRpc.EnginePort 8551 --JsonRpc.Host 0.0.0.0" diff --git a/src/Nethermind/Nethermind.Runner/configs/clique-test.cfg b/src/Nethermind/Nethermind.Runner/configs/clique-test.cfg deleted file mode 100644 index a9c22d26eb3..00000000000 --- a/src/Nethermind/Nethermind.Runner/configs/clique-test.cfg +++ /dev/null @@ -1,27 +0,0 @@ -{ - "Init": { - "WebSocketsEnabled": false, - "StoreReceipts": true, - "EnableUnsecuredDevWallet": true, - "IsMining": true, - "ChainSpecPath": "chainspec/clique-test.json", - "BaseDbPath": "nethermind_db/clique-joc", - "LogFileName": "clique.logs.txt", - "StaticNodesPath": "Data/static-nodes.json" - }, - "Blocks": { - "TargetBlockGasLimit": 30000000 - }, - "JsonRpc": { - "Enabled": true, - "Timeout": 20000, - "Host": "127.0.0.1", - "Port": 8545, - "AdditionalRpcUrls": [ - "http://localhost:8551|http;ws|net;eth;subscribe;engine;web3;client" - ] - }, - "Merge": { - "Enabled": true - } -} From 48dcd4c4198a4f80bd04b9891a8945034ab9781e Mon Sep 17 00:00:00 2001 From: ak88 Date: Mon, 26 Feb 2024 11:51:01 +0100 Subject: [PATCH 19/27] test fix --- .../Consensus/ClefSignerTests.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs index a078c0b0f74..bd84589f60f 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs @@ -43,12 +43,12 @@ public async Task SignCliqueHeader_SigningCliqueHeader_RequestHasCorrectParamete { IJsonRpcClient client = Substitute.For(); client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString()])); - Task postMethod = client.Post("account_signData", "account/x-clique-header", Arg.Any(), Keccak.Zero); + Task postMethod = client.Post("account_signData", "application/x-clique-header", Arg.Any(), Arg.Any()); var returnValue = (new byte[65]).ToHexString(); postMethod.Returns(returnValue); ClefSigner sut = await ClefSigner.Create(client, 0); - var result = sut.SignCliqueHeader(new byte[1]); + var result = sut.SignCliqueHeader(Keccak.Zero.Bytes.ToArray()); Assert.That(new Signature(returnValue).Bytes, Is.EqualTo(result.Bytes)); } @@ -60,7 +60,7 @@ public async Task SignCliqueHeader_RecoveryIdIsSetToCliqueValues_RecoveryIdIsAdj { IJsonRpcClient client = Substitute.For(); client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString()])); - Task postMethod = client.Post("account_signData", "account/x-clique-header", Arg.Any(), Keccak.Zero); + Task postMethod = client.Post("account_signData", "application/x-clique-header", Arg.Any(), Arg.Any()); var returnValue = (new byte[65]); returnValue[64] = recId; postMethod.Returns(returnValue.ToHexString()); @@ -68,7 +68,7 @@ public async Task SignCliqueHeader_RecoveryIdIsSetToCliqueValues_RecoveryIdIsAdj var result = sut.SignCliqueHeader(new byte[1]); - Assert.That(new Signature(returnValue).V, Is.EqualTo(expected)); + Assert.That(result.V, Is.EqualTo(expected)); } [Test] @@ -83,14 +83,12 @@ public async Task Create_SignerAddressSpecified_CorrectAddressIsSet() } [Test] - public async Task Create_SignerAddressDoesNotExists_ThrowInvalidOperationException() + public void Create_SignerAddressDoesNotExists_ThrowInvalidOperationException() { IJsonRpcClient client = Substitute.For(); client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString(), TestItem.AddressB!.ToString()])); - ClefSigner sut = await ClefSigner.Create(client, 0, TestItem.AddressC); - - Assert.That(() => ClefSigner.Create(client, 0, TestItem.AddressC), Throws.InstanceOf()); + Assert.That(async () => await ClefSigner.Create(client, 0, TestItem.AddressC), Throws.InstanceOf()); } [Test] From 2a34f39ab582b20247e24df4660b4b1028a6f02c Mon Sep 17 00:00:00 2001 From: ak88 Date: Mon, 26 Feb 2024 13:31:20 +0100 Subject: [PATCH 20/27] remove sandbox spec --- src/Nethermind/Chains/joc-sandbox.json | 840 ------------------ .../Consensus/ClefSignerTests.cs | 7 - 2 files changed, 847 deletions(-) delete mode 100644 src/Nethermind/Chains/joc-sandbox.json diff --git a/src/Nethermind/Chains/joc-sandbox.json b/src/Nethermind/Chains/joc-sandbox.json deleted file mode 100644 index ec68d0a4944..00000000000 --- a/src/Nethermind/Chains/joc-sandbox.json +++ /dev/null @@ -1,840 +0,0 @@ -{ - "name": "JOC Sandbox", - "dataDir": "joc-sandbox", - "engine": { - "clique": { - "params": { - "period": 5, - "epoch": 30000 - } - } - }, - "params": { - "accountStartNonce": "0x0", - "chainID": "0x1869F", - "eip140Transition": "0x0", - "eip145Transition": "0x0", - "eip150Transition": "0x0", - "eip155Transition": "0x0", - "eip160Transition": "0x0", - "eip161abcTransition": "0x0", - "eip161dTransition": "0x0", - "eip211Transition": "0x0", - "eip214Transition": "0x0", - "eip658Transition": "0x0", - "eip1014Transition": "0x0", - "eip1052Transition": "0x0", - "eip1283Transition": "0x0", - "eip1283DisableTransition": "0x0", - "eip152Transition": "0x0", - "eip1108Transition": "0x0", - "eip1344Transition": "0x0", - "eip1884Transition": "0x0", - "eip2028Transition": "0x0", - "eip2200Transition": "0x0", - "eip2565Transition": "0xD82F2E", - "eip2929Transition": "0xD82F2E", - "eip2930Transition": "0xD82F2E", - "eip1559Transition": "0xD82F2E", - "eip3198Transition": "0xD82F2E", - "eip3529Transition": "0xD82F2E", - "eip3541Transition": "0xD82F2E", - "gasLimitBoundDivisor": "0x400", - "maxCodeSize": "0x6000", - "maxCodeSizeTransition": "0x0", - "maximumExtraDataSize": "0xffff", - "minGasLimit": "0x1388", - "networkID": "0x1869F" - }, - "genesis": { - "author": "0x0000000000000000000000000000000000000000", - "difficulty": "0x1", - "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000f308d66df5d0d2e19b708959a5d6d2da9b4aebb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "gasLimit": "0x1c03a180", - "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "seal": { - "ethereum": { - "nonce": "0x0000000000000000", - "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000" - } - }, - "timestamp": "0x5bfbe6b5" - }, - "nodes": [ - "enode://4f2d95357543549bca62d350b615b3a04e2f2f4a5e0237b9b93736387c0b388c323a6a7eebd5890f8719ee0b83c33c6206e68fa72b452030edf7c03642fd7a01@18.182.60.47:30303" - - ], - "accounts": { - "0000000000000000000000000000000000000000": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000001": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000002": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000003": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000004": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000005": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000006": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000007": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000008": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000009": { - "balance": "0x1" - }, - "000000000000000000000000000000000000000a": { - "balance": "0x1" - }, - "000000000000000000000000000000000000000b": { - "balance": "0x1" - }, - "000000000000000000000000000000000000000c": { - "balance": "0x1" - }, - "000000000000000000000000000000000000000d": { - "balance": "0x1" - }, - "000000000000000000000000000000000000000e": { - "balance": "0x1" - }, - "000000000000000000000000000000000000000f": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000010": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000011": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000012": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000013": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000014": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000015": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000016": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000017": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000018": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000019": { - "balance": "0x1" - }, - "000000000000000000000000000000000000001a": { - "balance": "0x1" - }, - "000000000000000000000000000000000000001b": { - "balance": "0x1" - }, - "000000000000000000000000000000000000001c": { - "balance": "0x1" - }, - "000000000000000000000000000000000000001d": { - "balance": "0x1" - }, - "000000000000000000000000000000000000001e": { - "balance": "0x1" - }, - "000000000000000000000000000000000000001f": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000020": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000021": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000022": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000023": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000024": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000025": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000026": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000027": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000028": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000029": { - "balance": "0x1" - }, - "000000000000000000000000000000000000002a": { - "balance": "0x1" - }, - "000000000000000000000000000000000000002b": { - "balance": "0x1" - }, - "000000000000000000000000000000000000002c": { - "balance": "0x1" - }, - "000000000000000000000000000000000000002d": { - "balance": "0x1" - }, - "000000000000000000000000000000000000002e": { - "balance": "0x1" - }, - "000000000000000000000000000000000000002f": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000030": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000031": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000032": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000033": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000034": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000035": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000036": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000037": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000038": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000039": { - "balance": "0x1" - }, - "000000000000000000000000000000000000003a": { - "balance": "0x1" - }, - "000000000000000000000000000000000000003b": { - "balance": "0x1" - }, - "000000000000000000000000000000000000003c": { - "balance": "0x1" - }, - "000000000000000000000000000000000000003d": { - "balance": "0x1" - }, - "000000000000000000000000000000000000003e": { - "balance": "0x1" - }, - "000000000000000000000000000000000000003f": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000040": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000041": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000042": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000043": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000044": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000045": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000046": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000047": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000048": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000049": { - "balance": "0x1" - }, - "000000000000000000000000000000000000004a": { - "balance": "0x1" - }, - "000000000000000000000000000000000000004b": { - "balance": "0x1" - }, - "000000000000000000000000000000000000004c": { - "balance": "0x1" - }, - "000000000000000000000000000000000000004d": { - "balance": "0x1" - }, - "000000000000000000000000000000000000004e": { - "balance": "0x1" - }, - "000000000000000000000000000000000000004f": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000050": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000051": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000052": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000053": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000054": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000055": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000056": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000057": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000058": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000059": { - "balance": "0x1" - }, - "000000000000000000000000000000000000005a": { - "balance": "0x1" - }, - "000000000000000000000000000000000000005b": { - "balance": "0x1" - }, - "000000000000000000000000000000000000005c": { - "balance": "0x1" - }, - "000000000000000000000000000000000000005d": { - "balance": "0x1" - }, - "000000000000000000000000000000000000005e": { - "balance": "0x1" - }, - "000000000000000000000000000000000000005f": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000060": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000061": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000062": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000063": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000064": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000065": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000066": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000067": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000068": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000069": { - "balance": "0x1" - }, - "000000000000000000000000000000000000006a": { - "balance": "0x1" - }, - "000000000000000000000000000000000000006b": { - "balance": "0x1" - }, - "000000000000000000000000000000000000006c": { - "balance": "0x1" - }, - "000000000000000000000000000000000000006d": { - "balance": "0x1" - }, - "000000000000000000000000000000000000006e": { - "balance": "0x1" - }, - "000000000000000000000000000000000000006f": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000070": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000071": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000072": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000073": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000074": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000075": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000076": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000077": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000078": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000079": { - "balance": "0x1" - }, - "000000000000000000000000000000000000007a": { - "balance": "0x1" - }, - "000000000000000000000000000000000000007b": { - "balance": "0x1" - }, - "000000000000000000000000000000000000007c": { - "balance": "0x1" - }, - "000000000000000000000000000000000000007d": { - "balance": "0x1" - }, - "000000000000000000000000000000000000007e": { - "balance": "0x1" - }, - "000000000000000000000000000000000000007f": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000080": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000081": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000082": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000083": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000084": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000085": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000086": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000087": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000088": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000089": { - "balance": "0x1" - }, - "000000000000000000000000000000000000008a": { - "balance": "0x1" - }, - "000000000000000000000000000000000000008b": { - "balance": "0x1" - }, - "000000000000000000000000000000000000008c": { - "balance": "0x1" - }, - "000000000000000000000000000000000000008d": { - "balance": "0x1" - }, - "000000000000000000000000000000000000008e": { - "balance": "0x1" - }, - "000000000000000000000000000000000000008f": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000090": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000091": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000092": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000093": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000094": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000095": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000096": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000097": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000098": { - "balance": "0x1" - }, - "0000000000000000000000000000000000000099": { - "balance": "0x1" - }, - "000000000000000000000000000000000000009a": { - "balance": "0x1" - }, - "000000000000000000000000000000000000009b": { - "balance": "0x1" - }, - "000000000000000000000000000000000000009c": { - "balance": "0x1" - }, - "000000000000000000000000000000000000009d": { - "balance": "0x1" - }, - "000000000000000000000000000000000000009e": { - "balance": "0x1" - }, - "000000000000000000000000000000000000009f": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000a0": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000a1": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000a2": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000a3": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000a4": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000a5": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000a6": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000a7": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000a8": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000a9": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000aa": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000ab": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000ac": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000ad": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000ae": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000af": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000b0": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000b1": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000b2": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000b3": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000b4": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000b5": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000b6": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000b7": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000b8": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000b9": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000ba": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000bb": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000bc": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000bd": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000be": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000bf": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000c0": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000c1": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000c2": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000c3": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000c4": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000c5": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000c6": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000c7": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000c8": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000c9": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000ca": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000cb": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000cc": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000cd": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000ce": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000cf": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000d0": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000d1": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000d2": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000d3": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000d4": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000d5": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000d6": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000d7": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000d8": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000d9": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000da": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000db": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000dc": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000dd": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000de": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000df": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000e0": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000e1": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000e2": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000e3": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000e4": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000e5": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000e6": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000e7": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000e8": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000e9": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000ea": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000eb": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000ec": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000ed": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000ee": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000ef": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000f0": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000f1": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000f2": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000f3": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000f4": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000f5": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000f6": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000f7": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000f8": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000f9": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000fa": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000fb": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000fc": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000fd": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000fe": { - "balance": "0x1" - }, - "00000000000000000000000000000000000000ff": { - "balance": "0x1" - }, - "0xe546882a744f43d20b84e8a0e5a6ac9f83f9d6e0": { - "balance": "0x0000000000000000000000000000000000000000033B2E3C9FD0803CE8000000" - } - } -} diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs index bd84589f60f..8a693b39296 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs @@ -3,18 +3,11 @@ using System; using System.Threading.Tasks; -using Nethermind.Consensus; using Nethermind.Core.Crypto; using Nethermind.Core.Extensions; using Nethermind.Core.Test.Builders; -using Nethermind.Crypto; -using Nethermind.Evm.Tracing.GethStyle.JavaScript; -using Nethermind.Int256; using Nethermind.JsonRpc; using Nethermind.JsonRpc.Client; -using Nethermind.JsonRpc.Data; -using Nethermind.Logging; -using Nethermind.Serialization.Json; using NSubstitute; using NUnit.Framework; From c99c5fa3706f795eb77e231f94d43139b2e75782 Mon Sep 17 00:00:00 2001 From: ak88 Date: Mon, 25 Mar 2024 13:37:05 +0100 Subject: [PATCH 21/27] Squashed commit of the following: commit ab6f5bec2e6eb04a1220e0751ebf8264054b404c Author: ak88 Date: Mon Mar 25 13:36:30 2024 +0100 unittest commit ad2bf4c37d607aede21cb14e1f30d772c4448402 Author: ak88 Date: Mon Mar 25 11:49:35 2024 +0100 small fixes commit 503db49b3fa46b1fcd0f39a37a73470d479e301a Author: ak88 Date: Thu Mar 21 15:17:54 2024 +0100 plugin methods commit 1034179d00522805f408a4894a9b165b41033fea Author: ak88 Date: Thu Mar 21 12:57:53 2024 +0100 clef signer as plugin --- .../Consensus/ClefSignerTests.cs | 28 +++--- .../Nethermind.Blockchain.Test.csproj | 1 + .../Nethermind.Clique.Test/CliqueTests.cs | 18 ++++ .../CliqueSealer.cs | 15 +++- .../SnapshotManager.cs | 12 --- .../Nethermind.Consensus/ISigner.cs | 3 + .../Nethermind.Consensus/NullSigner.cs | 4 + src/Nethermind/Nethermind.Consensus/Signer.cs | 9 +- .../ClefSigner.cs | 85 ++++++++++--------- .../ClefSignerPlugin.cs | 80 +++++++++++++++++ .../Nethermind.ExternalSigner.Plugin.csproj | 13 +++ .../Steps/InitializeBlockTree.cs | 43 ++-------- .../Nethermind.Mev.Test/TestMevSigner.cs | 4 + .../Nethermind.Runner.csproj | 9 +- src/Nethermind/Nethermind.sln | 12 ++- 15 files changed, 224 insertions(+), 112 deletions(-) rename src/Nethermind/{Nethermind.JsonRpc/Modules => Nethermind.ExternalSigner.Plugin}/ClefSigner.cs (63%) create mode 100644 src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSignerPlugin.cs create mode 100644 src/Nethermind/Nethermind.ExternalSigner.Plugin/Nethermind.ExternalSigner.Plugin.csproj diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs index 8a693b39296..b4ce5520b71 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Consensus/ClefSignerTests.cs @@ -3,6 +3,8 @@ using System; using System.Threading.Tasks; +using FluentAssertions; +using Nethermind.Core; using Nethermind.Core.Crypto; using Nethermind.Core.Extensions; using Nethermind.Core.Test.Builders; @@ -24,7 +26,7 @@ public async Task Sign_SigningHash_RequestHasCorrectParameters() Task postMethod = client.Post("account_signData", "text/plain", Arg.Any(), Keccak.Zero); var returnValue = (new byte[65]).ToHexString(); postMethod.Returns(returnValue); - ClefSigner sut = await ClefSigner.Create(client, 0); + ClefSigner sut = await ClefSigner.Create(client); var result = sut.Sign(Keccak.Zero); @@ -32,24 +34,25 @@ public async Task Sign_SigningHash_RequestHasCorrectParameters() } [Test] - public async Task SignCliqueHeader_SigningCliqueHeader_RequestHasCorrectParameters() + public async Task Sign_SigningCliqueHeader_PassingCorrectClefParametersForRequest() { IJsonRpcClient client = Substitute.For(); client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString()])); - Task postMethod = client.Post("account_signData", "application/x-clique-header", Arg.Any(), Arg.Any()); + Task postMethod = client.Post(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()); var returnValue = (new byte[65]).ToHexString(); postMethod.Returns(returnValue); - ClefSigner sut = await ClefSigner.Create(client, 0); + BlockHeader blockHeader = Build.A.BlockHeader.TestObject; + ClefSigner sut = await ClefSigner.Create(client); - var result = sut.SignCliqueHeader(Keccak.Zero.Bytes.ToArray()); + sut.Sign(blockHeader); - Assert.That(new Signature(returnValue).Bytes, Is.EqualTo(result.Bytes)); + await client.Received().Post("account_signData", "application/x-clique-header", Arg.Any(), Arg.Any()); } [TestCase(0, 27)] [TestCase(1, 28)] - public async Task SignCliqueHeader_RecoveryIdIsSetToCliqueValues_RecoveryIdIsAdjusted(byte recId, byte expected) + public async Task Sign_RecoveryIdIsSetToCliqueValues_RecoveryIdIsAdjusted(byte recId, byte expected) { IJsonRpcClient client = Substitute.For(); client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString()])); @@ -57,9 +60,10 @@ public async Task SignCliqueHeader_RecoveryIdIsSetToCliqueValues_RecoveryIdIsAdj var returnValue = (new byte[65]); returnValue[64] = recId; postMethod.Returns(returnValue.ToHexString()); - ClefSigner sut = await ClefSigner.Create(client, 0); + BlockHeader blockHeader = Build.A.BlockHeader.TestObject; + ClefSigner sut = await ClefSigner.Create(client); - var result = sut.SignCliqueHeader(new byte[1]); + var result = sut.Sign(blockHeader); Assert.That(result.V, Is.EqualTo(expected)); } @@ -70,7 +74,7 @@ public async Task Create_SignerAddressSpecified_CorrectAddressIsSet() IJsonRpcClient client = Substitute.For(); client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString(), TestItem.AddressB!.ToString()])); - ClefSigner sut = await ClefSigner.Create(client, 0, TestItem.AddressB); + ClefSigner sut = await ClefSigner.Create(client, TestItem.AddressB); Assert.That(sut.Address, Is.EqualTo(TestItem.AddressB)); } @@ -81,7 +85,7 @@ public void Create_SignerAddressDoesNotExists_ThrowInvalidOperationException() IJsonRpcClient client = Substitute.For(); client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString(), TestItem.AddressB!.ToString()])); - Assert.That(async () => await ClefSigner.Create(client, 0, TestItem.AddressC), Throws.InstanceOf()); + Assert.That(async () => await ClefSigner.Create(client, TestItem.AddressC), Throws.InstanceOf()); } [Test] @@ -89,7 +93,7 @@ public async Task SetSigner_TryingToASigner_ThrowInvalidOperationException() { IJsonRpcClient client = Substitute.For(); client.Post("account_list").Returns(Task.FromResult([TestItem.AddressA!.ToString()])); - ClefSigner sut = await ClefSigner.Create(client, 0); + ClefSigner sut = await ClefSigner.Create(client); Assert.That(() => sut.SetSigner(Build.A.PrivateKey.TestObject), Throws.InstanceOf()); } diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Nethermind.Blockchain.Test.csproj b/src/Nethermind/Nethermind.Blockchain.Test/Nethermind.Blockchain.Test.csproj index a4aa0b53879..caa031ac836 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Nethermind.Blockchain.Test.csproj +++ b/src/Nethermind/Nethermind.Blockchain.Test/Nethermind.Blockchain.Test.csproj @@ -26,6 +26,7 @@ + diff --git a/src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs b/src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs index 2dc9a891343..e762f6d76e7 100644 --- a/src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs +++ b/src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs @@ -13,7 +13,9 @@ using Nethermind.Int256; using Nethermind.Logging; using Nethermind.Serialization.Rlp; +using NSubstitute; using NUnit.Framework; +using System.Threading.Tasks; using BlockTree = Nethermind.Blockchain.BlockTree; namespace Nethermind.Clique.Test @@ -90,6 +92,22 @@ public void Test_no_signer_data_at_epoch_fails(string blockRlp) Assert.True(validSeal); } + [TestCase(Block4Rlp)] + public async Task SealBlock_SignerCanSignHeader_FullHeaderIsUsedToSign(string blockRlp) + { + ISigner signer = Substitute.For(); + signer.CanSignHeader.Returns(true); + signer.CanSign.Returns(true); + signer.Address.Returns(new Address("0x7ffc57839b00206d1ad20c69a1981b489f772031")); + signer.Sign(Arg.Any()).Returns(new Signature(new byte[65])); + CliqueSealer sut = new CliqueSealer(signer, new CliqueConfig(), _snapshotManager, LimboLogs.Instance); + Block block = Rlp.Decode(new Rlp(Bytes.FromHexString(blockRlp))); + + await sut.SealBlock(block, System.Threading.CancellationToken.None); + + signer.Received().Sign(Arg.Any()); + } + public static Block GetGenesis() { Hash256 parentHash = Keccak.Zero; diff --git a/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs b/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs index 08804ed317a..882c807c5e9 100644 --- a/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs +++ b/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs @@ -7,9 +7,11 @@ using System.Threading.Tasks; using Nethermind.Core; using Nethermind.Core.Crypto; +using Nethermind.Core.Extensions; using Nethermind.Crypto; using Nethermind.JsonRpc; using Nethermind.Logging; +using Nethermind.Serialization.Rlp; [assembly: InternalsVisibleTo("Nethermind.Clique.Test")] @@ -64,12 +66,19 @@ public CliqueSealer(ISigner signer, ICliqueConfig config, ISnapshotManager snaps // Sign all the things! Hash256 headerHash = SnapshotManager.CalculateCliqueHeaderHash(header); - Signature signature; - if (_signer is ClefSigner clefSigner) - signature = clefSigner.SignCliqueHeader(SnapshotManager.CalculateCliqueRlp(header)); + if (_signer.CanSignHeader) + { + BlockHeader clone = header.Clone(); + int extraSeal = 65; + clone.ExtraData = clone.ExtraData.Slice(0, clone.ExtraData.Length - extraSeal); + clone.Hash = headerHash; + signature = _signer.Sign(clone); + } else + { signature = _signer.Sign(headerHash); + } // Copy signature bytes (R and S) byte[] signatureBytes = signature.Bytes; diff --git a/src/Nethermind/Nethermind.Consensus.Clique/SnapshotManager.cs b/src/Nethermind/Nethermind.Consensus.Clique/SnapshotManager.cs index 3a8a8e69991..de902c4840a 100644 --- a/src/Nethermind/Nethermind.Consensus.Clique/SnapshotManager.cs +++ b/src/Nethermind/Nethermind.Consensus.Clique/SnapshotManager.cs @@ -86,18 +86,6 @@ public static Hash256 CalculateCliqueHeaderHash(BlockHeader blockHeader) return sigHash; } - public static byte[] CalculateCliqueRlp(BlockHeader header) - { - int extraSeal = 65; - int shortExtraLength = header.ExtraData.Length - extraSeal; - byte[] fullExtraData = header.ExtraData; - byte[] shortExtraData = header.ExtraData.Slice(0, shortExtraLength); - header.ExtraData = shortExtraData; - byte[] rlp = _headerDecoder.Encode(header).Bytes; - header.ExtraData = fullExtraData; - return rlp; - } - private readonly object _snapshotCreationLock = new(); public ulong GetLastSignersCount() => _lastSignersCount; diff --git a/src/Nethermind/Nethermind.Consensus/ISigner.cs b/src/Nethermind/Nethermind.Consensus/ISigner.cs index 1174e68a1d0..a654bfe6a0a 100644 --- a/src/Nethermind/Nethermind.Consensus/ISigner.cs +++ b/src/Nethermind/Nethermind.Consensus/ISigner.cs @@ -5,6 +5,7 @@ using Nethermind.Core.Crypto; using Nethermind.Crypto; using Nethermind.TxPool; +using System; namespace Nethermind.Consensus { @@ -14,6 +15,8 @@ public interface ISigner : ITxSigner PrivateKey? Key { get; } Address Address { get; } Signature Sign(Hash256 message); + Signature Sign(BlockHeader header); bool CanSign { get; } + bool CanSignHeader { get; } } } diff --git a/src/Nethermind/Nethermind.Consensus/NullSigner.cs b/src/Nethermind/Nethermind.Consensus/NullSigner.cs index a6028d49dec..f4976cac687 100644 --- a/src/Nethermind/Nethermind.Consensus/NullSigner.cs +++ b/src/Nethermind/Nethermind.Consensus/NullSigner.cs @@ -22,8 +22,12 @@ public class NullSigner : ISigner, ISignerStore public PrivateKey? Key { get; } = null; + public bool CanSignHeader => false; + public void SetSigner(PrivateKey key) { } public void SetSigner(ProtectedPrivateKey key) { } + + public Signature Sign(BlockHeader header) { return new(new byte[65]); } } } diff --git a/src/Nethermind/Nethermind.Consensus/Signer.cs b/src/Nethermind/Nethermind.Consensus/Signer.cs index 3a48950a129..bf2a9820bc3 100644 --- a/src/Nethermind/Nethermind.Consensus/Signer.cs +++ b/src/Nethermind/Nethermind.Consensus/Signer.cs @@ -21,6 +21,8 @@ public class Signer : ISigner, ISignerStore public bool CanSign => _key is not null; + public bool CanSignHeader => false; + public Signer(ulong chainId, PrivateKey? key, ILogManager logManager) { _chainId = chainId; @@ -42,6 +44,11 @@ public Signature Sign(Hash256 message) return new Signature(rs, v); } + public Signature Sign(BlockHeader header) + { + return Sign(header.Hash); + } + public ValueTask Sign(Transaction tx) { Hash256 hash = Keccak.Compute(Rlp.Encode(tx, true, true, _chainId).Bytes); @@ -68,6 +75,6 @@ public void SetSigner(ProtectedPrivateKey? key) } SetSigner(pk); - } + } } } diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/ClefSigner.cs b/src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSigner.cs similarity index 63% rename from src/Nethermind/Nethermind.JsonRpc/Modules/ClefSigner.cs rename to src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSigner.cs index 2554a32ec54..b867e8ce993 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/ClefSigner.cs +++ b/src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSigner.cs @@ -1,45 +1,41 @@ // SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only +using DotNetty.Buffers; using Nethermind.Consensus; using Nethermind.Core; using Nethermind.Core.Crypto; using Nethermind.Core.Extensions; using Nethermind.Crypto; -using Nethermind.Evm.Tracing.GethStyle.JavaScript; using Nethermind.JsonRpc.Client; -using Nethermind.JsonRpc.Data; using Nethermind.Serialization.Rlp; -using System; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; namespace Nethermind.JsonRpc; public class ClefSigner : ISigner, ISignerStore { private readonly IJsonRpcClient rpcClient; - private readonly ulong _chainId; + private HeaderDecoder _headerDecoder; - private ClefSigner(IJsonRpcClient rpcClient, ulong chainId) + private ClefSigner(IJsonRpcClient rpcClient, Address author) { this.rpcClient = rpcClient; - this._chainId = chainId; - CanSign = true; + Address = author; + _headerDecoder = new HeaderDecoder(); } - public static async Task Create(IJsonRpcClient jsonRpcClient, ulong chainId, Address? blockAuthorAccount = null) + public static async Task Create(IJsonRpcClient jsonRpcClient, Address? blockAuthorAccount = null) { - ClefSigner signer = new(jsonRpcClient, chainId); - await signer.SetSignerAddress(blockAuthorAccount); + ClefSigner signer = new(jsonRpcClient, await GetSignerAddress(jsonRpcClient, blockAuthorAccount)); return signer; } public Address Address { get; private set; } - public bool CanSign { get; } + public bool CanSign => true; + + public bool CanSignHeader => true; public PrivateKey? Key => throw new InvalidOperationException("Cannot get private keys from remote signer."); @@ -68,45 +64,57 @@ public Signature Sign(Hash256 message) /// /// Full Rlp of the clique header. /// of the hash of the clique header. - public Signature SignCliqueHeader(byte[] rlpHeader) + public Signature Sign(BlockHeader header) { - var signed = rpcClient.Post( - "account_signData", - "application/x-clique-header", - Address.ToString(), - rlpHeader.ToHexString(true)).GetAwaiter().GetResult(); - if (signed == null) - ThrowInvalidOperationSignFailed(); - var bytes = Bytes.FromHexString(signed); - - //Clef will set recid to 0/1, but we expect it to be 27/28 - if (bytes.Length == 65 && bytes[64] == 0 || bytes[64] == 1) - //We expect V to be 27/28 - bytes[64] += 27; - - return new Signature(bytes); + if (header is null) throw new ArgumentNullException(nameof(header)); + int contentLength = _headerDecoder.GetLength(header, RlpBehaviors.None); + IByteBuffer buffer = PooledByteBufferAllocator.Default.Buffer(contentLength); + try + { + RlpStream rlpStream = new NettyRlpStream(buffer); + rlpStream.Encode(header); + string? signed = rpcClient.Post( + "account_signData", + "application/x-clique-header", + Address.ToString(), + buffer.AsSpan().ToHexString(true)).GetAwaiter().GetResult(); + if (signed == null) + ThrowInvalidOperationSignFailed(); + byte[] bytes = Bytes.FromHexString(signed); + + //Clef will set recid to 0/1, but we expect it to be 27/28 + if (bytes.Length == 65 && bytes[64] == 0 || bytes[64] == 1) + //We expect V to be 27/28 + bytes[64] += 27; + + return new Signature(bytes); + } + finally + { + buffer.Release(); + } } public ValueTask Sign(Transaction tx) => throw new NotImplementedException("Remote signing of transactions is not supported."); - private async Task SetSignerAddress(Address? blockAuthorAccount) + private async static Task
GetSignerAddress(IJsonRpcClient rpcClient, Address? blockAuthorAccount) { var accounts = await rpcClient.Post("account_list"); + if (accounts is null) + throw new InvalidOperationException("Remote signer 'account_list' response is invalid."); if (!accounts.Any()) - { throw new InvalidOperationException("Remote signer has not been configured with any signers."); - } if (blockAuthorAccount != null) { if (accounts.Any(a => new Address(a).Bytes.SequenceEqual(blockAuthorAccount.Bytes))) - Address = blockAuthorAccount; + return blockAuthorAccount; else throw new InvalidOperationException($"Remote signer cannot sign for {blockAuthorAccount}."); } else { - Address = new Address(accounts[0]); + return new Address(accounts[0]); } } @@ -129,13 +137,6 @@ private static void ThrowInvalidOperationSignFailed() => [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void ThrowInvalidOperationSetSigner() => throw new InvalidOperationException("Cannot set a signer when using a remote signer."); - - - private class RemoteTxSignResponse - { - public string Raw { get; set; } - public TransactionForRpc Tx { get; set; } - } } diff --git a/src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSignerPlugin.cs b/src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSignerPlugin.cs new file mode 100644 index 00000000000..19daea61b1d --- /dev/null +++ b/src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSignerPlugin.cs @@ -0,0 +1,80 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using Nethermind.Api; +using Nethermind.Api.Extensions; +using Nethermind.Core; +using Nethermind.JsonRpc.Client; +using Nethermind.JsonRpc; +using Nethermind.Network; +using Nethermind.Consensus; +using Nethermind.KeyStore.Config; +using System.Configuration; + +namespace Nethermind.ExternalSigner.Plugin; + +public class ClefSignerPlugin : INethermindPlugin +{ + private INethermindApi? _nethermindApi; + + public string Name => "Clef signer"; + + public string Description => "Enabled signing from a remote Clef instance over Json RPC."; + + public string Author => "Nethermind"; + + public ValueTask DisposeAsync() + { + return ValueTask.CompletedTask; + } + + public async Task Init(INethermindApi nethermindApi) + { + _nethermindApi = nethermindApi ?? throw new ArgumentNullException(nameof(nethermindApi)); + + if (_nethermindApi == null) + throw new InvalidOperationException("Init() must be called first."); + + IMiningConfig miningConfig = _nethermindApi.Config(); + if (miningConfig.Enabled) + { + if (!string.IsNullOrEmpty(miningConfig.Signer)) + { + Uri? uri; + if (!Uri.TryCreate(miningConfig.Signer, UriKind.Absolute, out uri)) + { + throw new ConfigurationErrorsException($"{miningConfig.Signer} must have be a valid uri."); + } + ClefSigner signer = + await SetupExternalSigner(uri, _nethermindApi.Config().BlockAuthorAccount); + _nethermindApi.EngineSigner = signer; + } + } + + } + + public Task InitNetworkProtocol() + { + return Task.CompletedTask; + } + + public Task InitRpcModules() + { + return Task.CompletedTask; + } + + private async Task SetupExternalSigner(Uri urlSigner, string blockAuthorAccount) + { + try + { + Address? address = string.IsNullOrEmpty(blockAuthorAccount) ? null : new Address(blockAuthorAccount); + BasicJsonRpcClient rpcClient = new(urlSigner, _nethermindApi!.EthereumJsonSerializer, _nethermindApi.LogManager, TimeSpan.FromSeconds(10)); + _nethermindApi.DisposeStack.Push(rpcClient); + return await ClefSigner.Create(rpcClient, address); + } + catch (HttpRequestException e) + { + throw new NetworkingException($"Remote signer at {urlSigner} did not respond.", NetworkExceptionType.TargetUnreachable, e); + } + } +} diff --git a/src/Nethermind/Nethermind.ExternalSigner.Plugin/Nethermind.ExternalSigner.Plugin.csproj b/src/Nethermind/Nethermind.ExternalSigner.Plugin/Nethermind.ExternalSigner.Plugin.csproj new file mode 100644 index 00000000000..a4b5d385bb7 --- /dev/null +++ b/src/Nethermind/Nethermind.ExternalSigner.Plugin/Nethermind.ExternalSigner.Plugin.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs index de527c7dec0..021924c55dc 100644 --- a/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs +++ b/src/Nethermind/Nethermind.Init/Steps/InitializeBlockTree.cs @@ -1,9 +1,7 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only -using System; using System.IO; -using System.Net.Http; using System.Threading; using System.Threading.Tasks; using Nethermind.Api; @@ -17,10 +15,6 @@ using Nethermind.Core; using Nethermind.Db; using Nethermind.Db.Blooms; -using Nethermind.JsonRpc; -using Nethermind.JsonRpc.Client; -using Nethermind.KeyStore.Config; -using Nethermind.Network; using Nethermind.Serialization.Rlp; using Nethermind.State.Repositories; @@ -37,7 +31,7 @@ public InitializeBlockTree(INethermindApi api) (_get, _set) = api.ForInit; } - public async Task Execute(CancellationToken cancellationToken) + public Task Execute(CancellationToken cancellationToken) { IInitConfig initConfig = _get.Config(); IBloomConfig bloomConfig = _get.Config(); @@ -74,22 +68,11 @@ public async Task Execute(CancellationToken cancellationToken) ISigner signer = NullSigner.Instance; ISignerStore signerStore = NullSigner.Instance; - IMiningConfig miningConfig = _get.Config(); - if (miningConfig.Enabled) + if (_get.Config().Enabled) { - if (!string.IsNullOrEmpty(miningConfig.Signer)) - { - ClefSigner signerAndStore = - await SetupExternalSigner(miningConfig.Signer, _get.SpecProvider!.ChainId, _get.Config().BlockAuthorAccount); - signer = signerAndStore; - signerStore = signerAndStore; - } - else - { - Signer signerAndStore = new Signer(_get.SpecProvider!.ChainId, _get.OriginalSignerKey!, _get.LogManager); - signer = signerAndStore; - signerStore = signerAndStore; - } + Signer signerAndStore = new(_get.SpecProvider!.ChainId, _get.OriginalSignerKey!, _get.LogManager); + signer = signerAndStore; + signerStore = signerAndStore; } _set.EngineSigner = signer; @@ -126,21 +109,7 @@ public async Task Execute(CancellationToken cancellationToken) new ExitOnBlockNumberHandler(blockTree, _get.ProcessExit!, initConfig.ExitOnBlockNumber.Value, _get.LogManager); } - } - - private async Task SetupExternalSigner(string urlSigner, ulong chainId, string blockAuthorAccount) - { - try - { - Address? address = string.IsNullOrEmpty(blockAuthorAccount) ? null : new Address(blockAuthorAccount); - BasicJsonRpcClient rpcClient = new(new Uri(urlSigner), _get.EthereumJsonSerializer, _get.LogManager, TimeSpan.FromSeconds(10)); - _get.DisposeStack.Push(rpcClient); - return await ClefSigner.Create(rpcClient, chainId, address); - } - catch (HttpRequestException e) - { - throw new NetworkingException($"Remote signer at {urlSigner} did not respond.", NetworkExceptionType.TargetUnreachable, e); - } + return Task.CompletedTask; } } } diff --git a/src/Nethermind/Nethermind.Mev.Test/TestMevSigner.cs b/src/Nethermind/Nethermind.Mev.Test/TestMevSigner.cs index 45447315c9d..4c61258f97f 100644 --- a/src/Nethermind/Nethermind.Mev.Test/TestMevSigner.cs +++ b/src/Nethermind/Nethermind.Mev.Test/TestMevSigner.cs @@ -24,6 +24,10 @@ public TestMevSigner(Address blockAuthorAddress) public Signature Sign(Hash256 message) => null!; + public Signature Sign(BlockHeader header) => null!; + public bool CanSign => true; + + public bool CanSignHeader => true; } } diff --git a/src/Nethermind/Nethermind.Runner/Nethermind.Runner.csproj b/src/Nethermind/Nethermind.Runner/Nethermind.Runner.csproj index 93fe2428b3a..8dbf12742da 100644 --- a/src/Nethermind/Nethermind.Runner/Nethermind.Runner.csproj +++ b/src/Nethermind/Nethermind.Runner/Nethermind.Runner.csproj @@ -38,6 +38,7 @@ + @@ -85,11 +86,11 @@ - - + + - - + + diff --git a/src/Nethermind/Nethermind.sln b/src/Nethermind/Nethermind.sln index 005f6c46d3f..3e4f9c25d2d 100644 --- a/src/Nethermind/Nethermind.sln +++ b/src/Nethermind/Nethermind.sln @@ -224,7 +224,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution nuget.config = nuget.config EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nethermind.JsonRpc.Clients", "Nethermind.JsonRpc.Connectors\Nethermind.JsonRpc.Clients.csproj", "{513049F7-B0AD-4FB5-9223-C3B0237FD3B0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nethermind.JsonRpc.Clients", "Nethermind.JsonRpc.Connectors\Nethermind.JsonRpc.Clients.csproj", "{513049F7-B0AD-4FB5-9223-C3B0237FD3B0}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Signer", "Signer", "{89311B58-AF36-4956-883D-54531BC1D5A3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nethermind.ExternalSigner.Plugin", "Nethermind.ExternalSigner.Plugin\Nethermind.ExternalSigner.Plugin.csproj", "{6528010D-7DCE-4935-9785-5270FF515F3E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -620,6 +624,10 @@ Global {513049F7-B0AD-4FB5-9223-C3B0237FD3B0}.Debug|Any CPU.Build.0 = Debug|Any CPU {513049F7-B0AD-4FB5-9223-C3B0237FD3B0}.Release|Any CPU.ActiveCfg = Release|Any CPU {513049F7-B0AD-4FB5-9223-C3B0237FD3B0}.Release|Any CPU.Build.0 = Release|Any CPU + {6528010D-7DCE-4935-9785-5270FF515F3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6528010D-7DCE-4935-9785-5270FF515F3E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6528010D-7DCE-4935-9785-5270FF515F3E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6528010D-7DCE-4935-9785-5270FF515F3E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -684,6 +692,8 @@ Global {2EDE2554-59C0-4E78-92F7-EB8077AA597D} = {78BED57D-720E-4E6C-ABA2-397B73B494F9} {48E50409-26FE-4FD8-AF6E-2A0E79F794CE} = {2EDE2554-59C0-4E78-92F7-EB8077AA597D} {E1E7BEFC-52C0-49ED-B0A7-CB8C3250D120} = {4019B82F-1104-4D2C-9F96-05FD7D3575E8} + {89311B58-AF36-4956-883D-54531BC1D5A3} = {78BED57D-720E-4E6C-ABA2-397B73B494F9} + {6528010D-7DCE-4935-9785-5270FF515F3E} = {89311B58-AF36-4956-883D-54531BC1D5A3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {092CA5E3-6180-4ED7-A3CB-9B57FAC2AA85} From d06892a25183c003dddd1b5ff241537637891c45 Mon Sep 17 00:00:00 2001 From: ak88 Date: Mon, 25 Mar 2024 14:04:15 +0100 Subject: [PATCH 22/27] format whitespace --- src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs | 2 +- src/Nethermind/Nethermind.Consensus/Signer.cs | 2 +- src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSigner.cs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs b/src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs index e762f6d76e7..861e2471696 100644 --- a/src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs +++ b/src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs @@ -95,7 +95,7 @@ public void Test_no_signer_data_at_epoch_fails(string blockRlp) [TestCase(Block4Rlp)] public async Task SealBlock_SignerCanSignHeader_FullHeaderIsUsedToSign(string blockRlp) { - ISigner signer = Substitute.For(); + ISigner signer = Substitute.For(); signer.CanSignHeader.Returns(true); signer.CanSign.Returns(true); signer.Address.Returns(new Address("0x7ffc57839b00206d1ad20c69a1981b489f772031")); diff --git a/src/Nethermind/Nethermind.Consensus/Signer.cs b/src/Nethermind/Nethermind.Consensus/Signer.cs index bf2a9820bc3..0a22c939499 100644 --- a/src/Nethermind/Nethermind.Consensus/Signer.cs +++ b/src/Nethermind/Nethermind.Consensus/Signer.cs @@ -75,6 +75,6 @@ public void SetSigner(ProtectedPrivateKey? key) } SetSigner(pk); - } + } } } diff --git a/src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSigner.cs b/src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSigner.cs index b867e8ce993..4044ff37ae0 100644 --- a/src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSigner.cs +++ b/src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSigner.cs @@ -67,12 +67,12 @@ public Signature Sign(Hash256 message) public Signature Sign(BlockHeader header) { if (header is null) throw new ArgumentNullException(nameof(header)); - int contentLength = _headerDecoder.GetLength(header, RlpBehaviors.None); + int contentLength = _headerDecoder.GetLength(header, RlpBehaviors.None); IByteBuffer buffer = PooledByteBufferAllocator.Default.Buffer(contentLength); try { RlpStream rlpStream = new NettyRlpStream(buffer); - rlpStream.Encode(header); + rlpStream.Encode(header); string? signed = rpcClient.Post( "account_signData", "application/x-clique-header", From 18f01ef46647e9cb441b5be41a65e7d740be0bcf Mon Sep 17 00:00:00 2001 From: ak88 Date: Fri, 12 Apr 2024 13:37:52 +0200 Subject: [PATCH 23/27] Update src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs Co-authored-by: Lukasz Rozmej --- .../Client/BasicJsonRpcClient.cs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs b/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs index cb1f19e16e0..70c18af6be2 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs @@ -110,22 +110,9 @@ private void AddAuthorizationHeader() private static string Base64Encode(string plainText) => Convert.ToBase64String(Encoding.UTF8.GetBytes(plainText)); - protected virtual void Dispose(bool disposing) + protected virtual void Dispose() { - if (!disposedValue) - { - if (disposing) - { - _client?.Dispose(); - } - disposedValue = true; - } - } - - public void Dispose() - { - Dispose(disposing: true); - GC.SuppressFinalize(this); + _client.Dispose(); } } } From ece7b6f0c4b8dd77bb7e78f97fa4dd7cd9aa3175 Mon Sep 17 00:00:00 2001 From: ak88 Date: Fri, 12 Apr 2024 14:52:20 +0200 Subject: [PATCH 24/27] code review comments --- .../Nethermind.Clique.Test/CliqueTests.cs | 2 +- .../CliqueSealer.cs | 4 +-- .../Nethermind.Consensus/IHeaderSigner.cs | 12 ++++++++ .../Nethermind.Consensus/ISigner.cs | 2 -- .../ClefSigner.cs | 12 ++++---- .../Client/BasicJsonRpcClient.cs | 29 ++++++------------- 6 files changed, 29 insertions(+), 32 deletions(-) create mode 100644 src/Nethermind/Nethermind.Consensus/IHeaderSigner.cs diff --git a/src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs b/src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs index 861e2471696..b2a38dbd0c5 100644 --- a/src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs +++ b/src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs @@ -95,7 +95,7 @@ public void Test_no_signer_data_at_epoch_fails(string blockRlp) [TestCase(Block4Rlp)] public async Task SealBlock_SignerCanSignHeader_FullHeaderIsUsedToSign(string blockRlp) { - ISigner signer = Substitute.For(); + IHeaderSigner signer = Substitute.For(); signer.CanSignHeader.Returns(true); signer.CanSign.Returns(true); signer.Address.Returns(new Address("0x7ffc57839b00206d1ad20c69a1981b489f772031")); diff --git a/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs b/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs index 882c807c5e9..ca298e352c0 100644 --- a/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs +++ b/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs @@ -67,13 +67,13 @@ public CliqueSealer(ISigner signer, ICliqueConfig config, ISnapshotManager snaps // Sign all the things! Hash256 headerHash = SnapshotManager.CalculateCliqueHeaderHash(header); Signature signature; - if (_signer.CanSignHeader) + if (_signer is IHeaderSigner headerSigner) { BlockHeader clone = header.Clone(); int extraSeal = 65; clone.ExtraData = clone.ExtraData.Slice(0, clone.ExtraData.Length - extraSeal); clone.Hash = headerHash; - signature = _signer.Sign(clone); + signature = headerSigner.Sign(clone); } else { diff --git a/src/Nethermind/Nethermind.Consensus/IHeaderSigner.cs b/src/Nethermind/Nethermind.Consensus/IHeaderSigner.cs new file mode 100644 index 00000000000..d1749d0d400 --- /dev/null +++ b/src/Nethermind/Nethermind.Consensus/IHeaderSigner.cs @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using Nethermind.Core; +using Nethermind.Core.Crypto; + +namespace Nethermind.Consensus; +public interface IHeaderSigner:ISigner +{ + bool CanSignHeader { get; } + Signature Sign(BlockHeader header); +} diff --git a/src/Nethermind/Nethermind.Consensus/ISigner.cs b/src/Nethermind/Nethermind.Consensus/ISigner.cs index a654bfe6a0a..ec34eafa187 100644 --- a/src/Nethermind/Nethermind.Consensus/ISigner.cs +++ b/src/Nethermind/Nethermind.Consensus/ISigner.cs @@ -15,8 +15,6 @@ public interface ISigner : ITxSigner PrivateKey? Key { get; } Address Address { get; } Signature Sign(Hash256 message); - Signature Sign(BlockHeader header); bool CanSign { get; } - bool CanSignHeader { get; } } } diff --git a/src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSigner.cs b/src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSigner.cs index 4044ff37ae0..dfeaaf7a0df 100644 --- a/src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSigner.cs +++ b/src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSigner.cs @@ -13,7 +13,7 @@ using System.Runtime.CompilerServices; namespace Nethermind.JsonRpc; -public class ClefSigner : ISigner, ISignerStore +public class ClefSigner : IHeaderSigner, ISignerStore { private readonly IJsonRpcClient rpcClient; private HeaderDecoder _headerDecoder; @@ -78,15 +78,13 @@ public Signature Sign(BlockHeader header) "application/x-clique-header", Address.ToString(), buffer.AsSpan().ToHexString(true)).GetAwaiter().GetResult(); - if (signed == null) + if (signed is null) ThrowInvalidOperationSignFailed(); byte[] bytes = Bytes.FromHexString(signed); - //Clef will set recid to 0/1, but we expect it to be 27/28 - if (bytes.Length == 65 && bytes[64] == 0 || bytes[64] == 1) - //We expect V to be 27/28 - bytes[64] += 27; - + //Clef will set recid to 0/1, without the VOffset + if (bytes.Length == 65 && (bytes[64] == 0 || bytes[64] == 1)) + return new Signature(bytes.AsSpan(0,64), bytes[64]); return new Signature(bytes); } finally diff --git a/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs b/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs index 70c18af6be2..6a9de6225fa 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs @@ -15,7 +15,6 @@ public class BasicJsonRpcClient : IJsonRpcClient, IDisposable private readonly HttpClient _client; private readonly IJsonSerializer _jsonSerializer; private readonly ILogger _logger; - private bool disposedValue; public BasicJsonRpcClient(Uri uri, IJsonSerializer jsonSerializer, ILogManager logManager) : this(uri, jsonSerializer, logManager, /*support long block traces better, default 100s might be too small*/ TimeSpan.FromMinutes(5)) @@ -58,25 +57,15 @@ public async Task Post(string method, params object[] parameters) return jsonResponse.Result; } - catch (NotSupportedException) + catch (Exception e) when + ( + e is not TaskCanceledException && + e is not HttpRequestException && + e is not NotImplementedException&& + e is not NotSupportedException + ) { - throw; - } - catch (NotImplementedException) - { - throw; - } - catch (HttpRequestException) - { - throw; - } - catch (TaskCanceledException) - { - throw; - } - catch (Exception) - { - throw new DataException($"Cannot deserialize {responseString}"); + throw new DataException($"Cannot deserialize {responseString}", e); } } @@ -110,7 +99,7 @@ private void AddAuthorizationHeader() private static string Base64Encode(string plainText) => Convert.ToBase64String(Encoding.UTF8.GetBytes(plainText)); - protected virtual void Dispose() + public virtual void Dispose() { _client.Dispose(); } From 821117fbfbd85f5496add21b490c02e18c205f10 Mon Sep 17 00:00:00 2001 From: ak88 Date: Fri, 12 Apr 2024 14:54:24 +0200 Subject: [PATCH 25/27] format whitespace --- src/Nethermind/Nethermind.Consensus/IHeaderSigner.cs | 2 +- .../Nethermind.ExternalSigner.Plugin/ClefSigner.cs | 2 +- .../Client/BasicJsonRpcClient.cs | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/IHeaderSigner.cs b/src/Nethermind/Nethermind.Consensus/IHeaderSigner.cs index d1749d0d400..a51b1ca800a 100644 --- a/src/Nethermind/Nethermind.Consensus/IHeaderSigner.cs +++ b/src/Nethermind/Nethermind.Consensus/IHeaderSigner.cs @@ -5,7 +5,7 @@ using Nethermind.Core.Crypto; namespace Nethermind.Consensus; -public interface IHeaderSigner:ISigner +public interface IHeaderSigner : ISigner { bool CanSignHeader { get; } Signature Sign(BlockHeader header); diff --git a/src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSigner.cs b/src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSigner.cs index dfeaaf7a0df..16b5c8c0026 100644 --- a/src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSigner.cs +++ b/src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSigner.cs @@ -84,7 +84,7 @@ public Signature Sign(BlockHeader header) //Clef will set recid to 0/1, without the VOffset if (bytes.Length == 65 && (bytes[64] == 0 || bytes[64] == 1)) - return new Signature(bytes.AsSpan(0,64), bytes[64]); + return new Signature(bytes.AsSpan(0, 64), bytes[64]); return new Signature(bytes); } finally diff --git a/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs b/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs index 6a9de6225fa..a96d834bb16 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs @@ -59,9 +59,9 @@ public async Task Post(string method, params object[] parameters) } catch (Exception e) when ( - e is not TaskCanceledException && - e is not HttpRequestException && - e is not NotImplementedException&& + e is not TaskCanceledException && + e is not HttpRequestException && + e is not NotImplementedException && e is not NotSupportedException ) { @@ -101,7 +101,7 @@ private static string Base64Encode(string plainText) public virtual void Dispose() { - _client.Dispose(); + _client.Dispose(); } } } From 8d07596eabc940e830695e9488ee6b3d5de78050 Mon Sep 17 00:00:00 2001 From: ak88 Date: Fri, 12 Apr 2024 15:15:44 +0200 Subject: [PATCH 26/27] removed Nethermind.JsonRpc.Clients.csproj --- .../Nethermind.Consensus.Clique/CliqueSealer.cs | 3 +-- .../Nethermind.Consensus.Clique/SnapshotManager.cs | 12 ++++++++---- .../Nethermind.Consensus.csproj | 1 - .../Nethermind.ExternalSigner.Plugin.csproj | 1 + .../Nethermind.JsonRpc.Clients.csproj | 14 -------------- .../Client/BasicJsonRpcClient.cs | 4 ++++ .../Client/IJsonRpcClient.cs | 0 .../Client/JsonRpcResponse.cs | 0 .../Error.cs | 0 .../Nethermind.JsonRpc/Nethermind.JsonRpc.csproj | 1 - src/Nethermind/Nethermind.sln | 8 +------- 11 files changed, 15 insertions(+), 29 deletions(-) delete mode 100644 src/Nethermind/Nethermind.JsonRpc.Connectors/Nethermind.JsonRpc.Clients.csproj rename src/Nethermind/{Nethermind.JsonRpc.Connectors => Nethermind.JsonRpc}/Client/BasicJsonRpcClient.cs (97%) rename src/Nethermind/{Nethermind.JsonRpc.Connectors => Nethermind.JsonRpc}/Client/IJsonRpcClient.cs (100%) rename src/Nethermind/{Nethermind.JsonRpc.Connectors => Nethermind.JsonRpc}/Client/JsonRpcResponse.cs (100%) rename src/Nethermind/{Nethermind.JsonRpc.Connectors => Nethermind.JsonRpc}/Error.cs (100%) diff --git a/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs b/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs index ca298e352c0..2e47118d42e 100644 --- a/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs +++ b/src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs @@ -70,8 +70,7 @@ public CliqueSealer(ISigner signer, ICliqueConfig config, ISnapshotManager snaps if (_signer is IHeaderSigner headerSigner) { BlockHeader clone = header.Clone(); - int extraSeal = 65; - clone.ExtraData = clone.ExtraData.Slice(0, clone.ExtraData.Length - extraSeal); + clone.ExtraData = SnapshotManager.SliceExtraSealFromExtraData(clone.ExtraData); clone.Hash = headerHash; signature = headerSigner.Sign(clone); } diff --git a/src/Nethermind/Nethermind.Consensus.Clique/SnapshotManager.cs b/src/Nethermind/Nethermind.Consensus.Clique/SnapshotManager.cs index de902c4840a..0e25a7559fd 100644 --- a/src/Nethermind/Nethermind.Consensus.Clique/SnapshotManager.cs +++ b/src/Nethermind/Nethermind.Consensus.Clique/SnapshotManager.cs @@ -31,7 +31,6 @@ public class SnapshotManager : ISnapshotManager private readonly IDb _blocksDb; private ulong _lastSignersCount = 0; private readonly LruCache _snapshotCache = new(Clique.InMemorySnapshots, "clique snapshots"); - private static readonly HeaderDecoder _headerDecoder = new HeaderDecoder(); public SnapshotManager(ICliqueConfig cliqueConfig, IDb blocksDb, IBlockTree blockTree, IEthereumEcdsa ecdsa, ILogManager logManager) { @@ -76,16 +75,21 @@ private int CalculateSignersCount(BlockHeader blockHeader) public static Hash256 CalculateCliqueHeaderHash(BlockHeader blockHeader) { - int extraSeal = 65; - int shortExtraLength = blockHeader.ExtraData.Length - extraSeal; byte[] fullExtraData = blockHeader.ExtraData; - byte[] shortExtraData = blockHeader.ExtraData.Slice(0, shortExtraLength); + byte[] shortExtraData = SliceExtraSealFromExtraData(blockHeader.ExtraData); blockHeader.ExtraData = shortExtraData; Hash256 sigHash = blockHeader.CalculateHash(); blockHeader.ExtraData = fullExtraData; return sigHash; } + public static byte[] SliceExtraSealFromExtraData(byte[] extraData) + { + if (extraData.Length < Clique.ExtraSealLength) + new ArgumentException($"Cannot be less than extra seal length ({Clique.ExtraSealLength}).", nameof(extraData)); + return extraData.Slice(0, extraData.Length - Clique.ExtraSealLength); + } + private readonly object _snapshotCreationLock = new(); public ulong GetLastSignersCount() => _lastSignersCount; diff --git a/src/Nethermind/Nethermind.Consensus/Nethermind.Consensus.csproj b/src/Nethermind/Nethermind.Consensus/Nethermind.Consensus.csproj index 07227f9da94..b5c11b8078e 100644 --- a/src/Nethermind/Nethermind.Consensus/Nethermind.Consensus.csproj +++ b/src/Nethermind/Nethermind.Consensus/Nethermind.Consensus.csproj @@ -10,7 +10,6 @@ - diff --git a/src/Nethermind/Nethermind.ExternalSigner.Plugin/Nethermind.ExternalSigner.Plugin.csproj b/src/Nethermind/Nethermind.ExternalSigner.Plugin/Nethermind.ExternalSigner.Plugin.csproj index a4b5d385bb7..31ecca4eede 100644 --- a/src/Nethermind/Nethermind.ExternalSigner.Plugin/Nethermind.ExternalSigner.Plugin.csproj +++ b/src/Nethermind/Nethermind.ExternalSigner.Plugin/Nethermind.ExternalSigner.Plugin.csproj @@ -8,6 +8,7 @@ + diff --git a/src/Nethermind/Nethermind.JsonRpc.Connectors/Nethermind.JsonRpc.Clients.csproj b/src/Nethermind/Nethermind.JsonRpc.Connectors/Nethermind.JsonRpc.Clients.csproj deleted file mode 100644 index 521306775f9..00000000000 --- a/src/Nethermind/Nethermind.JsonRpc.Connectors/Nethermind.JsonRpc.Clients.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - net8.0 - enable - annotations - - - - - - - - diff --git a/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs b/src/Nethermind/Nethermind.JsonRpc/Client/BasicJsonRpcClient.cs similarity index 97% rename from src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs rename to src/Nethermind/Nethermind.JsonRpc/Client/BasicJsonRpcClient.cs index a96d834bb16..a75fca723c2 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/BasicJsonRpcClient.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Client/BasicJsonRpcClient.cs @@ -2,9 +2,13 @@ // SPDX-License-Identifier: LGPL-3.0-only using System; +using System.Collections.Generic; using System.Data; +using System.Linq; +using System.Net.Http; using System.Net.Http.Headers; using System.Text; +using System.Threading.Tasks; using Nethermind.Logging; using Nethermind.Serialization.Json; diff --git a/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/IJsonRpcClient.cs b/src/Nethermind/Nethermind.JsonRpc/Client/IJsonRpcClient.cs similarity index 100% rename from src/Nethermind/Nethermind.JsonRpc.Connectors/Client/IJsonRpcClient.cs rename to src/Nethermind/Nethermind.JsonRpc/Client/IJsonRpcClient.cs diff --git a/src/Nethermind/Nethermind.JsonRpc.Connectors/Client/JsonRpcResponse.cs b/src/Nethermind/Nethermind.JsonRpc/Client/JsonRpcResponse.cs similarity index 100% rename from src/Nethermind/Nethermind.JsonRpc.Connectors/Client/JsonRpcResponse.cs rename to src/Nethermind/Nethermind.JsonRpc/Client/JsonRpcResponse.cs diff --git a/src/Nethermind/Nethermind.JsonRpc.Connectors/Error.cs b/src/Nethermind/Nethermind.JsonRpc/Error.cs similarity index 100% rename from src/Nethermind/Nethermind.JsonRpc.Connectors/Error.cs rename to src/Nethermind/Nethermind.JsonRpc/Error.cs diff --git a/src/Nethermind/Nethermind.JsonRpc/Nethermind.JsonRpc.csproj b/src/Nethermind/Nethermind.JsonRpc/Nethermind.JsonRpc.csproj index 7b0c0ba9d27..a7900f361f1 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Nethermind.JsonRpc.csproj +++ b/src/Nethermind/Nethermind.JsonRpc/Nethermind.JsonRpc.csproj @@ -16,7 +16,6 @@ - diff --git a/src/Nethermind/Nethermind.sln b/src/Nethermind/Nethermind.sln index 3e4f9c25d2d..c5b17d28c4d 100644 --- a/src/Nethermind/Nethermind.sln +++ b/src/Nethermind/Nethermind.sln @@ -224,11 +224,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution nuget.config = nuget.config EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nethermind.JsonRpc.Clients", "Nethermind.JsonRpc.Connectors\Nethermind.JsonRpc.Clients.csproj", "{513049F7-B0AD-4FB5-9223-C3B0237FD3B0}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Signer", "Signer", "{89311B58-AF36-4956-883D-54531BC1D5A3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nethermind.ExternalSigner.Plugin", "Nethermind.ExternalSigner.Plugin\Nethermind.ExternalSigner.Plugin.csproj", "{6528010D-7DCE-4935-9785-5270FF515F3E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nethermind.ExternalSigner.Plugin", "Nethermind.ExternalSigner.Plugin\Nethermind.ExternalSigner.Plugin.csproj", "{6528010D-7DCE-4935-9785-5270FF515F3E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -620,10 +618,6 @@ Global {AD09FBCB-5496-499B-9129-B6D139A65B6F}.Debug|Any CPU.Build.0 = Debug|Any CPU {AD09FBCB-5496-499B-9129-B6D139A65B6F}.Release|Any CPU.ActiveCfg = Release|Any CPU {AD09FBCB-5496-499B-9129-B6D139A65B6F}.Release|Any CPU.Build.0 = Release|Any CPU - {513049F7-B0AD-4FB5-9223-C3B0237FD3B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {513049F7-B0AD-4FB5-9223-C3B0237FD3B0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {513049F7-B0AD-4FB5-9223-C3B0237FD3B0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {513049F7-B0AD-4FB5-9223-C3B0237FD3B0}.Release|Any CPU.Build.0 = Release|Any CPU {6528010D-7DCE-4935-9785-5270FF515F3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6528010D-7DCE-4935-9785-5270FF515F3E}.Debug|Any CPU.Build.0 = Debug|Any CPU {6528010D-7DCE-4935-9785-5270FF515F3E}.Release|Any CPU.ActiveCfg = Release|Any CPU From 206a61b9e7344edc4424d3ba05b450790c60f021 Mon Sep 17 00:00:00 2001 From: ak88 Date: Mon, 15 Apr 2024 16:09:52 +0200 Subject: [PATCH 27/27] one more unittest --- .../Nethermind.Clique.Test/CliqueTests.cs | 15 +++++++++++++++ .../Nethermind.Mev.Test/TestMevSigner.cs | 4 ---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs b/src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs index b2a38dbd0c5..a4b401808e4 100644 --- a/src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs +++ b/src/Nethermind/Nethermind.Clique.Test/CliqueTests.cs @@ -108,6 +108,21 @@ public async Task SealBlock_SignerCanSignHeader_FullHeaderIsUsedToSign(string bl signer.Received().Sign(Arg.Any()); } + [TestCase(Block4Rlp)] + public async Task SealBlock_SignerCannotSignHeader_HashIsUsedToSign(string blockRlp) + { + ISigner signer = Substitute.For(); + signer.CanSign.Returns(true); + signer.Address.Returns(new Address("0x7ffc57839b00206d1ad20c69a1981b489f772031")); + signer.Sign(Arg.Any()).Returns(new Signature(new byte[65])); + CliqueSealer sut = new CliqueSealer(signer, new CliqueConfig(), _snapshotManager, LimboLogs.Instance); + Block block = Rlp.Decode(new Rlp(Bytes.FromHexString(blockRlp))); + + await sut.SealBlock(block, System.Threading.CancellationToken.None); + + signer.Received().Sign(Arg.Any()); + } + public static Block GetGenesis() { Hash256 parentHash = Keccak.Zero; diff --git a/src/Nethermind/Nethermind.Mev.Test/TestMevSigner.cs b/src/Nethermind/Nethermind.Mev.Test/TestMevSigner.cs index 4c61258f97f..45447315c9d 100644 --- a/src/Nethermind/Nethermind.Mev.Test/TestMevSigner.cs +++ b/src/Nethermind/Nethermind.Mev.Test/TestMevSigner.cs @@ -24,10 +24,6 @@ public TestMevSigner(Address blockAuthorAddress) public Signature Sign(Hash256 message) => null!; - public Signature Sign(BlockHeader header) => null!; - public bool CanSign => true; - - public bool CanSignHeader => true; } }