Skip to content
Open
1 change: 1 addition & 0 deletions aion_pool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ Make the following edits to the config file (aion_pool.json):
- ***accountPassword***: Change to contain the "password" which matches the miner account specified in the kernel configuration.
- (Optional) Change ***minimumConfirmations*** to the number of blocks (depth in the chain) that must be established before rewards begin to be distributed.
- (Optional) ***minimumPeerCount*** is the number of peers your kernel must be connected to minimum this number of peers in order to distribute rewards. This ensures rewards are not distributed should the aion kernel become disconnected from the rest of the network.
- (Optional) ***hashratePercentageCalcInterval*** (seconds) is the interval at which your pool(s) will poll the kernal to get the network hashrate and pool hashrate. These are used to calculate the pool(s)' hashrate percentage of the total network hashrate.

More information on the configuration file [here](https://github.com/coinfoundry/miningcore/wiki/Configuration).

Expand Down
4 changes: 3 additions & 1 deletion aion_pool/examples/aion_pool.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"jobRebroadcastTimeout": 10,

"clientConnectionTimeout": 600,

"hashratePercentageCalcInterval": 40,

"banning": {
"enabled": true,
Expand Down Expand Up @@ -118,4 +120,4 @@
}
}]
}


2 changes: 1 addition & 1 deletion aion_pool/src/MiningCore/Api/ApiServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private async Task GetMiningPoolHashrateStats(HttpContext context, Match m)
PoolValueStat[] stats = cf.Run(con => statsRepo.GetPoolHashrate(con, pool.Id, start, end, granularity));
await SendJsonAsync(context, stats);
}

private async Task GetMiningPoolStats(HttpContext context, Match m)
{
var pool = GetPool(context, m);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public partial class AggregatedPoolStats
public int ConnectedMiners { get; set; }
public double NetworkHashrate { get; set; }
public DateTime Created { get; set; }
public double PoolHashratePercentage {get; set;}
}

public class GetPoolStatsResponse
Expand Down
1 change: 1 addition & 0 deletions aion_pool/src/MiningCore/Api/Responses/GetPoolsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public partial class PoolInfo
public BlockchainStats NetworkStats { get; set; }
public MinerPerformanceStats[] TopMiners { get; set; }
public decimal TotalPaid { get; set; }

}

public class GetPoolsResponse
Expand Down
3 changes: 3 additions & 0 deletions aion_pool/src/MiningCore/AutofacModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ protected override void Load(ContainerBuilder builder)

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

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

builder.RegisterType<NotificationService>()
.SingleInstance();
Expand Down
1 change: 1 addition & 0 deletions aion_pool/src/MiningCore/Blockchain/Aion/AionConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static class AionCommands
public const string GetDifficulty = "getdifficulty";
public const string GetMinerStats = "getMinerStats";
public const string Ping = "ping";

}

}
27 changes: 24 additions & 3 deletions aion_pool/src/MiningCore/Blockchain/Aion/AionJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
using NBitcoin;
using NBitcoin.DataEncoders;
using NLog;
using MiningCore.Blockchain.Aion.DaemonResponses;


namespace MiningCore.Blockchain.Aion
{
Expand Down Expand Up @@ -52,7 +54,7 @@ public AionJob(string id, AionBlockTemplate blockTemplate, ILogger logger, Daemo
private readonly ILogger logger;
private EquihashSolver equihash = EquihashSolver.Instance.Value;
private IHashAlgorithm headerHasher = new Blake2b();
public double Difficulty { get; protected set; }
public double Difficulty { get; set; }
public DaemonClient daemonClient;

private void RegisterNonce(StratumClient worker, string nonce)
Expand Down Expand Up @@ -191,8 +193,27 @@ private byte[] SerializeHeader(string nonce)
}

private double getNetworkDifficulty() {
var response = daemonClient.ExecuteCmdAnyAsync<string>(AionCommands.GetDifficulty).Result;
return (double) Convert.ToInt32(response.Response, 16);
var response = daemonClient.ExecuteStringResponseCmdSingleAsync(AionCommands.GetDifficulty).Result;
try
{
double output = (double)Convert.ToInt32(response, 16);
return output;
}
catch
{
logger.Info(() => $"Error in casting getDifficulty response from string to int. Response: {response}");
logger.Error($"Network Difficulty Cast error: {response}");
}

return 0;
}

private double GetPoolNetworkPercentage(string poolAddress)
{
var response = daemonClient.ExecuteCmdAnyAsync<GetMinerHashRateResponse>(AionCommands.GetMinerStats, new [] { poolAddress }).Result;
var networkPercentage = (double) Convert.ToDouble(response.Response.MinerHashrateShare);
return networkPercentage;
}

}
}
2 changes: 2 additions & 0 deletions aion_pool/src/MiningCore/Blockchain/Aion/AionJobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ protected bool UpdateJob(AionBlockTemplate blockTemplate)
BlockchainStats.BlockHeight = (long) currentJob.BlockTemplate.Height;
var (networkHashrate, poolHashRate) = getNetworkAndMinerHashRate();
BlockchainStats.NetworkHashrate = networkHashrate;
// Update network difficulty
BlockchainStats.NetworkDifficulty = job.Difficulty;
PoolHashRate = poolHashRate;
}

Expand Down
2 changes: 2 additions & 0 deletions aion_pool/src/MiningCore/Blockchain/Aion/AionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ private async Task OnSubmitAsync(StratumClient client, Timestamped<JsonRpcReques
// update pool stats
if (share.IsBlockCandidate)
poolStats.LastPoolBlockTime = clock.Now;
// included by Andre-aion
poolStats.NetworkDifficulty = context.Difficulty;

}
catch (MiningCore.Stratum.StratumException ex)
Expand Down
26 changes: 26 additions & 0 deletions aion_pool/src/MiningCore/Blockchain/Aion/AionUtils.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
using System.Numerics;
using System.Linq;
using System;
using MiningCore.DaemonInterface;
using MiningCore.Persistence.Postgres.Entities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog;

namespace MiningCore.Blockchain.Aion
{
Expand Down Expand Up @@ -64,5 +69,26 @@ protected static string bytetoHex(byte[] tmp)
return new string(c);
}

public static double getNetworkDifficulty()
{
JsonSerializerSettings serializerSettings = null;
DaemonClient daemonClient = new DaemonClient(serializerSettings);
var response = daemonClient.ExecuteStringResponseCmdSingleAsync(AionCommands.GetDifficulty).Result;
try
{
double output = (double)Convert.ToInt32(response, 16);
return output;
}
catch
{
Console.WriteLine($"Network Difficulty Cast error: {response}");
}

return 0;
}


}


}
1 change: 1 addition & 0 deletions aion_pool/src/MiningCore/Configuration/ClusterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ public partial class PoolConfig
public int ClientConnectionTimeout { get; set; }
public int JobRebroadcastTimeout { get; set; }
public int BlockRefreshInterval { get; set; }
public int HashratePercentageCalcInterval { get; set; }

/// <summary>
/// If true, internal stratum ports are not initialized
Expand Down
23 changes: 22 additions & 1 deletion aion_pool/src/MiningCore/DaemonInterface/DaemonClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,29 @@ public Task<DaemonResponse<JToken>> ExecuteCmdSingleAsync(string method)
{
return ExecuteCmdAnyAsync<JToken>(method);
}

/// <summary>
/// /Executes the request for only getDifficulty
/// </summary>
/// <param name="method"></param>
/// <param name="payload"></param>
/// <param name="payloadJsonSerializerSettings"></param>
/// <param name="throwOnError"></param>
/// <returns></returns>
public async Task<string> ExecuteStringResponseCmdSingleAsync(string method, object payload = null,
JsonSerializerSettings payloadJsonSerializerSettings = null, bool throwOnError = false)
{
Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(method), $"{nameof(method)} must not be empty");

logger.LogInvoke(new[] { method });

var tasks = endPoints.Select(endPoint => BuildRequestTask(endPoint, method, payload, payloadJsonSerializerSettings)).ToArray();

var taskFirstCompleted = await Task.WhenAny(tasks);
return MapDaemonResponse<string>(0, taskFirstCompleted).Response;
}


/// <summary>
/// Executes the request against all configured demons and returns the first successful response
/// </summary>
Expand All @@ -200,7 +222,6 @@ public async Task<DaemonResponse<TResponse>> ExecuteCmdSingleAsync<TResponse>(st
where TResponse : class
{
Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(method), $"{nameof(method)} must not be empty");

logger.LogInvoke(new[] { method });

var task = BuildRequestTask(endPoints.First(), method, payload, payloadJsonSerializerSettings);
Expand Down
1 change: 1 addition & 0 deletions aion_pool/src/MiningCore/DaemonInterface/DaemonResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ public class DaemonResponse<T>
public JsonRpcException Error { get; set; }
public T Response { get; set; }
public AuthenticatedNetworkEndpointConfig Instance { get; set; }
public string DifficultyResponse { get; set; }
}
}
3 changes: 2 additions & 1 deletion aion_pool/src/MiningCore/Mining/PoolBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using AutoMapper;
using MiningCore.Banning;
using MiningCore.Blockchain;
using MiningCore.Blockchain.Aion;
using MiningCore.Configuration;
using MiningCore.Extensions;
using MiningCore.Messaging;
Expand Down Expand Up @@ -312,7 +313,7 @@ private void OutputPoolInfo()
Detected Reward Type: {blockchainStats?.RewardType}
Current Block Height: {blockchainStats?.BlockHeight}
Current Connect Peers: {blockchainStats?.ConnectedPeers}
Network Difficulty: {blockchainStats?.NetworkDifficulty}
Network Difficulty: {FormatUtil.FormatDifficulty(blockchainStats != null ? blockchainStats.NetworkDifficulty: AionUtils.getNetworkDifficulty())}
Network Hash Rate: {FormatUtil.FormatHashrate(blockchainStats != null ? blockchainStats.NetworkHashrate : 0)}
Stratum Port(s): {(poolConfig.Ports?.Any() == true ? string.Join(", ", poolConfig.Ports.Keys) : string.Empty )}
Pool Fee: {(poolConfig.RewardRecipients?.Any() == true ? poolConfig.RewardRecipients.Sum(x => x.Percentage) : 0)}%
Expand Down
Loading