Skip to content

Commit

Permalink
Merge pull request #176 from adshares/bioinfo-fixes
Browse files Browse the repository at this point in the history
Merge usptream fixes, libboost 1.7
  • Loading branch information
m-pilarczyk authored Sep 20, 2021
2 parents 3625f97 + 58fcc30 commit acc6dd4
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cmake_policy(SET CMP0048 NEW)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wextra")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -m64 -fPIC -Os -fno-strict-aliasing")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -m64 -fPIC -Os -fno-strict-aliasing -Wno-class-memaccess -Wno-unused-result")

#set(Boost_USE_STATIC_LIBS ON)

Expand Down
11 changes: 8 additions & 3 deletions src/common/helper/blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ namespace Helper {
boost::mutex blocklock;

void arch_old_blocks(uint32_t currentTime) {
DLOG("Arch old blocks\n");
int blocks_shift = 16;
#ifdef BLOCKS_COMPRESSED_SHIFT
unsigned int blocksComprShift = (BLOCKS_COMPRESSED_SHIFT <= BLOCKDIV) ? BLOCKDIV+1 : BLOCKS_COMPRESSED_SHIFT;
blocks_shift = BLOCKS_COMPRESSED_SHIFT;
#endif

unsigned int blocksComprShift = (blocks_shift <= BLOCKDIV) ? BLOCKDIV+1 : blocks_shift;
DLOG("Block compressed shift: %d\n", blocksComprShift);
currentTime -= ((blocksComprShift-1) * BLOCKSEC);
char dirpath[16];
char filepath[32];
Expand All @@ -43,13 +49,12 @@ void arch_old_blocks(uint32_t currentTime) {
Helper::remove_block(dirpath);
}
} else {
std::cerr << "Error directory compressing "<<dirpath<<std::endl;
ELOG("Error directory: %s compressing\n", dirpath);
}
} else {
return;
}
}
#endif
}

void remove_block(const char* blockPath)
Expand Down
1 change: 0 additions & 1 deletion src/common/helper/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ bool parse_amount(int64_t& amount,std::string str_amount) {
}

std::string print_amount(int64_t amount) {
static char text[32];
uint is_neg = amount<0?1:0;
std::string str_amount = std::to_string(amount);
if(str_amount.length() < AMOUNT_DECIMALS + 1 + is_neg) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void update_log_level(const char* iniFilePath)
try {
int log_level = std::stoi(line.substr(length+1));
settings.level = (LoggingLevel)log_level;
} catch (std::exception) {}
} catch (std::exception&) {}
break;
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/default_esc.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@
#define BANK_MIN_MTIME (BLOCKSEC*2) /* AND if no transaction in this period bank can be taken over */
//#define BLOCKS_COMPRESSED_SHIFT 16 /* shift from current block to archive old blocks */
#else
#define BLOCKSEC 512 /* block period in seconds (17min) */
#define BLOCKDIV 2048 /* number of blocks for dividend update (dividend period 12 days) */
#define BLOCKSEC 32 /* block period in seconds (17min) */
#define BLOCKDIV 8 /* number of blocks for dividend update (dividend period 12 days) */
#define MAX_UNDO 4096 /* maximum history of block undo files in blocks (24 days) */
#define MAX_MSGWAIT 0x10 /* wait no more than 16s for a message */
#define VOTE_DELAY 4 /*increase later (maybe monitor network delay)!!!*/
#define VOTE_DELAY 1 /*increase later (maybe monitor network delay)!!!*/
#define VIP_MAX 31 /* maximum number of VIP servers */
#define MIN_PEERS 8 /* keep at least 8 peers connected */
#define MAX_PEERS 16 /* keep not more than 16 peers connected */
#define VALIDATORS 8 /* number of validator threads */
#define CLIENT_POOL 16 /* do not offer more threads that are used for network message validation */
#define USER_MIN_AGE (BLOCKSEC*10000L) /* wait at least 10000 blocks before deleting an account */
#define BANK_MIN_MTIME (BLOCKSEC*1000L) /* AND if no transaction in this period bank can be taken over */
#define BLOCKS_COMPRESSED_SHIFT 16 /* shift from current block to archive old blocks */
#endif

#define TOTALMASS 3875820600000000000L /* total balance (target) */
Expand Down
7 changes: 6 additions & 1 deletion src/escd/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#define NETSRV_SOCK_IDLE 5
#define NETSRV_SOCK_MAXTRY 3

#if BOOST_VERSION >= 107000
#define BUFFER_SIZE(s) ((s).size())
#else
#define BUFFER_SIZE(s) (boost::asio::detail::buffer_size_helper(s))
#endif

//this could all go to the office class and we could use just the start() function

Expand Down Expand Up @@ -274,7 +279,7 @@ class client : public boost::enable_shared_from_this<client> {
void sendError(const ErrorCodes::Code error, boost::asio::const_buffer error_info) {
try {
if(m_version == 2) {
uint32_t size = ERROR_CODE_LENGTH + boost::asio::detail::buffer_size_helper(error_info);
uint32_t size = ERROR_CODE_LENGTH + BUFFER_SIZE(error_info);
boost::asio::write(m_socket, boost::asio::buffer(&size, sizeof(size)));
}
boost::asio::write(m_socket, boost::asio::buffer(&error, ERROR_CODE_LENGTH));
Expand Down
23 changes: 16 additions & 7 deletions src/escd/network/peerclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@
using namespace boost::asio;
using namespace boost::lambda;


#if BOOST_VERSION >= 107000
#define GET_IO_SERVICE(s) ((boost::asio::io_context&)(s).get_executor().context())
#else
#define GET_IO_SERVICE(s) ((s).get_io_service())
#endif


PeerClient::PeerClient(ip::tcp::socket& socket, peer& peer):
m_peer(peer),
m_socket(socket),
m_deadline(m_socket.get_io_service())
m_deadline(GET_IO_SERVICE(m_socket))
{}

void PeerClient::checkDeadline(boost::shared_ptr<deadline_timer> timer, const boost::system::error_code& ec)
Expand Down Expand Up @@ -76,7 +84,7 @@ std::size_t PeerClient::writeSync(void* data , uint32_t len, int timeout)
boost::asio::async_write(m_socket, boost::asio::buffer(data, len), boost::bind(&PeerClient::operationDone, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));

do{
auto& ioService = m_socket.get_io_service();
auto& ioService = GET_IO_SERVICE(m_socket);
if (ioService.stopped()) {
ELOG("Stopping writeSync task because io_service is stopped\n");
m_ec = boost::asio::error::timed_out;
Expand Down Expand Up @@ -108,8 +116,9 @@ std::size_t PeerClient::readSync(void* data , uint32_t len, int timeout)
m_bytes_transferred = 0;
boost::asio::async_read(m_socket, boost::asio::buffer(data, len), boost::bind(&PeerClient::operationDone, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));

do{
auto& ioService = m_socket.get_io_service();
do {
auto& ioService = GET_IO_SERVICE(m_socket);

if (ioService.stopped()) {
ELOG("Stopping readSync task because io_service is stopped\n");
m_ec = boost::asio::error::timed_out;
Expand All @@ -132,7 +141,7 @@ std::size_t PeerClient::readSync(void* data , uint32_t len, int timeout)

void PeerClient::asyncRead(void* data, uint32_t len, peerCallback handler, int timeout)
{
boost::shared_ptr<deadline_timer> timer = boost::make_shared<deadline_timer>(m_socket.get_io_service());
boost::shared_ptr<deadline_timer> timer = boost::make_shared<deadline_timer>(GET_IO_SERVICE(m_socket));

if(timeout > 0){
timer->expires_from_now(boost::posix_time::seconds(timeout));
Expand All @@ -146,7 +155,7 @@ void PeerClient::asyncRead(void* data, uint32_t len, peerCallback handler, int t

void PeerClient::asyncConnect(boost::asio::ip::tcp::resolver::iterator& tcpIterator, peerConnectCallback handler, int timeout)
{
boost::shared_ptr<deadline_timer> timer = boost::make_shared<deadline_timer>(m_socket.get_io_service());
boost::shared_ptr<deadline_timer> timer = boost::make_shared<deadline_timer>(GET_IO_SERVICE(m_socket));

if(timeout > 0)
{
Expand All @@ -159,7 +168,7 @@ void PeerClient::asyncConnect(boost::asio::ip::tcp::resolver::iterator& tcpItera

void PeerClient::asyncWrite(void* data, uint32_t len, peerCallback handler, int timeout)
{
boost::shared_ptr<deadline_timer> timer = boost::make_shared<deadline_timer>(m_socket.get_io_service());
boost::shared_ptr<deadline_timer> timer = boost::make_shared<deadline_timer>(GET_IO_SERVICE(m_socket));

if(timeout > 0){
timer->expires_from_now(boost::posix_time::seconds(timeout));
Expand Down
24 changes: 16 additions & 8 deletions src/escd/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1127,14 +1127,14 @@ void server::LAST_block_final(hash_s& cand) {
}
if(tm->second->svid!=lastsvid) {
lastsvid=tm->second->svid;
if(last_srvs_.nodes.size()<=lastsvid) {
if(lastsvid < last_srvs_.nodes.size()) {
minmsid=last_srvs_.nodes[lastsvid].msid;
} else {
minmsid=0;
}
}
if(tm->second->msid<=minmsid) {
ELOG("FORGET message %04X:%08X [min:%08X len:%d]\n",tm->second->svid,tm->second->msid,minmsid,tm->second->len);
ILOG("FORGET message %04X:%08X [min:%08X len:%d]\n",tm->second->svid,tm->second->msid,minmsid,tm->second->len);
tm->second->remove_undo();
txs_msgs_.erase(tm);
continue;
Expand All @@ -1146,12 +1146,18 @@ void server::LAST_block_final(hash_s& cand) {
}
//bad_insert(tm->second); ... already inserted
//remove_message(tm->second);
txs_msgs_.erase(tm);

if(tm->second->svid==opts_.svid)
message_ptr msg = tm->second;

if(msg->svid==opts_.svid)
{
ELOG("ERROR: trying to remove own invalid message, adding message to sign: %04X:%08X\n", msg->svid, msg->msid);
msg->status &= ~MSGSTAT_BAD;
sign_msgs_.push_front(msg);
} else
{
ELOG("ERROR: trying to remove own invalid message, FATAL, MUST RESUBMIT (TODO!)\n");
SHUTDOWN();
ELOG("Erase invalid message from other node\n");
txs_msgs_.erase(tm);
}

continue;
Expand Down Expand Up @@ -1189,8 +1195,6 @@ void server::LAST_block_final(hash_s& cand) {
txs_msgs_.erase(tm);
if(msg->svid==opts_.svid) {
sign_msgs_.push_front(msg);
} else {
txs_msgs_.erase(tm);
}
} else {
ILOG("MOVE message %04X:%08X [min:%08X len:%d]\n",tm->second->svid,tm->second->msid,minmsid,tm->second->len);
Expand Down Expand Up @@ -1285,11 +1289,15 @@ void server::signlater()
if (opts_.svid != mp->second->svid) {
break;
}
WLOG("Signlater message: %04X:%08X\n", mp->second->svid, mp->second->msid);
msid++;
assert(msid == mp->second->msid);
mp->second->load(opts_.svid);
mp->second->signnewtime(ntime, skey, pkey, msha);
mp->second->status &= ~MSGSTAT_BAD;
mp->second->know.clear();
mp->second->busy.clear();
mp->second->sent.clear();
memcpy(msha, mp->second->sigh, sizeof(hash_t));
mp->second->save();
mp->second->unload(opts_.svid);
Expand Down

0 comments on commit acc6dd4

Please sign in to comment.