Browse Source

add more debug, use singleshot instead of loop

pull/139/head
Deniod 5 months ago
parent
commit
1f31adc30c
  1. 6
      lib/src/lib.rs
  2. 99
      src/connection.cpp
  3. 2
      src/controller.cpp
  4. 1
      src/firsttimewizard.cpp

6
lib/src/lib.rs

@ -51,9 +51,6 @@ println!("\nBlake3 Hash: {}", hash1);
//let sttring = CString::new(hash1).unwrap(); //let sttring = CString::new(hash1).unwrap();
let e_str = CString::new(format!("{}", hash1)).unwrap(); let e_str = CString::new(format!("{}", hash1)).unwrap();
return e_str.into_raw(); return e_str.into_raw();
} }
/// Create a new wallet and return the seed for the newly created wallet. /// Create a new wallet and return the seed for the newly created wallet.
@ -112,7 +109,6 @@ pub extern fn litelib_initialize_new(dangerous: bool,server: *const c_char) -> *
#[no_mangle] #[no_mangle]
pub extern "C" fn litelib_initialize_new_from_phrase(dangerous: bool, server: *const c_char, pub extern "C" fn litelib_initialize_new_from_phrase(dangerous: bool, server: *const c_char,
seed: *const c_char, birthday: u64, number: u64, overwrite: bool) -> *mut c_char { seed: *const c_char, birthday: u64, number: u64, overwrite: bool) -> *mut c_char {
// Prüfen auf null-Pointer
if server.is_null() || seed.is_null() { if server.is_null() || seed.is_null() {
println!("Server or seed is null"); println!("Server or seed is null");
return ptr::null_mut(); return ptr::null_mut();
@ -167,7 +163,6 @@ pub extern "C" fn litelib_initialize_new_from_phrase(dangerous: bool, server: *c
return c_str.into_raw(); return c_str.into_raw();
} }
// Initialize a new lightclient and store its value // Initialize a new lightclient and store its value
#[no_mangle] #[no_mangle]
pub extern fn litelib_initialize_existing(dangerous: bool, server: *const c_char) -> *mut c_char { pub extern fn litelib_initialize_existing(dangerous: bool, server: *const c_char) -> *mut c_char {
@ -197,7 +192,6 @@ pub extern fn litelib_initialize_existing(dangerous: bool, server: *const c_char
// Initialize logging // Initialize logging
let _ = lightclient.init_logging(); let _ = lightclient.init_logging();
let lc = Arc::new(lightclient); let lc = Arc::new(lightclient);
match LightClient::start_mempool_monitor(lc.clone()) { match LightClient::start_mempool_monitor(lc.clone()) {
Ok(_) => {println!("Starting Mempool")}, Ok(_) => {println!("Starting Mempool")},

99
src/connection.cpp

@ -100,64 +100,62 @@ void ConnectionLoader::ShowProgress()
config->dangerous = false; config->dangerous = false;
config->server = Settings::getInstance()->getSettings().server; config->server = Settings::getInstance()->getSettings().server;
DEBUG("Creating connection with server=" << config->server);
auto connection = makeConnection(config); auto connection = makeConnection(config);
auto me = this; if (!connection) {
DEBUG("server=" << config->server << " connection=" << connection << " me=" << me); DEBUG("Failed to create connection");
return;
}
isSyncing = new QAtomicInteger<bool>(); auto me = this;
isSyncing->storeRelaxed(true); isSyncing = new QAtomicInteger<bool>(true);
DEBUG("isSyncing"); DEBUG("isSyncing set to true");
// Do a sync after import // Do a sync after import
syncTimer = new QTimer(main); syncTimer = new QTimer(main);
DEBUG("Beginning sync after import wif"); DEBUG("Created syncTimer");
connection->doRPC("sync", "", [=](auto) { connection->doRPC("sync", "", [=](auto) {
qDebug()<< "finished syncing"; qDebug()<< "Finished syncing";
isSyncing->storeRelaxed(false); isSyncing->storeRelaxed(false);
// Cancel the timer
syncTimer->deleteLater(); syncTimer->deleteLater();
// When sync is done, set the connection
this->doRPCSetConnectionShield(connection); this->doRPCSetConnectionShield(connection);
}, [=](auto) { }, [=](auto) {
DEBUG("sync rpc error! server=" << config->server); DEBUG("sync rpc error! server=" << config->server);
}); });
// While it is syncing, we'll show the status updates while it is alive.
QObject::connect(syncTimer, &QTimer::timeout, [=]() { QObject::connect(syncTimer, &QTimer::timeout, [=]() {
DEBUG("Check the sync status"); if (!isSyncing || !isSyncing->loadRelaxed()) {
if (isSyncing != nullptr && isSyncing->loadRelaxed()) { DEBUG("Syncing complete or isSyncing is null, stopping timer");
DEBUG("Get the sync status"); syncTimer->stop();
try { return;
connection->doRPC("syncstatus", "", [=](json reply) { }
if (isSyncing != nullptr && reply.find("synced_blocks") != reply.end()) {
qint64 synced = reply["synced_blocks"].get<json::number_unsigned_t>();
qint64 total = reply["total_blocks"].get<json::number_unsigned_t>();
me->showInformation(
"Syncing... " + QString::number(synced) + " / " + QString::number(total)
);
}
}, [=](QString err) {
DEBUG("Sync error " << err);
// We may have gotten "Unexpected compression flag: 60"
// or some other error, so let's try another server
config->server = Settings::getRandomServer();
DEBUG("Changed server to " << config->server );
});
} catch (const std::exception& e) {
DEBUG("syncstatus exception: " << e.what() );
main->logger->write("catch sync progress reply");
// rethrow exception so loadProgress can catch DEBUG("Checking sync status");
// it and retry the entire ShowProgress() function again try {
throw new std::runtime_error(std::string("syncstatus failed")); connection->doRPC("syncstatus", "", [=](json reply) {
} if (isSyncing && reply.find("synced_blocks") != reply.end()) {
qint64 synced = reply["synced_blocks"].get<json::number_unsigned_t>();
qint64 total = reply["total_blocks"].get<json::number_unsigned_t>();
DEBUG("Sync status: " << synced << " / " << total);
me->showInformation(
"Syncing... " + QString::number(synced) + " / " + QString::number(total)
);
}
}, [=](QString err) {
DEBUG("Sync status error: " << err);
config->server = Settings::getRandomServer();
DEBUG("Changed server to " << config->server);
});
} catch (const std::exception& e) {
DEBUG("Exception caught in syncstatus: " << e.what());
throw;
} }
}); });
int interval = 1*1000; int interval = 1 * 1000;
syncTimer->setInterval(interval); syncTimer->setInterval(interval);
syncTimer->start(); syncTimer->start();
DEBUG("Start sync timer with interval=" << interval); DEBUG("Sync timer started with interval=" << interval);
} }
void ConnectionLoader::doAutoConnect() void ConnectionLoader::doAutoConnect()
@ -165,10 +163,10 @@ void ConnectionLoader::doAutoConnect()
auto config = std::shared_ptr<ConnectionConfig>(new ConnectionConfig()); auto config = std::shared_ptr<ConnectionConfig>(new ConnectionConfig());
config->dangerous = false; config->dangerous = false;
config->server = Settings::getInstance()->getSettings().server; config->server = Settings::getInstance()->getSettings().server;
DEBUG(" server=" << config->server); DEBUG("Creating connection with server=" << config->server);
// Initialize the library // Initialize the library
DEBUG("Attempting to initialize library with "<< config->server); DEBUG("Attempting to initialize library with " << config->server);
// Check to see if there's an existing wallet // Check to see if there's an existing wallet
if (litelib_wallet_exists(Settings::getDefaultChainName().toStdString().c_str())) { if (litelib_wallet_exists(Settings::getDefaultChainName().toStdString().c_str())) {
@ -219,22 +217,21 @@ void ConnectionLoader::doAutoConnect()
auto connection = makeConnection(config); auto connection = makeConnection(config);
auto me = this; auto me = this;
qDebug() << __func__ << ": server=" << config->server qDebug() << __func__ << ": server=" << config->server
<< " connection=" << connection << " me=" << me << Qt::endl; << " connection=" << connection << " me=" << me << Qt::endl;
// After the lib is initialized, try to do get info // After the lib is initialized, try to do get info
connection->doRPC("info", "", [=](auto reply) { connection->doRPC("info", "", [=](auto reply) {
// If success, set the connection
DEBUG("Connection is online."); DEBUG("Connection is online.");
connection->setInfo(reply); connection->setInfo(reply);
DEBUG("getting Connection reply"); DEBUG("getting Connection reply");
isSyncing = new QAtomicInteger<bool>(); isSyncing = new QAtomicInteger<bool>();
isSyncing->storeRelaxed(true); isSyncing->storeRelaxed(true);
DEBUG("isSyncing"); DEBUG("isSyncing set to true");
// Do a sync at startup // Do a sync at startup
syncTimer = new QTimer(main); syncTimer = new QTimer(main);
DEBUG("Beginning sync"); DEBUG("Beginning sync at startup");
connection->doRPC("sync", "", [=](auto) { connection->doRPC("sync", "", [=](auto) {
qDebug()<<"finished syncing startup"; qDebug()<<"finished syncing startup";
isSyncing->storeRelaxed(false); isSyncing->storeRelaxed(false);
@ -244,25 +241,19 @@ void ConnectionLoader::doAutoConnect()
this->doRPCSetConnection(connection); this->doRPCSetConnection(connection);
}, [=](auto) mutable { }, [=](auto) mutable {
DEBUG("sync rpc error! server=" << config->server); DEBUG("sync rpc error! server=" << config->server);
// continually retry sync RPC until it succeeds // Attempt to retry sync RPC with a delay
// don't change server each time it fails QTimer::singleShot(5000, [=]() { // 5-second delay
bool failed = true;
do {
// config->server = Settings::getRandomServer();
// auto connection = makeConnection(config);
// DEBUG("changed server to " << config->server);
connection->doRPC("sync", "", [=](auto) mutable { connection->doRPC("sync", "", [=](auto) mutable {
qDebug()<<"sync success with server=" << config->server; qDebug()<<"sync success with server=" << config->server;
failed = false;
isSyncing->storeRelaxed(false); isSyncing->storeRelaxed(false);
// Cancel the timer // Cancel the timer
syncTimer->deleteLater(); syncTimer->deleteLater();
// When sync is done, set the connection // When sync is done, set the connection
this->doRPCSetConnection(connection); this->doRPCSetConnection(connection);
}, [=](auto) { }, [=](auto) {
DEBUG("sync failed with server=" << config->server << " . continuing sync loop" ); DEBUG("sync failed with server=" << config->server << " . retrying after delay");
}); });
} while (failed); });
}); });
// While it is syncing, we'll show the status updates while it is alive. // While it is syncing, we'll show the status updates while it is alive.

2
src/controller.cpp

@ -247,8 +247,6 @@ void Controller::fillTxJsonParams(json& allRecepients, Tx tx)
} }
} }
void Controller::noConnection() void Controller::noConnection()
{ {
qDebug()<< __func__; qDebug()<< __func__;

1
src/firsttimewizard.cpp

@ -759,7 +759,6 @@ if (reply.toUpper().trimmed() != "OK") {
qDebug() << __func__ << ": Null response on retry from litelib_initialize_new_from_phrase"; qDebug() << __func__ << ": Null response on retry from litelib_initialize_new_from_phrase";
} }
} }
// 4. Finally attempt to save the wallet // 4. Finally attempt to save the wallet
{ {
QString reply = ""; QString reply = "";

Loading…
Cancel
Save