Пример #1
0
        public AddTxResult AddTransaction(Transaction transaction, long blockNumber, bool doNotEvict = false)
        {
            Metrics.PendingTransactionsReceived++;
            if (doNotEvict)
            {
                _nonEvictableTransactions.TryAdd(transaction.Hash, true);
                if (_logger.IsDebug)
                {
                    _logger.Debug($"Added a transaction: {transaction.Hash} that will not be evicted.");
                }
            }

            // beware we are discarding here the old signature scheme without ChainId
            if (transaction.Signature.GetChainId == null)
            {
                Metrics.PendingTransactionsDiscarded++;
                return(AddTxResult.OldScheme);
            }

            if (transaction.Signature.GetChainId != _specProvider.ChainId)
            {
                Metrics.PendingTransactionsDiscarded++;
                return(AddTxResult.InvalidChainId);
            }

            if (!_pendingTransactions.TryAdd(transaction.Hash, transaction))
            {
                Metrics.PendingTransactionsKnown++;
                return(AddTxResult.AlreadyKnown);
            }

            if (_txStorage.Get(transaction.Hash) != null)
            {
                Metrics.PendingTransactionsKnown++;
                return(AddTxResult.AlreadyKnown);
            }

            transaction.SenderAddress = _ecdsa.RecoverAddress(transaction, blockNumber);
            // check nonce

            if (transaction.DeliveredBy == null)
            {
                _ownTransactions.TryAdd(transaction.Hash, transaction);
                _ownTimer.Enabled = true;

                if (_logger.IsInfo)
                {
                    _logger.Info($"Broadcasting own transaction {transaction.Hash} to {_peers.Count} peers");
                }
            }

            NotifySelectedPeers(transaction);

            FilterAndStoreTransaction(transaction, blockNumber);
            NewPending?.Invoke(this, new TxEventArgs(transaction));
            return(AddTxResult.Added);
        }
Пример #2
0
        public void AddTransaction(Transaction transaction, UInt256 blockNumber)
        {
            if (!_pendingTransactions.TryAdd(transaction.Hash, transaction))
            {
                return;
            }

            NewPending?.Invoke(this, new TransactionEventArgs(transaction));
            NotifyPeers(SelectPeers(transaction), transaction);
            FilterAndStoreTransaction(transaction, blockNumber);
        }
Пример #3
0
        public AddTransactionResult AddTransaction(Transaction transaction, UInt256 blockNumber)
        {
            Metrics.PendingTransactionsReceived++;

            // beware we are discarding here the old signature scheme without ChainId
            if (transaction.Signature.GetChainId == null)
            {
                Metrics.PendingTransactionsDiscarded++;
                return(AddTransactionResult.OldScheme);
            }

            if (transaction.Signature.GetChainId != _specProvider.ChainId)
            {
                Metrics.PendingTransactionsDiscarded++;
                return(AddTransactionResult.InvalidChainId);
            }

            if (!_pendingTransactions.TryAdd(transaction.Hash, transaction))
            {
                Metrics.PendingTransactionsKnown++;
                return(AddTransactionResult.AlreadyKnown);
            }

            if (_transactionStorage.Get(transaction.Hash) != null)
            {
                Metrics.PendingTransactionsKnown++;
                return(AddTransactionResult.AlreadyKnown);
            }

            transaction.SenderAddress = _signer.RecoverAddress(transaction, blockNumber);

            // check nonce

            if (transaction.DeliveredBy == null)
            {
                _ownTransactions.TryAdd(transaction.Hash, transaction);
                _ownTimer.Enabled = true;

                if (_logger.IsInfo)
                {
                    _logger.Info($"Broadcasting own transaction {transaction.Hash} to {_peers.Count} peers");
                }
            }

            NotifySelectedPeers(transaction);

            FilterAndStoreTransaction(transaction, blockNumber);
            NewPending?.Invoke(this, new TransactionEventArgs(transaction));
            return(AddTransactionResult.Added);
        }
Пример #4
0
        public AddTransactionResult AddPending(Transaction transaction)
        {
            if (_processedTransactions.Contains(transaction.Hash))
            {
                return(AddTransactionResult.AlreadyProcessed);
            }

            if (_pending.ContainsKey(transaction.Hash))
            {
                return(AddTransactionResult.AlreadyKnown);
            }

            _pending[transaction.Hash] = transaction;
            NewPending?.Invoke(this, new TransactionEventArgs(transaction));
            return(AddTransactionResult.Added);
        }
Пример #5
0
        public AddTransactionResult AddTransaction(Transaction transaction, UInt256 blockNumber)
        {
            Metrics.PendingTransactionsReceived++;

            // beware we are discarding here the old signature scheme without ChainId
            if (transaction.Signature.GetChainId == null)
            {
                Metrics.PendingTransactionsDiscarded++;
                return(AddTransactionResult.OldScheme);
            }

            if (transaction.Signature.GetChainId != _specProvider.ChainId)
            {
                Metrics.PendingTransactionsDiscarded++;
                return(AddTransactionResult.InvalidChainId);
            }

            if (!_pendingTransactions.TryAdd(transaction.Hash, transaction))
            {
                Metrics.PendingTransactionsKnown++;
                return(AddTransactionResult.AlreadyKnown);
            }

            if (_transactionStorage.Get(transaction.Hash) != null)
            {
                Metrics.PendingTransactionsKnown++;
                return(AddTransactionResult.AlreadyKnown);
            }

            transaction.SenderAddress = _signer.RecoverAddress(transaction, blockNumber);

            // check nonce

            List <ISynchronizationPeer> selectedPeers = SelectPeers(transaction);

            NotifyPeers(selectedPeers, transaction);

            FilterAndStoreTransaction(transaction, blockNumber);
            NewPending?.Invoke(this, new TransactionEventArgs(transaction));
            return(AddTransactionResult.Added);
        }