Merge pull request #5 from iamsmooth/master

release phoenix
This commit is contained in:
aeonix
2015-07-21 10:26:42 -07:00
26 changed files with 112 additions and 65 deletions
+1 -1
View File
@@ -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));
}
+3 -1
View File
@@ -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);
+6 -2
View File
@@ -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<char *>(&hash));
inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int light) {
cn_slow_hash(data, length, reinterpret_cast<char *>(&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) {
+11 -12
View File
@@ -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++)
{
+10 -3
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2014, AEON, The Monero Project
// Copyright (c) 2014, 2015 AEON, The Monero Project
//
// All rights reserved.
//
@@ -30,6 +30,13 @@
#pragma once
#define HARDFORK_1_HEIGHT 592000
#define HARDFORK_1_OLD_TARGET 60
#define HARDFORK_1_OLD_SPEED_FACTOR (20)
#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
@@ -46,7 +53,7 @@
// MONEY_SUPPLY - total number coins to be generated
#define MONEY_SUPPLY ((uint64_t)(-1))
#define EMISSION_SPEED_FACTOR (20)
#define EMISSION_SPEED_FACTOR (18)
#define CRYPTONOTE_REWARD_BLOCKS_WINDOW 100
#define CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE 20000 //size of block (bytes) after which reward for block calculated using block size
@@ -60,7 +67,7 @@
#define ORPHANED_BLOCKS_MAX_COUNT 100
#define DIFFICULTY_TARGET 60 // seconds
#define DIFFICULTY_TARGET 240 // seconds
#define DIFFICULTY_WINDOW 720 // blocks
#define DIFFICULTY_LAG 15 // !!!
#define DIFFICULTY_CUT 60 // timestamps to cut after sorting
+18 -6
View File
@@ -89,7 +89,17 @@ bool blockchain_storage::init(const std::string& config_folder)
m_config_folder = config_folder;
LOG_PRINT_L0("Loading blockchain...");
const std::string filename = m_config_folder + "/" CRYPTONOTE_BLOCKCHAINDATA_FILENAME;
if(!tools::unserialize_obj_from_file(*this, filename))
if(tools::unserialize_obj_from_file(*this, filename))
{
// checkpoints
// mainchain
for (size_t height=0; height < m_blocks.size(); ++height)
{
CHECK_AND_ASSERT_MES((!m_checkpoints.is_in_checkpoint_zone(height)) || m_checkpoints.check_block(height,get_block_hash(m_blocks[height].bl)),false,"checkpoint fail, blockchain.bin invalid");
}
}
else
{
LOG_PRINT_L0("Can't load blockchain storage from file, generating genesis block.");
block bl = boost::value_initialized<block>();
@@ -98,6 +108,7 @@ bool blockchain_storage::init(const std::string& config_folder)
add_new_block(bl, bvc);
CHECK_AND_ASSERT_MES(!bvc.m_verifivation_failed && bvc.m_added_to_main_chain, false, "Failed to add genesis block to blockchain");
}
if(!m_blocks.size())
{
LOG_PRINT_L0("Blockchain not loaded, generating genesis block.");
@@ -373,7 +384,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<block>& original_chain, size_t rollback_height)
@@ -507,7 +518,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)
@@ -533,7 +544,7 @@ bool blockchain_storage::prevalidate_miner_transaction(const block& b, uint64_t
return true;
}
//------------------------------------------------------------------
bool blockchain_storage::validate_miner_transaction(const block& b, size_t cumulative_block_size, uint64_t fee, uint64_t& base_reward, uint64_t already_generated_coins)
bool blockchain_storage::validate_miner_transaction(const block& b, size_t cumulative_block_size, uint64_t fee, uint64_t& base_reward, uint64_t already_generated_coins, size_t height)
{
//validate reward
uint64_t money_in_use = 0;
@@ -542,7 +553,7 @@ bool blockchain_storage::validate_miner_transaction(const block& b, size_t cumul
std::vector<size_t> last_blocks_sizes;
get_last_n_blocks_sizes(last_blocks_sizes, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
if (!get_block_reward(epee::misc_utils::median(last_blocks_sizes), cumulative_block_size, already_generated_coins, base_reward)) {
if (!get_block_reward(epee::misc_utils::median(last_blocks_sizes), cumulative_block_size, already_generated_coins, base_reward, height)) {
LOG_PRINT_L0("block size " << cumulative_block_size << " is bigger than allowed for this blockchain");
return false;
}
@@ -1551,6 +1562,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;
@@ -1631,7 +1643,7 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt
}
uint64_t base_reward = 0;
uint64_t already_generated_coins = m_blocks.size() ? m_blocks.back().already_generated_coins:0;
if(!validate_miner_transaction(bl, cumulative_block_size, fee_summary, base_reward, already_generated_coins))
if(!validate_miner_transaction(bl, cumulative_block_size, fee_summary, base_reward, already_generated_coins, get_current_blockchain_height()))
{
LOG_PRINT_L0("Block with id: " << id
<< " have wrong miner transaction");
+1 -1
View File
@@ -225,7 +225,7 @@ namespace cryptonote
bool handle_alternative_block(const block& b, const crypto::hash& id, block_verification_context& bvc);
difficulty_type get_next_difficulty_for_alternative_chain(const std::list<blocks_ext_by_hash::iterator>& alt_chain, block_extended_info& bei);
bool prevalidate_miner_transaction(const block& b, uint64_t height);
bool validate_miner_transaction(const block& b, size_t cumulative_block_size, uint64_t fee, uint64_t& base_reward, uint64_t already_generated_coins);
bool validate_miner_transaction(const block& b, size_t cumulative_block_size, uint64_t fee, uint64_t& base_reward, uint64_t already_generated_coins, size_t height);
bool validate_transaction(const block& b, uint64_t height, const transaction& tx);
bool rollback_blockchain_switching(std::list<block>& original_chain, size_t rollback_height);
bool add_transaction_from_block(const transaction& tx, const crypto::hash& tx_id, const crypto::hash& bl_id, uint64_t bl_height);
+1
View File
@@ -44,6 +44,7 @@ namespace cryptonote {
ADD_CHECKPOINT(10000, "1ac1ebd25baf0d6ec593daa3389f1aa7e860ff2cc29f3cf1be586d245b379da4");
ADD_CHECKPOINT(15000, "15567af42afc1ed00538f53b5e3822d421e3ed6372ca79f4ea4e3e3bab709a87");
ADD_CHECKPOINT(175500, "3f7dd748b3b863b04654d87a387f2b65a365f467188971f3192eab2368e64a35");
ADD_CHECKPOINT(450000, "f69a6e57c4dd5df2f492c9d31c50f11aad2c25a64d540ce5f5d11b572aec8ab7");
ADD_CHECKPOINT(540000, "94e19cf9d5a16ae90f67c321f8376b87da21d6d6c2cb0957b9ab558dca66c1dc");
return true;
@@ -58,8 +58,9 @@ namespace cryptonote {
return CRYPTONOTE_MAX_TX_SIZE;
}
//-----------------------------------------------------------------------------------------------
bool get_block_reward(size_t median_size, size_t current_block_size, uint64_t already_generated_coins, uint64_t &reward) {
uint64_t base_reward = (MONEY_SUPPLY - already_generated_coins) >> EMISSION_SPEED_FACTOR;
bool get_block_reward(size_t median_size, size_t current_block_size, uint64_t already_generated_coins, uint64_t &reward, size_t height) {
int speed = height < HARDFORK_1_HEIGHT ? HARDFORK_1_OLD_SPEED_FACTOR : EMISSION_SPEED_FACTOR;
uint64_t base_reward = (MONEY_SUPPLY - already_generated_coins) >> speed;
//make it soft
if (median_size < CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE) {
+1 -1
View File
@@ -64,7 +64,7 @@ namespace cryptonote {
/************************************************************************/
size_t get_max_block_size();
size_t get_max_tx_size();
bool get_block_reward(size_t median_size, size_t current_block_size, uint64_t already_generated_coins, uint64_t &reward);
bool get_block_reward(size_t median_size, size_t current_block_size, uint64_t already_generated_coins, uint64_t &reward, size_t height);
uint8_t get_account_address_checksum(const public_address_outer_blob& bl);
std::string get_account_address_as_str(const account_public_address& adr);
bool get_account_address_from_str(account_public_address& adr, const std::string& str);
@@ -95,7 +95,7 @@ namespace cryptonote
in.height = height;
uint64_t block_reward;
if(!get_block_reward(median_size, current_block_size, already_generated_coins, block_reward))
if(!get_block_reward(median_size, current_block_size, already_generated_coins, block_reward, height))
{
LOG_PRINT_L0("Block is too big");
return false;
@@ -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;
}
//---------------------------------------------------------------
+14 -6
View File
@@ -89,7 +89,12 @@ namespace cryptonote {
return !carry;
}
difficulty_type next_difficulty(vector<uint64_t> timestamps, vector<difficulty_type> cumulative_difficulties, size_t target_seconds) {
difficulty_type next_difficulty(vector<uint64_t> timestamps, vector<difficulty_type> 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<uint64_t> timestamps, vector<difficulty_type> cumulative_difficulties)
{
return next_difficulty(std::move(timestamps), std::move(cumulative_difficulties), DIFFICULTY_TARGET);
}
}
+2 -2
View File
@@ -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<std::uint64_t> timestamps, std::vector<difficulty_type> cumulative_difficulties);
difficulty_type next_difficulty(std::vector<std::uint64_t> timestamps, std::vector<difficulty_type> cumulative_difficulties, size_t target_seconds);
// difficulty_type next_difficulty(std::vector<std::uint64_t> timestamps, std::vector<difficulty_type> cumulative_difficulties);
difficulty_type next_difficulty(std::vector<std::uint64_t> timestamps, std::vector<difficulty_type> cumulative_difficulties, size_t height);
}
@@ -30,6 +30,7 @@
#include <boost/interprocess/detail/atomic.hpp>
#include <list>
#include <algorithm>
#include "cryptonote_core/cryptonote_format_utils.h"
#include "profile_tools.h"
@@ -182,7 +183,7 @@ namespace cryptonote
int64_t diff = static_cast<int64_t>(hshd.current_height) - static_cast<int64_t>(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);
+4 -1
View File
@@ -90,6 +90,7 @@ namespace mining
const command_line::arg_descriptor<std::string, true> arg_pool_addr = {"pool-addr", ""};
const command_line::arg_descriptor<std::string, true> arg_login = {"login", ""};
const command_line::arg_descriptor<std::string, true> arg_pass = {"pass", ""};
const command_line::arg_descriptor<bool, false> 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!
+2
View File
@@ -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;
};
}
+2 -2
View File
@@ -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<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::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")
<< ")...");
+2 -2
View File
@@ -1,4 +1,4 @@
#define BUILD_COMMIT_ID "@VERSION@"
#define PROJECT_VERSION "0.8.8"
#define PROJECT_VERSION_BUILD_NO "2"
#define PROJECT_VERSION "0.9.0"
#define PROJECT_VERSION_BUILD_NO "0"
#define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO "(" BUILD_COMMIT_ID ")"
+1 -1
View File
@@ -52,7 +52,7 @@ set_property(TARGET coretests crypto-tests functional_tests difficulty-tests gte
add_test(coretests coretests --generate_and_play_test_data)
add_test(crypto crypto-tests ${CMAKE_CURRENT_SOURCE_DIR}/crypto/tests.txt)
add_test(difficulty difficulty-tests ${CMAKE_CURRENT_SOURCE_DIR}/difficulty/data.txt)
foreach(hash IN ITEMS fast slow tree extra-blake extra-groestl extra-jh extra-skein)
foreach(hash IN ITEMS fast slow-2m tree extra-blake extra-groestl extra-jh extra-skein)
add_test(hash-${hash} hash-tests ${hash} ${CMAKE_CURRENT_SOURCE_DIR}/hash/tests-${hash}.txt)
endforeach(hash)
add_test(hash-target hash-target-tests)
+5 -5
View File
@@ -45,7 +45,7 @@ namespace
for (size_t i = 0; i < new_block_count; ++i)
{
block blk_next;
difficulty_type diffic = next_difficulty(timestamps, cummulative_difficulties);
difficulty_type diffic = next_difficulty(timestamps, cummulative_difficulties, get_block_height(blk_prev)+1);
if (!generator.construct_block_manually(blk_next, blk_prev, miner_account,
test_generator::bf_timestamp | test_generator::bf_diffic, 0, 0, blk_prev.timestamp, crypto::hash(), diffic))
return false;
@@ -175,9 +175,9 @@ bool gen_block_invalid_nonce::generate(std::vector<test_event_entry>& events) co
return false;
// Create invalid nonce
difficulty_type diffic = next_difficulty(timestamps, commulative_difficulties);
assert(1 < diffic);
const block& blk_last = boost::get<block>(events.back());
difficulty_type diffic = next_difficulty(timestamps, commulative_difficulties, get_block_height(blk_last)+1);
assert(1 < diffic);
uint64_t timestamp = blk_last.timestamp;
block blk_3;
do
@@ -570,7 +570,7 @@ bool gen_block_invalid_binary_format::generate(std::vector<test_event_entry>& ev
do
{
blk_last = boost::get<block>(events.back());
diffic = next_difficulty(timestamps, cummulative_difficulties);
diffic = next_difficulty(timestamps, cummulative_difficulties, get_block_height(blk_last)+1);
if (!lift_up_difficulty(events, timestamps, cummulative_difficulties, generator, 1, blk_last, miner_account))
return false;
std::cout << "Block #" << events.size() << ", difficulty: " << diffic << std::endl;
@@ -585,7 +585,7 @@ bool gen_block_invalid_binary_format::generate(std::vector<test_event_entry>& ev
std::vector<crypto::hash> tx_hashes;
tx_hashes.push_back(get_transaction_hash(tx_0));
size_t txs_size = get_object_blobsize(tx_0);
diffic = next_difficulty(timestamps, cummulative_difficulties);
diffic = next_difficulty(timestamps, cummulative_difficulties, get_block_height(blk_last)+1);
if (!generator.construct_block_manually(blk_test, blk_last, miner_account,
test_generator::bf_diffic | test_generator::bf_timestamp | test_generator::bf_tx_hashes, 0, 0, blk_last.timestamp,
crypto::hash(), diffic, transaction(), tx_hashes, txs_size))
+5 -5
View File
@@ -94,11 +94,11 @@ uint64_t test_generator::get_already_generated_coins(const cryptonote::block& bl
return get_already_generated_coins(blk_hash);
}
void test_generator::add_block(const cryptonote::block& blk, size_t tsx_size, std::vector<size_t>& block_sizes, uint64_t already_generated_coins)
void test_generator::add_block(const cryptonote::block& blk, size_t tsx_size, std::vector<size_t>& block_sizes, uint64_t already_generated_coins, size_t height)
{
const size_t block_size = tsx_size + get_object_blobsize(blk.miner_tx);
uint64_t block_reward;
get_block_reward(misc_utils::median(block_sizes), block_size, already_generated_coins, block_reward);
get_block_reward(misc_utils::median(block_sizes), block_size, already_generated_coins, block_reward, height);
m_blocks_info[get_block_hash(blk)] = block_info(blk.prev_id, already_generated_coins + block_reward, block_size);
}
@@ -182,7 +182,7 @@ bool test_generator::construct_block(cryptonote::block& blk, uint64_t height, co
while (!miner::find_nonce_for_given_block(blk, get_test_difficulty(), height))
blk.timestamp++;
add_block(blk, txs_size, block_sizes, already_generated_coins);
add_block(blk, txs_size, block_sizes, already_generated_coins,height);
return true;
}
@@ -244,7 +244,7 @@ bool test_generator::construct_block_manually(block& blk, const block& prev_bloc
difficulty_type a_diffic = actual_params & bf_diffic ? diffic : get_test_difficulty();
fill_nonce(blk, a_diffic, height);
add_block(blk, txs_sizes, block_sizes, already_generated_coins);
add_block(blk, txs_sizes, block_sizes, already_generated_coins, height);
return true;
}
@@ -526,7 +526,7 @@ bool construct_miner_tx_manually(size_t height, uint64_t already_generated_coins
// This will work, until size of constructed block is less then CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE
uint64_t block_reward;
if (!get_block_reward(0, 0, already_generated_coins, block_reward))
if (!get_block_reward(0, 0, already_generated_coins, block_reward, height))
{
LOG_PRINT_L0("Block is too big");
return false;
+1 -1
View File
@@ -228,7 +228,7 @@ public:
uint64_t get_already_generated_coins(const crypto::hash& blk_id) const;
uint64_t get_already_generated_coins(const cryptonote::block& blk) const;
void add_block(const cryptonote::block& blk, size_t tsx_size, std::vector<size_t>& block_sizes, uint64_t already_generated_coins);
void add_block(const cryptonote::block& blk, size_t tsx_size, std::vector<size_t>& block_sizes, uint64_t already_generated_coins, size_t height);
bool construct_block(cryptonote::block& blk, uint64_t height, const crypto::hash& prev_id,
const cryptonote::account_base& miner_acc, uint64_t timestamp, uint64_t already_generated_coins,
std::vector<size_t>& block_sizes, const std::list<cryptonote::transaction>& tx_list);
+2 -1
View File
@@ -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}};
+1 -1
View File
@@ -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;
}
+11 -5
View File
@@ -46,8 +46,10 @@ namespace
uint64_t m_block_reward;
};
// block 100k is below any hard fork, TODO add tests above hard forks
#define TEST_ALREADY_GENERATED_COINS(already_generated_coins, expected_reward) \
m_block_not_too_big = get_block_reward(0, current_block_size, already_generated_coins, m_block_reward); \
m_block_not_too_big = get_block_reward(0, current_block_size, already_generated_coins, m_block_reward, 100000); \
ASSERT_TRUE(m_block_not_too_big); \
ASSERT_EQ(m_block_reward, UINT64_C(expected_reward));
@@ -78,14 +80,16 @@ namespace
protected:
virtual void SetUp()
{
m_block_not_too_big = get_block_reward(0, 0, already_generated_coins, m_standard_block_reward);
// block 100k is below any hard fork, TODO add tests above hard forks
m_block_not_too_big = get_block_reward(0, 0, already_generated_coins, m_standard_block_reward, 100000);
ASSERT_TRUE(m_block_not_too_big);
ASSERT_LT(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE, m_standard_block_reward);
}
void do_test(size_t median_block_size, size_t current_block_size)
{
m_block_not_too_big = get_block_reward(median_block_size, current_block_size, already_generated_coins, m_block_reward);
// block 100k is below any hard fork, TODO add tests above hard forks
m_block_not_too_big = get_block_reward(median_block_size, current_block_size, already_generated_coins, m_block_reward, 100000);
}
static const uint64_t already_generated_coins = 0;
@@ -167,14 +171,16 @@ namespace
m_last_block_sizes_median = 7 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE;
m_block_not_too_big = get_block_reward(epee::misc_utils::median(m_last_block_sizes), 0, already_generated_coins, m_standard_block_reward);
// block 100k is below any hard fork, TODO add tests above hard forks
m_block_not_too_big = get_block_reward(epee::misc_utils::median(m_last_block_sizes), 0, already_generated_coins, m_standard_block_reward,100000);
ASSERT_TRUE(m_block_not_too_big);
ASSERT_LT(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE, m_standard_block_reward);
}
void do_test(size_t current_block_size)
{
m_block_not_too_big = get_block_reward(epee::misc_utils::median(m_last_block_sizes), current_block_size, already_generated_coins, m_block_reward);
// block 100k is below any hard fork, TODO add tests above hard forks
m_block_not_too_big = get_block_reward(epee::misc_utils::median(m_last_block_sizes), current_block_size, already_generated_coins, m_block_reward, 100000);
}
static const uint64_t already_generated_coins = 0;