diff --git a/BTCPayServer/HostedServices/NBXplorerListener.cs b/BTCPayServer/HostedServices/NBXplorerListener.cs index c0b0bb7db..145d9e2c7 100644 --- a/BTCPayServer/HostedServices/NBXplorerListener.cs +++ b/BTCPayServer/HostedServices/NBXplorerListener.cs @@ -25,11 +25,9 @@ namespace BTCPayServer.HostedServices private TaskCompletionSource _RunningTask; private CancellationTokenSource _Cts; NBXplorerDashboard _Dashboards; - TransactionCacheProvider _TxCache; public NBXplorerListener(ExplorerClientProvider explorerClients, NBXplorerDashboard dashboard, - TransactionCacheProvider cacheProvider, InvoiceRepository invoiceRepository, EventAggregator aggregator, IApplicationLifetime lifetime) { @@ -39,7 +37,6 @@ namespace BTCPayServer.HostedServices _ExplorerClients = explorerClients; _Aggregator = aggregator; _Lifetime = lifetime; - _TxCache = cacheProvider; } CompositeDisposable leases = new CompositeDisposable(); @@ -137,13 +134,11 @@ namespace BTCPayServer.HostedServices switch (newEvent) { case NBXplorer.Models.NewBlockEvent evt: - _TxCache.GetTransactionCache(network).NewBlock(evt.Hash, evt.PreviousBlockHash); _Aggregator.Publish(new Events.NewBlockEvent() { CryptoCode = evt.CryptoCode }); break; case NBXplorer.Models.NewTransactionEvent evt: foreach (var txout in evt.Outputs) { - _TxCache.GetTransactionCache(network).AddToCache(evt.TransactionData); _Aggregator.Publish(new Events.TxOutReceivedEvent() { Network = network, diff --git a/BTCPayServer/Hosting/BTCPayServerServices.cs b/BTCPayServer/Hosting/BTCPayServerServices.cs index 7ea398465..b8f076bef 100644 --- a/BTCPayServer/Hosting/BTCPayServerServices.cs +++ b/BTCPayServer/Hosting/BTCPayServerServices.cs @@ -142,8 +142,6 @@ namespace BTCPayServer.Hosting BlockTarget = 20 }); - services.AddSingleton(); - services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/BTCPayServer/Services/TransactionCache.cs b/BTCPayServer/Services/TransactionCache.cs deleted file mode 100644 index b48980753..000000000 --- a/BTCPayServer/Services/TransactionCache.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using Microsoft.Extensions.Logging; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Extensions.Caching.Memory; -using Microsoft.Extensions.Options; -using NBitcoin; -using NBXplorer.Models; - -namespace BTCPayServer.Services -{ - public class TransactionCacheProvider - { - IOptions _Options; - public TransactionCacheProvider(IOptions options) - { - _Options = options; - } - - ConcurrentDictionary _TransactionCaches = new ConcurrentDictionary(); - public TransactionCache GetTransactionCache(BTCPayNetwork network) - { - if (network == null) - throw new ArgumentNullException(nameof(network)); - return _TransactionCaches.GetOrAdd(network.CryptoCode, c => new TransactionCache(_Options, network)); - } - } - public class TransactionCache : IDisposable - { - //IOptions _Options; - public TransactionCache(IOptions options, BTCPayNetwork network) - { - //if (network == null) - // throw new ArgumentNullException(nameof(network)); - //_Options = options; - //_MemoryCache = new MemoryCache(_Options); - //Network = network; - } - - //uint256 _LastHash; - //int _ConfOffset; - //IMemoryCache _MemoryCache; - - public void NewBlock(uint256 newHash, uint256 previousHash) - { - //if (_LastHash != previousHash) - //{ - // var old = _MemoryCache; - // _ConfOffset = 0; - // _MemoryCache = new MemoryCache(_Options); - // Thread.MemoryBarrier(); - // old.Dispose(); - //} - //else - // _ConfOffset++; - //_LastHash = newHash; - } - - public TimeSpan CacheSpan { get; private set; } = TimeSpan.FromMinutes(60); - - public BTCPayNetwork Network { get; private set; } - - public void AddToCache(TransactionResult tx) - { - //Logging.Logs.PayServer.LogInformation($"ADD CACHE: {tx.Transaction.GetHash()} ({tx.Confirmations} conf)"); - //_MemoryCache.Set(tx.Transaction.GetHash(), tx, DateTimeOffset.UtcNow + CacheSpan); - } - - - public TransactionResult GetTransaction(uint256 txId) - { - //var ok = _MemoryCache.TryGetValue(txId.ToString(), out object tx); - //Logging.Logs.PayServer.LogInformation($"GET CACHE: {txId} ({ok} plus {_ConfOffset})"); - - //var result = tx as TransactionResult; - //var confOffset = _ConfOffset; - //if (result != null && result.Confirmations > 0 && confOffset > 0) - //{ - // var serializer = new NBXplorer.Serializer(Network.NBitcoinNetwork); - // result = serializer.ToObject(serializer.ToString(result)); - // result.Confirmations += confOffset; - // result.Height += confOffset; - //} - //return result; - return null; // Does not work correctly yet - } - - public void Dispose() - { - //_MemoryCache.Dispose(); - } - } -} diff --git a/BTCPayServer/Services/Wallets/BTCPayWallet.cs b/BTCPayServer/Services/Wallets/BTCPayWallet.cs index 37b41b5bf..6bce43e8e 100644 --- a/BTCPayServer/Services/Wallets/BTCPayWallet.cs +++ b/BTCPayServer/Services/Wallets/BTCPayWallet.cs @@ -32,14 +32,12 @@ namespace BTCPayServer.Services.Wallets public class BTCPayWallet { private ExplorerClient _Client; - private TransactionCache _Cache; - public BTCPayWallet(ExplorerClient client, TransactionCache cache, BTCPayNetwork network) + public BTCPayWallet(ExplorerClient client, BTCPayNetwork network) { if (client == null) throw new ArgumentNullException(nameof(client)); _Client = client; _Network = network; - _Cache = cache; } @@ -91,11 +89,7 @@ namespace BTCPayServer.Services.Wallets { if (txId == null) throw new ArgumentNullException(nameof(txId)); - var tx = _Cache.GetTransaction(txId); - if (tx != null) - return tx; - tx = await _Client.GetTransactionAsync(txId, cancellation); - _Cache.AddToCache(tx); + var tx = await _Client.GetTransactionAsync(txId, cancellation); return tx; } diff --git a/BTCPayServer/Services/Wallets/BTCPayWalletProvider.cs b/BTCPayServer/Services/Wallets/BTCPayWalletProvider.cs index f62426e98..7fad2db05 100644 --- a/BTCPayServer/Services/Wallets/BTCPayWalletProvider.cs +++ b/BTCPayServer/Services/Wallets/BTCPayWalletProvider.cs @@ -10,15 +10,12 @@ namespace BTCPayServer.Services.Wallets { private ExplorerClientProvider _Client; BTCPayNetworkProvider _NetworkProvider; - TransactionCacheProvider _TransactionCacheProvider; public BTCPayWalletProvider(ExplorerClientProvider client, - TransactionCacheProvider transactionCacheProvider, BTCPayNetworkProvider networkProvider) { if (client == null) throw new ArgumentNullException(nameof(client)); _Client = client; - _TransactionCacheProvider = transactionCacheProvider; _NetworkProvider = networkProvider; } @@ -36,7 +33,7 @@ namespace BTCPayServer.Services.Wallets var client = _Client.GetExplorerClient(cryptoCode); if (network == null || client == null) return null; - return new BTCPayWallet(client, _TransactionCacheProvider.GetTransactionCache(network), network); + return new BTCPayWallet(client, network); } public bool IsAvailable(BTCPayNetwork network)