-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge/continous block improvement (#4488)
* Make Payload Production continuous improving block while in slot. * Remove whitespace * Change timings for more reliable tests * Comments + better naming * Move to DateTimeOffset * Add more logs * Review improvements * Move to TimeSpan's * Fix merging master
- Loading branch information
1 parent
8f26979
commit c21b094
Showing
14 changed files
with
642 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...mind/Nethermind.Merge.Plugin.Test/EngineModuleTests.MockBlockImprovementContextFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2021 Demerzel Solutions Limited | ||
// This file is part of the Nethermind library. | ||
// | ||
// The Nethermind library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The Nethermind library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Nethermind.Consensus.Producers; | ||
using Nethermind.Core; | ||
using Nethermind.Core.Extensions; | ||
using Nethermind.Evm.Tracing; | ||
using Nethermind.Merge.Plugin.BlockProduction; | ||
|
||
namespace Nethermind.Merge.Plugin.Test; | ||
|
||
public partial class EngineModuleTests | ||
{ | ||
private class MockBlockImprovementContextFactory : IBlockImprovementContextFactory | ||
{ | ||
public IBlockImprovementContext StartBlockImprovementContext(Block currentBestBlock, BlockHeader parentHeader, PayloadAttributes payloadAttributes, DateTimeOffset startDateTime) => | ||
new MockBlockImprovementContext(currentBestBlock, startDateTime); | ||
} | ||
|
||
private class MockBlockImprovementContext : IBlockImprovementContext | ||
{ | ||
public MockBlockImprovementContext(Block currentBestBlock, DateTimeOffset startDateTime) | ||
{ | ||
CurrentBestBlock = currentBestBlock; | ||
StartDateTime = startDateTime; | ||
ImprovementTask = Task.FromResult((Block?)currentBestBlock); | ||
} | ||
|
||
public void Dispose() => Disposed = true; | ||
public Task<Block?> ImprovementTask { get; } | ||
public Block? CurrentBestBlock { get; } | ||
public bool Disposed { get; private set; } | ||
public DateTimeOffset StartDateTime { get; } | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...d/Nethermind.Merge.Plugin.Test/EngineModuleTests.StoringBlockImprovementContextFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) 2021 Demerzel Solutions Limited | ||
// This file is part of the Nethermind library. | ||
// | ||
// The Nethermind library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The Nethermind library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Nethermind.Consensus.Producers; | ||
using Nethermind.Core; | ||
using Nethermind.Core.Extensions; | ||
using Nethermind.Evm.Tracing; | ||
using Nethermind.Merge.Plugin.BlockProduction; | ||
|
||
namespace Nethermind.Merge.Plugin.Test; | ||
|
||
public partial class EngineModuleTests | ||
{ | ||
private class StoringBlockImprovementContextFactory : IBlockImprovementContextFactory | ||
{ | ||
private readonly IBlockImprovementContextFactory _blockImprovementContextFactory; | ||
public IList<IBlockImprovementContext> CreatedContexts { get; } = new List<IBlockImprovementContext>(); | ||
|
||
public event EventHandler<ImprovementStartedEventArgs>? ImprovementStarted; | ||
|
||
public StoringBlockImprovementContextFactory(IBlockImprovementContextFactory blockImprovementContextFactory) | ||
{ | ||
_blockImprovementContextFactory = blockImprovementContextFactory; | ||
} | ||
|
||
public IBlockImprovementContext StartBlockImprovementContext(Block currentBestBlock, BlockHeader parentHeader, PayloadAttributes payloadAttributes, DateTimeOffset startDateTime) | ||
{ | ||
IBlockImprovementContext blockImprovementContext = _blockImprovementContextFactory.StartBlockImprovementContext(currentBestBlock, parentHeader, payloadAttributes, startDateTime); | ||
CreatedContexts.Add(blockImprovementContext); | ||
Task.Run(() => ImprovementStarted?.Invoke(this, new ImprovementStartedEventArgs(blockImprovementContext))); | ||
return blockImprovementContext; | ||
} | ||
} | ||
|
||
private class ImprovementStartedEventArgs : EventArgs | ||
{ | ||
public IBlockImprovementContext BlockImprovementContext { get; } | ||
|
||
public ImprovementStartedEventArgs(IBlockImprovementContext blockImprovementContext) | ||
{ | ||
BlockImprovementContext = blockImprovementContext; | ||
} | ||
} | ||
} |
Oops, something went wrong.