Ejemplo n.º 1
0
        public TransactionsRegistryService(IStatesRepository statesRepository, IPredicatesRepository predicatesRepository, IRegistryMemPool registryMemPool,
                                           IIdentityKeyProvidersRegistry identityKeyProvidersRegistry, ICryptoService cryptoService, IConfigurationService configurationService,
                                           IServerCommunicationServicesRegistry serverCommunicationServicesRegistry, IPerformanceCountersRepository performanceCountersRepository,
                                           ISerializersFactory signatureSupportSerializersFactory, ITransactionsRegistryHelper transactionsRegistryHelper, IHashCalculationsRepository hashCalculationsRepository, ILoggerService loggerService)
        {
            _synchronizationContext              = statesRepository.GetInstance <ISynchronizationContext>();
            _registryGroupState                  = statesRepository.GetInstance <IRegistryGroupState>();
            _isBlockProducerPredicate            = predicatesRepository.GetInstance("IsBlockProducer");
            _transactionHashKey                  = identityKeyProvidersRegistry.GetTransactionsIdenityKeyProvider();
            _cryptoService                       = cryptoService;
            _configurationService                = configurationService;
            _serverCommunicationServicesRegistry = serverCommunicationServicesRegistry;
            _signatureSupportSerializersFactory  = signatureSupportSerializersFactory;
            _transactionsRegistryHelper          = transactionsRegistryHelper;
            _powCalculation                      = hashCalculationsRepository.Create(Globals.POW_TYPE);
            _hashCalculation                     = hashCalculationsRepository.Create(Globals.DEFAULT_HASH);
            _logger = loggerService.GetLogger(nameof(TransactionsRegistryService));
            TransformBlock <IRegistryMemPool, SortedList <ushort, ITransactionRegistryBlock> > deduplicateAndOrderTransactionRegisterBlocksBlock = new TransformBlock <IRegistryMemPool, SortedList <ushort, ITransactionRegistryBlock> >((Func <IRegistryMemPool, SortedList <ushort, ITransactionRegistryBlock> >)DeduplicateAndOrderTransactionRegisterBlocks);
            TransformBlock <SortedList <ushort, ITransactionRegistryBlock>, RegistryFullBlock> produceTransactionsFullBlock = new TransformBlock <SortedList <ushort, ITransactionRegistryBlock>, RegistryFullBlock>((Func <SortedList <ushort, ITransactionRegistryBlock>, RegistryFullBlock>)ProduceTransactionsFullBlock);
            ActionBlock <Tuple <RegistryFullBlock, RegistryShortBlock> > sendTransactionsBlocks = new ActionBlock <Tuple <RegistryFullBlock, RegistryShortBlock> >((Action <Tuple <RegistryFullBlock, RegistryShortBlock> >)SendTransactionsBlocks);
            TransformBlock <RegistryFullBlock, Tuple <RegistryFullBlock, RegistryShortBlock> > produceTransactionsShortBlock = new TransformBlock <RegistryFullBlock, Tuple <RegistryFullBlock, RegistryShortBlock> >((Func <RegistryFullBlock, Tuple <RegistryFullBlock, RegistryShortBlock> >)ProduceTransactionsShortBlock);

            deduplicateAndOrderTransactionRegisterBlocksBlock.LinkTo(produceTransactionsFullBlock);
            produceTransactionsFullBlock.LinkTo(produceTransactionsShortBlock);
            produceTransactionsShortBlock.LinkTo(sendTransactionsBlocks);

            _transactionsRegistryProducingFlow = deduplicateAndOrderTransactionRegisterBlocksBlock;


            _registryMemPool = registryMemPool;

            _nodeCountersService = performanceCountersRepository.GetInstance <NodeCountersService>();
        }
Ejemplo n.º 2
0
        public TransactionRegistryMemPool(ILoggerService loggerService, IIdentityKeyProvidersRegistry identityKeyProvidersRegistry, ICryptoService cryptoService,
                                          IStatesRepository statesRepository, ITransactionsRegistryHelper transactionsRegistryHelper, IHashCalculationsRepository hashCalculationsRepository)
        {
            _oldValue = 0;
            //_timer = new Timer(1000);
            //_timer.Elapsed += (s, e) =>
            //{
            //    if (_synchronizationContext.LastBlockDescriptor != null && _transactionRegisterBlocksOrdered.ContainsKey(_synchronizationContext.LastBlockDescriptor.BlockHeight))
            //    {
            //        _logger.Info($"MemPoolCount total = {_transactionRegisterBlocksOrdered[_synchronizationContext.LastBlockDescriptor.BlockHeight].Count};  delta = {_transactionRegisterBlocksOrdered[_synchronizationContext.LastBlockDescriptor.BlockHeight].Count - _oldValue}");
            //        _oldValue = _transactionRegisterBlocksOrdered[_synchronizationContext.LastBlockDescriptor.BlockHeight].Count;
            //    }
            //};
            //_timer.Start();

            _transactionHashKey                   = identityKeyProvidersRegistry.GetTransactionsIdenityKeyProvider();
            _logger                               = loggerService.GetLogger(nameof(TransactionRegistryMemPool));
            _transactionsIndicies                 = new Dictionary <ulong, int>();
            _transactionRegisterBlocksOrdered     = new Dictionary <ulong, SortedDictionary <int, ITransactionRegistryBlock> >();
            _transactionKeyBySourceKeys           = new Dictionary <ulong, Dictionary <ITransactionSourceKey, List <IKey> > >();
            _transactionsShortBlocks              = new Dictionary <ulong, Dictionary <ulong, HashSet <RegistryShortBlock> > >();
            _transactionOrderByTransactionKey     = new Dictionary <ulong, Dictionary <IKey, int> >();
            _transactionSourceKeyByTransactionKey = new Dictionary <ulong, Dictionary <IKey, ITransactionSourceKey> >();
            _cryptoService                        = cryptoService;
            _transactionsRegistryHelper           = transactionsRegistryHelper;
            _synchronizationContext               = statesRepository.GetInstance <ISynchronizationContext>();
            _hashCalculation                      = hashCalculationsRepository.Create(Globals.DEFAULT_HASH);
        }
Ejemplo n.º 3
0
        public static RegistryShortBlock GetTransactionsShortBlock(ulong syncBlockHeight, uint nonce, byte[] powHash, ulong blockHeight, byte round, IEnumerable <RegistryRegisterBlock> transactionRegisterBlocks, byte[] privateKey, ITransactionsRegistryHelper transactionsRegistryHelper)
        {
            byte[] publicKey = Ed25519.PublicKeyFromSeed(privateKey);

            SortedList <ushort, IKey> transactionHeaders = new SortedList <ushort, IKey>();

            ushort order = 0;

            foreach (var item in transactionRegisterBlocks)
            {
                transactionHeaders.Add(order++, transactionsRegistryHelper.GetTransactionRegistryTwiceHashedKey(item));
            }

            RegistryShortBlock transactionsShortBlock = new RegistryShortBlock
            {
                SyncBlockHeight         = syncBlockHeight,
                Nonce                   = nonce,
                PowHash                 = powHash ?? new byte[Globals.POW_HASH_SIZE],
                BlockHeight             = blockHeight,
                TransactionHeaderHashes = transactionHeaders,
                Signer                  = new Key32(publicKey)
            };

            return(transactionsShortBlock);
        }