-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Exit on block number * Some minor log
- Loading branch information
Showing
6 changed files
with
78 additions
and
1 deletion.
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
37 changes: 37 additions & 0 deletions
37
src/Nethermind/Nethermind.Blockchain.Test/ExitOnBlocknumberHandlerTests.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,37 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Config; | ||
using Nethermind.Core; | ||
using Nethermind.Core.Test.Builders; | ||
using Nethermind.Logging; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace Nethermind.Blockchain.Test; | ||
|
||
public class ExitOnBlocknumberHandlerTests | ||
{ | ||
[TestCase(10, false)] | ||
[TestCase(99, false)] | ||
[TestCase(100, true)] | ||
[TestCase(101, true)] | ||
public void Will_Exit_When_BlockReached(long blockNumber, bool exitReceived) | ||
{ | ||
IBlockTree blockTree = Substitute.For<IBlockTree>(); | ||
IProcessExitSource processExitSource = Substitute.For<IProcessExitSource>(); | ||
new ExitOnBlockNumberHandler(blockTree, processExitSource, 100, LimboLogs.Instance); | ||
|
||
blockTree.BlockAddedToMain += Raise.EventWith( | ||
new BlockReplacementEventArgs(Build.A.Block.WithNumber(blockNumber).TestObject)); | ||
|
||
if (exitReceived) | ||
{ | ||
processExitSource.Received().Exit(0); | ||
} | ||
else | ||
{ | ||
processExitSource.DidNotReceive().Exit(0); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Nethermind/Nethermind.Blockchain/ExitOnBlockNumberHandler.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,31 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Config; | ||
using Nethermind.Logging; | ||
|
||
namespace Nethermind.Blockchain; | ||
|
||
/// <summary> | ||
/// Just call exit if blocktree report added block is more than a specific number. | ||
/// </summary> | ||
public class ExitOnBlockNumberHandler | ||
{ | ||
public ExitOnBlockNumberHandler( | ||
IBlockTree blockTree, | ||
IProcessExitSource processExitSource, | ||
long initConfigExitOnBlockNumber, | ||
ILogManager logManager) | ||
{ | ||
ILogger logger = logManager.GetClassLogger(); | ||
|
||
blockTree.BlockAddedToMain += (sender, args) => | ||
{ | ||
if (args.Block.Number >= initConfigExitOnBlockNumber) | ||
{ | ||
logger.Info($"Block {args.Block.Number} reached. Exiting."); | ||
processExitSource.Exit(0); | ||
} | ||
}; | ||
} | ||
} |
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