Skip to content

Commit c2737fc

Browse files
committed
CalculateMaxBlobTxSize through transitionActivations
1 parent 0c309ea commit c2737fc

File tree

5 files changed

+17
-26
lines changed

5 files changed

+17
-26
lines changed

src/Nethermind/Nethermind.Init/Steps/InitializeNetwork.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ private async Task InitPeer()
372372
ForkInfo forkInfo = new(_api.SpecProvider!, syncServer.Genesis.Hash!);
373373

374374
ProtocolValidator protocolValidator = new(_api.NodeStatsManager!, _api.BlockTree, forkInfo, _api.LogManager);
375-
PooledTxsRequestor pooledTxsRequestor = new(_api.TxPool!, _api.Config<ITxPoolConfig>(), _api.SpecProvider, _api.BlockTree);
375+
PooledTxsRequestor pooledTxsRequestor = new(_api.TxPool!, _api.Config<ITxPoolConfig>(), _api.SpecProvider);
376376

377377
ISnapServer? snapServer = null;
378378
if (_syncConfig.SnapServingEnabled == true)

src/Nethermind/Nethermind.Network.Test/P2P/Subprotocols/Eth/V65/PooledTxsRequestorTests.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using Nethermind.TxPool;
1111
using NSubstitute;
1212
using NUnit.Framework;
13-
using Nethermind.Blockchain;
1413
using Nethermind.Core.Collections;
1514
using Nethermind.Core.Extensions;
1615
using Nethermind.Core.Specs;
@@ -20,7 +19,6 @@ namespace Nethermind.Network.Test.P2P.Subprotocols.Eth.V65
2019
public class PooledTxsRequestorTests
2120
{
2221
private readonly ITxPool _txPool = Substitute.For<ITxPool>();
23-
private IBlockTree _blockTree = Substitute.For<IBlockTree>();
2422
private ISpecProvider _specProvider = Substitute.For<ISpecProvider>();
2523
private readonly Action<GetPooledTransactionsMessage> _doNothing = static msg => msg.Dispose();
2624
private IPooledTxsRequestor _requestor;
@@ -35,7 +33,7 @@ public void TearDown()
3533
[Test]
3634
public void filter_properly_newPooledTxHashes()
3735
{
38-
_requestor = new PooledTxsRequestor(_txPool, new TxPoolConfig(), _specProvider, _blockTree);
36+
_requestor = new PooledTxsRequestor(_txPool, new TxPoolConfig(), _specProvider);
3937
using var skipped = new ArrayPoolList<Hash256>(2) { TestItem.KeccakA, TestItem.KeccakD };
4038
_requestor.RequestTransactions(_doNothing, skipped);
4139

@@ -48,7 +46,7 @@ public void filter_properly_newPooledTxHashes()
4846
[Test]
4947
public void filter_properly_already_pending_hashes()
5048
{
51-
_requestor = new PooledTxsRequestor(_txPool, new TxPoolConfig(), _specProvider, _blockTree);
49+
_requestor = new PooledTxsRequestor(_txPool, new TxPoolConfig(), _specProvider);
5250
using var skipped = new ArrayPoolList<Hash256>(3) { TestItem.KeccakA, TestItem.KeccakB, TestItem.KeccakC };
5351
_requestor.RequestTransactions(_doNothing, skipped);
5452

@@ -60,7 +58,7 @@ public void filter_properly_already_pending_hashes()
6058
[Test]
6159
public void filter_properly_discovered_hashes()
6260
{
63-
_requestor = new PooledTxsRequestor(_txPool, new TxPoolConfig(), _specProvider, _blockTree);
61+
_requestor = new PooledTxsRequestor(_txPool, new TxPoolConfig(), _specProvider);
6462

6563
using var request = new ArrayPoolList<Hash256>(3) { TestItem.KeccakA, TestItem.KeccakB, TestItem.KeccakC };
6664
using var expected = new ArrayPoolList<Hash256>(3) { TestItem.KeccakA, TestItem.KeccakB, TestItem.KeccakC };
@@ -71,7 +69,7 @@ public void filter_properly_discovered_hashes()
7169
[Test]
7270
public void can_handle_empty_argument()
7371
{
74-
_requestor = new PooledTxsRequestor(_txPool, new TxPoolConfig(), _specProvider, _blockTree);
72+
_requestor = new PooledTxsRequestor(_txPool, new TxPoolConfig(), _specProvider);
7573
using var skipped = new ArrayPoolList<Hash256>(0);
7674
_requestor.RequestTransactions(Send, skipped);
7775
_response.Should().BeEmpty();
@@ -82,7 +80,7 @@ public void filter_properly_hashes_present_in_hashCache()
8280
{
8381
ITxPool txPool = Substitute.For<ITxPool>();
8482
txPool.IsKnown(Arg.Any<Hash256>()).Returns(true);
85-
_requestor = new PooledTxsRequestor(txPool, new TxPoolConfig(), _specProvider, _blockTree);
83+
_requestor = new PooledTxsRequestor(txPool, new TxPoolConfig(), _specProvider);
8684

8785
using var request = new ArrayPoolList<Hash256>(2) { TestItem.KeccakA, TestItem.KeccakB };
8886
using var expected = new ArrayPoolList<Hash256>(0) { };

src/Nethermind/Nethermind.Network.Test/P2P/Subprotocols/Eth/V66/Eth66ProtocolHandlerTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Threading.Tasks;
88
using DotNetty.Buffers;
99
using FluentAssertions;
10-
using Nethermind.Blockchain;
1110
using Nethermind.Blockchain.Synchronization;
1211
using Nethermind.Consensus;
1312
using Nethermind.Core;
@@ -64,7 +63,6 @@ public class Eth66ProtocolHandlerTests
6463
private Block _genesisBlock = null!;
6564
private Eth66ProtocolHandler _handler = null!;
6665
private CompositeDisposable _disposables = null!;
67-
private IBlockTree _blockTree = null!;
6866

6967
[SetUp]
7068
public void Setup()
@@ -87,7 +85,6 @@ public void Setup()
8785
_syncManager.Head.Returns(_genesisBlock.Header);
8886
_syncManager.Genesis.Returns(_genesisBlock.Header);
8987
_timerFactory = Substitute.For<ITimerFactory>();
90-
_blockTree = Substitute.For<IBlockTree>();
9188
_handler = new Eth66ProtocolHandler(
9289
_session,
9390
_svc,
@@ -325,7 +322,7 @@ public void should_request_in_GetPooledTransactionsMessage_up_to_256_txs(int num
325322
_syncManager,
326323
RunImmediatelyScheduler.Instance,
327324
_transactionPool,
328-
new PooledTxsRequestor(_transactionPool, new TxPoolConfig(), _specProvider, _blockTree),
325+
new PooledTxsRequestor(_transactionPool, new TxPoolConfig(), _specProvider),
329326
_gossipPolicy,
330327
new ForkInfo(_specProvider, _genesisBlock.Header.Hash!),
331328
LimboLogs.Instance);

src/Nethermind/Nethermind.Network.Test/P2P/Subprotocols/Eth/V68/Eth68ProtocolHandlerTests.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
// SPDX-License-Identifier: LGPL-3.0-only
33

44
using System;
5-
using System.Collections.Generic;
65
using System.Net;
76
using DotNetty.Buffers;
87
using FluentAssertions;
9-
using Nethermind.Blockchain;
108
using Nethermind.Consensus;
119
using Nethermind.Core;
1210
using Nethermind.Core.Collections;
@@ -51,7 +49,6 @@ public class Eth68ProtocolHandlerTests
5149
private ITxGossipPolicy _txGossipPolicy = null!;
5250
private ITimerFactory _timerFactory = null!;
5351
private CompositeDisposable _disposables = null!;
54-
private IBlockTree _blockTree = null!;
5552

5653
[SetUp]
5754
public void Setup()
@@ -69,7 +66,6 @@ public void Setup()
6966
_transactionPool = Substitute.For<ITxPool>();
7067
_pooledTxsRequestor = Substitute.For<IPooledTxsRequestor>();
7168
_specProvider = Substitute.For<ISpecProvider>();
72-
_blockTree = Substitute.For<IBlockTree>();
7369
_gossipPolicy = Substitute.For<IGossipPolicy>();
7470
_genesisBlock = Build.A.Block.Genesis.TestObject;
7571
_syncManager.Head.Returns(_genesisBlock.Header);
@@ -234,7 +230,7 @@ public void should_divide_GetPooledTransactionsMessage_if_max_message_size_is_ex
234230
_syncManager,
235231
RunImmediatelyScheduler.Instance,
236232
_transactionPool,
237-
new PooledTxsRequestor(_transactionPool, new TxPoolConfig() { MaxTxSize = sizeOfOneTx }, _specProvider, _blockTree),
233+
new PooledTxsRequestor(_transactionPool, new TxPoolConfig() { MaxTxSize = sizeOfOneTx }, _specProvider),
238234
_gossipPolicy,
239235
new ForkInfo(_specProvider, _genesisBlock.Header.Hash!),
240236
LimboLogs.Instance,

src/Nethermind/Nethermind.Network/P2P/Subprotocols/Eth/PooledTxsRequestor.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,38 @@
22
// SPDX-License-Identifier: LGPL-3.0-only
33

44
using System;
5-
using Nethermind.Blockchain;
5+
using System.Linq;
66
using Nethermind.Core;
77
using Nethermind.Core.Caching;
88
using Nethermind.Core.Collections;
99
using Nethermind.Core.Crypto;
1010
using Nethermind.Core.Specs;
1111
using Nethermind.Network.P2P.Subprotocols.Eth.V62.Messages;
1212
using Nethermind.Network.P2P.Subprotocols.Eth.V65.Messages;
13-
using Nethermind.Specs.Forks;
1413
using Nethermind.TxPool;
1514

1615
namespace Nethermind.Network.P2P.Subprotocols.Eth
1716
{
18-
public class PooledTxsRequestor(ITxPool txPool, ITxPoolConfig txPoolConfig, ISpecProvider specProvider, IBlockTree blockTree) : IPooledTxsRequestor
17+
public class PooledTxsRequestor(ITxPool txPool, ITxPoolConfig txPoolConfig, ISpecProvider specProvider) : IPooledTxsRequestor
1918
{
2019
private const int MaxNumberOfTxsInOneMsg = 256;
2120
private readonly bool _blobSupportEnabled = txPoolConfig.BlobsSupport.IsEnabled();
2221
private readonly long _configuredMaxTxSize = txPoolConfig.MaxTxSize ?? long.MaxValue;
2322

24-
private readonly long _configuredMaxBlobTxSize = CalculateMaxBlobTxSize(txPoolConfig.MaxBlobTxSize, blockTree, specProvider);
23+
private readonly long _configuredMaxBlobTxSize = CalculateMaxBlobTxSize(txPoolConfig.MaxBlobTxSize, specProvider);
2524

26-
private static long CalculateMaxBlobTxSize(long? maxBlobTxSize, IBlockTree blockTree, ISpecProvider specProvider)
25+
private static long CalculateMaxBlobTxSize(long? maxBlobTxSize, ISpecProvider specProvider)
2726
{
2827
if (maxBlobTxSize is null)
2928
{
3029
return long.MaxValue;
3130
}
32-
IReleaseSpec currentSpec = blockTree.Head is null
33-
? specProvider.GenesisSpec
34-
: specProvider.GetSpec(blockTree.Head.Header);
3531

36-
return maxBlobTxSize.Value + (long)(Eip4844Constants.GasPerBlob * currentSpec.MaxBlobCount);
32+
ulong maxBlobCount = specProvider.TransitionActivations
33+
.Select(transitionActivation => specProvider.GetSpec(transitionActivation).MaxBlobCount)
34+
.DefaultIfEmpty(0ul)
35+
.Max();
36+
return maxBlobTxSize.Value + (long)(Eip4844Constants.GasPerBlob * maxBlobCount);
3737
}
3838

3939
private readonly ClockKeyCache<ValueHash256> _pendingHashes = new(MemoryAllowance.TxHashCacheSize);

0 commit comments

Comments
 (0)