private async Task OnPartialValidationCompletedCallbackAsync(PartialValidationResult validationResult) { this.logger.LogTrace("({0}:'{1}')", nameof(validationResult), validationResult); if (validationResult.Succeeded) { await this.OnPartialValidationSucceededAsync(validationResult.ChainedHeaderBlock).ConfigureAwait(false); } else { var peersToBan = new List <INetworkPeer>(); lock (this.peerLock) { List <int> peerIdsToBan = this.chainedHeaderTree.PartialOrFullValidationFailed(validationResult.ChainedHeaderBlock.ChainedHeader); this.logger.LogDebug("Validation of block '{0}' failed, banning and disconnecting {1} peers.", validationResult.ChainedHeaderBlock, peerIdsToBan.Count); foreach (int peerId in peerIdsToBan) { if (this.peersByPeerId.TryGetValue(peerId, out INetworkPeer peer)) { peersToBan.Add(peer); } } } foreach (INetworkPeer peer in peersToBan) { this.peerBanning.BanAndDisconnectPeer(peer.RemoteSocketEndpoint, validationResult.BanDurationSeconds, validationResult.BanReason); } } this.logger.LogTrace("(-)"); }
private async Task OnEnqueueAsync(PartialValidationItem item, CancellationToken cancellationtoken) { this.logger.LogTrace("({0}:'{1}')", nameof(item), item); var validationContext = new ValidationContext { Block = item.ChainedHeaderBlock.Block }; // TODO: pass the tip. await this.consensusRules.PartialValidationAsync(validationContext, null).ConfigureAwait(false); var partialValidationResult = new PartialValidationResult { ChainedHeaderBlock = item.ChainedHeaderBlock, BanDurationSeconds = validationContext.BanDurationSeconds, BanReason = validationContext.Error != null ? $"Invalid block received: {validationContext.Error.Message}" : string.Empty, Succeeded = validationContext.Error != null }; await item.PartialValidationCompletedAsyncCallback(partialValidationResult).ConfigureAwait(false); this.logger.LogTrace("(-)"); }
public void Returns_correct_boolean_according_to_given_input_boolean(bool input, bool expected) { var sut = new PartialValidationResult(input); Assert.Equal(expected, sut.IsValid); }