public ValidationStateChanged(string blockHashToHex, ulong index, bool start, BlockValidationResult blockValidationResult) { BlockHashToHex = blockHashToHex; Index = index; Start = start; BlockValidationResult = blockValidationResult; }
public GraphChainValidationResult ValidateGraphChain() { bool isValid = false; var blocks = new List <BlockValidationResult>(); try { LastBlockInfo lastBlockInfo = _repositoryManager.GetLastBlockInfo(); _logger.LogDebug("Last block IRI: '{0}'", lastBlockInfo.BlockIri); bool getPreviousBlock = true; string blockIriToObtain = lastBlockInfo.BlockIri; while (getPreviousBlock) { Block currentBlock = _repositoryManager.GetBlockByIri(blockIriToObtain); HashSet <Triple> triples = _hashingService.HandleTriplesBeforeHashing(currentBlock.BlockContent.Triples); string calculatedDataHash = _hashingService.CalculateHash(triples); BlockValidationResult blockValidationResult = _blockHashValidator.ValidateBlock(currentBlock, calculatedDataHash); if (blockValidationResult.IsValid) { _logger.LogInformation("Block '{0}' is valid.", currentBlock.BlockIri); } else { _logger.LogWarning("Block '{0}' is not valid. Details: {1}", currentBlock.BlockIri, blockValidationResult); getPreviousBlock = false; } blocks.Add(blockValidationResult); blockIriToObtain = currentBlock.BlockHeader.PreviousBlock; if (IsGenesisBlock(currentBlock)) { // for the first block IRI and its previous block IRI are the same, // so we do not go further _logger.LogDebug("Block '{0}' has '{1}' as the previous block; they are equal.", blockIriToObtain, currentBlock.BlockIri); getPreviousBlock = false; isValid = true; } } } catch (ReadingBlockException ex) { _logger.LogError("Exception was thrown while normalizing rdf graph.", ex); } catch (CalculatingHashException ex) { _logger.LogError("Exception was thrown while normalizing rdf graph.", ex); } return(new GraphChainValidationResult(isValid, blocks)); }
private async Task HandleInvalidBlock(IBlock block, BlockValidationResult blockValidationResult) { _logger?.Warn( $"Invalid block {block.BlockHashToHex} : {blockValidationResult.ToString()}. Height: *{block.Index}*"); MessageHub.Instance.Publish(new LockMining(false)); // Handle the invalid blocks according to their validation results. if ((int)blockValidationResult < 100) { _blockSet.AddBlock(block); } }
public IActionResult SubmitMinedBlock(string minerAddress, [FromBody] MinedBlockContract block) { MinedBlock minedBlock = block.ToDomainModel(minerAddress); BlockValidationResult validationResult = NodeService.TryAddBlock( minedBlock, out Block candidateBlock); if (validationResult != BlockValidationResult.Ok) { return(BadRequest(new Error(validationResult.GetEnumDescription()))); } return(CreatedAtRoute( "GetBlock", new { controller = "Blocks", index = candidateBlock.Index }, candidateBlock.ToContract())); }
/// <summary> /// Bad block means we'd like to discard this block immediately. /// </summary> /// <param name="result"></param> /// <returns></returns> public static bool IsBadBlock(this BlockValidationResult result) { return((int)result > 100); }
public static bool IsFailed(this BlockValidationResult result) { return((int)result > 10); }
public static bool IsSuccess(this BlockValidationResult result) { return((int)result < 11); }
public NeuraliumBlockValidationException(BlockValidationResult results) : base(results) { }