Skip to content

Commit

Permalink
Add the batch of release v3.2.0 commits
Browse files Browse the repository at this point in the history
  • Loading branch information
developer-at-bcn committed Aug 2, 2018
1 parent 8d31663 commit 4b926b0
Show file tree
Hide file tree
Showing 78 changed files with 1,300 additions and 921 deletions.
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ if(USE_SQLITE)
# Requires dl on Linux, we add it unconditionally for simplicity.
message(STATUS "Database selected: SQLite 3. Make sure it is put into ../sqlite/")
include_directories(../sqlite)
set(SRC_DB ../sqlite/sqlite3.c src/platform/DBsqlite3.cpp src/platform/DBsqlite3.hpp)
set(SRC_WARNINGS_DB ../sqlite/sqlite3.c)
set(SRC_DB src/platform/DBsqlite3.cpp src/platform/DBsqlite3.hpp)
add_definitions(-Dplatform_USE_SQLITE=1)
else()
message(STATUS "Database selected: LMDB. Make sure it is put into ../lmdb/")
include_directories(../lmdb/libraries/liblmdb)
set(SRC_DB ../lmdb/libraries/liblmdb/mdb.c ../lmdb/libraries/liblmdb/midl.c src/platform/DBlmdb.cpp src/platform/DBlmdb.hpp)
set(SRC_WARNINGS_DB ../lmdb/libraries/liblmdb/mdb.c ../lmdb/libraries/liblmdb/midl.c)
set(SRC_DB src/platform/DBlmdb.cpp src/platform/DBlmdb.hpp)
endif()
if(USE_SSL)
message(STATUS "SSL usage: ON. Make sure openssl headers are in " ${OPENSSL_ROOT} "/include and static libs are in " ${OPENSSL_ROOT} "/")
Expand Down Expand Up @@ -86,27 +88,31 @@ file(GLOB SRC_HTTP src/http/*.cpp src/http/*.hpp)
file(GLOB SRC_PLATFORM
src/platform/ExclusiveLock.cpp src/platform/ExclusiveLock.hpp
src/platform/Files.cpp src/platform/Files.hpp
src/platform/Time.cpp src/platform/Time.hpp
src/platform/Network.cpp src/platform/Network.hpp
src/platform/PathTools.cpp src/platform/PathTools.hpp
src/platform/PreventSleep.cpp src/platform/PreventSleep.hpp
src/platform/Windows.hpp src/platform/DB.hpp
)
if(WIN32)
set_property(SOURCE ${SRC_CRYPTO} PROPERTY COMPILE_FLAGS -Ot)
set_property(SOURCE ${SRC_DB} PROPERTY COMPILE_FLAGS "-Ot -w")
set_property(SOURCE ${SRC_DB} PROPERTY COMPILE_FLAGS -Ot)
set_property(SOURCE ${SRC_WARNINGS_DB} PROPERTY COMPILE_FLAGS "-Ot -w")
set_property(SOURCE ${SRC_COMMON} PROPERTY COMPILE_FLAGS -Ot)
set_property(SOURCE ${SRC_SERIALIZATION} PROPERTY COMPILE_FLAGS -Ot)
set_property(SOURCE ${SRC_SERIA} PROPERTY COMPILE_FLAGS -Ot)
else()
set_property(SOURCE ${SRC_CRYPTO} PROPERTY COMPILE_FLAGS -O3)
set_property(SOURCE ${SRC_DB} PROPERTY COMPILE_FLAGS "-O3 -w")
set_property(SOURCE ${SRC_DB} PROPERTY COMPILE_FLAGS -O3)
set_property(SOURCE ${SRC_WARNINGS_DB} PROPERTY COMPILE_FLAGS "-O3 -w")
set_property(SOURCE ${SRC_COMMON} PROPERTY COMPILE_FLAGS -O3)
set_property(SOURCE ${SRC_SERIALIZATION} PROPERTY COMPILE_FLAGS -O3)
set_property(SOURCE ${SRC_SERIA} PROPERTY COMPILE_FLAGS -O3)
endif()
include_directories(src)
set(SOURCE_FILES
${SRC_DB}
${SRC_WARNINGS_DB}
${SRC_COMMON}
${SRC_HTTP}
${SRC_CORE}
Expand Down
6 changes: 6 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Release Notes

### v3.2.0

- *Warning:* This version uses different format of `bytecoind` database and `walletd` caches, they will be upgraded to the new format on a first start of daemons. Prepare for downtime of up to 2 hours depending on your wallet size and computer performance.
- __API change:__ Renamed methods `create_send_proof` and `check_send_proof` to `create_sendproof` and `check_sendproof` respectively (along with input parameter `send_proof` that became `sendproof`).
- Fixed minor bugs found in the beta release.

### v3.2.0-beta-20180723

- *Warning:* This version uses different format of `bytecoind` database and `walletd` caches, they will be upgraded to the new format on a first start of daemons. Prepare for downtime of up to 2 hours depending on your wallet size and computer performance.
Expand Down
142 changes: 142 additions & 0 deletions src/Core/Archive.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// Copyright (c) 2012-2018, The CryptoNote developers, The Bytecoin developers.
// Licensed under the GNU Lesser General Public License. See LICENSE for details.

#include "Archive.hpp"
#include <boost/lexical_cast.hpp>
#include <iostream>
#include "CryptoNoteTools.hpp"
#include "Currency.hpp"
#include "common/StringTools.hpp"
#include "common/Varint.hpp"
#include "crypto/crypto.hpp"
#include "platform/Time.hpp"
#include "seria/BinaryInputStream.hpp"
#include "seria/BinaryOutputStream.hpp"

using namespace bytecoin;
using namespace platform;

static const std::string RECORDS_PREFIX = "r";
static const std::string HASHES_PREFIX = "h";

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 {
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());
if (!cur.end())
throw std::runtime_error("Archive database format unknown version, please delete " + m_db->get_path());
unique_id = common::pod_to_hex(crypto::random_keypair().public_key);
m_db->put("$unique_id", unique_id, true);
std::cout << "Created archive with unique id: " << unique_id << std::endl;
}
DB::Cursor cur2 = m_db->rbegin(RECORDS_PREFIX);
next_record_id = cur2.end() ? 0 : 1 + common::read_varint_sqlite4(cur2.get_suffix());
} catch (const std::exception &) {
if (read_only)
m_db = nullptr;
else
throw;
}
}

// struct Record {
// std::string type;
// BinaryArray data;
// Timestamp timestamp;
//};

void Archive::add(const std::string &type,
const BinaryArray &data,
const Hash &hash,
const std::string &source_address) {
if (!m_db || read_only || source_address.empty())
return;
std::cout << "Adding to archive: " << type << " hash=" << hash << " size=" << data.size()
<< " source_address=" << source_address << std::endl;
auto hash_key = HASHES_PREFIX + DB::to_binary_key(hash.data, sizeof(hash.data));
DB::Value value;
if (!m_db->get(hash_key, value))
m_db->put(hash_key, data, true);
api::bytecoind::GetArchive::ArchiveRecord rec;
rec.timestamp = now_unix_timestamp(&rec.timestamp_usec);
rec.type = type;
rec.hash = hash;
rec.source_address = source_address;
m_db->put(RECORDS_PREFIX + common::write_varint_sqlite4(next_record_id), seria::to_binary(rec), true);
next_record_id += 1;
}

void Archive::db_commit() {
if (!m_db || read_only)
return;
m_db->commit_db_txn();
}

void Archive::read_archive(api::bytecoind::GetArchive::Request &&req, api::bytecoind::GetArchive::Response &resp) {
if (req.archive_id != unique_id) {
api::bytecoind::GetArchive::Error err;
err.code = api::bytecoind::GetArchive::WRONG_ARCHIVE_ID;
err.message = "Archive id changed";
err.archive_id = unique_id;
throw err;
}
resp.from_record = req.from_record;
if (resp.from_record > next_record_id)
resp.from_record = next_record_id;
if (req.max_count > api::bytecoind::GetArchive::Request::MAX_COUNT)
req.max_count = api::bytecoind::GetArchive::Request::MAX_COUNT;
if (!m_db)
return;
resp.records.reserve(static_cast<size_t>(req.max_count));
for (DB::Cursor cur = m_db->begin(RECORDS_PREFIX, common::write_varint_sqlite4(resp.from_record)); !cur.end();
cur.next()) {
if (resp.records.size() >= req.max_count)
break;
api::bytecoind::GetArchive::ArchiveRecord rec;
seria::from_binary(rec, cur.get_value_array());
resp.records.push_back(rec);
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) {
if (resp.blocks.count(str_hash) == 0) {
BinaryArray data;
invariant(m_db->get(hash_key, data), "");
api::bytecoind::GetArchive::ArchiveBlock &bl = resp.blocks[str_hash];
RawBlock raw_block;
seria::from_binary(raw_block, data);
Block block;
invariant(block.from_raw_block(raw_block), "");
bl.raw_header = block.header;
bl.raw_transactions.reserve(block.transactions.size());
for (size_t i = 0; i != block.transactions.size(); ++i) {
bl.raw_transactions.push_back(static_cast<TransactionPrefix &>(block.transactions.at(i)));
bl.transaction_binary_sizes.push_back(static_cast<uint32_t>(raw_block.transactions.at(i).size()));
}
bl.base_transaction_hash = get_transaction_hash(block.header.base_transaction);
}
}
if (rec.type == TRANSACTION) {
if (resp.transactions.count(str_hash) == 0) {
BinaryArray data;
invariant(m_db->get(hash_key, data), "");
TransactionPrefix &tr = resp.transactions[str_hash];
Transaction transaction;
seria::from_binary(transaction, data);
tr = static_cast<TransactionPrefix &>(transaction);
}
}
if (rec.type == CHECKPOINT) {
if (resp.checkpoints.count(str_hash) == 0) {
BinaryArray data;
invariant(m_db->get(hash_key, data), "");
SignedCheckPoint &ch = resp.checkpoints[str_hash];
seria::from_binary(ch, data);
}
}
}
}
30 changes: 30 additions & 0 deletions src/Core/Archive.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2012-2018, The CryptoNote developers, The Bytecoin developers.
// Licensed under the GNU Lesser General Public License. See LICENSE for details.

#pragma once

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

namespace bytecoin {

class Archive {
const bool read_only;
std::unique_ptr<platform::DB> m_db;
uint64_t next_record_id = 0;
std::string unique_id;

public:
explicit Archive(bool read_only, const std::string &path);
std::string get_unique_id() const { return unique_id; }
void add(
const std::string &type, const common::BinaryArray &data, const Hash &hash, const std::string &source_address);
void read_archive(api::bytecoind::GetArchive::Request &&req, api::bytecoind::GetArchive::Response &resp);
void db_commit();

static const std::string BLOCK;
static const std::string TRANSACTION;
static const std::string CHECKPOINT;
};

} // namespace bytecoin
Loading

0 comments on commit 4b926b0

Please sign in to comment.