mirror of
https://github.com/jwinterm/aeon.git
synced 2026-11-14 08:43:54 +01:00
merge devel up to master
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user