Ejemplo n.º 1
0
        public override ServiceBlock GetBlockProposal(VoteProcess <ServiceBlock> voteProcess, ServiceBlock lastBlock, int revision)
        {
            var remove    = new HashSet <long>();
            var generator = new ServiceBlockGenerator(_coreChain, _serviceChain, _maintainChain, lastBlock);

            lock (_lock)
            {
                foreach (var item in _transactions)
                {
                    var transaction = item.Value;
                    if (_blockStorage.HistoryContainsTransactionOrRegistration(transaction) != TransactionResultTypes.Ok)
                    {
                        remove.Add(transaction.UniqueIdentifier);
                        continue;
                    }

                    if (generator.ConsumeTransaction(transaction as ServiceTransaction) != TransactionResultTypes.Ok)
                    {
                        remove.Add(transaction.UniqueIdentifier);
                    }
                }

                foreach (var item in remove)
                {
                    _transactions.Remove(item);
                }
            }

            return(generator.GenerateBlock(voteProcess.LocalIssuer, revision));
        }
Ejemplo n.º 2
0
        public override bool CheckBlockProposal(VoteProcess <MaintainBlock> voteProcess, MaintainBlock block, MaintainBlock lastBlock, out HashSet <long> invalidTransactionIds)
        {
            var generator = new MaintainBlockGenerator(_maintainChain, lastBlock);

            invalidTransactionIds = generator.CheckBlock(block);

            if (invalidTransactionIds.Count > 0)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public override void NewBlockAvailable(VoteProcess <MaintainBlock> voteProcess, BlockData <MaintainBlock> blockData, BlockProposalSignatures blockProposalSignatures)
        {
            base.NewBlockAvailable(voteProcess, blockData, blockProposalSignatures);

            var block = blockData.Block;

            TaskRunner.Run(async() =>
            {
                await _node.SyncManager.HandleBlockData(blockData, GetVoteConnections());
                await _node.NodeServer.Broadcast(new NodeBlockDataMessage(block.ChainType, block.BlockId, block.ChainId, block.ChainIndex, _node.NodeConfiguration.LocaleNodeInfo.IsPublicEndPoint ? null : blockData)
                {
                    SignKey = _node.NodeConfiguration.LocaleNodePrivateKey
                }, null);
            });
        }
Ejemplo n.º 4
0
        public override void NewBlockAvailable(VoteProcess <ServiceBlock> voteProcess, BlockData <ServiceBlock> blockData, BlockProposalSignatures blockProposalSignatures)
        {
            base.NewBlockAvailable(voteProcess, blockData, blockProposalSignatures);

            var block = blockData.Block;

            if (block.Issuer == LocalKeyIndex)
            {
                var message = new NodeTransactionMessage(new ServiceBlockCoreTransaction(blockData.Block, blockProposalSignatures, _chainAccountId)
                {
                    SignKey = _localKey
                });
                message.ToByteArray();

                _node.TransactionManager.AddNodeTransaction(message, null);
                _ = _node.NodeServer.Broadcast(message, null);
            }
        }
Ejemplo n.º 5
0
        public override MaintainBlock GetBlockProposal(VoteProcess <MaintainBlock> voteProcess, MaintainBlock lastBlock, int revision)
        {
            var remove    = new HashSet <long>();
            var generator = new MaintainBlockGenerator(_maintainChain, lastBlock);

            lock (_lock)
            {
                foreach (var item in _transactions)
                {
                    var transaction = item.Value;
                    if (_blockStorage.HistoryContainsTransactionOrRegistration(transaction) != TransactionResultTypes.Ok)
                    {
                        remove.Add(transaction.UniqueIdentifier);
                        continue;
                    }

                    try
                    {
                        if (generator.ConsumeTransaction(transaction as MaintainTransaction) != TransactionResultTypes.Ok)
                        {
                            remove.Add(transaction.UniqueIdentifier);
                        }
                    }
                    catch (Exception ex)
                    {
                        remove.Add(transaction.UniqueIdentifier);
                        Log.HandleException(ex, this);
                    }
                }

                foreach (var item in remove)
                {
                    _transactions.Remove(item);
                }
            }

            return(generator.GenerateBlock(voteProcess.LocalIssuer, revision));
        }