Skip to content

Commit

Permalink
Merge with v3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
4egod committed Apr 21, 2018
1 parent 5e89a68 commit 173d65d
Show file tree
Hide file tree
Showing 88 changed files with 1,410 additions and 2,267 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
bin
libs
/.vs
/tests/wallet_file/*.wallet
11 changes: 6 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ set(CMAKE_C_STANDARD 11)
# message(STATUS "Bitsumd profile: According to cmake, sizeof(void *) == " ${CMAKE_SIZEOF_VOID_P})
option(USE_INSTRUMENTATION "For testing - builds with address sanitizer instrument" OFF)
option(WITH_THREAD_SANITIZER "For testing - builds with thread sanitizer instrument, USE_INSTRUMENTATION must be also set" OFF)
option(USE_SSL "Builds with support of https between walletd and bytecoind" OFF)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
option(USE_SQLITE "Builds with SQLite instead of LMDB. 4x slower, but works on 32-bit and mobile platforms" OFF)
option(USE_SSL "Builds with support of https between wallet-rpc and bitsumd" OFF)
set(OPENSSL_ROOT ../openssl)
else()
option(USE_SQLITE "Builds with sqlite instead of LMDB. 4x slower, but works on 32-bit and mobile platforms" ON)
option(USE_SSL "Builds with support of https between wallet-rpc and bitsumd" OFF)
set(OPENSSL_ROOT ../openssl32)
endif()
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
Expand Down Expand Up @@ -47,9 +48,9 @@ else()
set(SRC_DB ../lmdb/libraries/liblmdb/mdb.c ../lmdb/libraries/liblmdb/midl.c src/platform/DBlmdb.cpp src/platform/DBlmdb.hpp)
endif()
if(USE_SSL)
message(STATUS "SSL usage: ON. Make sure openssl headers are in ../openssl/include and static libs are in ../openssl/")
include_directories(../openssl/include)
link_directories(../openssl) # Must be placed before add_executable, add_library.
message(STATUS "SSL usage: ON. Make sure openssl headers are in " ${OPENSSL_ROOT} "/include and static libs are in " ${OPENSSL_ROOT} "/")
include_directories(${OPENSSL_ROOT}/include)
link_directories(${OPENSSL_ROOT}) # Must be placed before add_executable, add_library.
set(LINK_OPENSSL ssl crypto)
add_definitions(-Dplatform_USE_SSL=1)
else()
Expand Down
3 changes: 3 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Release Notes

### v1.18.4.20
- Merge code with bytecoin v3.0.2

### v1.18.4.5
- Merge code with bytecoin v3.0.0

Expand Down
8 changes: 4 additions & 4 deletions src/Core/BlockChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ bool Block::from_raw_block(const RawBlock &raw_block) {
seria::from_binary(bheader, raw_block.block);
transactions.resize(0);
transactions.reserve(raw_block.transactions.size());
for (auto &&rawTransaction : raw_block.transactions) {
for (auto &&raw_transaction : raw_block.transactions) {
Transaction transaction;
seria::from_binary(transaction, rawTransaction);
seria::from_binary(transaction, raw_transaction);
transactions.push_back(std::move(transaction));
}
} catch (...) {
Expand All @@ -61,8 +61,8 @@ bool Block::to_raw_block(RawBlock &raw_block) const {
raw_block.transactions.resize(0);
raw_block.transactions.reserve(transactions.size());
for (auto &&transaction : transactions) {
BinaryArray rawTransaction = seria::to_binary(transaction);
raw_block.transactions.push_back(std::move(rawTransaction));
BinaryArray raw_transaction = seria::to_binary(transaction);
raw_block.transactions.push_back(std::move(raw_transaction));
}
} catch (...) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/BlockChainFileFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ bool LegacyBlockChainReader::import_blocks(BlockChainState &block_chain) {
bool LegacyBlockChainReader::import_blockchain2(const std::string &coin_folder, BlockChainState &block_chain) {
// std::fstream ts_file("/Users/user/bytecoin/timestamps.txt",
// std::ios::out | std::ios::trunc);
// ts_file << "Block timestamp\tBlock medianTimestamp\tBlock
// ts_file << "Block timestamp\tBlock median_timestamp\tBlock
// unlockTimestamp\tTimestamp difference\tMedian timestamp "
// "difference\tMedian - Timestamp"
// << std::endl;
Expand Down
26 changes: 12 additions & 14 deletions src/Core/BlockChainState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,14 @@ std::string BlockChainState::get_standalone_consensus_error(
0, info.base_reward, emission_change) ||
!m_currency.get_block_reward(block.header.major_version, info.effective_size_median, info.block_size,
already_generated_coins, cumulative_fee, info.reward, emission_change)) {
// log(Logging::WARNING) << "Block " << cachedBlock.getBlockHash() <<
// " has too big cumulative size";
// log(Logging::WARNING) << "Block " << hash << " has too big cumulative size";
return "CUMULATIVE_BLOCK_SIZE_TOO_BIG";
}

if (miner_reward != info.reward) {
// log(Logging::WARNING) << "Block reward mismatch for block " <<
// cachedBlock.getBlockHash()
// << ". Expected reward: " << reward << ", got reward: " <<
// minerReward;
// hash << ". Expected reward: " << reward << ", got reward: " <<
// miner_reward;
return "BLOCK_REWARD_MISMATCH";
}
info.already_generated_coins = prev_info.already_generated_coins + emission_change;
Expand Down Expand Up @@ -306,7 +304,7 @@ void BlockChainState::calculate_consensus_values(Height height_delta, uint32_t &
timestamps.push_back(it->timestamp);
next_median_timestamp = common::median_value(timestamps); // sorts timestamps
next_unlock_timestamp = timestamps[timestamps.size() / 2];
// unlike medianValue, here we select lesser of 2 middle values for
// unlike median_value, here we select lesser of 2 middle values for
// even-sized array, so
// that m_next_unlock_timestamp will never decrease with block number
if (next_unlock_timestamp < m_currency.block_future_time_limit)
Expand Down Expand Up @@ -408,7 +406,7 @@ bool BlockChainState::create_mining_block_template(BlockTemplate &b, const Accou
BlockGlobalIndices global_indices;
std::string result =
redo_transaction_get_error(false, tit->second, &memory_state, global_indices, true, single_fee,
fatal); // nextMedianTimestamp
fatal); // next_median_timestamp
if (!result.empty()) {
m_log(logging::ERROR) << "Transaction " << common::pod_to_hex(tit->first)
<< " is in pool, but could not be redone result=" << result << std::endl;
Expand Down Expand Up @@ -463,7 +461,7 @@ bool BlockChainState::create_mining_block_template(BlockTemplate &b, const Accou
m_log(logging::ERROR)
<< logging::BrightRed << "unexpected case: cumulative_size=" << cumulative_size
<< " + 1 is not equal txs_cumulative_size=" << txs_size
<< " + get_object_blobsize(b.baseTransaction)=" << seria::binary_size(b.base_transaction);
<< " + get_object_blobsize(b.base_transaction)=" << seria::binary_size(b.base_transaction);
return false;
}

Expand All @@ -487,7 +485,7 @@ bool BlockChainState::create_mining_block_template(BlockTemplate &b, const Accou
if (cumulative_size != txs_size + seria::binary_size(b.base_transaction)) {
m_log(logging::ERROR) << logging::BrightRed << "unexpected case: cumulative_size=" << cumulative_size
<< " is not equal txs_cumulative_size=" << txs_size
<< " + get_object_blobsize(b.baseTransaction)="
<< " + get_object_blobsize(b.base_transaction)="
<< seria::binary_size(b.base_transaction);
return false;
}
Expand Down Expand Up @@ -541,7 +539,7 @@ void BlockChainState::clear_mining_transactions() const {
++tit;
}

static std::string validateSemantic(bool generating, const Transaction &tx, uint64_t &fee, bool check_output_key) {
static std::string validate_semantic(bool generating, const Transaction &tx, uint64_t &fee, bool check_output_key) {
if (tx.inputs.empty())
return "EMPTY_INPUTS";
uint64_t summary_output_amount = 0;
Expand Down Expand Up @@ -575,7 +573,7 @@ static std::string validateSemantic(bool generating, const Transaction &tx, uint
return "INPUT_IDENTICAL_KEYIMAGES";
if (in.output_indexes.empty())
return "INPUT_EMPTY_OUTPUT_USAGE";
// outputIndexes are packed here, first is absolute, others are offsets to
// output_indexes are packed here, first is absolute, others are offsets to
// previous,
// so first can be zero, others can't
if (std::find(++std::begin(in.output_indexes), std::end(in.output_indexes), 0) !=
Expand Down Expand Up @@ -617,7 +615,7 @@ BroadcastAction BlockChainState::add_transaction(const Hash &tid, const Transact
bool fatal = false;
BlockGlobalIndices global_indices;
std::string result = redo_transaction_get_error(false, tx, &memory_state, global_indices, check_sigs, my_fee,
fatal); // nextMedianTimestamp
fatal); // next_median_timestamp
if (!result.empty()) {
return BroadcastAction::NOTHING; // TODO - ban if fatal
}
Expand Down Expand Up @@ -842,7 +840,7 @@ bool RingCheckerMulticore::signatures_valid() const {
std::string BlockChainState::redo_transaction_get_error(bool generating, const Transaction &transaction,
DeltaState *delta_state, BlockGlobalIndices &global_indices, bool check_sigs, Amount &fee, bool &fatal) const {
const bool check_outputs = check_sigs;
std::string error = validateSemantic(generating, transaction, fee, check_outputs);
std::string error = validate_semantic(generating, transaction, fee, check_outputs);
fatal = false; // for now we do not distinguish between fatal and non-fatal
// errors
if (!error.empty())
Expand Down Expand Up @@ -998,7 +996,7 @@ void BlockChainState::undo_block(const Hash &bhash, const Block &block, Height h
if (m_memory_state_total_complexity < MAX_POOL_COMPLEXITY * 2) {
auto thash = get_transaction_hash(*tit);
// undo is rare, otherwise we'd optimize to use
// block.header.transactionHashes
// block.header.transaction_hashes
add_transaction(thash, *tit, height, get_tip().timestamp + m_currency.block_future_time_limit * 2,
std::numeric_limits<size_t>::max(), false);
// we use increased timestamp so that just unlocked transactions will not
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Config::Config(common::CommandLine &cmd)
"# Uncomment line below and point it to desired blockchain location. Only full path is supported\r\n"
"# You should manually move content of old data folder to new location after completely stopping "
"bitsum\r\n\r\n"
"# D:\\Bitsum\\data\r\n";
"# D:\\bitsum\\data\r\n";
#else
const char content[] =
"# Edit this file to switch data folder\n"
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Config { // Consensus does not depend on those parameters
Height locked_tx_allowed_delta_blocks;

Timestamp mempool_tx_live_time;
// Timestamp mempoolTxFromAltBlockLiveTime;
// size_t numberOfPeriodsToForgetTxDeletedFromPool;
// Timestamp mempool_tx_from_alt_block_live_time;
// size_t number_of_periods_to_forget_tx_deleted_from_pool;

std::string blocks_file_name;
std::string block_indexes_file_name;
Expand Down
58 changes: 26 additions & 32 deletions src/Core/CryptoNoteTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ void decompose_amount_into_digits(
}
}

void bytecoin::decompose_amount(Amount amount, Amount dustThreshold, std::vector<Amount> &decomposedAmounts) {
decompose_amount_into_digits(amount, dustThreshold, [&](Amount amount) { decomposedAmounts.push_back(amount); },
void bytecoin::decompose_amount(Amount amount, Amount dust_threshold, std::vector<Amount> &decomposed_amounts) {
decompose_amount_into_digits(amount, dust_threshold, [&](Amount amount) { decomposed_amounts.push_back(amount); },
[&](Amount dust) {
Amount du0 = dust % 1000;
Amount du1 = dust - du0;
if (du0 != 0)
decomposedAmounts.push_back(du0);
decomposed_amounts.push_back(du0);
if (du1 != 0)
decomposedAmounts.push_back(du1);
decomposed_amounts.push_back(du1);
});
}

size_t bytecoin::get_maximum_tx_size(size_t inputCount, size_t outputCount, size_t mixinCount) {
size_t bytecoin::get_maximum_tx_size(size_t input_count, size_t output_count, size_t mixin_count) {
const size_t KEY_IMAGE_SIZE = sizeof(crypto::KeyImage);
const size_t OUTPUT_KEY_SIZE = sizeof(crypto::PublicKey);
const size_t AMOUNT_SIZE = sizeof(uint64_t) + 2; // varint
Expand All @@ -83,13 +83,13 @@ size_t bytecoin::get_maximum_tx_size(size_t inputCount, size_t outputCount, size
const size_t TRANSACTION_VERSION_SIZE = sizeof(uint8_t);
const size_t TRANSACTION_UNLOCK_TIME_SIZE = sizeof(uint64_t);

const size_t outputsSize = outputCount * (OUTPUT_TAG_SIZE + OUTPUT_KEY_SIZE + AMOUNT_SIZE);
const size_t headerSize =
const size_t outputs_size = output_count * (OUTPUT_TAG_SIZE + OUTPUT_KEY_SIZE + AMOUNT_SIZE);
const size_t header_size =
TRANSACTION_VERSION_SIZE + TRANSACTION_UNLOCK_TIME_SIZE + EXTRA_TAG_SIZE + PUBLIC_KEY_SIZE;
const size_t inputSize = INPUT_TAG_SIZE + AMOUNT_SIZE + KEY_IMAGE_SIZE + SIGNATURE_SIZE +
GLOBAL_INDEXES_VECTOR_SIZE_SIZE + GLOBAL_INDEXES_INITIAL_VALUE_SIZE +
mixinCount * (GLOBAL_INDEXES_DIFFERENCE_SIZE + SIGNATURE_SIZE);
return headerSize + outputsSize + inputSize * inputCount;
const size_t input_size = INPUT_TAG_SIZE + AMOUNT_SIZE + KEY_IMAGE_SIZE + SIGNATURE_SIZE +
GLOBAL_INDEXES_VECTOR_SIZE_SIZE + GLOBAL_INDEXES_INITIAL_VALUE_SIZE +
mixin_count * (GLOBAL_INDEXES_DIFFERENCE_SIZE + SIGNATURE_SIZE);
return header_size + outputs_size + input_size * input_count;
}

bool bytecoin::get_tx_fee(const Transaction &tx, uint64_t &fee) {
Expand Down Expand Up @@ -131,60 +131,54 @@ void seria::ser_members(ParentBlockSerializer &v, ISeria &s) {
s.binary(&v.m_nonce, sizeof(v.m_nonce)); // TODO - fix endianess

if (v.m_hashing_serialization) {
crypto::Hash minerTxHash = get_base_transaction_hash(v.m_parent_block.base_transaction);
crypto::Hash merkleRoot = crypto::tree_hash_from_branch(v.m_parent_block.base_transaction_branch.data(),
v.m_parent_block.base_transaction_branch.size(), minerTxHash, 0);
crypto::Hash miner_tx_hash = get_base_transaction_hash(v.m_parent_block.base_transaction);
crypto::Hash merkle_root = crypto::tree_hash_from_branch(v.m_parent_block.base_transaction_branch.data(),
v.m_parent_block.base_transaction_branch.size(), miner_tx_hash, 0);

seria_kv("merkle_root", merkleRoot, s);
seria_kv("merkle_root", merkle_root, s);
}

uint64_t txNum = static_cast<uint64_t>(v.m_parent_block.transaction_count);
seria_kv("transaction_count", txNum, s);
v.m_parent_block.transaction_count = static_cast<uint16_t>(txNum);
uint64_t tx_num = static_cast<uint64_t>(v.m_parent_block.transaction_count);
seria_kv("transaction_count", tx_num, s);
v.m_parent_block.transaction_count = static_cast<uint16_t>(tx_num);
if (v.m_parent_block.transaction_count < 1)
throw std::runtime_error("Wrong transactions number");

if (v.m_header_only) {
return;
}

size_t branchSize = crypto::tree_depth(v.m_parent_block.transaction_count);
size_t branch_size = crypto::tree_depth(v.m_parent_block.transaction_count);
if (!s.is_input()) {
if (v.m_parent_block.base_transaction_branch.size() != branchSize)
if (v.m_parent_block.base_transaction_branch.size() != branch_size)
throw std::runtime_error("Wrong miner transaction branch size");
} else {
v.m_parent_block.base_transaction_branch.resize(branchSize);
v.m_parent_block.base_transaction_branch.resize(branch_size);
}

// serializer(m_parent_block.baseTransactionBranch, "baseTransactionBranch");
s.object_key("base_transaction_branch");
size_t btb_size = v.m_parent_block.base_transaction_branch.size();
s.begin_array(btb_size, true);
// TODO: Make arrays with computable size! This code won't work with json
// serialization!
for (crypto::Hash &hash : v.m_parent_block.base_transaction_branch) {
s(hash);
}
s.end_array();

seria_kv("miner_tx", v.m_parent_block.base_transaction, s);

TransactionExtraMergeMiningTag mmTag;
if (!get_merge_mining_tag_from_extra(v.m_parent_block.base_transaction.extra, mmTag))
TransactionExtraMergeMiningTag mm_tag;
if (!get_merge_mining_tag_from_extra(v.m_parent_block.base_transaction.extra, mm_tag))
throw std::runtime_error("Can't get extra merge mining tag");
if (mmTag.depth > 8 * sizeof(crypto::Hash))
if (mm_tag.depth > 8 * sizeof(crypto::Hash))
throw std::runtime_error("Wrong merge mining tag depth");

if (!s.is_input()) {
if (mmTag.depth != v.m_parent_block.blockchain_branch.size())
if (mm_tag.depth != v.m_parent_block.blockchain_branch.size())
throw std::runtime_error("Blockchain branch size must be equal to merge mining tag depth");
} else {
v.m_parent_block.blockchain_branch.resize(mmTag.depth);
v.m_parent_block.blockchain_branch.resize(mm_tag.depth);
}

// serializer(m_parent_block.blockchainBranch, "blockchainBranch");
// TODO: Make arrays with computable size! This code won't work with json
// serialization!
s.object_key("blockchain_branch");
btb_size = v.m_parent_block.blockchain_branch.size();
s.begin_array(btb_size, true);
Expand Down
6 changes: 3 additions & 3 deletions src/Core/CryptoNoteTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Hash get_object_hash(const T &object, size_t *size = nullptr) {

Hash get_base_transaction_hash(const BaseTransaction &tx);

void decompose_amount(Amount amount, Amount dustThreshold, std::vector<Amount> &decomposedAmounts);
size_t get_maximum_tx_size(size_t inputCount, size_t outputCount, size_t mixinCount);
void decompose_amount(Amount amount, Amount dust_threshold, std::vector<Amount> &decomposed_amounts);
size_t get_maximum_tx_size(size_t input_count, size_t output_count, size_t mixin_count);

bool get_tx_fee(const Transaction &tx, uint64_t &fee);
uint64_t get_tx_fee(const Transaction &tx);
Expand All @@ -41,7 +41,7 @@ struct ParentBlockSerializer {
bool m_header_only;
};

inline ParentBlockSerializer makeParentBlockSerializer(
inline ParentBlockSerializer make_parent_block_serializer(
const BlockTemplate &b, bool hashing_serialization, bool header_only) {
BlockTemplate &block_ref = const_cast<BlockTemplate &>(b);
return ParentBlockSerializer(
Expand Down
Loading

0 comments on commit 173d65d

Please sign in to comment.