Skip to content

Commit

Permalink
Add the batch of release v3.2.4 commits
Browse files Browse the repository at this point in the history
  • Loading branch information
developer-at-bcn committed Aug 17, 2018
1 parent 31eb6a7 commit 8fb1958
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 29 deletions.
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.4

- Added the testnet functionality.
- Fixed `WRONG_BLOCKCHAIN` problem when walletd ends up in a state where it could not sync with `bytecoind`.
- Put a stop to infinite attempts to download blockchain from nodes lagging behind.

### v3.2.3

- Fixed issues in SQLite logic in x86-32 daemons.
Expand Down
4 changes: 2 additions & 2 deletions src/Core/BlockChainState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,8 @@ AddTransactionResult BlockChainState::add_transaction(const Hash &tid, const Tra
if (read_keyimage(in.key_image, conflict_height)) {
// std::cout << tid << " " << in.key_image <<
// std::endl;
m_log(logging::WARNING) << "OUTPUT_ALREADY_SPENT in transaction " << tid
<< std::endl; // TODO - remove
// m_log(logging::WARNING) << "OUTPUT_ALREADY_SPENT in transaction " << tid
// << std::endl; // TODO - remove
return AddTransactionResult::OUTPUT_ALREADY_SPENT; // Already spent in main chain
}
}
Expand Down
28 changes: 25 additions & 3 deletions src/Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,36 @@ static void parse_peer_and_add_to_container(const std::string &str, std::vector<
container.push_back(na);
}

static void parse_net(const std::string &str, bool* is_testnet, bool* is_stagenet) {
if (str == "main") {
*is_stagenet = false;
*is_testnet = false;
return;
}
if (str == "stage") {
*is_stagenet = true;
*is_testnet = false;
return;
}
if (str == "test") {
*is_stagenet = false;
*is_testnet = true;
return;
}
throw std::runtime_error("Wrong net value " + str + ", should be test, or stage, or main");
}

using namespace common;
using namespace bytecoin;

const static UUID BYTECOIN_NETWORK{{0x11, 0x10, 0x01, 0x11, 0x11, 0x00, 0x01, 0x01, 0x10, 0x11, 0x00, 0x12, 0x10, 0x11,
0x01, 0x10}}; // Bender's nightmare

Config::Config(common::CommandLine &cmd)
: is_testnet(cmd.get_bool("--testnet"))
: is_testnet(false)
, is_stagenet(false)
, is_archive(cmd.get_bool("--archive"))
// , mempool_tx_live_time(parameters::CRYPTONOTE_MEMPOOL_TX_LIVETIME)
// , mempool_tx_live_time(parameters::CRYPTONOTE_MEMPOOL_TX_LIVETIME)
, blocks_file_name(parameters::CRYPTONOTE_BLOCKS_FILENAME)
, block_indexes_file_name(parameters::CRYPTONOTE_BLOCKINDEXES_FILENAME)
, crypto_note_name(CRYPTONOTE_NAME)
Expand All @@ -44,13 +64,15 @@ Config::Config(common::CommandLine &cmd)
, p2p_local_gray_list_limit(P2P_LOCAL_GRAY_PEERLIST_LIMIT)
, p2p_default_peers_in_handshake(P2P_DEFAULT_PEERS_IN_HANDSHAKE)
, p2p_default_connections_count(P2P_DEFAULT_CONNECTIONS_COUNT)
, p2p_allow_local_ip(is_testnet)
, p2p_allow_local_ip(false)
, p2p_whitelist_connections_percent(P2P_DEFAULT_WHITELIST_CONNECTIONS_PERCENT)
, p2p_block_ids_sync_default_count(BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT)
, p2p_blocks_sync_default_count(BLOCKS_SYNCHRONIZING_DEFAULT_COUNT)
, rpc_get_blocks_fast_max_count(COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT) {
common::pod_from_hex(P2P_STAT_TRUSTED_PUBLIC_KEY, trusted_public_key);

if (const char *pa = cmd.get("--net"))
parse_net(pa, &is_testnet, &is_stagenet);
if (is_testnet) {
network_id.data[0] += 1;
p2p_bind_port += 1000;
Expand Down
1 change: 1 addition & 0 deletions src/Core/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Config { // Consensus does not depend on those parameters
explicit Config(common::CommandLine &cmd);

bool is_testnet;
bool is_stagenet;
bool is_archive;
Timestamp locked_tx_allowed_delta_seconds;
Height locked_tx_allowed_delta_blocks;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Multicore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void WalletPreparatorMulticore::thread_run() {
SecretKey view_secret_key;
Height height = 0;
int local_work_counter = 0;
api::bytecoind::SyncBlocks::SyncBlock sync_block;
api::bytecoind::GetRawBlock::Response sync_block;
std::vector<std::vector<uint32_t>> global_indices;
{
std::unique_lock<std::mutex> lock(mu);
Expand Down
32 changes: 32 additions & 0 deletions src/Core/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ std::unordered_map<std::string, Node::JSONRPCHandlerFunction> Node::m_jsonrpc_ha
{api::bytecoind::GetArchive::method(), json_rpc::make_member_method(&Node::on_get_archive)},
{api::bytecoind::SendTransaction::method(), json_rpc::make_member_method(&Node::handle_send_transaction3)},
{api::bytecoind::CheckSendProof::method(), json_rpc::make_member_method(&Node::handle_check_sendproof3)},
// {api::bytecoind::GetRawBlock::method(), json_rpc::make_member_method(&Node::on_get_raw_block)},
{api::bytecoind::SyncBlocks::method(), json_rpc::make_member_method(&Node::on_wallet_sync3)},
{api::bytecoind::GetRawTransaction::method(), json_rpc::make_member_method(&Node::on_get_raw_transaction3)},
{api::bytecoind::SyncMemPool::method(), json_rpc::make_member_method(&Node::on_sync_mempool3)}};
Expand Down Expand Up @@ -662,6 +663,37 @@ bool Node::on_sync_mempool3(http::Client *, http::RequestData &&, json_rpc::Requ
return true;
}

bool Node::on_get_raw_block(http::Client *, http::RequestData &&, json_rpc::Request &&,
api::bytecoind::GetRawBlock::Request && request, api::bytecoind::GetRawBlock::Response & response){

if (!m_block_chain.read_header(request.hash, &response.header))
throw json_rpc::Error(-5, "Block not found by hash"); // TODO - use HASH_NOT_FOUND enum
BlockChainState::BlockGlobalIndices global_indices;

RawBlock rb;
invariant(m_block_chain.read_block(request.hash, &rb), "Block must be there, but it is not there");
Block block;
invariant(block.from_raw_block(rb), "RawBlock failed to convert into block");

auto coinbase_size = static_cast<uint32_t>(seria::binary_size(block.header.base_transaction));
response.header.transactions_cumulative_size = response.header.block_size;

response.header.block_size = response.header.transactions_cumulative_size + static_cast<uint32_t>(rb.block.size()) - coinbase_size;
response.base_transaction_hash = get_transaction_hash(block.header.base_transaction);
response.raw_header = std::move(block.header);
response.raw_transactions.reserve(block.transactions.size());
response.transaction_binary_sizes.reserve(block.transactions.size() + 1);
response.transaction_binary_sizes.push_back(coinbase_size);
for (size_t tx_index = 0; tx_index != block.transactions.size(); ++tx_index) {
response.raw_transactions.push_back(std::move(block.transactions.at(tx_index)));
response.transaction_binary_sizes.push_back(
static_cast<uint32_t>(rb.transactions.at(tx_index).size()));
}
m_block_chain.read_block_output_global_indices(request.hash, &response.global_indices);
// If block not in main chain - global indices will be empty
return true;
}

bool Node::on_get_raw_transaction3(http::Client *, http::RequestData &&, json_rpc::Request &&,
api::bytecoind::GetRawTransaction::Request &&req, api::bytecoind::GetRawTransaction::Response &res) {
const auto &pool = m_block_chain.get_memory_state_transactions();
Expand Down
4 changes: 3 additions & 1 deletion src/Core/Node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ class Node {
bool on_sync_mempool3(http::Client *, http::RequestData &&, json_rpc::Request &&,
api::bytecoind::SyncMemPool::Request &&, api::bytecoind::SyncMemPool::Response &);
bool on_get_raw_transaction3(http::Client *, http::RequestData &&, json_rpc::Request &&,
api::bytecoind::GetRawTransaction::Request &&, api::bytecoind::GetRawTransaction::Response &);
api::bytecoind::GetRawTransaction::Request &&, api::bytecoind::GetRawTransaction::Response &);
bool on_get_raw_block(http::Client *, http::RequestData &&, json_rpc::Request &&,
api::bytecoind::GetRawBlock::Request &&, api::bytecoind::GetRawBlock::Response &);

api::bytecoind::GetStatus::Response create_status_response3() const;
// json_rpc_node
Expand Down
6 changes: 6 additions & 0 deletions src/Core/NodeDownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ void Node::DownloaderV11::on_msg_notify_request_chain(P2PClientBytecoin *who,
if (req.m_block_ids.size() != m_chain.size() + 1) {
m_node->m_log(logging::INFO) << "Downloader truncated chain length=" << m_chain.size() << std::endl;
}
if (req.m_block_ids.empty()){ // Most likely peer is 3.2.0
const auto now = m_node->m_p2p.get_local_time();
m_node->m_log(logging::INFO) << "Downloader truncated chain to zero, delaying connect to " << who->get_address() << std::endl;
m_node->m_peer_db.delay_connection_attempt(who->get_address(), now);
who->disconnect(std::string()); // Will recursively call advance_chain again
}
advance_download();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Core/WalletState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ bool WalletState::sync_with_blockchain(api::bytecoind::SyncBlocks::Response &res
pop_chain();
m_tx_pool_version = 1;
}
if (get_tip_height() + 1 < resp.start_height)
if (get_tip_height() < resp.start_height)
while (!empty_chain()) { // undo everything
pop_chain();
m_tx_pool_version = 1;
Expand Down
15 changes: 9 additions & 6 deletions src/Core/rpc_api_serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,20 +417,23 @@ void ser_members(api::bytecoind::GetStatus::Response &v, ISeria &s) {
seria_kv("next_block_effective_median_size", v.next_block_effective_median_size, s);
seria_kv("top_known_block_height", v.top_known_block_height, s);
}
void ser_members(api::bytecoind::SyncBlocks::Request &v, ISeria &s) {
seria_kv("sparse_chain", v.sparse_chain, s);
seria_kv("first_block_timestamp", v.first_block_timestamp, s);
seria_kv("max_count", v.max_count, s);
// seria_kv("send_signatures", v.send_signatures, s);
void ser_members(bytecoin::api::bytecoind::GetRawBlock::Request &v, ISeria &s) {
seria_kv("hash", v.hash, s);
}
void ser_members(bytecoin::api::bytecoind::SyncBlocks::SyncBlock &v, ISeria &s) {
void ser_members(bytecoin::api::bytecoind::GetRawBlock::Response &v, ISeria &s) {
seria_kv("header", v.header, s);
seria_kv("raw_header", v.raw_header, s);
seria_kv("raw_transactions", v.raw_transactions, s);
seria_kv("base_transaction_hash", v.base_transaction_hash, s);
seria_kv("global_indices", v.global_indices, s);
seria_kv("transaction_binary_sizes", v.transaction_binary_sizes, s);
}
void ser_members(api::bytecoind::SyncBlocks::Request &v, ISeria &s) {
seria_kv("sparse_chain", v.sparse_chain, s);
seria_kv("first_block_timestamp", v.first_block_timestamp, s);
seria_kv("max_count", v.max_count, s);
// seria_kv("send_signatures", v.send_signatures, s);
}
void ser_members(api::bytecoind::SyncBlocks::Response &v, ISeria &s) {
seria_kv("blocks", v.blocks, s);
seria_kv("start_height", v.start_height, s);
Expand Down
1 change: 1 addition & 0 deletions src/main_bytecoind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static const char USAGE[] =
--exclusive-node-address=<ip:port> Specify list (one or more) of nodes to connect to only. All other nodes including seed nodes will be ignored.
--export-blocks=<folder-path> Perform hot export of blockchain into specified folder as blocks.bin and blockindexes.bin, then exit. This overwrites existing files.
--backup-blockchain=<folder-path> Perform hot backup of blockchain into specified backup data folder, then exit.
--net=<main|test> Configure for mainnet or testnet [default: main].
--archive Work as an archive node [default: off].
--data-folder=<folder-path> Folder for blockchain, logs and peer DB [default: )" platform_DEFAULT_DATA_FOLDER_PATH_PREFIX
R"(bytecoin].
Expand Down
1 change: 1 addition & 0 deletions src/main_walletd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static const char USAGE[] =
--bytecoind-remote-address=<ip:port> Connect to remote bytecoind and suppress running built-in bytecoind.
--bytecoind-authorization=<user:pass> HTTP basic authentication credentials for RPC API.
--backup-wallet-data=<folder-path> Perform hot backup of wallet file, history, payment queue and wallet cache into specified backup data folder, then exit.
--net=<main|test> Configure for mainnet or testnet [default: main].
Options for built-in bytecoind (run when no --bytecoind-remote-address specified):
--p2p-bind-address=<ip:port> IP and port for P2P network protocol [default: 0.0.0.0:8080].
Expand Down
32 changes: 19 additions & 13 deletions src/rpc_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,21 @@ struct GetStatus {
typedef walletd::GetStatus::Response Response;
};

// Signature of this method will stabilize to the end of beta
struct GetRawBlock {
static std::string method() { return "get_raw_block"; }
struct Request {
Hash hash;
};
struct Response {
api::BlockHeader header;
BlockTemplate raw_header;
std::vector<TransactionPrefix> raw_transactions;
Hash base_transaction_hash; // BlockTemplate does not contain it
std::vector<std::vector<uint32_t>> global_indices; // for each transaction, not empty only if block in main chain
std::vector<uint32_t> transaction_binary_sizes; // for each transaction
};
};

struct SyncBlocks { // Used by walletd, block explorer, etc to sync to bytecoind
static std::string method() { return "sync_blocks"; }
static std::string bin_method() { return "/sync_blocks_v1.bin"; }
Expand All @@ -429,23 +443,14 @@ struct SyncBlocks { // Used by walletd, block explorer, etc to sync to bytecoin
Timestamp first_block_timestamp = 0;
uint32_t max_count = MAX_COUNT / 10;
};
struct SyncBlock { // Signatures are checked by bytecoind so usually they are of no interest
api::BlockHeader header;
BlockTemplate raw_header;
// the only method returning actual BlockHeader from blockchain, not api::BlockHeader
std::vector<TransactionPrefix> raw_transactions;
// the only method returning actual Transaction from blockchain, not api::Transaction
Hash base_transaction_hash; // BlockTemplate does not contain it
std::vector<std::vector<uint32_t>> global_indices; // for each transaction
std::vector<uint32_t> transaction_binary_sizes; // for each transaction
};
struct Response {
std::vector<SyncBlock> blocks;
std::vector<GetRawBlock::Response> blocks;
Height start_height = 0;
GetStatus::Response status; // We save roundtrip during sync by also sending status here
};
};

// TODO - return json error
struct GetRawTransaction {
static std::string method() { return "get_raw_transaction"; }
struct Request {
Expand Down Expand Up @@ -676,8 +681,9 @@ void ser_members(bytecoin::api::walletd::GetTransaction::Response &v, ISeria &s)

void ser_members(bytecoin::api::bytecoind::GetStatus::Request &v, ISeria &s);
void ser_members(bytecoin::api::bytecoind::GetStatus::Response &v, ISeria &s);
void ser_members(bytecoin::api::bytecoind::GetRawBlock::Request &v, ISeria &s);
void ser_members(bytecoin::api::bytecoind::GetRawBlock::Response &v, ISeria &s);
void ser_members(bytecoin::api::bytecoind::SyncBlocks::Request &v, ISeria &s);
void ser_members(bytecoin::api::bytecoind::SyncBlocks::SyncBlock &v, ISeria &s);
void ser_members(bytecoin::api::bytecoind::SyncBlocks::Response &v, ISeria &s);
void ser_members(bytecoin::api::bytecoind::GetRawTransaction::Request &v, ISeria &s);
void ser_members(bytecoin::api::bytecoind::GetRawTransaction::Response &v, ISeria &s);
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, 13
#define bytecoin_VERSION_STRING "3.2.3"
#define bytecoin_VERSION_WINDOWS_COMMA 3, 18, 8, 17
#define bytecoin_VERSION_STRING "3.2.4"
#ifndef RC_INVOKED // Windows resource compiler

namespace bytecoin {
Expand Down

0 comments on commit 8fb1958

Please sign in to comment.