Skip to content

Commit

Permalink
Merge branch 'master' into feature/doc-md-reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
rubo authored Oct 9, 2024
2 parents a842899 + 522deba commit e0d944e
Show file tree
Hide file tree
Showing 78 changed files with 678 additions and 614 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/build-tools.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build tools

on:
merge_group:
types: [checks_requested]
pull_request:
branches: [master]
push:
branches: [master]

jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
config: [release]
project:
- docgen/DocGen.sln
- HiveCompare/HiveCompare.sln
- HiveConsensusWorkflowGenerator/HiveConsensusWorkflowGenerator.csproj
- Nethermind.Tools.Kute/Nethermind.Tools.Kute.csproj
- SendBlobs/SendBlobs.sln
- TxParser/TxParser.csproj
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up .NET
uses: actions/setup-dotnet@v4
- name: Build ${{ matrix.project }}
working-directory: tools
run: dotnet build ./${{ matrix.project }} -c ${{ matrix.config }}
12 changes: 4 additions & 8 deletions src/Nethermind/Nethermind.Cli/NodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ public async Task<JsValue> PostJint(string method, params object[] parameters)
}
else
{
Stopwatch stopwatch = new();
stopwatch.Start();
long startTime = Stopwatch.GetTimestamp();
object? result = await _currentClient.Post<object>(method, parameters);
stopwatch.Stop();
decimal totalMicroseconds = stopwatch.ElapsedTicks * (1_000_000m / Stopwatch.Frequency);
decimal totalMicroseconds = (decimal)Stopwatch.GetElapsedTime(startTime).TotalMicroseconds;
Colorful.Console.WriteLine($"Request complete in {totalMicroseconds}μs");

if (result is bool boolResult)
Expand Down Expand Up @@ -121,11 +119,9 @@ public async Task<JsValue> PostJint(string method, params object[] parameters)
}
else
{
Stopwatch stopwatch = new();
stopwatch.Start();
long starting = Stopwatch.GetTimestamp();
result = await _currentClient.Post<T>(method, parameters);
stopwatch.Stop();
decimal totalMicroseconds = stopwatch.ElapsedTicks * (1_000_000m / Stopwatch.Frequency);
decimal totalMicroseconds = (decimal)Stopwatch.GetElapsedTime(starting).TotalMicroseconds;
Colorful.Console.WriteLine($"Request complete in {totalMicroseconds}μs");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,8 @@ private void WaitForNumber(PrivateKey nodeKey, long number)
{
if (_logger.IsInfo) _logger.Info($"WAITING ON {nodeKey.Address} FOR BLOCK {number}");
SpinWait spinWait = new();
Stopwatch stopwatch = new();
stopwatch.Start();
while (stopwatch.ElapsedMilliseconds < _timeout)
long startTime = Stopwatch.GetTimestamp();
while (Stopwatch.GetElapsedTime(startTime).TotalMilliseconds < _timeout)
{
spinWait.SpinOnce();
if (_blockTrees[nodeKey].Head.Number >= number)
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Config/IBlocksConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public interface IBlocksConfig : IConfig
[ConfigItem(Description = "Whether to pre-warm the state when processing blocks. This can lead to an up to 2x speed-up in the main loop block processing.", DefaultValue = "True")]
bool PreWarmStateOnBlockProcessing { get; set; }

[ConfigItem(Description = "Block Production timeout, in milliseconds.", DefaultValue = "4000")]
[ConfigItem(Description = "The block production timeout, in milliseconds.", DefaultValue = "4000")]
int BlockProductionTimeoutMs { get; set; }

[ConfigItem(Description = "Genesis block load timeout, in milliseconds.", DefaultValue = "40000")]
[ConfigItem(Description = "The genesis block load timeout, in milliseconds.", DefaultValue = "40000")]
int GenesisTimeoutMs { get; set; }

byte[] GetExtraDataBytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only


using FluentAssertions;
using Nethermind.Config;
using Nethermind.Core;
using Nethermind.Core.Test.Builders;
Expand Down Expand Up @@ -29,5 +30,21 @@ public void Is_bump_on_1559_eip_block()
long actualValue = targetedAdjustedGasLimitCalculator.GetGasLimit(header);
Assert.That(actualValue, Is.EqualTo(gasLimit * Eip1559Constants.DefaultElasticityMultiplier));
}

[TestCase(30_000_000, 100_000_000, 30029295)]
public void Is_calculating_correct_gasLimit(long currentGasLimit, long targetGasLimit, long expectedGasLimit)
{
int blockNumber = 20_000_000;
long gasLimit = currentGasLimit;
TestSpecProvider specProvider = new(Prague.Instance);
TargetAdjustedGasLimitCalculator targetedAdjustedGasLimitCalculator = new(specProvider,
new BlocksConfig()
{
TargetBlockGasLimit = targetGasLimit
});
BlockHeader header = Build.A.BlockHeader.WithNumber(blockNumber - 1).WithGasLimit(gasLimit).TestObject;
long actualValue = targetedAdjustedGasLimitCalculator.GetGasLimit(header);
actualValue.Should().Be(expectedGasLimit);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Nethermind.Consensus.Processing.CensorshipDetector;

public class CensorshipDetectorConfig : ICensorshipDetectorConfig
{
public bool Enabled { get; set; } = true;
public bool Enabled { get; set; } = false;
public uint BlockCensorshipThreshold { get; set; } = 2;
public string[]? AddressesForCensorshipDetection { get; set; } = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ namespace Nethermind.Consensus.Processing.CensorshipDetector;

public interface ICensorshipDetectorConfig : IConfig
{
[ConfigItem(DefaultValue = "true",
Description = "Enabling censorship detection feature")]
[ConfigItem(DefaultValue = "false", Description = "Whether to enable censorship detection.")]
bool Enabled { get; set; }

[ConfigItem(DefaultValue = "2",
Description = "Number of consecutive blocks with detected potential censorship to report censorship attempt")]
Description = "The number of the consecutive blocks with detected potential censorship to report.")]
uint BlockCensorshipThreshold { get; set; }

[ConfigItem(DefaultValue = "null",
Description = "The addresses for which censorship is being detected.")]
[ConfigItem(DefaultValue = "null", Description = "The addresses to detect censorship for.")]
string[]? AddressesForCensorshipDetection { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,17 @@ void IThreadPoolWorkItem.Execute()
_logger.Info($"- Block{(chunkBlocks > 1 ? $"s {chunkBlocks,-9:N0}" : " ")}{(chunkBlocks == 1 ? mgasColor : "")} {chunkMGas,9:F2}{resetColor} MGas | {chunkTx,8:N0} txs | calls {callsColor}{chunkCalls,6:N0}{resetColor} {darkGreyText}({chunkEmptyCalls,3:N0}){resetColor} | sload {chunkSload,7:N0} | sstore {sstoreColor}{chunkSstore,6:N0}{resetColor} | create {createsColor}{chunkCreates,3:N0}{resetColor}{(currentSelfDestructs - _lastSelfDestructs > 0 ? $"{darkGreyText}({-(currentSelfDestructs - _lastSelfDestructs),3:N0}){resetColor}" : "")}");
if (recoveryQueue > 0 || processingQueue > 0)
{
_logger.Info($"- Block throughput {mgasPerSecondColor}{mgasPerSecond,9:F2}{resetColor} MGas/s{(mgasPerSecond > 1000 ? "🔥" : " ")}| {txps,10:N1} t/s | {bps,7:F2} Blk/s | recover {recoveryQueue,5:N0} | process {processingQueue,5:N0}");
_logger.Info($"- Block throughput {mgasPerSecondColor}{mgasPerSecond,9:F2}{resetColor} MGas/s{(mgasPerSecond > 1000 ? "🔥" : " ")}| {txps,10:N1} tps | {bps,7:F2} Blk/s | recover {recoveryQueue,5:N0} | process {processingQueue,5:N0}");
}
else
{
_logger.Info($"- Block throughput {mgasPerSecondColor}{mgasPerSecond,9:F2}{resetColor} MGas/s{(mgasPerSecond > 1000 ? "🔥" : " ")}| {txps,10:N1} t/s | {bps,7:F2} Blk/s | exec code {resetColor} from cache {cachedContractsUsed,7:N0} |{resetColor} new {contractsAnalysed,6:N0}");
_logger.Info($"- Block throughput {mgasPerSecondColor}{mgasPerSecond,9:F2}{resetColor} MGas/s{(mgasPerSecond > 1000 ? "🔥" : " ")}| {txps,10:N1} tps | {bps,7:F2} Blk/s | exec code {resetColor} from cache {cachedContractsUsed,7:N0} |{resetColor} new {contractsAnalysed,6:N0}");
}

// Only output the total throughput in debug mode
if (_logger.IsDebug)
{
_logger.Debug($"- Total throughput {totalMgasPerSecond,9:F2} MGas/s | {totalTxPerSecond,9:F2} t/s | {totalBlocksPerSecond,7:F2} Blk/s |⛽ Gas gwei: {Evm.Metrics.MinGasPrice:N2} .. {Math.Max(Evm.Metrics.MinGasPrice, Evm.Metrics.EstMedianGasPrice):N2} ({Evm.Metrics.AveGasPrice:N2}) .. {Evm.Metrics.MaxGasPrice:N2}");
_logger.Debug($"- Total throughput {totalMgasPerSecond,9:F2} MGas/s | {totalTxPerSecond,9:F2} tps | {totalBlocksPerSecond,7:F2} Blk/s |⛽ Gas gwei: {Evm.Metrics.MinGasPrice:N2} .. {Math.Max(Evm.Metrics.MinGasPrice, Evm.Metrics.EstMedianGasPrice):N2} ({Evm.Metrics.AveGasPrice:N2}) .. {Evm.Metrics.MaxGasPrice:N2}");
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Nethermind/Nethermind.Core/Collections/ArrayPoolList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,5 +363,6 @@ public void Dispose()

public Span<T> AsSpan() => _array.AsSpan(0, Count);

public ReadOnlyMemory<T> AsMemory() => new(_array, 0, Count);
public Memory<T> AsMemory() => new(_array, 0, Count);
public ReadOnlyMemory<T> AsReadOnlyMemory() => new(_array, 0, Count);
}
137 changes: 0 additions & 137 deletions src/Nethermind/Nethermind.Core/Crypto/KeccakHash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;

using static System.Numerics.BitOperations;

// ReSharper disable InconsistentNaming
Expand Down Expand Up @@ -92,18 +88,6 @@ private KeccakHash(int size)

// update the state with given number of rounds
private static void KeccakF(Span<ulong> st)
{
if (Avx512F.IsSupported)
{
KeccakF1600Avx512F(st);
}
else
{
KeccakF1600(st);
}
}

private static void KeccakF1600(Span<ulong> st)
{
Debug.Assert(st.Length == 25);

Expand Down Expand Up @@ -637,126 +621,5 @@ public static void ReturnState(ref ulong[] state)
state = Array.Empty<ulong>();
}
}

[SkipLocalsInit]
public static void KeccakF1600Avx512F(Span<ulong> state)
{
{
// Redundant statement that removes all the in loop bounds checks
_ = state[24];
}

// Can straight load and over-read for start elements
Vector512<ulong> mask = Vector512.Create(ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, 0UL, 0UL, 0UL);
Vector512<ulong> c0 = Unsafe.As<ulong, Vector512<ulong>>(ref MemoryMarshal.GetReference(state));
// Clear the over-read values from first vectors
c0 = Vector512.BitwiseAnd(mask, c0);
Vector512<ulong> c1 = Unsafe.As<ulong, Vector512<ulong>>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 5));
c1 = Vector512.BitwiseAnd(mask, c1);
Vector512<ulong> c2 = Unsafe.As<ulong, Vector512<ulong>>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 10));
c2 = Vector512.BitwiseAnd(mask, c2);
Vector512<ulong> c3 = Unsafe.As<ulong, Vector512<ulong>>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 15));
c3 = Vector512.BitwiseAnd(mask, c3);

// Can't over-read for the last elements (8 items in vector 5 to be remaining)
// so read a Vector256 and ulong then combine
Vector256<ulong> c4a = Unsafe.As<ulong, Vector256<ulong>>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 20));
Vector256<ulong> c4b = Vector256.Create(state[24], 0UL, 0UL, 0UL);
Vector512<ulong> c4 = Vector512.Create(c4a, c4b);

ulong[] roundConstants = RoundConstants;
for (int round = 0; round < roundConstants.Length; round++)
{
// Theta step
Vector512<ulong> bVec = Vector512.Xor(Vector512.Xor(Vector512.Xor(c0, c1), Vector512.Xor(c2, c3)), c4);

// Compute Theta Vector
Vector512<ulong> bVecRot1 = Avx512F.PermuteVar8x64(bVec, Vector512.Create(1UL, 2UL, 3UL, 4UL, 0UL, 5UL, 6UL, 7UL));
Vector512<ulong> bVecRot4 = Avx512F.PermuteVar8x64(bVec, Vector512.Create(4UL, 0UL, 1UL, 2UL, 3UL, 5UL, 6UL, 7UL));

// Rotate bVecRot1 left by 1
Vector512<ulong> bVecRot1ShiftedLeft = Avx512F.ShiftLeftLogical(bVecRot1, 1);
Vector512<ulong> bVecRot1ShiftedRight = Avx512F.ShiftRightLogical(bVecRot1, 63);
Vector512<ulong> bVecRot1Rotated = Avx512F.Or(bVecRot1ShiftedLeft, bVecRot1ShiftedRight);

Vector512<ulong> thetaVec = Avx512F.Xor(bVecRot4, bVecRot1Rotated);

c0 = Avx512F.Xor(c0, thetaVec);
c1 = Avx512F.Xor(c1, thetaVec);
c2 = Avx512F.Xor(c2, thetaVec);
c3 = Avx512F.Xor(c3, thetaVec);
c4 = Avx512F.Xor(c4, thetaVec);

// Rho step
Vector512<ulong> rhoVec0 = Vector512.Create(0UL, 1UL, 62UL, 28UL, 27UL, 0UL, 0UL, 0UL);
c0 = Avx512F.RotateLeftVariable(c0, rhoVec0);

Vector512<ulong> rhoVec1 = Vector512.Create(36UL, 44UL, 6UL, 55UL, 20UL, 0UL, 0UL, 0UL);
c1 = Avx512F.RotateLeftVariable(c1, rhoVec1);

Vector512<ulong> rhoVec2 = Vector512.Create(3UL, 10UL, 43UL, 25UL, 39UL, 0UL, 0UL, 0UL);
c2 = Avx512F.RotateLeftVariable(c2, rhoVec2);

Vector512<ulong> rhoVec3 = Vector512.Create(41UL, 45UL, 15UL, 21UL, 8UL, 0UL, 0UL, 0UL);
c3 = Avx512F.RotateLeftVariable(c3, rhoVec3);

Vector512<ulong> rhoVec4 = Vector512.Create(18UL, 2UL, 61UL, 56UL, 14UL, 0UL, 0UL, 0UL);
c4 = Avx512F.RotateLeftVariable(c4, rhoVec4);

// Pi step
Vector512<ulong> c0Pi = Avx512F.PermuteVar8x64x2(c0, Vector512.Create(0UL, 8 + 1, 2, 3, 4, 5, 6, 7), c1);
c0Pi = Avx512F.PermuteVar8x64x2(c0Pi, Vector512.Create(0UL, 1, 8 + 2, 3, 4, 5, 6, 7), c2);
c0Pi = Avx512F.PermuteVar8x64x2(c0Pi, Vector512.Create(0UL, 1, 2, 8 + 3, 4, 5, 6, 7), c3);
c0Pi = Avx512F.PermuteVar8x64x2(c0Pi, Vector512.Create(0UL, 1, 2, 3, 8 + 4, 5, 6, 7), c4);

Vector512<ulong> c1Pi = Avx512F.PermuteVar8x64x2(c0, Vector512.Create(3UL, 8 + 4, 2, 3, 4, 5, 6, 7), c1);
c1Pi = Avx512F.PermuteVar8x64x2(c1Pi, Vector512.Create(0UL, 1, 8 + 0, 3, 4, 5, 6, 7), c2);
c1Pi = Avx512F.PermuteVar8x64x2(c1Pi, Vector512.Create(0UL, 1, 2, 8 + 1, 4, 5, 6, 7), c3);
c1Pi = Avx512F.PermuteVar8x64x2(c1Pi, Vector512.Create(0UL, 1, 2, 3, 8 + 2, 5, 6, 7), c4);

Vector512<ulong> c2Pi = Avx512F.PermuteVar8x64x2(c0, Vector512.Create(1UL, 8 + 2, 2, 3, 4, 5, 6, 7), c1);
c2Pi = Avx512F.PermuteVar8x64x2(c2Pi, Vector512.Create(0UL, 1, 8 + 3, 3, 4, 5, 6, 7), c2);
c2Pi = Avx512F.PermuteVar8x64x2(c2Pi, Vector512.Create(0UL, 1, 2, 8 + 4, 4, 5, 6, 7), c3);
c2Pi = Avx512F.PermuteVar8x64x2(c2Pi, Vector512.Create(0UL, 1, 2, 3, 8 + 0, 5, 6, 7), c4);

Vector512<ulong> c3Pi = Avx512F.PermuteVar8x64x2(c0, Vector512.Create(4UL, 8 + 0, 2, 3, 4, 5, 6, 7), c1);
c3Pi = Avx512F.PermuteVar8x64x2(c3Pi, Vector512.Create(0UL, 1, 8 + 1, 3, 4, 5, 6, 7), c2);
c3Pi = Avx512F.PermuteVar8x64x2(c3Pi, Vector512.Create(0UL, 1, 2, 8 + 2, 4, 5, 6, 7), c3);
c3Pi = Avx512F.PermuteVar8x64x2(c3Pi, Vector512.Create(0UL, 1, 2, 3, 8 + 3, 5, 6, 7), c4);

Vector512<ulong> c4Pi = Avx512F.PermuteVar8x64x2(c0, Vector512.Create(2UL, 8 + 3, 2, 3, 4, 5, 6, 7), c1);
c4Pi = Avx512F.PermuteVar8x64x2(c4Pi, Vector512.Create(0UL, 1, 8 + 4, 3, 4, 5, 6, 7), c2);
c4Pi = Avx512F.PermuteVar8x64x2(c4Pi, Vector512.Create(0UL, 1, 2, 8 + 0, 4, 5, 6, 7), c3);
c4Pi = Avx512F.PermuteVar8x64x2(c4Pi, Vector512.Create(0UL, 1, 2, 3, 8 + 1, 5, 6, 7), c4);

c0 = c0Pi;
c1 = c1Pi;
c2 = c2Pi;
c3 = c3Pi;
c4 = c4Pi;

// Chi step
Vector512<ulong> permute1 = Vector512.Create(1UL, 2UL, 3UL, 4UL, 0UL, 5UL, 6UL, 7UL);
Vector512<ulong> permute2 = Vector512.Create(2UL, 3UL, 4UL, 0UL, 1UL, 5UL, 6UL, 7UL);

c0 = Avx512F.TernaryLogic(c0, Avx512F.PermuteVar8x64(c0, permute1), Avx512F.PermuteVar8x64(c0, permute2), 0xD2);
c1 = Avx512F.TernaryLogic(c1, Avx512F.PermuteVar8x64(c1, permute1), Avx512F.PermuteVar8x64(c1, permute2), 0xD2);
c2 = Avx512F.TernaryLogic(c2, Avx512F.PermuteVar8x64(c2, permute1), Avx512F.PermuteVar8x64(c2, permute2), 0xD2);
c3 = Avx512F.TernaryLogic(c3, Avx512F.PermuteVar8x64(c3, permute1), Avx512F.PermuteVar8x64(c3, permute2), 0xD2);
c4 = Avx512F.TernaryLogic(c4, Avx512F.PermuteVar8x64(c4, permute1), Avx512F.PermuteVar8x64(c4, permute2), 0xD2);

// Iota step
c0 = Vector512.Xor(c0, Vector512.Create(roundConstants[round], 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL));
}

// Can over-write for first elements
Unsafe.As<ulong, Vector512<ulong>>(ref MemoryMarshal.GetReference(state)) = c0;
Unsafe.As<ulong, Vector512<ulong>>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 5)) = c1;
Unsafe.As<ulong, Vector512<ulong>>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 10)) = c2;
Unsafe.As<ulong, Vector512<ulong>>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 15)) = c3;
// Can't over-write for last elements so write the upper Vector256 and then ulong
Unsafe.As<ulong, Vector256<ulong>>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 20)) = c3.GetUpper();
state[24] = c4.GetElement(4);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

namespace Nethermind.Evm.Test;

public class BlsMultiMulG1PrecompileTests
public class BlsG1MSMPrecompileTests
{
[Test]
public void Test()
{
foreach ((byte[] input, ReadOnlyMemory<byte> expectedResult) in Inputs)
{
IPrecompile precompile = G1MultiMulPrecompile.Instance;
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, MuirGlacier.Instance);
IPrecompile precompile = G1MSMPrecompile.Instance;
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, Prague.Instance);
output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray());
success.Should().BeTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Nethermind.Evm.Test;

public class BlsAddG2PrecompileTests
public class BlsG2AddPrecompileTests
{
[Test]
public void Test()
Expand Down
Loading

0 comments on commit e0d944e

Please sign in to comment.