Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ak88 committed Mar 25, 2024
1 parent 503db49 commit ad2bf4c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
11 changes: 7 additions & 4 deletions src/Nethermind/Nethermind.Consensus.Clique/CliqueSealer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

Expand Down Expand Up @@ -67,10 +69,11 @@ public CliqueSealer(ISigner signer, ICliqueConfig config, ISnapshotManager snaps
Signature signature;
if (_signer.CanSignHeader)
{
Hash256 original = header.Hash;
header.Hash = headerHash;
signature = _signer.Sign(header);
header.Hash = original;
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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ private ClefSigner(IJsonRpcClient rpcClient, Address author)
{
this.rpcClient = rpcClient;
Address = author;
CanSign = true;
_headerDecoder = new HeaderDecoder();
}

Expand All @@ -34,7 +33,7 @@ public static async Task<ClefSigner> Create(IJsonRpcClient jsonRpcClient, Addres

public Address Address { get; private set; }

public bool CanSign { get; }
public bool CanSign => true;

public bool CanSignHeader => true;

Expand Down
39 changes: 21 additions & 18 deletions src/Nethermind/Nethermind.ExternalSigner.Plugin/ClefSignerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Api;

// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

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;

Expand All @@ -31,19 +28,10 @@ public ValueTask DisposeAsync()
return ValueTask.CompletedTask;
}

public Task Init(INethermindApi nethermindApi)
public async Task Init(INethermindApi nethermindApi)
{
_nethermindApi = nethermindApi ?? throw new ArgumentNullException(nameof(nethermindApi));
return Task.CompletedTask;
}

public Task InitNetworkProtocol()
{
return Task.CompletedTask;
}

public async Task InitRpcModules()
{
if (_nethermindApi == null)
throw new InvalidOperationException("Init() must be called first.");

Expand All @@ -52,20 +40,35 @@ public async Task InitRpcModules()
{
if (!string.IsNullOrEmpty(miningConfig.Signer))
{
JsonRpcUrl.Parse(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(miningConfig.Signer, _nethermindApi.Config<IKeyStoreConfig>().BlockAuthorAccount);
await SetupExternalSigner(uri, _nethermindApi.Config<IKeyStoreConfig>().BlockAuthorAccount);
_nethermindApi.EngineSigner = signer;
}
}

}

public Task InitNetworkProtocol()
{
return Task.CompletedTask;
}

public Task InitRpcModules()
{
return Task.CompletedTask;
}

private async Task<ClefSigner> SetupExternalSigner(string urlSigner, string blockAuthorAccount)
private async Task<ClefSigner> SetupExternalSigner(Uri urlSigner, string blockAuthorAccount)
{
try
{
Address? address = string.IsNullOrEmpty(blockAuthorAccount) ? null : new Address(blockAuthorAccount);
BasicJsonRpcClient rpcClient = new(new Uri(urlSigner), _nethermindApi!.EthereumJsonSerializer, _nethermindApi.LogManager, TimeSpan.FromSeconds(10));
BasicJsonRpcClient rpcClient = new(urlSigner, _nethermindApi!.EthereumJsonSerializer, _nethermindApi.LogManager, TimeSpan.FromSeconds(10));
_nethermindApi.DisposeStack.Push(rpcClient);
return await ClefSigner.Create(rpcClient, address);
}
Expand Down

0 comments on commit ad2bf4c

Please sign in to comment.