Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekM25 committed Sep 14, 2021
2 parents cc05945 + 2ee8d40 commit 2963427
Show file tree
Hide file tree
Showing 35 changed files with 454 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public async Task Produces_block()
(await StartStop(new Context())).ShouldProduceBlocks(Quantity.AtLeastOne());
}

[Test, Retry(3)]
[Test, Retry(6)]
public async Task Can_produce_first_block_when_private_chains_allowed()
{
Context context = new();
Expand Down
10 changes: 5 additions & 5 deletions src/Nethermind/Nethermind.Consensus.Ethash/Ethash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ private static ulong GetRandomNonce()
return BitConverter.ToUInt64(buffer, 0);
}

private bool IsLessThanTarget(byte[] result, UInt256 difficulty)
private bool IsLessOrEqualThanTarget(byte[] result, UInt256 difficulty)
{
UInt256 resultAsInteger = new(result, true);
BigInteger threshold = BigInteger.Divide(_2To256, (BigInteger)difficulty);
return (BigInteger)resultAsInteger < threshold;
BigInteger target = BigInteger.Divide(_2To256, (BigInteger)difficulty);
return (BigInteger)resultAsInteger <= target;
}

public (Keccak MixHash, ulong Nonce) Mine(BlockHeader header, ulong? startNonce = null)
Expand All @@ -178,7 +178,7 @@ private bool IsLessThanTarget(byte[] result, UInt256 difficulty)
{
byte[] result;
(mixHash, result, _) = Hashimoto(fullSize, dataSet, headerHashed, null, nonce);
if (IsLessThanTarget(result, header.Difficulty))
if (IsLessOrEqualThanTarget(result, header.Difficulty))
{
break;
}
Expand Down Expand Up @@ -243,7 +243,7 @@ public bool Validate(BlockHeader header)
return false;
}

return IsLessThanTarget(result, header.Difficulty);
return IsLessOrEqualThanTarget(result, header.Difficulty);
}

private readonly Stopwatch _cacheStopwatch = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public void GasPriceEstimate_IfPreviousGasPriceDoesNotExist_FallbackGasPriceSetT
GasPriceOracle testGasPriceOracle = new(blockFinder, specProvider, gasPrice);

testGasPriceOracle.GetGasPriceEstimate();

testGasPriceOracle.FallbackGasPrice.Should().BeEquivalentTo(gasPrice ?? 1.GWei());
UInt256 expectedGasPrice = 110 * (gasPrice ?? 1.GWei()) / 100;
testGasPriceOracle.FallbackGasPrice.Should().BeEquivalentTo(expectedGasPrice);
}

[TestCase(3)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ public class GasPriceOracle : IGasPriceOracle
public UInt256 IgnoreUnder { get; set; } = EthGasPriceConstants.DefaultIgnoreUnder;
public int BlockLimit { get; set; } = EthGasPriceConstants.DefaultBlocksLimit;
private int SoftTxThreshold => BlockLimit * 2;
private readonly UInt256 _defaultMinGasPriceMultiplier = 110;

public GasPriceOracle(
IBlockFinder blockFinder,
ISpecProvider specProvider,
UInt256? minGasPrice = null)
{
_blockFinder = blockFinder;
_minGasPrice = minGasPrice ?? new MiningConfig().MinGasPrice;
_minGasPrice = _defaultMinGasPriceMultiplier * (minGasPrice ?? new MiningConfig().MinGasPrice) / 100;
SpecProvider = specProvider;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2021 Demerzel Solutions Limited
// This file is part of the Nethermind library.
//
// The Nethermind library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The Nethermind library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.
//

using Nethermind.Core.Crypto;

namespace Nethermind.Merge.Plugin.Data
{
public class ExecutePayloadResult
{
public Keccak BlockHash { get; set; }

public VerificationStatus Status { get; set; }
}
}
27 changes: 27 additions & 0 deletions src/Nethermind/Nethermind.Merge.Plugin/Data/SyncStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2021 Demerzel Solutions Limited
// This file is part of the Nethermind library.
//
// The Nethermind library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The Nethermind library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.
//

namespace Nethermind.Merge.Plugin.Data
{
public enum SyncStatus
{
Snap,
Block,
Finished,
Error
}
}
26 changes: 26 additions & 0 deletions src/Nethermind/Nethermind.Merge.Plugin/Data/VerificationStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2021 Demerzel Solutions Limited
// This file is part of the Nethermind library.
//
// The Nethermind library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The Nethermind library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.
//

namespace Nethermind.Merge.Plugin.Data
{
public enum VerificationStatus
{
Valid,
Invalid,
Known
}
}
66 changes: 66 additions & 0 deletions src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Int256;
using Nethermind.JsonRpc;
using Nethermind.Logging;
using Nethermind.Merge.Plugin.Data;
using Nethermind.Merge.Plugin.Handlers;
using Org.BouncyCastle.Asn1.Cms;
using Result = Nethermind.Merge.Plugin.Data.Result;

namespace Nethermind.Merge.Plugin
{
Expand Down Expand Up @@ -98,5 +101,68 @@ public async Task<ResultWrapper<Result>> engine_setHead(Keccak blockHash)

public Task<ResultWrapper<Result>> engine_finaliseBlock(Keccak blockHash) =>
Task.FromResult(_finaliseBlockHandler.Handle(blockHash));

public Task engine_preparePayload(Keccak parentHash, UInt256 timestamp, Keccak random, Address coinbase)
{
throw new NotImplementedException();
}

public Task<ResultWrapper<BlockRequestResult?>> engine_getPayload(Keccak parentHash, UInt256 timeStamp,
Keccak random, Address coinbase)
{
throw new NotImplementedException();
}

public Task<ResultWrapper<ExecutePayloadResult>> engine_executePayload(BlockRequestResult executionPayload)
{
throw new NotImplementedException();
}

public Task engine_consensusValidated(Keccak parentHash, VerificationStatus status)
{
throw new NotImplementedException();
}

public Task engine_forkchoiceUpdated(Keccak headBlockHash, Keccak finalizedBlockHash, Keccak confirmedBlockHash)
{
throw new NotImplementedException();
}

public Task engine_terminalTotalDifficultyOverride(UInt256 terminalTotalDifficulty)
{
throw new NotImplementedException();
}

public Task engine_terminalPoWBlockOverride(Keccak blockHash)
{
throw new NotImplementedException();
}

public Task<ResultWrapper<Block?>> engine_getPowBlock(Keccak blockHash)
{
throw new NotImplementedException();
}

public Task engine_syncCheckpointSet(BlockRequestResult executionPayloadHeader)
{
throw new NotImplementedException();
}

public Task engine_syncStatus(SyncStatus sync, Keccak blockHash, UInt256 blockNumber)
{
throw new NotImplementedException();
}

public Task engine_consensusStatus(UInt256 transitionTotalDifficulty, Keccak terminalPowBlockHash,
Keccak finalizedBlockHash,
Keccak confirmedBlockHash, Keccak headBlockHash)
{
throw new NotImplementedException();
}

public Task engine_executionStatus(Keccak finalizedBlockHash, Keccak confirmedBlockHash, Keccak headBlockHash)
{
throw new NotImplementedException();
}
}
}
85 changes: 85 additions & 0 deletions src/Nethermind/Nethermind.Merge.Plugin/IEngineRpcModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
//

using System.Threading.Tasks;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Int256;
using Nethermind.JsonRpc;
using Nethermind.JsonRpc.Modules;
using Nethermind.JsonRpc.Modules.Eth;
using Nethermind.Merge.Plugin.Data;
using Result = Nethermind.Merge.Plugin.Data.Result;

namespace Nethermind.Merge.Plugin
{
Expand Down Expand Up @@ -53,5 +56,87 @@ Task<ResultWrapper<Result>> engine_setHead(
IsImplemented = true)]
Task<ResultWrapper<Result>> engine_finaliseBlock(
Keccak blockHash);

[JsonRpcMethod(
Description =
"Builds an execution payload on top of a given parent with transactions selected from the mempool.",
IsSharable = true,
IsImplemented = false)]
Task engine_preparePayload(Keccak parentHash, UInt256 timestamp, Keccak random, Address coinbase);

[JsonRpcMethod(
Description =
"Returns the most recent version of an execution payload with respect to the transaction set contained by the mempool.",
IsSharable = true,
IsImplemented = false)]
Task<ResultWrapper<BlockRequestResult?>> engine_getPayload(Keccak parentHash, UInt256 timeStamp, Keccak random,
Address coinbase);

[JsonRpcMethod(
Description =
"Verifies the payload according to the execution environment rule set and returns the status of the verification.",
IsSharable = true,
IsImplemented = false)]
Task<ResultWrapper<ExecutePayloadResult>> engine_executePayload(BlockRequestResult executionPayload);

[JsonRpcMethod(
Description =
"Communicates that full consensus validation of an execution payload is complete along with its corresponding status.",
IsSharable = true,
IsImplemented = false)]
Task engine_consensusValidated(Keccak parentHash, VerificationStatus status);

[JsonRpcMethod(
Description = "Propagates the change in the fork choice to the execution client.",
IsSharable = true,
IsImplemented = false)]
Task engine_forkchoiceUpdated(Keccak headBlockHash, Keccak finalizedBlockHash, Keccak confirmedBlockHash);

[JsonRpcMethod(
Description = "Propagates an override of the TERMINAL_TOTAL_DIFFICULTY to the execution client.",
IsSharable = true,
IsImplemented = false)]
Task engine_terminalTotalDifficultyOverride(UInt256 terminalTotalDifficulty);

[JsonRpcMethod(
Description = "Propagates the hash of the terminal PoW block.",
IsSharable = true,
IsImplemented = false)]
Task engine_terminalPoWBlockOverride(Keccak blockHash);

[JsonRpcMethod(
Description = "Given the hash returns the information of the PoW block.",
IsSharable = true,
IsImplemented = false)]
Task<ResultWrapper<Block?>> engine_getPowBlock(Keccak blockHash);

[JsonRpcMethod(
Description =
"Propagates the header of the payload obtained from the state at the weak subjectivity checkpoint.",
IsSharable = true,
IsImplemented = false)]
Task engine_syncCheckpointSet(BlockRequestResult executionPayloadHeader);

[JsonRpcMethod(
Description =
"An execution client responds with this status to any request of the consensus layer while sync is being in progress.",
IsSharable = true,
IsImplemented = false)]
Task engine_syncStatus(SyncStatus sync, Keccak blockHash, UInt256 blockNumber);

[JsonRpcMethod(
Description =
"Sends information on the state of the client to the execution side.",
IsSharable = true,
IsImplemented = false)]
Task engine_consensusStatus(UInt256 transitionTotalDifficulty, Keccak terminalPowBlockHash,
Keccak finalizedBlockHash, Keccak confirmedBlockHash, Keccak headBlockHash);

[JsonRpcMethod(
Description =
"Responds with information on the state of the execution client to either engine_consensusStatus or any other call if consistency failure has occurred.",
IsSharable = true,
IsImplemented = false)]
Task engine_executionStatus(Keccak finalizedBlockHash, Keccak confirmedBlockHash, Keccak headBlockHash);
}
}
6 changes: 3 additions & 3 deletions src/Nethermind/Nethermind.Runner/configs/energyweb.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
},
"Sync": {
"FastSync": true,
"PivotNumber": 13790000,
"PivotHash": "0x08d798a74438f37748d52fc5e37b0bc22ac69d5902c29c219547af807d08f635",
"PivotTotalDifficulty": "4692493839839741411159935836484083635638296744",
"PivotNumber": 13810000,
"PivotHash": "0x9881bce585ff1d73098d05c8a18cfd0bea658d02690bbefe8f5b14b1e1949e82",
"PivotTotalDifficulty": "4699299487178160180429203328632718999867375783",
"FastBlocks": true,
"UseGethLimitsInFastBlocks": false,
"FastSyncCatchUpHeightDelta": 10000000000
Expand Down
6 changes: 3 additions & 3 deletions src/Nethermind/Nethermind.Runner/configs/energyweb_pruned.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
},
"Sync": {
"FastSync": true,
"PivotNumber": 13790000,
"PivotHash": "0x08d798a74438f37748d52fc5e37b0bc22ac69d5902c29c219547af807d08f635",
"PivotTotalDifficulty": "4692493839839741411159935836484083635638296744",
"PivotNumber": 13810000,
"PivotHash": "0x9881bce585ff1d73098d05c8a18cfd0bea658d02690bbefe8f5b14b1e1949e82",
"PivotTotalDifficulty": "4699299487178160180429203328632718999867375783",
"FastBlocks": true,
"UseGethLimitsInFastBlocks": false,
"FastSyncCatchUpHeightDelta": 10000000000
Expand Down
6 changes: 3 additions & 3 deletions src/Nethermind/Nethermind.Runner/configs/mainnet.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
},
"Sync": {
"FastSync": true,
"PivotNumber": 13212000,
"PivotHash": "0x373ef865825dfc5001258adedafb4a57004de1c0b946bdf3cf98b45792229906",
"PivotTotalDifficulty": "30511108919641849170143",
"PivotNumber": 13218000,
"PivotHash": "0x1765bccda14394a27f3865f604e118a8be7d84ce6ad6e024852e850fcc680e34",
"PivotTotalDifficulty": "30564941907494799221708",
"FastBlocks": true,
"DownloadBodiesInFastSync": true,
"DownloadReceiptsInFastSync": true,
Expand Down
6 changes: 3 additions & 3 deletions src/Nethermind/Nethermind.Runner/configs/mainnet_beam.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"Sync": {
"FastSync": true,
"BeamSync": true,
"PivotNumber": 13212000,
"PivotHash": "0x373ef865825dfc5001258adedafb4a57004de1c0b946bdf3cf98b45792229906",
"PivotTotalDifficulty": "30511108919641849170143",
"PivotNumber": 13218000,
"PivotHash": "0x1765bccda14394a27f3865f604e118a8be7d84ce6ad6e024852e850fcc680e34",
"PivotTotalDifficulty": "30564941907494799221708",
"FastBlocks": true,
"DownloadHeadersInFastSync": false,
"DownloadBodiesInFastSync": false,
Expand Down
Loading

0 comments on commit 2963427

Please sign in to comment.