-
Notifications
You must be signed in to change notification settings - Fork 479
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
Nethermind UI (initial) #8109
Open
benaadams
wants to merge
3
commits into
master
Choose a base branch
from
nethermind-ui
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Nethermind UI (initial) #8109
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -404,3 +404,5 @@ FodyWeavers.xsd | |
## Nethermind | ||
keystore/ | ||
/.githooks | ||
bundle.js | ||
src/Nethermind/Nethermind.Runner/wwwroot/js.map |
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
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
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 |
---|---|---|
|
@@ -63,6 +63,7 @@ public sealed class BlockchainProcessor : IBlockchainProcessor, IBlockProcessing | |
private readonly Stopwatch _stopwatch = new(); | ||
|
||
public event EventHandler<IBlockchainProcessor.InvalidBlockEventArgs>? InvalidBlock; | ||
public event EventHandler<BlockStatistics>? NewProcessingStatistics; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just pass through add/remove for simplicity? |
||
|
||
/// <summary> | ||
/// | ||
|
@@ -92,8 +93,12 @@ public BlockchainProcessor( | |
_blockTree.NewHeadBlock += OnNewHeadBlock; | ||
|
||
_stats = new ProcessingStats(stateReader, _logger); | ||
_stats.NewProcessingStatistics += OnNewProcessingStatistics; | ||
} | ||
|
||
private void OnNewProcessingStatistics(object? sender, BlockStatistics stats) | ||
=> NewProcessingStatistics?.Invoke(sender, stats); | ||
|
||
private void OnNewHeadBlock(object? sender, BlockEventArgs e) | ||
{ | ||
_lastProcessedBlock = DateTime.UtcNow; | ||
|
@@ -730,6 +735,7 @@ private bool RunSimpleChecksAheadOfProcessing(Block suggestedBlock, ProcessingOp | |
public void Dispose() | ||
{ | ||
_recoveryComplete = true; | ||
_stats.NewProcessingStatistics -= OnNewProcessingStatistics; | ||
_recoveryQueue.Writer.TryComplete(); | ||
_blockQueue.Writer.TryComplete(); | ||
_loopCancellationSource?.Dispose(); | ||
|
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
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
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 |
---|---|---|
|
@@ -2,19 +2,39 @@ | |
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
|
||
namespace Nethermind.Runner; | ||
|
||
public static class ConsoleHelpers | ||
{ | ||
private static LineInterceptingTextWriter _interceptingWriter; | ||
public static event EventHandler<string>? LineWritten; | ||
public static string[] GetRecentMessages() => _interceptingWriter.GetRecentMessages(); | ||
|
||
public static void EnableConsoleColorOutput() | ||
{ | ||
const int STD_OUTPUT_HANDLE = -11; | ||
const uint ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4; | ||
|
||
Console.OutputEncoding = System.Text.Encoding.UTF8; | ||
|
||
// Capture original out | ||
TextWriter originalOut = Console.Out; | ||
|
||
// Create our intercepting writer | ||
_interceptingWriter = new LineInterceptingTextWriter(originalOut); | ||
_interceptingWriter.LineWritten += (sender, line) => | ||
{ | ||
LineWritten?.Invoke(sender, line); | ||
}; | ||
|
||
// Redirect Console.Out | ||
Console.SetOut(_interceptingWriter); | ||
|
||
if (!OperatingSystem.IsWindowsVersionAtLeast(10)) | ||
return; | ||
|
||
|
@@ -41,3 +61,114 @@ public static void EnableConsoleColorOutput() | |
[DllImport("kernel32.dll")] | ||
private static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode); | ||
} | ||
|
||
|
||
public sealed class LineInterceptingTextWriter : TextWriter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need that? Doesn't NLog have something that would make it simpler for us? |
||
{ | ||
// Event raised every time a full line ending with Environment.NewLine is written | ||
public event EventHandler<string>? LineWritten; | ||
|
||
// The "real" underlying writer (i.e., the original Console.Out) | ||
private readonly TextWriter _underlyingWriter; | ||
|
||
// Buffer used to accumulate written data until we detect a new line | ||
private readonly StringBuilder _buffer; | ||
|
||
public LineInterceptingTextWriter(TextWriter underlyingWriter) | ||
{ | ||
_underlyingWriter = underlyingWriter ?? throw new ArgumentNullException(nameof(underlyingWriter)); | ||
_buffer = new StringBuilder(); | ||
} | ||
|
||
// You must override Encoding, even if just forwarding | ||
public override Encoding Encoding => _underlyingWriter.Encoding; | ||
|
||
// Overriding WriteLine(string) is handy for direct calls to Console.WriteLine(...). | ||
// However, you also want to handle the general case in Write(string). | ||
public override void WriteLine(string? value) | ||
{ | ||
Write(value); | ||
Write(Environment.NewLine); | ||
} | ||
|
||
public override void Write(string? value) | ||
{ | ||
if (value == null) | ||
{ | ||
return; | ||
} | ||
|
||
// Append to the buffer | ||
_buffer.Append(value); | ||
|
||
// Pass the data along to the underlying writer | ||
_underlyingWriter.Write(value); | ||
|
||
// Check if we can extract lines from the buffer | ||
CheckForLines(); | ||
} | ||
|
||
public override void Write(char value) | ||
{ | ||
_buffer.Append(value); | ||
_underlyingWriter.Write(value); | ||
CheckForLines(); | ||
} | ||
|
||
public override void Flush() | ||
{ | ||
base.Flush(); | ||
_underlyingWriter.Flush(); | ||
} | ||
|
||
private void CheckForLines() | ||
{ | ||
// Environment.NewLine might be "\r\n" or "\n" depending on platform | ||
// so let's find each occurrence and split it off | ||
string newLine = Environment.NewLine; | ||
|
||
while (true) | ||
{ | ||
// Find the next index of the new line | ||
int newLinePos = _buffer.ToString().IndexOf(newLine, StringComparison.Ordinal); | ||
|
||
// If there's no complete new line, break | ||
if (newLinePos < 0) | ||
{ | ||
break; | ||
} | ||
|
||
// Extract the line up to the new line | ||
string line = _buffer.ToString(0, newLinePos); | ||
|
||
// Remove that portion (including the new line) from the buffer | ||
_buffer.Remove(0, newLinePos + newLine.Length); | ||
|
||
// Raise the event | ||
OnLineWritten(line); | ||
} | ||
} | ||
|
||
public string[] GetRecentMessages() | ||
{ | ||
lock (_recentMessages) | ||
{ | ||
return _recentMessages.ToArray(); | ||
} | ||
} | ||
|
||
Queue<string> _recentMessages = new(capacity: 100); | ||
private void OnLineWritten(string line) | ||
{ | ||
lock (_recentMessages) | ||
{ | ||
if (_recentMessages.Count > 100) | ||
{ | ||
_recentMessages.Dequeue(); | ||
} | ||
_recentMessages.Enqueue(line); | ||
} | ||
// Raise the event, if subscribed | ||
LineWritten?.Invoke(this, line); | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potentially two lookups when we aren't sure if anyone is listening, seems wasteful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ForkChoiceHandler has already looked them up; however need to work out how to plumb it through