Skip to content

Commit

Permalink
catch exception in fetch txFailed
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyShi22 committed Apr 8, 2024
1 parent 05f1503 commit c7b8910
Showing 1 changed file with 52 additions and 40 deletions.
92 changes: 52 additions & 40 deletions bcos-scheduler/src/SchedulerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,52 +401,64 @@ void SchedulerImpl::executeBlockInternal(bcos::protocol::Block::Ptr block, bool
SCHEDULER_LOG(INFO) << BLOCK_NUMBER(requestBlockNumber) << LOG_BADGE("BlockTrace")
<< "ExecuteBlock start" << LOG_KV("time(ms)", utcTime() - start);
auto startTime = utcTime();
blockExecutive->asyncExecute(
[this, startTime, requestBlockNumber, callback = std::move(callback), executeLock](
Error::UniquePtr error, protocol::BlockHeader::Ptr header, bool _sysBlock) {
if (!m_isRunning)
{
executeLock->unlock();
callback(
BCOS_ERROR_UNIQUE_PTR(SchedulerError::Stopped, "Scheduler is not running"),
nullptr, false);
return;
}
try
{
blockExecutive->asyncExecute(
[this, startTime, requestBlockNumber, callback = std::move(callback), executeLock](
Error::UniquePtr error, protocol::BlockHeader::Ptr header, bool _sysBlock) {
if (!m_isRunning)
{
executeLock->unlock();
callback(BCOS_ERROR_UNIQUE_PTR(
SchedulerError::Stopped, "Scheduler is not running"),
nullptr, false);
return;
}

if (error)
{
SCHEDULER_LOG(ERROR) << BLOCK_NUMBER(requestBlockNumber)
<< "executeBlock error: " << error->what();
if (error)
{
std::unique_lock<std::mutex> blocksLock(m_blocksMutex);
if (!m_blocks->empty() && m_blocks->back()->number() == requestBlockNumber)
SCHEDULER_LOG(ERROR) << BLOCK_NUMBER(requestBlockNumber)
<< "executeBlock error: " << error->what();
{
m_blocks->pop_back();
std::unique_lock<std::mutex> blocksLock(m_blocksMutex);
if (!m_blocks->empty() &&
m_blocks->back()->number() == requestBlockNumber)
{
m_blocks->pop_back();
}
blocksLock.unlock();
}
blocksLock.unlock();
executeLock->unlock();
callback(BCOS_ERROR_WITH_PREV_PTR(
SchedulerError::UnknownError, "executeBlock error:", *error),
nullptr, _sysBlock);
return;
}
auto signature = header->signatureList();
SCHEDULER_LOG(INFO)
<< BLOCK_NUMBER(header->number()) << LOG_BADGE("BlockTrace")
<< "ExecuteBlock success" << LOG_KV("hash", header->hash().abridged())
<< LOG_KV("stateRoot", header->stateRoot().hex())
<< LOG_KV("receiptRoot", header->receiptsRoot().hex())
<< LOG_KV("txsRoot", header->txsRoot().abridged())
<< LOG_KV("gasUsed", header->gasUsed())
<< LOG_KV("signatureSize", signature.size())
<< LOG_KV("timeCost", utcTime() - startTime)
<< LOG_KV("blockVersion", header->version());

m_lastExecuteFinishTime = utcTime();
executeLock->unlock();
callback(BCOS_ERROR_WITH_PREV_PTR(
SchedulerError::UnknownError, "executeBlock error:", *error),
nullptr, _sysBlock);
return;
}
auto signature = header->signatureList();
SCHEDULER_LOG(INFO)
<< BLOCK_NUMBER(header->number()) << LOG_BADGE("BlockTrace")
<< "ExecuteBlock success" << LOG_KV("hash", header->hash().abridged())
<< LOG_KV("stateRoot", header->stateRoot().hex())
<< LOG_KV("receiptRoot", header->receiptsRoot().hex())
<< LOG_KV("txsRoot", header->txsRoot().abridged())
<< LOG_KV("gasUsed", header->gasUsed())
<< LOG_KV("signatureSize", signature.size())
<< LOG_KV("timeCost", utcTime() - startTime)
<< LOG_KV("blockVersion", header->version());

m_lastExecuteFinishTime = utcTime();
executeLock->unlock();
callback(std::move(error), std::move(header), _sysBlock);
});
callback(std::move(error), std::move(header), _sysBlock);
});
}
catch (std::exception const& e)
{
executeLock->unlock();
SCHEDULER_LOG(ERROR) << BLOCK_NUMBER(requestBlockNumber)
<< "whenQueueBack asyncExecute exception"
<< boost::diagnostic_information(e);
throw e;
}
};

// run all handler
Expand Down

0 comments on commit c7b8910

Please sign in to comment.