Skip to content

Commit

Permalink
Fix sending new single tx p2p update (#6895)
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 authored Apr 3, 2024
1 parent 1490738 commit 3f7b552
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,25 @@ public void should_send_up_to_MaxCount_hashes_in_one_NewPooledTransactionHashesM

_handler.SendNewTransactions(txs, false);

_session.Received(1).DeliverMessage(Arg.Is<NewPooledTransactionHashesMessage68>(m => m.Hashes.Count == txCount));
_session.Received(1).DeliverMessage(Arg.Is<NewPooledTransactionHashesMessage68>(m =>
m.Hashes.Count == txCount &&
m.Sizes.Count == txCount &&
m.Types.Count == txCount));
}

[Test]
public void should_send_blob_tx_announcement_in_NewPooledTransactionHashesMessage68()
{
Transaction tx = Build.A.Transaction.WithNonce((UInt256)0).WithShardBlobTxTypeAndFields().SignedAndResolved().TestObject;

_handler.SendNewTransaction(tx);

_session.Received(1).DeliverMessage(Arg.Is<NewPooledTransactionHashesMessage68>(m =>
m.Hashes.Count == 1 &&
m.Sizes.Count == 1 &&
m.Types.Count == 1 &&
m.Hashes[0] == tx.Hash &&
(TxType)m.Types[0] == tx.Type));
}

[TestCase(NewPooledTransactionHashesMessage68.MaxCount - 1)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using Nethermind.Core.Extensions;
using Nethermind.Int256;
using Nethermind.Logging;
using Nethermind.Network.P2P.Messages;
using Nethermind.Network.P2P.Subprotocols.Eth.V62;
using Nethermind.Network.P2P.Subprotocols.Eth.V62.Messages;
using Nethermind.Network.P2P.Subprotocols.Eth.V63.Messages;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ protected override void SendNewTransactionCore(Transaction tx)
else
{
SendMessage(
new ArrayPoolList<byte>((byte)tx.Type),
new ArrayPoolList<int>(tx.GetLength()),
new ArrayPoolList<byte>(1) { (byte)tx.Type },
new ArrayPoolList<int>(1) { tx.GetLength() },
new ArrayPoolList<Hash256>(1) { tx.Hash }
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Logging;

namespace Nethermind.TxPool.Collections;

public class BlobTxDistinctSortedPool : TxDistinctSortedPool
public class BlobTxDistinctSortedPool(int capacity, IComparer<Transaction> comparer, ILogManager logManager)
: TxDistinctSortedPool(capacity, comparer, logManager)
{
private readonly ILogger _logger;

public BlobTxDistinctSortedPool(int capacity, IComparer<Transaction> comparer, ILogManager logManager)
: base(capacity, comparer, logManager)
{
_logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
}

protected override IComparer<Transaction> GetReplacementComparer(IComparer<Transaction> comparer)
=> comparer.GetBlobReplacementComparer();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

using Nethermind.Core;
using Nethermind.Core.Collections;
using Nethermind.Core.Crypto;
using Nethermind.Core.Threading;
using Nethermind.Int256;
using Nethermind.Logging;
using Nethermind.TxPool.Comparison;
Expand Down Expand Up @@ -73,7 +72,7 @@ protected override void UpdateGroup(AddressAsKey groupKey, EnhancedSortedSet<Tra

public void UpdatePool(IAccountStateProvider accounts, Func<Address, AccountStruct, EnhancedSortedSet<Transaction>, IEnumerable<(Transaction Tx, UInt256? changedGasBottleneck)>> changingElements)
{
using var lockRelease = Lock.Acquire();
using McsLock.Disposable lockRelease = Lock.Acquire();

EnsureCapacity();
foreach ((AddressAsKey address, EnhancedSortedSet<Transaction> bucket) in _buckets)
Expand Down Expand Up @@ -122,7 +121,7 @@ private void UpdateGroupNonLocked(Address groupKey, AccountStruct groupValue, En

public void UpdateGroup(Address groupKey, AccountStruct groupValue, Func<Address, AccountStruct, EnhancedSortedSet<Transaction>, IEnumerable<(Transaction Tx, UInt256? changedGasBottleneck)>> changingElements)
{
using var lockRelease = Lock.Acquire();
using McsLock.Disposable lockRelease = Lock.Acquire();

ArgumentNullException.ThrowIfNull(groupKey);
if (_buckets.TryGetValue(groupKey, out EnhancedSortedSet<Transaction>? bucket))
Expand Down

0 comments on commit 3f7b552

Please sign in to comment.