diff --git a/src/crypto/chacha8.h b/src/crypto/chacha8.h index f098620..cf07c6e 100644 --- a/src/crypto/chacha8.h +++ b/src/crypto/chacha8.h @@ -73,7 +73,7 @@ namespace crypto { inline void generate_chacha8_key(std::string password, chacha8_key& key) { static_assert(sizeof(chacha8_key) <= sizeof(hash), "Size of hash must be at least that of chacha8_key"); char pwd_hash[HASH_SIZE]; - crypto::cn_slow_hash(password.data(), password.size(), pwd_hash); + crypto::cn_slow_hash_2m(password.data(), password.size(), pwd_hash); memcpy(&key, pwd_hash, sizeof(key)); memset(pwd_hash, 0, sizeof(pwd_hash)); } diff --git a/src/crypto/hash-ops.h b/src/crypto/hash-ops.h index f779314..ab2ca1a 100644 --- a/src/crypto/hash-ops.h +++ b/src/crypto/hash-ops.h @@ -79,7 +79,9 @@ enum { }; void cn_fast_hash(const void *data, size_t length, char *hash); -void cn_slow_hash(const void *data, size_t length, char *hash); +void cn_slow_hash(const void *data, size_t length, char *hash, int light); +inline void cn_slow_hash_1m(const void *data, size_t length, char *hash) { cn_slow_hash(data,length,hash,1); } +inline void cn_slow_hash_2m(const void *data, size_t length, char *hash) { cn_slow_hash(data,length,hash,0); } void hash_extra_blake(const void *data, size_t length, char *hash); void hash_extra_groestl(const void *data, size_t length, char *hash); diff --git a/src/crypto/hash.h b/src/crypto/hash.h index 0cade64..ee1268d 100644 --- a/src/crypto/hash.h +++ b/src/crypto/hash.h @@ -63,8 +63,12 @@ namespace crypto { return h; } - inline void cn_slow_hash(const void *data, std::size_t length, hash &hash) { - cn_slow_hash(data, length, reinterpret_cast(&hash)); + inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int light) { + cn_slow_hash(data, length, reinterpret_cast(&hash), light); + } + + inline void cn_slow_hash_2m(const void *data, std::size_t length, hash &hash) { + cn_slow_hash(data, length, hash, 0); } inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) { diff --git a/src/crypto/slow-hash.c b/src/crypto/slow-hash.c index af15170..24615b9 100644 --- a/src/crypto/slow-hash.c +++ b/src/crypto/slow-hash.c @@ -76,7 +76,7 @@ #define U64(x) ((uint64_t *) (x)) #define R128(x) ((__m128i *) (x)) -#define state_index(x) (((*((uint64_t *)x) >> 4) & (TOTALBLOCKS - 1)) << 4) +#define state_index(x,div) (((*((uint64_t *)x) >> 4) & (TOTALBLOCKS /(div) - 1)) << 4) #if defined(_MSC_VER) #if !defined(_WIN64) #define __mul() lo = mul128(c[0], b[0], &hi); @@ -92,7 +92,7 @@ #endif #define pre_aes() \ - j = state_index(a); \ + j = state_index(a,(light?2:1)); \ _c = _mm_load_si128(R128(&hp_state[j])); \ _a = _mm_load_si128(R128(a)); \ @@ -101,7 +101,7 @@ _mm_store_si128(R128(c), _c); \ _b = _mm_xor_si128(_b, _c); \ _mm_store_si128(R128(&hp_state[j]), _b); \ - j = state_index(c); \ + j = state_index(c,(light?2:1)); \ p = U64(&hp_state[j]); \ b[0] = p[0]; b[1] = p[1]; \ __mul(); \ @@ -321,7 +321,6 @@ BOOL SetLockPagesPrivilege(HANDLE hProcess, BOOL bEnable) void slow_hash_allocate_state(void) { - int state = 0; if(hp_state != NULL) return; @@ -368,7 +367,7 @@ void slow_hash_free_state(void) hp_allocated = 0; } -void cn_slow_hash(const void *data, size_t length, char *hash) +void cn_slow_hash(const void *data, size_t length, char *hash, int light) { RDATA_ALIGN16 uint8_t expandedKey[240]; @@ -392,7 +391,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash) // this isn't supposed to happen, but guard against it for now. if(hp_state == NULL) - slow_hash_allocate_state(); + slow_hash_allocate_state(); hash_process(&state.hs, data, length); memcpy(text, state.init, INIT_SIZE_BYTE); @@ -400,7 +399,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash) if(useAes) { aes_expand_key(state.hs.b, expandedKey); - for(i = 0; i < MEMORY / INIT_SIZE_BYTE; i++) + for(i = 0; i < MEMORY / (light?2:1) / INIT_SIZE_BYTE; i++) { aes_pseudo_round(text, text, expandedKey, INIT_SIZE_BLK); memcpy(&hp_state[i * INIT_SIZE_BYTE], text, INIT_SIZE_BYTE); @@ -410,7 +409,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash) { aes_ctx = (oaes_ctx *) oaes_alloc(); oaes_key_import_data(aes_ctx, state.hs.b, AES_KEY_SIZE); - for(i = 0; i < MEMORY / INIT_SIZE_BYTE; i++) + for(i = 0; i < MEMORY / (light?2:1) / INIT_SIZE_BYTE; i++) { for(j = 0; j < INIT_SIZE_BLK; j++) aesb_pseudo_round(&text[AES_BLOCK_SIZE * j], &text[AES_BLOCK_SIZE * j], aes_ctx->key->exp_data); @@ -428,7 +427,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash) // this is ugly but the branching affects the loop somewhat so put it outside. if(useAes) { - for(i = 0; i < ITER / 2; i++) + for(i = 0; i < ITER / (light?2:1) / 2; i++) { pre_aes(); _c = _mm_aesenc_si128(_c, _a); @@ -438,7 +437,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash) } else { - for(i = 0; i < ITER / 2; i++) + for(i = 0; i < ITER / (light?2:1) / 2; i++) { pre_aes(); aesb_single_round((uint8_t *) &_c, (uint8_t *) &_c, (uint8_t *) &_a); @@ -450,7 +449,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash) if(useAes) { aes_expand_key(&state.hs.b[32], expandedKey); - for(i = 0; i < MEMORY / INIT_SIZE_BYTE; i++) + for(i = 0; i < MEMORY / (light?2:1) / INIT_SIZE_BYTE; i++) { // add the xor to the pseudo round aes_pseudo_round_xor(text, text, expandedKey, &hp_state[i * INIT_SIZE_BYTE], INIT_SIZE_BLK); @@ -459,7 +458,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash) else { oaes_key_import_data(aes_ctx, &state.hs.b[32], AES_KEY_SIZE); - for(i = 0; i < MEMORY / INIT_SIZE_BYTE; i++) + for(i = 0; i < MEMORY / (light?2:1) / INIT_SIZE_BYTE; i++) { for(j = 0; j < INIT_SIZE_BLK; j++) { diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index e39c21f..e1571ee 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -30,6 +30,12 @@ #pragma once +#define HARDFORK_1_HEIGHT 1000 +#define HARDFORK_1_OLD_TARGET 1 +#define HARDFORK_1_POW_SPEED_MULTIPLIER 2 +#define HARDFORK_1_DIFFADJ HARDFORK_1_POW_SPEED_MULTIPLIER +#define HARDFORK_1_DIFFADJ_WINDOW 360 + #define CRYPTONOTE_MAX_BLOCK_NUMBER 500000000 #define CRYPTONOTE_MAX_BLOCK_SIZE 500000000 // block header blob limit, never used! #define CRYPTONOTE_GETBLOCKTEMPLATE_MAX_BLOCK_SIZE 196608 //size of block (bytes) that is the maximum that miners will produce @@ -60,7 +66,7 @@ #define ORPHANED_BLOCKS_MAX_COUNT 100 -#define DIFFICULTY_TARGET 60 // seconds +#define DIFFICULTY_TARGET 4 // seconds #define DIFFICULTY_WINDOW 720 // blocks #define DIFFICULTY_LAG 15 // !!! #define DIFFICULTY_CUT 60 // timestamps to cut after sorting @@ -81,8 +87,8 @@ #define CRYPTONOTE_MEMPOOL_TX_LIVETIME 86400 //seconds, one day #define CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME 604800 //seconds, one week -#define P2P_DEFAULT_PORT 11180 -#define RPC_DEFAULT_PORT 11181 +#define P2P_DEFAULT_PORT 31180 +#define RPC_DEFAULT_PORT 31181 #define COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT 1000 #define P2P_LOCAL_WHITE_PEERLIST_LIMIT 1000 @@ -101,7 +107,7 @@ #define ALLOW_DEBUG_COMMANDS -#define CRYPTONOTE_NAME "aeon" +#define CRYPTONOTE_NAME "aeone" #define CRYPTONOTE_POOLDATA_FILENAME "poolstate.bin" #define CRYPTONOTE_BLOCKCHAINDATA_FILENAME "blockchain.bin" #define CRYPTONOTE_BLOCKCHAINDATA_TEMP_FILENAME "blockchain.bin.tmp" diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp index 9b80b85..90136d8 100644 --- a/src/cryptonote_core/blockchain_storage.cpp +++ b/src/cryptonote_core/blockchain_storage.cpp @@ -373,7 +373,7 @@ difficulty_type blockchain_storage::get_difficulty_for_next_block() timestamps.push_back(m_blocks[offset].bl.timestamp); commulative_difficulties.push_back(m_blocks[offset].cumulative_difficulty); } - return next_difficulty(timestamps, commulative_difficulties); + return next_difficulty(timestamps, commulative_difficulties,m_blocks.size()); } //------------------------------------------------------------------ bool blockchain_storage::rollback_blockchain_switching(std::list& original_chain, size_t rollback_height) @@ -507,7 +507,7 @@ difficulty_type blockchain_storage::get_next_difficulty_for_alternative_chain(co break; } } - return next_difficulty(timestamps, commulative_difficulties); + return next_difficulty(timestamps, commulative_difficulties,bei.height); } //------------------------------------------------------------------ bool blockchain_storage::prevalidate_miner_transaction(const block& b, uint64_t height) @@ -1551,6 +1551,7 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt if(!check_hash(proof_of_work, current_diffic)) { LOG_PRINT_L0("Block with id: " << id << ENDL + << "height: " << m_blocks.size() << ENDL << "have not enough proof of work: " << proof_of_work << ENDL << "nexpected difficulty: " << current_diffic ); bvc.m_verifivation_failed = true; diff --git a/src/cryptonote_core/checkpoints_create.h b/src/cryptonote_core/checkpoints_create.h index 19ed135..e6b5b1d 100644 --- a/src/cryptonote_core/checkpoints_create.h +++ b/src/cryptonote_core/checkpoints_create.h @@ -38,6 +38,7 @@ namespace cryptonote { inline bool create_checkpoints(cryptonote::checkpoints& checkpoints) { +#if 0 ADD_CHECKPOINT(1, "1440a20f078bf3264822234b347f8382606577d73d4e9d3cb7296d73889bc421"); ADD_CHECKPOINT(100, "6dd13aaab16679f49ee6b2b75c7dc99b1fd09ab2282b18cb4b55b73110655742"); ADD_CHECKPOINT(1000, "bc6458452fd0575a314089bf302f6fd68ebaa2d689c42f3365293b96bbdf1f25"); @@ -45,6 +46,7 @@ namespace cryptonote { ADD_CHECKPOINT(15000, "15567af42afc1ed00538f53b5e3822d421e3ed6372ca79f4ea4e3e3bab709a87"); ADD_CHECKPOINT(175500, "3f7dd748b3b863b04654d87a387f2b65a365f467188971f3192eab2368e64a35"); +#endif return true; } } diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp index ba8ec7c..d1f65db 100644 --- a/src/cryptonote_core/cryptonote_format_utils.cpp +++ b/src/cryptonote_core/cryptonote_format_utils.cpp @@ -667,9 +667,9 @@ namespace cryptonote //--------------------------------------------------------------- bool get_block_longhash(const block& b, crypto::hash& res, uint64_t height) { - block b_local = b; //workaround to avoid const errors with do_serialize + //block b_local = b; //workaround to avoid const errors with do_serialize blobdata bd = get_block_hashing_blob(b); - crypto::cn_slow_hash(bd.data(), bd.size(), res); + crypto::cn_slow_hash(bd.data(), bd.size(), res, height >= HARDFORK_1_HEIGHT); return true; } //--------------------------------------------------------------- diff --git a/src/cryptonote_core/difficulty.cpp b/src/cryptonote_core/difficulty.cpp index 9c0e530..389112c 100644 --- a/src/cryptonote_core/difficulty.cpp +++ b/src/cryptonote_core/difficulty.cpp @@ -89,7 +89,12 @@ namespace cryptonote { return !carry; } - difficulty_type next_difficulty(vector timestamps, vector cumulative_difficulties, size_t target_seconds) { + difficulty_type next_difficulty(vector timestamps, vector cumulative_difficulties, size_t height) { + size_t target_seconds = DIFFICULTY_TARGET; + + if (height < HARDFORK_1_HEIGHT) + target_seconds = HARDFORK_1_OLD_TARGET; + //cutoff DIFFICULTY_LAG if(timestamps.size() > DIFFICULTY_WINDOW) { @@ -127,11 +132,14 @@ namespace cryptonote { if (high != 0 || low + time_span - 1 < low) { return 0; } - return (low + time_span - 1) / time_span; + + difficulty_type new_diff = (low + time_span - 1) / time_span; + + if (height >= HARDFORK_1_HEIGHT && height < HARDFORK_1_HEIGHT+HARDFORK_1_DIFFADJ_WINDOW) { + new_diff += new_diff*(HARDFORK_1_HEIGHT+HARDFORK_1_DIFFADJ_WINDOW-height)*(HARDFORK_1_DIFFADJ-1)/HARDFORK_1_DIFFADJ_WINDOW; + } + + return new_diff; } - difficulty_type next_difficulty(vector timestamps, vector cumulative_difficulties) - { - return next_difficulty(std::move(timestamps), std::move(cumulative_difficulties), DIFFICULTY_TARGET); - } } diff --git a/src/cryptonote_core/difficulty.h b/src/cryptonote_core/difficulty.h index f707173..326eabf 100644 --- a/src/cryptonote_core/difficulty.h +++ b/src/cryptonote_core/difficulty.h @@ -40,6 +40,6 @@ namespace cryptonote typedef std::uint64_t difficulty_type; bool check_hash(const crypto::hash &hash, difficulty_type difficulty); - difficulty_type next_difficulty(std::vector timestamps, std::vector cumulative_difficulties); - difficulty_type next_difficulty(std::vector timestamps, std::vector cumulative_difficulties, size_t target_seconds); + // difficulty_type next_difficulty(std::vector timestamps, std::vector cumulative_difficulties); + difficulty_type next_difficulty(std::vector timestamps, std::vector cumulative_difficulties, size_t height); } diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index 9460ff9..107613c 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -30,6 +30,7 @@ #include #include +#include #include "cryptonote_core/cryptonote_format_utils.h" #include "profile_tools.h" @@ -182,7 +183,7 @@ namespace cryptonote int64_t diff = static_cast(hshd.current_height) - static_cast(m_core.get_current_blockchain_height()); LOG_PRINT_CCONTEXT_YELLOW("Sync data returned unknown top block: " << m_core.get_current_blockchain_height() << " -> " << hshd.current_height - << " [" << std::abs(diff) << " blocks (" << diff / (24 * 60 * 60 / DIFFICULTY_TARGET) << " days) " + << " [" << std::abs(diff) << " blocks (" << (std::min(m_core.get_current_blockchain_height(),hshd.current_height) < HARDFORK_1_HEIGHT ? std::to_string(diff) + " blocks) " : std::to_string(diff / (24 * 60 * 60 / DIFFICULTY_TARGET)) +" days) ") << (0 <= diff ? std::string("behind") : std::string("ahead")) << "] " << ENDL << "SYNCHRONIZATION started", (is_inital ? LOG_LEVEL_0:LOG_LEVEL_1)); LOG_PRINT_L1("Remote top block height: " << hshd.current_height << ", id: " << hshd.top_id); diff --git a/src/miner/simpleminer.cpp b/src/miner/simpleminer.cpp index 234a49e..a333614 100644 --- a/src/miner/simpleminer.cpp +++ b/src/miner/simpleminer.cpp @@ -90,6 +90,7 @@ namespace mining const command_line::arg_descriptor arg_pool_addr = {"pool-addr", ""}; const command_line::arg_descriptor arg_login = {"login", ""}; const command_line::arg_descriptor arg_pass = {"pass", ""}; + const command_line::arg_descriptor arg_lite = {"lite", ""}; //----------------------------------------------------------------------------------------------------- void simpleminer::init_options(boost::program_options::options_description& desc) @@ -97,6 +98,7 @@ namespace mining command_line::add_arg(desc, arg_pool_addr); command_line::add_arg(desc, arg_login); command_line::add_arg(desc, arg_pass); + command_line::add_arg(desc, arg_lite); } bool simpleminer::init(const boost::program_options::variables_map& vm) { @@ -108,6 +110,7 @@ namespace mining m_pool_port = pool_addr.substr(p + 1, pool_addr.size()); m_login = command_line::get_arg(vm, arg_login); m_pass = command_line::get_arg(vm, arg_pass); + m_cryptonight_lite = command_line::get_arg(vm, arg_lite); return true; } @@ -183,7 +186,7 @@ namespace mining //uint32_t c = (*((uint32_t*)&job.blob.data()[39])); ++(*((uint32_t*)&job.blob.data()[39])); crypto::hash h = cryptonote::null_hash; - crypto::cn_slow_hash(job.blob.data(), job.blob.size(), h); + crypto::cn_slow_hash(job.blob.data(), job.blob.size(), h, m_cryptonight_lite); if( ((uint32_t*)&h)[7] < job.target ) { //found! diff --git a/src/miner/simpleminer.h b/src/miner/simpleminer.h index 876934d..61ed7c6 100644 --- a/src/miner/simpleminer.h +++ b/src/miner/simpleminer.h @@ -54,6 +54,8 @@ namespace mining std::string m_pool_port; std::string m_login; std::string m_pass; + bool m_cryptonight_lite; + epee::net_utils::http::http_simple_client m_http_client; }; } diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index d4496ac..2b0fba0 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -533,14 +533,14 @@ namespace nodetool if (priority) {\ LOG_PRINT_CC_L0(con, msg); \ } else {\ - LOG_PRINT_CC_L1(con, msg); \ + LOG_PRINT_CC_L2(con, msg); \ } \ } while(0) template bool node_server::try_to_connect_and_handshake_with_new_peer(const net_address& na, bool just_take_peerlist, uint64_t last_seen_stamp, bool white) { - LOG_PRINT_L1("Connecting to " << epee::string_tools::get_ip_string_from_int32(na.ip) << ":" + LOG_PRINT_L2("Connecting to " << epee::string_tools::get_ip_string_from_int32(na.ip) << ":" << epee::string_tools::num_to_string_fast(na.port) << "(white=" << white << ", last_seen: " << (last_seen_stamp ? epee::misc_utils::get_time_interval_string(time(NULL) - last_seen_stamp):"never") << ")..."); diff --git a/tests/hash/main.cpp b/tests/hash/main.cpp index 57a502b..58935f6 100644 --- a/tests/hash/main.cpp +++ b/tests/hash/main.cpp @@ -58,7 +58,8 @@ extern "C" typedef void hash_f(const void *, size_t, char *); struct hash_func { const string name; hash_f &f; -} hashes[] = {{"fast", cn_fast_hash}, {"slow", cn_slow_hash}, {"tree", hash_tree}, +} hashes[] = {{"fast", cn_fast_hash}, {"slow-2m", cn_slow_hash_2m}, {"slow-1m", cn_slow_hash_1m}, + {"tree", hash_tree}, {"extra-blake", hash_extra_blake}, {"extra-groestl", hash_extra_groestl}, {"extra-jh", hash_extra_jh}, {"extra-skein", hash_extra_skein}}; diff --git a/tests/performance_tests/cn_slow_hash.h b/tests/performance_tests/cn_slow_hash.h index c7b467e..264ea93 100644 --- a/tests/performance_tests/cn_slow_hash.h +++ b/tests/performance_tests/cn_slow_hash.h @@ -61,7 +61,7 @@ public: bool test() { crypto::hash hash; - crypto::cn_slow_hash(&m_data, sizeof(m_data), hash); + crypto::cn_slow_hash_2m(&m_data, sizeof(m_data), hash); return hash == m_expected_hash; }