Skip to content

Commit

Permalink
Merge branch 'NethermindEth:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
FuzzysTodd authored Mar 5, 2024
2 parents 319c100 + d18e4f6 commit 3f8b04f
Show file tree
Hide file tree
Showing 309 changed files with 2,860 additions and 2,226 deletions.
31 changes: 15 additions & 16 deletions .github/workflows/hive-consensus-tests.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: 'Hive consensus tests'
name: 'Hive consensus tests'

on:
workflow_run:
workflows: ["Publish Docker image"]
branches: ["release/*"]
types:
- completed
- completed
workflow_dispatch:
inputs:
parallelism:
Expand Down Expand Up @@ -40,7 +40,7 @@ jobs:
run: |
echo "ORG_NAME=${{ github.repository_owner }}" >> $GITHUB_ENV
echo "REPO_NAME=${{ github.event.repository.name }}" >> $GITHUB_ENV
- name: Check if master or release branch
id: check_conditions
run: |
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
"dockerfile": "Dockerfile",
"build-config": "release"
}'

- name: Wait for Docker Build Action to complete
if: steps.check_conditions.outputs.skip_docker_build != 'true'
env:
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
dotnet run
cat matrix.json
echo "matrix=$(jq -c . matrix.json)" >> $GITHUB_OUTPUT
run_hive_tests:
runs-on: ubuntu-latest
needs: [generate_hive_consensus_tests, create_docker_image]
Expand All @@ -124,7 +124,7 @@ jobs:
uses: actions/checkout@v4
with:
path: nethermind

- name: Install Linux packages
run: |
sudo apt-get update
Expand Down Expand Up @@ -164,13 +164,12 @@ jobs:
run: |
chmod +x nethermind/scripts/hive-results.sh
nethermind/scripts/hive-results.sh "hive/workspace/logs/*.json"
- name: Send results to dashboard
continue-on-error: true
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HIVE_HOST }}
username: ${{ secrets.HIVE_USERNAME }}
key: ${{ secrets.HIVE_KEY }}
port: ${{ secrets.HIVE_PORT }}
source: hive/workspace/logs/*
target: ${{ secrets.HIVE_DIR }}/
# - name: Send results to dashboard
# uses: appleboy/scp-action@master
# with:
# host: ${{ secrets.HIVE_HOST }}
# username: ${{ secrets.HIVE_USERNAME }}
# key: ${{ secrets.HIVE_KEY }}
# port: ${{ secrets.HIVE_PORT }}
# source: hive/workspace/logs/*
# target: ${{ secrets.HIVE_DIR }}/
7 changes: 2 additions & 5 deletions src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,13 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?
stopwatch?.Start();
List<(Block Block, string ExpectedException)> correctRlp = DecodeRlps(test, failOnInvalidRlp);

if (test.GenesisRlp == null)
{
test.GenesisRlp = Rlp.Encode(new Block(JsonToEthereumTest.Convert(test.GenesisBlockHeader)));
}
test.GenesisRlp ??= Rlp.Encode(new Block(JsonToEthereumTest.Convert(test.GenesisBlockHeader)));

Block genesisBlock = Rlp.Decode<Block>(test.GenesisRlp.Bytes);
Assert.That(genesisBlock.Header.Hash, Is.EqualTo(new Hash256(test.GenesisBlockHeader.Hash)));

ManualResetEvent genesisProcessed = new(false);

blockTree.NewHeadBlock += (_, args) =>
{
if (args.Block.Number == 0)
Expand Down Expand Up @@ -271,7 +269,6 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?
{
Assert.That(suggestedBlock.Header.Hash, Is.EqualTo(new Hash256(testBlockJson.BlockHeader.Hash)));


for (int uncleIndex = 0; uncleIndex < suggestedBlock.Uncles.Length; uncleIndex++)
{
Assert.That(suggestedBlock.Uncles[uncleIndex].Hash, Is.EqualTo(new Hash256(testBlockJson.UncleHeaders[uncleIndex].Hash)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Nethermind.AccountAbstraction.Network;
using Nethermind.AccountAbstraction.Source;
using Nethermind.Core;
using Nethermind.Core.Collections;
using Nethermind.Core.Test.Builders;
using Nethermind.Core.Timers;
using Nethermind.Logging;
Expand Down Expand Up @@ -83,10 +84,12 @@ public void Can_handle_user_operations_message()
parsed = Address.TryParse("0x90f3e1105e63c877bf9587de5388c23cdb702c6b", out Address? _ep2);
Address ep1 = _ep1 ?? throw new ArgumentNullException(nameof(_ep1));
Address ep2 = _ep2 ?? throw new ArgumentNullException(nameof(_ep2));
IList<UserOperationWithEntryPoint> uOps = new List<UserOperationWithEntryPoint>();
uOps.Add(new UserOperationWithEntryPoint(Build.A.UserOperation.SignedAndResolved().TestObject, ep1));
uOps.Add(new UserOperationWithEntryPoint(Build.A.UserOperation.SignedAndResolved().TestObject, ep2));
UserOperationsMessage msg = new UserOperationsMessage(uOps);
ArrayPoolList<UserOperationWithEntryPoint> uOps = new(2)
{
new UserOperationWithEntryPoint(Build.A.UserOperation.SignedAndResolved().TestObject, ep1),
new UserOperationWithEntryPoint(Build.A.UserOperation.SignedAndResolved().TestObject, ep2)
};
using UserOperationsMessage msg = new UserOperationsMessage(uOps);
HandleZeroMessage(msg, AaMessageCode.UserOperations);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Nethermind.AccountAbstraction.Data;
using Nethermind.AccountAbstraction.Network;
using Nethermind.Core;
using Nethermind.Core.Collections;
using Nethermind.Network.Test.P2P;
using Nethermind.Serialization.Rlp;
using NUnit.Framework;
Expand Down Expand Up @@ -42,7 +43,7 @@ public void Roundtrip()
Signature = new byte[] { 1, 2, 3 }
});

UserOperationsMessage message = new(new[] { new UserOperationWithEntryPoint(userOperation, new Address("0x90f3e1105e63c877bf9587de5388c23cdb702c6b")) });
using UserOperationsMessage message = new(new ArrayPoolList<UserOperationWithEntryPoint>(1) { new(userOperation, new Address("0x90f3e1105e63c877bf9587de5388c23cdb702c6b")) });
TestZero(serializer, message, "f856f8549400000000000000000000000000000000000000018203e88203048201020506070801940000000000000000000000000000000000000002820506830102039490f3e1105e63c877bf9587de5388c23cdb702c6b");

// Meaning of RLP above:
Expand Down Expand Up @@ -70,8 +71,8 @@ public void Roundtrip()
// 83 = 131 = 128 + 3 (length of Signature)
// 010203 (Signature)

message = new(new[] { new UserOperationWithEntryPoint(userOperation, new Address("0x90f3e1105e63c877bf9587de5388c23cdb702c6b")), new UserOperationWithEntryPoint(userOperation, new Address("0xdb8b5f6080a8e466b64a8d7458326cb650b3353f")) });
TestZero(serializer, message, "f8acf8549400000000000000000000000000000000000000018203e88203048201020506070801940000000000000000000000000000000000000002820506830102039490f3e1105e63c877bf9587de5388c23cdb702c6bf8549400000000000000000000000000000000000000018203e882030482010205060708019400000000000000000000000000000000000000028205068301020394db8b5f6080a8e466b64a8d7458326cb650b3353f");
using UserOperationsMessage message2 = new(new ArrayPoolList<UserOperationWithEntryPoint>(2) { new(userOperation, new Address("0x90f3e1105e63c877bf9587de5388c23cdb702c6b")), new(userOperation, new Address("0xdb8b5f6080a8e466b64a8d7458326cb650b3353f")) });
TestZero(serializer, message2, "f8acf8549400000000000000000000000000000000000000018203e88203048201020506070801940000000000000000000000000000000000000002820506830102039490f3e1105e63c877bf9587de5388c23cdb702c6bf8549400000000000000000000000000000000000000018203e882030482010205060708019400000000000000000000000000000000000000028205068301020394db8b5f6080a8e466b64a8d7458326cb650b3353f");

// Meaning of RLP above:
// f8
Expand All @@ -88,15 +89,15 @@ public void Roundtrip()
public void Can_handle_empty()
{
UserOperationsMessageSerializer serializer = new();
UserOperationsMessage message = new(new UserOperationWithEntryPoint[] { });
using UserOperationsMessage message = new(ArrayPoolList<UserOperationWithEntryPoint>.Empty());

SerializerTester.TestZero(serializer, message);
}

[Test]
public void To_string_empty()
{
UserOperationsMessage message = new(new UserOperationWithEntryPoint[] { });
using UserOperationsMessage message = new(ArrayPoolList<UserOperationWithEntryPoint>.Empty());
_ = message.ToString();
}

Expand All @@ -107,7 +108,7 @@ private static void TestZero(UserOperationsMessageSerializer serializer, UserOpe
try
{
serializer.Serialize(buffer, message);
UserOperationsMessage deserialized = serializer.Deserialize(buffer);
using UserOperationsMessage deserialized = serializer.Deserialize(buffer);
// Abi is similar in deserialized and message, but for assertion there is some difference and an error. Line below excludes Abi from assertion
deserialized.Should().BeEquivalentTo(message, options => options.Excluding(o => o.Path.EndsWith("Abi")));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,20 @@ public void HandleMessage(ZeroPacket message)
switch (message.PacketType)
{
case AaMessageCode.UserOperations:
Metrics.UserOperationsMessagesReceived++;
UserOperationsMessage uopMsg = Deserialize<UserOperationsMessage>(message.Content);
ReportIn(uopMsg, size);
Handle(uopMsg);
break;
{
Metrics.UserOperationsMessagesReceived++;
using UserOperationsMessage uopMsg = Deserialize<UserOperationsMessage>(message.Content);
ReportIn(uopMsg, size);
Handle(uopMsg);

break;
}
}
}

private void Handle(UserOperationsMessage uopMsg)
{
IList<UserOperationWithEntryPoint> userOperations = uopMsg.UserOperationsWithEntryPoint;
IOwnedReadOnlyList<UserOperationWithEntryPoint> userOperations = uopMsg.UserOperationsWithEntryPoint;
for (int i = 0; i < userOperations.Count; i++)
{
UserOperationWithEntryPoint uop = userOperations[i];
Expand All @@ -125,20 +128,20 @@ private void Handle(UserOperationsMessage uopMsg)

public void SendNewUserOperation(UserOperationWithEntryPoint uop)
{
SendMessage(new[] { uop });
SendMessage(new ArrayPoolList<UserOperationWithEntryPoint>(1) { uop });
}

public void SendNewUserOperations(IEnumerable<UserOperationWithEntryPoint> uops)
{
const int maxCapacity = 256;
using ArrayPoolList<UserOperationWithEntryPoint> uopsToSend = new(maxCapacity);
ArrayPoolList<UserOperationWithEntryPoint> uopsToSend = new(maxCapacity);

foreach (UserOperationWithEntryPoint uop in uops)
{
if (uopsToSend.Count == maxCapacity)
{
SendMessage(uopsToSend);
uopsToSend.Clear();
uopsToSend = new(maxCapacity);
}

// TODO: Why this check
Expand All @@ -153,9 +156,13 @@ public void SendNewUserOperations(IEnumerable<UserOperationWithEntryPoint> uops)
{
SendMessage(uopsToSend);
}
else
{
uopsToSend.Dispose();
}
}

private void SendMessage(IList<UserOperationWithEntryPoint> uopsToSend)
private void SendMessage(IOwnedReadOnlyList<UserOperationWithEntryPoint> uopsToSend)
{
UserOperationsMessage msg = new(uopsToSend);
Send(msg);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using Nethermind.AccountAbstraction.Data;
using Nethermind.Core;
using Nethermind.Core.Collections;
using Nethermind.Network.P2P.Messages;

namespace Nethermind.AccountAbstraction.Network
{
public class UserOperationsMessage : P2PMessage
public class UserOperationsMessage(IOwnedReadOnlyList<UserOperationWithEntryPoint> userOperations) : P2PMessage
{
public override int PacketType { get; } = AaMessageCode.UserOperations;
public override string Protocol { get; } = "aa";

public IList<UserOperationWithEntryPoint> UserOperationsWithEntryPoint { get; }
public IOwnedReadOnlyList<UserOperationWithEntryPoint> UserOperationsWithEntryPoint { get; } = userOperations;

public UserOperationsMessage(IList<UserOperationWithEntryPoint> userOperations)
public override void Dispose()
{
UserOperationsWithEntryPoint = userOperations;
base.Dispose();
UserOperationsWithEntryPoint.Dispose();
}

public override string ToString() => $"{nameof(UserOperationsMessage)}({UserOperationsWithEntryPoint?.Count})";
}

public class UserOperationWithEntryPoint
public class UserOperationWithEntryPoint(UserOperation userOperation, Address entryPoint)
{
public UserOperation UserOperation { get; }
public Address EntryPoint { get; }

public UserOperationWithEntryPoint(UserOperation userOperation, Address entryPoint)
{
UserOperation = userOperation;
EntryPoint = entryPoint;
}
public UserOperation UserOperation { get; } = userOperation;
public Address EntryPoint { get; } = entryPoint;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using DotNetty.Buffers;
using Nethermind.AccountAbstraction.Data;
using Nethermind.Core.Collections;
using Nethermind.Network;
using Nethermind.Serialization.Rlp;

Expand All @@ -28,7 +29,7 @@ public void Serialize(IByteBuffer byteBuffer, UserOperationsMessage message)
public UserOperationsMessage Deserialize(IByteBuffer byteBuffer)
{
NettyRlpStream rlpStream = new(byteBuffer);
UserOperationWithEntryPoint[] uOps = DeserializeUOps(rlpStream);
ArrayPoolList<UserOperationWithEntryPoint> uOps = DeserializeUOps(rlpStream);
return new UserOperationsMessage(uOps);
}

Expand All @@ -43,9 +44,9 @@ public int GetLength(UserOperationsMessage message, out int contentLength)
return Rlp.LengthOfSequence(contentLength);
}

private static UserOperationWithEntryPoint[] DeserializeUOps(NettyRlpStream rlpStream)
private static ArrayPoolList<UserOperationWithEntryPoint> DeserializeUOps(NettyRlpStream rlpStream)
{
return Rlp.DecodeArray<UserOperationWithEntryPoint>(rlpStream);
return Rlp.DecodeArrayPool<UserOperationWithEntryPoint>(rlpStream);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ TestCaseData GetTestCaseData(
public (bool, object) validate_params(BlockHeader parentBlock, BlockHeader block, Action<AuRaParameters> modifyParameters, Repeat repeat, bool parentIsHead, bool isValidSealer)
{
_blockTree.Head.Returns(parentIsHead ? new Block(parentBlock) : new Block(Build.A.BlockHeader.WithNumber(parentBlock.Number - 1).TestObject));
_validSealerStrategy.IsValidSealer(Arg.Any<IList<Address>>(), block.Beneficiary, block.AuRaStep.Value).Returns(isValidSealer);
_validSealerStrategy.IsValidSealer(Arg.Any<IList<Address>>(), block.Beneficiary, block.AuRaStep.Value, out _).Returns(isValidSealer);

object cause = null;

Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.AuRa.Test/AuRaSealerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ public void Setup()
public bool can_seal(long auRaStep, bool validSealer)
{
_auRaStepCalculator.CurrentStep.Returns(auRaStep);
_validSealerStrategy.IsValidSealer(Arg.Any<IList<Address>>(), _address, auRaStep).Returns(validSealer);
_validSealerStrategy.IsValidSealer(Arg.Any<IList<Address>>(), _address, auRaStep, out _).Returns(validSealer);
return _auRaSealer.CanSeal(10, _blockTree.Head.Hash);
}

[Test]
public async Task seal_can_recover_address()
{
_auRaStepCalculator.CurrentStep.Returns(11);
_validSealerStrategy.IsValidSealer(Arg.Any<IList<Address>>(), _address, 11).Returns(true);
_validSealerStrategy.IsValidSealer(Arg.Any<IList<Address>>(), _address, 11, out _).Returns(true);
Block block = Build.A.Block.WithHeader(Build.A.BlockHeader.WithBeneficiary(_address).WithAura(11, null).TestObject).TestObject;

block = await _auRaSealer.SealBlock(block, CancellationToken.None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public void transactions_are_addable_to_block_after_sealing()
Address nodeAddress = TestItem.AddressA;

UInt256 expectedNonce = 10;
stateReader.GetAccount(blockHeader.StateRoot, nodeAddress).Returns(new AccountStruct(expectedNonce, UInt256.Zero));
stateReader.TryGetAccount(blockHeader.StateRoot, nodeAddress, out Arg.Any<AccountStruct>())
.Returns(x =>
{
x[2] = new AccountStruct(expectedNonce, UInt256.Zero);
return true;
});

ulong expectedTimeStamp = 100;
timestamper.UnixTime.Returns(UnixTime.FromSeconds(expectedTimeStamp));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static IEnumerable ValidateTestCases

[TestCaseSource(nameof(ValidateTestCases))]
public bool should_validate_correctly(Address address, long index) =>
_validSealerStrategy.IsValidSealer(GetListValidator(TestItem.AddressA, TestItem.AddressB).Validators, address, index);
_validSealerStrategy.IsValidSealer(GetListValidator(TestItem.AddressA, TestItem.AddressB).Validators, address, index, out _);

[TestCase(1)]
[TestCase(2)]
Expand Down
Loading

0 comments on commit 3f8b04f

Please sign in to comment.