Ejemplo n.º 1
0
 public bool IsProcessed(uint256 txid)
 {
     lock (ProcessedLock)
     {
         return(ProcessedTransactionHashes.Contains(txid));
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Tries to perform mempool cleanup with the help of the backend.
        /// </summary>
        public async Task <bool> TryPerformMempoolCleanupAsync(Func <Uri> destAction, EndPoint torSocks)
        {
            // If already cleaning, then no need to run it that often.
            if (Interlocked.CompareExchange(ref _cleanupInProcess, 1, 0) == 1)
            {
                return(false);
            }

            // This function is designed to prevent forever growing mempool.
            try
            {
                // No need for locking when accessing Count.
                if (ProcessedTransactionHashes.Count == 0)
                {
                    // There's nothing to cleanup.
                    return(true);
                }

                Logger.LogInfo("Start cleaning out mempool...");
                using (var client = new WasabiClient(destAction, torSocks))
                {
                    var compactness      = 10;
                    var allMempoolHashes = await client.GetMempoolHashesAsync(compactness);

                    lock (ProcessedLock)
                    {
                        int removedTxCount = ProcessedTransactionHashes.RemoveWhere(x => !allMempoolHashes.Contains(x.ToString().Substring(0, compactness)));

                        Logger.LogInfo($"{removedTxCount} transactions were cleaned from mempool.");
                    }
                }

                // Display warning if total receives would be reached by duplicated receives.
                // Also reset the benchmarking.
                var totalReceived      = Interlocked.Exchange(ref _totalReceives, 0);
                var duplicatedReceived = Interlocked.Exchange(ref _duplicatedReceives, 0);
                if (duplicatedReceived >= totalReceived)
                {
                    // Note that the worst case scenario is not duplicatedReceived == totalReceived, but duplicatedReceived == (number of peers) * totalReceived.
                    // It's just duplicatedReceived == totalReceived is maximum what we want to tolerate.
                    // By turning off Tor, we can notice that the ratio is much better, so this mainly depends on the internet speed.
                    Logger.LogWarning($"Too many duplicated mempool transactions are downloaded.\n{nameof(duplicatedReceived)} : {duplicatedReceived}\n{nameof(totalReceived)} : {totalReceived}");
                }

                return(true);
            }
            catch (Exception ex)
            {
                Logger.LogWarning(ex);
            }
            finally
            {
                Interlocked.Exchange(ref _cleanupInProcess, 0);
            }

            return(false);
        }
Ejemplo n.º 3
0
        public void Process(Transaction tx)
        {
            lock (ProcessedLock)
            {
                if (ProcessedTransactionHashes.Add(tx.GetHash()))
                {
                    TransactionReceived?.Invoke(this, new SmartTransaction(tx, Height.Mempool));
                }
                else
                {
                    Interlocked.Increment(ref _duplicatedReceives);
                }

                Interlocked.Increment(ref _totalReceives);
            }
        }
Ejemplo n.º 4
0
        public void Process(Transaction tx)
        {
            SmartTransaction txAdded = null;

            lock (ProcessedLock)
            {
                if (ProcessedTransactionHashes.Add(tx.GetHash()))
                {
                    txAdded = new SmartTransaction(tx, Height.Mempool);
                }
                else
                {
                    Interlocked.Increment(ref _duplicatedReceives);
                }
                Interlocked.Increment(ref _totalReceives);
            }
            if (txAdded is { })