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

Commit

Permalink
Dev (#432)
Browse files Browse the repository at this point in the history
* Fixed fatal array reverse bug
* Improved rejected share logging
  • Loading branch information
Oliver Weichhold authored Oct 19, 2018
1 parent bf5015a commit 70f224e
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/Miningcore/Blockchain/Bitcoin/BitcoinPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ protected virtual async Task OnSubmitAsync(StratumClient client, Timestamped<Jso

// validate worker
if (!context.IsAuthorized)
throw new StratumException(StratumError.UnauthorizedWorker, "Unauthorized worker");
throw new StratumException(StratumError.UnauthorizedWorker, "unauthorized worker");
else if (!context.IsSubscribed)
throw new StratumException(StratumError.NotSubscribed, "Not subscribed");
throw new StratumException(StratumError.NotSubscribed, "not subscribed");

// submit
var requestParams = request.ParamsAs<string[]>();
Expand Down Expand Up @@ -220,7 +220,7 @@ protected virtual async Task OnSubmitAsync(StratumClient client, Timestamped<Jso

// update client stats
context.Stats.InvalidShares++;
logger.Info(() => $"[{client.ConnectionId}] Share rejected: {ex.Code}");
logger.Info(() => $"[{client.ConnectionId}] Share rejected: {ex.Message}");

// banning
ConsiderBan(client, context, poolConfig.Banning);
Expand Down
6 changes: 3 additions & 3 deletions src/Miningcore/Blockchain/Equihash/EquihashPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ protected virtual async Task OnSubmitAsync(StratumClient client, Timestamped<Jso

// validate worker
if (!context.IsAuthorized)
throw new StratumException(StratumError.UnauthorizedWorker, "Unauthorized worker");
throw new StratumException(StratumError.UnauthorizedWorker, "unauthorized worker");
else if (!context.IsSubscribed)
throw new StratumException(StratumError.NotSubscribed, "Not subscribed");
throw new StratumException(StratumError.NotSubscribed, "not subscribed");

// submit
var requestParams = request.ParamsAs<string[]>();
Expand Down Expand Up @@ -275,7 +275,7 @@ protected virtual async Task OnSubmitAsync(StratumClient client, Timestamped<Jso

// update client stats
context.Stats.InvalidShares++;
logger.Info(() => $"[{client.ConnectionId}] Share rejected: {ex.Code}");
logger.Info(() => $"[{client.ConnectionId}] Share rejected: {ex.Message}");

// banning
ConsiderBan(client, context, poolConfig.Banning);
Expand Down
6 changes: 3 additions & 3 deletions src/Miningcore/Blockchain/Ethereum/EthereumPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ private async Task OnSubmitAsync(StratumClient client, Timestamped<JsonRpcReques

// validate worker
if (!context.IsAuthorized)
throw new StratumException(StratumError.UnauthorizedWorker, "Unauthorized worker");
throw new StratumException(StratumError.UnauthorizedWorker, "unauthorized worker");
else if (!context.IsSubscribed)
throw new StratumException(StratumError.NotSubscribed, "Not subscribed");
throw new StratumException(StratumError.NotSubscribed, "not subscribed");

// check request
var submitRequest = request.ParamsAs<string[]>();
Expand Down Expand Up @@ -205,7 +205,7 @@ private async Task OnSubmitAsync(StratumClient client, Timestamped<JsonRpcReques

// update client stats
context.Stats.InvalidShares++;
logger.Info(() => $"[{client.ConnectionId}] Share rejected: {ex.Code}");
logger.Info(() => $"[{client.ConnectionId}] Share rejected: {ex.Message}");

// banning
ConsiderBan(client, context, poolConfig.Banning);
Expand Down
4 changes: 2 additions & 2 deletions src/Miningcore/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public static byte[] HexToReverseByteArray(this string str)
var arr = new byte[str.Length >> 1];
var count = str.Length >> 1;

for (var i = count - 1; i > 0; i--)
arr[i] = (byte)((GetHexVal(str[i << 1]) << 4) + GetHexVal(str[(i << 1) + 1]));
for (var i = 0; i < count; ++i)
arr[count - 1 - i] = (byte)((GetHexVal(str[i << 1]) << 4) + GetHexVal(str[(i << 1) + 1]));

return arr;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Miningcore/Mining/ShareRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ await cf.RunTx(async (con, tx) =>
{
// Insert shares
var mapped = shares.Select(mapper.Map<Persistence.Model.Share>).ToArray();
await shareRepo.BulkInsertAsync(con, tx, mapped);
await shareRepo.BatchInsertAsync(con, tx, mapped);

// Insert blocks
foreach (var share in shares)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,19 @@ public async Task InsertAsync(IDbConnection con, IDbTransaction tx, Share share)
await con.ExecuteAsync(query, mapped, tx);
}

public Task BulkInsertAsync(IDbConnection con, IDbTransaction tx, IEnumerable<Share> shares)
public Task BatchInsertAsync(IDbConnection con, IDbTransaction tx, IEnumerable<Share> shares)
{
logger.LogInvoke();

// NOTE: Even though the tx parameter is completely ignored here,
// the COPY command still honors the current transaction if there is one
logger.LogInvoke();

// NOTE: Even though the tx parameter is completely ignored here,
// the COPY command still honors a current ambient transaction

var pgCon = (NpgsqlConnection)con;

const string query = "COPY shares (poolid, blockheight, difficulty, " +
"networkdifficulty, miner, worker, useragent, ipaddress, source, created) FROM STDIN (FORMAT BINARY)";

using (var writer = ((NpgsqlConnection) con).BeginBinaryImport(query))
using (var writer = pgCon.BeginBinaryImport(query))
{
foreach (var share in shares)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Miningcore.Persistence.Repositories
public interface IShareRepository
{
Task InsertAsync(IDbConnection con, IDbTransaction tx, Share share);
Task BulkInsertAsync(IDbConnection con, IDbTransaction tx, IEnumerable<Share> shares);
Task BatchInsertAsync(IDbConnection con, IDbTransaction tx, IEnumerable<Share> shares);
Task<Share[]> ReadSharesBeforeCreatedAsync(IDbConnection con, string poolId, DateTime before, bool inclusive, int pageSize);
Task<Share[]> ReadSharesBeforeAndAfterCreatedAsync(IDbConnection con, string poolId, DateTime before, DateTime after, bool inclusive, int pageSize);
Task<Share[]> PageSharesBetweenCreatedAsync(IDbConnection con, string poolId, DateTime start, DateTime end, int page, int pageSize);
Expand Down

0 comments on commit 70f224e

Please sign in to comment.