Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="deliver"></param>
        /// <returns></returns>
        private async Task Delivered(Interpreted deliver)
        {
            Guard.Argument(deliver, nameof(deliver)).NotNull();
            _logger.Here().Information("Delivered");
            try
            {
                foreach (var next in deliver.Blocks.Where(x => x.Data != null))
                {
                    var blockGraph = await _unitOfWork.BlockGraphRepository.GetAsync(x =>
                                                                                     new ValueTask <bool>(x.Block.Hash.Equals(next.Hash) && x.Block.Round == next.Round));

                    if (blockGraph == null)
                    {
                        _logger.Here()
                        .Error(
                            "Unable to find the matching block - Hash: {@Hash} Round: {@Round} from node {@Node}",
                            next.Hash, next.Round, next.Node);
                        continue;
                    }

                    await RemoveBlockGraph(blockGraph, next);

                    var block  = Helper.Util.DeserializeFlatBuffer <BlockHeaderProto>(next.Data);
                    var exists = await _validator.BlockExists(block);

                    if (exists == VerifyResult.AlreadyExists)
                    {
                        continue;
                    }

                    var verifyBlockGraphSignatureNodeRound =
                        await _validator.VerifyBlockGraphSignatureNodeRound(blockGraph);

                    if (verifyBlockGraphSignatureNodeRound == VerifyResult.Succeed)
                    {
                        var saved = await _unitOfWork.DeliveredRepository.PutAsync(block.ToIdentifier(), block);

                        if (!saved)
                        {
                            _logger.Here().Error("Unable to save the block: {@MerkleRoot}", block.MerkelRoot);
                        }

                        _logger.Here().Information("Saved block to Delivered");
                        continue;
                    }

                    _logger.Here()
                    .Error("Unable to verify the node signatures - Hash: {@Hash} Round: {@Round} from node {@Node}",
                           next.Hash, next.Round, next.Node);
                }
            }
            catch (Exception ex)
            {
                _logger.Here().Error(ex, "Delivered error");
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="interpreted"></param>
        private async Task BlockmaniaCallback(object sender, Interpreted interpreted)
        {
            if (interpreted == null)
            {
                throw new ArgumentNullException(nameof(interpreted));
            }

            var interpretedList = new List <BlockID>();

            try
            {
                foreach (var block in interpreted.Blocks)
                {
                    var blockGraphs = await unitOfWork.BlockGraph.GetWhere(x => x.Block.Hash.Equals(block.Hash) && x.Block.Node.Equals(httpService.NodeIdentity));

                    if (blockGraphs.Any() != true)
                    {
                        logger.Warning($"<<< BoostGraphActor.BlockmaniaCallback >>>: Unable to find blocks with - Hash: {block.Hash} Round: {block.Round} from node {block.Node}");
                        continue;
                    }

                    var blockGraph = blockGraphs.FirstOrDefault(x => x.Block.Node.Equals(httpService.NodeIdentity) && x.Block.Round.Equals(block.Round));
                    if (blockGraph == null)
                    {
                        logger.Error($"<<< BoostGraphActor.BlockmaniaCallback >>>: Unable to find matching block - Hash: {block.Hash} Round: {block.Round} from node {block.Node}");
                        continue;
                    }

                    interpretedList.Add(new BlockID(blockGraph.Block.Hash, blockGraph.Block.Node, blockGraph.Block.Round, blockGraph.Block.SignedBlock));
                }

                // Should return success blocks instead of bool.
                var success = await interpretActorProvider.Interpret(new InterpretBlocksMessage(httpService.NodeIdentity, interpretedList));

                if (success)
                {
                    await unitOfWork.Job.SetStates(interpretedList.Select(x => x.Hash), JobState.Polished);
                }
            }
            catch (Exception ex)
            {
                logger.Error($"<<< BoostGraphActor.BlockmaniaCallback >>>: {ex.ToString()}");
            }
        }
Exemple #3
0
 public InterpretedEventArgs(Interpreted interpreted)
 {
     Interpreted = interpreted;
     Round       = Interpreted.Round;
 }