Update docker, remove tx cache, use new nbxplorer

This commit is contained in:
nicolas.dorier
2018-01-17 15:02:53 +09:00
parent c9b5f89f17
commit 3f9889d374
8 changed files with 58 additions and 49 deletions

View File

@@ -359,7 +359,7 @@ namespace BTCPayServer.Tests
change.Value -= (payment2 - payment1) * 2; //Add more fees change.Value -= (payment2 - payment1) * 2; //Add more fees
var replaced = tester.ExplorerNode.SignRawTransaction(tx); var replaced = tester.ExplorerNode.SignRawTransaction(tx);
tester.ExplorerNode.SendRawTransaction(replaced); tester.ExplorerNode.SendRawTransaction(replaced);
var test = tester.ExplorerClient.Sync(user.DerivationScheme, null); var test = tester.ExplorerClient.GetUTXOs(user.DerivationScheme, null);
Eventually(() => Eventually(() =>
{ {
invoice = user.BitPay.GetInvoice(invoice.Id); invoice = user.BitPay.GetInvoice(invoice.Id);

View File

@@ -37,7 +37,7 @@ services:
- postgres - postgres
nbxplorer: nbxplorer:
image: nicolasdorier/nbxplorer:1.0.0.71 image: nicolasdorier/nbxplorer:1.0.1.3
ports: ports:
- "32838:32838" - "32838:32838"
expose: expose:

View File

@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<Version>1.0.0.83</Version> <Version>1.0.1.0</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Remove="Build\dockerfiles\**" /> <Compile Remove="Build\dockerfiles\**" />
@@ -21,22 +21,22 @@
<PackageReference Include="Hangfire.MemoryStorage" Version="1.5.2" /> <PackageReference Include="Hangfire.MemoryStorage" Version="1.5.2" />
<PackageReference Include="Hangfire.PostgreSql" Version="1.4.8.1" /> <PackageReference Include="Hangfire.PostgreSql" Version="1.4.8.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.2" /> <PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.2" />
<PackageReference Include="NBitcoin" Version="4.0.0.51" /> <PackageReference Include="NBitcoin" Version="4.0.0.52" />
<PackageReference Include="NBitpayClient" Version="1.0.0.16" /> <PackageReference Include="NBitpayClient" Version="1.0.0.16" />
<PackageReference Include="DBreeze" Version="1.87.0" /> <PackageReference Include="DBreeze" Version="1.87.0" />
<PackageReference Include="NBXplorer.Client" Version="1.0.0.33" /> <PackageReference Include="NBXplorer.Client" Version="1.0.1.2" />
<PackageReference Include="NicolasDorier.CommandLine" Version="1.0.0.1" /> <PackageReference Include="NicolasDorier.CommandLine" Version="1.0.0.1" />
<PackageReference Include="NicolasDorier.CommandLine.Configuration" Version="1.0.0.2" /> <PackageReference Include="NicolasDorier.CommandLine.Configuration" Version="1.0.0.2" />
<PackageReference Include="NicolasDorier.StandardConfiguration" Version="1.0.0.13" /> <PackageReference Include="NicolasDorier.StandardConfiguration" Version="1.0.0.13" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.1" />
<PackageReference Include="System.ValueTuple" Version="4.4.0" /> <PackageReference Include="System.ValueTuple" Version="4.4.0" />
<PackageReference Include="System.Xml.XmlSerializer" Version="4.0.11" /> <PackageReference Include="System.Xml.XmlSerializer" Version="4.0.11" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" /> <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" PrivateAssets="All" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.1" PrivateAssets="All" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.2" PrivateAssets="All" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -38,11 +38,15 @@ namespace BTCPayServer
private static ExplorerClient CreateExplorerClient(BTCPayNetwork n, Uri uri, string cookieFile) private static ExplorerClient CreateExplorerClient(BTCPayNetwork n, Uri uri, string cookieFile)
{ {
var explorer = new ExplorerClient(n.NBXplorerNetwork, uri); var explorer = new ExplorerClient(n.NBXplorerNetwork, uri);
if (cookieFile == null || !explorer.SetCookieAuth(cookieFile)) if (cookieFile == null)
{ {
Logs.Configuration.LogWarning($"{n.CryptoCode}: Not using cookie authentication"); Logs.Configuration.LogWarning($"{n.CryptoCode}: Not using cookie authentication");
explorer.SetNoAuth(); explorer.SetNoAuth();
} }
if(!explorer.SetCookieAuth(cookieFile))
{
Logs.Configuration.LogWarning($"{n.CryptoCode}: Using cookie auth against NBXplorer, but {cookieFile} is not found");
}
return explorer; return explorer;
} }

View File

@@ -19,6 +19,8 @@ using System.Linq;
using System.Threading; using System.Threading;
using BTCPayServer.Services.Wallets; using BTCPayServer.Services.Wallets;
using System.IO; using System.IO;
using BTCPayServer.Logging;
using Microsoft.Extensions.Logging;
namespace BTCPayServer namespace BTCPayServer
{ {

View File

@@ -1,4 +1,5 @@
using System; using System;
using Microsoft.Extensions.Logging;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -29,33 +30,33 @@ namespace BTCPayServer.Services
} }
public class TransactionCache : IDisposable public class TransactionCache : IDisposable
{ {
IOptions<MemoryCacheOptions> _Options; //IOptions<MemoryCacheOptions> _Options;
public TransactionCache(IOptions<MemoryCacheOptions> options, BTCPayNetwork network) public TransactionCache(IOptions<MemoryCacheOptions> options, BTCPayNetwork network)
{ {
if (network == null) //if (network == null)
throw new ArgumentNullException(nameof(network)); // throw new ArgumentNullException(nameof(network));
_Options = options; //_Options = options;
_MemoryCache = new MemoryCache(_Options); //_MemoryCache = new MemoryCache(_Options);
Network = network; //Network = network;
} }
uint256 _LastHash; //uint256 _LastHash;
int _ConfOffset; //int _ConfOffset;
IMemoryCache _MemoryCache; //IMemoryCache _MemoryCache;
public void NewBlock(uint256 newHash, uint256 previousHash) public void NewBlock(uint256 newHash, uint256 previousHash)
{ {
if (_LastHash != previousHash) //if (_LastHash != previousHash)
{ //{
var old = _MemoryCache; // var old = _MemoryCache;
_ConfOffset = 0; // _ConfOffset = 0;
_MemoryCache = new MemoryCache(_Options); // _MemoryCache = new MemoryCache(_Options);
Thread.MemoryBarrier(); // Thread.MemoryBarrier();
old.Dispose(); // old.Dispose();
} //}
else //else
_ConfOffset++; // _ConfOffset++;
_LastHash = newHash; //_LastHash = newHash;
} }
public TimeSpan CacheSpan { get; private set; } = TimeSpan.FromMinutes(60); public TimeSpan CacheSpan { get; private set; } = TimeSpan.FromMinutes(60);
@@ -64,29 +65,32 @@ namespace BTCPayServer.Services
public void AddToCache(TransactionResult tx) public void AddToCache(TransactionResult tx)
{ {
_MemoryCache.Set(tx.Transaction.GetHash(), tx, DateTimeOffset.UtcNow + CacheSpan); //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) public TransactionResult GetTransaction(uint256 txId)
{ {
_MemoryCache.TryGetValue(txId.ToString(), out object tx); //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 result = tx as TransactionResult;
var confOffset = _ConfOffset; //var confOffset = _ConfOffset;
if (result != null && result.Confirmations > 0 && confOffset > 0) //if (result != null && result.Confirmations > 0 && confOffset > 0)
{ //{
var serializer = new NBXplorer.Serializer(Network.NBitcoinNetwork); // var serializer = new NBXplorer.Serializer(Network.NBitcoinNetwork);
result = serializer.ToObject<TransactionResult>(serializer.ToString(result)); // result = serializer.ToObject<TransactionResult>(serializer.ToString(result));
result.Confirmations += confOffset; // result.Confirmations += confOffset;
result.Height += confOffset; // result.Height += confOffset;
} //}
return result; //return result;
return null; // Does not work correctly yet
} }
public void Dispose() public void Dispose()
{ {
_MemoryCache.Dispose(); //_MemoryCache.Dispose();
} }
} }
} }

View File

@@ -15,8 +15,7 @@ namespace BTCPayServer.Services.Wallets
{ {
public class KnownState public class KnownState
{ {
public uint256 UnconfirmedHash { get; set; } public UTXOChanges PreviousCall { get; set; }
public uint256 ConfirmedHash { get; set; }
} }
public class NetworkCoins public class NetworkCoins
{ {
@@ -88,11 +87,11 @@ namespace BTCPayServer.Services.Wallets
public async Task<NetworkCoins> GetCoins(DerivationStrategyBase strategy, KnownState state, CancellationToken cancellation = default(CancellationToken)) public async Task<NetworkCoins> GetCoins(DerivationStrategyBase strategy, KnownState state, CancellationToken cancellation = default(CancellationToken))
{ {
var changes = await _Client.SyncAsync(strategy, state?.ConfirmedHash, state?.UnconfirmedHash, true, cancellation).ConfigureAwait(false); var changes = await _Client.GetUTXOsAsync(strategy, state?.PreviousCall, false, cancellation).ConfigureAwait(false);
return new NetworkCoins() return new NetworkCoins()
{ {
TimestampedCoins = changes.Confirmed.UTXOs.Concat(changes.Unconfirmed.UTXOs).Select(c => new NetworkCoins.TimestampedCoin() { Coin = c.AsCoin(), DateTime = c.Timestamp }).ToArray(), TimestampedCoins = changes.Confirmed.UTXOs.Concat(changes.Unconfirmed.UTXOs).Select(c => new NetworkCoins.TimestampedCoin() { Coin = c.AsCoin(), DateTime = c.Timestamp }).ToArray(),
State = new KnownState() { ConfirmedHash = changes.Confirmed.Hash, UnconfirmedHash = changes.Unconfirmed.Hash }, State = new KnownState() { PreviousCall = changes },
Strategy = strategy, Strategy = strategy,
Wallet = this Wallet = this
}; };
@@ -107,7 +106,7 @@ namespace BTCPayServer.Services.Wallets
public async Task<Money> GetBalance(DerivationStrategyBase derivationStrategy) public async Task<Money> GetBalance(DerivationStrategyBase derivationStrategy)
{ {
var result = await _Client.SyncAsync(derivationStrategy, null, true); var result = await _Client.GetUTXOsAsync(derivationStrategy, null, true);
Dictionary<OutPoint, UTXO> received = new Dictionary<OutPoint, UTXO>(); Dictionary<OutPoint, UTXO> received = new Dictionary<OutPoint, UTXO>();
foreach(var utxo in result.Confirmed.UTXOs.Concat(result.Unconfirmed.UTXOs)) foreach(var utxo in result.Confirmed.UTXOs.Concat(result.Unconfirmed.UTXOs))

View File

@@ -1,4 +1,4 @@
FROM microsoft/aspnetcore-build AS builder FROM microsoft/aspnetcore-build:2.0.5-2.1.4-stretch AS builder
WORKDIR /source WORKDIR /source
COPY BTCPayServer/BTCPayServer.csproj BTCPayServer.csproj COPY BTCPayServer/BTCPayServer.csproj BTCPayServer.csproj
# Cache some dependencies # Cache some dependencies
@@ -6,7 +6,7 @@ RUN dotnet restore
COPY BTCPayServer/. . COPY BTCPayServer/. .
RUN dotnet publish --output /app/ --configuration Release RUN dotnet publish --output /app/ --configuration Release
FROM microsoft/aspnetcore:2.0.3 FROM microsoft/aspnetcore:2.0.5-stretch
WORKDIR /app WORKDIR /app
RUN mkdir /datadir RUN mkdir /datadir