Skip to content

Commit

Permalink
Merge pull request #12 from scala-network/dist-fix
Browse files Browse the repository at this point in the history
Diardi: refactor
  • Loading branch information
hayzamjs authored Oct 5, 2022
2 parents 923ad4b + b2a3625 commit 15d6ced
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 45 deletions.
1 change: 0 additions & 1 deletion src/checkpoints/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ scala_add_library(checkpoints
${checkpoints_private_headers})
target_link_libraries(checkpoints
PUBLIC
diardi
common
cncrypto
${Boost_DATE_TIME_LIBRARY}
Expand Down
21 changes: 8 additions & 13 deletions src/checkpoints/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};

Diardi diardi_;

//---------------------------------------------------------------------------
checkpoints::checkpoints()
{
Expand Down Expand Up @@ -200,25 +198,22 @@ namespace cryptonote
bool checkpoints::init_default_checkpoints(network_type nettype)
{
if(nettype == MAINNET) {
MGINFO("Downloading checkpoints from IPFS might take a while...");
bool downloadCompleted = diardi_.get_checkpoints(nettype);

if (!downloadCompleted)
{
LOG_ERROR("Failed to download checkpoints from diardi");
}
ADD_CHECKPOINT(0, "3fa5c8976978f52ad7d8fc3663e902a229a232ef987fc11ca99628366652ba99");
ADD_CHECKPOINT(100, "61e49040154df814f90ff106dae115d79a0dc54480278de605f016f6451ce3b0");
ADD_CHECKPOINT(1000, "f0610f14129ca53cf4812334ddd8ae6bbec459113367a853adc36c163fab5cd2");
ADD_CHECKPOINT(10000, "4a220652f8fb723d1d627022b2fd556132d51915ad4f78964fda4ec071b89504");
}

if (nettype == TESTNET)
{
ADD_CHECKPOINT(0,"eb093694aef3a0fba15e64ff70260d04b65dfbf7b198e54936e99c9151c53e72");
ADD_CHECKPOINT(5,"3be192a55b3b4d7896d1a07fdebb04634f5cce85f6b9536cf4353c35c087cfb0");
ADD_CHECKPOINT(15,"ff2d2f5ffe5ef3443ff9d6f5330bff05f03cdd8de2ba6e54fc01110d0fa2b9a5");
return true;
}

if (nettype == STAGENET)
{
return true;
}
{}

return true;
}
//---------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion src/checkpoints/checkpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "cryptonote_config.h"
#include "net/http_client.h"
#include "cryptonote_basic/difficulty.h"
#include "diardi/diardi.h"

#define ADD_CHECKPOINT(h, hash) CHECK_AND_ASSERT(add_checkpoint(h, hash), false);
#define ADD_CHECKPOINT_2(h, hash, difficulty) CHECK_AND_ASSERT(add_checkpoint(h, hash, difficulty), false);
Expand Down
4 changes: 2 additions & 2 deletions src/common/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ namespace tools
uint16_t port = u_c.port ? u_c.port : ssl == epee::net_utils::ssl_support_t::e_ssl_support_enabled ? 443 : 80;
MDEBUG("Connecting to " << u_c.host << ":" << port);
client.set_server(u_c.host, std::to_string(port), boost::none, ssl);
if (!client.connect(std::chrono::seconds(30)))
if (!client.connect(std::chrono::seconds(5)))
{
boost::lock_guard<boost::mutex> lock(control->mutex);
MERROR("Failed to connect to " << control->uri);
Expand All @@ -203,7 +203,7 @@ namespace tools
MDEBUG("Asking for range: " << range);
fields.push_back(std::make_pair("Range", range));
}
if (!client.invoke_get(u_c.uri, std::chrono::seconds(30), "", &info, fields))
if (!client.invoke_get(u_c.uri, std::chrono::seconds(5), "", &info, fields))
{
boost::lock_guard<boost::mutex> lock(control->mutex);
MERROR("Failed to connect to " << control->uri);
Expand Down
1 change: 1 addition & 0 deletions src/cryptonote_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ scala_add_library(cryptonote_core
target_link_libraries(cryptonote_core
PUBLIC
version
diardi
common
cncrypto
blockchain_db
Expand Down
17 changes: 16 additions & 1 deletion src/cryptonote_core/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ DISABLE_VS_WARNINGS(4267)
// used to overestimate the block reward when estimating a per kB to use
#define BLOCK_REWARD_OVERESTIMATE (10 * 1000000000000)

Diardi diardi_;

//------------------------------------------------------------------
Blockchain::Blockchain(tx_memory_pool& tx_pool) :
m_db(), m_tx_pool(tx_pool), m_hardfork(NULL), m_timestamps_and_difficulties_height(0), m_current_block_cumul_weight_limit(0), m_current_block_cumul_weight_median(0),
Expand Down Expand Up @@ -4499,8 +4501,21 @@ void Blockchain::check_against_checkpoints(const checkpoints& points, bool enfor
// returns false if any of the checkpoints loading returns false.
// That should happen only if a checkpoint is added that conflicts
// with an existing checkpoint.
bool Blockchain::update_checkpoints(const std::string& file_path, bool check_dns)
bool Blockchain::update_checkpoints(const std::string& file_path, bool check_dns, bool ipfs)
{
if(ipfs) {
LOG_PRINT_L1("Downloading checkpoints from IPFS might take a while... ");
if (!diardi_.get_checkpoints(m_nettype, file_path))
{
LOG_PRINT_L1("Failed to download checkpoints from diardi");
}

if (!m_checkpoints.load_checkpoints_from_json(file_path))
{
LOG_PRINT_L1("Failed to parse checkpoints from IPFS");
}
}

if (!m_checkpoints.load_checkpoints_from_json(file_path))
{
return false;
Expand Down
3 changes: 2 additions & 1 deletion src/cryptonote_core/blockchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "checkpoints/checkpoints.h"
#include "cryptonote_basic/hardfork.h"
#include "blockchain_db/blockchain_db.h"
#include "diardi/diardi.h"

namespace tools { class Notify; }

Expand Down Expand Up @@ -744,7 +745,7 @@ namespace cryptonote
*
* @return false if any enforced checkpoint type fails to load, otherwise true
*/
bool update_checkpoints(const std::string& file_path, bool check_dns);
bool update_checkpoints(const std::string& file_path, bool check_dns, bool ipfs = false);


// user options, must be called before calling init()
Expand Down
9 changes: 8 additions & 1 deletion src/cryptonote_core/cryptonote_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ namespace cryptonote
m_checkpoints_path(""),
m_last_dns_checkpoints_update(0),
m_last_json_checkpoints_update(0),
m_last_ipfs_checkpoints_update(0),
m_disable_dns_checkpoints(false),
m_update_download(0),
m_nettype(UNDEFINED),
Expand Down Expand Up @@ -277,12 +278,18 @@ namespace cryptonote
res = m_blockchain_storage.update_checkpoints(m_checkpoints_path, true);
m_last_dns_checkpoints_update = time(NULL);
m_last_json_checkpoints_update = time(NULL);
m_last_ipfs_checkpoints_update = time(NULL);
}
else if (time(NULL) - m_last_json_checkpoints_update >= 600)
else if (time(NULL) - m_last_json_checkpoints_update >= 86400)
{
res = m_blockchain_storage.update_checkpoints(m_checkpoints_path, false);
m_last_json_checkpoints_update = time(NULL);
}
else if(time(NULL) - m_last_ipfs_checkpoints_update >= 2700)
{
res = m_blockchain_storage.update_checkpoints(m_checkpoints_path, false, true);
m_last_ipfs_checkpoints_update = time(NULL);
}

m_checkpoints_updating.clear();

Expand Down
1 change: 1 addition & 0 deletions src/cryptonote_core/cryptonote_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,7 @@ namespace cryptonote
std::string m_checkpoints_path; //!< path to json checkpoints file
time_t m_last_dns_checkpoints_update; //!< time when dns checkpoints were last updated
time_t m_last_json_checkpoints_update; //!< time when json checkpoints were last updated
time_t m_last_ipfs_checkpoints_update;

std::atomic_flag m_checkpoints_updating; //!< set if checkpoints are currently updating to avoid multiple threads attempting to update at once
bool m_disable_dns_checkpoints;
Expand Down
20 changes: 1 addition & 19 deletions src/diardi/diardi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,7 @@ namespace cryptonote {

Diardi::Diardi() {}

std::string Diardi::get_checkpoints_location(network_type nettype) {
std::string path;
std::string default_directory = tools::get_default_data_dir();

if(nettype == MAINNET) {
path = default_directory + "/" + "checkpoints.json";
} else if(nettype == TESTNET) {
path = default_directory + "/testnet/" + "checkpoints.json";
} else if(nettype == STAGENET) {
path = default_directory + "/stagenet/" + "checkpoints.json";
} else {
throw std::runtime_error("Invalid network type");
}

return path;
}

bool Diardi::get_checkpoints(network_type nettype) {
std::string checkpoint_location = get_checkpoints_location(nettype);
bool Diardi::get_checkpoints(network_type nettype, std::string checkpoint_location) {
if (boost::filesystem::exists(checkpoint_location)) {
boost::filesystem::remove_all(checkpoint_location);
}
Expand Down
3 changes: 1 addition & 2 deletions src/diardi/diardi.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ namespace cryptonote {
public:
Diardi();

std::string get_checkpoints_location(network_type nettype);
std::string fetch_dns_txt_ipfs_path(network_type nettype);
bool get_checkpoints(network_type nettype);
bool get_checkpoints(network_type nettype, std::string checkpoint_location);
};
}
4 changes: 2 additions & 2 deletions src/rpc/core_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ using namespace epee;
#undef SCALA_DEFAULT_LOG_CATEGORY
#define SCALA_DEFAULT_LOG_CATEGORY "daemon.rpc"

#define MAX_RESTRICTED_FAKE_OUTS_COUNT 40
#define MAX_RESTRICTED_GLOBAL_FAKE_OUTS_COUNT 5000
#define MAX_RESTRICTED_FAKE_OUTS_COUNT 10000
#define MAX_RESTRICTED_GLOBAL_FAKE_OUTS_COUNT 10000

#define OUTPUT_HISTOGRAM_RECENT_CUTOFF_RESTRICTION (3 * 86400) // 3 days max, the wallet requests 1.8 days

Expand Down
4 changes: 2 additions & 2 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7890,8 +7890,8 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
// check we're clear enough of rct start, to avoid corner cases below
THROW_WALLET_EXCEPTION_IF(rct_offsets.size() <= CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE,
error::get_output_distribution, "Not enough rct outputs");
THROW_WALLET_EXCEPTION_IF(rct_offsets.back() <= max_rct_index,
error::get_output_distribution, "Daemon reports suspicious number of rct outputs");
//THROW_WALLET_EXCEPTION_IF(rct_offsets.back() <= max_rct_index,
// error::get_output_distribution, "Daemon reports suspicious number of rct outputs");
}

// get histogram for the amounts we need
Expand Down

0 comments on commit 15d6ced

Please sign in to comment.