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

Commit

Permalink
Dev (#218)
Browse files Browse the repository at this point in the history
* Payment Processing crash fix (invalid tablename balances_changes)
* Drop Id column for shares table
* Add index on table balance_changes
* API Hashrate case consolidation
  • Loading branch information
Oliver Weichhold authored Feb 22, 2018
1 parent 2e81a03 commit 618bba4
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/MiningCore/Api/Responses/GetPoolStatsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace MiningCore.Api.Responses
{
public partial class AggregatedPoolStats
{
public float PoolHashRate { get; set; }
public float PoolHashrate { get; set; }
public int ConnectedMiners { get; set; }
public int ValidSharesPerSecond { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/MiningCore/Blockchain/Abstractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace MiningCore.Blockchain
public class BlockchainStats
{
public string NetworkType { get; set; }
public double NetworkHashRate { get; set; }
public double NetworkHashrate { get; set; }
public double NetworkDifficulty { get; set; }
public DateTime? LastNetworkBlockTime { get; set; }
public long BlockHeight { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions src/MiningCore/Blockchain/Bitcoin/BitcoinJobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private async Task UpdateNetworkStatsAsync()
var networkInfoResponse = results[2].Response.ToObject<NetworkInfo>();

BlockchainStats.BlockHeight = infoResponse.Blocks;
BlockchainStats.NetworkHashRate = miningInfoResponse.NetworkHashps;
BlockchainStats.NetworkHashrate = miningInfoResponse.NetworkHashps;
BlockchainStats.ConnectedPeers = networkInfoResponse.Connections;
}

Expand Down Expand Up @@ -375,7 +375,7 @@ private async Task UpdateNetworkStatsLegacyAsync()
var connectionCountResponse = results[1].Response.ToObject<object>();

BlockchainStats.BlockHeight = miningInfoResponse.Blocks;
//BlockchainStats.NetworkHashRate = miningInfoResponse.NetworkHashps;
//BlockchainStats.NetworkHashrate = miningInfoResponse.NetworkHashps;
BlockchainStats.ConnectedPeers = (int) (long) connectionCountResponse;
}

Expand Down
2 changes: 1 addition & 1 deletion src/MiningCore/Blockchain/Ethereum/EthereumJobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private async Task UpdateNetworkStatsAsync()

BlockchainStats.BlockHeight = block.Height.HasValue ? (long)block.Height.Value : -1;
BlockchainStats.NetworkDifficulty = block.Difficulty.IntegralFromHex<ulong>();
BlockchainStats.NetworkHashRate = 0; // TODO
BlockchainStats.NetworkHashrate = 0; // TODO
BlockchainStats.ConnectedPeers = peerCount;
}

Expand Down
2 changes: 1 addition & 1 deletion src/MiningCore/Blockchain/Monero/MoneroJobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private async Task UpdateNetworkStatsAsync()

BlockchainStats.BlockHeight = (int)info.Height;
BlockchainStats.NetworkDifficulty = info.Difficulty;
BlockchainStats.NetworkHashRate = info.Target > 0 ? (double)info.Difficulty / info.Target : 0;
BlockchainStats.NetworkHashrate = info.Target > 0 ? (double)info.Difficulty / info.Target : 0;
BlockchainStats.ConnectedPeers = info.OutgoingConnectionsCount + info.IncomingConnectionsCount;
}

Expand Down
2 changes: 1 addition & 1 deletion src/MiningCore/Mining/PoolBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ private void OutputPoolInfo()
Current Block Height: {blockchainStats.BlockHeight}
Current Connect Peers: {blockchainStats.ConnectedPeers}
Network Difficulty: {blockchainStats.NetworkDifficulty}
Network Hash Rate: {FormatUtil.FormatHashRate(blockchainStats.NetworkHashRate)}
Network Hash Rate: {FormatUtil.FormatHashrate(blockchainStats.NetworkHashrate)}
Stratum Port(s): {string.Join(", ", poolConfig.Ports.Keys)}
Pool Fee: {poolConfig.RewardRecipients.Sum(x => x.Percentage)}%
";
Expand Down
2 changes: 1 addition & 1 deletion src/MiningCore/Mining/PoolStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class PoolStats
{
public DateTime? LastPoolBlockTime { get; set; }
public int ConnectedMiners { get; set; }
public ulong PoolHashRate { get; set; }
public ulong PoolHashrate { get; set; }
public int ValidSharesPerSecond { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/MiningCore/Mining/StatsRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private void UpdatePoolHashrates()

// update
pool.PoolStats.ConnectedMiners = byMiner.Length;
pool.PoolStats.PoolHashRate = (ulong) Math.Ceiling(poolHashrate);
pool.PoolStats.PoolHashrate = (ulong) Math.Ceiling(poolHashrate);
pool.PoolStats.ValidSharesPerSecond = (int) (poolHashesCountAccumulated / windowActual);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/MiningCore/Persistence/Model/PoolStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class PoolStats
public string PoolId { get; set; }

public int ConnectedMiners { get; set; }
public float PoolHashRate { get; set; }
public double NetworkHashRate { get; set; }
public float PoolHashrate { get; set; }
public double NetworkHashrate { get; set; }
public double NetworkDifficulty { get; set; }
public DateTime? LastNetworkBlockTime { get; set; }
public long BlockHeight { get; set; }
Expand Down
1 change: 0 additions & 1 deletion src/MiningCore/Persistence/Model/Share.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace MiningCore.Persistence.Model
{
public class Share
{
public long Id { get; set; }
public string PoolId { get; set; }
public ulong BlockHeight { get; set; }
public string PayoutInfo { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions src/MiningCore/Persistence/Postgres/Entities/PoolStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class PoolStats
public string PoolId { get; set; }

public int ConnectedMiners { get; set; }
public float PoolHashRate { get; set; }
public double NetworkHashRate { get; set; }
public float PoolHashrate { get; set; }
public double NetworkHashrate { get; set; }
public double NetworkDifficulty { get; set; }
public DateTime? LastNetworkBlockTime { get; set; }
public long BlockHeight { get; set; }
Expand Down
1 change: 0 additions & 1 deletion src/MiningCore/Persistence/Postgres/Entities/Share.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace MiningCore.Persistence.Postgres.Entities
{
public class Share
{
public long Id { get; set; }
public string PoolId { get; set; }
public long BlockHeight { get; set; }
public string PayoutInfo { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void AddAmount(IDbConnection con, IDbTransaction tx, string poolId, CoinT
var now = DateTime.UtcNow;

// record balance change
var query = "INSERT INTO balances_changes(poolid, coin, address, amount, usage, created) " +
var query = "INSERT INTO balance_changes(poolid, coin, address, amount, usage, created) " +
"VALUES(@poolid, @coin, @address, @amount, @usage, @created)";

var balanceChange = new Entities.BalanceChange
Expand Down
18 changes: 2 additions & 16 deletions src/MiningCore/Persistence/Postgres/Scripts/createdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

CREATE TABLE shares
(
id BIGSERIAL NOT NULL PRIMARY KEY,
poolid TEXT NOT NULL,
blockheight BIGINT NOT NULL,
difficulty DOUBLE PRECISION NOT NULL,
Expand Down Expand Up @@ -60,6 +59,8 @@ CREATE TABLE balance_changes
created TIMESTAMP NOT NULL
);

CREATE INDEX IDX_BALANCE_CHANGES_POOL_ADDRESS_CREATED on balance_changes(poolid, miner, created desc);

CREATE TABLE payments
(
id BIGSERIAL NOT NULL PRIMARY KEY,
Expand Down Expand Up @@ -105,18 +106,3 @@ CREATE INDEX IDX_MINERSTATS_POOL_CREATED on minerstats(poolid, created);
CREATE INDEX IDX_MINERSTATS_POOL_MINER_CREATED on minerstats(poolid, miner, created);
CREATE INDEX IDX_MINERSTATS_POOL_MINER_CREATED_HOUR on minerstats(poolid, miner, date_trunc('hour',created));
CREATE INDEX IDX_MINERSTATS_POOL_MINER_CREATED_DAY on minerstats(poolid, miner, date_trunc('day',created));

CREATE TABLE minerstats_pre_agg
(
poolid TEXT NOT NULL,
miner TEXT NOT NULL,
worker TEXT NOT NULL,

sharecount BIGINT NOT NULL,
sharesaccumulated DOUBLE PRECISION NOT NULL,

created TIMESTAMP NOT NULL,
updated TIMESTAMP NOT NULL,

primary key(poolid, miner, worker)
);
8 changes: 4 additions & 4 deletions src/MiningCore/Util/FormatUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ namespace MiningCore.Util
{
public static class FormatUtil
{
public static readonly string[] HashRateUnits = { " KH/s", " MH/s", " GH/s", " TH/s", " PH/s" };
public static readonly string[] HashrateUnits = { " KH/s", " MH/s", " GH/s", " TH/s", " PH/s" };
public static readonly string[] DifficultyUnits = { " K", " M", " G", " T", " P" };
public static readonly string[] CapacityUnits = { " KB", " MB", " GB", " TB", " PB" };
public static readonly string[] QuantityUnits = { "K", "M", "B", "T", "Q" };

public static string FormatHashRate(double hashrate)
public static string FormatHashrate(double hashrate)
{
var i = -1;

do
{
hashrate = hashrate / 1024;
i++;
} while(hashrate > 1024 && i < HashRateUnits.Length - 1);
} while(hashrate > 1024 && i < HashrateUnits.Length - 1);

return (int) Math.Abs(hashrate) + HashRateUnits[i];
return (int) Math.Abs(hashrate) + HashrateUnits[i];
}

public static string FormatDifficulty(double difficulty)
Expand Down

0 comments on commit 618bba4

Please sign in to comment.