diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..412eeda78 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/.gitmodules b/.gitmodules index 60a8f52ae..9a649de56 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "deps/csredis"] path = deps/csredis - url = https://github.com/CoiniumServ/csredis.git -[submodule "deps/json-rpc"] - path = deps/json-rpc - url = https://github.com/CoiniumServ/JSON-RPC.NET.git + url = https://github.com/CoiniumServ/csredis.git \ No newline at end of file diff --git a/build/CoiniumServ.sln b/build/CoiniumServ.sln index b2c3815e8..12145daa3 100644 --- a/build/CoiniumServ.sln +++ b/build/CoiniumServ.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30723.0 +VisualStudioVersion = 12.0.30501.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{02E410C9-83C5-4D63-8902-5AD041EBEB6C}" ProjectSection(SolutionItems) = preProject @@ -24,8 +24,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSRedis", "..\deps\csredis\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "libCoiniumServ", "..\src\libCoiniumServ\libCoiniumServ.csproj", "{F908636C-BC75-4B93-A774-E4878F3D39AF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AustinHarris.JsonRpc", "..\deps\json-rpc\Json-Rpc\AustinHarris.JsonRpc.csproj", "{24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -109,24 +107,6 @@ Global {F908636C-BC75-4B93-A774-E4878F3D39AF}.Testing|Mixed Platforms.ActiveCfg = Release|Any CPU {F908636C-BC75-4B93-A774-E4878F3D39AF}.Testing|Mixed Platforms.Build.0 = Release|Any CPU {F908636C-BC75-4B93-A774-E4878F3D39AF}.Testing|x86.ActiveCfg = Release|Any CPU - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|Any CPU.Build.0 = Debug|Any CPU - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|Mixed Platforms.Build.0 = Debug|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|x86.ActiveCfg = Debug|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Debug|x86.Build.0 = Debug|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Any CPU.ActiveCfg = Release|Any CPU - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Any CPU.Build.0 = Release|Any CPU - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|Mixed Platforms.Build.0 = Release|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|x86.ActiveCfg = Release|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Release|x86.Build.0 = Release|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Testing|Any CPU.ActiveCfg = Release|Any CPU - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Testing|Any CPU.Build.0 = Release|Any CPU - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Testing|Mixed Platforms.ActiveCfg = Release|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Testing|Mixed Platforms.Build.0 = Release|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Testing|x86.ActiveCfg = Release|x86 - {24FC1A2A-0BC3-43A7-9BFE-B628C2C4A307}.Testing|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/deps/json-rpc b/deps/json-rpc deleted file mode 160000 index 6669face8..000000000 --- a/deps/json-rpc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6669face8648d2a22ce369bb466834d95a556827 diff --git a/src/CoiniumServ/Banning/BanManager.cs b/src/CoiniumServ/Banning/BanManager.cs index 820520da1..46db9d86e 100644 --- a/src/CoiniumServ/Banning/BanManager.cs +++ b/src/CoiniumServ/Banning/BanManager.cs @@ -31,7 +31,7 @@ using CoiniumServ.Server.Mining.Getwork; using CoiniumServ.Server.Mining.Stratum.Sockets; using CoiniumServ.Shares; -using CoiniumServ.Utils.Helpers.Time; +using CoiniumServ.Utils.Helpers; using Serilog; namespace CoiniumServ.Banning diff --git a/src/CoiniumServ/Blocks/BlockProcessor.cs b/src/CoiniumServ/Blocks/BlockProcessor.cs index 81199504b..01916c6d7 100644 --- a/src/CoiniumServ/Blocks/BlockProcessor.cs +++ b/src/CoiniumServ/Blocks/BlockProcessor.cs @@ -23,7 +23,6 @@ using System.Diagnostics; using System.Linq; -using System.Threading; using CoiniumServ.Daemon; using CoiniumServ.Daemon.Errors; using CoiniumServ.Daemon.Exceptions; diff --git a/src/CoiniumServ/Coin/Coinbase/Serializers.cs b/src/CoiniumServ/Coin/Coinbase/Serializers.cs index a675b17d7..81312001d 100644 --- a/src/CoiniumServ/Coin/Coinbase/Serializers.cs +++ b/src/CoiniumServ/Coin/Coinbase/Serializers.cs @@ -26,7 +26,7 @@ using System.Text; using CoiniumServ.Jobs; using CoiniumServ.Utils.Extensions; -using CoiniumServ.Utils.Helpers.Arrays; +using CoiniumServ.Utils.Helpers; using Gibbed.IO; namespace CoiniumServ.Coin.Coinbase diff --git a/src/CoiniumServ/Coin/Config/CoinOptions.cs b/src/CoiniumServ/Coin/Config/CoinOptions.cs index e2dae324b..0e7626a5b 100644 --- a/src/CoiniumServ/Coin/Config/CoinOptions.cs +++ b/src/CoiniumServ/Coin/Config/CoinOptions.cs @@ -37,6 +37,8 @@ public class CoinOptions:ICoinOptions public bool TxMessageSupported { get; private set; } + public bool SubmitBlockSupported { get; set; } + public bool Valid { get; private set; } public CoinOptions(dynamic config) @@ -47,6 +49,7 @@ public CoinOptions(dynamic config) BlockTemplateModeRequired = config.blockTemplateModeRequired is NullExceptionPreventer ? false : config.blockTemplateModeRequired; UseDefaultAccount = config.useDefaultAccount is NullExceptionPreventer ? false : config.useDefaultAccount; TxMessageSupported = config.txMessageSupported is NullExceptionPreventer ? false : config.txMessageSupported; + SubmitBlockSupported = true; // setting true by default, but will be actually checked in NetworkInfo.cs to see if the coin supports it. Valid = true; } catch (Exception e) diff --git a/src/CoiniumServ/Coin/Config/ICoinOptions.cs b/src/CoiniumServ/Coin/Config/ICoinOptions.cs index 4e4dca5e2..1fc3d867b 100644 --- a/src/CoiniumServ/Coin/Config/ICoinOptions.cs +++ b/src/CoiniumServ/Coin/Config/ICoinOptions.cs @@ -48,5 +48,10 @@ public interface ICoinOptions:IConfig /// Does the coin uses TxMessages. /// bool TxMessageSupported { get; } + + /// + /// Does the coin daemon support submitblock call? + /// + bool SubmitBlockSupported { get; set; } } } diff --git a/src/CoiniumServ/CoiniumServ.csproj b/src/CoiniumServ/CoiniumServ.csproj index 5d54d42f7..18f0dac84 100644 --- a/src/CoiniumServ/CoiniumServ.csproj +++ b/src/CoiniumServ/CoiniumServ.csproj @@ -46,6 +46,10 @@ Coinium.ico + + False + ..\..\build\packages\AustinHarris.JsonRpc.1.0.4.22\lib\net40\AustinHarris.JsonRpc.dll + False ..\..\build\packages\BouncyCastle.1.7.0\lib\Net40-Client\BouncyCastle.Crypto.dll @@ -54,9 +58,9 @@ False ..\..\build\packages\CryptSharpOfficial.2.0.0.0\lib\CryptSharp.dll - + False - ..\..\build\packages\Dapper.1.34\lib\net45\Dapper.dll + ..\..\build\packages\Dapper.1.35\lib\net45\Dapper.dll False @@ -82,9 +86,9 @@ False ..\..\build\packages\JsonFx.2.0.1209.2802\lib\net40\JsonFx.dll - + False - ..\..\build\packages\Metrics.NET.0.2.0\lib\net45\Metrics.dll + ..\..\build\packages\Metrics.NET.0.2.5\lib\net45\Metrics.dll False @@ -102,9 +106,9 @@ False ..\..\build\packages\Nancy.Hosting.Self.0.23.2\lib\net40\Nancy.Hosting.Self.dll - + False - ..\..\build\packages\NancyFx.Metrics.0.2.0\lib\net45\Nancy.Metrics.dll + ..\..\build\packages\Nancy.Metrics.0.2.1\lib\net45\Nancy.Metrics.dll False @@ -116,11 +120,11 @@ False - ..\..\build\packages\Serilog.1.4.10\lib\net45\Serilog.dll + ..\..\build\packages\Serilog.1.4.12\lib\net45\Serilog.dll False - ..\..\build\packages\Serilog.1.4.10\lib\net45\Serilog.FullNetFx.dll + ..\..\build\packages\Serilog.1.4.12\lib\net45\Serilog.FullNetFx.dll @@ -147,7 +151,7 @@ - + @@ -368,14 +372,14 @@ - + - - - - + + + + @@ -400,7 +404,7 @@ - + @@ -507,6 +511,18 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + PreserveNewest @@ -953,10 +969,6 @@ {d35e185e-a7e1-41e1-846c-21944f56074f} CSRedis - - {24fc1a2a-0bc3-43a7-9bfe-b628c2c4a307} - AustinHarris.JsonRpc - {f908636c-bc75-4b93-a774-e4878f3d39af} libCoiniumServ diff --git a/src/CoiniumServ/Configuration/ConfigManager.cs b/src/CoiniumServ/Configuration/ConfigManager.cs index 3497bb53e..80183869e 100644 --- a/src/CoiniumServ/Configuration/ConfigManager.cs +++ b/src/CoiniumServ/Configuration/ConfigManager.cs @@ -37,7 +37,7 @@ using CoiniumServ.Server.Web; using CoiniumServ.Server.Web.Config; using CoiniumServ.Statistics; -using CoiniumServ.Utils.Helpers.IO; +using CoiniumServ.Utils.Helpers; using CoiniumServ.Utils.Platform; using libCoiniumServ.Versions; using Serilog; diff --git a/src/CoiniumServ/Configuration/JsonConfigReader.cs b/src/CoiniumServ/Configuration/JsonConfigReader.cs index 35533e2d1..8f41c40ab 100644 --- a/src/CoiniumServ/Configuration/JsonConfigReader.cs +++ b/src/CoiniumServ/Configuration/JsonConfigReader.cs @@ -24,7 +24,7 @@ using System; using System.IO; using System.Text.RegularExpressions; -using CoiniumServ.Utils.Helpers.IO; +using CoiniumServ.Utils.Helpers; using JsonConfig; using Newtonsoft.Json; using Serilog; diff --git a/src/CoiniumServ/Cryptology/Merkle/MerkleTree.cs b/src/CoiniumServ/Cryptology/Merkle/MerkleTree.cs index 1a9bf73ed..181aeaf35 100644 --- a/src/CoiniumServ/Cryptology/Merkle/MerkleTree.cs +++ b/src/CoiniumServ/Cryptology/Merkle/MerkleTree.cs @@ -24,7 +24,7 @@ using System.Collections.Generic; using System.Linq; using CoiniumServ.Utils.Extensions; -using CoiniumServ.Utils.Helpers.Misc; +using CoiniumServ.Utils.Helpers; namespace CoiniumServ.Cryptology.Merkle { diff --git a/src/CoiniumServ/Daemon/Converters/TimeConverter.cs b/src/CoiniumServ/Daemon/Converters/TimeConverter.cs index fe348a6fe..efb07034b 100644 --- a/src/CoiniumServ/Daemon/Converters/TimeConverter.cs +++ b/src/CoiniumServ/Daemon/Converters/TimeConverter.cs @@ -23,7 +23,7 @@ using System; using System.Globalization; -using CoiniumServ.Utils.Helpers.Time; +using CoiniumServ.Utils.Helpers; using Newtonsoft.Json; using Newtonsoft.Json.Linq; diff --git a/src/CoiniumServ/Daemon/DaemonClient.cs b/src/CoiniumServ/Daemon/DaemonClient.cs index 385b800ec..28a142c8c 100644 --- a/src/CoiniumServ/Daemon/DaemonClient.cs +++ b/src/CoiniumServ/Daemon/DaemonClient.cs @@ -271,13 +271,13 @@ public BlockTemplate GetBlockTemplate(bool modeRequired = false) /// public BlockTemplate GetBlockTemplate(string blockHex) { - var submission = new Dictionary + var data = new Dictionary { {"mode", "submit"}, {"data", blockHex} }; - return MakeRequest("getblocktemplate", submission); + return MakeRequest("getblocktemplate", data); } /// diff --git a/src/CoiniumServ/Jobs/Job.cs b/src/CoiniumServ/Jobs/Job.cs index a32522f30..e3ba833a8 100644 --- a/src/CoiniumServ/Jobs/Job.cs +++ b/src/CoiniumServ/Jobs/Job.cs @@ -33,7 +33,7 @@ using CoiniumServ.Transactions; using CoiniumServ.Transactions.Utils; using CoiniumServ.Utils.Extensions; -using CoiniumServ.Utils.Helpers.Time; +using CoiniumServ.Utils.Helpers; using CoiniumServ.Utils.Numerics; using Gibbed.IO; diff --git a/src/CoiniumServ/Jobs/Tracker/JobTracker.cs b/src/CoiniumServ/Jobs/Tracker/JobTracker.cs index 56d08b43e..bd618166b 100644 --- a/src/CoiniumServ/Jobs/Tracker/JobTracker.cs +++ b/src/CoiniumServ/Jobs/Tracker/JobTracker.cs @@ -26,7 +26,7 @@ using System.Linq; using System.Threading; using CoiniumServ.Pools; -using CoiniumServ.Utils.Helpers.Time; +using CoiniumServ.Utils.Helpers; using Serilog; namespace CoiniumServ.Jobs.Tracker diff --git a/src/CoiniumServ/Logging/LogManager.cs b/src/CoiniumServ/Logging/LogManager.cs index c75dca90d..9ce7c7e77 100644 --- a/src/CoiniumServ/Logging/LogManager.cs +++ b/src/CoiniumServ/Logging/LogManager.cs @@ -24,7 +24,7 @@ using System; using System.IO; using System.Linq; -using CoiniumServ.Utils.Helpers.IO; +using CoiniumServ.Utils.Helpers; using Serilog; using Serilog.Core; using Serilog.Events; diff --git a/src/CoiniumServ/Mining/MinerManager.cs b/src/CoiniumServ/Mining/MinerManager.cs index 8c220291f..fd4b1c5c9 100644 --- a/src/CoiniumServ/Mining/MinerManager.cs +++ b/src/CoiniumServ/Mining/MinerManager.cs @@ -37,6 +37,7 @@ namespace CoiniumServ.Mining public class MinerManager : IMinerManager { public int Count { get { return _miners.Count(kvp => kvp.Value.Authenticated); } } + public IList Miners { get { return _miners.Values.ToList(); } } public event EventHandler MinerAuthenticated; @@ -51,7 +52,12 @@ public class MinerManager : IMinerManager private readonly IAccountManager _accountManager; - private readonly ILogger _logger; + private readonly ILogger _logger; + + /// + /// Used for locking miners list. + /// + private readonly object _minersLock = new object(); public MinerManager(IPoolConfig poolConfig, IStorageLayer storageLayer, IAccountManager accountManager) { @@ -87,7 +93,9 @@ public T Create(IPool pool) where T : IGetworkMiner var instance = Activator.CreateInstance(typeof(T), @params); // create an instance of the miner. var miner = (IGetworkMiner)instance; - _miners.Add(miner.Id, miner); // add it to our collection. + + lock(_minersLock) // lock the list before we modify the collection. + _miners.Add(miner.Id, miner); // add it to our collection. return (T)miner; } @@ -106,20 +114,26 @@ public T Create(UInt32 extraNonce, IConnection connection, IPool pool) where var instance = Activator.CreateInstance(typeof(T), @params); // create an instance of the miner. var miner = (IStratumMiner)instance; - _miners.Add(miner.Id, miner); // add it to our collection. + + lock (_minersLock) // lock the list before we modify the collection. + _miners.Add(miner.Id, miner); // add it to our collection. return (T)miner; } public void Remove(IConnection connection) { - var miner = (from pair in _miners // find the miner associated with the connection. - let client = (IClient)pair.Value - where client.Connection == connection + // find the miner associated with the connection. + var miner = (from pair in _miners + let client = (IClient) pair.Value + where client.Connection == connection select pair.Value).FirstOrDefault(); - if (miner != null) - _miners.Remove(miner.Id); + if (miner == null) // make sure the miner exists + return; + + lock (_minersLock) // lock the list before we modify the collection. + _miners.Remove(miner.Id); // remove the miner. } public void Authenticate(IMiner miner) diff --git a/src/CoiniumServ/Persistance/Blocks/PersistedBlock.cs b/src/CoiniumServ/Persistance/Blocks/PersistedBlock.cs index adb475ec9..1f83f9971 100644 --- a/src/CoiniumServ/Persistance/Blocks/PersistedBlock.cs +++ b/src/CoiniumServ/Persistance/Blocks/PersistedBlock.cs @@ -23,7 +23,7 @@ using System; using System.Diagnostics; -using CoiniumServ.Utils.Helpers.Time; +using CoiniumServ.Utils.Helpers; namespace CoiniumServ.Persistance.Blocks { diff --git a/src/CoiniumServ/Persistance/Layers/Hybrid/HybridStorage.Blocks.cs b/src/CoiniumServ/Persistance/Layers/Hybrid/HybridStorage.Blocks.cs index 3cfcf41a1..89b2d0c77 100644 --- a/src/CoiniumServ/Persistance/Layers/Hybrid/HybridStorage.Blocks.cs +++ b/src/CoiniumServ/Persistance/Layers/Hybrid/HybridStorage.Blocks.cs @@ -28,7 +28,7 @@ using CoiniumServ.Persistance.Query; using CoiniumServ.Shares; using CoiniumServ.Utils.Extensions; -using CoiniumServ.Utils.Helpers.Time; +using CoiniumServ.Utils.Helpers; using Dapper; using MySql.Data.MySqlClient; diff --git a/src/CoiniumServ/Persistance/Layers/Hybrid/HybridStorage.Shares.cs b/src/CoiniumServ/Persistance/Layers/Hybrid/HybridStorage.Shares.cs index de8919dc2..ea46ed5d1 100644 --- a/src/CoiniumServ/Persistance/Layers/Hybrid/HybridStorage.Shares.cs +++ b/src/CoiniumServ/Persistance/Layers/Hybrid/HybridStorage.Shares.cs @@ -27,7 +27,7 @@ using CoiniumServ.Payments; using CoiniumServ.Persistance.Blocks; using CoiniumServ.Shares; -using CoiniumServ.Utils.Helpers.Time; +using CoiniumServ.Utils.Helpers; namespace CoiniumServ.Persistance.Layers.Hybrid { diff --git a/src/CoiniumServ/Pools/NetworkInfo.cs b/src/CoiniumServ/Pools/NetworkInfo.cs index cc1ee987a..054fdf0d6 100644 --- a/src/CoiniumServ/Pools/NetworkInfo.cs +++ b/src/CoiniumServ/Pools/NetworkInfo.cs @@ -24,7 +24,9 @@ using CoiniumServ.Algorithms; using CoiniumServ.Coin.Helpers; using CoiniumServ.Daemon; +using CoiniumServ.Daemon.Errors; using CoiniumServ.Daemon.Exceptions; +using CoiniumServ.Utils.Helpers; using Serilog; namespace CoiniumServ.Pools @@ -61,6 +63,7 @@ public NetworkInfo(IDaemonClient daemonClient, IHashAlgorithm hashAlgorithm, IPo _logger = Log.ForContext().ForContext("Component", poolConfig.Coin.Name); DetectProofOfStakeCoin(); // detect if we are running on a proof-of-stake coin. + DetectSubmitBlockSupport(); // detect if the coin daemon supports submitblock call. Recache(); // recache the data initially. PrintNetworkInfo(); // print the collected network info. } @@ -127,6 +130,28 @@ private void PrintNetworkInfo() string.IsNullOrEmpty(Errors) ? "none" : Errors); } + + private void DetectSubmitBlockSupport() + { + // issue a submitblock() call too see if it's supported. + // If the coin supports the submitblock() call it's should return a RPC_DESERIALIZATION_ERROR (-22) - 'Block decode failed' as we just supplied an empty string as block hash. + // otherwise if it doesn't support the call, it should return a RPC_METHOD_NOT_FOUND (-32601) - 'Method not found' error. + + try + { + var response = _daemonClient.SubmitBlock(string.Empty); + } + catch (RpcErrorException e) + { + if (e.Code == (int)RpcErrorCode.RPC_METHOD_NOT_FOUND) // 'Method not found' error. + _poolConfig.Coin.Options.SubmitBlockSupported = false; // the coin doesn't support submitblock(). + else if (e.Code == (int)RpcErrorCode.RPC_DESERIALIZATION_ERROR) // 'Block decode failed' error. + _poolConfig.Coin.Options.SubmitBlockSupported = true; // the coin supports submitblock(). + else // we shouldn't be really recieving any other errors. + _logger.Error("Recieved an unexpected response for DetectSubmitBlockSupport() - {0}, {1:l}", e.Code, e.Message); + } + } + private void DetectProofOfStakeCoin() { // use getdifficulty() to determine if it's POS coin. diff --git a/src/CoiniumServ/Pools/Pool.cs b/src/CoiniumServ/Pools/Pool.cs index 7cb0b9f05..f397406f8 100644 --- a/src/CoiniumServ/Pools/Pool.cs +++ b/src/CoiniumServ/Pools/Pool.cs @@ -43,8 +43,7 @@ using CoiniumServ.Server.Mining; using CoiniumServ.Server.Mining.Service; using CoiniumServ.Shares; -using CoiniumServ.Utils.Helpers.Time; -using CoiniumServ.Utils.Helpers.Validation; +using CoiniumServ.Utils.Helpers; using Newtonsoft.Json; using Serilog; diff --git a/src/CoiniumServ/Program.cs b/src/CoiniumServ/Program.cs index b9b4ee555..8859785e2 100644 --- a/src/CoiniumServ/Program.cs +++ b/src/CoiniumServ/Program.cs @@ -99,13 +99,13 @@ private static void RunGlobalManagers(IObjectFactory objectFactory) // run software repository. objectFactory.GetSoftwareRepository(); - // start web server. - objectFactory.GetWebServer(); - #if DEBUG // only initialize metrics support in debug mode objectFactory.GetMetricsManager(); #endif + + // start web server. + objectFactory.GetWebServer(); } #region unhandled exception emitter diff --git a/src/CoiniumServ/Server/Mining/Stratum/StratumServer.cs b/src/CoiniumServ/Server/Mining/Stratum/StratumServer.cs index b255f069e..cba0c15e7 100644 --- a/src/CoiniumServ/Server/Mining/Stratum/StratumServer.cs +++ b/src/CoiniumServ/Server/Mining/Stratum/StratumServer.cs @@ -155,8 +155,14 @@ private void OnBannedConnection(object sender, BannedConnectionEventArgs e) /// private void OnDataReceived(object sender, ConnectionDataEventArgs e) { - var connection = (Connection)e.Connection; - ((StratumMiner)connection.Client).Parse(e); + if (e.Connection == null) + return; + + var connection = (Connection) e.Connection; + if (connection.Client == null) + return; + + ((StratumMiner) connection.Client).Parse(e); } } } diff --git a/src/CoiniumServ/Server/Web/RootPathProvider.cs b/src/CoiniumServ/Server/Web/RootPathProvider.cs index d3e1dbbbc..63807b0f4 100644 --- a/src/CoiniumServ/Server/Web/RootPathProvider.cs +++ b/src/CoiniumServ/Server/Web/RootPathProvider.cs @@ -22,7 +22,7 @@ #endregion using System.IO; -using CoiniumServ.Utils.Helpers.IO; +using CoiniumServ.Utils.Helpers; using Nancy; namespace CoiniumServ.Server.Web diff --git a/src/CoiniumServ/Server/Web/WebServer.cs b/src/CoiniumServ/Server/Web/WebServer.cs index 166de12ef..de9f870e4 100644 --- a/src/CoiniumServ/Server/Web/WebServer.cs +++ b/src/CoiniumServ/Server/Web/WebServer.cs @@ -126,6 +126,7 @@ public bool Start() _logger.Error("Invalid template path for web-server given; {0:l}", baseException.Message); else _logger.Error("An error occured while starting web-server: {0:l}", e); + IsListening = false; return false; } diff --git a/src/CoiniumServ/Shares/Share.cs b/src/CoiniumServ/Shares/Share.cs index dfb18dff4..5e7d1967e 100644 --- a/src/CoiniumServ/Shares/Share.cs +++ b/src/CoiniumServ/Shares/Share.cs @@ -30,7 +30,7 @@ using CoiniumServ.Mining; using CoiniumServ.Server.Mining.Stratum; using CoiniumServ.Utils.Extensions; -using CoiniumServ.Utils.Helpers.Time; +using CoiniumServ.Utils.Helpers; using CoiniumServ.Utils.Numerics; namespace CoiniumServ.Shares diff --git a/src/CoiniumServ/Shares/ShareManager.cs b/src/CoiniumServ/Shares/ShareManager.cs index 610106af9..3e781e94a 100644 --- a/src/CoiniumServ/Shares/ShareManager.cs +++ b/src/CoiniumServ/Shares/ShareManager.cs @@ -173,7 +173,10 @@ private bool SubmitBlock(IShare share) try { - _daemonClient.SubmitBlock(share.BlockHex.ToHexString()); // submit the block. + if (_poolConfig.Coin.Options.SubmitBlockSupported) // see if submitblock() is available. + _daemonClient.SubmitBlock(share.BlockHex.ToHexString()); // submit the block. + else + _daemonClient.GetBlockTemplate(share.BlockHex.ToHexString()); // use getblocktemplate() if submitblock() is not supported. var block = _daemonClient.GetBlock(share.BlockHash.ToHexString()); // query the block. @@ -225,7 +228,7 @@ private bool SubmitBlock(IShare share) // unlike BlockProcessor's detailed exception handling and decision making based on the error, // here in share-manager we only one-shot submissions. If we get an error, basically we just don't care about the rest // and flag the submission as failed. - _logger.Error("Submit block [{0}] failed with hash [{1:l}] - reason; {2:l}", share.Height, share.BlockHash.ToHexString(), e.Message); + _logger.Error("We thought a block was found but it was rejected by the coin daemon; [{0:l}] - reason; {1:l}", share.BlockHash.ToHexString(), e.Message); return false; } } diff --git a/src/CoiniumServ/Transactions/GenerationTransaction.cs b/src/CoiniumServ/Transactions/GenerationTransaction.cs index 00f179510..1caa99b51 100644 --- a/src/CoiniumServ/Transactions/GenerationTransaction.cs +++ b/src/CoiniumServ/Transactions/GenerationTransaction.cs @@ -32,7 +32,7 @@ using CoiniumServ.Jobs; using CoiniumServ.Pools; using CoiniumServ.Transactions.Script; -using CoiniumServ.Utils.Helpers.Time; +using CoiniumServ.Utils.Helpers; using Gibbed.IO; namespace CoiniumServ.Transactions diff --git a/src/CoiniumServ/Coin/Helpers/Amount.cs b/src/CoiniumServ/Utils/Helpers/Amount.cs similarity index 100% rename from src/CoiniumServ/Coin/Helpers/Amount.cs rename to src/CoiniumServ/Utils/Helpers/Amount.cs diff --git a/src/CoiniumServ/Utils/Helpers/Arrays/ArrayHelpers.cs b/src/CoiniumServ/Utils/Helpers/ArrayHelpers.cs similarity index 98% rename from src/CoiniumServ/Utils/Helpers/Arrays/ArrayHelpers.cs rename to src/CoiniumServ/Utils/Helpers/ArrayHelpers.cs index e4002b26b..37b50b978 100644 --- a/src/CoiniumServ/Utils/Helpers/Arrays/ArrayHelpers.cs +++ b/src/CoiniumServ/Utils/Helpers/ArrayHelpers.cs @@ -23,7 +23,7 @@ using System; -namespace CoiniumServ.Utils.Helpers.Arrays +namespace CoiniumServ.Utils.Helpers { public static class ArrayHelpers { diff --git a/src/CoiniumServ/Utils/Helpers/Validation/Enforce.cs b/src/CoiniumServ/Utils/Helpers/Enforce.cs similarity index 99% rename from src/CoiniumServ/Utils/Helpers/Validation/Enforce.cs rename to src/CoiniumServ/Utils/Helpers/Enforce.cs index aa25f0376..557d1df5a 100644 --- a/src/CoiniumServ/Utils/Helpers/Validation/Enforce.cs +++ b/src/CoiniumServ/Utils/Helpers/Enforce.cs @@ -25,7 +25,7 @@ using System.Collections.Generic; using System.Linq.Expressions; -namespace CoiniumServ.Utils.Helpers.Validation +namespace CoiniumServ.Utils.Helpers { /// /// The enforce. diff --git a/src/CoiniumServ/Utils/Helpers/IO/FileHelpers.cs b/src/CoiniumServ/Utils/Helpers/FileHelpers.cs similarity index 98% rename from src/CoiniumServ/Utils/Helpers/IO/FileHelpers.cs rename to src/CoiniumServ/Utils/Helpers/FileHelpers.cs index 48430ab69..f74afe552 100644 --- a/src/CoiniumServ/Utils/Helpers/IO/FileHelpers.cs +++ b/src/CoiniumServ/Utils/Helpers/FileHelpers.cs @@ -28,7 +28,7 @@ using CoiniumServ.Utils.Platform; using Serilog; -namespace CoiniumServ.Utils.Helpers.IO +namespace CoiniumServ.Utils.Helpers { public static class FileHelpers { diff --git a/src/CoiniumServ/Coin/Helpers/Hashrate.cs b/src/CoiniumServ/Utils/Helpers/Humanize.cs similarity index 56% rename from src/CoiniumServ/Coin/Helpers/Hashrate.cs rename to src/CoiniumServ/Utils/Helpers/Humanize.cs index 6113b588e..43425f1f0 100644 --- a/src/CoiniumServ/Coin/Helpers/Hashrate.cs +++ b/src/CoiniumServ/Utils/Helpers/Humanize.cs @@ -22,17 +22,48 @@ #endregion using System; +using System.Globalization; -namespace CoiniumServ.Coin.Helpers +namespace CoiniumServ.Utils.Helpers { - public static class Hashrate + public static class Humanize { + + /// + /// Returns given hashrate value as human readable string. + /// + /// + /// public static string GetReadableHashrate(this UInt64 hashrate) { var index = -1; double rate = hashrate; - var units = new[] { "KH/s", "MH/s", "GH/s", "TH/s", "PH/s" }; + var units = new[] {"KH/s", "MH/s", "GH/s", "TH/s", "PH/s", "EH/s", "ZH/s", "YH/s"}; + + do + { + rate = rate/1000; + index++; + } while (rate > 1000); + + return string.Format("{0:0.00} {1}", rate, units[index]); + } + + /// + /// Returns given difficulty value as human readable string. + /// + /// + /// + public static string GetReadableDifficulty(this double difficulty) + { + var index = -1; + var rate = difficulty; + + var units = new[] {"K", "M", "B", "T", "Q"}; + + if (difficulty < 1000) + return difficulty.ToString(CultureInfo.InvariantCulture); do { diff --git a/src/CoiniumServ/Utils/Helpers/Misc/Range.cs b/src/CoiniumServ/Utils/Helpers/Range.cs similarity index 98% rename from src/CoiniumServ/Utils/Helpers/Misc/Range.cs rename to src/CoiniumServ/Utils/Helpers/Range.cs index 21b596879..95cfc3598 100644 --- a/src/CoiniumServ/Utils/Helpers/Misc/Range.cs +++ b/src/CoiniumServ/Utils/Helpers/Range.cs @@ -24,7 +24,7 @@ using System.Collections; using System.Collections.Generic; -namespace CoiniumServ.Utils.Helpers.Misc +namespace CoiniumServ.Utils.Helpers { /// /// Port of python's range from diff --git a/src/CoiniumServ/Utils/Helpers/Time/TimeHelpers.cs b/src/CoiniumServ/Utils/Helpers/TimeHelpers.cs similarity index 97% rename from src/CoiniumServ/Utils/Helpers/Time/TimeHelpers.cs rename to src/CoiniumServ/Utils/Helpers/TimeHelpers.cs index 9dc128d1e..1dc8a7627 100644 --- a/src/CoiniumServ/Utils/Helpers/Time/TimeHelpers.cs +++ b/src/CoiniumServ/Utils/Helpers/TimeHelpers.cs @@ -23,7 +23,7 @@ using System; -namespace CoiniumServ.Utils.Helpers.Time +namespace CoiniumServ.Utils.Helpers { public static class TimeHelpers { diff --git a/src/CoiniumServ/Utils/Metrics/MetricsManager.cs b/src/CoiniumServ/Utils/Metrics/MetricsManager.cs index 6391f2f4d..f5364d621 100644 --- a/src/CoiniumServ/Utils/Metrics/MetricsManager.cs +++ b/src/CoiniumServ/Utils/Metrics/MetricsManager.cs @@ -23,7 +23,7 @@ using System; using CoiniumServ.Configuration; -using CoiniumServ.Utils.Helpers.IO; +using CoiniumServ.Utils.Helpers; using CoiniumServ.Utils.Platform; using Metrics; using Serilog; diff --git a/src/CoiniumServ/Vardiff/VardiffManager.cs b/src/CoiniumServ/Vardiff/VardiffManager.cs index 1a816fc46..2346b3757 100644 --- a/src/CoiniumServ/Vardiff/VardiffManager.cs +++ b/src/CoiniumServ/Vardiff/VardiffManager.cs @@ -25,7 +25,7 @@ using CoiniumServ.Pools; using CoiniumServ.Shares; using CoiniumServ.Utils.Buffers; -using CoiniumServ.Utils.Helpers.Time; +using CoiniumServ.Utils.Helpers; using Serilog; namespace CoiniumServ.Vardiff diff --git a/src/CoiniumServ/config/pools/pool.json b/src/CoiniumServ/config/pools/pool.json index 5c6be0258..b8b531325 100644 --- a/src/CoiniumServ/config/pools/pool.json +++ b/src/CoiniumServ/config/pools/pool.json @@ -20,7 +20,7 @@ "storage": { "hybrid": { "mysql": { - "database": "db-name" + "database": "dbname" } } } diff --git a/src/CoiniumServ/packages.config b/src/CoiniumServ/packages.config index 6a3f6cdd8..69b4692c7 100644 --- a/src/CoiniumServ/packages.config +++ b/src/CoiniumServ/packages.config @@ -1,22 +1,23 @@  + - + - + + - - + \ No newline at end of file diff --git a/src/CoiniumServ/web/default/views/index/index.cshtml b/src/CoiniumServ/web/default/views/index/index.cshtml index e85b24901..56cdc8323 100644 --- a/src/CoiniumServ/web/default/views/index/index.cshtml +++ b/src/CoiniumServ/web/default/views/index/index.cshtml @@ -1,4 +1,5 @@ @using CoiniumServ.Coin.Helpers +@using CoiniumServ.Utils.Helpers @inherits Nancy.ViewEngines.Razor.NancyRazorViewBase @{ Layout = "layout/main.cshtml"; } diff --git a/src/CoiniumServ/web/default/views/partial/algorithms.cshtml b/src/CoiniumServ/web/default/views/partial/algorithms.cshtml index 88b20bd4a..2d82debdc 100644 --- a/src/CoiniumServ/web/default/views/partial/algorithms.cshtml +++ b/src/CoiniumServ/web/default/views/partial/algorithms.cshtml @@ -1,4 +1,4 @@ -@using CoiniumServ.Coin.Helpers +@using CoiniumServ.Utils.Helpers @inherits Nancy.ViewEngines.Razor.NancyRazorViewBase>
diff --git a/src/CoiniumServ/web/default/views/partial/pools.cshtml b/src/CoiniumServ/web/default/views/partial/pools.cshtml index 499228168..b65002db3 100644 --- a/src/CoiniumServ/web/default/views/partial/pools.cshtml +++ b/src/CoiniumServ/web/default/views/partial/pools.cshtml @@ -1,4 +1,4 @@ -@using CoiniumServ.Coin.Helpers +@using CoiniumServ.Utils.Helpers @inherits Nancy.ViewEngines.Razor.NancyRazorViewBase>
@@ -33,7 +33,7 @@ @pool.Config.Coin.Name @pool.Hashrate.GetReadableHashrate() @pool.NetworkInfo.Hashrate.GetReadableHashrate() - @pool.NetworkInfo.Difficulty + @pool.NetworkInfo.Difficulty.GetReadableDifficulty() @pool.MinerManager.Count @pool.Config.Coin.Algorithm @pool.NetworkInfo.Round diff --git a/src/CoiniumServ/web/default/views/pool/pool.cshtml b/src/CoiniumServ/web/default/views/pool/pool.cshtml index c9ca3ddf1..28b04bde0 100644 --- a/src/CoiniumServ/web/default/views/pool/pool.cshtml +++ b/src/CoiniumServ/web/default/views/pool/pool.cshtml @@ -1,5 +1,5 @@ -@using CoiniumServ.Coin.Helpers -@using CoiniumServ.Persistance.Blocks +@using CoiniumServ.Persistance.Blocks +@using CoiniumServ.Utils.Helpers @inherits Nancy.ViewEngines.Razor.NancyRazorViewBase @{ Layout = "layout/main.cshtml"; } @@ -65,7 +65,7 @@
Difficulty
-
@Model.Pool.NetworkInfo.Difficulty
+
@Model.Pool.NetworkInfo.Difficulty.GetReadableDifficulty()
diff --git a/src/Tests/CoiniumServ.Tests.csproj b/src/Tests/CoiniumServ.Tests.csproj index 34ed1ef34..5b41a6a4c 100644 --- a/src/Tests/CoiniumServ.Tests.csproj +++ b/src/Tests/CoiniumServ.Tests.csproj @@ -35,6 +35,10 @@ false + + False + ..\..\build\packages\AustinHarris.JsonRpc.1.0.4.22\lib\net40\AustinHarris.JsonRpc.dll + False ..\..\build\packages\BouncyCastle.1.7.0\lib\Net40-Client\BouncyCastle.Crypto.dll @@ -102,10 +106,6 @@ - - {24fc1a2a-0bc3-43a7-9bfe-b628c2c4a307} - AustinHarris.JsonRpc - {5fca1e48-0751-4625-9532-cb804df55db5} CoiniumServ diff --git a/src/Tests/packages.config b/src/Tests/packages.config index 644a0e4c5..f4a8f53f9 100644 --- a/src/Tests/packages.config +++ b/src/Tests/packages.config @@ -1,5 +1,6 @@  +