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

Commit

Permalink
Dev (#484)
Browse files Browse the repository at this point in the history
* Eliminate BlockrewardMultiplier and read actual block-reward from coinbase-tx
* Log bitcoin family shares with actual stratum diff
* sslstream disposing was still not 100% ensured
* PAC coin support
* Config overridable coinbase tx comments
* Improved Http connection pooling
* Publish Hashrate updated notification on WebSocket
* More block notification properties
* camelcase enum serialization
* Fix <code>sendmany</code> RPC rounding problems with Bitcoin Core 0.17
* Dash v13 support
* Enhance pool/blocks API with block state parameter support
* x22i hash support
* Payee support
* Ban on SSL handshake error
  • Loading branch information
Oliver Weichhold authored Nov 23, 2018
1 parent ea5ddee commit 21356c8
Show file tree
Hide file tree
Showing 62 changed files with 4,368 additions and 416 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.user
*.sln.docstates
.vs/
.vscode/

[Dd]ebug/
[Rr]elease/
Expand Down
3 changes: 1 addition & 2 deletions examples/flo_pool.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@
{
"id": "flo1",
"enabled": true,
"coin": "florincoin",
"coin": "flo",
"address": "FC3d6JT1Z3uZvKVNWjKt3qN8PX8knhAU7d",
"rewardRecipients": [
{
"address": "FCH4uesFJADBGK85gW74Cqmka54dpZk4ZH",
"percentage": 1.0
}
],
"floData": "Flo MiningCore",
"maxActiveJobs": 10,
"blockRefreshInterval": 500,
"jobRebroadcastTimeout": 10,
Expand Down
Binary file modified libs/runtimes/win-x64/libmultihash.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions src/Miningcore.Tests/Blockchain/Bitcoin/BitcoinJobTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void BitcoinJob_Should_Accept_Valid_Share()
// set clock to job creation time
var clock = new MockMasterClock { CurrentTime = DateTimeOffset.FromUnixTimeSeconds(1508869874).UtcDateTime };

job.Init(bt, "1", poolConfig, clusterConfig, clock, poolAddressDestination, Network.RegTest,
job.Init(bt, "1", poolConfig, null, clusterConfig, clock, poolAddressDestination, Network.RegTest,
false, 1, sha256d, sha256d, sha256dReverse);

// set clock to submission time
Expand Down Expand Up @@ -85,7 +85,7 @@ public void BitcoinJob_Should_Not_Accept_Invalid_Share()
// set clock to job creation time
var clock = new MockMasterClock { CurrentTime = DateTimeOffset.FromUnixTimeSeconds(1508869874).UtcDateTime };

job.Init(bt, "1", poolConfig, clusterConfig, clock, poolAddressDestination, Network.RegTest,
job.Init(bt, "1", poolConfig, null, clusterConfig, clock, poolAddressDestination, Network.RegTest,
false, 1, sha256d, sha256d, sha256dReverse);

// set clock to submission time
Expand Down
11 changes: 11 additions & 0 deletions src/Miningcore.Tests/Crypto/HashingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,17 @@ public void X16S_Hash()
Assert.Equal("c1b0a424e65b3e01e89de43c4007803be68164320aed1a8ab9a34924cfcc5055", result);
}

[Fact]
public void X22I_Hash()
{
var hasher = new X22I();
var hash = new byte[32];
hasher.Digest(testValue, hash);
var result = hash.ToHexString();

Assert.Equal("616c341e79417e6623dacff834c5c480d8d7d43ba6ae60fcee99f69343fd7c99", result);
}

[Fact]
public void Skein_Hash()
{
Expand Down
112 changes: 112 additions & 0 deletions src/Miningcore/Api/Controllers/ClusterApiController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using Autofac;
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Miningcore.Api.Extensions;
using Miningcore.Api.Responses;
using Miningcore.Blockchain;
using Miningcore.Configuration;
using Miningcore.Extensions;
using Miningcore.Mining;
using Miningcore.Persistence;
using Miningcore.Persistence.Model;
using Miningcore.Persistence.Model.Projections;
using Miningcore.Persistence.Repositories;
using Miningcore.Time;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Threading.Tasks;

namespace Miningcore.Api.Controllers
{
[Route("api")]
[ApiController]
public class ClusterApiController : ControllerBase
{
public ClusterApiController(IComponentContext ctx)
{
clusterConfig = ctx.Resolve<ClusterConfig>();
cf = ctx.Resolve<IConnectionFactory>();
statsRepo = ctx.Resolve<IStatsRepository>();
blocksRepo = ctx.Resolve<IBlockRepository>();
paymentsRepo = ctx.Resolve<IPaymentRepository>();
mapper = ctx.Resolve<IMapper>();
clock = ctx.Resolve<IMasterClock>();
pools = ctx.Resolve<ConcurrentDictionary<string, IMiningPool>>();
enabledPools = new HashSet<string>(clusterConfig.Pools.Where(x => x.Enabled).Select(x => x.Id));
}

private readonly ClusterConfig clusterConfig;
private readonly IConnectionFactory cf;
private readonly IStatsRepository statsRepo;
private readonly IBlockRepository blocksRepo;
private readonly IPaymentRepository paymentsRepo;
private readonly IMapper mapper;
private readonly IMasterClock clock;
private readonly ConcurrentDictionary<string, IMiningPool> pools;
private readonly HashSet<string> enabledPools;

#region Actions

[HttpGet("blocks")]
public async Task<Responses.Block[]> PageBlocksPagedAsync(
[FromQuery] int page, [FromQuery] int pageSize, [FromQuery] BlockStatus[] state)
{
var blockStates = state != null && state.Length > 0 ?
state :
new[] { BlockStatus.Confirmed, BlockStatus.Pending, BlockStatus.Orphaned };

var blocks = (await cf.Run(con => blocksRepo.PageBlocksAsync(con, blockStates, page, pageSize)))
.Select(mapper.Map<Responses.Block>)
.Where(x=> enabledPools.Contains(x.PoolId))
.ToArray();

// enrich blocks
var blocksByPool = blocks.GroupBy(x => x.PoolId);

foreach (var poolBlocks in blocksByPool)
{
var pool = GetPoolNoThrow(poolBlocks.Key);

if (pool == null)
continue;

var blockInfobaseDict = pool.Template.ExplorerBlockLinks;

// compute infoLink
if (blockInfobaseDict != null)
{
foreach (var block in poolBlocks)
{
blockInfobaseDict.TryGetValue(!string.IsNullOrEmpty(block.Type) ? block.Type : "block", out var blockInfobaseUrl);

if (!string.IsNullOrEmpty(blockInfobaseUrl))
{
if (blockInfobaseUrl.Contains(CoinMetaData.BlockHeightPH))
block.InfoLink = blockInfobaseUrl.Replace(CoinMetaData.BlockHeightPH, block.BlockHeight.ToString(CultureInfo.InvariantCulture));
else if (blockInfobaseUrl.Contains(CoinMetaData.BlockHashPH) && !string.IsNullOrEmpty(block.Hash))
block.InfoLink = blockInfobaseUrl.Replace(CoinMetaData.BlockHashPH, block.Hash);
}
}
}
}

return blocks;
}

#endregion // Actions

private PoolConfig GetPoolNoThrow(string poolId)
{
if (string.IsNullOrEmpty(poolId))
return null;

var pool = clusterConfig.Pools.FirstOrDefault(x => x.Id == poolId && x.Enabled);
return pool;
}
}
}
9 changes: 6 additions & 3 deletions src/Miningcore/Api/Controllers/PoolApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,15 @@ public async Task<MinerPerformanceStats[]> PagePoolMinersAsync(

[HttpGet("{poolId}/blocks")]
public async Task<Responses.Block[]> PagePoolBlocksPagedAsync(
string poolId, [FromQuery] int page, [FromQuery] int pageSize)
string poolId, [FromQuery] int page, [FromQuery] int pageSize, [FromQuery] BlockStatus[] state)
{
var pool = GetPool(poolId);

var blocks = (await cf.Run(con => blocksRepo.PageBlocksAsync(con, pool.Id,
new[] { BlockStatus.Confirmed, BlockStatus.Pending, BlockStatus.Orphaned }, page, pageSize)))
var blockStates = state != null && state.Length > 0 ?
state :
new[] { BlockStatus.Confirmed, BlockStatus.Pending, BlockStatus.Orphaned };

var blocks = (await cf.Run(con => blocksRepo.PageBlocksAsync(con, pool.Id, blockStates, page, pageSize)))
.Select(mapper.Map<Responses.Block>)
.ToArray();

Expand Down
1 change: 1 addition & 0 deletions src/Miningcore/Api/Responses/GetBlocksResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Miningcore.Api.Responses
{
public class Block
{
public string PoolId { get; set; }
public ulong BlockHeight { get; set; }
public double NetworkDifficulty { get; set; }
public string Status { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum WsNotificationType
NewChainHeight,
Payment,
BlockUnlocked,
BlockUnlockProgress
BlockUnlockProgress,
HashrateUpdated
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public WebSocketNotificationsRelay(WebSocketConnectionManager webSocketConnectio
Relay<BlockConfirmationProgressNotification>(WsNotificationType.BlockUnlockProgress);
Relay<NewChainHeightNotification>(WsNotificationType.NewChainHeight);
Relay<PaymentNotification>(WsNotificationType.Payment);
Relay<HashrateNotification>(WsNotificationType.HashrateUpdated);
}

private IMessageBus messageBus;
Expand Down
Loading

0 comments on commit 21356c8

Please sign in to comment.