From 18906161e753c34e2aaa78d004dddc780ece6ec6 Mon Sep 17 00:00:00 2001 From: s2quake Date: Tue, 13 Feb 2024 10:20:49 +0900 Subject: [PATCH] style: Removed '#nullable disable' from the Libplanet.Net project (etc) --- .../BlockCandidateTableTest.cs | 4 ++-- Libplanet.Net/AppProtocolVersion.cs | 13 +++++------ Libplanet.Net/AssemblyInfo.cs | 1 - Libplanet.Net/BlockCompletion.cs | 22 +++++++++---------- Libplanet/Blockchain/Branch.cs | 6 ++--- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Libplanet.Net.Tests/BlockCandidateTableTest.cs b/Libplanet.Net.Tests/BlockCandidateTableTest.cs index 2cdc14532c..1c737075e0 100644 --- a/Libplanet.Net.Tests/BlockCandidateTableTest.cs +++ b/Libplanet.Net.Tests/BlockCandidateTableTest.cs @@ -24,14 +24,14 @@ public void Add() // Ignore existing key var firstBranch = new Branch( - new List<(Block, BlockCommit)> + new List<(Block, BlockCommit?)> { (_fx.Block2, TestUtils.CreateBlockCommit(_fx.Block2)), (_fx.Block3, TestUtils.CreateBlockCommit(_fx.Block3)), (_fx.Block4, TestUtils.CreateBlockCommit(_fx.Block4)), }); var secondBranch = new Branch( - new List<(Block, BlockCommit)> + new List<(Block, BlockCommit?)> { (_fx.Block3, TestUtils.CreateBlockCommit(_fx.Block3)), (_fx.Block4, TestUtils.CreateBlockCommit(_fx.Block4)), diff --git a/Libplanet.Net/AppProtocolVersion.cs b/Libplanet.Net/AppProtocolVersion.cs index cef570e309..fa8ffa952e 100644 --- a/Libplanet.Net/AppProtocolVersion.cs +++ b/Libplanet.Net/AppProtocolVersion.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Collections.Immutable; using System.Diagnostics.Contracts; @@ -34,7 +33,7 @@ namespace Libplanet.Net /// Optional extra data about the version. This can be used for any purpose /// by apps, such as a URL to download the software. /// - public readonly IValue Extra; + public readonly IValue? Extra; /// /// A signer who claims presence of a version. @@ -54,7 +53,7 @@ namespace Libplanet.Net /// Gets the . public AppProtocolVersion( int version, - IValue extra, + IValue? extra, ImmutableArray signature, Address signer ) @@ -121,7 +120,7 @@ public string Token /// A signed version claim. /// Thrown when is /// . - public static AppProtocolVersion Sign(PrivateKey signer, int version, IValue extra = null) + public static AppProtocolVersion Sign(PrivateKey signer, int version, IValue? extra = null) { if (signer is null) { @@ -201,7 +200,7 @@ public static AppProtocolVersion FromToken(string token) throw new FormatException($"Failed to parse a signature: {token}", e); } - IValue extra = null; + IValue? extra = null; if (pos >= 0) { pos++; @@ -246,7 +245,7 @@ other field values. A value of this struct can represent an invalid claim. */ /// [Pure] - public override bool Equals(object obj) => + public override bool Equals(object? obj) => obj is AppProtocolVersion other && Equals(other); /// @@ -279,7 +278,7 @@ public override string ToString() => string.Format( /// /// A deterministic message to sign. [Pure] - private static byte[] GetMessage(int version, IValue extra) + private static byte[] GetMessage(int version, IValue? extra) { byte[] msg = NetworkOrderBitsConverter.GetBytes(version); if (!(extra is null)) diff --git a/Libplanet.Net/AssemblyInfo.cs b/Libplanet.Net/AssemblyInfo.cs index 917a5d0248..9fbbfa9e81 100644 --- a/Libplanet.Net/AssemblyInfo.cs +++ b/Libplanet.Net/AssemblyInfo.cs @@ -1,4 +1,3 @@ -#nullable disable using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Libplanet.Benchmarks")] diff --git a/Libplanet.Net/BlockCompletion.cs b/Libplanet.Net/BlockCompletion.cs index 14ed17dc13..866f9dcb4c 100644 --- a/Libplanet.Net/BlockCompletion.cs +++ b/Libplanet.Net/BlockCompletion.cs @@ -1,4 +1,3 @@ -#nullable disable using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -16,16 +15,17 @@ namespace Libplanet.Net { internal class BlockCompletion + where TPeer : notnull { private readonly ILogger _logger; - private readonly Func _completionPredicate; + private readonly Func? _completionPredicate; private readonly int _window; private readonly ConcurrentDictionary _satisfiedBlocks; private readonly ConcurrentQueue _demands; private readonly SemaphoreSlim _demandEnqueued; private bool _started; - public BlockCompletion(Func completionPredicate = null, int window = 100) + public BlockCompletion(Func? completionPredicate = null, int window = 100) { _logger = Log.ForContext>(); _completionPredicate = completionPredicate; @@ -36,7 +36,7 @@ public BlockCompletion(Func completionPredicate = null, int win _demandEnqueued = new SemaphoreSlim(0); } - public delegate IAsyncEnumerable<(Block, BlockCommit)> BlockFetcher( + public delegate IAsyncEnumerable<(Block, BlockCommit?)> BlockFetcher( TPeer peer, IEnumerable blockHashes, CancellationToken cancellationToken @@ -182,7 +182,7 @@ public bool Satisfy(Block block) /// for the task to complete. /// An async enumerable that yields pairs of a fetched block and its source /// peer. It terminates when all demands are satisfied. - public async IAsyncEnumerable> Complete( + public async IAsyncEnumerable> Complete( IReadOnlyList peers, BlockFetcher blockFetcher, [EnumeratorCancellation] CancellationToken cancellationToken = default @@ -195,7 +195,7 @@ public async IAsyncEnumerable> Complete( var pool = new PeerPool(peers); var queue = - new AsyncProducerConsumerQueue>(); + new AsyncProducerConsumerQueue>(); Task producer = Task.Run(async () => { @@ -229,7 +229,7 @@ await pool.SpawnAsync( while (await queue.OutputAvailableAsync(cancellationToken)) { - Tuple triple; + Tuple triple; try { triple = await queue.DequeueAsync(cancellationToken); @@ -291,7 +291,7 @@ private Func CreateEnqueuing( IList blockHashes, BlockFetcher blockFetcher, CancellationToken cancellationToken, - AsyncProducerConsumerQueue> queue + AsyncProducerConsumerQueue> queue ) => async (peer, ct) => { @@ -307,10 +307,10 @@ AsyncProducerConsumerQueue> queue try { - ConfiguredCancelableAsyncEnumerable<(Block, BlockCommit)> blocks = + ConfiguredCancelableAsyncEnumerable<(Block, BlockCommit?)> blocks = blockFetcher(peer, blockHashes, cancellationToken) .WithCancellation(cancellationToken); - await foreach ((Block block, BlockCommit commit) in blocks) + await foreach ((Block block, BlockCommit? commit) in blocks) { _logger.Debug( "Downloaded block #{BlockIndex} {BlockHash} from {Peer}", @@ -405,7 +405,7 @@ public async Task SpawnAsync( cancellationToken.ThrowIfCancellationRequested(); } - if (_tasks.TryRemove(peer, out Task completeTask)) + if (_tasks.TryRemove(peer, out Task? completeTask)) { await completeTask; } diff --git a/Libplanet/Blockchain/Branch.cs b/Libplanet/Blockchain/Branch.cs index 236c09bd5f..f9d170854c 100644 --- a/Libplanet/Blockchain/Branch.cs +++ b/Libplanet/Blockchain/Branch.cs @@ -28,9 +28,9 @@ public class Branch /// /// /// - public Branch(IEnumerable<(Block, BlockCommit)> blocks) + public Branch(IEnumerable<(Block, BlockCommit?)> blocks) { - ImmutableArray<(Block, BlockCommit)> sorted = + ImmutableArray<(Block, BlockCommit?)> sorted = blocks.OrderBy(block => block.Item1.Index).ToImmutableArray(); if (!sorted.Any()) { @@ -71,6 +71,6 @@ public Branch(IEnumerable<(Block, BlockCommit)> blocks) /// /// /// - public ImmutableArray<(Block, BlockCommit)> Blocks { get; } + public ImmutableArray<(Block, BlockCommit?)> Blocks { get; } } }