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

Commit

Permalink
Dev (#135)
Browse files Browse the repository at this point in the history
* Log block height for balance changes
* Fix share traversal
* Log one address per line
* Compute miner/worker hashrates from database instead of buffering shares in memory
* PPLNS fixes
* ZCash shield coinbase fix
* Increase stats update interval
  • Loading branch information
Oliver Weichhold authored Dec 29, 2017
1 parent 321ac0e commit 8acbf4f
Show file tree
Hide file tree
Showing 30 changed files with 487 additions and 504 deletions.
20 changes: 11 additions & 9 deletions src/MiningCore/Api/ApiServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
Expand All @@ -35,14 +36,12 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using MiningCore.Api.Extensions;
using MiningCore.Api.Responses;
using MiningCore.Blockchain;
using MiningCore.Buffers;
using MiningCore.Configuration;
using MiningCore.Extensions;
using MiningCore.Mining;
using MiningCore.Persistence;
using MiningCore.Persistence.Model;
using MiningCore.Persistence.Repositories;
using MiningCore.Stratum;
using MiningCore.Time;
using MiningCore.Util;
using Newtonsoft.Json;
Expand Down Expand Up @@ -171,7 +170,7 @@ private IMiningPool GetPool(HttpContext context, Match m)
lock(pools)
{
var pool = pools.FirstOrDefault(x => x.Config.Id == poolId);

if (pool != null)
return pool;
}
Expand Down Expand Up @@ -206,7 +205,7 @@ private async Task HandleGetPoolAsync(HttpContext context, Match m)
{
Pool = pool.ToPoolInfo(mapper)
};

await SendJson(context, response);
}

Expand Down Expand Up @@ -247,7 +246,7 @@ private async Task HandleGetBlocksPagedAsync(HttpContext context, Match m)
}

var blocks = cf.Run(con => blocksRepo.PageBlocks(con, pool.Config.Id,
new[] { BlockStatus.Confirmed, BlockStatus.Pending }, page, pageSize))
new[] { BlockStatus.Confirmed, BlockStatus.Pending, BlockStatus.Orphaned }, page, pageSize))
.Select(mapper.Map<Responses.Block>)
.ToArray();

Expand Down Expand Up @@ -320,12 +319,15 @@ private async Task HandleGetMinerStatsAsync(HttpContext context, Match m)
return;
}

var statsResult = cf.Run(con => statsRepo.GetMinerStats(con, pool.Config.Id, address));
Responses.MinerStats stats = null;
var statsResult = cf.RunTx((con, tx) =>
statsRepo.GetMinerStats(con, tx, pool.Config.Id, address),
true, IsolationLevel.Serializable);

MinerStats stats = null;

if (statsResult != null)
{
stats = mapper.Map<Responses.MinerStats>(statsResult);
stats = mapper.Map<MinerStats>(statsResult);

// optional fields
if (statsResult.LastPayment != null)
Expand Down Expand Up @@ -393,6 +395,6 @@ public void AttachPool(IMiningPool pool)
}

#endregion // API-Surface

}
}
2 changes: 1 addition & 1 deletion src/MiningCore/Api/Responses/GetMinerStatsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public class MinerStats
public decimal TotalPaid { get; set; }
public DateTime? LastPayment { get; set; }
public string LastPaymentLink { get; set; }
public MinerHashrateSample[] Hashrate { get; set; }
public MinerWorkerPerformanceStats[] PerformanceStats { get; set; }
}
}
8 changes: 8 additions & 0 deletions src/MiningCore/AutoMapperProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using MiningCore.Blockchain;
using MiningCore.Configuration;
using MiningCore.Persistence.Model;
using MiningCore.Persistence.Model.Projections;
using MinerStats = MiningCore.Persistence.Model.Projections.MinerStats;

namespace MiningCore
{
Expand Down Expand Up @@ -63,6 +65,9 @@ public AutoMapperProfile()
CreateMap<Payment, Persistence.Postgres.Entities.Payment>();
CreateMap<PoolStats, Persistence.Postgres.Entities.PoolStats>();

CreateMap<MinerWorkerPerformanceStats, Persistence.Postgres.Entities.MinerWorkerPerformanceStats>()
.ForMember(dest => dest.Id, opt => opt.Ignore());

//////////////////////
// incoming mappings

Expand All @@ -72,6 +77,9 @@ public AutoMapperProfile()
CreateMap<Persistence.Postgres.Entities.Balance, Balance>();
CreateMap<Persistence.Postgres.Entities.Payment, Payment>();
CreateMap<Persistence.Postgres.Entities.PoolStats, PoolStats>();
CreateMap<Persistence.Postgres.Entities.MinerWorkerPerformanceStats, MinerWorkerPerformanceStats>();

CreateMap<PoolStats, Mining.PoolStats>();
}
}
}
6 changes: 4 additions & 2 deletions src/MiningCore/AutofacModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using MiningCore.Blockchain.ZCash;
using MiningCore.Blockchain.ZCash.DaemonResponses;
using MiningCore.Configuration;
using MiningCore.JsonRpc;
using MiningCore.Mining;
using MiningCore.Notifications;
using MiningCore.Payments;
Expand Down Expand Up @@ -83,6 +82,9 @@ protected override void Load(ContainerBuilder builder)
builder.RegisterType<ApiServer>()
.SingleInstance();

builder.RegisterType<StatsRecorder>()
.AsSelf();

builder.RegisterType<NotificationService>()
.SingleInstance();

Expand All @@ -98,7 +100,7 @@ protected override void Load(ContainerBuilder builder)
//////////////////////
// Payment Schemes

builder.RegisterType<PayPerLastNShares>()
builder.RegisterType<PPLNS>()
.Keyed<IPayoutScheme>(PayoutScheme.PPLNS)
.SingleInstance();

Expand Down
50 changes: 4 additions & 46 deletions src/MiningCore/Blockchain/Bitcoin/BitcoinPoolBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,58 +343,16 @@ protected override async Task OnRequestAsync(StratumClient client,
}
}

protected override void SetupStats()
public override ulong HashrateFromShares(double shares, double interval)
{
base.SetupStats();

// Pool Hashrate
var poolHashRateSampleIntervalSeconds = 60 * 10;

disposables.Add(Shares
.ObserveOn(ThreadPoolScheduler.Instance)
.Buffer(TimeSpan.FromSeconds(poolHashRateSampleIntervalSeconds))
.Do(shares => UpdateMinerHashrates(shares, poolHashRateSampleIntervalSeconds))
.Select(shares =>
{
if (!shares.Any())
return 0ul;

try
{
return HashrateFromShares(shares, poolHashRateSampleIntervalSeconds);
}

catch(Exception ex)
{
logger.Error(ex);
return 0ul;
}
})
.Subscribe(hashRate => poolStats.PoolHashRate = hashRate));

// shares/sec
disposables.Add(Shares
.Buffer(TimeSpan.FromSeconds(1))
.Do(shares =>
{
poolStats.ValidSharesPerSecond = shares.Count;

logger.Debug(() => $"[{LogCat}] Share/sec = {poolStats.ValidSharesPerSecond}");
})
.Subscribe());
}

protected override ulong HashrateFromShares(IEnumerable<ClientShare> shares, int interval)
{
var sum = shares.Sum(share => Math.Max(0.00000001, share.Share.Difficulty));
var multiplier = BitcoinConstants.Pow2x32 / manager.ShareMultiplier;
var result = Math.Ceiling(sum * multiplier / interval);
var result = Math.Ceiling(shares * multiplier / interval);

// OW: tmp hotfix
if (poolConfig.Coin.Type == CoinType.MONA || poolConfig.Coin.Type == CoinType.VTC)
result *= 1.3;

return (ulong) result;
Console.WriteLine(result);
return (ulong)result;
}

protected override void OnVarDiffUpdate(StratumClient client, double newDiff)
Expand Down
49 changes: 4 additions & 45 deletions src/MiningCore/Blockchain/Ethereum/EthereumPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,52 +309,11 @@ protected override async Task OnRequestAsync(StratumClient client,
}
}

protected override void SetupStats()
public override ulong HashrateFromShares(double shares, double interval)
{
base.SetupStats();

// Pool Hashrate
var poolHashRateSampleIntervalSeconds = 60 * 10;

disposables.Add(Shares
.ObserveOn(ThreadPoolScheduler.Instance)
.Buffer(TimeSpan.FromSeconds(poolHashRateSampleIntervalSeconds))
.Do(shares => UpdateMinerHashrates(shares, poolHashRateSampleIntervalSeconds))
.Select(shares =>
{
if (!shares.Any())
return 0ul;

try
{
return HashrateFromShares(shares, poolHashRateSampleIntervalSeconds);
}

catch(Exception ex)
{
logger.Error(ex);
return 0ul;
}
})
.Subscribe(hashRate => poolStats.PoolHashRate = hashRate));

// shares/sec
disposables.Add(Shares
.Buffer(TimeSpan.FromSeconds(1))
.Do(shares =>
{
poolStats.ValidSharesPerSecond = shares.Count;

logger.Debug(() => $"[{LogCat}] Share/sec = {poolStats.ValidSharesPerSecond}");
})
.Subscribe());
}

protected override ulong HashrateFromShares(IEnumerable<ClientShare> shares, int interval)
{
var result = Math.Ceiling(shares.Sum(share => share.Share.Difficulty) / interval);
return (ulong) result;
}
var result = Math.Ceiling(shares / interval);
return (ulong)result;
}

protected override void OnVarDiffUpdate(StratumClient client, double newDiff)
{
Expand Down
49 changes: 4 additions & 45 deletions src/MiningCore/Blockchain/Monero/MoneroPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,52 +347,11 @@ protected override async Task OnRequestAsync(StratumClient client,
}
}

protected override void SetupStats()
public override ulong HashrateFromShares(double shares, double interval)
{
base.SetupStats();

// Pool Hashrate
var poolHashRateSampleIntervalSeconds = 60 * 10;

disposables.Add(Shares
.ObserveOn(ThreadPoolScheduler.Instance)
.Buffer(TimeSpan.FromSeconds(poolHashRateSampleIntervalSeconds))
.Do(shares => UpdateMinerHashrates(shares, poolHashRateSampleIntervalSeconds))
.Select(shares =>
{
if (!shares.Any())
return 0ul;

try
{
return HashrateFromShares(shares, poolHashRateSampleIntervalSeconds);
}

catch(Exception ex)
{
logger.Error(ex);
return 0ul;
}
})
.Subscribe(hashRate => poolStats.PoolHashRate = hashRate));

// shares/sec
disposables.Add(Shares
.Buffer(TimeSpan.FromSeconds(1))
.Do(shares =>
{
poolStats.ValidSharesPerSecond = shares.Count;

logger.Debug(() => $"[{LogCat}] Share/sec = {poolStats.ValidSharesPerSecond}");
})
.Subscribe());
}

protected override ulong HashrateFromShares(IEnumerable<ClientShare> shares, int interval)
{
var result = Math.Ceiling(shares.Sum(share => share.Share.Difficulty) / interval);
return (ulong) result;
}
var result = Math.Ceiling(shares / interval);
return (ulong)result;
}

protected override void OnVarDiffUpdate(StratumClient client, double newDiff)
{
Expand Down
Loading

0 comments on commit 8acbf4f

Please sign in to comment.