コード例 #1
0
ファイル: ValidationStateChanged.cs プロジェクト: wyk125/AElf
 public ValidationStateChanged(string blockHashToHex, ulong index, bool start,
                               BlockValidationResult blockValidationResult)
 {
     BlockHashToHex        = blockHashToHex;
     Index                 = index;
     Start                 = start;
     BlockValidationResult = blockValidationResult;
 }
コード例 #2
0
        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));
        }
コード例 #3
0
ファイル: BlockSynchronizer.cs プロジェクト: pskbank64/AElf
        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);
            }
        }
コード例 #4
0
        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()));
        }
コード例 #5
0
 /// <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);
 }
コード例 #6
0
 public static bool IsFailed(this BlockValidationResult result)
 {
     return((int)result > 10);
 }
コード例 #7
0
 public static bool IsSuccess(this BlockValidationResult result)
 {
     return((int)result < 11);
 }
コード例 #8
0
 public NeuraliumBlockValidationException(BlockValidationResult results) : base(results)
 {
 }