Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/MiningCore.Tests/Blockchain/Bitcoin/BitcoinJobTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net;
using MiningCore.Blockchain.Bitcoin;
using MiningCore.Configuration;
using MiningCore.Crypto;
Expand All @@ -7,6 +8,7 @@
using MiningCore.Extensions;
using MiningCore.Stratum;
using MiningCore.Tests.Util;
using MiningCore.Time;
using NBitcoin;
using Newtonsoft.Json;
using Xunit;
Expand All @@ -25,7 +27,7 @@ public class BitcoinJobTests : TestBase
[Fact]
public void BitcoinJob_Should_Accept_Valid_Share()
{
var worker = new StratumClient();
var worker = new StratumClient(new StandardClock(), new IPEndPoint(IPAddress.Any, 3000), string.Empty);

worker.SetContext(new BitcoinWorkerContext
{
Expand Down Expand Up @@ -61,9 +63,9 @@ public void BitcoinJob_Should_Accept_Valid_Share()
[Fact]
public void BitcoinJob_Should_Not_Accept_Invalid_Share()
{
var worker = new StratumClient();
var worker = new StratumClient(new StandardClock(), new IPEndPoint(IPAddress.Any, 3000), string.Empty);

worker.SetContext(new BitcoinWorkerContext
worker.SetContext(new BitcoinWorkerContext
{
Difficulty = 0.5,
ExtraNonce1 = "01000058",
Expand Down
12 changes: 7 additions & 5 deletions src/MiningCore.Tests/Blockchain/Monero/MoneroJobTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using MiningCore.Blockchain.Monero;
using System.Net;
using MiningCore.Blockchain.Monero;
using MiningCore.Configuration;
using MiningCore.Extensions;
using MiningCore.Stratum;
using MiningCore.Time;
using Newtonsoft.Json;
using Xunit;

Expand All @@ -15,9 +17,9 @@ public class BitcoinJobTests : TestBase
[Fact]
public void MoneroJob_Should_Accept_Valid_Share()
{
var worker = new StratumClient();
var worker = new StratumClient(new StandardClock(), new IPEndPoint(IPAddress.Any, 3000), string.Empty);

worker.SetContext(new MoneroWorkerContext
worker.SetContext(new MoneroWorkerContext
{
Difficulty = 1000,
});
Expand All @@ -39,9 +41,9 @@ public void MoneroJob_Should_Accept_Valid_Share()
[Fact]
public void MoneroJob_Should_Not_Accept_Invalid_Share()
{
var worker = new StratumClient();
var worker = new StratumClient(new StandardClock(), new IPEndPoint(IPAddress.Any, 3000), string.Empty);

worker.SetContext(new MoneroWorkerContext
worker.SetContext(new MoneroWorkerContext
{
Difficulty = 1000,
});
Expand Down
1 change: 1 addition & 0 deletions src/MiningCore/Blockchain/Bitcoin/BitcoinProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private static BitcoinCoinProperties GetDigiByteProperties(string algorithm)
switch(algorithm.ToLower())
{
case "sha256d":
case "sha256":
return sha256Coin;

case "skein":
Expand Down
4 changes: 4 additions & 0 deletions src/MiningCore/Blockchain/CoinMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static class CoinMetaData
{ CoinType.XMR, new Dictionary<string, string> { { string.Empty, $"https://chainradar.com/xmr/block/{BlockHeightPH}" }}},
{ CoinType.ETN, new Dictionary<string, string> { { string.Empty, $"https://blockexplorer.electroneum.com/block/{BlockHeightPH}" } }},
{ CoinType.LTC, new Dictionary<string, string> { { string.Empty, $"https://chainz.cryptoid.info/ltc/block.dws?{BlockHeightPH}.htm" } }},
{ CoinType.PPC, new Dictionary<string, string> { { string.Empty, $"https://chainz.cryptoid.info/ppc/block.dws?{BlockHeightPH}.htm" } }},
{ CoinType.BCH, new Dictionary<string, string> { { string.Empty, $"https://www.blocktrail.com/BCC/block/{BlockHeightPH}" }}},
{ CoinType.DASH, new Dictionary<string, string> { { string.Empty, $"https://chainz.cryptoid.info/dash/block.dws?{BlockHeightPH}.htm" }}},
{ CoinType.BTC, new Dictionary<string, string> { { string.Empty, $"https://blockchain.info/block/{BlockHeightPH}" }}},
Expand Down Expand Up @@ -58,6 +59,7 @@ public static class CoinMetaData
{ CoinType.ETH, "https://etherscan.io/tx/{0}" },
{ CoinType.ETC, "https://gastracker.io/tx/{0}" },
{ CoinType.LTC, "https://chainz.cryptoid.info/ltc/tx.dws?{0}.htm" },
{ CoinType.PPC, "https://chainz.cryptoid.info/ppc/tx.dws?{0}.htm" },
{ CoinType.BCH, "https://www.blocktrail.com/BCC/tx/{0}" },
{ CoinType.DASH, "https://chainz.cryptoid.info/dash/tx.dws?{0}.htm" },
{ CoinType.BTC, "https://blockchain.info/tx/{0}" },
Expand Down Expand Up @@ -88,6 +90,7 @@ public static class CoinMetaData
{ CoinType.ETH, "https://etherscan.io/address/{0}" },
{ CoinType.ETC, "https://gastracker.io/addr/{0}" },
{ CoinType.LTC, "https://chainz.cryptoid.info/ltc/address.dws?{0}.htm" },
{ CoinType.PPC, "https://chainz.cryptoid.info/ppc/address.dws?{0}.htm" },
{ CoinType.BCH, "https://www.blocktrail.com/BCC/address/{0}" },
{ CoinType.DASH, "https://chainz.cryptoid.info/dash/address.dws?{0}.htm" },
{ CoinType.BTC, "https://blockchain.info/address/{0}" },
Expand Down Expand Up @@ -120,6 +123,7 @@ public static class CoinMetaData
{ CoinType.ETH, (coin, alg)=> Ethash },
{ CoinType.ETC, (coin, alg)=> Ethash },
{ CoinType.LTC, BitcoinProperties.GetAlgorithm },
{ CoinType.PPC, BitcoinProperties.GetAlgorithm },
{ CoinType.BCH, BitcoinProperties.GetAlgorithm },
{ CoinType.DASH, BitcoinProperties.GetAlgorithm },
{ CoinType.BTC, BitcoinProperties.GetAlgorithm },
Expand Down
12 changes: 12 additions & 0 deletions src/MiningCore/Configuration/ClusterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ public class PoolEndpoint
public string Name { get; set; }
public double Difficulty { get; set; }
public VarDiffConfig VarDiff { get; set; }

/// <summary>
/// Enable Transport layer security (TLS)
/// If set to true, you must specify values for either TlsPemFile or TlsPfxFile
/// If TlsPemFile does not include the private key, TlsKeyFile is also required
/// </summary>
public bool Tls { get; set; }

/// <summary>
/// PKCS certificate file
/// </summary>
public string TlsPfxFile { get; set; }
}

public partial class VarDiffConfig
Expand Down
30 changes: 30 additions & 0 deletions src/MiningCore/Configuration/ClusterConfigValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ portions of the Software.
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

using System;
using System.IO;
using FluentValidation;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using FluentValidation.Attributes;

namespace MiningCore.Configuration
Expand Down Expand Up @@ -100,6 +103,33 @@ public PoolEndpointValidator()
.GreaterThan(0)
.WithMessage("Pool Endpoint: Difficulty missing or invalid");

RuleFor(j => j.TlsPfxFile)
.NotNull()
.NotEmpty()
.When(j=> j.Tls)
.WithMessage("Pool Endpoint: Tls enabled but neither TlsPemFile nor TlsPfxFile specified");

RuleFor(j => j.TlsPfxFile)
.Must(j=> File.Exists(j))
.When(j => j.Tls)
.WithMessage(j=> $"Pool Endpoint: {j.TlsPfxFile} does not exist");

RuleFor(j => j.TlsPfxFile)
.Must(j =>
{
try
{
var tlsCert = new X509Certificate2(j);
return tlsCert.HasPrivateKey;
}
catch
{
return false;
}
})
.When(j => j.Tls)
.WithMessage(j => $"Pool Endpoint: {j.TlsPfxFile} is not valid or does not include the private key and cannot be used");

RuleFor(j => j.VarDiff)
.SetValidator(new VarDiffConfigValidator())
.When(x => x.VarDiff != null);
Expand Down
20 changes: 10 additions & 10 deletions src/MiningCore/Extensions/NumberExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/*
/*
Copyright 2017 Coin Foundry (coinfoundry.org)
Authors: Oliver Weichhold (oliver@weichhold.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

Expand Down
10 changes: 7 additions & 3 deletions src/MiningCore/Mining/PoolBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,15 @@ public virtual async Task StartAsync()

if (poolConfig.EnableInternalStratum == true)
{
var ipEndpoints = poolConfig.Ports.Keys
.Select(port => PoolEndpoint2IPEndpoint(port, poolConfig.Ports[port]))
var endpoints = poolConfig.Ports.Keys
.Select(port =>
{
var endpointConfig = poolConfig.Ports[port];
return (PoolEndpoint2IPEndpoint(port, endpointConfig), endpointConfig);
})
.ToArray();

StartListeners(poolConfig.Id, ipEndpoints);
Start(poolConfig.Id, endpoints);
}

if(poolConfig.ExternalStratums?.Length > 0)
Expand Down
1 change: 0 additions & 1 deletion src/MiningCore/MiningCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" />
<PackageReference Include="NBitcoin" Version="4.0.0.51" />
<PackageReference Include="NetMQ" Version="4.0.0.1" />
<PackageReference Include="NetUV.Core" Version="0.1.140" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="NLog" Version="5.0.0-beta09" />
<PackageReference Include="Npgsql" Version="3.2.6" />
Expand Down
5 changes: 5 additions & 0 deletions src/MiningCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
Expand All @@ -41,6 +42,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using MiningCore.Api;
using MiningCore.Api.Responses;
using MiningCore.Blockchain;
using MiningCore.Blockchain.Bitcoin;
using MiningCore.Blockchain.Bitcoin.DaemonResponses;
using MiningCore.Blockchain.ZCash;
using MiningCore.Configuration;
Expand Down Expand Up @@ -256,6 +258,9 @@ private static void Bootstrap()
var amConf = new MapperConfiguration(cfg => { cfg.AddProfile(new AutoMapperProfile()); });
builder.Register((ctx, parms) => amConf.CreateMapper());

// Misc
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

ConfigurePersistence(builder);
container = builder.Build();
ConfigureLogging();
Expand Down
14 changes: 7 additions & 7 deletions src/MiningCore/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"profiles": {
"MiningCore": {
"commandName": "Project",
"commandLineArgs": "-c config.json"
}
}
{
"profiles": {
"MiningCore": {
"commandName": "Project",
"commandLineArgs": "-c ..\\..\\..\\config.json"
}
}
}
Loading