From a2980065981ca954f99228773037fd80a7abdd1e Mon Sep 17 00:00:00 2001 From: Thomas Baumbach Date: Sat, 12 Oct 2013 21:07:14 +0200 Subject: [PATCH] v0.6 RC1 - increased minimum chain length for submission to 7 - additional triggers for reconnect on connection problems --- src/main.cpp | 6 +++++- src/main_poolminer.cpp | 31 ++++++++++++++++++++++--------- src/prime.h | 3 ++- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e0811f4b..9c6f7e48 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4804,8 +4804,12 @@ void BitcoinMiner(CWallet *pwallet, CBlockProvider *block_provider, unsigned int break; if (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 10) break; - if (pindexPrev != pindexBest || (block_provider != NULL && GetTime() - nStart > 120)) + if (pindexPrev != pindexBest/* || (block_provider != NULL && GetTime() - nStart > 200)*/) break; + if (thread_id == 0 && block_provider != NULL && (GetTime() - nStart) > 300) { //5 minutes no update? something's wrong -> reconnect! + block_provider->forceReconnect(); + nStart = GetTime(); + } if (fNewBlock) //aka: sieve's done, we need a updated nonce { // Primecoin: a sieve+primality round completes diff --git a/src/main_poolminer.cpp b/src/main_poolminer.cpp index a3c8f122..117ebb08 100644 --- a/src/main_poolminer.cpp +++ b/src/main_poolminer.cpp @@ -18,8 +18,8 @@ #include #define VERSION_MAJOR 0 -#define VERSION_MINOR 5 -#define VERSION_EXT "RC2" +#define VERSION_MINOR 6 +#define VERSION_EXT "RC1" #define MAX_THREADS 32 @@ -153,18 +153,29 @@ public: boost::posix_time::ptime submit_start = boost::posix_time::second_clock::universal_time(); boost::system::error_code submit_error = boost::asio::error::host_not_found; //run at least 1 time ++submitting_share; - while (submit_error && running && (boost::posix_time::second_clock::universal_time() - submit_start).total_seconds() < 100) { - while (socket_to_server == NULL && running && (boost::posix_time::second_clock::universal_time() - submit_start).total_seconds() < 100) //socket error was issued somewhere else + while (submit_error && running && (boost::posix_time::second_clock::universal_time() - submit_start).total_seconds() < 80) { + while (socket_to_server == NULL && running && (boost::posix_time::second_clock::universal_time() - submit_start).total_seconds() < 80) //socket error was issued somewhere else boost::this_thread::sleep(boost::posix_time::milliseconds(100)); - if (running && (boost::posix_time::second_clock::universal_time() - submit_start).total_seconds() < 100) { - size_t len = boost::asio::write(*socket_to_server, boost::asio::buffer((unsigned char*)&blockraw, 128), boost::asio::transfer_all(), submit_error); + if (running && (boost::posix_time::second_clock::universal_time() - submit_start).total_seconds() < 80) { + boost::asio::write(*socket_to_server, boost::asio::buffer((unsigned char*)&blockraw, 128), boost::asio::transfer_at_least(1), submit_error); //FaF + //size_t len = boost::asio::write(*socket_to_server, boost::asio::buffer((unsigned char*)&blockraw, 128), boost::asio::transfer_all(), submit_error); //socket_to_server->write_some(boost::asio::buffer((unsigned char*)&blockraw, 128), submit_error); - if (submit_error || len != 128) + if (submit_error) std::cout << submit_error << " @ write_submit" << std::endl; } } --submitting_share; } + + void forceReconnect() { + std::cout << "force reconnect if possible!" << std::endl; + if (socket_to_server != NULL) { + boost::system::error_code close_error; + socket_to_server->close(close_error); + if (close_error) + std::cout << close_error << " @ close" << std::endl; + } + } protected: boost::shared_mutex _mutex_getwork; @@ -231,6 +242,7 @@ public: boost::asio::ip::tcp::resolver::iterator endpoint; boost::asio::ip::tcp::resolver::iterator end; boost::asio::ip::tcp::no_delay nd_option(true); + boost::asio::socket_base::keep_alive ka_option(true); while (running) { endpoint = resolver.resolve(query); @@ -245,6 +257,7 @@ public: std::cout << "connecting to " << tcp_ep << std::endl; } socket->set_option(nd_option); + socket->set_option(ka_option); if (error_socket) { std::cout << error_socket << std::endl; @@ -351,7 +364,7 @@ public: else reject_counter++; if (reject_counter >= 3) { - std::cout << "too many rejects (3), forcing reconnect." << std::endl; + std::cout << "too many rejects (3) in a row, forcing reconnect." << std::endl; socket->close(); done = true; } @@ -372,7 +385,7 @@ public: } socket_to_server = NULL; //TODO: lock/mutex - for (int i = 0; i < 100 && submitting_share < 1; ++i) + for (int i = 0; i < 50 && submitting_share < 1; ++i) //wait <5 seconds until reconnect (force reconnect when share is waiting to be submitted) boost::this_thread::sleep(boost::posix_time::milliseconds(100)); } } diff --git a/src/prime.h b/src/prime.h index 41588d1a..e1894438 100644 --- a/src/prime.h +++ b/src/prime.h @@ -15,7 +15,7 @@ /* POOL ADDON */ /**************/ -static const unsigned int POOL_SHARE_MINIMUM = 6; +static const unsigned int POOL_SHARE_MINIMUM = 7; extern size_t thread_num_max; class CBlockProvider { @@ -24,6 +24,7 @@ public: ~CBlockProvider() { } virtual CBlock* getBlock(unsigned int thread_id, unsigned int last_time) = 0; virtual void submitBlock(CBlock* block) = 0; + virtual void forceReconnect() = 0; }; /**********************/