public void AcceptExternalBlock(EncodedBlock encodedBlock)
        {
            _backgroundQueue.Enqueue(token => new Task(() =>
            {
                if (encodedBlock?.Base64Block != null &&
                    !_encodedBlocksStorage.EncodedBlocksIds.Contains(encodedBlock.Id))
                {
                    _encodedBlocksStorage.EncodedBlocksIds.Add(encodedBlock.Id);

                    var blockchainJson = Encoding.UTF8.GetString(Convert.FromBase64String(encodedBlock.Base64Block));
                    var incomingBlock  = BlockchainConverter.DeserializeBlock(blockchainJson);

                    var result = AcceptBlock(incomingBlock, encodedBlock.NodeSenderId);
                    if (result.IsSuccess)
                    {
                        DistributeBlock(encodedBlock);
                    }
                }
            }, token));
        }
        public BaseResponse <bool> SynchronizeWithOtherNodes()
        {
            var blocks = new ConcurrentDictionary <string, DAM.Block.BlockBase>();

            ServerNodes.Values.ParallelForEach(node =>
            {
                var json = node.HubConnection.Invoke <string>(nameof(ConsensusHub.GetLastBlockJson));
                if (json != null)
                {
                    blocks.TryAdd(node.Id, BlockchainConverter.DeserializeBlock(json));
                }
            });

            var currentLastBlock = _blockchainService.GetLastBlock();

            if (blocks.IsEmpty && currentLastBlock == null)
            {
                return(new ErrorResponse <bool>(
                           "The current blockchain is empty and there is no block to synchronize", false));
            }

            if (blocks.IsEmpty)
            {
                return(new ErrorResponse <bool>("There is no blocks to synchronize with!", false));
            }

            var longestBlock = blocks.OrderBy(b => b.Value.Depth).ThenBy(b => b.Value.Header.TimeStamp).First();

            if (currentLastBlock == null)
            {
                return(AcceptBlock(longestBlock.Value, longestBlock.Key));
            }

            return(currentLastBlock.Depth >= longestBlock.Value.Depth
                ? new SuccessResponse <bool>("There is no need for synchronization!", false)
                : AcceptBlock(longestBlock.Value, longestBlock.Key));
        }