Skip to content

Commit

Permalink
Merge branch 'aionpool_test_libuv'
Browse files Browse the repository at this point in the history
  • Loading branch information
leoaion committed Jun 3, 2020
2 parents e2f3020 + bcd8b83 commit 6f7f566
Show file tree
Hide file tree
Showing 101 changed files with 1,369 additions and 11,742 deletions.
22 changes: 11 additions & 11 deletions aion_pool/examples/aion_pool_slave.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@
"checkThreshold": 50
},
"ports": {
"3334": {
"3334": {
"listenAddress": "0.0.0.0",
"difficulty": 128,
"varDiff": {
"minDiff": 128,
"maxDiff": 2048,
"targetTime": 5,
"retargetTime": 5,
"variancePercent": 30,
"maxDelta": 500
}
}
"difficulty": 128,
"varDiff": {
"minDiff": 128,
"maxDiff": 2048,
"targetTime": 5,
"retargetTime": 5,
"variancePercent": 30,
"maxDelta": 500
}
}
},
"daemons": [{
"host": "127.0.0.1",
Expand Down
33 changes: 0 additions & 33 deletions aion_pool/src/Miningcore/AutofacModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using Autofac;
using Miningcore.Api;
using Miningcore.Banning;
using Miningcore.Blockchain.Bitcoin;
using Miningcore.Blockchain.Aion;
using Miningcore.Blockchain.Bitcoin.DaemonResponses;
using Miningcore.Blockchain.Ethereum;
using Miningcore.Blockchain.Cryptonote;
using Miningcore.Blockchain.Equihash;
using Miningcore.Blockchain.Equihash.DaemonResponses;
using Miningcore.Configuration;
using Miningcore.Crypto;
using Miningcore.Crypto.Hashing.Equihash;
Expand Down Expand Up @@ -93,9 +87,6 @@ protected override void Load(ContainerBuilder builder)
builder.RegisterType<RelayReceiver>()
.SingleInstance();

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

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

Expand Down Expand Up @@ -145,30 +136,6 @@ protected override void Load(ContainerBuilder builder)
.Keyed<IPayoutScheme>(PayoutScheme.Solo)
.SingleInstance();

//////////////////////
// Bitcoin and family

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

//////////////////////
// Cryptonote

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

//////////////////////
// Ethereum

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

//////////////////////
// ZCash

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

//////////////////////
// Aion

Expand Down
4 changes: 1 addition & 3 deletions aion_pool/src/Miningcore/Blockchain/Aion/AionJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
using System.Collections.Concurrent;
using Autofac;
using Newtonsoft.Json.Linq;
using Miningcore.Blockchain.Bitcoin;
using Miningcore.Blockchain.Bitcoin.DaemonResponses;
using Miningcore.Configuration;
using Miningcore.Contracts;
using Miningcore.Crypto;
using Miningcore.Crypto.Hashing.Algorithms;
using Miningcore.Crypto.Hashing.Equihash;
using Miningcore.Extensions;
using Miningcore.Stratum;
using Miningcore.Stratum1;
using Miningcore.Time;
using Miningcore.Util;
using Miningcore.DaemonInterface;
Expand Down
13 changes: 10 additions & 3 deletions aion_pool/src/Miningcore/Blockchain/Aion/AionJobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
using Miningcore.Extensions;
using Miningcore.Messaging;
using Miningcore.Notifications;
using Miningcore.Stratum;
using Miningcore.Stratum1;
using Miningcore.Time;
using NBitcoin;
using NLog;
Expand Down Expand Up @@ -101,8 +101,10 @@ public async Task<Share> SubmitShareAsync(StratumClient worker,
// stale?
lock(jobLock)
{
if (!validJobs.TryGetValue(jobId, out job))
if (!validJobs.TryGetValue(jobId, out job)){
// logger.Info(() => $"!!! src/Mingingcore/Blockchain/Aion/AionJobManager.cs/SubmitShareAsync stale-share jobId '{jobId}'");
throw new StratumException(StratumError.MinusOne, "stale share");
}
}

// validate & process
Expand Down Expand Up @@ -233,6 +235,9 @@ protected bool UpdateJob(AionBlockTemplate blockTemplate)

var jobId = NextJobId("x8");
job = new AionJob(jobId, blockTemplate, logger, daemon, ctx, solver);

// logger.Info(() => $"!!! src/Mingingcore/Blockchain/Aion/AionJobManager.cs/UpdateJob jobId '{jobId}' height '{(long)job.BlockTemplate.Height}'");

lock (jobLock)
{
// add jobs
Expand All @@ -242,8 +247,10 @@ protected bool UpdateJob(AionBlockTemplate blockTemplate)
var obsoleteKeys = validJobs.Keys
.Where(key => (long) validJobs[key].BlockTemplate.Height < (long) (job.BlockTemplate.Height - MaxBlockBacklog)).ToArray();

foreach (var key in obsoleteKeys)
foreach (var key in obsoleteKeys){
// logger.Info(() => $"!!! src/Mingingcore/Blockchain/Aion/AionJobManager.cs/UpdateJob job-remove key '{key}' height '{(long) validJobs[key].BlockTemplate.Height}' current-height '{(long)job.BlockTemplate.Height}'");
validJobs.Remove(key);
}
}

currentJob = job;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public AionPayoutHandler(

#region IPayoutHandler

public async Task ConfigureAsync(ClusterConfig clusterConfig, PoolConfig poolConfig)
public void ConfigureAsync(ClusterConfig clusterConfig, PoolConfig poolConfig)
{
this.poolConfig = poolConfig;
this.clusterConfig = clusterConfig;
Expand Down
65 changes: 40 additions & 25 deletions aion_pool/src/Miningcore/Blockchain/Aion/AionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using Miningcore.Notifications;
using Miningcore.Persistence;
using Miningcore.Persistence.Repositories;
using Miningcore.Stratum;
using Miningcore.Stratum1;
using Miningcore.Time;
using Miningcore.Util;
using Newtonsoft.Json;
Expand Down Expand Up @@ -69,7 +69,7 @@ public AionPool(IComponentContext ctx,
private AionJobManager manager;
protected static readonly Regex regexMinimumPayment = new Regex(@";?mp=(\d*(\.\d+)?)", RegexOptions.Compiled);

private async Task OnSubscribeAsync(StratumClient client, Timestamped<JsonRpcRequest> tsRequest)
private void OnSubscribeAsync(StratumClient client, Timestamped<JsonRpcRequest> tsRequest)
{
var request = tsRequest.Value;
var context = client.ContextAs<AionWorkerContext>();
Expand All @@ -95,7 +95,8 @@ private async Task OnSubscribeAsync(StratumClient client, Timestamped<JsonRpcReq
}
.ToArray();

await client.RespondAsync(data, request.Id);
// await client.RespondAsync(data, request.Id);
client.Respond(data, request.Id);

// setup worker context
context.IsSubscribed = true;
Expand Down Expand Up @@ -126,7 +127,8 @@ private async Task OnAuthorizeAsync(StratumClient client, Timestamped<JsonRpcReq
context.MinerName = minerName;
context.WorkerName = workerName;
// respond
await client.RespondAsync(context.IsAuthorized, request.Id);
// await client.RespondAsync(context.IsAuthorized, request.Id);
client.Respond(context.IsAuthorized, request.Id);

// extract control vars from password
var staticDiff = GetStaticDiffFromPassparts(passParts);
Expand All @@ -141,7 +143,7 @@ private async Task OnAuthorizeAsync(StratumClient client, Timestamped<JsonRpcReq
messageBus.SendMessage(new MinerInfo(poolConfig.Id,
context.MinerName, context.MinimumPayment = minimumPayment));

await EnsureInitialWorkSent(client);
EnsureInitialWorkSent(client);

// log association
logger.Info(() => $"[{client.ConnectionId}] Authorized worker {workerValue} mp {minimumPayment}");
Expand Down Expand Up @@ -186,14 +188,15 @@ private async Task OnSubmitAsync(StratumClient client, Timestamped<JsonRpcReques
{
var share = await manager.SubmitShareAsync(client, submitRequest, context.Difficulty, poolEndpoint.Difficulty);
// success
await client.RespondAsync(true, request.Id);
// await client.RespondAsync(true, request.Id);
client.Respond(true, request.Id);
// publish
messageBus.SendMessage(new ClientShare(client, share));
// telemetry
PublishTelemetry(TelemetryCategory.Share, clock.Now - tsRequest.Timestamp.UtcDateTime, true);

logger.Debug(() => $"[{client.ConnectionId}] Share accepted: D={Math.Round(share.Difficulty, 3)}");
await EnsureInitialWorkSent(client);
EnsureInitialWorkSent(client);

// update pool stats
if (share.IsBlockCandidate)
Expand All @@ -202,7 +205,7 @@ private async Task OnSubmitAsync(StratumClient client, Timestamped<JsonRpcReques
context.Stats.ValidShares++;
await UpdateVarDiffAsync(client);
}
catch (Miningcore.Stratum.StratumException ex)
catch (StratumException ex)
{
// telemetry
PublishTelemetry(TelemetryCategory.Share, clock.Now - tsRequest.Timestamp.UtcDateTime, false);
Expand All @@ -220,7 +223,8 @@ private async Task OnSubmitAsync(StratumClient client, Timestamped<JsonRpcReques
}
catch (StratumException ex)
{
await client.RespondErrorAsync(ex.Code, ex.Message, request.Id, false);
// await client.RespondErrorAsync(ex.Code, ex.Message, request.Id, false);
client.RespondError(ex.Code, ex.Message, request.Id, false);
messageBus.SendMessage(new InvalidShare
{
PoolId = poolConfig.Id,
Expand All @@ -242,7 +246,7 @@ private async Task OnSubmitAsync(StratumClient client, Timestamped<JsonRpcReques
}
}

private async Task EnsureInitialWorkSent(StratumClient client)
private void EnsureInitialWorkSent(StratumClient client)
{
var context = client.ContextAs<AionWorkerContext>();
ArrayList arrayTarget = new ArrayList();
Expand All @@ -262,18 +266,21 @@ private async Task EnsureInitialWorkSent(StratumClient client)
if (sendInitialWork)
{
// send intial update
await client.NotifyAsync(AionStratumMethods.MiningNotify, currentJobParams);
await client.NotifyAsync(AionStratumMethods.SetTarget, arrayTarget);
// await client.NotifyAsync(AionStratumMethods.MiningNotify, currentJobParams);
// await client.NotifyAsync(AionStratumMethods.SetTarget, arrayTarget);
client.Notify(AionStratumMethods.MiningNotify, currentJobParams);
client.Notify(AionStratumMethods.SetTarget, arrayTarget);
}
}

protected virtual Task OnNewJobAsync(object jobParams)
protected void OnNewJobAsync(object jobParams)
{
currentJobParams = jobParams;

logger.Debug(() => $"Broadcasting job");

var tasks = ForEachClient(async client =>
// logger.Info(() => "!!! src/Miningcore/Blockchain/Aion/AionPool.cs/OnNewJobAsync");
ForEachClient(client =>
{
var context = client.ContextAs<AionWorkerContext>();

Expand All @@ -292,18 +299,20 @@ protected virtual Task OnNewJobAsync(object jobParams)

// varDiff: if the client has a pending difficulty change, apply it now
if (context.ApplyPendingDifficulty())
await client.NotifyAsync(AionStratumMethods.SetDifficulty, new object[] { context.Difficulty });
// await client.NotifyAsync(AionStratumMethods.SetDifficulty, new object[] { context.Difficulty });
client.Notify(AionStratumMethods.SetDifficulty, new object[] { context.Difficulty });

string newTarget = AionUtils.diffToTarget(context.Difficulty);
ArrayList arrayTarget = new ArrayList();
arrayTarget.Add(newTarget);

await client.NotifyAsync(AionStratumMethods.MiningNotify, currentJobParams);
await client.NotifyAsync(AionStratumMethods.SetTarget, arrayTarget);
// await client.NotifyAsync(AionStratumMethods.MiningNotify, currentJobParams);
// await client.NotifyAsync(AionStratumMethods.SetTarget, arrayTarget);
client.Notify(AionStratumMethods.MiningNotify, currentJobParams);
client.Notify(AionStratumMethods.SetTarget, arrayTarget);
}
});

return Task.WhenAll(tasks);
}

#region Overrides
Expand Down Expand Up @@ -332,23 +341,25 @@ protected override async Task SetupJobManager(CancellationToken ct)
disposables.Add(manager.Jobs
.Select(job => Observable.FromAsync(async () =>
{
await Task.Run(() => {
try
{
await OnNewJobAsync(job);
OnNewJobAsync(job);
}

catch (Exception ex)
{
logger.Debug(() => $"{nameof(OnNewJobAsync)}: {ex.Message}");
}
});
}))
.Concat()
.Subscribe(_ => { }, ex =>
{
logger.Debug(ex, nameof(OnNewJobAsync));
}));

// // we need work before opening the gates
// we need work before opening the gates
await manager.Jobs.Take(1).ToTask(ct);
}
else
Expand Down Expand Up @@ -408,7 +419,7 @@ protected override async Task OnRequestAsync(StratumClient client,
switch (request.Method)
{
case AionStratumMethods.Subscribe:
await OnSubscribeAsync(client, tsRequest);
OnSubscribeAsync(client, tsRequest);
break;

case AionStratumMethods.Authorize:
Expand All @@ -421,13 +432,15 @@ protected override async Task OnRequestAsync(StratumClient client,
default:
logger.Debug(() => $"[{client.ConnectionId}] Unsupported RPC request: {JsonConvert.SerializeObject(request, serializerSettings)}");

await client.RespondErrorAsync(StratumError.Other, $"Unsupported request {request.Method}", request.Id);
//await client.RespondErrorAsync(StratumError.Other, $"Unsupported request {request.Method}", request.Id);
client.RespondError(StratumError.Other, $"Unsupported request {request.Method}", request.Id);
break;
}
}
catch (StratumException ex)
{
await client.RespondErrorAsync(ex.Code, ex.Message, request.Id, false);
// await client.RespondErrorAsync(ex.Code, ex.Message, request.Id, false);
client.RespondError(ex.Code, ex.Message, request.Id, false);
}
}

Expand All @@ -452,8 +465,10 @@ protected override async Task OnVarDiffUpdateAsync(StratumClient client, double
targetArray.Add(newTarget);

// send job
await client.NotifyAsync(AionStratumMethods.MiningNotify, currentJobParams);
await client.NotifyAsync(AionStratumMethods.SetTarget, targetArray);
// await client.NotifyAsync(AionStratumMethods.MiningNotify, currentJobParams);
// await client.NotifyAsync(AionStratumMethods.SetTarget, targetArray);
client.Notify(AionStratumMethods.MiningNotify, currentJobParams);
client.Notify(AionStratumMethods.SetTarget, targetArray);
}
}

Expand Down
Loading

0 comments on commit 6f7f566

Please sign in to comment.