Visitar URL original
Dev (#290) · ishrikrishna/miningcore@a057083 · GitHub
Skip to content

Commit a057083

Browse files
authored
* 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 oliverw#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 oliverw#289
1 parent d2ad288 commit a057083

36 files changed

Lines changed: 1214 additions & 791 deletions

‎src/MiningCore.Tests/Blockchain/Ethereum/EthereumJobTests.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace MiningCore.Tests.Blockchain.Ethereum
1414
/// </summary>
1515
public class EthereumJobTests : TestBase
1616
{
17-
static readonly EthashFull ethash = new EthashFull(3, Path.GetTempPath(), true);
17+
static readonly EthashFull ethash = new EthashFull(3, Path.GetTempPath());
1818

1919
/*
2020
[Fact]

‎src/MiningCore.Tests/Crypto/EthashTests.cs‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
using MiningCore.Crypto.Hashing.Algorithms;
77
using MiningCore.Crypto.Hashing.Ethash;
88
using MiningCore.Extensions;
9+
using NLog;
910
using Xunit;
1011

1112
namespace MiningCore.Tests.Crypto
1213
{
1314
public class EthashTests : TestBase
1415
{
16+
private ILogger logger = LogManager.GetCurrentClassLogger();
17+
1518
[Fact]
1619
public async Task Ethhash_Verify_Valid_Blocks()
1720
{
@@ -47,9 +50,9 @@ public async Task Ethhash_Verify_Valid_Blocks()
4750

4851
using (var ethash = new EthashLight(3))
4952
{
50-
Assert.True(await ethash.VerifyBlockAsync(validBlocks[0]));
51-
Assert.True(await ethash.VerifyBlockAsync(validBlocks[1]));
52-
Assert.True(await ethash.VerifyBlockAsync(validBlocks[2]));
53+
Assert.True(await ethash.VerifyBlockAsync(validBlocks[0], logger));
54+
Assert.True(await ethash.VerifyBlockAsync(validBlocks[1], logger));
55+
Assert.True(await ethash.VerifyBlockAsync(validBlocks[2], logger));
5356
}
5457
}
5558

@@ -99,10 +102,10 @@ public async Task Ethhash_Verify_Invalid_Blocks()
99102

100103
using (var ethash = new EthashLight(3))
101104
{
102-
Assert.False(await ethash.VerifyBlockAsync(invalidBlocks[0]));
103-
Assert.False(await ethash.VerifyBlockAsync(invalidBlocks[1]));
104-
Assert.False(await ethash.VerifyBlockAsync(invalidBlocks[2]));
105-
Assert.False(await ethash.VerifyBlockAsync(invalidBlocks[3]));
105+
Assert.False(await ethash.VerifyBlockAsync(invalidBlocks[0], logger));
106+
Assert.False(await ethash.VerifyBlockAsync(invalidBlocks[1], logger));
107+
Assert.False(await ethash.VerifyBlockAsync(invalidBlocks[2], logger));
108+
Assert.False(await ethash.VerifyBlockAsync(invalidBlocks[3], logger));
106109
}
107110
}
108111

@@ -111,7 +114,7 @@ public async Task EthHash_VerifyAsync_Should_Throw_On_Null_Argument()
111114
{
112115
using (var ethash = new EthashLight(3))
113116
{
114-
await Assert.ThrowsAsync<ArgumentNullException>(async () => await ethash.VerifyBlockAsync(null));
117+
await Assert.ThrowsAsync<ArgumentNullException>(async () => await ethash.VerifyBlockAsync(null, logger));
115118
}
116119
}
117120
}

‎src/MiningCore/Api/ApiServer.cs‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private PoolConfig GetPool(HttpContext context, Match m)
132132
return null;
133133
}
134134

135-
private async Task SendJson(HttpContext context, object response)
135+
private async Task SendJsonAsync(HttpContext context, object response)
136136
{
137137
context.Response.ContentType = "application/json";
138138

@@ -250,7 +250,7 @@ private async Task GetPoolInfosAsync(HttpContext context, Match m)
250250
}).ToArray()
251251
};
252252

253-
await SendJson(context, response);
253+
await SendJsonAsync(context, response);
254254
}
255255

256256
private async Task GetPoolInfoAsync(HttpContext context, Match m)
@@ -280,7 +280,7 @@ private async Task GetPoolInfoAsync(HttpContext context, Match m)
280280
.Select(mapper.Map<MinerPerformanceStats>)
281281
.ToArray();
282282

283-
await SendJson(context, response);
283+
await SendJsonAsync(context, response);
284284
}
285285

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

304-
await SendJson(context, response);
304+
await SendJsonAsync(context, response);
305305
}
306306

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

331-
await SendJson(context, miners);
331+
await SendJsonAsync(context, miners);
332332
}
333333

334334
private async Task PagePoolBlocksPagedAsync(HttpContext context, Match m)
@@ -371,7 +371,7 @@ private async Task PagePoolBlocksPagedAsync(HttpContext context, Match m)
371371
}
372372
}
373373

374-
await SendJson(context, blocks);
374+
await SendJsonAsync(context, blocks);
375375
}
376376

377377
private async Task PagePoolPaymentsAsync(HttpContext context, Match m)
@@ -409,7 +409,7 @@ private async Task PagePoolPaymentsAsync(HttpContext context, Match m)
409409
payment.AddressInfoLink = string.Format(addressInfobaseUrl, payment.Address);
410410
}
411411

412-
await SendJson(context, payments);
412+
await SendJsonAsync(context, payments);
413413
}
414414

415415
private async Task GetMinerInfoAsync(HttpContext context, Match m)
@@ -450,7 +450,7 @@ private async Task GetMinerInfoAsync(HttpContext context, Match m)
450450
stats.PerformanceSamples = GetMinerPerformanceInternal(perfMode, pool, address);
451451
}
452452

453-
await SendJson(context, stats);
453+
await SendJsonAsync(context, stats);
454454
}
455455

456456
private async Task PageMinerPaymentsAsync(HttpContext context, Match m)
@@ -495,7 +495,7 @@ private async Task PageMinerPaymentsAsync(HttpContext context, Match m)
495495
payment.AddressInfoLink = string.Format(addressInfobaseUrl, payment.Address);
496496
}
497497

498-
await SendJson(context, payments);
498+
await SendJsonAsync(context, payments);
499499
}
500500

501501
private async Task PageMinerBalanceChangesAsync(HttpContext context, Match m)
@@ -525,7 +525,7 @@ private async Task PageMinerBalanceChangesAsync(HttpContext context, Match m)
525525
.Select(mapper.Map<Responses.BalanceChange>)
526526
.ToArray();
527527

528-
await SendJson(context, balanceChanges);
528+
await SendJsonAsync(context, balanceChanges);
529529
}
530530

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

547-
await SendJson(context, result);
547+
await SendJsonAsync(context, result);
548548
}
549549

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

554-
await SendJson(context, true);
554+
await SendJsonAsync(context, true);
555555
}
556556

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

565-
await SendJson(context, Program.gcStats);
565+
await SendJsonAsync(context, Program.gcStats);
566566
}
567567

568568
#region API-Surface

‎src/MiningCore/Blockchain/Bitcoin/BitcoinConstants.cs‎

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,75 @@ public class BitcoinConstants
6969
public static readonly BigInteger Diff1 = BigInteger.Parse("00ffff0000000000000000000000000000000000000000000000000000", NumberStyles.HexNumber);
7070
public const int CoinbaseMinConfimations = 102;
7171

72-
public const int ErrorMethodNotFound = -32601;
73-
7472
public const string ZmqPublisherTopicBlockHash = "hashblock";
7573
public const string ZmqPublisherTopicTxHash = "hashtx";
7674
public const string ZmqPublisherTopicBlockRaw = "rawblock";
7775
public const string ZmqPublisherTopicTxRaw = "rawtx";
7876
}
7977

80-
public class KnownAddresses
78+
public enum BitcoinRPCErrorCode
8179
{
82-
public static readonly Dictionary<CoinType, string> DevFeeAddresses = new Dictionary<CoinType, string>
80+
//! Standard JSON-RPC 2.0 errors
81+
// RPC_INVALID_REQUEST is internally mapped to HTTP_BAD_REQUEST (400).
82+
// It should not be used for application-layer errors.
83+
RPC_INVALID_REQUEST = -32600,
84+
// RPC_METHOD_NOT_FOUND is internally mapped to HTTP_NOT_FOUND (404).
85+
// It should not be used for application-layer errors.
86+
RPC_METHOD_NOT_FOUND = -32601,
87+
RPC_INVALID_PARAMS = -32602,
88+
// RPC_INTERNAL_ERROR should only be used for genuine errors in bitcoind
89+
// (for example datadir corruption).
90+
RPC_INTERNAL_ERROR = -32603,
91+
RPC_PARSE_ERROR = -32700,
92+
93+
//! General application defined errors
94+
RPC_MISC_ERROR = -1, //!< std::exception thrown in command handling
95+
RPC_FORBIDDEN_BY_SAFE_MODE = -2, //!< Server is in safe mode, and command is not allowed in safe mode
96+
RPC_TYPE_ERROR = -3, //!< Unexpected type was passed as parameter
97+
RPC_INVALID_ADDRESS_OR_KEY = -5, //!< Invalid address or key
98+
RPC_OUT_OF_MEMORY = -7, //!< Ran out of memory during operation
99+
RPC_INVALID_PARAMETER = -8, //!< Invalid, missing or duplicate parameter
100+
RPC_DATABASE_ERROR = -20, //!< Database error
101+
RPC_DESERIALIZATION_ERROR = -22, //!< Error parsing or validating structure in raw format
102+
RPC_VERIFY_ERROR = -25, //!< General error during transaction or block submission
103+
RPC_VERIFY_REJECTED = -26, //!< Transaction or block was rejected by network rules
104+
RPC_VERIFY_ALREADY_IN_CHAIN = -27, //!< Transaction already in chain
105+
RPC_IN_WARMUP = -28, //!< Client still warming up
106+
RPC_METHOD_DEPRECATED = -32, //!< RPC method is deprecated
107+
108+
//! Aliases for backward compatibility
109+
RPC_TRANSACTION_ERROR = RPC_VERIFY_ERROR,
110+
RPC_TRANSACTION_REJECTED = RPC_VERIFY_REJECTED,
111+
RPC_TRANSACTION_ALREADY_IN_CHAIN = RPC_VERIFY_ALREADY_IN_CHAIN,
112+
113+
//! P2P client errors
114+
RPC_CLIENT_NOT_CONNECTED = -9, //!< Bitcoin is not connected
115+
RPC_CLIENT_IN_INITIAL_DOWNLOAD = -10, //!< Still downloading initial blocks
116+
RPC_CLIENT_NODE_ALREADY_ADDED = -23, //!< Node is already added
117+
RPC_CLIENT_NODE_NOT_ADDED = -24, //!< Node has not been added before
118+
RPC_CLIENT_NODE_NOT_CONNECTED = -29, //!< Node to disconnect not found in connected nodes
119+
RPC_CLIENT_INVALID_IP_OR_SUBNET = -30, //!< Invalid IP/Subnet
120+
RPC_CLIENT_P2P_DISABLED = -31, //!< No valid connection manager instance found
121+
122+
//! Wallet errors
123+
RPC_WALLET_ERROR = -4, //!< Unspecified problem with wallet (key not found etc.)
124+
RPC_WALLET_INSUFFICIENT_FUNDS = -6, //!< Not enough funds in wallet or account
125+
RPC_WALLET_INVALID_ACCOUNT_NAME = -11, //!< Invalid account name
126+
RPC_WALLET_KEYPOOL_RAN_OUT = -12, //!< Keypool ran out, call keypoolrefill first
127+
RPC_WALLET_UNLOCK_NEEDED = -13, //!< Enter the wallet passphrase with walletpassphrase first
128+
RPC_WALLET_PASSPHRASE_INCORRECT = -14, //!< The wallet passphrase entered was incorrect
129+
RPC_WALLET_WRONG_ENC_STATE = -15, //!< Command given in wrong wallet encryption state (encrypting an encrypted wallet etc.)
130+
RPC_WALLET_ENCRYPTION_FAILED = -16, //!< Failed to encrypt the wallet
131+
RPC_WALLET_ALREADY_UNLOCKED = -17, //!< Wallet is already unlocked
132+
RPC_WALLET_NOT_FOUND = -18, //!< Invalid wallet specified
133+
RPC_WALLET_NOT_SPECIFIED = -19, //!< No wallet specified (error when there are multiple wallets loaded)
134+
}
135+
136+
public class DevDonation
137+
{
138+
public const decimal Percent = 0.1m;
139+
140+
public static readonly Dictionary<CoinType, string> Addresses = new Dictionary<CoinType, string>
83141
{
84142
{CoinType.BTC, "17QnVor1B6oK1rWnVVBrdX9gFzVkZZbhDm"},
85143
{CoinType.BCH, "1LJGTzNDTuTvkHpTxNSdmAEBAXAnEHDVqQ"},
@@ -93,11 +151,11 @@ public class KnownAddresses
93151
{CoinType.DASH, "XqpBAV9QCaoLnz42uF5frSSfrJTrqHoxjp"},
94152
{CoinType.VIA, "Vc5rJr2QdA2yo1jBoqYUAH7T59uBh2Vw5q"},
95153
{CoinType.MONA, "MBbkeAM3VQKg474bgxJEXrtcnMg8cjHY3S"},
96-
{CoinType.VTC, "VfCAvPVrksYvwcpU7E44e51HxfvVhcxMXf"},
154+
{CoinType.VTC, "VwDWBHzhYeuyMcHpaZ5nZryggUjHSxUKKK"},
97155
{CoinType.ZEC, "t1YHZHz2DGVMJiggD2P4fBQ2TAPgtLSUwZ7"},
98156
{CoinType.ZCL, "t1MFU1vD3YKgsK6Uh8hW7UTY8mKAV2xVqBr"},
99157
{CoinType.ZEN, "znigQacfTvRiwD2TRhwkBHLNchQ2AZisD94"},
100-
{CoinType.BTG, "GQb77ZuMCyJGZFyxpzqNfm7GB1rQreP4n6"},
158+
{CoinType.BTG, "GRao6KHQ8a4GUjAZRVbeCLfRbSkJQQaeMg"},
101159
{CoinType.MOON, "2QvpGimMYLyqKsczQXZjv56h6me3M8orwj" },
102160
{CoinType.XVG, "D5xPoHLM6HPkwWSqAweECTSQirJBmRjS8i" },
103161
{CoinType.XMR, "475YVJbPHPedudkhrcNp1wDcLMTGYusGPF5fqE7XjnragVLPdqbCHBdZg3dF4dN9hXMjjvGbykS6a77dTAQvGrpiQqHp2eH"},
@@ -120,6 +178,8 @@ public static class BitcoinCommands
120178
public const string GetBlock = "getblock";
121179
public const string GetTransaction = "gettransaction";
122180
public const string SendMany = "sendmany";
181+
public const string WalletPassphrase = "walletpassphrase";
182+
public const string WalletLock = "walletlock";
123183

124184
// Legacy commands
125185
public const string GetInfo = "getinfo";

0 commit comments

Comments
 (0)