Reimplement whole stratum network communication with boost::asio (#90)
Logger is now thread safe
This commit is contained in:
parent
15d752d9e0
commit
df084acff6
40 changed files with 915 additions and 1942 deletions
|
@ -34,10 +34,10 @@
|
|||
#include "crypto/CryptoNight_test.h"
|
||||
|
||||
template <size_t NUM_HASH_BLOCKS>
|
||||
static void cryptonight_aesni(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) {
|
||||
static void cryptonight_aesni(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) {
|
||||
# if !defined(XMRIG_ARMv7)
|
||||
if ((reinterpret_cast<const uint8_t*>(input)[0] > 6 && Options::i()->forcePowVersion() == Options::PowVersion::POW_AUTODETECT) ||
|
||||
Options::i()->forcePowVersion() == Options::PowVersion::POW_V2) {
|
||||
if ((reinterpret_cast<const uint8_t*>(input)[0] > 6 && powVersion == Options::PowVersion::POW_AUTODETECT) ||
|
||||
powVersion == Options::PowVersion::POW_V2) {
|
||||
CryptoNightMultiHash<0x80000, MEMORY, 0x1FFFF0, false, NUM_HASH_BLOCKS>::hashPowV2(input, size, output, ctx);
|
||||
} else {
|
||||
CryptoNightMultiHash<0x80000, MEMORY, 0x1FFFF0, false, NUM_HASH_BLOCKS>::hash(input, size, output, ctx);
|
||||
|
@ -46,9 +46,9 @@ static void cryptonight_aesni(const uint8_t* input, size_t size, uint8_t* output
|
|||
}
|
||||
|
||||
template <size_t NUM_HASH_BLOCKS>
|
||||
static void cryptonight_softaes(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) {
|
||||
if ((reinterpret_cast<const uint8_t*>(input)[0] > 6 && Options::i()->forcePowVersion() == Options::PowVersion::POW_AUTODETECT) ||
|
||||
Options::i()->forcePowVersion() == Options::PowVersion::POW_V2) {
|
||||
static void cryptonight_softaes(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) {
|
||||
if ((reinterpret_cast<const uint8_t*>(input)[0] > 6 && powVersion == Options::PowVersion::POW_AUTODETECT) ||
|
||||
powVersion == Options::PowVersion::POW_V2) {
|
||||
CryptoNightMultiHash<0x80000, MEMORY, 0x1FFFF0, true, NUM_HASH_BLOCKS>::hashPowV2(input, size, output, ctx);
|
||||
} else {
|
||||
CryptoNightMultiHash<0x80000, MEMORY, 0x1FFFF0, true, NUM_HASH_BLOCKS>::hash(input, size, output, ctx);
|
||||
|
@ -56,10 +56,10 @@ static void cryptonight_softaes(const uint8_t* input, size_t size, uint8_t* outp
|
|||
}
|
||||
|
||||
template <size_t NUM_HASH_BLOCKS>
|
||||
static void cryptonight_lite_aesni(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) {
|
||||
static void cryptonight_lite_aesni(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) {
|
||||
# if !defined(XMRIG_ARMv7)
|
||||
if ((reinterpret_cast<const uint8_t*>(input)[0] > 1 && Options::i()->forcePowVersion() == Options::PowVersion::POW_AUTODETECT) ||
|
||||
Options::i()->forcePowVersion() == Options::PowVersion::POW_V2) {
|
||||
if ((reinterpret_cast<const uint8_t*>(input)[0] > 1 && powVersion == Options::PowVersion::POW_AUTODETECT) ||
|
||||
powVersion == Options::PowVersion::POW_V2) {
|
||||
CryptoNightMultiHash<0x40000, MEMORY_LITE, 0xFFFF0, false, NUM_HASH_BLOCKS>::hashPowV2(input, size, output, ctx);
|
||||
} else {
|
||||
CryptoNightMultiHash<0x40000, MEMORY_LITE, 0xFFFF0, false, NUM_HASH_BLOCKS>::hash(input, size, output, ctx);
|
||||
|
@ -68,9 +68,9 @@ static void cryptonight_lite_aesni(const uint8_t* input, size_t size, uint8_t* o
|
|||
}
|
||||
|
||||
template <size_t NUM_HASH_BLOCKS>
|
||||
static void cryptonight_lite_softaes(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) {
|
||||
if ((reinterpret_cast<const uint8_t*>(input)[0] > 1 && Options::i()->forcePowVersion() == Options::PowVersion::POW_AUTODETECT) ||
|
||||
Options::i()->forcePowVersion() == Options::PowVersion::POW_V2) {
|
||||
static void cryptonight_lite_softaes(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) {
|
||||
if ((reinterpret_cast<const uint8_t*>(input)[0] > 1 && powVersion == Options::PowVersion::POW_AUTODETECT) ||
|
||||
powVersion == Options::PowVersion::POW_V2) {
|
||||
CryptoNightMultiHash<0x40000, MEMORY_LITE, 0xFFFF0, true, NUM_HASH_BLOCKS>::hashPowV2(input, size, output, ctx);
|
||||
} else {
|
||||
CryptoNightMultiHash<0x40000, MEMORY_LITE, 0xFFFF0, true, NUM_HASH_BLOCKS>::hash(input, size, output, ctx);
|
||||
|
@ -79,18 +79,18 @@ static void cryptonight_lite_softaes(const uint8_t* input, size_t size, uint8_t*
|
|||
|
||||
|
||||
template <size_t NUM_HASH_BLOCKS>
|
||||
static void cryptonight_heavy_aesni(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) {
|
||||
static void cryptonight_heavy_aesni(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) {
|
||||
# if !defined(XMRIG_ARMv7)
|
||||
CryptoNightMultiHash<0x40000, MEMORY_HEAVY, 0x3FFFF0, false, NUM_HASH_BLOCKS>::hashHeavy(input, size, output, ctx);
|
||||
# endif
|
||||
}
|
||||
|
||||
template <size_t NUM_HASH_BLOCKS>
|
||||
static void cryptonight_heavy_softaes(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) {
|
||||
static void cryptonight_heavy_softaes(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx) {
|
||||
CryptoNightMultiHash<0x40000, MEMORY_HEAVY, 0x3FFFF0, true, NUM_HASH_BLOCKS>::hashHeavy(input, size, output, ctx);
|
||||
}
|
||||
|
||||
void (*cryptonight_hash_ctx[MAX_NUM_HASH_BLOCKS])(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx);
|
||||
void (*cryptonight_hash_ctx[MAX_NUM_HASH_BLOCKS])(Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx *ctx);
|
||||
|
||||
template <size_t HASH_FACTOR>
|
||||
void setCryptoNightHashMethods(Options::Algo algo, bool aesni)
|
||||
|
@ -136,9 +136,9 @@ bool CryptoNight::init(int algo, bool aesni)
|
|||
return selfTest(algo);
|
||||
}
|
||||
|
||||
void CryptoNight::hash(size_t factor, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx* ctx)
|
||||
void CryptoNight::hash(size_t factor, Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx* ctx)
|
||||
{
|
||||
cryptonight_hash_ctx[factor-1](input, size, output, ctx);
|
||||
cryptonight_hash_ctx[factor-1](powVersion, input, size, output, ctx);
|
||||
}
|
||||
|
||||
bool CryptoNight::selfTest(int algo)
|
||||
|
@ -169,80 +169,81 @@ bool CryptoNight::selfTest(int algo)
|
|||
bool resultV2Pow = true;
|
||||
bool resultHeavy = true;
|
||||
|
||||
if (algo == Options::ALGO_CRYPTONIGHT_HEAVY)
|
||||
{
|
||||
cryptonight_hash_ctx[0](test_input, 76, output, ctx);
|
||||
if (algo == Options::ALGO_CRYPTONIGHT_HEAVY) {
|
||||
// cn-heavy tests
|
||||
|
||||
cryptonight_hash_ctx[0](Options::PowVersion::POW_AUTODETECT, test_input, 76, output, ctx);
|
||||
resultHeavy = resultHeavy && memcmp(output, test_output_heavy, 32) == 0;
|
||||
|
||||
#if MAX_NUM_HASH_BLOCKS > 1
|
||||
cryptonight_hash_ctx[1](test_input, 76, output, ctx);
|
||||
cryptonight_hash_ctx[1](Options::PowVersion::POW_AUTODETECT, test_input, 76, output, ctx);
|
||||
resultHeavy = resultHeavy && memcmp(output, test_output_heavy, 64) == 0;
|
||||
#endif
|
||||
|
||||
#if MAX_NUM_HASH_BLOCKS > 2
|
||||
cryptonight_hash_ctx[2](test_input, 76, output, ctx);
|
||||
cryptonight_hash_ctx[2](Options::PowVersion::POW_AUTODETECT, test_input, 76, output, ctx);
|
||||
resultHeavy = resultHeavy && memcmp(output, test_output_heavy, 96) == 0;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
if (Options::i()->forcePowVersion() == Options::PowVersion::POW_AUTODETECT ||
|
||||
Options::i()->forcePowVersion() == Options::PowVersion::POW_V1) {
|
||||
cryptonight_hash_ctx[0](test_input, 76, output, ctx);
|
||||
resultV1Pow = resultV1Pow &&
|
||||
memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output,
|
||||
32) == 0;
|
||||
// < v7 tests autodetect
|
||||
cryptonight_hash_ctx[0](Options::PowVersion::POW_AUTODETECT,test_input, 76, output, ctx);
|
||||
resultV1Pow = resultV1Pow &&
|
||||
memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output,
|
||||
32) == 0;
|
||||
|
||||
#if MAX_NUM_HASH_BLOCKS > 1
|
||||
cryptonight_hash_ctx[1](test_input, 76, output, ctx);
|
||||
resultV1Pow = resultV1Pow &&
|
||||
memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output,
|
||||
64) == 0;
|
||||
#endif
|
||||
#if MAX_NUM_HASH_BLOCKS > 1
|
||||
cryptonight_hash_ctx[1](Options::PowVersion::POW_AUTODETECT, test_input, 76, output, ctx);
|
||||
resultV1Pow = resultV1Pow &&
|
||||
memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output,
|
||||
64) == 0;
|
||||
#endif
|
||||
|
||||
#if MAX_NUM_HASH_BLOCKS > 2
|
||||
cryptonight_hash_ctx[2](test_input, 76, output, ctx);
|
||||
resultV1Pow = resultV1Pow &&
|
||||
memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output,
|
||||
96) == 0;
|
||||
#endif
|
||||
#if MAX_NUM_HASH_BLOCKS > 2
|
||||
cryptonight_hash_ctx[2](Options::PowVersion::POW_AUTODETECT, test_input, 76, output, ctx);
|
||||
resultV1Pow = resultV1Pow &&
|
||||
memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output,
|
||||
96) == 0;
|
||||
#endif
|
||||
|
||||
#if MAX_NUM_HASH_BLOCKS > 3
|
||||
cryptonight_hash_ctx[3](test_input, 76, output, ctx);
|
||||
resultV1Pow = resultV1Pow &&
|
||||
memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output,
|
||||
128) == 0;
|
||||
#endif
|
||||
// < v7 tests force pow
|
||||
#if MAX_NUM_HASH_BLOCKS > 3
|
||||
cryptonight_hash_ctx[3](Options::PowVersion::POW_V1, test_input, 76, output, ctx);
|
||||
resultV1Pow = resultV1Pow &&
|
||||
memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output,
|
||||
128) == 0;
|
||||
#endif
|
||||
|
||||
#if MAX_NUM_HASH_BLOCKS > 4
|
||||
cryptonight_hash_ctx[4](test_input, 76, output, ctx);
|
||||
resultV1Pow = resultV1Pow &&
|
||||
memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output,
|
||||
160) == 0;
|
||||
#endif
|
||||
}
|
||||
#if MAX_NUM_HASH_BLOCKS > 4
|
||||
cryptonight_hash_ctx[4](Options::PowVersion::POW_V1, test_input, 76, output, ctx);
|
||||
resultV1Pow = resultV1Pow &&
|
||||
memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_light : test_output,
|
||||
160) == 0;
|
||||
#endif
|
||||
|
||||
// monero/aeon v2 pow (monero/aeon blockchain version 7)
|
||||
if (Options::i()->forcePowVersion() == Options::PowVersion::POW_AUTODETECT ||
|
||||
Options::i()->forcePowVersion() == Options::PowVersion::POW_V2) {
|
||||
cryptonight_hash_ctx[0](test_input_monero_v2_pow_0, sizeof(test_input_monero_v2_pow_0), output, ctx);
|
||||
resultV2Pow = resultV2Pow && memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE
|
||||
? test_output_monero_v2_pow_light[0]
|
||||
: test_output_monero_v2_pow[0], 32) == 0;
|
||||
// v7 tests autodetect
|
||||
cryptonight_hash_ctx[0](Options::PowVersion::POW_AUTODETECT, test_input_monero_v2_pow_0,
|
||||
sizeof(test_input_monero_v2_pow_0), output, ctx);
|
||||
resultV2Pow = resultV2Pow && memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE
|
||||
? test_output_monero_v2_pow_light[0]
|
||||
: test_output_monero_v2_pow[0], 32) == 0;
|
||||
|
||||
#if MAX_NUM_HASH_BLOCKS > 1
|
||||
cryptonight_hash_ctx[1](test_input_monero_v2_pow_1, sizeof(test_input_monero_v2_pow_1), output, ctx);
|
||||
resultV2Pow = resultV2Pow && memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE
|
||||
? test_output_monero_v2_pow_light[1]
|
||||
: test_output_monero_v2_pow[1], 32) == 0;
|
||||
#endif
|
||||
#if MAX_NUM_HASH_BLOCKS > 1
|
||||
cryptonight_hash_ctx[1](Options::PowVersion::POW_AUTODETECT, test_input_monero_v2_pow_1,
|
||||
sizeof(test_input_monero_v2_pow_1), output, ctx);
|
||||
resultV2Pow = resultV2Pow && memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE
|
||||
? test_output_monero_v2_pow_light[1]
|
||||
: test_output_monero_v2_pow[1], 32) == 0;
|
||||
#endif
|
||||
|
||||
#if MAX_NUM_HASH_BLOCKS > 2
|
||||
cryptonight_hash_ctx[2](test_input_monero_v2_pow_2, sizeof(test_input_monero_v2_pow_2), output, ctx);
|
||||
resultV2Pow = resultV2Pow && memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE
|
||||
? test_output_monero_v2_pow_light[2]
|
||||
: test_output_monero_v2_pow[2], 32) == 0;
|
||||
#endif
|
||||
}
|
||||
// v7 tests force pow
|
||||
#if MAX_NUM_HASH_BLOCKS > 2
|
||||
cryptonight_hash_ctx[2](Options::PowVersion::POW_V2, test_input_monero_v2_pow_2,
|
||||
sizeof(test_input_monero_v2_pow_2), output, ctx);
|
||||
resultV2Pow = resultV2Pow && memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE
|
||||
? test_output_monero_v2_pow_light[2]
|
||||
: test_output_monero_v2_pow[2], 32) == 0;
|
||||
#endif
|
||||
}
|
||||
_mm_free(ctx->memory);
|
||||
_mm_free(ctx);
|
||||
|
|
|
@ -48,7 +48,7 @@ class CryptoNight
|
|||
public:
|
||||
static bool init(int algo, bool aesni);
|
||||
|
||||
static void hash(size_t factor, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx* ctx);
|
||||
static void hash(size_t factor, Options::PowVersion powVersion, const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx* ctx);
|
||||
|
||||
private:
|
||||
static bool selfTest(int algo);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue