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

Commit

Permalink
Dev (#290)
Browse files Browse the repository at this point in the history
* BCH address validation
* Implemented support for encrypted wallets for Bitcoin & Family
* Support custom RPC endpoints with optional SSL
* Added Monero ZMQ block notify support
* Graceful shutdown
* Changed ZMQ block notify message evaluation to be content agnostic
* Streamlined block template updating
* Added additional Ethereum Websocket streaming options
* HTTP2 support for daemons behind HTTP reverse proxies
* Ethhash logging
* Fix missing poolstats fields
* Dev donation is now hard-wired to 0.1% (since absolutely everyone disabled it)
* Obey to NotificationsConfig.Enabled - Fixes #276
* Improved block submission failure notifications
* Remove HTTP client timeout
* Fixed Monero login error when UserAgent is missing
* Calculate Ethereum Classic Mining Rewards using New Monetary Policy Fixes #289
  • Loading branch information
Oliver Weichhold authored Mar 27, 2018
1 parent d2ad288 commit a057083
Show file tree
Hide file tree
Showing 36 changed files with 1,214 additions and 791 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace MiningCore.Tests.Blockchain.Ethereum
/// </summary>
public class EthereumJobTests : TestBase
{
static readonly EthashFull ethash = new EthashFull(3, Path.GetTempPath(), true);
static readonly EthashFull ethash = new EthashFull(3, Path.GetTempPath());

/*
[Fact]
Expand Down
19 changes: 11 additions & 8 deletions src/MiningCore.Tests/Crypto/EthashTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
using MiningCore.Crypto.Hashing.Algorithms;
using MiningCore.Crypto.Hashing.Ethash;
using MiningCore.Extensions;
using NLog;
using Xunit;

namespace MiningCore.Tests.Crypto
{
public class EthashTests : TestBase
{
private ILogger logger = LogManager.GetCurrentClassLogger();

[Fact]
public async Task Ethhash_Verify_Valid_Blocks()
{
Expand Down Expand Up @@ -47,9 +50,9 @@ public async Task Ethhash_Verify_Valid_Blocks()

using (var ethash = new EthashLight(3))
{
Assert.True(await ethash.VerifyBlockAsync(validBlocks[0]));
Assert.True(await ethash.VerifyBlockAsync(validBlocks[1]));
Assert.True(await ethash.VerifyBlockAsync(validBlocks[2]));
Assert.True(await ethash.VerifyBlockAsync(validBlocks[0], logger));
Assert.True(await ethash.VerifyBlockAsync(validBlocks[1], logger));
Assert.True(await ethash.VerifyBlockAsync(validBlocks[2], logger));
}
}

Expand Down Expand Up @@ -99,10 +102,10 @@ public async Task Ethhash_Verify_Invalid_Blocks()

using (var ethash = new EthashLight(3))
{
Assert.False(await ethash.VerifyBlockAsync(invalidBlocks[0]));
Assert.False(await ethash.VerifyBlockAsync(invalidBlocks[1]));
Assert.False(await ethash.VerifyBlockAsync(invalidBlocks[2]));
Assert.False(await ethash.VerifyBlockAsync(invalidBlocks[3]));
Assert.False(await ethash.VerifyBlockAsync(invalidBlocks[0], logger));
Assert.False(await ethash.VerifyBlockAsync(invalidBlocks[1], logger));
Assert.False(await ethash.VerifyBlockAsync(invalidBlocks[2], logger));
Assert.False(await ethash.VerifyBlockAsync(invalidBlocks[3], logger));
}
}

Expand All @@ -111,7 +114,7 @@ public async Task EthHash_VerifyAsync_Should_Throw_On_Null_Argument()
{
using (var ethash = new EthashLight(3))
{
await Assert.ThrowsAsync<ArgumentNullException>(async () => await ethash.VerifyBlockAsync(null));
await Assert.ThrowsAsync<ArgumentNullException>(async () => await ethash.VerifyBlockAsync(null, logger));
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions src/MiningCore/Api/ApiServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private PoolConfig GetPool(HttpContext context, Match m)
return null;
}

private async Task SendJson(HttpContext context, object response)
private async Task SendJsonAsync(HttpContext context, object response)
{
context.Response.ContentType = "application/json";

Expand Down Expand Up @@ -250,7 +250,7 @@ private async Task GetPoolInfosAsync(HttpContext context, Match m)
}).ToArray()
};

await SendJson(context, response);
await SendJsonAsync(context, response);
}

private async Task GetPoolInfoAsync(HttpContext context, Match m)
Expand Down Expand Up @@ -280,7 +280,7 @@ private async Task GetPoolInfoAsync(HttpContext context, Match m)
.Select(mapper.Map<MinerPerformanceStats>)
.ToArray();

await SendJson(context, response);
await SendJsonAsync(context, response);
}

private async Task GetPoolPerformanceAsync(HttpContext context, Match m)
Expand All @@ -301,7 +301,7 @@ private async Task GetPoolPerformanceAsync(HttpContext context, Match m)
Stats = stats.Select(mapper.Map<AggregatedPoolStats>).ToArray()
};

await SendJson(context, response);
await SendJsonAsync(context, response);
}

private async Task PagePoolMinersAsync(HttpContext context, Match m)
Expand All @@ -328,7 +328,7 @@ private async Task PagePoolMinersAsync(HttpContext context, Match m)
.Select(mapper.Map<MinerPerformanceStats>)
.ToArray();

await SendJson(context, miners);
await SendJsonAsync(context, miners);
}

private async Task PagePoolBlocksPagedAsync(HttpContext context, Match m)
Expand Down Expand Up @@ -371,7 +371,7 @@ private async Task PagePoolBlocksPagedAsync(HttpContext context, Match m)
}
}

await SendJson(context, blocks);
await SendJsonAsync(context, blocks);
}

private async Task PagePoolPaymentsAsync(HttpContext context, Match m)
Expand Down Expand Up @@ -409,7 +409,7 @@ private async Task PagePoolPaymentsAsync(HttpContext context, Match m)
payment.AddressInfoLink = string.Format(addressInfobaseUrl, payment.Address);
}

await SendJson(context, payments);
await SendJsonAsync(context, payments);
}

private async Task GetMinerInfoAsync(HttpContext context, Match m)
Expand Down Expand Up @@ -450,7 +450,7 @@ private async Task GetMinerInfoAsync(HttpContext context, Match m)
stats.PerformanceSamples = GetMinerPerformanceInternal(perfMode, pool, address);
}

await SendJson(context, stats);
await SendJsonAsync(context, stats);
}

private async Task PageMinerPaymentsAsync(HttpContext context, Match m)
Expand Down Expand Up @@ -495,7 +495,7 @@ private async Task PageMinerPaymentsAsync(HttpContext context, Match m)
payment.AddressInfoLink = string.Format(addressInfobaseUrl, payment.Address);
}

await SendJson(context, payments);
await SendJsonAsync(context, payments);
}

private async Task PageMinerBalanceChangesAsync(HttpContext context, Match m)
Expand Down Expand Up @@ -525,7 +525,7 @@ private async Task PageMinerBalanceChangesAsync(HttpContext context, Match m)
.Select(mapper.Map<Responses.BalanceChange>)
.ToArray();

await SendJson(context, balanceChanges);
await SendJsonAsync(context, balanceChanges);
}

private async Task GetMinerPerformanceAsync(HttpContext context, Match m)
Expand All @@ -544,14 +544,14 @@ private async Task GetMinerPerformanceAsync(HttpContext context, Match m)
var mode = context.GetQueryParameter<string>("mode", "day").ToLower(); // "day" or "month"
var result = GetMinerPerformanceInternal(mode, pool, address);

await SendJson(context, result);
await SendJsonAsync(context, result);
}

private async Task HandleForceGcAsync(HttpContext context, Match m)
{
GC.Collect(2, GCCollectionMode.Forced);

await SendJson(context, true);
await SendJsonAsync(context, true);
}

private async Task HandleGcStatsAsync(HttpContext context, Match m)
Expand All @@ -562,7 +562,7 @@ private async Task HandleGcStatsAsync(HttpContext context, Match m)
Program.gcStats.GcGen2 = GC.CollectionCount(2);
Program.gcStats.MemAllocated = FormatUtil.FormatCapacity(GC.GetTotalMemory(false));

await SendJson(context, Program.gcStats);
await SendJsonAsync(context, Program.gcStats);
}

#region API-Surface
Expand Down
72 changes: 66 additions & 6 deletions src/MiningCore/Blockchain/Bitcoin/BitcoinConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,75 @@ public class BitcoinConstants
public static readonly BigInteger Diff1 = BigInteger.Parse("00ffff0000000000000000000000000000000000000000000000000000", NumberStyles.HexNumber);
public const int CoinbaseMinConfimations = 102;

public const int ErrorMethodNotFound = -32601;

public const string ZmqPublisherTopicBlockHash = "hashblock";
public const string ZmqPublisherTopicTxHash = "hashtx";
public const string ZmqPublisherTopicBlockRaw = "rawblock";
public const string ZmqPublisherTopicTxRaw = "rawtx";
}

public class KnownAddresses
public enum BitcoinRPCErrorCode
{
public static readonly Dictionary<CoinType, string> DevFeeAddresses = new Dictionary<CoinType, string>
//! Standard JSON-RPC 2.0 errors
// RPC_INVALID_REQUEST is internally mapped to HTTP_BAD_REQUEST (400).
// It should not be used for application-layer errors.
RPC_INVALID_REQUEST = -32600,
// RPC_METHOD_NOT_FOUND is internally mapped to HTTP_NOT_FOUND (404).
// It should not be used for application-layer errors.
RPC_METHOD_NOT_FOUND = -32601,
RPC_INVALID_PARAMS = -32602,
// RPC_INTERNAL_ERROR should only be used for genuine errors in bitcoind
// (for example datadir corruption).
RPC_INTERNAL_ERROR = -32603,
RPC_PARSE_ERROR = -32700,

//! General application defined errors
RPC_MISC_ERROR = -1, //!< std::exception thrown in command handling
RPC_FORBIDDEN_BY_SAFE_MODE = -2, //!< Server is in safe mode, and command is not allowed in safe mode
RPC_TYPE_ERROR = -3, //!< Unexpected type was passed as parameter
RPC_INVALID_ADDRESS_OR_KEY = -5, //!< Invalid address or key
RPC_OUT_OF_MEMORY = -7, //!< Ran out of memory during operation
RPC_INVALID_PARAMETER = -8, //!< Invalid, missing or duplicate parameter
RPC_DATABASE_ERROR = -20, //!< Database error
RPC_DESERIALIZATION_ERROR = -22, //!< Error parsing or validating structure in raw format
RPC_VERIFY_ERROR = -25, //!< General error during transaction or block submission
RPC_VERIFY_REJECTED = -26, //!< Transaction or block was rejected by network rules
RPC_VERIFY_ALREADY_IN_CHAIN = -27, //!< Transaction already in chain
RPC_IN_WARMUP = -28, //!< Client still warming up
RPC_METHOD_DEPRECATED = -32, //!< RPC method is deprecated

//! Aliases for backward compatibility
RPC_TRANSACTION_ERROR = RPC_VERIFY_ERROR,
RPC_TRANSACTION_REJECTED = RPC_VERIFY_REJECTED,
RPC_TRANSACTION_ALREADY_IN_CHAIN = RPC_VERIFY_ALREADY_IN_CHAIN,

//! P2P client errors
RPC_CLIENT_NOT_CONNECTED = -9, //!< Bitcoin is not connected
RPC_CLIENT_IN_INITIAL_DOWNLOAD = -10, //!< Still downloading initial blocks
RPC_CLIENT_NODE_ALREADY_ADDED = -23, //!< Node is already added
RPC_CLIENT_NODE_NOT_ADDED = -24, //!< Node has not been added before
RPC_CLIENT_NODE_NOT_CONNECTED = -29, //!< Node to disconnect not found in connected nodes
RPC_CLIENT_INVALID_IP_OR_SUBNET = -30, //!< Invalid IP/Subnet
RPC_CLIENT_P2P_DISABLED = -31, //!< No valid connection manager instance found

//! Wallet errors
RPC_WALLET_ERROR = -4, //!< Unspecified problem with wallet (key not found etc.)
RPC_WALLET_INSUFFICIENT_FUNDS = -6, //!< Not enough funds in wallet or account
RPC_WALLET_INVALID_ACCOUNT_NAME = -11, //!< Invalid account name
RPC_WALLET_KEYPOOL_RAN_OUT = -12, //!< Keypool ran out, call keypoolrefill first
RPC_WALLET_UNLOCK_NEEDED = -13, //!< Enter the wallet passphrase with walletpassphrase first
RPC_WALLET_PASSPHRASE_INCORRECT = -14, //!< The wallet passphrase entered was incorrect
RPC_WALLET_WRONG_ENC_STATE = -15, //!< Command given in wrong wallet encryption state (encrypting an encrypted wallet etc.)
RPC_WALLET_ENCRYPTION_FAILED = -16, //!< Failed to encrypt the wallet
RPC_WALLET_ALREADY_UNLOCKED = -17, //!< Wallet is already unlocked
RPC_WALLET_NOT_FOUND = -18, //!< Invalid wallet specified
RPC_WALLET_NOT_SPECIFIED = -19, //!< No wallet specified (error when there are multiple wallets loaded)
}

public class DevDonation
{
public const decimal Percent = 0.1m;

public static readonly Dictionary<CoinType, string> Addresses = new Dictionary<CoinType, string>
{
{CoinType.BTC, "17QnVor1B6oK1rWnVVBrdX9gFzVkZZbhDm"},
{CoinType.BCH, "1LJGTzNDTuTvkHpTxNSdmAEBAXAnEHDVqQ"},
Expand All @@ -93,11 +151,11 @@ public class KnownAddresses
{CoinType.DASH, "XqpBAV9QCaoLnz42uF5frSSfrJTrqHoxjp"},
{CoinType.VIA, "Vc5rJr2QdA2yo1jBoqYUAH7T59uBh2Vw5q"},
{CoinType.MONA, "MBbkeAM3VQKg474bgxJEXrtcnMg8cjHY3S"},
{CoinType.VTC, "VfCAvPVrksYvwcpU7E44e51HxfvVhcxMXf"},
{CoinType.VTC, "VwDWBHzhYeuyMcHpaZ5nZryggUjHSxUKKK"},
{CoinType.ZEC, "t1YHZHz2DGVMJiggD2P4fBQ2TAPgtLSUwZ7"},
{CoinType.ZCL, "t1MFU1vD3YKgsK6Uh8hW7UTY8mKAV2xVqBr"},
{CoinType.ZEN, "znigQacfTvRiwD2TRhwkBHLNchQ2AZisD94"},
{CoinType.BTG, "GQb77ZuMCyJGZFyxpzqNfm7GB1rQreP4n6"},
{CoinType.BTG, "GRao6KHQ8a4GUjAZRVbeCLfRbSkJQQaeMg"},
{CoinType.MOON, "2QvpGimMYLyqKsczQXZjv56h6me3M8orwj" },
{CoinType.XVG, "D5xPoHLM6HPkwWSqAweECTSQirJBmRjS8i" },
{CoinType.XMR, "475YVJbPHPedudkhrcNp1wDcLMTGYusGPF5fqE7XjnragVLPdqbCHBdZg3dF4dN9hXMjjvGbykS6a77dTAQvGrpiQqHp2eH"},
Expand All @@ -120,6 +178,8 @@ public static class BitcoinCommands
public const string GetBlock = "getblock";
public const string GetTransaction = "gettransaction";
public const string SendMany = "sendmany";
public const string WalletPassphrase = "walletpassphrase";
public const string WalletLock = "walletlock";

// Legacy commands
public const string GetInfo = "getinfo";
Expand Down
Loading

0 comments on commit a057083

Please sign in to comment.