Skip to content

Commit

Permalink
Merge branch 'fix-txs-registration' of https://github.com/NethermindE…
Browse files Browse the repository at this point in the history
…th/nethermind into fix-txs-registration
  • Loading branch information
flcl42 committed Oct 28, 2024
2 parents eab5ac6 + c1adbb3 commit b203414
Show file tree
Hide file tree
Showing 38 changed files with 652 additions and 140 deletions.
9 changes: 5 additions & 4 deletions src/Nethermind/Ethereum.Test.Base/AuthorizationListJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core;
using Nethermind.Int256;

namespace Ethereum.Test.Base;
public class AuthorizationListJson
{
public ulong ChainId { get; set; }
public UInt256 ChainId { get; set; }
public Address Address { get; set; }
public ulong Nonce { get; set; }
public UInt256 Nonce { get; set; }
public ulong V { get; set; }
public byte[] R { get; set; }
public byte[] S { get; set; }
public string R { get; set; }
public string S { get; set; }
public Address Signer { get; set; }
}
52 changes: 45 additions & 7 deletions src/Nethermind/Ethereum.Test.Base/JsonToEthereumTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,51 @@ public static Transaction Convert(PostStateJson postStateJson, TransactionJson t
{
transaction.AuthorizationList =
transactionJson.AuthorizationList
.Select(i => new AuthorizationTuple(
i.ChainId,
i.Address,
i.Nonce,
i.V,
i.R,
i.S)).ToArray();
.Select(i =>
{
if (i.ChainId > ulong.MaxValue)
{
i.ChainId = 0;
transaction.SenderAddress = Address.Zero;
}
if (i.Nonce > ulong.MaxValue)
{
i.Nonce = 0;
transaction.SenderAddress = Address.Zero;
}
UInt256 s = UInt256.Zero;
if (i.S.Length > 66)
{
i.S = "0x0";
transaction.SenderAddress = Address.Zero;
}
else
{
s = UInt256.Parse(i.S);
}
UInt256 r = UInt256.Zero;
if (i.R.Length > 66)
{
i.R = "0x0";
transaction.SenderAddress = Address.Zero;
}
else
{
r = UInt256.Parse(i.R);
}
if (i.V > byte.MaxValue)
{
i.V = 0;
transaction.SenderAddress = Address.Zero;
}
return new AuthorizationTuple(
i.ChainId.u0,
i.Address,
i.Nonce.u0,
(byte)i.V,
r,
s);
}).ToArray();
if (transaction.AuthorizationList.Any())
{
transaction.Type = TxType.SetCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Numerics;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc.Routing;
using Nethermind.Consensus.Messages;
using Nethermind.Consensus.Validators;
using Nethermind.Core;
Expand Down Expand Up @@ -528,7 +529,7 @@ public void IsWellFormed_CreateTxInSetCode_ReturnsFalse()
{
TransactionBuilder<Transaction> txBuilder = Build.A.Transaction
.WithType(TxType.SetCode)
.WithAuthorizationCode(new AuthorizationTuple(0, TestItem.AddressA, 0, 0, [], []))
.WithAuthorizationCode(new AuthorizationTuple(0, TestItem.AddressA, 0, 0, 0, 0))
.WithMaxFeePerGas(100000)
.WithGasLimit(1000000)
.WithChainId(TestBlockchainIds.ChainId)
Expand All @@ -552,7 +553,7 @@ public void IsWellFormed_AuthorizationListTxInPragueSpec_ReturnsTrue()
TransactionBuilder<Transaction> txBuilder = Build.A.Transaction
.WithType(TxType.SetCode)
.WithTo(TestItem.AddressA)
.WithAuthorizationCode(new AuthorizationTuple(0, TestItem.AddressA, 0, 0, [], []))
.WithAuthorizationCode(new AuthorizationTuple(0, TestItem.AddressA, 0, 0, 0, 0))
.WithMaxFeePerGas(100000)
.WithGasLimit(1000000)
.WithChainId(TestBlockchainIds.ChainId)
Expand Down Expand Up @@ -599,30 +600,6 @@ public void IsWellFormed_NullAuthorizationList_ReturnsFalse()
Assert.That(txValidator.IsWellFormed(tx, Prague.Instance).AsBool, Is.False);
}

private static object[] BadSignatures =
{
new object[] { 1ul, (UInt256)1, Secp256K1Curve.HalfNPlusOne, false},
new object[] { 1ul, UInt256.Zero, Secp256K1Curve.HalfN, true },
new object[] { 0ul, UInt256.Zero, UInt256.Zero, true },
};
[TestCaseSource(nameof(BadSignatures))]
public void IsWellFormed_AuthorizationTupleHasBadSignature_ReturnsFalse(ulong yParity, UInt256 r, UInt256 s, bool expected)
{
TransactionBuilder<Transaction> txBuilder = Build.A.Transaction
.WithType(TxType.SetCode)
.WithTo(TestItem.AddressA)
.WithAuthorizationCode(new AuthorizationTuple(0, Address.Zero, 0, new Signature(r, s, yParity + Signature.VOffset)))
.WithMaxFeePerGas(100000)
.WithGasLimit(1000000)
.WithChainId(TestBlockchainIds.ChainId)
.SignedAndResolved();

Transaction tx = txBuilder.TestObject;
TxValidator txValidator = new(TestBlockchainIds.ChainId);

Assert.That(txValidator.IsWellFormed(tx, Prague.Instance).AsBool, Is.EqualTo(expected));
}

private static IEnumerable<TxType> NonSetCodeTypes() =>
Enum.GetValues<TxType>().Where(t => t != TxType.SetCode && t != TxType.DepositTx);

Expand Down
4 changes: 4 additions & 0 deletions src/Nethermind/Nethermind.Config/BlocksConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,9 @@ public byte[] GetExtraDataBytes()
{
return _extraDataBytes;
}

public string GasToken { get => GasTokenTicker; set => GasTokenTicker = value; }

public static string GasTokenTicker { get; set; } = "ETH";
}
}
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.Config/IBlocksConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ public interface IBlocksConfig : IConfig
[ConfigItem(Description = "The genesis block load timeout, in milliseconds.", DefaultValue = "40000")]
int GenesisTimeoutMs { get; set; }

[ConfigItem(Description = "The ticker that gas rewards are denominated in for processing logs", DefaultValue = "ETH", HiddenFromDocs = true)]
string GasToken { get; set; }

byte[] GetExtraDataBytes();
}
21 changes: 21 additions & 0 deletions src/Nethermind/Nethermind.Consensus/Processing/BlockExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Nethermind.Config;
using Nethermind.Consensus.Producers;
using Nethermind.Core;
using Nethermind.Core.Extensions;
using Nethermind.State.Proofs;

[assembly: InternalsVisibleTo("Nethermind.Consensus.Test")]
Expand Down Expand Up @@ -40,5 +41,25 @@ public static bool IsByNethermindNode(this BlockHeader block) =>
Ascii.IsValid(block.ExtraData)
&& Encoding.ASCII.GetString(block.ExtraData ?? Array.Empty<byte>())
.Contains(BlocksConfig.DefaultExtraData, StringComparison.InvariantCultureIgnoreCase);

public static string ParsedExtraData(this Block block)
{
byte[]? data = block.ExtraData;
if (data is null || data.Length == 0)
{
// If no extra data just show GasBeneficiary address
return $"Address: {(block.Header.GasBeneficiary?.ToString() ?? "0x")}";
}

// Ideally we'd prefer to show text; so convert invalid unicode
// and control chars to spaces and trim leading and trailing spaces.
string extraData = new ReadOnlySpan<byte>(data).ToCleanUtf8String();

// If the cleaned text is less than half length of input size,
// output it as hex, else output the text.
return extraData.Length > data.Length / 2 ?
$"Extra Data: {extraData}" :
$"Hex: {data.ToHexString(withZeroX: true)}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public BlockchainProcessor(
_blockTree.NewBestSuggestedBlock += OnNewBestBlock;
_blockTree.NewHeadBlock += OnNewHeadBlock;

_stats = new ProcessingStats(_logger);
_stats = new ProcessingStats(stateReader, _logger);
}

private void OnNewHeadBlock(object? sender, BlockEventArgs e)
Expand Down Expand Up @@ -419,7 +419,8 @@ private void FireProcessingQueueEmpty()
Metrics.LastBlockProcessingTimeInMs = blockProcessingTimeInMicrosecs / 1000;
Metrics.RecoveryQueueSize = _recoveryQueue.Count;
Metrics.ProcessingQueueSize = _blockQueue.Count;
_stats.UpdateStats(lastProcessed, blockProcessingTimeInMicrosecs);

_stats.UpdateStats(lastProcessed, processingBranch.Root, blockProcessingTimeInMicrosecs);
}

bool updateHead = !options.ContainsFlag(ProcessingOptions.DoNotUpdateHead);
Expand Down
Loading

0 comments on commit b203414

Please sign in to comment.