Skip to content

Commit

Permalink
Bytecoin v.2.0.5 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Juarez committed Jun 1, 2017
1 parent 918aaad commit 2cb6e01
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 79 deletions.
4 changes: 4 additions & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Release notes 2.0.5

- Fixed Bytecoin RPC Wallet hang issue

Release notes 2.0.4

- Fixed an issue where some users experienced daemon hanging
Expand Down
3 changes: 2 additions & 1 deletion src/CryptoNoteConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ const CheckpointData CHECKPOINTS[] = {
{1170000, "f48441157749e89687dfa6edec2128ff332bdaa9eb139f2330a193e3139d2980"},
{1268000, "d49fcaec1d53095e2c244913f123bfd4b26eabb6d75aca7b77a00de8aa8ac680"},
{1272000, "2fb2c50328c8345d2f0a16b3ec4ea680a8a93730358494265ada9edbb9bfa1a6"},
{1273000, "496a9238c654d79c48d269224aa75d61f51831bae6dc744f5e709bec11c7c9f2"}
{1273000, "496a9238c654d79c48d269224aa75d61f51831bae6dc744f5e709bec11c7c9f2"},
{1278000, "de0225cd279ca27cc8d4f8da1b5b92ba0112e48b3777b8c50301846ccfc9146b"}
};
} // CryptoNote

Expand Down
15 changes: 15 additions & 0 deletions src/NodeRpcProxy/NodeRpcProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ std::error_code NodeRpcProxy::doRelayTransaction(const CryptoNote::Transaction&
COMMAND_RPC_SEND_RAW_TX::request req;
COMMAND_RPC_SEND_RAW_TX::response rsp;
req.tx_as_hex = toHex(toBinaryArray(transaction));
m_logger(TRACE) << "NodeRpcProxy::doRelayTransaction, tx hex " << req.tx_as_hex;
return jsonCommand("/sendrawtransaction", req, rsp);
}

Expand Down Expand Up @@ -757,6 +758,7 @@ std::error_code NodeRpcProxy::jsonCommand(const std::string& url, const Request&
std::error_code ec;

try {
m_logger(TRACE) << "Send " << url << " JSON request";
EventLock eventLock(*m_httpEvent);
invokeJsonCommand(*m_httpClient, url, req, res);
ec = interpretResponseStatus(res.status);
Expand All @@ -766,6 +768,12 @@ std::error_code NodeRpcProxy::jsonCommand(const std::string& url, const Request&
ec = make_error_code(error::NETWORK_ERROR);
}

if (ec) {
m_logger(TRACE) << url << " JSON request failed: " << ec << ", " << ec.message();
} else {
m_logger(TRACE) << url << " JSON request compete";
}

return ec;
}

Expand All @@ -774,6 +782,7 @@ std::error_code NodeRpcProxy::jsonRpcCommand(const std::string& method, const Re
std::error_code ec = make_error_code(error::INTERNAL_NODE_ERROR);

try {
m_logger(TRACE) << "Send " << method << " JSON RPC request";
EventLock eventLock(*m_httpEvent);

JsonRpc::JsonRpcRequest jsReq;
Expand Down Expand Up @@ -803,6 +812,12 @@ std::error_code NodeRpcProxy::jsonRpcCommand(const std::string& method, const Re
ec = make_error_code(error::NETWORK_ERROR);
}

if (ec) {
m_logger(TRACE) << method << " JSON RPC request failed: " << ec << ", " << ec.message();
} else {
m_logger(TRACE) << method << " JSON RPC request compete";
}

return ec;
}

Expand Down
40 changes: 29 additions & 11 deletions src/Transfers/BlockchainSynchronizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ void BlockchainSynchronizer::processBlocks(GetBlocksResponse& response) {

CompleteBlock completeBlock;
completeBlock.blockHash = block.blockHash;
interval.blocks.push_back(completeBlock.blockHash);
if (block.hasBlock) {
completeBlock.block = std::move(block.block);
completeBlock.transactions.push_back(createTransactionPrefix(completeBlock.block->baseTransaction));
Expand All @@ -513,6 +512,7 @@ void BlockchainSynchronizer::processBlocks(GetBlocksResponse& response) {
}
}

interval.blocks.push_back(completeBlock.blockHash);
blocks.push_back(std::move(completeBlock));
}

Expand Down Expand Up @@ -546,11 +546,6 @@ void BlockchainSynchronizer::processBlocks(GetBlocksResponse& response) {
std::max(m_node.getKnownBlockCount(), m_node.getLocalBlockCount()));
break;
}

if (!blocks.empty()) {
lastBlockId = blocks.back().blockHash;
m_logger(DEBUGGING) << "Last block hash " << lastBlockId;
}
}

if (checkIfShouldStop()) { //Sic!
Expand All @@ -561,8 +556,12 @@ void BlockchainSynchronizer::processBlocks(GetBlocksResponse& response) {

/// \pre m_consumersMutex is locked
BlockchainSynchronizer::UpdateConsumersResult BlockchainSynchronizer::updateConsumers(const BlockchainInterval& interval, const std::vector<CompleteBlock>& blocks) {
assert(interval.blocks.size() == blocks.size());

bool smthChanged = false;
bool hasErrors = false;

uint32_t lastBlockIndex = std::numeric_limits<uint32_t>::max();
for (auto& kv : m_consumers) {
auto result = kv.second->checkInterval(interval);

Expand All @@ -574,21 +573,40 @@ BlockchainSynchronizer::UpdateConsumersResult BlockchainSynchronizer::updateCons

if (result.hasNewBlocks) {
uint32_t startOffset = result.newBlockHeight - interval.startHeight;
// update consumer
uint32_t blockCount = static_cast<uint32_t>(blocks.size()) - startOffset;
// update consumer
m_logger(DEBUGGING) << "Adding blocks to consumer, consumer " << kv.first << ", start index " << result.newBlockHeight << ", count " << blockCount;
if (kv.first->onNewBlocks(blocks.data() + startOffset, result.newBlockHeight, blockCount)) {
uint32_t addedCount = kv.first->onNewBlocks(blocks.data() + startOffset, result.newBlockHeight, blockCount);
if (addedCount > 0) {
if (addedCount < blockCount) {
m_logger(ERROR, BRIGHT_RED) << "Failed to add " << (blockCount - addedCount) << " blocks of " << blockCount << " to consumer, consumer " << kv.first;
hasErrors = true;
}

// update state if consumer succeeded
kv.second->addBlocks(interval.blocks.data() + startOffset, result.newBlockHeight, static_cast<uint32_t>(interval.blocks.size()) - startOffset);
kv.second->addBlocks(interval.blocks.data() + startOffset, result.newBlockHeight, addedCount);
smthChanged = true;
} else {
m_logger(ERROR, BRIGHT_RED) << "Failed to add blocks to consumer, consumer " << kv.first;
return UpdateConsumersResult::errorOccurred;
hasErrors = true;
}

if (addedCount > 0) {
lastBlockIndex = std::min(lastBlockIndex, startOffset + addedCount - 1);
}
}
}

if (smthChanged) {
if (lastBlockIndex != std::numeric_limits<uint32_t>::max()) {
assert(lastBlockIndex < blocks.size());
lastBlockId = blocks[lastBlockIndex].blockHash;
m_logger(DEBUGGING) << "Last block hash " << lastBlockId << ", index " << (interval.startHeight + lastBlockIndex);
}

if (hasErrors) {
m_logger(DEBUGGING) << "Not all blocks were added to consumers, there were errors";
return UpdateConsumersResult::errorOccurred;
} else if (smthChanged) {
m_logger(DEBUGGING) << "Blocks added to consumers";
return UpdateConsumersResult::addedNewBlocks;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Transfers/IBlockchainSynchronizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class IBlockchainConsumer : public IObservable<IBlockchainConsumerObserver> {
virtual SynchronizationStart getSyncStart() = 0;
virtual const std::unordered_set<Crypto::Hash>& getKnownPoolTxIds() const = 0;
virtual void onBlockchainDetach(uint32_t height) = 0;
virtual bool onNewBlocks(const CompleteBlock* blocks, uint32_t startHeight, uint32_t count) = 0;
virtual uint32_t onNewBlocks(const CompleteBlock* blocks, uint32_t startHeight, uint32_t count) = 0;
virtual std::error_code onPoolUpdated(const std::vector<std::unique_ptr<ITransactionReader>>& addedTransactions, const std::vector<Crypto::Hash>& deletedTransactions) = 0;

virtual std::error_code addUnconfirmedTransaction(const ITransactionReader& transaction) = 0;
Expand Down
63 changes: 44 additions & 19 deletions src/Transfers/TransfersConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,14 @@ void TransfersConsumer::onBlockchainDetach(uint32_t height) {
}
}

bool TransfersConsumer::onNewBlocks(const CompleteBlock* blocks, uint32_t startHeight, uint32_t count) {
uint32_t TransfersConsumer::onNewBlocks(const CompleteBlock* blocks, uint32_t startHeight, uint32_t count) {
assert(blocks);
assert(count > 0);

struct Tx {
TransactionBlockInfo blockInfo;
const ITransactionReader* tx;
bool isLastTransactionInBlock;
};

struct PreprocessedTx : Tx, PreprocessInfo {};
Expand Down Expand Up @@ -243,7 +244,8 @@ bool TransfersConsumer::onNewBlocks(const CompleteBlock* blocks, uint32_t startH
continue;
}

Tx item = { blockInfo, tx.get() };
bool isLastTransactionInBlock = blockInfo.transactionIndex + 1 == blocks[i].transactions.size();
Tx item = { blockInfo, tx.get(), isLastTransactionInBlock };
inputQueue.push(item);
++blockInfo.transactionIndex;
}
Expand Down Expand Up @@ -290,32 +292,55 @@ bool TransfersConsumer::onNewBlocks(const CompleteBlock* blocks, uint32_t startH
}
}

if (processingError) {
forEachSubscription([&](TransfersSubscription& sub) {
sub.onError(processingError, startHeight);
});

return 0;
}

std::vector<Crypto::Hash> blockHashes = getBlockHashes(blocks, count);
if (!processingError) {
m_observerManager.notify(&IBlockchainConsumerObserver::onBlocksAdded, this, blockHashes);
m_observerManager.notify(&IBlockchainConsumerObserver::onBlocksAdded, this, blockHashes);

// sort by block height and transaction index in block
std::sort(preprocessedTransactions.begin(), preprocessedTransactions.end(), [](const PreprocessedTx& a, const PreprocessedTx& b) {
return std::tie(a.blockInfo.height, a.blockInfo.transactionIndex) < std::tie(b.blockInfo.height, b.blockInfo.transactionIndex);
});
// sort by block height and transaction index in block
std::sort(preprocessedTransactions.begin(), preprocessedTransactions.end(), [](const PreprocessedTx& a, const PreprocessedTx& b) {
return std::tie(a.blockInfo.height, a.blockInfo.transactionIndex) < std::tie(b.blockInfo.height, b.blockInfo.transactionIndex);
});

uint32_t processedBlockCount = 0;
try {
for (const auto& tx : preprocessedTransactions) {
processTransaction(tx.blockInfo, *tx.tx, tx);
}
} else {
forEachSubscription([&](TransfersSubscription& sub) {
sub.onError(processingError, startHeight);
});

return false;
if (tx.isLastTransactionInBlock) {
++processedBlockCount;
m_logger(TRACE) << "Processed block " << processedBlockCount << " of " << count << ", last processed block index " << tx.blockInfo.height <<
", hash " << blocks[processedBlockCount - 1].blockHash;

auto newHeight = startHeight + processedBlockCount - 1;
forEachSubscription([newHeight](TransfersSubscription& sub) {
sub.advanceHeight(newHeight);
});
}
}
} catch (std::exception& e) {
m_logger(ERROR, BRIGHT_RED) << "Failed to process block transactions, exception: " << e.what();
} catch (...) {
m_logger(ERROR, BRIGHT_RED) << "Failed to process block transactions, unknown exception";
}

auto newHeight = startHeight + count - 1;
forEachSubscription([newHeight](TransfersSubscription& sub) {
sub.advanceHeight(newHeight);
});
if (processedBlockCount < count) {
uint32_t detachIndex = startHeight + processedBlockCount;
m_logger(ERROR, BRIGHT_RED) << "Not all block transactions are processed, fully processed block count: " << processedBlockCount << " of " << count <<
", last processed block hash " << (processedBlockCount > 0 ? blocks[processedBlockCount - 1].blockHash : NULL_HASH) <<
", detach block index " << detachIndex << " to remove partially processed block";
forEachSubscription([detachIndex](TransfersSubscription& sub) {
sub.onBlockchainDetach(detachIndex);
});
}

return true;
return processedBlockCount;
}

std::error_code TransfersConsumer::onPoolUpdated(const std::vector<std::unique_ptr<ITransactionReader>>& addedTransactions, const std::vector<Hash>& deletedTransactions) {
Expand Down
2 changes: 1 addition & 1 deletion src/Transfers/TransfersConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class TransfersConsumer: public IObservableImpl<IBlockchainConsumerObserver, IBl
// IBlockchainConsumer
virtual SynchronizationStart getSyncStart() override;
virtual void onBlockchainDetach(uint32_t height) override;
virtual bool onNewBlocks(const CompleteBlock* blocks, uint32_t startHeight, uint32_t count) override;
virtual uint32_t onNewBlocks(const CompleteBlock* blocks, uint32_t startHeight, uint32_t count) override;
virtual std::error_code onPoolUpdated(const std::vector<std::unique_ptr<ITransactionReader>>& addedTransactions, const std::vector<Crypto::Hash>& deletedTransactions) override;
virtual const std::unordered_set<Crypto::Hash>& getKnownPoolTxIds() const override;

Expand Down
4 changes: 2 additions & 2 deletions src/version.h.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define BUILD_COMMIT_ID "@VERSION@"
#define PROJECT_VERSION "2.0.4"
#define PROJECT_VERSION_BUILD_NO "1232"
#define PROJECT_VERSION "2.0.5"
#define PROJECT_VERSION_BUILD_NO "1233"
#define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO " (" BUILD_COMMIT_ID ")"
4 changes: 2 additions & 2 deletions tests/TransfersTests/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ class TransactionConsumer : public IBlockchainConsumer {
m_transactions.erase(it, m_transactions.end());
}

virtual bool onNewBlocks(const CompleteBlock* blocks, uint32_t startHeight, uint32_t count) override {
virtual uint32_t onNewBlocks(const CompleteBlock* blocks, uint32_t startHeight, uint32_t count) override {
std::lock_guard<std::mutex> lk(m_mutex);
for(size_t i = 0; i < count; ++i) {
for (const auto& tx : blocks[i].transactions) {
m_transactions[startHeight + i].insert(tx->getTransactionHash());
}
}
m_cv.notify_all();
return true;
return count;
}

bool waitForTransaction(const Hash& txHash) {
Expand Down
Loading

0 comments on commit 2cb6e01

Please sign in to comment.