Skip to content

Commit

Permalink
Add the batch of release v3.2.2 commits
Browse files Browse the repository at this point in the history
  • Loading branch information
developer-at-bcn committed Aug 6, 2018
1 parent 4c43f60 commit 25e429a
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 28 deletions.
5 changes: 5 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Release Notes

### v3.2.2

- Fixed an output bufferization issue in the `bytecoind` daemon.
- Fixed a rare downloader's crash on Windows.

### v3.2.1

- Fixed a severe bug in the downloader.
Expand Down
13 changes: 11 additions & 2 deletions src/Core/Archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ const std::string Archive::BLOCK("b");
const std::string Archive::TRANSACTION("t");
const std::string Archive::CHECKPOINT("c");

Archive::Archive(bool read_only, const std::string &path) : read_only(read_only) {
try {
//static const float DB_COMMIT_PERIOD = 60; // 1 minute sounds good for archive

Archive::Archive(bool read_only, const std::string &path)
: read_only(read_only)
// , commit_timer(std::bind(&Archive::db_commit, this))
{
try {
m_db = std::make_unique<DB>(read_only, path);
if (!m_db->get("$unique_id", unique_id)) {
DB::Cursor cur = m_db->begin(std::string());
Expand All @@ -42,6 +47,7 @@ Archive::Archive(bool read_only, const std::string &path) : read_only(read_only)
else
throw;
}
// commit_timer.once(DB_COMMIT_PERIOD);
}

// struct Record {
Expand Down Expand Up @@ -75,6 +81,7 @@ void Archive::db_commit() {
if (!m_db || read_only)
return;
m_db->commit_db_txn();
// commit_timer.once(DB_COMMIT_PERIOD);
}

void Archive::read_archive(api::bytecoind::GetArchive::Request &&req, api::bytecoind::GetArchive::Response &resp) {
Expand All @@ -100,6 +107,8 @@ void Archive::read_archive(api::bytecoind::GetArchive::Request &&req, api::bytec
api::bytecoind::GetArchive::ArchiveRecord rec;
seria::from_binary(rec, cur.get_value_array());
resp.records.push_back(rec);
if(req.records_only)
continue;
std::string str_hash = common::pod_to_hex(rec.hash);
const auto hash_key = HASHES_PREFIX + DB::to_binary_key(rec.hash.data, sizeof(rec.hash.data));
if (rec.type == BLOCK) {
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Archive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include "platform/DB.hpp"
//#include "platform/Network.hpp"
#include "rpc_api.hpp"

namespace bytecoin {
Expand All @@ -14,6 +15,7 @@ class Archive {
uint64_t next_record_id = 0;
std::string unique_id;

// platform::Timer commit_timer;
public:
explicit Archive(bool read_only, const std::string &path);
std::string get_unique_id() const { return unique_id; }
Expand Down
18 changes: 12 additions & 6 deletions src/Core/BlockChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ BroadcastAction BlockChain::add_block(
return BroadcastAction::NOTHING;
}
try {
if (!have_block) {
if (!have_block) { // have block, but not header during internal_import
store_block(pb.bid, pb.block_data); // Do not commit between here and
// reorganize_blocks or invariant might be dead
if (info->height > m_currency.last_sw_checkpoint().first)
Expand All @@ -197,6 +197,8 @@ BroadcastAction BlockChain::add_block(
}
check_children_counter(info->cumulative_difficulty, pb.bid, 1);
modify_children_counter(info->cumulative_difficulty, pb.bid, -1); // -1 from default 1 gives 0
if (info->hash == m_currency.last_sw_checkpoint().second)
build_blods();
auto tip_check_cd = get_checkpoint_difficulty(get_tip_bid());
auto bid_check_cd = get_checkpoint_difficulty(info->hash);
if (compare(bid_check_cd, info->cumulative_difficulty, tip_check_cd, get_tip_cumulative_difficulty()) > 0) {
Expand All @@ -209,7 +211,6 @@ BroadcastAction BlockChain::add_block(
} else
reorganize_blocks(pb.bid, pb, *info);
}
build_blods(); // In case we just passed the last checkpoint, otherwise it is nop
} catch (const std::exception &ex) {
m_log(logging::ERROR) << "Exception while reorganizing blockchain, probably out of disk space ex.what="
<< ex.what() << ", " << delete_blockchain_message << m_db.get_path() << std::endl;
Expand Down Expand Up @@ -548,7 +549,8 @@ bool BlockChain::read_block(const Hash &bid, BinaryArray *block_data, RawBlock *
auto key = BLOCK_PREFIX + DB::to_binary_key(bid.data, sizeof(bid.data)) + BLOCK_SUFFIX;
if (!m_db.get(key, rb))
return false;
seria::from_binary(*raw_block, rb);
if(raw_block)
seria::from_binary(*raw_block, rb);
*block_data = std::move(rb);
return true;
}
Expand Down Expand Up @@ -887,6 +889,9 @@ void BlockChain::start_internal_import() {
skipped += 1;
continue; // block in main chain
}
BinaryArray block_data;
if( read_block(bid, &block_data, nullptr) )
m_archive.add(Archive::BLOCK, block_data, bid, "start_internal_import");
}
cur.erase();
erased += 1;
Expand All @@ -909,7 +914,7 @@ bool BlockChain::internal_import() {
}
PreparedBlock pb(std::move(rb), nullptr);
api::BlockHeader info;
if (add_block(pb, &info, std::string()) != BroadcastAction::BROADCAST_ALL) {
if (add_block(pb, &info, "internal_import") != BroadcastAction::BROADCAST_ALL) {
m_log(logging::WARNING) << "Block corrupted during internal import for height=" << get_tip_height() + 1
<< " bid=" << bid << std::endl;
break;
Expand Down Expand Up @@ -1086,8 +1091,9 @@ bool BlockChain::add_blod(const api::BlockHeader &header) {
void BlockChain::build_blods() {
if (!blods.empty())
return; // build only once per daemon launch
if (!in_chain(m_currency.last_sw_checkpoint().first, m_currency.last_sw_checkpoint().second))
return; // build only after main chain passes through last SW checkpoint
api::BlockHeader last_sw_checkpoint_header;
if( !read_header(m_currency.last_sw_checkpoint().second, &last_sw_checkpoint_header) )
return;
std::set<Hash> bad_header_hashes; // sidechains that do not pass through last SW checkpoint
std::set<Hash> good_header_hashes; // sidechains that pass through last SW checkpoint
std::vector<api::BlockHeader> good_headers;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/BlockChain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class BlockChain {
bool read_chain(Height height, Hash *bid) const;
bool in_chain(Height height, Hash bid) const;
bool read_block(const Hash &bid, RawBlock *rb) const;
bool read_block(const Hash &bid, BinaryArray *block_data, RawBlock *rb) const;
bool read_block(const Hash &bid, BinaryArray *block_data, RawBlock *rb) const; // rb can be null here
bool has_block(const Hash &bid) const;
bool read_header(const Hash &bid, api::BlockHeader *info, Height hint = 0) const;
bool read_transaction(const Hash &tid, Transaction *tx, Height *block_height, Hash *block_hash,
Expand Down
4 changes: 2 additions & 2 deletions src/Core/BlockChainFileFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ bool LegacyBlockChainReader::import_blocks(BlockChainState *block_chain) {
BinaryArray rba = get_block_data_by_index(block_chain->get_tip_height() + 1);
PreparedBlock pb(std::move(rba), nullptr);
api::BlockHeader info;
if (block_chain->add_block(pb, &info, std::string()) != BroadcastAction::BROADCAST_ALL) {
if (block_chain->add_block(pb, &info, "blocks_file") != BroadcastAction::BROADCAST_ALL) {
std::cout << "block_chain.add_block !BROADCAST_ALL block=" << block_chain->get_tip_height() + 1
<< std::endl;
block_chain->db_commit();
Expand Down Expand Up @@ -183,7 +183,7 @@ bool LegacyBlockChainReader::import_blockchain2(const std::string &coin_folder,
while (block_chain->get_tip_height() < import_height) {
PreparedBlock pb = reader.get_prepared_block_by_index(block_chain->get_tip_height() + 1);
api::BlockHeader info;
if (block_chain->add_block(pb, &info, std::string()) != BroadcastAction::BROADCAST_ALL) {
if (block_chain->add_block(pb, &info, "blocks_file") != BroadcastAction::BROADCAST_ALL) {
std::cout << "block_chain.add_block !BROADCAST_ALL block=" << block_chain->get_tip_height() + 1
<< std::endl;
block_chain->db_commit();
Expand Down
4 changes: 2 additions & 2 deletions src/Core/BlockChainState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ BlockChainState::BlockChainState(logging::ILogger &log, const Config &config, co
m_db.get("$version", version);
if (version == "B" || version == "1" || version == "2" || version == "3" || version == "4") {
start_internal_import();
version = "5";
version = version_current;
m_db.put("$version", version, false);
db_commit();
}
Expand Down Expand Up @@ -772,7 +772,7 @@ BroadcastAction BlockChainState::add_mined_block(
}
PreparedBlock pb(std::move(*raw_block), nullptr);
*raw_block = pb.raw_block;
return add_block(pb, info, "0.0.0.0:0");
return add_block(pb, info, "json_rpc");
}

void BlockChainState::clear_mining_transactions() const {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Currency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ uint8_t Currency::get_block_minor_version_for_height(Height height) const {
return 0;
if (height > upgrade_height_v2 && height <= upgrade_height_v3)
return 0;
return 1; // Signal of checkpoints support
return 2; // Signal of checkpoints support
}

uint32_t Currency::block_granted_full_reward_zone_by_block_version(uint8_t block_major_version) const {
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ api::bytecoind::GetStatus::Response Node::create_status_response3() const {
res.top_block_hash = m_block_chain.get_tip_bid();
res.top_block_timestamp = tip.timestamp;
res.top_block_difficulty = tip.difficulty;
res.top_block_cumulative_difficulty = tip.cumulative_difficulty;
res.recommended_fee_per_byte = m_block_chain.get_currency().coin() / 1000000; // TODO - calculate
res.next_block_effective_median_size = m_block_chain.get_next_effective_median_size();
res.transaction_pool_version = m_block_chain.get_tx_pool_version();
Expand Down Expand Up @@ -701,7 +702,7 @@ bool Node::handle_send_transaction3(http::Client *, http::RequestData &&, json_r
}
const Hash tid = get_transaction_hash(tx);
auto action = m_block_chain.add_transaction(
tid, tx, request.binary_transaction, m_p2p.get_local_time(), &conflict_height, "0.0.0.0:0");
tid, tx, request.binary_transaction, m_p2p.get_local_time(), &conflict_height, "json_rpc");
switch (action) {
case AddTransactionResult::BAN:
throw json_rpc::Error(
Expand Down
22 changes: 12 additions & 10 deletions src/Core/NodeDownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,22 +278,23 @@ void Node::DownloaderV11::on_msg_notify_request_objects(P2PClientBytecoin *who,
}
}
for (auto &&bid : req.missed_ids) {
for (auto dit = m_download_chain.begin(); dit != m_download_chain.end(); ++dit) {
if (dit->status != DownloadCell::DOWNLOADING || dit->downloading_client != who || dit->bid != bid)
for (size_t dit_counter = 0; dit_counter != m_download_chain.size(); ++dit_counter) {
auto & dit = m_download_chain.at(dit_counter);
if (dit.status != DownloadCell::DOWNLOADING || dit.downloading_client != who || dit.bid != bid)
continue; // downloaded or downloading
stop_download(*dit, false);
stop_download(dit, false);
if (!m_chain_client || m_chain_client == who) {
m_node->m_log(logging::INFO)
<< "Downloader cannot download block from any connected client, cleaning chain" << std::endl;
while (dit != m_download_chain.end()) {
while (m_download_chain.size() > dit_counter) {
stop_download(m_download_chain.back(), false);
m_download_chain.pop_back();
}
m_chain.clear();
advance_download();
return;
}
start_download(*dit, m_chain_client);
start_download(dit, m_chain_client);
}
}
advance_download();
Expand Down Expand Up @@ -406,8 +407,9 @@ void Node::DownloaderV11::advance_download() {
for (auto lit = m_who_downloaded_block.begin(); lit != m_who_downloaded_block.end(); ++lit)
who_downloaded_counter[*lit] += 1;
auto idea_now = std::chrono::steady_clock::now();
for (auto dit = m_download_chain.begin(); dit != m_download_chain.end(); ++dit) {
if (dit->status != DownloadCell::DOWNLOADING || dit->downloading_client)
for (size_t dit_counter = 0; dit_counter != m_download_chain.size(); ++dit_counter) {
auto & dit = m_download_chain.at(dit_counter);
if (dit.status != DownloadCell::DOWNLOADING || dit.downloading_client)
continue; // downloaded or downloading
if (total_downloading_blocks >= TOTAL_DOWNLOAD_BLOCKS)
break;
Expand All @@ -420,7 +422,7 @@ void Node::DownloaderV11::advance_download() {
// We clamp speed so that if even 1 downloaded all blocks, we will give
// small % of blocks to other peers
if (who.second * ready_speed < ready_counter * speed &&
who.first->get_last_received_sync_data().current_height >= dit->expected_height) {
who.first->get_last_received_sync_data().current_height >= dit.expected_height) {
ready_client = who.first;
ready_counter = who.second;
ready_speed = speed;
Expand All @@ -432,15 +434,15 @@ void Node::DownloaderV11::advance_download() {
m_node->m_log(logging::INFO)
<< "DownloaderV11::advance_download cannot download blocks from any connected client, cleaning chain"
<< std::endl;
while (dit != m_download_chain.end()) {
while (m_download_chain.size() > dit_counter) {
stop_download(m_download_chain.back(), false);
m_download_chain.pop_back();
}
m_chain.clear();
advance_chain();
return;
}
start_download(*dit, ready_client);
start_download(dit, ready_client);
}
const bool bad_timeout =
!m_download_chain.empty() && m_download_chain.front().status == DownloadCell::DOWNLOADING &&
Expand Down
1 change: 1 addition & 0 deletions src/Core/rpc_api_serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ void ser_members(bytecoin::api::bytecoind::GetArchive::Request &v, ISeria &s) {
seria_kv("archive_id", v.archive_id, s);
seria_kv("from_record", v.from_record, s);
seria_kv("max_count", v.max_count, s);
seria_kv("records_only", v.records_only, s);
}
void ser_members(bytecoin::api::bytecoind::GetArchive::Response &v, ISeria &s) {
seria_kv("records", v.records, s);
Expand Down
2 changes: 1 addition & 1 deletion src/logging/ConsoleLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ void ConsoleLogger::do_log_string(const std::string &message) {
}
}

std::cout << std::flush;
if (changed_color) {
std::cout << std::flush;
common::console::set_text_color(Color::Default);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/rpc_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ struct GetArchive {
uint64_t from_record = 0;
uint64_t max_count = 100;
static constexpr uint64_t MAX_COUNT = 10000;
bool records_only = false; // no objects
};
struct ArchiveRecord {
Timestamp timestamp = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#pragma once

// defines are for Windows resource compiler
#define bytecoin_VERSION_WINDOWS_COMMA 3, 18, 8, 3
#define bytecoin_VERSION_STRING "3.2.1"
#define bytecoin_VERSION_WINDOWS_COMMA 3, 18, 8, 6
#define bytecoin_VERSION_STRING "3.2.2"
#ifndef RC_INVOKED // Windows resource compiler

namespace bytecoin {
Expand Down

0 comments on commit 25e429a

Please sign in to comment.