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

Commit

Permalink
Dev (#389)
Browse files Browse the repository at this point in the history
Fixes problem with ZCash during transition phase between "Overwinter" and "Sapling"
  • Loading branch information
Oliver Weichhold authored Sep 14, 2018
1 parent 57c26f7 commit 1191fc3
Show file tree
Hide file tree
Showing 243 changed files with 20,197 additions and 20,175 deletions.
57 changes: 28 additions & 29 deletions src/MiningCore/Api/ApiServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,22 @@ public ApiServer(

requestMap = new Dictionary<Regex, Func<HttpContext, Match, Task>>
{
{ new Regex("^/api/pools$", RegexOptions.Compiled), GetPoolInfosAsync },
{ new Regex("^/api/pools/(?<poolId>[^/]+)/performance$", RegexOptions.Compiled), GetPoolPerformanceAsync },
{ new Regex("^/api/pools/(?<poolId>[^/]+)/miners$", RegexOptions.Compiled), PagePoolMinersAsync },
{ new Regex("^/api/pools/(?<poolId>[^/]+)/blocks$", RegexOptions.Compiled), PagePoolBlocksPagedAsync },
{ new Regex("^/api/pools/(?<poolId>[^/]+)/payments$", RegexOptions.Compiled), PagePoolPaymentsAsync },
{ new Regex("^/api/pools/(?<poolId>[^/]+)$", RegexOptions.Compiled), GetPoolInfoAsync },
{ new Regex("^/api/pools/(?<poolId>[^/]+)/miners/(?<address>[^/]+)/payments$", RegexOptions.Compiled), PageMinerPaymentsAsync },
{ new Regex("^/api/pools/(?<poolId>[^/]+)/miners/(?<address>[^/]+)/balancechanges$", RegexOptions.Compiled), PageMinerBalanceChangesAsync },
{ new Regex("^/api/pools/(?<poolId>[^/]+)/miners/(?<address>[^/]+)/performance$", RegexOptions.Compiled), GetMinerPerformanceAsync },
{ new Regex("^/api/pools/(?<poolId>[^/]+)/miners/(?<address>[^/]+)$", RegexOptions.Compiled), GetMinerInfoAsync },
{new Regex("^/api/pools$", RegexOptions.Compiled), GetPoolInfosAsync},
{new Regex("^/api/pools/(?<poolId>[^/]+)/performance$", RegexOptions.Compiled), GetPoolPerformanceAsync},
{new Regex("^/api/pools/(?<poolId>[^/]+)/miners$", RegexOptions.Compiled), PagePoolMinersAsync},
{new Regex("^/api/pools/(?<poolId>[^/]+)/blocks$", RegexOptions.Compiled), PagePoolBlocksPagedAsync},
{new Regex("^/api/pools/(?<poolId>[^/]+)/payments$", RegexOptions.Compiled), PagePoolPaymentsAsync},
{new Regex("^/api/pools/(?<poolId>[^/]+)$", RegexOptions.Compiled), GetPoolInfoAsync},
{new Regex("^/api/pools/(?<poolId>[^/]+)/miners/(?<address>[^/]+)/payments$", RegexOptions.Compiled), PageMinerPaymentsAsync},
{new Regex("^/api/pools/(?<poolId>[^/]+)/miners/(?<address>[^/]+)/balancechanges$", RegexOptions.Compiled), PageMinerBalanceChangesAsync},
{new Regex("^/api/pools/(?<poolId>[^/]+)/miners/(?<address>[^/]+)/performance$", RegexOptions.Compiled), GetMinerPerformanceAsync},
{new Regex("^/api/pools/(?<poolId>[^/]+)/miners/(?<address>[^/]+)$", RegexOptions.Compiled), GetMinerInfoAsync},
};

requestMapAdmin = new Dictionary<Regex, Func<HttpContext, Match, Task>>
{
{ new Regex("^/api/admin/forcegc$", RegexOptions.Compiled), HandleForceGcAsync },
{ new Regex("^/api/admin/stats/gc$", RegexOptions.Compiled), HandleGcStatsAsync },
{new Regex("^/api/admin/forcegc$", RegexOptions.Compiled), HandleForceGcAsync},
{new Regex("^/api/admin/stats/gc$", RegexOptions.Compiled), HandleGcStatsAsync},
};
}

Expand Down Expand Up @@ -192,7 +192,7 @@ private async Task HandleRequest(HttpContext context)
context.Response.StatusCode = 404;
}

catch(Exception ex)
catch (Exception ex)
{
logger.Error(ex);
throw;
Expand All @@ -207,7 +207,7 @@ private WorkerPerformanceStatsContainer[] GetMinerPerformanceInternal(string mod
if (mode == "day" || mode != "month")
{
// set range
if(end.Minute < 30)
if (end.Minute < 30)
end = end.AddHours(-1);

end = end.AddMinutes(-end.Minute);
Expand All @@ -221,7 +221,7 @@ private WorkerPerformanceStatsContainer[] GetMinerPerformanceInternal(string mod

else
{
if(end.Hour < 12)
if (end.Hour < 12)
end = end.AddDays(-1);

end = end.Date;
Expand All @@ -242,7 +242,7 @@ private async Task GetPoolInfosAsync(HttpContext context, Match m)
{
var response = new GetPoolsResponse
{
Pools = clusterConfig.Pools.Where(x=> x.Enabled).Select(config =>
Pools = clusterConfig.Pools.Where(x => x.Enabled).Select(config =>
{
// load stats
var stats = cf.Run(con => statsRepo.GetLastPoolStats(con, config.Id));
Expand Down Expand Up @@ -281,8 +281,8 @@ private async Task GetPoolInfoAsync(HttpContext context, Match m)
var response = new GetPoolResponse
{
Pool = pool.ToPoolInfo(mapper, stats)
};

};

// enrich
response.Pool.TotalPaid = cf.Run(con => statsRepo.GetTotalPoolPayments(con, pool.Id));
#if DEBUG
Expand Down Expand Up @@ -363,14 +363,14 @@ private async Task PagePoolBlocksPagedAsync(HttpContext context, Match m)
}

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

// enrich blocks
CoinMetaData.BlockInfoLinks.TryGetValue(pool.Coin.Type, out var blockInfobaseDict);

foreach(var block in blocks)
foreach (var block in blocks)
{
// compute infoLink
if (blockInfobaseDict != null)
Expand All @@ -379,9 +379,9 @@ private async Task PagePoolBlocksPagedAsync(HttpContext context, Match m)

if (!string.IsNullOrEmpty(blockInfobaseUrl))
{
if(blockInfobaseUrl.Contains(CoinMetaData.BlockHeightPH))
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))
else if (blockInfobaseUrl.Contains(CoinMetaData.BlockHashPH) && !string.IsNullOrEmpty(block.Hash))
block.InfoLink = blockInfobaseUrl.Replace(CoinMetaData.BlockHashPH, block.Hash);
}
}
Expand Down Expand Up @@ -600,7 +600,7 @@ private void StartApi(ClusterConfig clusterConfig)
}

#endregion // API


#region Admin API

private async Task HandleRequestAdmin(HttpContext context)
Expand Down Expand Up @@ -632,7 +632,7 @@ private async Task HandleRequestAdmin(HttpContext context)
throw;
}
}


private void StartAdminApi(ClusterConfig clusterConfig)
{
var address = clusterConfig.Api?.ListenAddress != null
Expand All @@ -649,12 +649,12 @@ private void StartAdminApi(ClusterConfig clusterConfig)
webHostAdmin.Start();

logger.Info(() => $"Admin API Online @ {address}:{port}");
}

}

#endregion // Admin API


#region API-Surface


public void Start(ClusterConfig clusterConfig)
{
Contract.RequiresNonNull(clusterConfig, nameof(clusterConfig));
Expand All @@ -666,6 +666,5 @@ public void Start(ClusterConfig clusterConfig)
}

#endregion // API-Surface

}
}
6 changes: 3 additions & 3 deletions src/MiningCore/Api/Extensions/MiningPoolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static PoolInfo ToPoolInfo(this PoolConfig pool, IMapper mapper, Persiste
poolInfo.AddressInfoLink = string.Format(addressInfobaseUrl, poolInfo.Address);

// pool fees
poolInfo.PoolFeePercent = (float)pool.RewardRecipients.Sum(x => x.Percentage);
poolInfo.PoolFeePercent = (float) pool.RewardRecipients.Sum(x => x.Percentage);

// strip security critical stuff
if (poolInfo.PaymentProcessing.Extra != null)
Expand All @@ -45,7 +45,7 @@ private static string GetPoolAlgorithm(PoolConfig pool)
string result = null;

if (CoinMetaData.CoinAlgorithm.TryGetValue(pool.Coin.Type, out var getter))
result = getter(pool.Coin.Type, pool.Coin.Algorithm);
result = getter(pool.Coin.Type, pool.Coin.Algorithm);

// Capitalize
if (!string.IsNullOrEmpty(result) && result.Length > 1)
Expand All @@ -54,4 +54,4 @@ private static string GetPoolAlgorithm(PoolConfig pool)
return result;
}
}
}
}
66 changes: 33 additions & 33 deletions src/MiningCore/Api/Responses/GetAdminStatsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,37 @@ portions of the Software.
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.
*/

using System;

namespace MiningCore.Api.Responses
{
public class AdminGcStats
{
/// <summary>
/// Number of Generation 0 collections
/// </summary>
public int GcGen0 { get; set; }

/// <summary>
/// Number of Generation 1 collections
/// </summary>
public int GcGen1 { get; set; }

/// <summary>
/// Number of Generation 2 collections
/// </summary>
public int GcGen2 { get; set; }

/// <summary>
/// Assumed amount of allocated memory
/// </summary>
public string MemAllocated { get; set; }

/// <summary>
/// Maximum time in seconds spent in full GC
/// </summary>
public double MaxFullGcDuration { get; set; } = 0;
}
*/

using System;

namespace MiningCore.Api.Responses
{
public class AdminGcStats
{
/// <summary>
/// Number of Generation 0 collections
/// </summary>
public int GcGen0 { get; set; }

/// <summary>
/// Number of Generation 1 collections
/// </summary>
public int GcGen1 { get; set; }

/// <summary>
/// Number of Generation 2 collections
/// </summary>
public int GcGen2 { get; set; }

/// <summary>
/// Assumed amount of allocated memory
/// </summary>
public string MemAllocated { get; set; }

/// <summary>
/// Maximum time in seconds spent in full GC
/// </summary>
public double MaxFullGcDuration { get; set; } = 0;
}
}
32 changes: 16 additions & 16 deletions src/MiningCore/Api/Responses/GetBalanceChangesResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ portions of the Software.
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.
*/

using System;
using MiningCore.Configuration;

namespace MiningCore.Api.Responses
{
public class BalanceChange
{
public string PoolId { get; set; }
public string Coin { get; set; }
public string Address { get; set; }
public decimal Amount { get; set; }
public string Usage { get; set; }
public DateTime Created { get; set; }
}
*/

using System;
using MiningCore.Configuration;

namespace MiningCore.Api.Responses
{
public class BalanceChange
{
public string PoolId { get; set; }
public string Coin { get; set; }
public string Address { get; set; }
public decimal Amount { get; set; }
public string Usage { get; set; }
public DateTime Created { get; set; }
}
}
44 changes: 22 additions & 22 deletions src/MiningCore/Api/Responses/GetBlocksResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ portions of the Software.
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.
*/

using System;

namespace MiningCore.Api.Responses
{
public class Block
{
public ulong BlockHeight { get; set; }
public double NetworkDifficulty { get; set; }
public string Status { get; set; }
public string Type { get; set; }
public double ConfirmationProgress { get; set; }
public double? Effort { get; set; }
public string TransactionConfirmationData { get; set; }
public decimal Reward { get; set; }
public string InfoLink { get; set; }
public string Hash { get; set; }
public string Miner { get; set; }
public string Source { get; set; }
public DateTime Created { get; set; }
}
*/

using System;

namespace MiningCore.Api.Responses
{
public class Block
{
public ulong BlockHeight { get; set; }
public double NetworkDifficulty { get; set; }
public string Status { get; set; }
public string Type { get; set; }
public double ConfirmationProgress { get; set; }
public double? Effort { get; set; }
public string TransactionConfirmationData { get; set; }
public decimal Reward { get; set; }
public string InfoLink { get; set; }
public string Hash { get; set; }
public string Miner { get; set; }
public string Source { get; set; }
public DateTime Created { get; set; }
}
}
Loading

0 comments on commit 1191fc3

Please sign in to comment.