mirror of
https://github.com/monero-project/monero.git
synced 2025-07-24 21:35:22 -04:00
Merge remote-tracking branch 'monero-official/master' into network-1.6-work1
This commit is contained in:
commit
3cbdf198f1
98 changed files with 9505 additions and 2470 deletions
|
@ -89,6 +89,7 @@ bool blockchain_storage::init(const std::string& config_folder, bool testnet)
|
|||
{
|
||||
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
||||
m_config_folder = config_folder;
|
||||
m_testnet = testnet;
|
||||
LOG_PRINT_L0("Loading blockchain...");
|
||||
const std::string filename = m_config_folder + "/" CRYPTONOTE_BLOCKCHAINDATA_FILENAME;
|
||||
if(tools::unserialize_obj_from_file(*this, filename))
|
||||
|
@ -1365,7 +1366,7 @@ bool blockchain_storage::pop_transaction_from_global_index(const transaction& tx
|
|||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool blockchain_storage::add_transaction_from_block(const transaction& tx, const crypto::hash& tx_id, const crypto::hash& bl_id, uint64_t bl_height)
|
||||
bool blockchain_storage::add_transaction_from_block(const transaction& tx, const crypto::hash& tx_id, const crypto::hash& bl_id, uint64_t bl_height, size_t blob_size)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
||||
struct add_transaction_input_visitor: public boost::static_visitor<bool>
|
||||
|
@ -1404,6 +1405,7 @@ bool blockchain_storage::add_transaction_from_block(const transaction& tx, const
|
|||
}
|
||||
transaction_chain_entry ch_e;
|
||||
ch_e.m_keeper_block_height = bl_height;
|
||||
ch_e.m_blob_size = blob_size;
|
||||
ch_e.tx = tx;
|
||||
auto i_r = m_transactions.insert(std::pair<crypto::hash, transaction_chain_entry>(tx_id, ch_e));
|
||||
if(!i_r.second)
|
||||
|
@ -1669,10 +1671,12 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt
|
|||
bvc.m_verifivation_failed = true;
|
||||
return false;
|
||||
}
|
||||
size_t coinbase_blob_size = get_object_blobsize(bl.miner_tx);
|
||||
crypto::hash coinbase_hash = null_hash;
|
||||
size_t coinbase_blob_size = 0;
|
||||
get_transaction_hash(bl.miner_tx, coinbase_hash, coinbase_blob_size);
|
||||
size_t cumulative_block_size = coinbase_blob_size;
|
||||
//process transactions
|
||||
if(!add_transaction_from_block(bl.miner_tx, get_transaction_hash(bl.miner_tx), id, get_current_blockchain_height()))
|
||||
if(!add_transaction_from_block(bl.miner_tx, coinbase_hash, id, get_current_blockchain_height(), coinbase_blob_size))
|
||||
{
|
||||
LOG_PRINT_L1("Block with id: " << id << " failed to add transaction to blockchain storage");
|
||||
bvc.m_verifivation_failed = true;
|
||||
|
@ -1706,7 +1710,7 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt
|
|||
return false;
|
||||
}
|
||||
|
||||
if(!add_transaction_from_block(tx, tx_id, id, get_current_blockchain_height()))
|
||||
if(!add_transaction_from_block(tx, tx_id, id, get_current_blockchain_height(), blob_size))
|
||||
{
|
||||
LOG_PRINT_L1("Block with id: " << id << " failed to add transaction to blockchain storage");
|
||||
cryptonote::tx_verification_context tvc = AUTO_VAL_INIT(tvc);
|
||||
|
@ -1736,7 +1740,14 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt
|
|||
bei.bl = bl;
|
||||
bei.block_cumulative_size = cumulative_block_size;
|
||||
bei.cumulative_difficulty = current_diffic;
|
||||
bei.already_generated_coins = already_generated_coins + base_reward;
|
||||
|
||||
// In the "tail" state when the minimum subsidy (implemented in get_block_reward) is in effect, the number of
|
||||
// coins will eventually exceed MONEY_SUPPLY and overflow a uint64. To prevent overflow, cap already_generated_coins
|
||||
// at MONEY_SUPPLY. already_generated_coins is only used to compute the block subsidy and MONEY_SUPPLY yields a
|
||||
// subsidy of 0 under the base formula and therefore the minimum subsidy >0 in the tail state.
|
||||
|
||||
bei.already_generated_coins = base_reward < (MONEY_SUPPLY-already_generated_coins) ? already_generated_coins + base_reward : MONEY_SUPPLY;
|
||||
|
||||
if(m_blocks.size())
|
||||
bei.cumulative_difficulty += m_blocks.back().cumulative_difficulty;
|
||||
|
||||
|
@ -1862,7 +1873,7 @@ bool blockchain_storage::update_checkpoints(const std::string& file_path, bool c
|
|||
else if (check_dns)
|
||||
{
|
||||
checkpoints dns_points;
|
||||
cryptonote::load_checkpoints_from_dns(dns_points);
|
||||
cryptonote::load_checkpoints_from_dns(dns_points, m_testnet);
|
||||
if (m_checkpoints.check_for_conflicts(dns_points))
|
||||
{
|
||||
check_against_checkpoints(dns_points, false);
|
||||
|
|
|
@ -219,6 +219,7 @@ namespace cryptonote
|
|||
std::atomic<bool> m_is_blockchain_storing;
|
||||
|
||||
bool m_enforce_dns_checkpoints;
|
||||
bool m_testnet;
|
||||
|
||||
bool switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::iterator>& alt_chain, bool discard_disconnected_chain);
|
||||
bool pop_block_from_blockchain();
|
||||
|
@ -234,7 +235,7 @@ namespace cryptonote
|
|||
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_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);
|
||||
bool add_transaction_from_block(const transaction& tx, const crypto::hash& tx_id, const crypto::hash& bl_id, uint64_t bl_height, size_t blob_size);
|
||||
bool push_transaction_to_global_outs_index(const transaction& tx, const crypto::hash& tx_id, std::vector<uint64_t>& global_indexes);
|
||||
bool pop_transaction_from_global_index(const transaction& tx, const crypto::hash& tx_id);
|
||||
bool get_last_n_blocks_sizes(std::vector<size_t>& sz, size_t count);
|
||||
|
|
|
@ -76,6 +76,7 @@ bool create_checkpoints(cryptonote::checkpoints& checkpoints)
|
|||
ADD_CHECKPOINT(231350, "b5add137199b820e1ea26640e5c3e121fd85faa86a1e39cf7e6cc097bdeb1131");
|
||||
ADD_CHECKPOINT(232150, "955de8e6b6508af2c24f7334f97beeea651d78e9ade3ab18fec3763be3201aa8");
|
||||
ADD_CHECKPOINT(249380, "654fb0a81ce3e5caf7e3264a70f447d4bd07586c08fa50f6638cc54da0a52b2d");
|
||||
ADD_CHECKPOINT(460000, "75037a7aed3e765db96c75bcf908f59d690a5f3390baebb9edeafd336a1c4831");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -112,7 +113,7 @@ bool load_checkpoints_from_json(cryptonote::checkpoints& checkpoints, std::strin
|
|||
return true;
|
||||
}
|
||||
|
||||
bool load_checkpoints_from_dns(cryptonote::checkpoints& checkpoints)
|
||||
bool load_checkpoints_from_dns(cryptonote::checkpoints& checkpoints, bool testnet)
|
||||
{
|
||||
// All four MoneroPulse domains have DNSSEC on and valid
|
||||
static const std::vector<std::string> dns_urls = { "checkpoints.moneropulse.se"
|
||||
|
@ -120,6 +121,12 @@ bool load_checkpoints_from_dns(cryptonote::checkpoints& checkpoints)
|
|||
, "checkpoints.moneropulse.net"
|
||||
, "checkpoints.moneropulse.co"
|
||||
};
|
||||
|
||||
static const std::vector<std::string> testnet_dns_urls = { "testpoints.moneropulse.se"
|
||||
, "testpoints.moneropulse.org"
|
||||
, "testpoints.moneropulse.net"
|
||||
, "testpoints.moneropulse.co"
|
||||
};
|
||||
bool avail, valid;
|
||||
std::vector<std::string> records;
|
||||
|
||||
|
@ -131,14 +138,34 @@ bool load_checkpoints_from_dns(cryptonote::checkpoints& checkpoints)
|
|||
size_t cur_index = first_index;
|
||||
do
|
||||
{
|
||||
records = tools::DNSResolver::instance().get_txt_record(dns_urls[cur_index], avail, valid);
|
||||
if (records.size() == 0 || (avail && !valid))
|
||||
std::string url;
|
||||
if (testnet)
|
||||
{
|
||||
url = testnet_dns_urls[cur_index];
|
||||
}
|
||||
else
|
||||
{
|
||||
url = dns_urls[cur_index];
|
||||
}
|
||||
|
||||
records = tools::DNSResolver::instance().get_txt_record(url, avail, valid);
|
||||
if (!avail)
|
||||
{
|
||||
LOG_PRINT_L2("DNSSEC not available for checkpoint update at URL: " << url << ", skipping.");
|
||||
}
|
||||
if (!valid)
|
||||
{
|
||||
LOG_PRINT_L2("DNSSEC validation failed for checkpoint update at URL: " << url << ", skipping.");
|
||||
}
|
||||
|
||||
if (records.size() == 0 || !avail || !valid)
|
||||
{
|
||||
cur_index++;
|
||||
if (cur_index == dns_urls.size())
|
||||
{
|
||||
cur_index = 0;
|
||||
}
|
||||
records.clear();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
@ -146,13 +173,7 @@ bool load_checkpoints_from_dns(cryptonote::checkpoints& checkpoints)
|
|||
|
||||
if (records.size() == 0)
|
||||
{
|
||||
LOG_PRINT_L1("Fetching MoneroPulse checkpoints failed, no TXT records available.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (avail && !valid)
|
||||
{
|
||||
LOG_PRINT_L0("WARNING: MoneroPulse failed DNSSEC validation and/or returned no records");
|
||||
LOG_PRINT_L0("WARNING: All MoneroPulse checkpoint URLs failed DNSSEC validation and/or returned no records");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace cryptonote
|
|||
bool create_checkpoints(cryptonote::checkpoints& checkpoints);
|
||||
|
||||
bool load_checkpoints_from_json(cryptonote::checkpoints& checkpoints, std::string json_hashfile_fullpath);
|
||||
bool load_checkpoints_from_dns(cryptonote::checkpoints& checkpoints);
|
||||
bool load_checkpoints_from_dns(cryptonote::checkpoints& checkpoints, bool testnet = false);
|
||||
bool load_new_checkpoints(cryptonote::checkpoints& checkpoints, std::string json_hashfile_fullpath);
|
||||
|
||||
} // namespace cryptonote
|
||||
|
|
|
@ -60,6 +60,10 @@ namespace cryptonote {
|
|||
//-----------------------------------------------------------------------------------------------
|
||||
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;
|
||||
if (base_reward < FINAL_SUBSIDY_PER_MINUTE)
|
||||
{
|
||||
base_reward = FINAL_SUBSIDY_PER_MINUTE;
|
||||
}
|
||||
|
||||
//make it soft
|
||||
if (median_size < CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE) {
|
||||
|
|
|
@ -42,6 +42,8 @@ using namespace epee;
|
|||
#include "cryptonote_format_utils.h"
|
||||
#include "misc_language.h"
|
||||
#include <csignal>
|
||||
#include "daemon/command_line_args.h"
|
||||
#include "cryptonote_core/checkpoints_create.h"
|
||||
|
||||
DISABLE_VS_WARNINGS(4355)
|
||||
|
||||
|
@ -108,14 +110,41 @@ namespace cryptonote
|
|||
return res;
|
||||
}
|
||||
//-----------------------------------------------------------------------------------
|
||||
void core::stop()
|
||||
{
|
||||
graceful_exit();
|
||||
}
|
||||
//-----------------------------------------------------------------------------------
|
||||
void core::init_options(boost::program_options::options_description& /*desc*/)
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::handle_command_line(const boost::program_options::variables_map& vm, bool testnet)
|
||||
bool core::handle_command_line(const boost::program_options::variables_map& vm)
|
||||
{
|
||||
auto data_dir_arg = testnet ? command_line::arg_testnet_data_dir : command_line::arg_data_dir;
|
||||
m_testnet = command_line::get_arg(vm, daemon_args::arg_testnet_on);
|
||||
|
||||
auto data_dir_arg = m_testnet ? command_line::arg_testnet_data_dir : command_line::arg_data_dir;
|
||||
m_config_folder = command_line::get_arg(vm, data_dir_arg);
|
||||
|
||||
auto data_dir = boost::filesystem::path(m_config_folder);
|
||||
|
||||
if (!m_testnet)
|
||||
{
|
||||
cryptonote::checkpoints checkpoints;
|
||||
if (!cryptonote::create_checkpoints(checkpoints))
|
||||
{
|
||||
throw std::runtime_error("Failed to initialize checkpoints");
|
||||
}
|
||||
set_checkpoints(std::move(checkpoints));
|
||||
|
||||
boost::filesystem::path json(JSON_HASH_FILE_NAME);
|
||||
boost::filesystem::path checkpoint_json_hashfile_fullpath = data_dir / json;
|
||||
|
||||
set_checkpoints_file_path(checkpoint_json_hashfile_fullpath.string());
|
||||
}
|
||||
|
||||
|
||||
set_enforce_dns_checkpoints(command_line::get_arg(vm, daemon_args::arg_dns_checkpoints));
|
||||
return true;
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
|
@ -154,21 +183,21 @@ namespace cryptonote
|
|||
return m_blockchain_storage.get_alternative_blocks_count();
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::init(const boost::program_options::variables_map& vm, bool testnet)
|
||||
bool core::init(const boost::program_options::variables_map& vm)
|
||||
{
|
||||
bool r = handle_command_line(vm, testnet);
|
||||
bool r = handle_command_line(vm);
|
||||
|
||||
r = m_mempool.init(m_config_folder);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize memory pool");
|
||||
|
||||
r = m_blockchain_storage.init(m_config_folder, testnet);
|
||||
r = m_blockchain_storage.init(m_config_folder, m_testnet);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage");
|
||||
|
||||
// load json & DNS checkpoints, and verify them
|
||||
// with respect to what blocks we already have
|
||||
CHECK_AND_ASSERT_MES(update_checkpoints(), false, "One or more checkpoints loaded from json or dns conflicted with existing checkpoints.");
|
||||
|
||||
r = m_miner.init(vm, testnet);
|
||||
r = m_miner.init(vm, m_testnet);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage");
|
||||
|
||||
return load_state_data();
|
||||
|
|
|
@ -72,7 +72,7 @@ namespace cryptonote
|
|||
|
||||
miner& get_miner(){return m_miner;}
|
||||
static void init_options(boost::program_options::options_description& desc);
|
||||
bool init(const boost::program_options::variables_map& vm, bool testnet);
|
||||
bool init(const boost::program_options::variables_map& vm);
|
||||
bool set_genesis_block(const block& b);
|
||||
bool deinit();
|
||||
static void set_fast_exit();
|
||||
|
@ -131,6 +131,8 @@ namespace cryptonote
|
|||
|
||||
bool update_checkpoints();
|
||||
|
||||
void stop();
|
||||
|
||||
private:
|
||||
bool add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block);
|
||||
bool add_new_tx(const transaction& tx, tx_verification_context& tvc, bool keeped_by_block);
|
||||
|
@ -148,7 +150,7 @@ namespace cryptonote
|
|||
bool check_tx_ring_signature(const txin_to_key& tx, const crypto::hash& tx_prefix_hash, const std::vector<crypto::signature>& sig);
|
||||
bool is_tx_spendtime_unlocked(uint64_t unlock_time);
|
||||
bool update_miner_block_template();
|
||||
bool handle_command_line(const boost::program_options::variables_map& vm, bool testnet);
|
||||
bool handle_command_line(const boost::program_options::variables_map& vm);
|
||||
bool on_update_blocktemplate_interval();
|
||||
bool check_tx_inputs_keyimages_diff(const transaction& tx);
|
||||
void graceful_exit();
|
||||
|
@ -171,6 +173,7 @@ namespace cryptonote
|
|||
|
||||
uint64_t m_target_blockchain_height;
|
||||
|
||||
bool m_testnet;
|
||||
std::string m_checkpoints_path;
|
||||
time_t m_last_dns_checkpoints_update;
|
||||
time_t m_last_json_checkpoints_update;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue