Skip to content

Commit

Permalink
Bytecoin v.2.0.6 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Juarez committed Jun 8, 2017
1 parent 2cb6e01 commit 1d48dc2
Show file tree
Hide file tree
Showing 18 changed files with 266 additions and 91 deletions.
6 changes: 6 additions & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Release notes 2.0.6

- Wallet synchronization enhancements
- Correct application closing
- Daemon stability enhancements

Release notes 2.0.5

- Fixed Bytecoin RPC Wallet hang issue
Expand Down
3 changes: 2 additions & 1 deletion src/CryptoNoteConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ const CheckpointData CHECKPOINTS[] = {
{1268000, "d49fcaec1d53095e2c244913f123bfd4b26eabb6d75aca7b77a00de8aa8ac680"},
{1272000, "2fb2c50328c8345d2f0a16b3ec4ea680a8a93730358494265ada9edbb9bfa1a6"},
{1273000, "496a9238c654d79c48d269224aa75d61f51831bae6dc744f5e709bec11c7c9f2"},
{1278000, "de0225cd279ca27cc8d4f8da1b5b92ba0112e48b3777b8c50301846ccfc9146b"}
{1278000, "de0225cd279ca27cc8d4f8da1b5b92ba0112e48b3777b8c50301846ccfc9146b"},
{1283000, "826043db95e9801f038f254d223ce0d0912da269dcce1461b5f0f05ddfae9e1c"}
};
} // CryptoNote

Expand Down
12 changes: 12 additions & 0 deletions src/Platform/Linux/System/Dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Dispatcher::Dispatcher() {
mainContext.group = &contextGroup;
mainContext.groupPrev = nullptr;
mainContext.groupNext = nullptr;
mainContext.inExecutionQueue = false;
contextGroup.firstContext = nullptr;
contextGroup.lastContext = nullptr;
contextGroup.firstWaiter = nullptr;
Expand Down Expand Up @@ -169,6 +170,10 @@ void Dispatcher::dispatch() {
if (firstResumingContext != nullptr) {
context = firstResumingContext;
firstResumingContext = context->next;

assert(context->inExecutionQueue);
context->inExecutionQueue = false;

break;
}

Expand Down Expand Up @@ -251,7 +256,13 @@ bool Dispatcher::interrupted() {

void Dispatcher::pushContext(NativeContext* context) {
assert(context != nullptr);

if (context->inExecutionQueue)
return;

context->next = nullptr;
context->inExecutionQueue = true;

if(firstResumingContext != nullptr) {
assert(lastResumingContext != nullptr);
lastResumingContext->next = context;
Expand Down Expand Up @@ -414,6 +425,7 @@ void Dispatcher::contextProcedure(void* ucontext) {
context.ucontext = ucontext;
context.interrupted = false;
context.next = nullptr;
context.inExecutionQueue = false;
firstReusableContext = &context;
ucontext_t* oldContext = static_cast<ucontext_t*>(context.ucontext);
if (swapcontext(oldContext, static_cast<ucontext_t*>(currentContext->ucontext)) == -1) {
Expand Down
1 change: 1 addition & 0 deletions src/Platform/Linux/System/Dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct NativeContext {
void* ucontext;
void* stackPtr;
bool interrupted;
bool inExecutionQueue;
NativeContext* next;
NativeContextGroup* group;
NativeContext* groupPrev;
Expand Down
11 changes: 11 additions & 0 deletions src/Platform/OSX/System/Dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Dispatcher::Dispatcher() : lastCreatedTimer(0) {
mainContext.group = &contextGroup;
mainContext.groupPrev = nullptr;
mainContext.groupNext = nullptr;
mainContext.inExecutionQueue = false;
contextGroup.firstContext = nullptr;
contextGroup.lastContext = nullptr;
contextGroup.firstWaiter = nullptr;
Expand Down Expand Up @@ -145,6 +146,10 @@ void Dispatcher::dispatch() {
if (firstResumingContext != nullptr) {
context = firstResumingContext;
firstResumingContext = context->next;

assert(context->inExecutionQueue);
context->inExecutionQueue = false;

break;
}

Expand Down Expand Up @@ -237,7 +242,12 @@ bool Dispatcher::interrupted() {

void Dispatcher::pushContext(NativeContext* context) {
assert(context!=nullptr);

if (context->inExecutionQueue)
return;

context->next = nullptr;
context->inExecutionQueue = true;
if (firstResumingContext != nullptr) {
assert(lastResumingContext != nullptr);
lastResumingContext->next = context;
Expand Down Expand Up @@ -388,6 +398,7 @@ void Dispatcher::contextProcedure(void* ucontext) {
context.uctx = ucontext;
context.interrupted = false;
context.next = nullptr;
context.inExecutionQueue = false;
firstReusableContext = &context;
uctx* oldContext = static_cast<uctx*>(context.uctx);
if (swapcontext(oldContext, static_cast<uctx*>(currentContext->uctx)) == -1) {
Expand Down
1 change: 1 addition & 0 deletions src/Platform/OSX/System/Dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct NativeContext {
void* uctx;
void* stackPtr;
bool interrupted;
bool inExecutionQueue;
NativeContext* next;
NativeContextGroup* group;
NativeContext* groupPrev;
Expand Down
21 changes: 21 additions & 0 deletions src/Platform/Windows/System/Dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Dispatcher::Dispatcher() {
mainContext.group = &contextGroup;
mainContext.groupPrev = nullptr;
mainContext.groupNext = nullptr;
mainContext.inExecutionQueue = false;
contextGroup.firstContext = nullptr;
contextGroup.lastContext = nullptr;
contextGroup.firstWaiter = nullptr;
Expand Down Expand Up @@ -131,6 +132,10 @@ void Dispatcher::dispatch() {
if (firstResumingContext != nullptr) {
context = firstResumingContext;
firstResumingContext = context->next;

assert(context->inExecutionQueue);
context->inExecutionQueue = false;

break;
}

Expand All @@ -149,6 +154,10 @@ void Dispatcher::dispatch() {
if (firstResumingContext != nullptr) {
context = firstResumingContext;
firstResumingContext = context->next;

assert(context->inExecutionQueue);
context->inExecutionQueue = false;

break;
}

Expand Down Expand Up @@ -224,7 +233,13 @@ bool Dispatcher::interrupted() {
void Dispatcher::pushContext(NativeContext* context) {
assert(GetCurrentThreadId() == threadId);
assert(context != nullptr);

if (context->inExecutionQueue) {
return;
}

context->next = nullptr;
context->inExecutionQueue = true;
if (firstResumingContext != nullptr) {
assert(lastResumingContext->next == nullptr);
lastResumingContext->next = context;
Expand Down Expand Up @@ -359,6 +374,11 @@ void Dispatcher::pushReusableContext(NativeContext& context) {

void Dispatcher::interruptTimer(uint64_t time, NativeContext* context) {
assert(GetCurrentThreadId() == threadId);

if (context->inExecutionQueue) {
return;
}

auto range = timers.equal_range(time);
for (auto it = range.first; ; ++it) {
assert(it != range.second);
Expand All @@ -376,6 +396,7 @@ void Dispatcher::contextProcedure() {
NativeContext context;
context.interrupted = false;
context.next = nullptr;
context.inExecutionQueue = false;
firstReusableContext = &context;
SwitchToFiber(currentContext->fiber);
for (;;) {
Expand Down
1 change: 1 addition & 0 deletions src/Platform/Windows/System/Dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct NativeContextGroup;
struct NativeContext {
void* fiber;
bool interrupted;
bool inExecutionQueue;
NativeContext* next;
NativeContextGroup* group;
NativeContext* groupPrev;
Expand Down
8 changes: 8 additions & 0 deletions src/Platform/Windows/System/TcpConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ size_t TcpConnection::read(uint8_t* data, size_t size) {
throw InterruptedException();
}

if (context.interrupted) {
throw InterruptedException();
}

assert(transferred <= size);
assert(flags == 0);
return transferred;
Expand Down Expand Up @@ -209,6 +213,10 @@ size_t TcpConnection::write(const uint8_t* data, size_t size) {
throw InterruptedException();
}

if (context.interrupted) {
throw InterruptedException();
}

assert(transferred == size);
assert(flags == 0);
return transferred;
Expand Down
8 changes: 8 additions & 0 deletions src/Platform/Windows/System/TcpConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ TcpConnection TcpConnector::connect(const Ipv4Address& address, uint16_t port) {
}
}
} else {
if (context2.interrupted) {
if (closesocket(connection) != 0) {
throw std::runtime_error("TcpConnector::connect, closesocket failed, " + errorMessage(WSAGetLastError()));
} else {
throw InterruptedException();
}
}

assert(transferred == 0);
assert(flags == 0);
DWORD value = 1;
Expand Down
9 changes: 9 additions & 0 deletions src/Platform/Windows/System/TcpListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ TcpConnection TcpListener::accept() {
}
}
} else {
if (context2.interrupted) {
if (closesocket(connection) != 0) {
throw std::runtime_error("TcpConnector::connect, closesocket failed, " + errorMessage(WSAGetLastError()));
}
else {
throw InterruptedException();
}
}

assert(transferred == 0);
assert(flags == 0);
if (setsockopt(connection, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, reinterpret_cast<char*>(&listener), sizeof listener) != 0) {
Expand Down
4 changes: 4 additions & 0 deletions src/System/ContextGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ void ContextGroup::wait() {
if (contextGroup.firstContext != nullptr) {
NativeContext* context = dispatcher->getCurrentContext();
context->next = nullptr;

assert(!context->inExecutionQueue);
context->inExecutionQueue = true;

if (contextGroup.firstWaiter != nullptr) {
assert(contextGroup.lastWaiter->next == nullptr);
contextGroup.lastWaiter->next = context;
Expand Down
37 changes: 33 additions & 4 deletions src/Transfers/TransfersConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ namespace {

using namespace CryptoNote;

class MarkTransactionConfirmedException : public std::exception {
public:
MarkTransactionConfirmedException(const Crypto::Hash& txHash) {
}

const Hash& getTxHash() const {
return m_txHash;
}

private:
Crypto::Hash m_txHash;
};

void checkOutputKey(
const KeyDerivation& derivation,
const PublicKey& key,
Expand Down Expand Up @@ -218,17 +231,20 @@ uint32_t TransfersConsumer::onNewBlocks(const CompleteBlock* blocks, uint32_t st
BlockingQueue<Tx> inputQueue(workers * 2);

std::atomic<bool> stopProcessing(false);
std::atomic<size_t> emptyBlockCount(0);

auto pushingThread = std::async(std::launch::async, [&] {
for( uint32_t i = 0; i < count && !stopProcessing; ++i) {
const auto& block = blocks[i].block;

if (!block.is_initialized()) {
++emptyBlockCount;
continue;
}

// filter by syncStartTimestamp
if (m_syncStart.timestamp && block->timestamp < m_syncStart.timestamp) {
++emptyBlockCount;
continue;
}

Expand Down Expand Up @@ -308,7 +324,7 @@ uint32_t TransfersConsumer::onNewBlocks(const CompleteBlock* blocks, uint32_t st
return std::tie(a.blockInfo.height, a.blockInfo.transactionIndex) < std::tie(b.blockInfo.height, b.blockInfo.transactionIndex);
});

uint32_t processedBlockCount = 0;
uint32_t processedBlockCount = emptyBlockCount;
try {
for (const auto& tx : preprocessedTransactions) {
processTransaction(tx.blockInfo, *tx.tx, tx);
Expand All @@ -324,6 +340,14 @@ uint32_t TransfersConsumer::onNewBlocks(const CompleteBlock* blocks, uint32_t st
});
}
}
} catch (const MarkTransactionConfirmedException& e) {
m_logger(ERROR, BRIGHT_RED) << "Failed to process block transactions: failed to confirm transaction " << e.getTxHash() <<
", remove this transaction from all containers and transaction pool";
forEachSubscription([&e](TransfersSubscription& sub) {
sub.deleteUnconfirmedTransaction(e.getTxHash());
});

m_poolTxs.erase(e.getTxHash());
} catch (std::exception& e) {
m_logger(ERROR, BRIGHT_RED) << "Failed to process block transactions, exception: " << e.what();
} catch (...) {
Expand Down Expand Up @@ -539,9 +563,14 @@ void TransfersConsumer::processOutputs(const TransactionBlockInfo& blockInfo, Tr

if (contains) {
if (subscribtionTxInfo.blockHeight == WALLET_UNCONFIRMED_TRANSACTION_HEIGHT && blockInfo.height != WALLET_UNCONFIRMED_TRANSACTION_HEIGHT) {
// pool->blockchain
sub.markTransactionConfirmed(blockInfo, tx.getTransactionHash(), globalIdxs);
updated = true;
try {
// pool->blockchain
sub.markTransactionConfirmed(blockInfo, tx.getTransactionHash(), globalIdxs);
updated = true;
} catch (...) {
m_logger(ERROR, BRIGHT_RED) << "markTransactionConfirmed failed, throw MarkTransactionConfirmedException";
throw MarkTransactionConfirmedException(tx.getTransactionHash());
}
} else {
assert(subscribtionTxInfo.blockHeight == blockInfo.height);
}
Expand Down
Loading

0 comments on commit 1d48dc2

Please sign in to comment.