Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Dev #444

Merged
merged 71 commits into from
Oct 25, 2018
Merged

Dev #444

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
4f4cc77
Expose coin family through API
Oct 11, 2018
e195b6f
Return 24h payments in API
Oct 11, 2018
f22daf4
Refactor
Oct 11, 2018
c6a6e86
Reduce temporary allocations
Oct 12, 2018
ffaf3d5
Refactor
Oct 12, 2018
c3bd862
Fix bug in ShareRecorder recovery mode
Oct 12, 2018
8e8a319
Avoid shutdown exception
Oct 12, 2018
a088f2b
Console only logging in recovery mode
Oct 12, 2018
9c14b59
Stupid mistake
Oct 12, 2018
7005e61
Added miner earnings by day to API
Oct 14, 2018
47c5e6c
WIP
Oct 14, 2018
171ebe7
AEON
Oct 15, 2018
e251dd1
Completel Async Database Access
Oct 17, 2018
5e97e93
Fix release build
Oct 17, 2018
5ee2465
Housekeeping
Oct 17, 2018
cec5523
WIP
Oct 17, 2018
e92dafa
Simplified SoloPaymentScheme reward recipients configuration
Oct 18, 2018
f22d97b
Simplify ShareRecorder queue
Oct 18, 2018
735ce07
BulkInsert of shares
Oct 18, 2018
cea0340
Monero v8 fix
Oct 18, 2018
9e580d1
Enable bulk insert
Oct 18, 2018
437c0d4
wip
Oct 18, 2018
20e1bcc
More batching
Oct 18, 2018
847ef6a
Fixed async policy
Oct 18, 2018
4844262
Disable algo cache
Oct 18, 2018
55ac092
WIP
Oct 18, 2018
f6c6b8f
Revert "WIP"
Oct 18, 2018
855315c
WIP
Oct 18, 2018
bf33448
WIP
Oct 18, 2018
520d60d
WIP
Oct 18, 2018
9b58bbd
WIP
Oct 18, 2018
cc8a208
Revert "WIP"
Oct 18, 2018
2075da1
Update libcryptonight
Oct 19, 2018
fe1f293
WIP
Oct 19, 2018
8408331
Switch to INTEL assembly version for cryptonight v2
Oct 19, 2018
0b2e78b
Makefile -DCPU_INTEL
Oct 19, 2018
3e96d52
Fix build
Oct 19, 2018
1af2296
Re-enable cache
Oct 19, 2018
b68223f
Async-optimized ShareReceiver
Oct 19, 2018
af22d6c
Make it stop
Oct 19, 2018
a4114fc
Merge branch 'master' of https://github.com/coinfoundry/Miningcore in…
Oct 19, 2018
8b3257f
Mini refactor
Oct 19, 2018
17e8531
Fixed fatal array reverse bug
Oct 19, 2018
5bc4bcd
Logging
Oct 19, 2018
b9c8ba4
Merge branch 'master' of https://github.com/coinfoundry/miningcore in…
Oct 19, 2018
3dc279b
WIP
Oct 19, 2018
4961765
WIP
Oct 19, 2018
0a81f2d
Cleanup
Oct 19, 2018
062005d
WIP
Oct 19, 2018
3db3a4e
Enable DaemonClient keep-alive
Oct 20, 2018
d01e60e
Cleanup
Oct 21, 2018
bc65559
Metrics foundations
Oct 21, 2018
2539832
WIP
Oct 21, 2018
18adc70
Discord
Oct 22, 2018
3599bbe
Exception overhaul
Oct 22, 2018
bcb4e14
WIP
Oct 22, 2018
7a093c7
Merge branch 'master' of https://github.com/coinfoundry/Miningcore in…
Oct 23, 2018
b8e385f
Merge branch 'master' of https://github.com/coinfoundry/miningcore in…
Oct 23, 2018
f95cdb8
Ethereum geth compatibility fix
Oct 24, 2018
fbfccee
More geth compatibility fixes
Oct 24, 2018
c7c7789
BTStream support for Ethereum family
Oct 24, 2018
52f3b04
Ethminer jobparams fix
Oct 24, 2018
f16d96e
WIP
Oct 24, 2018
2d88ca4
WIP
Oct 24, 2018
31f6c41
Revert "Ethminer jobparams fix"
Oct 24, 2018
72f128b
StratumClient.SendMessage wasn't really async
Oct 25, 2018
82f4be0
More diagnostics
Oct 25, 2018
1084f4d
WIP
Oct 25, 2018
733d9e2
Added missing await for miner performance API endpoint. Fixes #441.
Oct 25, 2018
21cc538
Add nextBits and nextTarget to pool.networkStats (#443)
bitspill Oct 25, 2018
9637d56
WIP
Oct 25, 2018
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
98 changes: 67 additions & 31 deletions src/Miningcore/Api/ApiServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using NLog;
using Prometheus;
using Contract = Miningcore.Contracts.Contract;

namespace Miningcore.Api
Expand Down Expand Up @@ -120,6 +121,7 @@ public ApiServer(
private ClusterConfig clusterConfig;
private IWebHost webHost;
private IWebHost webHostAdmin;
private IWebHost webHostMetrics;
private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
private static readonly Encoding encoding = new UTF8Encoding(false);

Expand All @@ -130,6 +132,20 @@ public ApiServer(
NullValueHandling = NullValueHandling.Ignore
};

class ApiException : Exception
{
public ApiException(string message, int? responseStatusCode = null) : base(message)
{
ResponseStatusCode = responseStatusCode;
}

public ApiException()
{
}

public int? ResponseStatusCode { get; }
}

private readonly ConcurrentDictionary<string, IMiningPool> pools = new ConcurrentDictionary<string, IMiningPool>();

private readonly Dictionary<Regex, Func<HttpContext, Match, Task>> requestMap;
Expand All @@ -139,16 +155,15 @@ private PoolConfig GetPool(HttpContext context, Match m)
{
var poolId = m.Groups["poolId"]?.Value;

if (!string.IsNullOrEmpty(poolId))
{
var pool = clusterConfig.Pools.FirstOrDefault(x => x.Id == poolId && x.Enabled);
if (string.IsNullOrEmpty(poolId))
throw new ApiException($"Invalid pool id", 401);

if (pool != null)
return pool;
}
var pool = clusterConfig.Pools.FirstOrDefault(x => x.Id == poolId && x.Enabled);

context.Response.StatusCode = 404;
return null;
if (pool == null)
throw new ApiException($"Pool {poolId} is not known", 401);

return pool;
}

private async Task SendJsonAsync(HttpContext context, object response)
Expand Down Expand Up @@ -201,6 +216,14 @@ private async Task HandleRequest(HttpContext context)
context.Response.StatusCode = 404;
}

catch (ApiException ex)
{
if (ex.ResponseStatusCode.HasValue)
context.Response.StatusCode = ex.ResponseStatusCode.Value;

await SendJsonAsync(context, ex.Message);
}

catch (Exception ex)
{
logger.Error(ex);
Expand Down Expand Up @@ -284,8 +307,6 @@ private async Task GetPoolInfosAsync(HttpContext context, Match m)
private async Task GetPoolInfoAsync(HttpContext context, Match m)
{
var pool = GetPool(context, m);
if (pool == null)
return;

// load stats
var stats = await cf.Run(con => statsRepo.GetLastPoolStatsAsync(con, pool.Id));
Expand Down Expand Up @@ -317,8 +338,6 @@ private async Task GetPoolInfoAsync(HttpContext context, Match m)
private async Task GetPoolPerformanceAsync(HttpContext context, Match m)
{
var pool = GetPool(context, m);
if (pool == null)
return;

// set range
var end = clock.Now;
Expand All @@ -338,8 +357,6 @@ private async Task GetPoolPerformanceAsync(HttpContext context, Match m)
private async Task PagePoolMinersAsync(HttpContext context, Match m)
{
var pool = GetPool(context, m);
if (pool == null)
return;

// set range
var end = clock.Now;
Expand All @@ -365,8 +382,6 @@ private async Task PagePoolMinersAsync(HttpContext context, Match m)
private async Task PagePoolBlocksPagedAsync(HttpContext context, Match m)
{
var pool = GetPool(context, m);
if (pool == null)
return;

var page = context.GetQueryParameter<int>("page", 0);
var pageSize = context.GetQueryParameter<int>("pageSize", 20);
Expand Down Expand Up @@ -408,8 +423,6 @@ private async Task PagePoolBlocksPagedAsync(HttpContext context, Match m)
private async Task PagePoolPaymentsAsync(HttpContext context, Match m)
{
var pool = GetPool(context, m);
if (pool == null)
return;

var page = context.GetQueryParameter<int>("page", 0);
var pageSize = context.GetQueryParameter<int>("pageSize", 20);
Expand Down Expand Up @@ -446,8 +459,6 @@ private async Task PagePoolPaymentsAsync(HttpContext context, Match m)
private async Task GetMinerInfoAsync(HttpContext context, Match m)
{
var pool = GetPool(context, m);
if (pool == null)
return;

var address = m.Groups["address"]?.Value;
if (string.IsNullOrEmpty(address))
Expand Down Expand Up @@ -488,8 +499,6 @@ private async Task GetMinerInfoAsync(HttpContext context, Match m)
private async Task PageMinerPaymentsAsync(HttpContext context, Match m)
{
var pool = GetPool(context, m);
if (pool == null)
return;

var address = m.Groups["address"]?.Value;
if (string.IsNullOrEmpty(address))
Expand Down Expand Up @@ -533,8 +542,6 @@ private async Task PageMinerPaymentsAsync(HttpContext context, Match m)
private async Task PageMinerBalanceChangesAsync(HttpContext context, Match m)
{
var pool = GetPool(context, m);
if (pool == null)
return;

var address = m.Groups["address"]?.Value;
if (string.IsNullOrEmpty(address))
Expand Down Expand Up @@ -563,8 +570,6 @@ private async Task PageMinerBalanceChangesAsync(HttpContext context, Match m)
private async Task PageMinerEarningsByDayAsync(HttpContext context, Match m)
{
var pool = GetPool(context, m);
if (pool == null)
return;

var address = m.Groups["address"]?.Value;
if (string.IsNullOrEmpty(address))
Expand Down Expand Up @@ -592,8 +597,6 @@ private async Task PageMinerEarningsByDayAsync(HttpContext context, Match m)
private async Task GetMinerPerformanceAsync(HttpContext context, Match m)
{
var pool = GetPool(context, m);
if (pool == null)
return;

var address = m.Groups["address"]?.Value;
if (string.IsNullOrEmpty(address))
Expand All @@ -603,7 +606,7 @@ private async Task GetMinerPerformanceAsync(HttpContext context, Match m)
}

var mode = context.GetQueryParameter<string>("mode", "day").ToLower(); // "day" or "month"
var result = GetMinerPerformanceInternal(mode, pool, address);
var result = await GetMinerPerformanceInternal(mode, pool, address);

await SendJsonAsync(context, result);
}
Expand Down Expand Up @@ -671,7 +674,15 @@ private async Task HandleRequestAdmin(HttpContext context)
context.Response.StatusCode = 404;
}

catch(Exception ex)
catch (ApiException ex)
{
if (ex.ResponseStatusCode.HasValue)
context.Response.StatusCode = ex.ResponseStatusCode.Value;

await SendJsonAsync(context, ex.Message);
}

catch (Exception ex)
{
logger.Error(ex);
throw;
Expand All @@ -687,7 +698,10 @@ private void StartAdminApi(ClusterConfig clusterConfig)
var port = clusterConfig.Api?.AdminPort ?? 4001;

webHostAdmin = new WebHostBuilder()
.Configure(app => { app.Run(HandleRequestAdmin); })
.Configure(app =>
{
app.Run(HandleRequestAdmin);
})
.UseKestrel(options => { options.Listen(address, port); })
.Build();

Expand All @@ -696,6 +710,27 @@ private void StartAdminApi(ClusterConfig clusterConfig)
logger.Info(() => $"Admin API Online @ {address}:{port}");
}

private void StartMetrics(ClusterConfig clusterConfig)
{
var address = clusterConfig.Api?.ListenAddress != null
? (clusterConfig.Api.ListenAddress != "*" ? IPAddress.Parse(clusterConfig.Api.ListenAddress) : IPAddress.Any)
: IPAddress.Parse("127.0.0.1");

var port = clusterConfig.Api?.MetricsPort ?? 4002;

webHostMetrics = new WebHostBuilder()
.Configure(app =>
{
app.UseMetricServer();
})
.UseKestrel(options => { options.Listen(address, port); })
.Build();

webHostMetrics.Start();

logger.Info(() => $"Prometheus Metrics Online @ {address}:{port}/metrics");
}

#endregion // Admin API

#region API-Surface
Expand All @@ -708,6 +743,7 @@ public void Start(ClusterConfig clusterConfig)
logger.Info(() => $"Launching ...");
StartApi(clusterConfig);
StartAdminApi(clusterConfig);
StartMetrics(clusterConfig);
}

public void AttachPool(IMiningPool pool)
Expand Down
2 changes: 2 additions & 0 deletions src/Miningcore/Blockchain/Abstractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class BlockchainStats
public string NetworkType { get; set; }
public double NetworkHashrate { get; set; }
public double NetworkDifficulty { get; set; }
public string NextNetworkTarget { get; set; }
public string NextNetworkBits { get; set; }
public DateTime? LastNetworkBlockTime { get; set; }
public ulong BlockHeight { get; set; }
public int ConnectedPeers { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions src/Miningcore/Blockchain/Bitcoin/BitcoinJobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ private BitcoinJob CreateJob()
BlockchainStats.LastNetworkBlockTime = clock.Now;
BlockchainStats.BlockHeight = blockTemplate.Height;
BlockchainStats.NetworkDifficulty = job.Difficulty;
BlockchainStats.NextNetworkTarget = blockTemplate.Target;
BlockchainStats.NextNetworkBits = blockTemplate.Bits;
}

else
Expand Down
5 changes: 3 additions & 2 deletions src/Miningcore/Blockchain/Bitcoin/BitcoinJobManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected virtual void SetupJobUpdates()
{
logger.Info(() => $"Subscribing to ZMQ push-updates from {string.Join(", ", zmq.Values)}");

var blockNotify = daemon.ZmqSubscribe(logger, zmq, 2)
var blockNotify = daemon.ZmqSubscribe(logger, zmq)
.Select(msg =>
{
using (msg)
Expand Down Expand Up @@ -587,7 +587,8 @@ protected void ConfigureRewards()
new RewardRecipient
{
Address = address,
Percentage = DevDonation.Percent
Percentage = DevDonation.Percent,
Type = "dev"
}
}).ToArray();
}
Expand Down
12 changes: 4 additions & 8 deletions src/Miningcore/Blockchain/CoinMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,25 @@ public class DevDonation
public static readonly Dictionary<string, string> Addresses = new Dictionary<string, string>
{
{ "BTC", "17QnVor1B6oK1rWnVVBrdX9gFzVkZZbhDm" },
{ "BCH", "1LJGTzNDTuTvkHpTxNSdmAEBAXAnEHDVqQ" },
{ "BCH", "qrf6uhhapq7fgkjv2ce2hcjqpk8ec2zc25et4xsphv" },
{ "BCD", "1CdZ2PXisTRxyB4bkvq5oka9YjBHGU5Z36" },
{ "LTC", "LTK6CWastkmBzGxgQhTTtCUjkjDA14kxzC" },
{ "DOGE", "DGDuKRhBewGP1kbUz4hszNd2p6dDzWYy9Q" },
{ "NMC", "NDSLDpFEcTbuRVcWHdJyiRZThVAcb5Z79o" },
{ "DGB", "DAFtYMGVdNtqHJoBGg2xqZZwSuYAaEs2Bn" },
{ "DGB", "DEvrh1UEqm89bGJ9QTBjBonjGotKQSSBmq" },
{ "ETH", "0xcb55abBfe361B12323eb952110cE33d5F28BeeE1" },
{ "ETC", "0xF8cCE9CE143C68d3d4A7e6bf47006f21Cfcf93c0" },
{ "PPC", "PE8RH6HAvi8sqYg47D58TeKTjyeQFFHWR2" },
{ "DASH", "XqpBAV9QCaoLnz42uF5frSSfrJTrqHoxjp" },
{ "VIA", "Vc5rJr2QdA2yo1jBoqYUAH7T59uBh2Vw5q" },
{ "MONA", "MBbkeAM3VQKg474bgxJEXrtcnMg8cjHY3S" },
{ "VTC", "VwDWBHzhYeuyMcHpaZ5nZryggUjHSxUKKK" },
{ "ZEC", "t1YHZHz2DGVMJiggD2P4fBQ2TAPgtLSUwZ7" },
{ "ZEC", "t1YEgm6ovXFseeFxXgFY2zXxwsScD4BbfhT" },
{ "ZCL", "t1MFU1vD3YKgsK6Uh8hW7UTY8mKAV2xVqBr" },
{ "ZEN", "znigQacfTvRiwD2TRhwkBHLNchQ2AZisD94" },
{ "BTG", "GRao6KHQ8a4GUjAZRVbeCLfRbSkJQQaeMg" },
{ "MOON", "2QvpGimMYLyqKsczQXZjv56h6me3M8orwj" },
{ "XVG", "D5xPoHLM6HPkwWSqAweECTSQirJBmRjS8i" },
{ "XMR", "475YVJbPHPedudkhrcNp1wDcLMTGYusGPF5fqE7XjnragVLPdqbCHBdZg3dF4dN9hXMjjvGbykS6a77dTAQvGrpiQqHp2eH" },
{ "ETN", "etnkQJwBCjmR1MfkU8D355ZWxxLMhs8miPrtKHWN4U3uUowq9ugeKccVBoEG3n13n74us5AkT8tEoTog46w4HBgn8sMuBRhm9h" },
{ "RVN", "RQPJF65UoodQ2aZUkfnXoeX6gib3GNwm9u" },
{ "PGN", "PRm3ThUGfmU157NwcKzKBqWbgA2DPuFje1" },
{ "TUBE", "bxdAFKYA5sJYKM3zcn3SLaLRjsFF582VE1Uv5NChrVLm6o6UF4SdbZBZLrTBD6yEFZDzuTQGBCa8FLpX8charjxH2G3iMRX6R" },
};
}

Expand Down
7 changes: 5 additions & 2 deletions src/Miningcore/Blockchain/Cryptonote/CryptonoteJobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ protected async Task<bool> UpdateJob(string via = null, string json = null)
BlockchainStats.LastNetworkBlockTime = clock.Now;
BlockchainStats.BlockHeight = job.BlockTemplate.Height;
BlockchainStats.NetworkDifficulty = job.BlockTemplate.Difficulty;
BlockchainStats.NextNetworkTarget = "";
BlockchainStats.NextNetworkBits = "";
}

return isNew;
Expand Down Expand Up @@ -526,7 +528,8 @@ private void ConfigureRewards()
new RewardRecipient
{
Address = address,
Percentage = DevDonation.Percent
Percentage = DevDonation.Percent,
Type = "dev"
}
}).ToArray();
}
Expand Down Expand Up @@ -559,7 +562,7 @@ protected virtual void SetupJobUpdates()
{
logger.Info(() => $"Subscribing to ZMQ push-updates from {string.Join(", ", zmq.Values)}");

var blockNotify = daemon.ZmqSubscribe(logger, zmq, 2)
var blockNotify = daemon.ZmqSubscribe(logger, zmq)
.Select(msg =>
{
using (msg)
Expand Down
2 changes: 2 additions & 0 deletions src/Miningcore/Blockchain/Equihash/EquihashJobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ private EquihashJob CreateJob()
BlockchainStats.LastNetworkBlockTime = clock.Now;
BlockchainStats.BlockHeight = blockTemplate.Height;
BlockchainStats.NetworkDifficulty = job.Difficulty;
BlockchainStats.NextNetworkTarget = blockTemplate.Target;
BlockchainStats.NextNetworkBits = blockTemplate.Bits;
}

else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ portions of the Software.
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

using Miningcore.Configuration;

namespace Miningcore.Blockchain.Ethereum.Configuration
{
public class EthereumPoolConfigExtra
Expand All @@ -36,5 +38,10 @@ public class EthereumPoolConfigExtra
/// Useful to specify the real chain type when running geth
/// </summary>
public string ChainTypeOverride { get; set; }

/// <summary>
/// getWork stream published via ZMQ
/// </summary>
public ZmqPubSubEndpointConfig BtStream { get; set; }
}
}
Loading