Skip to content

Commit c19e884

Browse files
authored
fixed warnings (#47)
* removed redundant package references contained already in DirectoryBuilder.props incremente version to 0.8.* * fixed warnings
1 parent dc0ed50 commit c19e884

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

.editorconfig

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dotnet_style_null_propagation = true:warning
99
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
1010
dotnet_style_prefer_auto_properties = true:suggestion
1111
dotnet_style_object_initializer = true:warning
12+
dotnet_style_collection_initializer = true:suggestion
1213

1314
[*.xml]
1415
indent_style = space
@@ -144,7 +145,7 @@ dotnet_diagnostic.CA1001.severity = suggestion
144145
dotnet_diagnostic.CA1028.severity = suggestion
145146

146147
# CA1062: Validate arguments of public methods
147-
dotnet_diagnostic.CA1062.severity = suggestion
148+
dotnet_diagnostic.CA1062.severity = silent
148149

149150
# CA1308: Normalize strings to uppercase
150151
dotnet_diagnostic.CA1308.severity = silent

src/MithrilShards.Chain.Bitcoin/Protocol/Processors/AnnouncerProcessor.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ protected override ValueTask OnPeerAttachedAsync()
6262
/// <returns></returns>
6363
protected override async ValueTask OnPeerHandshakedAsync()
6464
{
65-
HandshakeProcessor.HandshakeProcessorStatus handshakeStatus = PeerContext.Features.Get<HandshakeProcessor.HandshakeProcessorStatus>();
65+
HandshakeProcessor.HandshakeProcessorStatus handshakeStatus = PeerContext.Features.Get<HandshakeProcessor.HandshakeProcessorStatus>()!;
6666

6767
VersionMessage peerVersion = handshakeStatus.PeerVersion!;
68+
logger.LogDebug("Peer {PeerId} handshake completed. Peer version: {PeerVersion}", PeerContext.PeerId, peerVersion);
6869

6970
await SendMessageAsync(minVersion: KnownVersion.V70012, new SendHeadersMessage()).ConfigureAwait(false);
7071
}

src/MithrilShards.Chain.Bitcoin/Protocol/Processors/SynchronizationProcessor.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ public SynchronizationProcessor(ILogger<SynchronizationProcessor> logger,
8585

8686
public void OnPeriodicWorkException(IPeriodicWork failedWork, Exception ex, ref IPeriodicWorkExceptionHandler.Feedback feedback)
8787
{
88+
ArgumentNullException.ThrowIfNull(failedWork, nameof(failedWork));
89+
ArgumentNullException.ThrowIfNull(ex, nameof(ex));
90+
ArgumentNullException.ThrowIfNull(feedback, nameof(feedback));
91+
92+
logger.LogError(ex, "Error in {FailedWork}", failedWork);
93+
8894
string? disconnectionReason = failedWork switch
8995
{
9096
IPeriodicWork work when work == _headerSyncLoop => "Peer header syncing loop had failures.",
@@ -116,7 +122,7 @@ protected override ValueTask OnPeerAttachedAsync()
116122
/// <returns></returns>
117123
protected override async ValueTask OnPeerHandshakedAsync()
118124
{
119-
HandshakeProcessor.HandshakeProcessorStatus handshakeStatus = PeerContext.Features.Get<HandshakeProcessor.HandshakeProcessorStatus>();
125+
HandshakeProcessor.HandshakeProcessorStatus handshakeStatus = PeerContext.Features.Get<HandshakeProcessor.HandshakeProcessorStatus>()!;
120126

121127
VersionMessage peerVersion = handshakeStatus.PeerVersion!;
122128

@@ -195,7 +201,7 @@ got back an empty response. */
195201
HashStop = UInt256.Zero
196202
};
197203

198-
await SendMessageAsync(newGetHeaderRequest).ConfigureAwait(false);
204+
await SendMessageAsync(newGetHeaderRequest, cancellationToken).ConfigureAwait(false);
199205
}
200206

201207
CheckSyncStallingLocked(bestBlockHeader);

src/MithrilShards.Core/Network/PeerContextFactory.cs

+2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ public PeerContextFactory(ILogger<PeerContextFactory<TPeerContext>> logger,
2828

2929
public virtual IPeerContext CreateIncomingPeerContext(string peerId, EndPoint localEndPoint, EndPoint remoteEndPoint, INetworkMessageWriter messageWriter)
3030
{
31+
_logger.LogTrace("Creating incoming peer context for {PeerId} from {RemoteEndPoint}", peerId, remoteEndPoint);
3132
return Create(PeerConnectionDirection.Inbound, peerId, localEndPoint, remoteEndPoint, messageWriter);
3233
}
3334

3435
public virtual IPeerContext CreateOutgoingPeerContext(string peerId, EndPoint localEndPoint, OutgoingConnectionEndPoint outgoingConnectionEndPoint, INetworkMessageWriter messageWriter)
3536
{
37+
_logger.LogTrace("Creating outgoing peer context for {PeerId} to {RemoteEndPoint}", peerId, outgoingConnectionEndPoint.EndPoint);
3638
IPeerContext peerContext = Create(PeerConnectionDirection.Outbound, peerId, localEndPoint, outgoingConnectionEndPoint.EndPoint, messageWriter);
3739
peerContext.Features.Set(outgoingConnectionEndPoint);
3840

src/MithrilShards.Core/Network/Protocol/Processors/NetworkMessageProcessorFactory.cs

+13-5
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@ public NetworkMessageProcessorFactory(ILogger<INetworkMessageProcessorFactory> l
2828
/// <param name="peerContext">The peer context.</param>
2929
public async Task StartProcessorsAsync(IPeerContext peerContext)
3030
{
31-
if (peerContext is null)
32-
{
33-
ThrowHelper.ThrowArgumentNullException(nameof(peerContext));
34-
}
31+
ArgumentNullException.ThrowIfNull(peerContext, nameof(peerContext));
3532

3633
IEnumerable<INetworkMessageProcessor> processors = _serviceProvider.GetService<IEnumerable<INetworkMessageProcessor>>()!;
3734
foreach (INetworkMessageProcessor processor in processors)
3835
{
3936
// skip processors that aren't enabled
4037
if (!processor.Enabled) continue;
4138

39+
if (_logger.IsEnabled(LogLevel.Trace))
40+
{
41+
_logger.LogTrace("Attaching processor {ProcessorType} to peer {PeerId}", processor.GetType().Name, peerContext.PeerId);
42+
}
43+
4244
peerContext.AttachNetworkMessageProcessor(processor);
4345
await processor.AttachAsync(peerContext).ConfigureAwait(false);
4446
}
@@ -48,6 +50,12 @@ public async Task StartProcessorsAsync(IPeerContext peerContext)
4850

4951
public async ValueTask ProcessMessageAsync(INetworkMessage message, IPeerContext peerContext, CancellationToken cancellation)
5052
{
51-
await peerContext.Features.Get<PeerNetworkMessageProcessorContainer>().ProcessMessageAsync(message, cancellation).ConfigureAwait(false);
53+
ArgumentNullException.ThrowIfNull(message, nameof(message));
54+
ArgumentNullException.ThrowIfNull(peerContext, nameof(peerContext));
55+
56+
var container = peerContext.Features.Get<PeerNetworkMessageProcessorContainer>()
57+
?? throw new InvalidOperationException("PeerNetworkMessageProcessorContainer not found in peer context.");
58+
59+
await container.ProcessMessageAsync(message, cancellation).ConfigureAwait(false);
5260
}
5361
}

src/MithrilShards.Example/Network/ExamplePeerContextFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public override IPeerContext CreateOutgoingPeerContext(string peerId, EndPoint l
3030
/// Since this information may be important to us, we decide to have an explicit property in our <see cref="ExamplePeerContext"/> so we can
3131
/// access that information easily in our code.
3232
/// Note that we set that information in our <see cref="Client.ExampleRequiredConnection"/> connector.
33-
string myExtraInformation = (string)peerContext.Features.Get<OutgoingConnectionEndPoint>().Items[nameof(ExampleEndPoint.MyExtraInformation)];
33+
string myExtraInformation = (string)peerContext.Features.Get<OutgoingConnectionEndPoint>()!.Items[nameof(ExampleEndPoint.MyExtraInformation)];
3434

3535
peerContext.MyExtraInformation = myExtraInformation;
3636

0 commit comments

Comments
 (0)