Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved BlockProductionTimeout to config, increased BlockProductionTimeout #7378

Merged
merged 7 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Nethermind/Nethermind.Config/BlocksConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class BlocksConfig : IBlocksConfig

public bool PreWarmStateOnBlockProcessing { get; set; } = true;

public int BlockProductionTimeoutMs { get; set; } = 4000;

public string ExtraData
{
get
Expand Down
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.Config/IBlocksConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ public interface IBlocksConfig : IConfig
[ConfigItem(Description = "Try to pre-warm the state when processing blocks. Can lead to 2x speedup in main loop block processing.", DefaultValue = "True")]
bool PreWarmStateOnBlockProcessing { get; set; }

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

byte[] GetExtraDataBytes();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract class BlockProducerBase : IBlockProducer
private readonly IDifficultyCalculator _difficultyCalculator;
protected readonly ISpecProvider _specProvider;
private readonly ITxSource _txSource;
protected const int BlockProductionTimeout = 2000;
protected readonly int BlockProductionTimeoutMs;
protected readonly SemaphoreSlim _producingBlockLock = new(1);
protected ILogger Logger { get; }
protected readonly IBlocksConfig _blocksConfig;
Expand Down Expand Up @@ -70,14 +70,16 @@ protected BlockProducerBase(
_difficultyCalculator = difficultyCalculator ?? throw new ArgumentNullException(nameof(difficultyCalculator));
Logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
_blocksConfig = blocksConfig ?? throw new ArgumentNullException(nameof(blocksConfig));

BlockProductionTimeoutMs = _blocksConfig.BlockProductionTimeoutMs;
}

public async Task<Block?> BuildBlock(BlockHeader? parentHeader = null, IBlockTracer? blockTracer = null,
PayloadAttributes? payloadAttributes = null, CancellationToken? token = null)
{
token ??= default;
Block? block = null;
if (await _producingBlockLock.WaitAsync(BlockProductionTimeout, token.Value))
if (await _producingBlockLock.WaitAsync(BlockProductionTimeoutMs, token.Value))
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public virtual Block PrepareEmptyBlock(BlockHeader parent, PayloadAttributes? pa
blockHeader.Bloom = Bloom.Empty;
var block = new Block(blockHeader, Array.Empty<Transaction>(), Array.Empty<BlockHeader>(), payloadAttributes?.Withdrawals);

if (_producingBlockLock.Wait(BlockProductionTimeout))
if (_producingBlockLock.Wait(BlockProductionTimeoutMs))
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public override Block PrepareEmptyBlock(BlockHeader parent, PayloadAttributes? p

Block block = new(blockHeader, txs, Array.Empty<BlockHeader>(), payloadAttributes?.Withdrawals);

if (_producingBlockLock.Wait(BlockProductionTimeout))
if (_producingBlockLock.Wait(BlockProductionTimeoutMs))
{
try
{
Expand Down
8 changes: 5 additions & 3 deletions src/Nethermind/Nethermind.Runner.Test/ConfigFilesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,16 +361,18 @@ public void Arena_order_is_default(string configWildcard)
Test<INetworkConfig, int>(configWildcard, c => c.NettyArenaOrder, -1);
}

[TestCase("chiado", 17_000_000L, 5UL)]
[TestCase("gnosis", 17_000_000L, 5UL)]
[TestCase("chiado", 17_000_000L, 5UL, 3000)]
[TestCase("gnosis", 17_000_000L, 5UL, 3000)]
[TestCase("mainnet", 30_000_000L)]
[TestCase("sepolia", 30_000_000L)]
[TestCase("holesky", 30_000_000L)]
[TestCase("^chiado ^gnosis ^mainnet ^sepolia ^holesky")]
public void Blocks_defaults_are_correct(string configWildcard, long? targetBlockGasLimit = null, ulong secondsPerSlot = 12)
public void Blocks_defaults_are_correct(string configWildcard, long? targetBlockGasLimit = null, ulong secondsPerSlot = 12, int blockProductionTimeout = 4000)
{
Test<IBlocksConfig, long?>(configWildcard, c => c.TargetBlockGasLimit, targetBlockGasLimit);
Test<IBlocksConfig, ulong>(configWildcard, c => c.SecondsPerSlot, secondsPerSlot);
Test<IBlocksConfig, int>(configWildcard, c => c.BlockProductionTimeoutMs, blockProductionTimeout);

}

[Test]
Expand Down
3 changes: 2 additions & 1 deletion src/Nethermind/Nethermind.Runner/configs/chiado.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"Blocks": {
"SecondsPerSlot": 5,
"BlockProductionTimeoutMs": 3000,
"TargetBlockGasLimit": 17000000
},
"Aura": {
Expand All @@ -43,4 +44,4 @@
16
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"Blocks": {
"SecondsPerSlot": 5,
"BlockProductionTimeoutMs": 3000,
"TargetBlockGasLimit": 17000000
},
"Receipt": {
Expand Down
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Runner/configs/gnosis.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"Blocks": {
"SecondsPerSlot": 5,
"BlockProductionTimeoutMs": 3000,
"TargetBlockGasLimit": 17000000
},
"Mining": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"Blocks": {
"SecondsPerSlot": 5,
"BlockProductionTimeoutMs": 3000,
"TargetBlockGasLimit": 17000000
},
"Receipt": {
Expand Down