From ea4e4a16921f08c3397343c7d1a17da4ca20e970 Mon Sep 17 00:00:00 2001 From: jon4hz Date: Tue, 6 Dec 2022 17:35:37 +0100 Subject: [PATCH 1/3] Revert "Make topMinersRange nullable" This reverts commit db1726e2fb2d37081895fb12c2a19d7267eb193f. --- src/Miningcore/Api/Controllers/PoolApiController.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Miningcore/Api/Controllers/PoolApiController.cs b/src/Miningcore/Api/Controllers/PoolApiController.cs index ff09cfe5c..2649a6c94 100644 --- a/src/Miningcore/Api/Controllers/PoolApiController.cs +++ b/src/Miningcore/Api/Controllers/PoolApiController.cs @@ -50,7 +50,7 @@ public PoolApiController(IComponentContext ctx, IActionDescriptorCollectionProvi #region Actions [HttpGet] - public async Task Get(CancellationToken ct, [FromQuery] uint? topMinersRange) + public async Task Get(CancellationToken ct, [FromQuery] uint topMinersRange = 24) { var response = new GetPoolsResponse { @@ -73,12 +73,12 @@ public async Task Get(CancellationToken ct, [FromQuery] uint? if(lastBlockTime.HasValue) { - var startTime = lastBlockTime.Value; + DateTime startTime = lastBlockTime.Value; var poolEffort = await cf.Run(con => shareRepo.GetEffortBetweenCreatedAsync(con, config.Id, pool.ShareMultiplier, startTime, clock.Now)); result.PoolEffort = poolEffort.Value; } - var from = topMinersRange.HasValue ? clock.Now.AddHours(-topMinersRange.Value) : clock.Now; + var from = clock.Now.AddHours(-topMinersRange); var minersByHashrate = await cf.Run(con => statsRepo.PagePoolMinersByHashrateAsync(con, config.Id, from, 0, 15, ct)); From 9c0459120302b75dfc30ded0da0d3df16973d65e Mon Sep 17 00:00:00 2001 From: jon4hz Date: Tue, 6 Dec 2022 17:35:58 +0100 Subject: [PATCH 2/3] fix: prevent exception if effort is null --- .../Api/Controllers/PoolApiController.cs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Miningcore/Api/Controllers/PoolApiController.cs b/src/Miningcore/Api/Controllers/PoolApiController.cs index 2649a6c94..7230b3e62 100644 --- a/src/Miningcore/Api/Controllers/PoolApiController.cs +++ b/src/Miningcore/Api/Controllers/PoolApiController.cs @@ -1,5 +1,10 @@ +using System.Collections.Concurrent; +using System.Data; +using System.Globalization; +using System.Net; using Autofac; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ActionConstraints; using Microsoft.AspNetCore.Mvc.Infrastructure; using Miningcore.Api.Extensions; using Miningcore.Api.Responses; @@ -11,11 +16,6 @@ using Miningcore.Persistence.Model.Projections; using Miningcore.Persistence.Repositories; using Miningcore.Time; -using System.Collections.Concurrent; -using System.Data; -using System.Globalization; -using System.Net; -using Microsoft.AspNetCore.Mvc.ActionConstraints; using NLog; namespace Miningcore.Api.Controllers; @@ -75,7 +75,8 @@ public async Task Get(CancellationToken ct, [FromQuery] uint t { DateTime startTime = lastBlockTime.Value; var poolEffort = await cf.Run(con => shareRepo.GetEffortBetweenCreatedAsync(con, config.Id, pool.ShareMultiplier, startTime, clock.Now)); - result.PoolEffort = poolEffort.Value; + if(poolEffort.HasValue) + result.PoolEffort = poolEffort.Value; } var from = clock.Now.AddHours(-topMinersRange); @@ -143,7 +144,8 @@ public async Task GetPoolInfoAsync(string poolId, CancellationT { DateTime startTime = lastBlockTime.Value; var poolEffort = await cf.Run(con => shareRepo.GetEffortBetweenCreatedAsync(con, pool.Id, poolInstance.ShareMultiplier, startTime, clock.Now)); - response.Pool.PoolEffort = poolEffort.Value; + if(poolEffort.HasValue) + response.Pool.PoolEffort = poolEffort.Value; } var from = clock.Now.AddHours(-topMinersRange); @@ -587,7 +589,7 @@ public async Task> PageMinerEarningsByDayV2A if(pool.Template.Family == CoinFamily.Ethereum) address = address.ToLower(); - var result = await cf.Run(con=> minerRepo.GetSettingsAsync(con, null, pool.Id, address)); + var result = await cf.Run(con => minerRepo.GetSettingsAsync(con, null, pool.Id, address)); if(result == null) throw new ApiException("No settings found", HttpStatusCode.NotFound); @@ -614,14 +616,14 @@ public async Task> PageMinerEarningsByDayV2A throw new ApiException("Invalid IP address", HttpStatusCode.BadRequest); // fetch recent IPs - var ips = await cf.Run(con=> shareRepo.GetRecentyUsedIpAddressesAsync(con, null, poolId, address, ct)); + var ips = await cf.Run(con => shareRepo.GetRecentyUsedIpAddressesAsync(con, null, poolId, address, ct)); // any known ips? if(ips == null || ips.Length == 0) throw new ApiException("Address not recently used for mining", HttpStatusCode.NotFound); // match? - if(!ips.Any(x=> IPAddress.TryParse(x, out var ipAddress) && ipAddress.IsEqual(requestIp))) + if(!ips.Any(x => IPAddress.TryParse(x, out var ipAddress) && ipAddress.IsEqual(requestIp))) throw new ApiException("None of the recently used IP addresses matches the request", HttpStatusCode.Forbidden); // map settings @@ -639,7 +641,7 @@ public async Task> PageMinerEarningsByDayV2A { await minerRepo.UpdateSettingsAsync(con, tx, mapped); - logger.Info(()=> $"Updated settings for pool {pool.Id}, miner {address}"); + logger.Info(() => $"Updated settings for pool {pool.Id}, miner {address}"); var result = await minerRepo.GetSettingsAsync(con, tx, mapped.PoolId, mapped.Address); return mapper.Map(result); From 760fab129a1550997b7fd75ba88efb1f97f02a59 Mon Sep 17 00:00:00 2001 From: jon4hz Date: Tue, 6 Dec 2022 17:37:02 +0100 Subject: [PATCH 3/3] fix: use var --- src/Miningcore/Api/Controllers/PoolApiController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Miningcore/Api/Controllers/PoolApiController.cs b/src/Miningcore/Api/Controllers/PoolApiController.cs index 7230b3e62..d84de8f7e 100644 --- a/src/Miningcore/Api/Controllers/PoolApiController.cs +++ b/src/Miningcore/Api/Controllers/PoolApiController.cs @@ -73,7 +73,7 @@ public async Task Get(CancellationToken ct, [FromQuery] uint t if(lastBlockTime.HasValue) { - DateTime startTime = lastBlockTime.Value; + var startTime = lastBlockTime.Value; var poolEffort = await cf.Run(con => shareRepo.GetEffortBetweenCreatedAsync(con, config.Id, pool.ShareMultiplier, startTime, clock.Now)); if(poolEffort.HasValue) result.PoolEffort = poolEffort.Value; @@ -142,7 +142,7 @@ public async Task GetPoolInfoAsync(string poolId, CancellationT if(lastBlockTime.HasValue) { - DateTime startTime = lastBlockTime.Value; + var startTime = lastBlockTime.Value; var poolEffort = await cf.Run(con => shareRepo.GetEffortBetweenCreatedAsync(con, pool.Id, poolInstance.ShareMultiplier, startTime, clock.Now)); if(poolEffort.HasValue) response.Pool.PoolEffort = poolEffort.Value;