diff --git a/CMakeLists.txt b/CMakeLists.txt index ab48b4c6..911d69c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,6 @@ if(TESTNET) endif() set(BUILD_GUI FALSE CACHE BOOL "Build qt-daemon") -set(USE_OPENCL FALSE CACHE BOOL "Build with opencl miner") set(STATIC ${MSVC} CACHE BOOL "Link libraries statically") @@ -171,18 +170,6 @@ if(BUILD_GUI) find_package(Qt5Widgets REQUIRED) endif() -if(USE_OPENCL) - find_package( OpenCL ) - if(NOT OpenCL_FOUND) - # add some Opencl - endif() - - include_directories( ${OpenCL_INCLUDE_DIRS} ) - include_directories( ${OpenCL_INCLUDE_DIR} ) - add_definitions(-DUSE_OPENCL) -endif() - - set(COMMIT_ID_IN_VERSION ON CACHE BOOL "Include commit ID in version") file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/version") if (NOT COMMIT_ID_IN_VERSION) diff --git a/src/connectivity_tool/conn_tool.cpp b/src/connectivity_tool/conn_tool.cpp index 031b248d..be6405ba 100644 --- a/src/connectivity_tool/conn_tool.cpp +++ b/src/connectivity_tool/conn_tool.cpp @@ -104,6 +104,7 @@ struct response_schema "\"time_started\": " << ce.time_started << ", " "\"last_recv\": " << ce.last_recv << ", " "\"last_send\": " << ce.last_send << ", " + "\"version\": " << ce.version << ", " "\"is_income\": " << ce.is_income << "}"; if(rs.ns_rsp.v.connections_list.size()-1 != i) ss << ","; @@ -373,19 +374,19 @@ bool generate_genesis(const std::string& path_config, uint64_t premine_split_amo uint64_t total_this = 0; double total_usd_eq = 0; - +#define COLUMN_INTERVAL_LAYOUT 30 std::stringstream ss; ss.precision(10); - ss << std::setw(15) << std::left << "NAME" << std::setw(15) << std::left << "AMOUNT" << std::setw(15) << std::left << "AMOUNT THIS" << std::setw(15) << std::left << "USD EQ" << ENDL; + ss << std::setw(COLUMN_INTERVAL_LAYOUT) << std::left << "NAME" << std::setw(COLUMN_INTERVAL_LAYOUT) << std::left << "AMOUNT" << std::setw(COLUMN_INTERVAL_LAYOUT) << std::left << "AMOUNT THIS" << std::setw(COLUMN_INTERVAL_LAYOUT) << std::left << "USD EQ" << ENDL; for (auto& se : payments_stat) { - ss << std::setw(15) << std::left << se.first << std::setw(15) << std::fixed << std::left << se.second.amount_total << std::setw(15) << std::fixed << std::left << print_money(se.second.amount_paid_this) << std::setw(15) << std::fixed << std::left << se.second.amount_usd_eq << ENDL; + ss << std::setw(COLUMN_INTERVAL_LAYOUT) << std::left << se.first << std::setw(COLUMN_INTERVAL_LAYOUT) << std::fixed << std::left << se.second.amount_total << std::setw(COLUMN_INTERVAL_LAYOUT) << std::fixed << std::left << print_money(se.second.amount_paid_this) << std::setw(COLUMN_INTERVAL_LAYOUT) << std::fixed << std::left << se.second.amount_usd_eq << ENDL; total_this += se.second.amount_paid_this; total_usd_eq += se.second.amount_usd_eq; } - ss << ENDL << std::setw(15) << std::left << "TOTAL" << std::setw(15) << std::fixed << std::left << " " << std::setw(15) << std::fixed << std::left << print_money(total_this) << std::setw(15) << std::fixed << std::left << total_usd_eq << ENDL; + ss << ENDL << std::setw(COLUMN_INTERVAL_LAYOUT) << std::left << "TOTAL" << std::setw(COLUMN_INTERVAL_LAYOUT) << std::fixed << std::left << " " << std::setw(COLUMN_INTERVAL_LAYOUT) << std::fixed << std::left << print_money(total_this) << std::setw(COLUMN_INTERVAL_LAYOUT) << std::fixed << std::left << total_usd_eq << ENDL; - ss << ENDL << std::setw(15) << std::left << "PREMINE_AMOUNT" << std::setw(15) << std::fixed << std::left << " " << std::setw(15) << std::fixed << std::left << total_this << "(" << print_money(total_this) <<"THIS)" << ENDL; + ss << ENDL << std::setw(COLUMN_INTERVAL_LAYOUT) << std::left << "PREMINE_AMOUNT" << std::setw(COLUMN_INTERVAL_LAYOUT) << std::fixed << std::left << " " << std::setw(COLUMN_INTERVAL_LAYOUT) << std::fixed << std::left << total_this << "(" << print_money(total_this) <<"THIS)" << ENDL; epee::log_space::set_console_color(epee::log_space::console_colors::console_color_magenta, true); std::cout << "GENESIS STAT: " << ENDL << ss.str(); @@ -450,6 +451,7 @@ bool generate_genesis(const std::string& path_config, uint64_t premine_split_amo return true; } +#undef COLUMN_INTERVAL_LAYOUT //--------------------------------------------------------------------------------------------------------------- bool handle_get_aliases(po::variables_map& vm) { diff --git a/src/crypto/wild_keccak.cpp b/src/crypto/wild_keccak.cpp new file mode 100644 index 00000000..89ffb258 --- /dev/null +++ b/src/crypto/wild_keccak.cpp @@ -0,0 +1,133 @@ +// keccak.c +// 19-Nov-11 Markku-Juhani O. Saarinen +// A baseline Keccak (3rd round) implementation. + +// Memory-hard extension of keccak for PoW +// Copyright (c) 2014 The Boolberry developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + + +#include "wild_keccak.h" +namespace crypto +{ + + const uint64_t keccakf_rndc[24] = + { + 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, + 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, + 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, + 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, + 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, + 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, + 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, + 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 + }; + + const int keccakf_rotc[24] = + { + 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, + 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 + }; + + const int keccakf_piln[24] = + { + 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, + 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 + }; + + // update the state with given number of rounds + void regular_f::keccakf(uint64_t st[25], int rounds) + { + int i, j, round; + uint64_t t, bc[5]; + + for (round = 0; round < rounds; round++) { + + // Theta + for (i = 0; i < 5; i++) + bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] ^ st[i + 15] ^ st[i + 20]; + + for (i = 0; i < 5; i++) { + t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); + for (j = 0; j < 25; j += 5) + st[j + i] ^= t; + } + + // Rho Pi + t = st[1]; + for (i = 0; i < 24; i++) { + j = keccakf_piln[i]; + bc[0] = st[j]; + st[j] = ROTL64(t, keccakf_rotc[i]); + t = bc[0]; + } + + // Chi + for (j = 0; j < 25; j += 5) { + for (i = 0; i < 5; i++) + bc[i] = st[j + i]; + for (i = 0; i < 5; i++) + st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5]; + } + + // Iota + st[0] ^= keccakf_rndc[round]; + } + } + + void mul_f::keccakf(uint64_t st[25], int rounds) + { + int i, j, round; + uint64_t t, bc[5]; + + for (round = 0; round < rounds; round++) { + + // Theta + for (i = 0; i < 5; i++) + { + bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] * st[i + 15] * st[i + 20];//surprise + } + + for (i = 0; i < 5; i++) { + t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); + for (j = 0; j < 25; j += 5) + st[j + i] ^= t; + } + + // Rho Pi + t = st[1]; + for (i = 0; i < 24; i++) { + j = keccakf_piln[i]; + bc[0] = st[j]; + st[j] = ROTL64(t, keccakf_rotc[i]); + t = bc[0]; + } + + // Chi + for (j = 0; j < 25; j += 5) { + for (i = 0; i < 5; i++) + bc[i] = st[j + i]; + for (i = 0; i < 5; i++) + st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5]; + } + + // Iota + st[0] ^= keccakf_rndc[round]; + } + } + bool generate_scratchpad(const crypto::hash& seed_data, std::vector& result_data, uint64_t target_size) + { + //this is very basic implementation, not considered for production (possible to reduce memory by keeping only every x10 item and calc it instead of read) + //TODO: research safe way for scratchpad generation + result_data.resize(target_size); + result_data[0] = crypto::cn_fast_hash(&seed_data, sizeof(seed_data)); + //crypto::hash = get_transaction_hash() + for (size_t i = 1; i < target_size; i++) + { + result_data[i] = crypto::cn_fast_hash(&result_data[i - 1], sizeof(result_data[i - 1])); + } + return true; + } +} + diff --git a/src/crypto/wild_keccak.h b/src/crypto/wild_keccak.h new file mode 100644 index 00000000..eb017aef --- /dev/null +++ b/src/crypto/wild_keccak.h @@ -0,0 +1,284 @@ +// keccak.h +// 19-Nov-11 Markku-Juhani O. Saarinen + +// Copyright (c) 2014 The Boolberry developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + + +#pragma once + +#include +#include +#include "crypto.h" + +extern "C" { +//#include "crypto/alt/KeccakNISTInterface.h" + } + +#ifndef KECCAK_ROUNDS +#define KECCAK_ROUNDS 24 +#endif + +#ifndef ROTL64 +#define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y)))) +#endif + + +#define KK_MIXIN_SIZE 24 + +namespace crypto +{ +#define OPT_XOR_4_RES(A_, B_, C_, D_, Res) \ + crypto::hash A = A_;crypto::hash B = B_;crypto::hash C = C_; crypto::hash D = D_; \ + ((uint64_t*)&Res)[0] = ((const uint64_t*)&A)[0] ^ ((const uint64_t*)&B)[0] ^ ((const uint64_t*)&C)[0] ^ ((const uint64_t*)&D)[0]; \ + ((uint64_t*)&Res)[1] = ((const uint64_t*)&A)[1] ^ ((const uint64_t*)&B)[1] ^ ((const uint64_t*)&C)[1] ^ ((const uint64_t*)&D)[1]; \ + ((uint64_t*)&Res)[2] = ((const uint64_t*)&A)[2] ^ ((const uint64_t*)&B)[2] ^ ((const uint64_t*)&C)[2] ^ ((const uint64_t*)&D)[2]; \ + ((uint64_t*)&Res)[3] = ((const uint64_t*)&A)[3] ^ ((const uint64_t*)&B)[3] ^ ((const uint64_t*)&C)[3] ^ ((const uint64_t*)&D)[3]; + + + typedef uint64_t state_t_m[25]; + typedef uint64_t mixin_t[KK_MIXIN_SIZE]; + + //with multiplication, for tests + template + int keccak_generic(const uint8_t *in, size_t inlen, uint8_t *md, size_t mdlen) + { + state_t_m st; + uint8_t temp[144]; + size_t i, rsiz, rsizw; + + rsiz = sizeof(state_t_m) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen; + rsizw = rsiz / 8; + + memset(st, 0, sizeof(st)); + + for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) { + for (i = 0; i < rsizw; i++) + st[i] ^= ((uint64_t *) in)[i]; + f_traits::keccakf(st, KECCAK_ROUNDS); + } + + + // last block and padding + memcpy(temp, in, inlen); + temp[inlen++] = 1; + memset(temp + inlen, 0, rsiz - inlen); + temp[rsiz - 1] |= 0x80; + + for (i = 0; i < rsizw; i++) + st[i] ^= ((uint64_t *) temp)[i]; + + f_traits::keccakf(st, KECCAK_ROUNDS); + + memcpy(md, st, mdlen); + + return 0; + } + /*inline + void print_state(UINT64* state, const char* comment, size_t rount) + { + printf("master_funct: %s round: %d\r\n", comment, rount); + int i; + for(i = 0; i != 25; i++) + { + printf("[%i]: %p\r\n", i, state[i]); + } + }*/ + + template + int wild_keccak(const uint8_t *in, size_t inlen, uint8_t *md, size_t mdlen, callback_t cb) + { + state_t_m st; + uint8_t temp[144]; + uint64_t rsiz, rsizw; + + rsiz = sizeof(state_t_m) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen; + rsizw = rsiz / 8; + memset(&st[0], 0, 25*sizeof(st[0])); + + + for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) + { + for (size_t i = 0; i < rsizw; i++) + st[i] ^= ((uint64_t *) in)[i]; + + for(size_t ll = 0; ll != KECCAK_ROUNDS; ll++) + { + if(ll != 0) + {//skip first round + mixin_t mix_in; + cb(st, mix_in); + for (size_t k = 0; k < KK_MIXIN_SIZE; k++) + st[k] ^= mix_in[k]; + } + //print_state(&st[0], "before_permut", ll); + f_traits::keccakf(st, 1); + //print_state(&st[0], "after_permut", ll); + } + } + + // last block and padding + memcpy(temp, in, inlen); + temp[inlen++] = 1; + memset(temp + inlen, 0, rsiz - inlen); + temp[rsiz - 1] |= 0x80; + + for (size_t i = 0; i < rsizw; i++) + st[i] ^= ((uint64_t *) temp)[i]; + + for(size_t ll = 0; ll != KECCAK_ROUNDS; ll++) + { + if(ll != 0) + {//skip first state with + mixin_t mix_in; + cb(st, mix_in); + for (size_t k = 0; k < KK_MIXIN_SIZE; k++) + st[k] ^= mix_in[k]; + } + f_traits::keccakf(st, 1); + } + + memcpy(md, st, mdlen); + + return 0; + } + + template + int wild_keccak2(const uint8_t *in, size_t inlen, uint8_t *md, size_t mdlen, callback_t cb) + { + state_t_m st; + uint8_t temp[144]; + uint64_t rsiz, rsizw; + + rsiz = sizeof(state_t_m) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen; + rsizw = rsiz / 8; + memset(&st[0], 0, 25 * sizeof(st[0])); + + + for (; inlen >= rsiz; inlen -= rsiz, in += rsiz) + { + for (size_t i = 0; i < rsizw; i++) + st[i] ^= ((uint64_t *)in)[i]; + + for (int keccak_round = 0; keccak_round != KECCAK_ROUNDS; keccak_round++) + { + f_traits::keccakf(st, keccak_round); + cb(st); + } + } + + // last block and padding + memcpy(temp, in, inlen); + temp[inlen++] = 1; + memset(temp + inlen, 0, rsiz - inlen); + temp[rsiz - 1] |= 0x80; + + for (size_t i = 0; i < rsizw; i++) + st[i] ^= ((uint64_t *)temp)[i]; + + for (int keccak_round = 0; keccak_round != KECCAK_ROUNDS; keccak_round++) + { + f_traits::keccakf(st, keccak_round); + cb(st); + } + + memcpy(md, st, mdlen); + + return 0; + } + + template + int wild_keccak_dbl(const uint8_t *in, size_t inlen, uint8_t *md, size_t mdlen, callback_t cb) + { + //Satoshi's classic + wild_keccak(in, inlen, md, mdlen, cb); + wild_keccak(md, mdlen, md, mdlen, cb); + return 0; + } + + template + int wild_keccak2_dbl(const uint8_t *in, size_t inlen, uint8_t *md, size_t mdlen, callback_t cb) + { + //Satoshi's classic + wild_keccak2(in, inlen, md, mdlen, cb); + wild_keccak2(md, mdlen, md, mdlen, cb); + return 0; + } + + class regular_f + { + public: + static void keccakf(uint64_t st[25], int rounds); + }; + + class mul_f + { + public: + static void keccakf(uint64_t st[25], int rounds); + }; + + //------------------------------------------------------------------ + inline + bool get_wild_keccak2(const std::string& bd, crypto::hash& res, const std::vector& scratchpad, uint64_t sz) + { + crypto::wild_keccak2_dbl(reinterpret_cast(bd.data()), bd.size(), reinterpret_cast(&res), sizeof(res), [&](crypto::state_t_m& st) + { + if (!sz) + { + return; + } + + const uint64_t* int_array_ptr = (const uint64_t*)&scratchpad[0]; + size_t int64_sz = sz * 4; + + for (size_t i = 0; i != sizeof(st) / sizeof(st[0]); i++) + { + size_t depend_index = 0; + if (i == 0) + { + depend_index = sizeof(st) / sizeof(st[0]) - 1; + } + else + { + depend_index = i - 1; + } + st[i] ^= int_array_ptr[ int_array_ptr[ int_array_ptr[st[depend_index] % int64_sz] % int64_sz] % int64_sz]; + } + }); + return true; + } + //------------------------------------------------------------------ + inline + bool get_wild_keccak2(const std::string& bd, crypto::hash& res, const std::vector& scratchpad) + { + return get_wild_keccak2(bd, res, scratchpad, scratchpad.size()); + } + //------------------------------------------------------------------ + inline + bool get_wild_keccak(const std::string& bd, crypto::hash& res, uint64_t height, const std::vector& scratchpad, uint64_t sz) + { + crypto::wild_keccak_dbl(reinterpret_cast(bd.data()), bd.size(), reinterpret_cast(&res), sizeof(res), [&](crypto::state_t_m& st, crypto::mixin_t& mix) + { + if (!height) + { + memset(&mix, 0, sizeof(mix)); + return; + } + +#define OPT_GET_H(index) scratchpad[st[index]%sz] +#define OPT_GET_M(index) scratchpad[mix[index]%sz] + + for (size_t i = 0; i != 6; i++) + { + OPT_XOR_4_RES(OPT_GET_H(i * 4), OPT_GET_H(i * 4 + 1), OPT_GET_H(i * 4 + 2), OPT_GET_H(i * 4 + 3), (*(crypto::hash*)&mix[i * 4])); + } + }); + return true; + } + //------------------------------------------------------------------ + bool generate_scratchpad(const crypto::hash& source_data, std::vector& result_data, uint64_t target_size); + + +} + diff --git a/src/crypto/wild_keccak2.cpp b/src/crypto/wild_keccak2.cpp deleted file mode 100644 index ecf4b7ea..00000000 --- a/src/crypto/wild_keccak2.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// keccak.c -// 19-Nov-11 Markku-Juhani O. Saarinen -// A baseline Keccak (3rd round) implementation. - -// Memory-hard extension of keccak for PoW -// Copyright (c) 2014 The Boolberry developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - - -#include "wild_keccak.h" -namespace crypto -{ - - const uint64_t keccakf_rndc[24] = - { - 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, - 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, - 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, - 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, - 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, - 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, - 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, - 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 - }; - - const int keccakf_rotc[24] = - { - 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, - 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 - }; - - const int keccakf_piln[24] = - { - 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, - 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 - }; - - // update the state with given number of rounds - void regular_f::keccakf2(uint64_t st[25], int round_index) - { - int i, j, round; - uint64_t t, bc[5]; - - - // Theta - for (i = 0; i < 5; i++) - bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] ^ st[i + 15] ^ st[i + 20]; - - for (i = 0; i < 5; i++) { - t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); - for (j = 0; j < 25; j += 5) - st[j + i] ^= t; - } - - // Rho Pi - t = st[1]; - for (i = 0; i < 24; i++) { - j = keccakf_piln[i]; - bc[0] = st[j]; - st[j] = ROTL64(t, keccakf_rotc[i]); - t = bc[0]; - } - - // Chi - for (j = 0; j < 25; j += 5) { - for (i = 0; i < 5; i++) - bc[i] = st[j + i]; - for (i = 0; i < 5; i++) - st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5]; - } - - // Iota - st[0] ^= keccakf_rndc[round_index]; - } -} \ No newline at end of file diff --git a/src/crypto/wild_keccak2.h b/src/crypto/wild_keccak2.h deleted file mode 100644 index 2e8dbc8d..00000000 --- a/src/crypto/wild_keccak2.h +++ /dev/null @@ -1,149 +0,0 @@ -// keccak.h -// 19-Nov-11 Markku-Juhani O. Saarinen - -// Copyright (c) 2014 The Boolberry developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - - -#pragma once - -#include -#include -#include "crypto.h" - -extern "C" { -#include "crypto/alt/KeccakNISTInterface.h" - } - -#ifndef KECCAK_ROUNDS -#define KECCAK_ROUNDS 24 -#endif - -#ifndef ROTL64 -#define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y)))) -#endif - -// compute a keccak hash (md) of given byte length from "in" - -#define KK_MIXIN_SIZE 24 - -namespace crypto -{ - -inline -// void wild_keccak_dbl_opt(const uint8_t *in, size_t inlen, uint8_t *md, size_t mdlen, const UINT64* pscr, UINT64 scr_sz) -// { -// Hash(256, in, inlen*8, md, pscr, scr_sz); -// Hash(256, md, mdlen*8, md, pscr, scr_sz); -// } - - - template - pod_operand_a xor_pod(const pod_operand_a& a, const pod_operand_b& b) - { - static_assert(sizeof(pod_operand_a) == sizeof(pod_operand_b), "invalid xor_h usage: different sizes"); - static_assert(sizeof(pod_operand_a)%8 == 0, "invalid xor_h usage: wrong size"); - - hash r; - for(size_t i = 0; i != 4; i++) - { - ((uint64_t*)&r)[i] = ((const uint64_t*)&a)[i] ^ ((const uint64_t*)&b)[i]; - } - return r; - } - -#define XOR_2(A, B) crypto::xor_pod(A, B) -#define XOR_3(A, B, C) crypto::xor_pod(A, XOR_2(B, C)) -#define XOR_4(A, B, C, D) crypto::xor_pod(A, XOR_3(B, C, D)) -#define XOR_5(A, B, C, D, E) crypto::xor_pod(A, XOR_4(B, C, D, E)) -#define XOR_8(A, B, C, D, F, G, H, I) crypto::xor_pod(XOR_4(A, B, C, D), XOR_4(F, G, H, I)) - - - - - typedef uint64_t state_t_m[25]; - typedef uint64_t mixin_t[KK_MIXIN_SIZE]; - - - template - int wild_keccak2(const uint8_t *in, size_t inlen, uint8_t *md, size_t mdlen, callback_t cb) - { - state_t_m st; - uint8_t temp[144]; - uint64_t rsiz, rsizw; - - rsiz = sizeof(state_t_m) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen; - rsizw = rsiz / 8; - memset(&st[0], 0, 25*sizeof(st[0])); - - - for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) - { - for (size_t i = 0; i < rsizw; i++) - st[i] ^= ((uint64_t *) in)[i]; - - for(size_t keccak_round = 0; keccak_round != KECCAK_ROUNDS; keccak_round++) - { - if(keccak_round != 0) - {//skip first round - mixin_t mix_in; - cb(st, mix_in); - for (size_t k = 0; k < KK_MIXIN_SIZE; k++) - st[k] ^= mix_in[k]; - } - //print_state(&st[0], "before_permut", ll); - f_traits::keccakf(st, 1); - //print_state(&st[0], "after_permut", ll); - } - } - - // last block and padding - memcpy(temp, in, inlen); - temp[inlen++] = 1; - memset(temp + inlen, 0, rsiz - inlen); - temp[rsiz - 1] |= 0x80; - - for (size_t i = 0; i < rsizw; i++) - st[i] ^= ((uint64_t *) temp)[i]; - - for(size_t keccak_round = 0; keccak_round != KECCAK_ROUNDS; keccak_round++) - { - if(keccak_round != 0) - {//skip first state with - mixin_t mix_in; - cb(st, mix_in); - for (size_t k = 0; k < KK_MIXIN_SIZE; k++) - st[k] ^= mix_in[k]; - } - f_traits::keccakf(st, 1); - } - - memcpy(md, st, mdlen); - - return 0; - } - - - template - int wild_keccak2_dbl(const uint8_t *in, size_t inlen, uint8_t *md, size_t mdlen, crypto::hash* pscratchpad, uint64_t sz) - { - //Satoshi's classic - regular_f::wild_keccak2(in, inlen, md, mdlen, cb); - regular_f::wild_keccak2(md, mdlen, md, mdlen, cb); - return 0; - } - - class regular_f - { - public: - static void keccakf(uint64_t st[25], int rounds); - }; -// -// class mul_f -// { -// public: -// static void keccakf(uint64_t st[25], int rounds); -// }; -} - diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 40032deb..5775b2bc 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -98,13 +98,20 @@ blockchain_storage::blockchain_storage(tx_memory_pool& tx_pool) :m_db(std::share m_interprocess_locker_file(0), m_current_fee_median(0), m_current_fee_median_effective_index(0), - m_is_reorganize_in_process(false) + m_is_reorganize_in_process(false), + m_deinit_is_done(false) { m_services_mgr.set_core_runtime_config(m_core_runtime_config); m_performance_data.epic_failure_happend = false; } +blockchain_storage::~blockchain_storage() +{ + if (!m_deinit_is_done) + deinit(); + +} //------------------------------------------------------------------ bool blockchain_storage::have_tx(const crypto::hash &id) const { @@ -264,7 +271,6 @@ bool blockchain_storage::init(const std::string& config_folder, const boost::pro if (m_db_storage_minor_compatibility_version < 1) need_reinit_medians = true; } - if (need_reinit) { clear(); @@ -316,6 +322,7 @@ bool blockchain_storage::deinit() { m_db.close(); epee::file_io_utils::unlock_and_close_file(m_interprocess_locker_file); + m_deinit_is_done = true; return true; } //------------------------------------------------------------------ @@ -1100,16 +1107,16 @@ uint64_t blockchain_storage::get_current_comulative_blocksize_limit() const return m_db_current_block_cumul_sz_limit; } //------------------------------------------------------------------ -bool blockchain_storage::create_block_template(block& b, +bool blockchain_storage::create_block_template(block& b, crypto::hash& seed, const account_public_address& miner_address, wide_difficulty_type& diffic, uint64_t& height, const blobdata& ex_nonce) const { - return create_block_template(b, miner_address, miner_address, diffic, height, ex_nonce, false, pos_entry()); + return create_block_template(b, seed, miner_address, miner_address, diffic, height, ex_nonce, false, pos_entry()); } //------------------------------------------------------------------ -bool blockchain_storage::create_block_template(block& b, +bool blockchain_storage::create_block_template(block& b, crypto::hash& seed, const account_public_address& miner_address, const account_public_address& stakeholder_address, wide_difficulty_type& diffic, @@ -1119,6 +1126,7 @@ bool blockchain_storage::create_block_template(block& b, const pos_entry& pe, fill_block_template_func_t custom_fill_block_template_func /* = nullptr */) const { + seed = m_current_scratchpad_seed; size_t median_size; uint64_t already_generated_coins; CRITICAL_REGION_BEGIN(m_read_lock); @@ -1320,6 +1328,7 @@ bool blockchain_storage::purge_altblock_keyimages_from_big_heap(const block& b, } return true; } + //------------------------------------------------------------------ bool blockchain_storage::handle_alternative_block(const block& b, const crypto::hash& id, block_verification_context& bvc) { @@ -1347,15 +1356,24 @@ bool blockchain_storage::handle_alternative_block(const block& b, const crypto:: alt_chain_type alt_chain; { //we have new block in alternative chain - //build alternative subchain, front -> mainchain, back -> alternative head + //build alternative subchain, front -> mainchain, back -> alternative head alt_chain_container::iterator alt_it = it_prev; //m_alternative_chains.find() std::vector timestamps; + std::list temp_container; while (alt_it != m_alternative_chains.end()) { - alt_chain.push_front(alt_it); + temp_container.push_front(alt_it); timestamps.push_back(alt_it->second.bl.timestamp); alt_it = m_alternative_chains.find(alt_it->second.bl.prev_id); } + //TODO: refactoring needed: vector push_front is dramatically ineffective + alt_chain.resize(temp_container.size()); + auto it_vec = alt_chain.begin(); + for (auto it = temp_container.begin(); it != temp_container.end();it++, it_vec++) + { + *it_vec = *it; + } + if (alt_chain.size()) { @@ -1433,7 +1451,11 @@ bool blockchain_storage::handle_alternative_block(const block& b, const crypto:: } else { - proof_of_work = get_block_longhash(abei.bl); + crypto::hash seed = null_hash; + get_seed_for_scratchpad_alt_chain(abei.height, seed, alt_chain); + + proof_of_work = m_scratchpad.get_pow_hash(abei.bl, seed); + if (!check_hash(proof_of_work, current_diff)) { LOG_PRINT_RED_L0("Block with id: " << id @@ -1585,9 +1607,8 @@ bool blockchain_storage::pre_validate_relayed_block(block& bl, block_verificatio bvc.m_added_to_main_chain = true; } else - { - - proof_hash = get_block_longhash(bl); + { + proof_hash = m_scratchpad.get_pow_hash(bl, m_current_scratchpad_seed); //get_block_longhash(bl); if (!check_hash(proof_hash, current_diffic)) { @@ -4226,9 +4247,8 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt << "expected: " << get_top_block_id()); return false; } -#ifdef _DEBUG + uint64_t h = get_block_height(bl); -#endif// _DEBUG if(!check_block_timestamp_main(bl)) { @@ -4273,7 +4293,12 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt } else { - proof_hash = get_block_longhash(bl); + //++++++++++++++++++++++++++++++++++++++++++++++++++++++ + //precaution(do we really need this check?) + check_scratchpad(); + //++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + proof_hash = m_scratchpad.get_pow_hash(bl, m_current_scratchpad_seed); if (!check_hash(proof_hash, current_diffic)) { @@ -4541,17 +4566,27 @@ void blockchain_storage::on_block_added(const block_extended_info& bei, const cr { update_next_comulative_size_limit(); m_timestamps_median_cache.clear(); - + check_scratchpad(); m_tx_pool.on_blockchain_inc(bei.height, id); TIME_MEASURE_START_PD(raise_block_core_event); rise_core_event(CORE_EVENT_BLOCK_ADDED, void_struct()); TIME_MEASURE_FINISH_PD(raise_block_core_event); } +//------------------------------------------------------------------ + bool blockchain_storage::check_scratchpad() +{ + if (get_scratchpad_size_for_height(m_db_blocks.size()) != m_scratchpad.size()) + { + get_seed_for_scratchpad(m_db_blocks.size(), m_current_scratchpad_seed); + } + return true; +} //------------------------------------------------------------------ void blockchain_storage::on_block_removed(const block_extended_info& bei) { m_tx_pool.on_blockchain_dec(m_db_blocks.size() - 1, get_top_block_id()); m_timestamps_median_cache.clear(); + check_scratchpad(); LOG_PRINT_L2("block at height " << bei.height << " was removed from the blockchain"); } //------------------------------------------------------------------ @@ -5285,6 +5320,41 @@ bool blockchain_storage::validate_alt_block_ms_input(const transaction& input_tx return false; } //------------------------------------------------------------------ +bool blockchain_storage::get_seed_for_scratchpad(uint64_t height, crypto::hash& seed)const +{ + CRITICAL_REGION_LOCAL(m_read_lock); + return get_seed_for_scratchpad_cb(height, seed, [&](uint64_t index) -> crypto::hash + { + return get_block_hash(m_db_blocks[index]->bl); + }); +} +//------------------------------------------------------------------ +bool blockchain_storage::get_seed_for_scratchpad_alt_chain(uint64_t height, crypto::hash& seed, const alt_chain_type& alt_chain)const +{ + CRITICAL_REGION_LOCAL(m_read_lock); + //alt_chain: front -> mainchain, back -> alternative head + uint64_t connection_to_main_chain = height; + if (alt_chain.size()) + connection_to_main_chain = alt_chain.front()->second.height; + + return get_seed_for_scratchpad_cb(height, seed, [&](uint64_t index) -> crypto::hash + { + if (index < connection_to_main_chain) + { + //addressed to main chain + return get_block_hash(m_db_blocks[index]->bl); + } + else + { + //addressed to alt chain + uint64_t offset = index - connection_to_main_chain; + CHECK_AND_ASSERT_THROW_MES(offset < alt_chain.size(), "Internal error: failed to validate offset(" << offset << ") < alt_chain.size()("<< alt_chain.size() <<")"); + CHECK_AND_ASSERT_THROW_MES(alt_chain[offset]->second.height == index, "Internal error: failed to validate offset(" << offset << ") < alt_chain.size()(" << alt_chain.size() << ")"); + return get_block_hash(alt_chain[offset]->second.bl); + } + }); +} +//------------------------------------------------------------------ bool blockchain_storage::get_transaction_from_pool_or_db(const crypto::hash& tx_id, std::shared_ptr& tx_ptr, uint64_t min_allowed_block_height /* = 0 */) const { tx_ptr.reset(new transaction()); diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index 93b32816..31ce5b67 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -39,6 +39,7 @@ #include "dispatch_core_events.h" #include "bc_attachments_service_manager.h" #include "common/median_db_cache.h" +#include "scratchpad_helper.h" MARK_AS_POD_C11(crypto::key_image); @@ -151,7 +152,8 @@ namespace currency std::map > outputs_pub_keys; }; typedef std::unordered_map alt_chain_container; - typedef std::list alt_chain_type; + //typedef std::list alt_chain_type; + typedef std::vector alt_chain_type; typedef std::unordered_map blocks_ext_by_hash; @@ -163,6 +165,7 @@ namespace currency //--------------------------------------------------------------------------------- blockchain_storage(tx_memory_pool& tx_pool); + ~blockchain_storage(); bool init(const boost::program_options::variables_map& vm) { return init(tools::get_default_data_dir(), vm); } @@ -228,8 +231,8 @@ namespace currency wide_difficulty_type get_cached_next_difficulty(bool pos) const; typedef bool fill_block_template_func_t(block &bl, bool pos, size_t median_size, uint64_t already_generated_coins, size_t &total_size, uint64_t &fee, uint64_t height); - bool create_block_template(block& b, const account_public_address& miner_address, const account_public_address& stakeholder_address, wide_difficulty_type& di, uint64_t& height, const blobdata& ex_nonce, bool pos, const pos_entry& pe, fill_block_template_func_t custom_fill_block_template_func = nullptr) const; - bool create_block_template(block& b, const account_public_address& miner_address, wide_difficulty_type& di, uint64_t& height, const blobdata& ex_nonce) const; + bool create_block_template(block& b, crypto::hash& seed, const account_public_address& miner_address, const account_public_address& stakeholder_address, wide_difficulty_type& di, uint64_t& height, const blobdata& ex_nonce, bool pos, const pos_entry& pe, fill_block_template_func_t custom_fill_block_template_func = nullptr) const; + bool create_block_template(block& b, crypto::hash& seed, const account_public_address& miner_address, wide_difficulty_type& di, uint64_t& height, const blobdata& ex_nonce) const; bool have_block(const crypto::hash& id) const; size_t get_total_transactions()const; @@ -508,6 +511,9 @@ namespace currency mutable uint64_t m_current_fee_median; mutable uint64_t m_current_fee_median_effective_index; bool m_is_reorganize_in_process; + mutable scratchpad_keeper m_scratchpad; + crypto::hash m_current_scratchpad_seed; + mutable std::atomic m_deinit_is_done; bool init_tx_fee_median(); @@ -535,6 +541,10 @@ namespace currency bool validate_alt_block_txs(const block& b, const crypto::hash& id, std::set& collected_keyimages, alt_block_extended_info& abei, const alt_chain_type& alt_chain, uint64_t split_height, uint64_t& ki_lookup_time_total) const; bool update_alt_out_indexes_for_tx_in_block(const transaction& tx, alt_block_extended_info& abei)const; bool get_transaction_from_pool_or_db(const crypto::hash& tx_id, std::shared_ptr& tx_ptr, uint64_t min_allowed_block_height = 0) const; + bool get_seed_for_scratchpad(uint64_t height, crypto::hash& seed)const ; + bool get_seed_for_scratchpad_alt_chain(uint64_t height, crypto::hash& seed, const alt_chain_type& alt_chain) const ; + + bool check_scratchpad(); bool prevalidate_miner_transaction(const block& b, uint64_t height, bool pos)const; bool validate_transaction(const block& b, uint64_t height, const transaction& tx)const; diff --git a/src/currency_core/connection_context.h b/src/currency_core/connection_context.h index 27c54cf7..6c242cc1 100644 --- a/src/currency_core/connection_context.h +++ b/src/currency_core/connection_context.h @@ -32,7 +32,6 @@ namespace currency //members that supposed to be accessed only from one thread std::list m_needed_objects; std::unordered_set m_requested_objects; - std::string m_remote_version; std::atomic m_callback_request_count; //in debug purpose: problem with double callback rise }; @@ -51,6 +50,7 @@ namespace currency uint64_t m_remote_blockchain_height; uint64_t m_last_response_height; int64_t m_time_delta; + std::string m_remote_version; private: template friend class t_currency_protocol_handler; uncopybale_currency_context m_priv; diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index 5cabbf25..27d5adc7 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -8,7 +8,7 @@ #pragma once -#define CURRENCY_FORMATION_VERSION 74 +#define CURRENCY_FORMATION_VERSION 75 #define CURRENCY_MAX_BLOCK_NUMBER 500000000 @@ -40,19 +40,29 @@ #define CURRENCY_COINBASE_BLOB_RESERVED_SIZE 1100 #define CURRENCY_MAX_TRANSACTION_BLOB_SIZE (CURRENCY_BLOCK_GRANTED_FULL_REWARD_ZONE - CURRENCY_COINBASE_BLOB_RESERVED_SIZE*2) #define CURRENCY_FREE_TX_MAX_BLOB_SIZE 1024 // soft txpool-based limit for free-of-charge txs (such as BC_OFFERS_SERVICE_INSTRUCTION_DEL) -#define CURRENCY_DISPLAY_DECIMAL_POINT 8 +#define CURRENCY_DISPLAY_DECIMAL_POINT 12 // COIN - number of smallest units in one coin -#define COIN ((uint64_t)100000000) // pow(10, CURRENCY_DISPLAY_DECIMAL_POINT) +#define COIN ((uint64_t)1000000000000) // pow(10, CURRENCY_DISPLAY_DECIMAL_POINT) #define BASE_REWARD_DUST_THRESHOLD ((uint64_t)1000000) // pow(10, 6) - change this will cause hard-fork! #define DEFAULT_DUST_THRESHOLD ((uint64_t)0)//((uint64_t)100000) // pow(10, 5) +//#define CURRENCY_SCRATCHPAD_BASE_SIZE 16777216 //count in crypto::hash, to get size in bytes x32 +#define CURRENCY_SCRATCHPAD_BASE_SIZE 167 //count in crypto::hash, to get size in bytes x32 +#define CURRENCY_SCRATCHPAD_REBUILD_INTERVAL 720 //once a day if block goes once in 2 minute +#define CURRENCY_SCRATCHPAD_BASE_INDEX_ID_OFFSET 20 //offset down from last rebuild height to block id, that used for indexing seed blocks in CURRENCY_SCRATCHPAD_SEED_BLOCKS_WINDOW +#define CURRENCY_SCRATCHPAD_SEED_BLOCKS_WINDOW 700 //window for addressing seed block ids +#define CURRENCY_SCRATCHPAD_GENESIS_SEED "4c98962ddce32c7763bb9326933a4692975ca29a76349ae7a139faa3430cc5ab" + #define TX_DEFAULT_FEE ((uint64_t)100000) // pow(10, 5) #define TX_MINIMUM_FEE ((uint64_t)100000) // pow(10, 5) -#define CURRENCY_FIXED_REWARD_ZONE_HEIGHT 300 // blocks will have fixed reward up to this height (including) -#define CURRENCY_FIXED_REWARD_ZONE_REWARD_AMOUNT ((uint64_t)100000000) // should be TX_MINIMUM_FEE * CURRENCY_FIXED_REWARD_ZONE_FEE_MULTIPLIER -#define CURRENCY_FIXED_REWARD_ZONE_FEE_MULTIPLIER 1000 // reward in minimum fees for a block in the zone +// #define CURRENCY_FIXED_REWARD_ZONE_HEIGHT 300 // blocks will have fixed reward up to this height (including) +// #define CURRENCY_FIXED_REWARD_ZONE_REWARD_AMOUNT ((uint64_t)100000000) // should be TX_MINIMUM_FEE * CURRENCY_FIXED_REWARD_ZONE_FEE_MULTIPLIER +// #define CURRENCY_FIXED_REWARD_ZONE_FEE_MULTIPLIER 1000 // reward in minimum fees for a block in the zone + +#define CURRENCY_TESTNET_CONST_REWARD 1000000000 + #define WALLET_MAX_ALLOWED_OUTPUT_AMOUNT ((uint64_t)0xffffffffffffffffLL) #define CURRENCY_MINER_TX_MAX_OUTS CURRENCY_TX_MAX_ALLOWED_OUTS @@ -167,7 +177,7 @@ #endif //premine -#define PREMINE_AMOUNT (500000000000000) +#define PREMINE_AMOUNT (2000000000000000000) //alias registration wallet #define ALIAS_REWARDS_ACCOUNT_SPEND_PUB_KEY "0000000000000000000000000000000000000000000000000000000000000000" //burn alias money @@ -214,4 +224,4 @@ static_assert(CURRENCY_MINER_TX_MAX_OUTS <= CURRENCY_TX_MAX_ALLOWED_OUTS, "Miner tx must obey normal tx max outs limit"); static_assert(PREMINE_AMOUNT / WALLET_MAX_ALLOWED_OUTPUT_AMOUNT < CURRENCY_MINER_TX_MAX_OUTS, "Premine can't be divided into reasonable number of outs"); -static_assert(CURRENCY_FIXED_REWARD_ZONE_REWARD_AMOUNT == TX_MINIMUM_FEE * CURRENCY_FIXED_REWARD_ZONE_FEE_MULTIPLIER, "CURRENCY_FIXED_REWARD_ZONE_REWARD_AMOUNT is incorrect with regard to TX_MINIMUM_FEE"); +//static_assert(CURRENCY_FIXED_REWARD_ZONE_REWARD_AMOUNT == TX_MINIMUM_FEE * CURRENCY_FIXED_REWARD_ZONE_FEE_MULTIPLIER, "CURRENCY_FIXED_REWARD_ZONE_REWARD_AMOUNT is incorrect with regard to TX_MINIMUM_FEE"); diff --git a/src/currency_core/currency_core.cpp b/src/currency_core/currency_core.cpp index c4b785f4..555df8ae 100644 --- a/src/currency_core/currency_core.cpp +++ b/src/currency_core/currency_core.cpp @@ -401,9 +401,14 @@ namespace currency return m_mempool.add_tx(tx, tx_hash, blob_size, tvc, kept_by_block); } //----------------------------------------------------------------------------------------------- + bool core::get_block_template(block& b, crypto::hash& seed, const account_public_address& adr, const account_public_address& stakeholder_address, wide_difficulty_type& diffic, uint64_t& height, const blobdata& ex_nonce, bool pos, const pos_entry& pe) + { + return m_blockchain_storage.create_block_template(b, seed, adr, stakeholder_address, diffic, height, ex_nonce, pos, pe); + } bool core::get_block_template(block& b, const account_public_address& adr, const account_public_address& stakeholder_address, wide_difficulty_type& diffic, uint64_t& height, const blobdata& ex_nonce, bool pos, const pos_entry& pe) { - return m_blockchain_storage.create_block_template(b, adr, stakeholder_address, diffic, height, ex_nonce, pos, pe); + crypto::hash seed_subst = currency::null_hash; + return m_blockchain_storage.create_block_template(b, seed_subst, adr, stakeholder_address, diffic, height, ex_nonce, pos, pe); } //----------------------------------------------------------------------------------------------- bool core::find_blockchain_supplement(const std::list& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp) const diff --git a/src/currency_core/currency_core.h b/src/currency_core/currency_core.h index 294939e5..1f178268 100644 --- a/src/currency_core/currency_core.h +++ b/src/currency_core/currency_core.h @@ -15,11 +15,7 @@ #include "storages/portable_storage_template_helper.h" #include "tx_pool.h" #include "blockchain_storage.h" -#ifdef USE_OPENCL -#include "gpu_miner.h" -#else #include "miner.h" -#endif #include "connection_context.h" #include "currency_core/currency_stat_info.h" #include "warnings.h" @@ -55,13 +51,11 @@ namespace currency //-------------------- i_miner_handler ----------------------- virtual bool handle_block_found(const block& b, block_verification_context* p_verification_result = nullptr); - virtual bool get_block_template(block& b, const account_public_address& adr, const account_public_address& stakeholder_address, wide_difficulty_type& diffic, uint64_t& height, const blobdata& ex_nonce, bool pos = false, const pos_entry& pe = pos_entry()); + virtual bool get_block_template(block& b, crypto::hash& seed, const account_public_address& adr, const account_public_address& stakeholder_address, wide_difficulty_type& diffic, uint64_t& height, const blobdata& ex_nonce, bool pos = false, const pos_entry& pe = pos_entry()); + + bool get_block_template(block& b, const account_public_address& adr, const account_public_address& stakeholder_address, wide_difficulty_type& diffic, uint64_t& height, const blobdata& ex_nonce, bool pos = false, const pos_entry& pe = pos_entry()); -#ifdef USE_OPENCL - gpu_miner& get_miner(){return m_miner;} -#else miner& get_miner(){ return m_miner; } -#endif static void init_options(boost::program_options::options_description& desc); bool init(const boost::program_options::variables_map& vm); bool set_genesis_block(const block& b); @@ -145,11 +139,7 @@ namespace currency tx_memory_pool m_mempool; i_currency_protocol* m_pprotocol; critical_section m_incoming_tx_lock; -#ifdef USE_OPENCL - gpu_miner m_miner; -#else miner m_miner; -#endif account_public_address m_miner_address; std::string m_config_folder; currency_protocol_stub m_protocol_stub; diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 7154b402..a590a94a 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -1712,24 +1712,24 @@ namespace currency } return true; } - //-------------------------------------------------------------- - crypto::hash get_block_longhash(uint64_t height, const crypto::hash& block_long_ash, uint64_t nonce) - { - //TODO: add wild keccak 2 - return null_hash;//TODO; - } - //--------------------------------------------------------------- - void get_block_longhash(const block& b, crypto::hash& res) - { - //TODO: add wild keccak 2 - } - //--------------------------------------------------------------- - crypto::hash get_block_longhash(const block& b) - { - crypto::hash p = null_hash; - get_block_longhash(b, p); - return p; - } +// //-------------------------------------------------------------- +// crypto::hash get_block_longhash(uint64_t height, const crypto::hash& block_long_ash, uint64_t nonce) +// { +// //TODO: add wild keccak 2 +// return null_hash;//TODO; +// } +// //--------------------------------------------------------------- +// void get_block_longhash(const block& b, crypto::hash& res) +// { +// //TODO: add wild keccak 2 +// } +// //--------------------------------------------------------------- +// crypto::hash get_block_longhash(const block& b) +// { +// crypto::hash p = null_hash; +// get_block_longhash(b, p); +// return p; +// } //--------------------------------------------------------------- uint64_t get_alias_coast_from_fee(const std::string& alias, uint64_t median_fee) { @@ -2562,22 +2562,19 @@ namespace currency { if (!height) return PREMINE_AMOUNT; - - if (height <= CURRENCY_FIXED_REWARD_ZONE_HEIGHT) - return CURRENCY_FIXED_REWARD_ZONE_REWARD_AMOUNT; - - uint64_t reward = 0; - if (is_pos) - reward = already_generated_coins / EMISSION_POS_REWARD_DEVIDER; - else - reward = already_generated_coins / EMISSION_POW_REWARD_DEVIDER; - - //crop dust if it make sense - if (reward <= BASE_REWARD_DUST_THRESHOLD) - return reward; - - reward = reward - reward%BASE_REWARD_DUST_THRESHOLD; - return reward; + + return CURRENCY_TESTNET_CONST_REWARD; + } + //----------------------------------------------------------------------------------------------- + uint64_t get_scratchpad_last_update_rebuild_height(uint64_t h) + { + return h - (h%CURRENCY_SCRATCHPAD_REBUILD_INTERVAL); + } + //----------------------------------------------------------------------------------------------- + uint64_t get_scratchpad_size_for_height(uint64_t h) + { + //let's have ~256MB/year if block interval is 2 minutes + return CURRENCY_SCRATCHPAD_BASE_SIZE + get_scratchpad_last_update_rebuild_height(h)*32; } //----------------------------------------------------------------------------------------------- bool get_block_reward(bool is_pos, size_t median_size, size_t current_block_size, uint64_t already_generated_coins, uint64_t &reward, uint64_t height) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 8efc358d..c6c5d0bf 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -308,10 +308,13 @@ namespace currency bool check_inputs_types_supported(const transaction& tx); bool check_outs_valid(const transaction& tx); bool parse_amount(uint64_t& amount, const std::string& str_amount); + + - crypto::hash get_block_longhash(uint64_t h, const crypto::hash& block_long_ash, uint64_t nonce); - void get_block_longhash(const block& b, crypto::hash& res); - crypto::hash get_block_longhash(const block& b); +// crypto::hash get_block_longhash(uint64_t h, const crypto::hash& block_long_ash, uint64_t nonce); +// void get_block_longhash(const block& b, crypto::hash& res); +// crypto::hash get_block_longhash(const block& b); + bool unserialize_block_complete_entry(const COMMAND_RPC_GET_BLOCKS_FAST::response& serialized, COMMAND_RPC_GET_BLOCKS_DIRECT::response& unserialized); @@ -411,6 +414,8 @@ namespace currency size_t get_max_tx_size(); bool get_block_reward(bool is_pos, size_t median_size, size_t current_block_size, uint64_t already_generated_coins, uint64_t &reward, uint64_t height); uint64_t get_base_block_reward(bool is_pos, uint64_t already_generated_coins, uint64_t height); + uint64_t get_scratchpad_last_update_rebuild_height(uint64_t h); + uint64_t get_scratchpad_size_for_height(uint64_t h); bool is_payment_id_size_ok(const std::string& payment_id); std::string get_account_address_as_str(const account_public_address& addr); std::string get_account_address_and_payment_id_as_str(const account_public_address& addr, const std::string& payment_id); @@ -628,9 +633,41 @@ namespace currency } return false; } + //--------------------------------------------------------------- + template + bool get_seed_for_scratchpad_cb(uint64_t height, crypto::hash& seed, block_chain_accessor_t cb) + { + //CHECK_AND_ASSERT_THROW_MES(m_db_blocks.size() > height, "Internal error: m_db_blocks.size()=" << m_db_blocks.size() << " > height=" << height); + uint64_t last_upd_h = get_scratchpad_last_update_rebuild_height(height); + std::vector seed_data; + if (last_upd_h == 0) + { + crypto::hash genesis_seed = null_hash; + bool r = epee::string_tools::hex_to_pod(CURRENCY_SCRATCHPAD_GENESIS_SEED, genesis_seed); + CHECK_AND_ASSERT_THROW_MES(r, "Unable to parse CURRENCY_SCRATCHPAD_GENESIS_SEED " << CURRENCY_SCRATCHPAD_GENESIS_SEED); + LOG_PRINT_MAGENTA("[SCRATCHPAD] GENESIS SEED SELECTED: " << genesis_seed, LOG_LEVEL_1); + seed = genesis_seed; + return true; + } + uint64_t low_bound_window = 0; + CHECK_AND_ASSERT_THROW_MES(last_upd_h >= CURRENCY_SCRATCHPAD_SEED_BLOCKS_WINDOW, "Internal error: last_upd_h(" << last_upd_h << ") < CURRENCY_SCRATCHPAD_SEED_BLOCKS_WINDOW(" << CURRENCY_SCRATCHPAD_SEED_BLOCKS_WINDOW << ")"); + low_bound_window = last_upd_h - CURRENCY_SCRATCHPAD_SEED_BLOCKS_WINDOW; + crypto::hash selector_id = cb(last_upd_h - CURRENCY_SCRATCHPAD_BASE_INDEX_ID_OFFSET); + const uint64_t* pselectors = (const uint64_t*)&selector_id; + std::stringstream ss; + for (size_t i = 0; i != 4; i++) + { + seed_data.push_back(cb(low_bound_window + pselectors[i] % CURRENCY_SCRATCHPAD_SEED_BLOCKS_WINDOW)); + ss << "[" << std::setw(8) << std::hex << pselectors[i] << "->" << low_bound_window + pselectors[i] % CURRENCY_SCRATCHPAD_SEED_BLOCKS_WINDOW << "]" << seed_data.back() << ENDL; + } + seed = crypto::cn_fast_hash(&seed_data[0], sizeof(seed_data[0]) * seed_data.size()); + LOG_PRINT_MAGENTA("[SCRATCHPAD] SEED SELECTED: h = " << last_upd_h << ", selector: " << selector_id << ENDL << ss.str() << "SEED: " << seed, LOG_LEVEL_1); + + return true; + } //--------------------------------------------------------------- template bool get_object_hash(const t_object& o, crypto::hash& res) diff --git a/src/currency_core/genesis.cpp b/src/currency_core/genesis.cpp index c3457ffc..1ae251af 100644 --- a/src/currency_core/genesis.cpp +++ b/src/currency_core/genesis.cpp @@ -8,8 +8,7 @@ namespace currency { const genesis_tx_raw_data ggenesis_tx_raw = { { - 0xe980800500000101,0x4c8e410316deb183,0x05dd061422e91958,0x485eb197e544946e,0xd7140a7b5b9eb8de,0x808000ea57342851,0xd3530316deb183e9,0x3e9a1019308058c6,0x07729e9e4683aead,0xae8521fc934a1d79,0x80000bb75ba1dd6d,0x5b0316deb183e980,0x98baefe7be9750fe,0xa50ef15adc5af73a,0x5086ca4ebadb9e01,0x00a78f2f9069699e,0x0316deb183e98080,0xab49b3c9fa79c665,0xa7ff95caf24e03c0,0xc6633659b32c545e,0x5081ddf42a3e7cbd,0x16deb183e9808000,0x33f1751141376803,0x776c2649e24c29f8,0xa956f3ec171294b2,0x91e727347006cd50,0x8d9c4a02160800cd,0xa4cbac8dd1535e29,0xc1b12659d4ba40f8,0x1b830f7079e20e51,0x8917001563cc51fd,0x17750417bd8617c8,0x000a0e5ebd17ee6e }, + 0xd080800a00000101,0xd20302e3a2de8bd8,0xa4c656f120022dac,0x6e2f69c4efec713d,0x1dab067faa99d2b0,0x004bc2ed989554f5,0xe3a2de8bd8d08080,0x0c893e3c11110302,0x923c676c08c3b3da,0x9d5f9bab3c153f86,0xceec49611dbff8fa,0x8bd8d0808000a087,0xda75030302e3a2de,0x9c6c996e44fb4fa8,0x57da9b191a0ea5e5,0x8300d36ad5146cb0,0x808000f70b26fb7c,0x0302e3a2de8bd8d0,0x0d971710a6f965c0,0x712f15d0c23ca097,0xab0cccfcffca2772,0x4d79952b97b321f0,0xa2de8bd8d0808000,0x6e95a338730302e3,0x699ed30d4fe42200,0x44acb4ec1910cbae,0xac396ca4d07c6032,0xd8d08080007ca3ab,0xf16e0302e3a2de8b,0xa51960554838e739,0x9e49a3a3891d8589,0xfdec3d1c43ce6c6a,0x8000e9d451bab45d,0x02e3a2de8bd8d080,0x441f83683012d103,0xfe5af148188baa39,0x9a6f3f19372b9a63,0xa3af018f526dbcd0,0xde8bd8d0808000fa,0x3002d9a70302e3a2,0x9f8afd984e34d469,0xb839504b8be18512,0x9d6e2d8197e5347e,0xd0808000321a67f6,0x770302e3a2de8bd8,0x13c5c72e5040ae82,0xd3430b8a3a8b8f3e,0x345f656308d8200e,0x008b35ba6c7ac665,0xe3a2de8bd8d08080,0xf47aaa9ee2230302,0x8c75dbd4e43c096d,0xa8479951e6621d52,0x4614fba0a021d84d,0x7b8b69160d00fb3b,0xb9579673ea1bfcd6,0xe6caa4a7a54184fa,0xe460fcdea2efb79c,0x170015f4099060c6,0x627a17ad0517f176,0x4f17b84817ad0717,0x179de517114f17b9,0x000a0e9f2a177c9f }, { 0x00 } }; - } diff --git a/src/currency_core/genesis.h b/src/currency_core/genesis.h index 1f8875f4..3cd77089 100644 --- a/src/currency_core/genesis.h +++ b/src/currency_core/genesis.h @@ -11,7 +11,7 @@ namespace currency #pragma pack(push, 1) struct genesis_tx_raw_data { - uint64_t const v[33]; + uint64_t const v[63]; uint8_t const r[1]; }; #pragma pack(pop) diff --git a/src/currency_core/genesis_acc.cpp b/src/currency_core/genesis_acc.cpp index 82d2c50b..50460c4b 100644 --- a/src/currency_core/genesis_acc.cpp +++ b/src/currency_core/genesis_acc.cpp @@ -9,16 +9,22 @@ namespace currency { - const std::string ggenesis_tx_pub_key_str = "024a9c8d295e53d18daccba4f840bad45926b1c1510ee279700f831bfd51cc63"; + const std::string ggenesis_tx_pub_key_str = "698b7bd6fc1bea739657b9fa8441a5a7a4cae69cb7efa2defc60e4c6609009f4"; const crypto::public_key ggenesis_tx_pub_key = epee::string_tools::parse_tpod_from_hex_string(ggenesis_tx_pub_key_str); - - const genesis_tx_dictionary_entry ggenesis_dict[5] = { - { 785828676124507135ULL,1 }, - { 1231353406545874119ULL,4 }, - { 2713905913089194270ULL,3 }, - { 3738391252528226312ULL,0 }, - { 11261277230714331250ULL,2 } + + const genesis_tx_dictionary_entry ggenesis_dict[10] = { + { 690562910953636312ULL,5 }, + { 940036618224342135ULL,3 }, + { 1343336992873709805ULL,9 }, + { 2417587344126263675ULL,7 }, + { 2976852013260878279ULL,8 }, + { 9662281438621735689ULL,4 }, + { 14708441932961059072ULL,6 }, + { 15678994962012632719ULL,1 }, + { 17191212896741366274ULL,2 }, + { 18291644074790683797ULL,0 } }; + } diff --git a/src/currency_core/genesis_acc.h b/src/currency_core/genesis_acc.h index ec6ff29d..49af5cce 100644 --- a/src/currency_core/genesis_acc.h +++ b/src/currency_core/genesis_acc.h @@ -24,7 +24,7 @@ namespace currency } }; #pragma pack(pop) - extern const genesis_tx_dictionary_entry ggenesis_dict[5]; + extern const genesis_tx_dictionary_entry ggenesis_dict[10]; extern const crypto::public_key ggenesis_tx_pub_key; diff --git a/src/currency_core/miner.cpp b/src/currency_core/miner.cpp index 5d32c6fe..0d0df760 100644 --- a/src/currency_core/miner.cpp +++ b/src/currency_core/miner.cpp @@ -72,6 +72,7 @@ namespace currency m_height = height; ++m_template_no; m_starter_nonce = crypto::rand(); + m_scratchpad.generate(m_seed, height); return true; } //----------------------------------------------------------------------------------------------------- @@ -94,7 +95,7 @@ namespace currency { extra_nonce += std::string("|") + m_extra_messages[m_config.current_extra_message_index]; } - if(!m_phandler->get_block_template(bl, m_mine_address, m_mine_address, di, height, extra_nonce)) + if(!m_phandler->get_block_template(bl, m_seed, m_mine_address, m_mine_address, di, height, extra_nonce)) { LOG_ERROR("Failed to get_block_template()"); return false; @@ -305,6 +306,8 @@ namespace currency uint64_t nonce = m_starter_nonce + th_local_index; wide_difficulty_type local_diff = 0; uint32_t local_template_ver = 0; + blobdata local_blob_data; + //uint64_t local_template_height = 0; block b; @@ -325,6 +328,7 @@ namespace currency //local_template_height = get_block_height(b); local_template_ver = m_template_no; nonce = m_starter_nonce + th_local_index; + local_blob_data = get_block_hashing_blob(b); } if(!local_template_ver)//no any set_block_template call @@ -334,7 +338,8 @@ namespace currency continue; } b.nonce = nonce; - crypto::hash h = get_block_longhash(b); + access_nonce_in_block_blob(local_blob_data) = b.nonce; + crypto::hash h = m_scratchpad.get_pow_hash(local_blob_data, m_height, m_seed); if(check_hash(h, local_diff)) { diff --git a/src/currency_core/miner.h b/src/currency_core/miner.h index c1955684..4087f26b 100644 --- a/src/currency_core/miner.h +++ b/src/currency_core/miner.h @@ -33,7 +33,7 @@ namespace currency struct i_miner_handler { virtual bool handle_block_found(const block& b, block_verification_context* p_verification_result = nullptr) = 0; - virtual bool get_block_template(block& b, const account_public_address& adr, const account_public_address& stakeholder_address, wide_difficulty_type& diffic, uint64_t& height, const blobdata& ex_nonce, bool pos = false, const pos_entry& pe = pos_entry()) = 0; + virtual bool get_block_template(block& b, crypto::hash& seed, const account_public_address& adr, const account_public_address& stakeholder_address, wide_difficulty_type& diffic, uint64_t& height, const blobdata& ex_nonce, bool pos = false, const pos_entry& pe = pos_entry()) = 0; protected: ~i_miner_handler(){}; }; @@ -63,15 +63,17 @@ namespace currency void do_print_hashrate(bool do_hr); inline - static bool find_nonce_for_given_block(block& bl, const wide_difficulty_type& diffic, uint64_t height) - { + static bool find_nonce_for_given_block(block& bl, const wide_difficulty_type& diffic, uint64_t height, const crypto::hash& seed, scratchpad_keeper& sk) + { blobdata bd = get_block_hashing_blob(bl); - access_nonce_in_block_blob(bd) = 0; - crypto::hash bl_hash = crypto::cn_fast_hash(bd.data(), bd.size()); + uint64_t& nonce_ref = access_nonce_in_block_blob(bd); + nonce_ref = 0; - for(; bl.nonce != std::numeric_limits::max(); bl.nonce++) + for(; bl.nonce != std::numeric_limits::max(); bl.nonce++) { - crypto::hash h = get_block_longhash(height, bl_hash, bl.nonce); + nonce_ref = bl.nonce; + + crypto::hash h = sk.get_pow_hash(bd, height, seed); if(check_hash(h, diffic)) { LOG_PRINT_L0("Found nonce for block: " << get_block_hash(bl) << "[" << height << "]: PoW:" << h << "(diff:" << diffic << "), ts: " << bl.timestamp); @@ -103,11 +105,13 @@ namespace currency std::atomic m_template_no; std::atomic m_starter_nonce; wide_difficulty_type m_diffic; - uint64_t m_height; + std::atomic m_height; + scratchpad_keeper m_scratchpad; + crypto::hash m_seed; volatile uint32_t m_thread_index; volatile uint32_t m_threads_total; std::atomic m_pausers_count; - ::critical_section m_miners_count_lock; + ::critical_section m_miners_count_lock; std::list m_threads; ::critical_section m_threads_lock; diff --git a/src/currency_core/offers_services_helpers.cpp b/src/currency_core/offers_services_helpers.cpp index ba068b8d..f73e3393 100644 --- a/src/currency_core/offers_services_helpers.cpp +++ b/src/currency_core/offers_services_helpers.cpp @@ -254,10 +254,10 @@ namespace bc_services } //now cut what not needed - auto it = std::next(offers.begin(), std::min(filter.offset, offers.size())); + auto it = std::next(offers.begin(), std::min(filter.offset, static_cast(offers.size()))); offers.erase(offers.begin(), it); // cut limit - it = std::next(offers.begin(), std::min(filter.limit, offers.size())); + it = std::next(offers.begin(), std::min(filter.limit, static_cast(offers.size()))); offers.erase(it, offers.end()); return true; diff --git a/src/currency_core/scratchpad_helper.cpp b/src/currency_core/scratchpad_helper.cpp new file mode 100644 index 00000000..fcdb38c6 --- /dev/null +++ b/src/currency_core/scratchpad_helper.cpp @@ -0,0 +1,54 @@ +// Copyright (c) 2018-2019 Zano Project + +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + + +#include "scratchpad_helper.h" +#include "currency_format_utils.h" + + + +namespace currency +{ + scratchpad_keeper::scratchpad_keeper():m_seed(null_hash) + { + + } + bool scratchpad_keeper::generate(const crypto::hash& scr_seed, uint64_t height) + { + bool r = false; + CRITICAL_REGION_BEGIN(m_lock); + r = crypto::generate_scratchpad(scr_seed, m_scratchpad, get_scratchpad_size_for_height(height)); + if (r) + m_seed = scr_seed; + CRITICAL_REGION_END(); + return r; + } + crypto::hash scratchpad_keeper::get_pow_hash(const blobdata& bd, uint64_t height, const crypto::hash& scr_seed) + { + crypto::hash res_hash = null_hash; + if (scr_seed != m_seed) + { + bool r = generate(scr_seed, height); + CHECK_AND_ASSERT_THROW_MES(r, "Unable to generate scratchpad"); + } + CRITICAL_REGION_BEGIN(m_lock); + CHECK_AND_ASSERT_THROW_MES(get_scratchpad_size_for_height(height) == this->size(), "Fatal error on hash calculation: scratchpad_size=" << m_scratchpad.size() << " at height=" << height << ", scr_seed=" << scr_seed << ", m_seed=" << m_seed); + CHECK_AND_ASSERT_THROW_MES(scr_seed == m_seed, "Fatal error on hash calculation: scratchpad_seed missmatch scr_seed=" << scr_seed << ", m_seed=" << m_seed); + + bool res = get_wild_keccak2(bd, res_hash, m_scratchpad); + CHECK_AND_ASSERT_THROW_MES(res, "Fatal error on hash calculation: scratchpad_size=" << m_scratchpad.size()); + CRITICAL_REGION_END(); + return res_hash; + } + crypto::hash scratchpad_keeper::get_pow_hash(const block& b, const crypto::hash& scr_seed) + { + blobdata bl = get_block_hashing_blob(b); + return get_pow_hash(bl, get_block_height(b), scr_seed); + } + uint64_t scratchpad_keeper::size() + { + return m_scratchpad.size(); + } +} \ No newline at end of file diff --git a/src/currency_core/scratchpad_helper.h b/src/currency_core/scratchpad_helper.h new file mode 100644 index 00000000..0ecf73ce --- /dev/null +++ b/src/currency_core/scratchpad_helper.h @@ -0,0 +1,27 @@ +// Copyright (c) 2014-2018 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once +#include "crypto/wild_keccak.h" +#include "currency_protocol/blobdatatype.h" +#include "currency_core/currency_basic.h" + +namespace currency +{ + class scratchpad_keeper + { + public: + scratchpad_keeper(); + bool generate(const crypto::hash& seed, uint64_t height); + crypto::hash get_pow_hash(const blobdata& bd, uint64_t height, const crypto::hash& seed); + crypto::hash get_pow_hash(const block& b, const crypto::hash& seed); + uint64_t size(); + private: + scratchpad_keeper(const scratchpad_keeper&) {} + crypto::hash m_seed; + std::vector m_scratchpad; + std::recursive_mutex m_lock; + }; + +} \ No newline at end of file diff --git a/src/currency_protocol/currency_protocol_handler.inl b/src/currency_protocol/currency_protocol_handler.inl index 83917f92..f449fc52 100644 --- a/src/currency_protocol/currency_protocol_handler.inl +++ b/src/currency_protocol/currency_protocol_handler.inl @@ -114,7 +114,7 @@ namespace currency { - context.m_priv.m_remote_version = hshd.client_version; + context.m_remote_version = hshd.client_version; if(context.m_state == currency_connection_context::state_befor_handshake && !is_inital) return true; diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index 459cc8e2..bd0e8958 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -83,11 +83,7 @@ int main(int argc, char* argv[]) currency::core::init_options(desc_cmd_sett); currency::core_rpc_server::init_options(desc_cmd_sett); nodetool::node_server >::init_options(desc_cmd_sett); -#ifdef USE_OPENCL - currency::gpu_miner::init_options(desc_cmd_sett); -#else currency::miner::init_options(desc_cmd_sett); -#endif bc_services::bc_offers_service::init_options(desc_cmd_sett); @@ -105,10 +101,6 @@ int main(int argc, char* argv[]) std::cout << desc_options << std::endl; return false; } -#ifdef USE_OPENCL - if (currency::gpu_miner::handle_cli_info_commands(vm)) - return false; -#endif std::string data_dir = command_line::get_arg(vm, command_line::arg_data_dir); std::string config = command_line::get_arg(vm, command_line::arg_config_file); diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 146d8cd8..4ccac2ba 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -1061,6 +1061,7 @@ namespace nodetool ce.time_started = cntxt.m_started; ce.last_recv = cntxt.m_last_recv; ce.last_send = cntxt.m_last_send; + ce.version = cntxt.m_remote_version; rsp.connections_list.push_back(ce); return true; }); diff --git a/src/p2p/p2p_protocol_defs.h b/src/p2p/p2p_protocol_defs.h index 49d819b4..c7920678 100644 --- a/src/p2p/p2p_protocol_defs.h +++ b/src/p2p/p2p_protocol_defs.h @@ -41,6 +41,7 @@ namespace nodetool uint64_t time_started; uint64_t last_recv; uint64_t last_send; + std::string version; }; #pragma pack(pop) diff --git a/src/pch/stdafx.h b/src/pch/stdafx.h index e5396219..ddde97fe 100644 --- a/src/pch/stdafx.h +++ b/src/pch/stdafx.h @@ -102,6 +102,5 @@ POP_WARNINGS // // contrib // -#include "ethereum/libethash/internal.h" #include "eos_portable_archive/eos/portable_archive.hpp" #include "db/liblmdb/lmdb.h" diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 92c11ddf..01c07dac 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -781,7 +781,7 @@ namespace currency //pe.keyimage key image will be set in the wallet //pe.wallet_index is not included in serialization map, TODO: refactoring here - if (!m_core.get_block_template(b, miner_address, stakeholder_address, dt, res.height, req.extra_text, req.pos_block, pe)) + if (!m_core.get_block_template(b, res.seed, miner_address, stakeholder_address, dt, res.height, req.extra_text, req.pos_block, pe)) { error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR; error_resp.message = "Internal error: failed to create block template"; diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 5bb6dab6..5f20b3d2 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -786,12 +786,14 @@ namespace currency { uint64_t difficulty; uint64_t height; + crypto::hash seed; blobdata blocktemplate_blob; std::string status; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(difficulty) KV_SERIALIZE(height) + KV_SERIALIZE_POD_AS_HEX_STRING(seed) KV_SERIALIZE(blocktemplate_blob) KV_SERIALIZE(status) END_KV_SERIALIZE_MAP() diff --git a/src/version.h.in b/src/version.h.in index 092da955..f9120dc9 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -2,6 +2,6 @@ #define BUILD_COMMIT_ID "@VERSION@" #define PROJECT_VERSION "1.0" -#define PROJECT_VERSION_BUILD_NO 3 +#define PROJECT_VERSION_BUILD_NO 4 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" diff --git a/tests/core_tests/alias_tests.cpp b/tests/core_tests/alias_tests.cpp index afe0c864..8996b88f 100644 --- a/tests/core_tests/alias_tests.cpp +++ b/tests/core_tests/alias_tests.cpp @@ -381,7 +381,8 @@ bool gen_alias_tests::check_too_many_aliases_registration(currency::core& c, siz wide_difficulty_type diff; uint64_t height; blobdata extra = AUTO_VAL_INIT(extra); - bool r = c.get_block_template(b, ai.m_address, ai.m_address, diff, height, extra); + crypto::hash seed = currency::null_hash; + bool r = c.get_block_template(b, seed, ai.m_address, ai.m_address, diff, height, extra); CHECK_AND_ASSERT_MES(r, false, "get_block_template failed"); CHECK_AND_ASSERT_MES(b.tx_hashes.empty(), false, "block template has some txs, expected--none"); @@ -412,7 +413,7 @@ bool gen_alias_tests::check_too_many_aliases_registration(currency::core& c, siz CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == total_alias_to_gen, false, "Unexpected number of txs in the pool: " << c.get_pool_transactions_count() << ", expected: " << total_alias_to_gen); // complete block template and try to process it - r = miner::find_nonce_for_given_block(b, diff, height); + r = miner::find_nonce_for_given_block(b, diff, height, seed, m_scratchpad_keeper); CHECK_AND_ASSERT_MES(r, false, "find_nonce_for_given_block failed"); currency::block_verification_context bvc = AUTO_VAL_INIT(bvc); @@ -1288,11 +1289,12 @@ bool gen_alias_switch_and_check_block_template::add_block_from_template(currency currency::block b; wide_difficulty_type diff; uint64_t height; + crypto::hash seed = currency::null_hash; blobdata extra = AUTO_VAL_INIT(extra); - bool r = c.get_block_template(b, acc.get_public_address(), acc.get_public_address(), diff, height, extra); + bool r = c.get_block_template(b, seed, acc.get_public_address(), acc.get_public_address(), diff, height, extra); CHECK_AND_ASSERT_MES(r, false, "get_block_template failed"); - r = miner::find_nonce_for_given_block(b, diff, height); + r = miner::find_nonce_for_given_block(b, diff, height, seed, m_scratchpad_keeper); CHECK_AND_ASSERT_MES(r, false, "find_nonce_for_given_block failed"); currency::block_verification_context bvc = AUTO_VAL_INIT(bvc); @@ -1407,11 +1409,12 @@ bool gen_alias_too_many_regs_in_block_template::add_block_from_template(currency currency::block b; wide_difficulty_type diff; uint64_t height; + crypto::hash seed = currency::null_hash; blobdata extra = AUTO_VAL_INIT(extra); - bool r = c.get_block_template(b, acc.get_public_address(), acc.get_public_address(), diff, height, extra); + bool r = c.get_block_template(b, seed, acc.get_public_address(), acc.get_public_address(), diff, height, extra); CHECK_AND_ASSERT_MES(r, false, "get_block_template failed"); - r = miner::find_nonce_for_given_block(b, diff, height); + r = miner::find_nonce_for_given_block(b, diff, height, seed, m_scratchpad_keeper); CHECK_AND_ASSERT_MES(r, false, "find_nonce_for_given_block failed"); currency::block_verification_context bvc = AUTO_VAL_INIT(bvc); @@ -1421,7 +1424,6 @@ bool gen_alias_too_many_regs_in_block_template::add_block_from_template(currency return true; } - //------------------------------------------------------------------------------ bool gen_alias_update_for_free::generate(std::vector& events) const diff --git a/tests/core_tests/block_reward.cpp b/tests/core_tests/block_reward.cpp index a7d01fd8..3fdf7d3b 100644 --- a/tests/core_tests/block_reward.cpp +++ b/tests/core_tests/block_reward.cpp @@ -87,7 +87,8 @@ bool block_template_against_txs_size::c1(currency::core& c, size_t ev_index, con wide_difficulty_type diff = 0; uint64_t height = 0; g_block_txs_total_size = txs_total_size; // passing an argument to custom_fill_block_template_func via global variable (not perfect but works well) - r = bcs.create_block_template(b, miner_addr, miner_addr, diff, height, ex_nonce, is_pos != 0, pe, &custom_fill_block_template_func); + crypto::hash seed = currency::null_hash; + r = bcs.create_block_template(b, seed, miner_addr, miner_addr, diff, height, ex_nonce, is_pos != 0, pe, &custom_fill_block_template_func); CHECK_AND_ASSERT_MES(r, false, "create_block_template failed, txs_total_size = " << txs_total_size); CHECK_AND_ASSERT_MES(height == top_block_height + 1, false, "Incorrect height: " << height << ", expected: " << top_block_height + 1 << ", txs_total_size = " << txs_total_size); diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index 944ffd77..97c420db 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -693,8 +693,15 @@ bool test_generator::find_nounce(currency::block& blk, std::vector crypto::hash + { + return currency::get_block_hash(blocks[index]->b); + }); + - return miner::find_nonce_for_given_block(blk, dif, height); + return miner::find_nonce_for_given_block(blk, dif, height, seed, m_scratchpad); } bool test_generator::construct_genesis_block(currency::block& blk, const currency::account_base& miner_acc, uint64_t timestamp) diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 3b8d7eff..321e9882 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -14,6 +14,7 @@ #include "wallet/wallet2.h" #include "test_core_time.h" #include "chaingen_helpers.h" +#include "currency_core/scratchpad_helper.h" #define TESTS_DEFAULT_FEE ((uint64_t)TX_DEFAULT_FEE) #define MK_TEST_COINS(amount) (static_cast(amount) * TESTS_DEFAULT_FEE) @@ -305,7 +306,7 @@ protected: uint64_t height; crypto::hash hash; }; - + currency::scratchpad_keeper m_scratchpad_keeper; size_t m_invalid_block_index; size_t m_invalid_tx_index; size_t m_orphan_block_index; @@ -506,6 +507,7 @@ private: std::unordered_map m_blocks_info; static test_gentime_settings m_test_gentime_settings; static test_gentime_settings m_test_gentime_settings_default; + mutable currency::scratchpad_keeper m_scratchpad; }; extern const crypto::signature invalid_signature; // invalid non-null signature for test purpose diff --git a/tests/core_tests/chaingen_helpers.h b/tests/core_tests/chaingen_helpers.h index 00b193dd..69216e7d 100644 --- a/tests/core_tests/chaingen_helpers.h +++ b/tests/core_tests/chaingen_helpers.h @@ -11,13 +11,14 @@ // chaingen-independent helpers that may be used outside of core_tests (for ex. in functional_tests) -inline bool mine_next_pow_block_in_playtime(const currency::account_public_address& miner_addr, currency::core& c, currency::block* output = nullptr) +inline bool mine_next_pow_block_in_playtime(currency::scratchpad_keeper& scr_keeper, const currency::account_public_address& miner_addr, currency::core& c, currency::block* output = nullptr) { currency::block b = AUTO_VAL_INIT(b); currency::wide_difficulty_type diff; uint64_t height; currency::blobdata extra = AUTO_VAL_INIT(extra); - bool r = c.get_block_template(b, miner_addr, miner_addr, diff, height, extra); + crypto::hash seed = currency::null_hash; + bool r = c.get_block_template(b, seed, miner_addr, miner_addr, diff, height, extra); CHECK_AND_ASSERT_MES(r, false, "get_block_template failed"); // adjust block's timestamp to keep difficulty low @@ -27,7 +28,7 @@ inline bool mine_next_pow_block_in_playtime(const currency::account_public_addre // keep global time up with blocks' timestamps test_core_time::adjust(b.timestamp); - r = currency::miner::find_nonce_for_given_block(b, diff, height); + r = currency::miner::find_nonce_for_given_block(b, diff, height, seed, scr_keeper); CHECK_AND_ASSERT_MES(r, false, "find_nonce_for_given_block failed"); currency::block_verification_context bvc = AUTO_VAL_INIT(bvc); @@ -40,7 +41,7 @@ inline bool mine_next_pow_block_in_playtime(const currency::account_public_addre return true; } -inline bool mine_next_pow_block_in_playtime_with_given_txs(const currency::account_public_address& miner_addr, currency::core& c, const std::vector& txs, const crypto::hash& prev_id, uint64_t height, currency::block* output = nullptr) +inline bool mine_next_pow_block_in_playtime_with_given_txs(currency::scratchpad_keeper& scr_keeper, const currency::account_public_address& miner_addr, currency::core& c, const std::vector& txs, const crypto::hash& prev_id, uint64_t height, currency::block* output = nullptr) { struct loc_helper { @@ -72,11 +73,12 @@ inline bool mine_next_pow_block_in_playtime_with_given_txs(const currency::accou uint64_t height_from_template = 0; currency::blobdata extra = AUTO_VAL_INIT(extra); currency::pos_entry pe = AUTO_VAL_INIT(pe); + crypto::hash seed; bool r = false; { CRITICAL_REGION_LOCAL(s_locker); loc_helper::txs_accessor() = &txs; - r = c.get_blockchain_storage().create_block_template(b, miner_addr, miner_addr, diff, height_from_template, extra, false, pe, loc_helper::fill_block_template_func); + r = c.get_blockchain_storage().create_block_template(b, seed, miner_addr, miner_addr, diff, height_from_template, extra, false, pe, loc_helper::fill_block_template_func); } CHECK_AND_ASSERT_MES(r, false, "get_block_template failed"); @@ -104,7 +106,7 @@ inline bool mine_next_pow_block_in_playtime_with_given_txs(const currency::accou height = height_from_template; } - r = currency::miner::find_nonce_for_given_block(b, diff, height); + r = currency::miner::find_nonce_for_given_block(b, diff, height, seed, scr_keeper); CHECK_AND_ASSERT_MES(r, false, "find_nonce_for_given_block failed"); currency::block_verification_context bvc = AUTO_VAL_INIT(bvc); @@ -117,15 +119,15 @@ inline bool mine_next_pow_block_in_playtime_with_given_txs(const currency::accou return true; } -inline bool mine_next_pow_block_in_playtime_with_given_txs(const currency::account_public_address& miner_addr, currency::core& c, const std::vector& txs, currency::block* output = nullptr) +inline bool mine_next_pow_block_in_playtime_with_given_txs(currency::scratchpad_keeper& scr_keeper, const currency::account_public_address& miner_addr, currency::core& c, const std::vector& txs, currency::block* output = nullptr) { - return mine_next_pow_block_in_playtime_with_given_txs(miner_addr, c, txs, currency::null_hash, SIZE_MAX, output); + return mine_next_pow_block_in_playtime_with_given_txs(scr_keeper, miner_addr, c, txs, currency::null_hash, SIZE_MAX, output); } -inline bool mine_next_pow_blocks_in_playtime(const currency::account_public_address& miner_addr, currency::core& c, size_t blocks_count) +inline bool mine_next_pow_blocks_in_playtime(currency::scratchpad_keeper& scr_keeper, const currency::account_public_address& miner_addr, currency::core& c, size_t blocks_count) { for (size_t i = 0; i != blocks_count; i++) - if (!mine_next_pow_block_in_playtime(miner_addr, c)) + if (!mine_next_pow_block_in_playtime(scr_keeper, miner_addr, c)) return false; return true; diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 7a0fd2b8..127a4021 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -104,6 +104,7 @@ bool generate_and_play(const char* const genclass_name) else { std::cout << concolor::magenta << "#TEST# Failed " << genclass_name << concolor::normal << std::endl; + LOG_PRINT_RED_L0("#TEST# Failed " << genclass_name); result = false; } std::cout << std::endl; @@ -217,7 +218,7 @@ bool gen_and_play_intermitted_by_blockchain_saveload(const char* const genclass_ #define GENERATE_AND_PLAY(genclass) \ - if(run_single_test.empty() || run_single_test == #genclass) \ + if(!postponed_tests.count(#genclass) && (run_single_test.empty() || run_single_test == #genclass)) \ { \ TIME_MEASURE_START_MS(t); \ ++tests_count; \ @@ -678,6 +679,23 @@ int main(int argc, char* argv[]) } //CALL_TEST("check_hash_and_difficulty_monte_carlo_test", check_hash_and_difficulty_monte_carlo_test); // it's rather an experiment with unclean results than a solid test, for further research... + std::set postponed_tests; + + // Postponed tests - tests that may fail for the time being (believed that it's a serious issue and should be fixed later for some reason). + // In a perfect world this list is empty. +#define MARK_TEST_AS_POSTPONED(genclass) postponed_tests.insert(#genclass) + MARK_TEST_AS_POSTPONED(gen_checkpoints_reorganize); + MARK_TEST_AS_POSTPONED(gen_alias_update_after_addr_changed); + MARK_TEST_AS_POSTPONED(gen_alias_blocking_reg_by_invalid_tx); + MARK_TEST_AS_POSTPONED(gen_alias_blocking_update_by_invalid_tx); + MARK_TEST_AS_POSTPONED(gen_wallet_fake_outputs_randomness); + MARK_TEST_AS_POSTPONED(gen_wallet_fake_outputs_not_enough); + MARK_TEST_AS_POSTPONED(gen_wallet_spending_coinstake_after_minting); + MARK_TEST_AS_POSTPONED(gen_wallet_fake_outs_while_having_too_little_own_outs); + MARK_TEST_AS_POSTPONED(gen_uint_overflow_1); + +#undef MARK_TEST_AS_POSTPONED + GENERATE_AND_PLAY(multisig_wallet_test); GENERATE_AND_PLAY(multisig_wallet_test_many_dst); @@ -918,22 +936,6 @@ int main(int argc, char* argv[]) //GENERATE_AND_PLAY(gen_block_reward); */ - std::set postponed_tests; - - // Postponed tests - tests that may fail for the time being (believed that it's a serious issue and should be fixed later for some reason). - // In a perfect world this list is empty. -#define MARK_TEST_AS_POSTPONED(genclass) postponed_tests.insert(#genclass) - MARK_TEST_AS_POSTPONED(gen_checkpoints_reorganize); - MARK_TEST_AS_POSTPONED(gen_alias_update_after_addr_changed); - MARK_TEST_AS_POSTPONED(gen_alias_blocking_reg_by_invalid_tx); - MARK_TEST_AS_POSTPONED(gen_alias_blocking_update_by_invalid_tx); - MARK_TEST_AS_POSTPONED(gen_wallet_fake_outputs_randomness); - MARK_TEST_AS_POSTPONED(gen_wallet_fake_outputs_not_enough); - MARK_TEST_AS_POSTPONED(gen_wallet_spending_coinstake_after_minting); - MARK_TEST_AS_POSTPONED(gen_wallet_fake_outs_while_having_too_little_own_outs); - MARK_TEST_AS_POSTPONED(gen_uint_overflow_1); - -#undef MARK_TEST_AS_POSTPONED size_t failed_postponed_tests_count = 0; diff --git a/tests/core_tests/checkpoints_tests.cpp b/tests/core_tests/checkpoints_tests.cpp index 26c674b7..80faac39 100644 --- a/tests/core_tests/checkpoints_tests.cpp +++ b/tests/core_tests/checkpoints_tests.cpp @@ -628,7 +628,7 @@ bool gen_no_attchments_in_coinbase::init_config_set_cp(currency::core& c, size_t crc.pos_minimum_heigh = 1; c.get_blockchain_storage().set_core_runtime_config(crc); - m_checkpoints.add_checkpoint(12, "6cac77f011a1d16c7c64fc16403670b71dbad38268e9bfc94d1c08c349ea19c5"); + m_checkpoints.add_checkpoint(12, "57ba6f8b5de551d361d6c56f42ebf3ce1e0b21e42d1499dc9bd2b69c09357062");//"6cac77f011a1d16c7c64fc16403670b71dbad38268e9bfc94d1c08c349ea19c5"); c.set_checkpoints(currency::checkpoints(m_checkpoints)); return true; @@ -683,19 +683,19 @@ bool gen_no_attchments_in_coinbase::c1(currency::core& c, size_t ev_index, const test_core_time::adjust(blk_0r.timestamp + DIFFICULTY_TOTAL_TARGET); block blk_a; - r = mine_next_pow_block_in_playtime(m_miner_acc.get_public_address(), c, &blk_a); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_miner_acc.get_public_address(), c, &blk_a); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); test_core_time::adjust(blk_a.timestamp + DIFFICULTY_TOTAL_TARGET); block blk_b; - r = mine_next_pow_block_in_playtime(m_miner_acc.get_public_address(), c, &blk_b); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_miner_acc.get_public_address(), c, &blk_b); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); test_core_time::adjust(blk_b.timestamp + DIFFICULTY_TOTAL_TARGET); block blk_c; - r = mine_next_pow_block_in_playtime(m_miner_acc.get_public_address(), c, &blk_c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_miner_acc.get_public_address(), c, &blk_c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); // make sure the checkpoint zone is successfully left behind diff --git a/tests/core_tests/emission_test.cpp b/tests/core_tests/emission_test.cpp index 33de91e6..590524f7 100644 --- a/tests/core_tests/emission_test.cpp +++ b/tests/core_tests/emission_test.cpp @@ -66,9 +66,10 @@ bool emission_test::c1(currency::core& c, size_t ev_index, const std::vector& events) bool escrow_altchain_meta_impl::mine_next_block_with_tx(currency::core& c, const currency::transaction& tx) { block b = AUTO_VAL_INIT(b); - bool r = mine_next_pow_block_in_playtime_with_given_txs(m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector({ tx }), m_last_block_hash, m_last_block_height + 1, &b); + bool r = mine_next_pow_block_in_playtime_with_given_txs(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector({ tx }), m_last_block_hash, m_last_block_height + 1, &b); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime_with_given_txs failed"); m_last_block_hash = get_block_hash(b); m_last_block_height = get_block_height(b); @@ -95,7 +95,7 @@ bool escrow_altchain_meta_impl::mine_next_block_with_tx(currency::core& c, const bool escrow_altchain_meta_impl::mine_next_block_with_no_tx(currency::core& c) { block b = AUTO_VAL_INIT(b); - bool r = mine_next_pow_block_in_playtime_with_given_txs(m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector(), m_last_block_hash, m_last_block_height + 1, &b); + bool r = mine_next_pow_block_in_playtime_with_given_txs(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector(), m_last_block_hash, m_last_block_height + 1, &b); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime_with_given_txs failed"); m_last_block_hash = get_block_hash(b); m_last_block_height = get_block_height(b); diff --git a/tests/core_tests/escrow_wallet_tests.cpp b/tests/core_tests/escrow_wallet_tests.cpp index a0045d0d..f0d02778 100644 --- a/tests/core_tests/escrow_wallet_tests.cpp +++ b/tests/core_tests/escrow_wallet_tests.cpp @@ -80,7 +80,7 @@ bool escrow_wallet_test::prepare_proposal_accepted_test(currency::core& c, const miner_wlt->transfer(AMOUNT_TO_TRANSFER_ESCROW + TX_DEFAULT_FEE * 2, accunt_seller.get_public_address()); LOG_PRINT_MAGENTA("Transaction sent to seller_account: " << AMOUNT_TO_TRANSFER_ESCROW + TX_DEFAULT_FEE * 2, LOG_LEVEL_0); - bool r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + bool r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, m_mining_accunt.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); @@ -121,7 +121,7 @@ bool escrow_wallet_test::prepare_proposal_accepted_test(currency::core& c, const LOG_PRINT_MAGENTA("Escrow proposal sent bseller_account: escrow_proposal_tx id: " << currency::get_transaction_hash(escrow_proposal_tx) << ", multisig_id: " << multisig_id, LOG_LEVEL_0); - r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, 2); + r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, m_mining_accunt.get_public_address(), c, 2); wallet_buyer->refresh(); wallet_seller->refresh(); @@ -147,7 +147,7 @@ bool escrow_wallet_test::prepare_proposal_accepted_test(currency::core& c, const //---------------------- wallet_seller->accept_proposal(multisig_id, TX_DEFAULT_FEE); - r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, m_mining_accunt.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); wallet_buyer->refresh(); wallet_seller->refresh(); @@ -197,7 +197,7 @@ bool escrow_wallet_test::exec_test_with_specific_release_type(currency::core& c, tools::wallet2::escrow_contracts_container contracts_buyer, contracts_seller; wallet_buyer->finish_contract(multisig_id, release_instruction); - r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, 2); + r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, m_mining_accunt.get_public_address(), c, 2); wallet_buyer->refresh(); wallet_seller->refresh(); wallet_buyer->get_contracts(contracts_buyer); @@ -230,11 +230,11 @@ bool escrow_wallet_test::exec_test_with_cancel_release_type(currency::core& c, c wallet_miner = init_playtime_test_wallet(events, c, m_mining_accunt); wallet_miner->refresh(); wallet_miner->transfer(TX_DEFAULT_FEE, wallet_buyer->get_account().get_public_address()); - r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, 10); + r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, m_mining_accunt.get_public_address(), c, 10); wallet_buyer->refresh(); tools::wallet2::escrow_contracts_container contracts_buyer, contracts_seller; wallet_buyer->request_cancel_contract(multisig_id, TX_DEFAULT_FEE, 60 * 60); - r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, 2); + r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, m_mining_accunt.get_public_address(), c, 2); wallet_buyer->refresh(); wallet_seller->refresh(); wallet_buyer->get_contracts(contracts_buyer); @@ -252,7 +252,7 @@ bool escrow_wallet_test::exec_test_with_cancel_release_type(currency::core& c, c //cancel contract wallet_seller->accept_cancel_contract(multisig_id); - r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, 2); + r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, m_mining_accunt.get_public_address(), c, 2); wallet_buyer->refresh(); wallet_seller->refresh(); wallet_buyer->get_contracts(contracts_buyer); @@ -396,7 +396,7 @@ bool escrow_w_and_fake_outputs::c1(currency::core& c, size_t ev_index, const std CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -406,7 +406,7 @@ bool escrow_w_and_fake_outputs::c1(currency::core& c, size_t ev_index, const std CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -416,7 +416,7 @@ bool escrow_w_and_fake_outputs::c1(currency::core& c, size_t ev_index, const std CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, WALLET_DEFAULT_TX_SPENDABLE_AGE); + r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, WALLET_DEFAULT_TX_SPENDABLE_AGE); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -441,7 +441,7 @@ bool escrow_w_and_fake_outputs::c1(currency::core& c, size_t ev_index, const std CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 2, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -651,7 +651,7 @@ bool escrow_incorrect_proposal::check_normal_proposal(currency::core& c, size_t alice_wlt->accept_proposal(contract_id, TX_DEFAULT_FEE); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -661,7 +661,7 @@ bool escrow_incorrect_proposal::check_normal_proposal(currency::core& c, size_t miner_wlt->finish_contract(contract_id, BC_ESCROW_SERVICE_INSTRUCTION_RELEASE_NORMAL); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -788,7 +788,7 @@ bool escrow_proposal_expiration::c1(currency::core& c, size_t ev_index, const st CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); // mine a block with proposal transport tx - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -797,7 +797,7 @@ bool escrow_proposal_expiration::c1(currency::core& c, size_t ev_index, const st CHECK_AND_ASSERT_MES(refresh_wallet_and_check_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::proposal_sent, ms_id, 1), false, ""); // mine few block to shift the timestamp median far enough - r = mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, TX_EXPIRATION_TIMESTAMP_CHECK_WINDOW); + r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, TX_EXPIRATION_TIMESTAMP_CHECK_WINDOW); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); // check Alice's balance @@ -866,7 +866,7 @@ bool escrow_proposal_expiration::c2(currency::core& c, size_t ev_index, const st // mine a few blocks with no txs for (size_t i = 0; i < TX_EXPIRATION_TIMESTAMP_CHECK_WINDOW + 1; ++i) { - r = mine_next_pow_block_in_playtime_with_given_txs(m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector()); + r = mine_next_pow_block_in_playtime_with_given_txs(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector()); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); } @@ -896,7 +896,7 @@ bool escrow_proposal_expiration::c2(currency::core& c, size_t ev_index, const st CHECK_AND_ASSERT_MES(r, false, "Bob tried to accept an expired proposal, but wallet exception was not caught"); // mine a block with proposal transport tx - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); // check it has left tx pool @@ -1022,7 +1022,7 @@ bool escrow_proposal_and_accept_expiration::c1(currency::core& c, size_t ev_inde // mine a few blocks with no txs for (size_t i = 0; i < TX_EXPIRATION_TIMESTAMP_CHECK_WINDOW + 1; ++i) { - r = mine_next_pow_block_in_playtime_with_given_txs(m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector()); + r = mine_next_pow_block_in_playtime_with_given_txs(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector()); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); } @@ -1057,7 +1057,7 @@ bool escrow_proposal_and_accept_expiration::c1(currency::core& c, size_t ev_inde CHECK_AND_ASSERT_MES(r, false, "Bob tried to accept an expired proposal, but wallet exception was not caught"); LOG_PRINT_CYAN("%%%%% mine a block with proposal transport tx", LOG_LEVEL_0); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); // check it has left tx pool @@ -1336,7 +1336,7 @@ bool escrow_incorrect_proposal_acceptance::check_normal_acceptance(currency::cor CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -1673,7 +1673,7 @@ bool escrow_custom_test::do_custom_test(currency::core& c, size_t ev_index, cons CHECK_AND_ASSERT_MES(check_wallet_balance_blocked_for_escrow(*alice_wlt.get(), "Alice", cd.cpd.amount_a_pledge + cd.cpd.amount_to_pay), false, ""); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -1712,7 +1712,7 @@ bool escrow_custom_test::do_custom_test(currency::core& c, size_t ev_index, cons false, ""); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -1751,7 +1751,7 @@ bool escrow_custom_test::do_custom_test(currency::core& c, size_t ev_index, cons CHECK_AND_ASSERT_MES(check_balance_via_wallet(*bob_wlt.get(), "Bob", bob_expected_balance, 0, INVALID_BALANCE_VAL, 0, 0), false, ""); // should not change CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -1795,7 +1795,7 @@ bool escrow_custom_test::do_custom_test(currency::core& c, size_t ev_index, cons CHECK_AND_ASSERT_MES(check_balance_via_wallet(*bob_wlt.get(), "Bob", bob_expected_balance, 0, INVALID_BALANCE_VAL, cd.is_release_normal() ? cd.cpd.amount_b_pledge + cd.cpd.amount_to_pay : 0, cd.is_release_normal() ? 0 : ms_amount - cd.b_release_fee), false, ""); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -1842,7 +1842,7 @@ bool escrow_custom_test::do_custom_test(currency::core& c, size_t ev_index, cons CHECK_AND_ASSERT_MES(check_balance_via_wallet(*bob_wlt.get(), "Bob", bob_expected_balance, 0, INVALID_BALANCE_VAL, bob_expected_aw_in_balance, 0), false, ""); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -2096,7 +2096,7 @@ bool escrow_incorrect_cancel_proposal::check_normal_cancel_proposal(currency::co bob_wlt->accept_cancel_contract(ms_id); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -2273,7 +2273,7 @@ bool escrow_proposal_not_enough_money::c1(currency::core& c, size_t ev_index, co CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt.get(), "Alice", MK_TEST_COINS(30), 0, MK_TEST_COINS(30), 0, 0), false, ""); // mine few blocks to make sure there's no problem - r = mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, 5); + r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, 5); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); // and check balance again @@ -2359,7 +2359,7 @@ bool escrow_cancellation_and_tx_order::c1(currency::core& c, size_t ev_index, co // mine a block, containing escrow proposal tx CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); @@ -2377,7 +2377,7 @@ bool escrow_cancellation_and_tx_order::c1(currency::core& c, size_t ev_index, co // mine a block containing contract acceptance CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); @@ -2437,8 +2437,8 @@ bool escrow_cancellation_and_tx_order::c1(currency::core& c, size_t ev_index, co CHECK_AND_ASSERT_MES(contracts.begin()->second.state == tools::wallet_rpc::escrow_contract_details::contract_released_cancelled, false, "Bob has invalid contract state: " << tools::wallet_rpc::get_escrow_contract_state_name(contracts.begin()->second.state)); // mine a block containing only cancel_request_acceptance_tx (this should trigger contracts' states swtiching into contract_released_cancelled) - LOG_PRINT_GREEN("\n" "mine_next_pow_block_in_playtime_with_given_txs(cancel_request_acceptance_tx)", LOG_LEVEL_0); - r = mine_next_pow_block_in_playtime_with_given_txs(m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector({cancel_request_acceptance_tx})); + LOG_PRINT_GREEN("\n" "mine_next_pow_block_in_playtime_with_given_txs(m_scratchpad_keeper, cancel_request_acceptance_tx)", LOG_LEVEL_0); + r = mine_next_pow_block_in_playtime_with_given_txs(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector({cancel_request_acceptance_tx})); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime_with_given_txs failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); @@ -2458,8 +2458,8 @@ bool escrow_cancellation_and_tx_order::c1(currency::core& c, size_t ev_index, co // mine a block containing only cancel_request_tx (this SHOULD NOT trigger contracts' states swtiching into contract_cancel_proposal_sent or anything) - LOG_PRINT_GREEN("\n" "mine_next_pow_block_in_playtime_with_given_txs(cancel_request_tx)", LOG_LEVEL_0); - r = mine_next_pow_block_in_playtime_with_given_txs(m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector({cancel_request_tx})); + LOG_PRINT_GREEN("\n" "mine_next_pow_block_in_playtime_with_given_txs(m_scratchpad_keeper, cancel_request_tx)", LOG_LEVEL_0); + r = mine_next_pow_block_in_playtime_with_given_txs(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector({cancel_request_tx})); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime_with_given_txs failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); @@ -2563,7 +2563,7 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in // mine a block, containing escrow proposal tx CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); @@ -2584,7 +2584,7 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in // mine a block containing contract acceptance CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); @@ -2621,7 +2621,7 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in // mine a few blocks with no txs to shift expiration median for(size_t i = 0; i < 7; ++i) { - r = mine_next_pow_block_in_playtime_with_given_txs(m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector()); + r = mine_next_pow_block_in_playtime_with_given_txs(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector()); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime_with_given_txs failed"); } // cancellation request is still in the pool @@ -2649,8 +2649,8 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::contract_accepted, 7), false, ""); // mine a block containing cancel_request_tx (already expired) -- should be okay - LOG_PRINT_GREEN("\n\n\n" "mine_next_pow_block_in_playtime() -- including expires contract cancellation request" "\n\n", LOG_LEVEL_0); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + LOG_PRINT_GREEN("\n\n\n" "mine_next_pow_block_in_playtime(m_scratchpad_keeper, ) -- including expires contract cancellation request" "\n\n", LOG_LEVEL_0); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); @@ -2684,8 +2684,8 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent, 0), false, ""); // mine a block containing cancel_request_tx - LOG_PRINT_GREEN("\n" "mine_next_pow_block_in_playtime()", LOG_LEVEL_0); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + LOG_PRINT_GREEN("\n" "mine_next_pow_block_in_playtime(m_scratchpad_keeper, )", LOG_LEVEL_0); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); @@ -2694,8 +2694,8 @@ bool escrow_cancellation_proposal_expiration::c1(currency::core& c, size_t ev_in CHECK_AND_ASSERT_MES(refresh_wallet_and_check_1_contract_state("Bob", bob_wlt, tools::wallet_rpc::escrow_contract_details::contract_cancel_proposal_sent, 1), false, ""); // mine one more block (it's necessary for triggering expiration checks in wallets and shifting an expiration ts median) - LOG_PRINT_GREEN("\n" "mine_next_pow_block_in_playtime()", LOG_LEVEL_0); - r = mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, 7); + LOG_PRINT_GREEN("\n" "mine_next_pow_block_in_playtime(m_scratchpad_keeper, )", LOG_LEVEL_0); + r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, 7); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); @@ -2810,7 +2810,7 @@ bool escrow_cancellation_acceptance_expiration::c1(currency::core& c, size_t ev_ // mine a block, containing escrow proposal tx CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); @@ -2825,7 +2825,7 @@ bool escrow_cancellation_acceptance_expiration::c1(currency::core& c, size_t ev_ // mine a block containing contract acceptance CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); @@ -2838,7 +2838,7 @@ bool escrow_cancellation_acceptance_expiration::c1(currency::core& c, size_t ev_ // confirm cancellation request in blockchain CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); - CHECK_AND_ASSERT_MES(mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c), false, "mine_next_pow_block_in_playtime failed"); + CHECK_AND_ASSERT_MES(mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c), false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); // contract state in wallets should be cancel_proposal_sent for both parties @@ -2862,7 +2862,7 @@ bool escrow_cancellation_acceptance_expiration::c1(currency::core& c, size_t ev_ // mine a few blocks with no txs to shift expiration median, cancellation acceptance is still in the pool for(size_t i = 0; i < 7; ++i) { - r = mine_next_pow_block_in_playtime_with_given_txs(m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector()); + r = mine_next_pow_block_in_playtime_with_given_txs(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector()); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime_with_given_txs failed"); } CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); @@ -2886,7 +2886,7 @@ bool escrow_cancellation_acceptance_expiration::c1(currency::core& c, size_t ev_ CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); // mine a block with cancel_accept_tx (already expired). It should be rejected - r = mine_next_pow_block_in_playtime_with_given_txs(m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector({ cancel_accept_tx })); + r = mine_next_pow_block_in_playtime_with_given_txs(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector({ cancel_accept_tx })); CHECK_AND_ASSERT_MES(!r, false, "mine_next_pow_block_in_playtime_with_given_txs should have been failed as block contains expired tx"); // no changes with contract state expected @@ -2968,6 +2968,6 @@ bool escrow_proposal_acceptance_in_alt_chain::generate(std::vector& events) { - //mine_next_pow_block_in_playtime() + //mine_next_pow_block_in_playtime(m_scratchpad_keeper, ) return true; } diff --git a/tests/core_tests/misc_tests.cpp b/tests/core_tests/misc_tests.cpp index ac4feddd..80c800ca 100644 --- a/tests/core_tests/misc_tests.cpp +++ b/tests/core_tests/misc_tests.cpp @@ -347,7 +347,7 @@ bool block_template_vs_invalid_txs_from_pool::check_block_template(currency::cor bool r = false; currency::block b = AUTO_VAL_INIT(b); - r = mine_next_pow_block_in_playtime(addr, c, &b); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, addr, c, &b); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); return true; diff --git a/tests/core_tests/mixin_attr.cpp b/tests/core_tests/mixin_attr.cpp index ac4fec15..3d68039b 100644 --- a/tests/core_tests/mixin_attr.cpp +++ b/tests/core_tests/mixin_attr.cpp @@ -289,7 +289,7 @@ bool mix_in_spent_outs::c1(currency::core& c, size_t ev_index, const std::vector CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect number of txs in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "There are txs in the pool"); diff --git a/tests/core_tests/multisig_wallet_tests.cpp b/tests/core_tests/multisig_wallet_tests.cpp index e5139134..6a767414 100644 --- a/tests/core_tests/multisig_wallet_tests.cpp +++ b/tests/core_tests/multisig_wallet_tests.cpp @@ -160,7 +160,7 @@ bool multisig_wallet_test::c1(currency::core& c, size_t ev_index, const std::vec transaction result_tx = AUTO_VAL_INIT(result_tx); miner_wlt->transfer(dst, 0, 0, TX_DEFAULT_FEE, extra, attachments, tools::detail::digit_split_strategy, tools::tx_dust_policy(DEFAULT_DUST_THRESHOLD), result_tx); - bool r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + bool r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, m_mining_accunt.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); //findout multisig out intex @@ -175,7 +175,7 @@ bool multisig_wallet_test::c1(currency::core& c, size_t ev_index, const std::vec crypto::hash multisig_id = get_multisig_out_id(result_tx, i); CHECK_AND_ASSERT_MES(multisig_id != null_hash, false, "Multisig failed: failed to get get_multisig_out_id"); - r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, m_mining_accunt.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); std::shared_ptr wallet_a = init_playtime_test_wallet(events, c, m_accunt_a); @@ -208,7 +208,7 @@ bool multisig_wallet_test::c1(currency::core& c, size_t ev_index, const std::vec tools::tx_dust_policy(DEFAULT_DUST_THRESHOLD), result_tx); - r = mine_next_pow_blocks_in_playtime(m_mining_accunt.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, m_mining_accunt.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); wallet_a->refresh(); @@ -300,7 +300,7 @@ bool multisig_wallet_test_many_dst::c1(currency::core& c, size_t ev_index, const CHECK_AND_ASSERT_MES(it != result_tx.vout.end(), false, "Can't find output txout_multisig"); size_t multisig_index = it - result_tx.vout.begin(); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); std::shared_ptr w = init_playtime_test_wallet(events, c, addresses[0]); @@ -317,7 +317,7 @@ bool multisig_wallet_test_many_dst::c1(currency::core& c, size_t ev_index, const transfer_multisig(*w.get(), owner_keys, get_multisig_out_id(result_tx, multisig_index), std::vector({ de2 }), 0, TESTS_DEFAULT_FEE, std::vector(), std::vector(), tools::detail::digit_split_strategy, tools::tx_dust_policy(DEFAULT_DUST_THRESHOLD), tx); TMP_LOG_RESTORE; - r = mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, m_accounts[ALICE_ACC_IDX]); @@ -428,7 +428,7 @@ bool multisig_wallet_heterogenous_dst::c1(currency::core& c, size_t ev_index, co // Mine a block and make sure tx was put into it CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -487,7 +487,7 @@ bool multisig_wallet_heterogenous_dst::c1(currency::core& c, size_t ev_index, co 0, TX_DEFAULT_FEE, std::vector(), std::vector(), tools::detail::digit_split_strategy, tools::tx_dust_policy(DEFAULT_DUST_THRESHOLD), tx); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); // Once Bob refreshes his wallet he should see that Alice has already spent they shared multisig @@ -549,7 +549,7 @@ bool multisig_wallet_heterogenous_dst::c1(currency::core& c, size_t ev_index, co 0, TX_DEFAULT_FEE, std::vector(), std::vector(), tools::detail::digit_split_strategy, tools::tx_dust_policy(DEFAULT_DUST_THRESHOLD), tx); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "There are txs in the pool."); @@ -584,7 +584,7 @@ bool multisig_wallet_heterogenous_dst::c1(currency::core& c, size_t ev_index, co CHECK_AND_ASSERT_MES(caught, false, "Dan was able to make multisig tx for alreadly spent output"); // Miner mines the next PoW block, confirming Alice's transaction. - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "There are txs in the pool."); @@ -689,7 +689,7 @@ bool multisig_wallet_same_dst_addr::c1(currency::core& c, size_t ev_index, const // mine the next PoW and make sure everythig is allright CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect number of tx in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "There are transactions in the pool"); @@ -707,7 +707,7 @@ bool multisig_wallet_same_dst_addr::c1(currency::core& c, size_t ev_index, const 0, TX_DEFAULT_FEE, empty_extra, empty_attachment, tools::detail::digit_split_strategy, tools::tx_dust_policy(DEFAULT_DUST_THRESHOLD), tx); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect number of tx in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "There are transactions in the pool"); @@ -778,7 +778,7 @@ bool multisig_wallet_ms_to_ms::c1(currency::core& c, size_t ev_index, const std: // mine the next PoW and make sure everythig is allright CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect number of tx in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "There are transactions in the pool"); @@ -802,7 +802,7 @@ bool multisig_wallet_ms_to_ms::c1(currency::core& c, size_t ev_index, const std: // check the pool and mine a block CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect number of tx in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "There are transactions in the pool"); @@ -818,7 +818,7 @@ bool multisig_wallet_ms_to_ms::c1(currency::core& c, size_t ev_index, const std: 0, TX_DEFAULT_FEE, empty_extra, empty_attachment, tools::detail::digit_split_strategy, tools::tx_dust_policy(DEFAULT_DUST_THRESHOLD), tx); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect number of tx in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "There are transactions in the pool"); @@ -1625,7 +1625,7 @@ multisig_and_checkpoints::multisig_and_checkpoints() bool multisig_and_checkpoints::set_cp(currency::core& c, size_t ev_index, const std::vector& events) { currency::checkpoints checkpoints; - checkpoints.add_checkpoint(15, "79a45b39dbac12bfc2e432734e64db45d1af83509cfd20f4f73e14968192ea80"); + checkpoints.add_checkpoint(15, "697d829dd0898fd8c766f5cfc9c174ba353d0c0ebf48def8edec0e2f2e355781"); c.set_checkpoints(std::move(checkpoints)); return true; @@ -2490,14 +2490,14 @@ bool multisig_unconfirmed_transfer_and_multiple_scan_pool_calls::c1(currency::co transaction key_to_ms_tx = AUTO_VAL_INIT(key_to_ms_tx); miner_wlt->transfer(dst, 0, 0, TX_DEFAULT_FEE, extra, attachments, tools::detail::digit_split_strategy, tools::tx_dust_policy(DEFAULT_DUST_THRESHOLD), key_to_ms_tx); - bool r = mine_next_pow_blocks_in_playtime(miner_acc.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + bool r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, miner_acc.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); size_t ms_out_idx = get_multisig_out_index(key_to_ms_tx.vout); crypto::hash multisig_id = get_multisig_out_id(key_to_ms_tx, ms_out_idx); CHECK_AND_ASSERT_MES(multisig_id != null_hash, false, "Multisig failed: failed to get get_multisig_out_id"); - //r = mine_next_pow_blocks_in_playtime(miner_acc.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + //r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, miner_acc.get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); //CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); std::shared_ptr alice_wlt = init_playtime_test_wallet(events, c, alice_acc); diff --git a/tests/core_tests/offers_test.cpp b/tests/core_tests/offers_test.cpp index ca72b906..8a24e711 100644 --- a/tests/core_tests/offers_test.cpp +++ b/tests/core_tests/offers_test.cpp @@ -567,7 +567,7 @@ bool offers_handling_on_chain_switching::c1(currency::core& c, size_t ev_index, uint64_t blk_1r_height = c.get_current_blockchain_size() - 2; crypto::hash blk_1r_id = c.get_block_id_by_height(blk_1r_height); block blk_2a = AUTO_VAL_INIT(blk_2a); - r = mine_next_pow_block_in_playtime_with_given_txs(m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector(), blk_1r_id, blk_1r_height + 1, &blk_2a); + r = mine_next_pow_block_in_playtime_with_given_txs(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector(), blk_1r_id, blk_1r_height + 1, &blk_2a); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime_with_given_txs failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); @@ -577,7 +577,7 @@ bool offers_handling_on_chain_switching::c1(currency::core& c, size_t ev_index, // mine second alt block (include offer tx) -- this should trigger chain switching block blk_3a = AUTO_VAL_INIT(blk_3a); - r = mine_next_pow_block_in_playtime_with_given_txs(m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector({tx_1}), get_block_hash(blk_2a), blk_1r_height + 2, &blk_3a); + r = mine_next_pow_block_in_playtime_with_given_txs(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector({tx_1}), get_block_hash(blk_2a), blk_1r_height + 2, &blk_3a); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime_with_given_txs failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); @@ -673,7 +673,7 @@ bool offer_removing_and_selected_output::check_offers(currency::core& c, size_t crypto::hash create_offer_tx_id = get_transaction_hash(create_offer_tx); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); - CHECK_AND_ASSERT_MES(mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c), false, "mine_next_pow_block_in_playtime failed"); + CHECK_AND_ASSERT_MES(mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c), false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); refresh_wallet_and_check_balance("offer's put into the blockchain", "Alice", alice_wlt, alice_start_balance - od.fee, true, 1); @@ -699,7 +699,7 @@ bool offer_removing_and_selected_output::check_offers(currency::core& c, size_t // add it to the blockchain CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); - CHECK_AND_ASSERT_MES(mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c), false, "mine_next_pow_block_in_playtime failed"); + CHECK_AND_ASSERT_MES(mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c), false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); // Alice's banace should not change @@ -937,7 +937,7 @@ bool offers_updating_hack::update_foreign_offer(currency::core& c, size_t ev_ind // put in a block 'tx', leave Alice's tx in the pool CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 2, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); - CHECK_AND_ASSERT_MES(mine_next_pow_block_in_playtime_with_given_txs(m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector({ tx })), false, "mine_next_pow_block_in_playtime failed"); + CHECK_AND_ASSERT_MES(mine_next_pow_block_in_playtime_with_given_txs(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector({ tx })), false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); LOG_PRINT_L0(ENDL << c.get_tx_pool().print_pool(true)); @@ -1005,7 +1005,7 @@ bool offers_updating_hack::delete_foreign_offer(currency::core& c, size_t ev_ind // put in a block 'tx', leave Alice's tx in the pool CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 2, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); - CHECK_AND_ASSERT_MES(mine_next_pow_block_in_playtime_with_given_txs(m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector({ tx_c })), false, "mine_next_pow_block_in_playtime failed"); + CHECK_AND_ASSERT_MES(mine_next_pow_block_in_playtime_with_given_txs(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector({ tx_c })), false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); LOG_PRINT_L0(ENDL << c.get_tx_pool().print_pool(true)); @@ -1264,7 +1264,7 @@ bool offer_lifecycle_via_tx_pool::c1(currency::core& c, size_t ev_index, const s CATCH_ENTRY2(false); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Invalid tx pool count: " << c.get_pool_transactions_count() << ENDL << "tx pool:" << ENDL << c.get_tx_pool().print_pool(true)); - r = mine_next_pow_block_in_playtime(some_addr, c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, some_addr, c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Invalid tx pool count: " << c.get_pool_transactions_count() << ENDL << "tx pool:" << ENDL << c.get_tx_pool().print_pool(true)); @@ -1280,7 +1280,7 @@ bool offer_lifecycle_via_tx_pool::c1(currency::core& c, size_t ev_index, const s CATCH_ENTRY2(false); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Invalid tx pool count: " << c.get_pool_transactions_count() << ENDL << "tx pool:" << ENDL << c.get_tx_pool().print_pool(true)); - r = mine_next_pow_block_in_playtime(some_addr, c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, some_addr, c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Invalid tx pool count: " << c.get_pool_transactions_count() << ENDL << "tx pool:" << ENDL << c.get_tx_pool().print_pool(true)); @@ -1297,7 +1297,7 @@ bool offer_lifecycle_via_tx_pool::c1(currency::core& c, size_t ev_index, const s CATCH_ENTRY2(false); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Invalid tx pool count: " << c.get_pool_transactions_count() << ENDL << "tx pool:" << ENDL << c.get_tx_pool().print_pool(true)); - r = mine_next_pow_block_in_playtime(some_addr, c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, some_addr, c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Invalid tx pool count: " << c.get_pool_transactions_count() << ENDL << "tx pool:" << ENDL << c.get_tx_pool().print_pool(true)); @@ -1313,7 +1313,7 @@ bool offer_lifecycle_via_tx_pool::c1(currency::core& c, size_t ev_index, const s CATCH_ENTRY2(false); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Invalid tx pool count: " << c.get_pool_transactions_count() << ENDL << "tx pool:" << ENDL << c.get_tx_pool().print_pool(true)); - r = mine_next_pow_block_in_playtime(some_addr, c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, some_addr, c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Invalid tx pool count: " << c.get_pool_transactions_count() << ENDL << "tx pool:" << ENDL << c.get_tx_pool().print_pool(true)); diff --git a/tests/core_tests/pos_validation.cpp b/tests/core_tests/pos_validation.cpp index 2757a225..9c45addf 100644 --- a/tests/core_tests/pos_validation.cpp +++ b/tests/core_tests/pos_validation.cpp @@ -495,7 +495,7 @@ bool pos_wallet_minting_same_amount_diff_outs::prepare_wallets_0(currency::core& r = populate_wallet_with_stake_coins(w.w, alice_wlt, w.pos_entries_count, m_wallet_stake_amount, pos_amounts); CHECK_AND_ASSERT_MES(r, false, "populate_wallet_with_stake_coins failed"); - r = mine_next_pow_blocks_in_playtime(alice_wlt->get_account().get_public_address(), c, WALLET_DEFAULT_TX_SPENDABLE_AGE + 1); // to preventing run out of the money for Alice + r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, alice_wlt->get_account().get_public_address(), c, WALLET_DEFAULT_TX_SPENDABLE_AGE + 1); // to preventing run out of the money for Alice CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); c.get_blockchain_storage().get_top_block(b); uint64_t ts = b.timestamp; @@ -552,7 +552,7 @@ bool pos_wallet_minting_same_amount_diff_outs::prepare_wallets_1(currency::core& r = populate_wallet_with_stake_coins(w.w, alice_wlt, w.pos_entries_count, m_wallet_stake_amount, pos_amounts); CHECK_AND_ASSERT_MES(r, false, "populate_wallet_with_stake_coins failed"); - r = mine_next_pow_blocks_in_playtime(alice_wlt->get_account().get_public_address(), c, WALLET_DEFAULT_TX_SPENDABLE_AGE + 1); // to preventing run out of the money for Alice + r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, alice_wlt->get_account().get_public_address(), c, WALLET_DEFAULT_TX_SPENDABLE_AGE + 1); // to preventing run out of the money for Alice CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); c.get_blockchain_storage().get_top_block(b); uint64_t ts = b.timestamp; @@ -662,7 +662,7 @@ bool pos_wallet_minting_same_amount_diff_outs::c1(currency::core& c, size_t ev_i ts = ideal_next_pow_block_ts; // "wait" until ideal_next_pow_block_ts if it was not already happened (fast forward but don't wayback the time) test_core_time::adjust(ts); size_t tx_count_before = c.get_pool_transactions_count(); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(tx_count_before == 0 || c.get_pool_transactions_count() < tx_count_before, false, "invalid number of txs in tx pool: " << c.get_pool_transactions_count() << ", was: " << tx_count_before); last_pow_block_ts = ts; diff --git a/tests/core_tests/tx_validation.cpp b/tests/core_tests/tx_validation.cpp index b8af35f7..5062d752 100644 --- a/tests/core_tests/tx_validation.cpp +++ b/tests/core_tests/tx_validation.cpp @@ -1309,7 +1309,7 @@ bool tx_expiration_time_and_block_template::c1(currency::core& c, size_t ev_inde CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect tx count in the pool: " << c.get_pool_transactions_count()); account_public_address addr = AUTO_VAL_INIT(addr); - bool r = mine_next_pow_block_in_playtime(addr, c); + bool r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, addr, c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); // tx MAY stay in the pool, check it as forced condition (may change in future) diff --git a/tests/core_tests/wallet_rpc_tests.cpp b/tests/core_tests/wallet_rpc_tests.cpp index c4ee2e51..34293b18 100644 --- a/tests/core_tests/wallet_rpc_tests.cpp +++ b/tests/core_tests/wallet_rpc_tests.cpp @@ -137,7 +137,7 @@ bool wallet_rpc_integrated_address_transfer::c1(currency::core& c, size_t ev_ind CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "enexpected pool txs count: " << c.get_pool_transactions_count()); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Tx pool is not empty: " << c.get_pool_transactions_count()); @@ -171,7 +171,7 @@ bool wallet_rpc_integrated_address_transfer::c1(currency::core& c, size_t ev_ind CHECK_AND_ASSERT_MES(r, false, "RPC call failed, code: " << je.code << ", msg: " << je.message); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "enexpected pool txs count: " << c.get_pool_transactions_count()); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Tx pool is not empty: " << c.get_pool_transactions_count()); diff --git a/tests/core_tests/wallet_tests.cpp b/tests/core_tests/wallet_tests.cpp index 0cbc7551..71427959 100644 --- a/tests/core_tests/wallet_tests.cpp +++ b/tests/core_tests/wallet_tests.cpp @@ -1179,7 +1179,7 @@ bool gen_wallet_oversized_payment_id::c1(currency::core& c, size_t ev_index, con CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Tx pool has incorrect number of txs: " << c.get_pool_transactions_count()); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Tx pool is not empty: " << c.get_pool_transactions_count()); @@ -1215,7 +1215,7 @@ bool gen_wallet_oversized_payment_id::c1(currency::core& c, size_t ev_index, con CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Tx pool has incorrect number of txs: " << c.get_pool_transactions_count()); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Tx pool is not empty: " << c.get_pool_transactions_count()); @@ -1769,7 +1769,7 @@ bool gen_wallet_alias_via_special_wallet_funcs::c1(currency::core& c, size_t ev_ CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - bool r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + bool r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -1790,7 +1790,7 @@ bool gen_wallet_alias_via_special_wallet_funcs::c1(currency::core& c, size_t ev_ CHECK_AND_ASSERT_MES(l->m_result, false, "Wrong wti received via callback"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); CHECK_AND_ASSERT_MES(c.get_current_blockchain_size() == 2 + CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 1 + WALLET_DEFAULT_TX_SPENDABLE_AGE + 2, false, "Incorrect blockchain size"); @@ -1803,7 +1803,7 @@ bool gen_wallet_alias_via_special_wallet_funcs::c1(currency::core& c, size_t ev_ alice_wlt->request_alias_update(ai, res_tx, TX_DEFAULT_FEE, 0); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); CHECK_AND_ASSERT_MES(c.get_current_blockchain_size() == 2 + CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 1 + WALLET_DEFAULT_TX_SPENDABLE_AGE + 3, false, "Incorrect blockchain size"); @@ -2072,7 +2072,7 @@ bool gen_wallet_offers_basic::c1(currency::core& c, size_t ev_index, const std:: CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 2, false, "Incorrect txs count in the pool"); - bool r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + bool r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -2123,7 +2123,7 @@ bool gen_wallet_offers_basic::c1(currency::core& c, size_t ev_index, const std:: CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -2154,7 +2154,7 @@ bool gen_wallet_offers_basic::c1(currency::core& c, size_t ev_index, const std:: CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool"); @@ -2274,7 +2274,7 @@ bool gen_wallet_offers_size_limit::c1(currency::core& c, size_t ev_index, const log_space::get_set_log_detalisation_level(true, log_level); // restore CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); miner_wlt->refresh(blocks_fetched, received_money, atomic_false); CHECK_AND_ASSERT_MES(blocks_fetched == 1, false, "Incorrect numbers of blocks fetched"); @@ -2373,7 +2373,7 @@ bool gen_wallet_dust_to_account::c1(currency::core& c, size_t ev_index, const st CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - bool r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + bool r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); miner_wlt->refresh(blocks_fetched, received_money, atomic_false); @@ -2473,7 +2473,7 @@ bool gen_wallet_selecting_pos_entries::c1(currency::core& c, size_t ev_index, co CHECK_AND_ASSERT_MES(c.get_current_blockchain_size() == CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3 + 1 + WALLET_DEFAULT_TX_SPENDABLE_AGE - 1, false, "Incorrect current blockchain height"); // this block should unlock the money and PoS-entries should become available - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); alice_wlt->refresh(blocks_fetched, received_money, atomic_false); CHECK_AND_ASSERT_MES(blocks_fetched == 1, false, "Incorrect number of blocks fetched"); @@ -2497,7 +2497,7 @@ bool gen_wallet_selecting_pos_entries::c1(currency::core& c, size_t ev_index, co alice_wlt->transfer(dst, 0, 0, TX_DEFAULT_FEE, std::vector(), std::vector()); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); alice_wlt->refresh(blocks_fetched, received_money, atomic_false); CHECK_AND_ASSERT_MES(blocks_fetched == 1, false, "Incorrect number of blocks fetched"); @@ -2571,7 +2571,7 @@ bool gen_wallet_spending_coinstake_after_minting::c1(currency::core& c, size_t e CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool"); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); alice_wlt->refresh(blocks_fetched, received_money, atomic_false); CHECK_AND_ASSERT_MES(blocks_fetched == 1, false, "Incorrect number of blocks fetched"); @@ -2878,7 +2878,7 @@ bool mined_balance_wallet_test::c1(currency::core& c, size_t ev_index, const std std::list blocks; size_t n = CURRENCY_MINED_MONEY_UNLOCK_WINDOW; - r = mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, n); + r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, n); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); r = bcs.get_blocks(bcs.get_current_blockchain_size() - n, n, blocks); CHECK_AND_ASSERT_MES(r, false, "get_blocks failed"); @@ -2994,11 +2994,11 @@ bool wallet_outputs_with_same_key_image::c1(currency::core& c, size_t ev_index, bool r = refresh_wallet_and_check_balance("before tx_1 and tx_2 added", "Alice", alice_wlt, MK_TEST_COINS(3) * 2, true, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 2, 0); CHECK_AND_ASSERT_MES(r, false, ""); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "there are txs in the pool!"); - r = mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + r = mine_next_pow_blocks_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); // only one tx_1 output is counted as the tx_2 output has the very same key image @@ -3017,7 +3017,7 @@ bool wallet_outputs_with_same_key_image::c1(currency::core& c, size_t ev_index, } CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "wrong tx count in the pool: " << c.get_pool_transactions_count()); - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "there are txs in the pool!"); @@ -3097,7 +3097,7 @@ bool wallet_unconfirmed_tx_expiration::c1(currency::core& c, size_t ev_index, co // mine a few block with no tx, so Alice's tx is expired in the pool for (size_t i = 0; i < 5; ++i) { - r = mine_next_pow_block_in_playtime_with_given_txs(m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector()); + r = mine_next_pow_block_in_playtime_with_given_txs(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c, std::vector()); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime_with_given_txs failed"); } @@ -3114,7 +3114,7 @@ bool wallet_unconfirmed_tx_expiration::c1(currency::core& c, size_t ev_index, co CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Invalid txs count in the pool: " << c.get_pool_transactions_count()); // mine one more block to trigger wallet's on_idle() and outdated tx clearing - r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + r = mine_next_pow_block_in_playtime(m_scratchpad_keeper, m_accounts[MINER_ACC_IDX].get_public_address(), c); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); // make sure all Alice's money are unlocked and no coins were actually spent diff --git a/tests/performance_tests/keccak_test.h b/tests/performance_tests/keccak_test.h new file mode 100644 index 00000000..668a9873 --- /dev/null +++ b/tests/performance_tests/keccak_test.h @@ -0,0 +1,235 @@ +// Copyright (c) 2012-2013 The Boolberry developers +// Copyright (c) 2012-2013 The Zano developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once + +#include "crypto/crypto.h" +#include "currency_core/currency_basic.h" + + +extern "C" { +#include "crypto/keccak.h" +//#include "crypto/alt/KeccakNISTInterface.h" +} + + +#include "crypto/wild_keccak.h" +//#include "crypto/wild_keccak2.h" +#include "../core_tests/random_helper.h" + + + + + +#define TEST_BUFF_LEN 200 + +class test_keccak_base +{ +public: + static const size_t loop_count = 100000; + + bool init() + { + currency::block b; + m_buff = currency::get_block_hashing_blob(b); + m_buff.append(32 * 4, 0); + return true; + } + + bool pretest() + { + ++m_buff[0]; + if (!m_buff[0]) + ++m_buff[0]; + return true; + } +protected: + std::string m_buff; +}; + +// class test_keccak : public test_keccak_base +// { +// public: +// bool test() +// { +// pretest(); +// crypto::hash h; +// keccak(reinterpret_cast(&m_buff[0]), m_buff.size(), reinterpret_cast(&h), sizeof(h)); +// LOG_PRINT_L4(h); +// return true; +// } +// }; + + +class test_keccak_generic : public test_keccak_base +{ +public: + bool test() + { + pretest(); + crypto::hash h; + crypto::keccak_generic(reinterpret_cast(&m_buff[0]), m_buff.size(), reinterpret_cast(&h), sizeof(h)); + LOG_PRINT_L4(h); + return true; + } +}; + +class test_keccak_generic_with_mul : public test_keccak_base +{ +public: + bool test() + { + pretest(); + crypto::hash h; + crypto::keccak_generic(reinterpret_cast(&m_buff[0]), m_buff.size(), reinterpret_cast(&h), sizeof(h)); + return true; + } +}; + +template +class test_wild_keccak : public test_keccak_base +{ +public: + bool init() + { + m_scratchpad_vec.resize(scratchpad_size / sizeof(crypto::hash)); + for (auto& h : m_scratchpad_vec) + h = crypto::rand(); + + return test_keccak_base::init(); + } + + bool test() + { + pretest(); + + crypto::hash h; + crypto::wild_keccak_dbl(reinterpret_cast(&m_buff[0]), m_buff.size(), reinterpret_cast(&h), sizeof(h), [&](crypto::state_t_m& st, crypto::mixin_t& mix) + { +#define SCR_I(i) m_scratchpad_vec[st[i]%m_scratchpad_vec.size()] + for (size_t i = 0; i != 6; i++) + { + *(crypto::hash*)&mix[i * 4] = XOR_4(SCR_I(i * 4), SCR_I(i * 4 + 1), SCR_I(i * 4 + 2), SCR_I(i * 4 + 3)); + } + }); + + return true; + } +protected: + std::vector m_scratchpad_vec; +}; + +// +// template +// class test_wild_keccak2 : public test_keccak_base +// { +// public: +// bool init() +// { +// m_scratchpad_vec.resize(scratchpad_size / sizeof(crypto::hash)); +// for (auto& h : m_scratchpad_vec) +// h = crypto::rand(); +// +// return test_keccak_base::init(); +// } +// +// bool test() +// { +// pretest(); +// +// crypto::hash h2; +// crypto::wild_keccak_dbl_opt(reinterpret_cast(&m_buff[0]), m_buff.size(), reinterpret_cast(&h2), sizeof(h2), (const UINT64*)&m_scratchpad_vec[0], m_scratchpad_vec.size() * 4); +// LOG_PRINT_L4("HASH:" << h2); +// return true; +// } +// protected: +// std::vector m_scratchpad_vec; +// }; + +#ifdef _DEBUG + #define max_measere_scratchpad 100000 +#else + #define max_measere_scratchpad 10000000 +#endif +#define measere_rounds 10000 +void measure_keccak_over_scratchpad() +{ + std::cout << std::setw(20) << std::left << "sz\t" << + //std::setw(10) << "original\t" << + std::setw(10) << "original opt\t" << +// std::setw(10) << "w2\t" << + std::setw(10) << "w2_opt" << ENDL; + + std::vector scratchpad_vec; + scratchpad_vec.resize(max_measere_scratchpad); + std::string has_str = "Keccak is a family of sponge functions. The sponge function is a generalization of the concept of cryptographic hash function with infinite output and can perform quasi all symmetric cryptographic functions, from hashing to pseudo-random number generation to authenticated encryption"; + + //static const uint64_t my_own_random_seed = 4669201609102990671; + //random_state_test_restorer::reset_random(my_own_random_seed); // random seeded, entering deterministic mode... + //uint64_t size_original = scratchpad_vec.size(); + //scratchpad_vec.resize(i / sizeof(crypto::hash)); + for (size_t j = 0; j != scratchpad_vec.size(); j++) + scratchpad_vec[j] = crypto::rand(); + + + crypto::hash res_to_test = { 0 }; + crypto::hash res_etalon = { 0 }; + OPT_XOR_4_RES(scratchpad_vec[0], scratchpad_vec[1], scratchpad_vec[2], scratchpad_vec[3], res_to_test); + res_etalon = XOR_4(scratchpad_vec[0], scratchpad_vec[1], scratchpad_vec[2], scratchpad_vec[3]); + + +// +// crypto::hash res_h1 = currency::null_hash; +// res_h1 = crypto::get_wild_keccak2_over_scratchpad(has_str, 1, scratchpad_vec, 1000); +// +// crypto::hash res_h2 = currency::null_hash; +// crypto::get_wild_keccak2(has_str, res_h2, 1, scratchpad_vec, 1000); +// if (res_h2 != res_h1) +// { +// return; +// } + + for (uint64_t i = 1000; i < max_measere_scratchpad; i += 100000) + { + + crypto::hash res_h = currency::null_hash; + uint64_t ticks_a = epee::misc_utils::get_tick_count(); + *(uint64_t*)(&has_str[8]) = i; + //original keccak +// for (size_t r = 0; r != measere_rounds; r++) +// { +// *(size_t*)(&has_str[0]) = r; +// res_h = crypto::get_blob_longhash(has_str, 1, scratchpad_vec, i); +// } + //original keccak opt + uint64_t ticks_b = epee::misc_utils::get_tick_count(); + for (size_t r = 0; r != measere_rounds; r++) + { + *(size_t*)(&has_str[1]) = r; + crypto::get_wild_keccak(has_str, res_h, 1, scratchpad_vec, i); + } + + //wild keccak 2 + uint64_t ticks_c = epee::misc_utils::get_tick_count(); +// for (size_t r = 0; r != measere_rounds; r++) +// { +// *(size_t*)(&has_str[1]) = r; +// res_h = crypto::get_wild_keccak2_over_scratchpad(has_str, 1, scratchpad_vec, i); +// } + //wild keccak 2 opt + uint64_t ticks_d = epee::misc_utils::get_tick_count(); + for (size_t r = 0; r != measere_rounds; r++) + { + crypto::get_wild_keccak2(has_str, res_h, 1, scratchpad_vec, i); + } + + uint64_t ticks_e = epee::misc_utils::get_tick_count(); + std::cout << std::setw(20) << std::left << i * sizeof(crypto::hash) << "\t" << + //std::setw(10) << ticks_b - ticks_a << "\t" << + std::setw(10) << ticks_c - ticks_b << "\t" << + //std::setw(10) << ticks_d - ticks_c << "\t" << + std::setw(10) << ticks_e - ticks_d << ENDL; + } +} diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index ebcf36f7..49728abb 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -17,6 +17,7 @@ #include "is_out_to_acc.h" #include "core_market_performance_test.h" #include "serialization_performance_test.h" +#include "keccak_test.h" int main(int argc, char** argv) { @@ -24,7 +25,7 @@ int main(int argc, char** argv) epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2); epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2); - run_serialization_performance_test(); + //run_serialization_performance_test(); //return 1; //run_core_market_performance_tests(100000); @@ -34,6 +35,8 @@ int main(int argc, char** argv) performance_timer timer; timer.start(); + measure_keccak_over_scratchpad(); + /* TEST_PERFORMANCE2(test_construct_tx, 1, 1); TEST_PERFORMANCE2(test_construct_tx, 1, 2); @@ -61,11 +64,11 @@ int main(int argc, char** argv) TEST_PERFORMANCE1(test_check_ring_signature, 10); TEST_PERFORMANCE1(test_check_ring_signature, 100); */ - TEST_PERFORMANCE0(test_is_out_to_acc); + //TEST_PERFORMANCE0(test_is_out_to_acc); //TEST_PERFORMANCE0(test_generate_key_image_helper); - TEST_PERFORMANCE0(test_generate_key_derivation); + //TEST_PERFORMANCE0(test_generate_key_derivation); //TEST_PERFORMANCE0(test_generate_key_image); - TEST_PERFORMANCE0(test_derive_public_key); + //TEST_PERFORMANCE0(test_derive_public_key); //TEST_PERFORMANCE0(test_derive_secret_key); std::cout << "Tests finished. Elapsed time: " << timer.elapsed_ms() / 1000 << " sec" << std::endl;