Skip to content

Commit

Permalink
Sync code from 3.12.5 (FISCO-BCOS#4820)
Browse files Browse the repository at this point in the history
  • Loading branch information
morebtcg authored Feb 17, 2025
2 parents 7bdfd24 + 2c89fa5 commit e24682c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 34 deletions.
6 changes: 6 additions & 0 deletions bcos-rpc/bcos-rpc/filter/LogMatcher.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <bcos-protocol/TransactionStatus.h>
#include <bcos-rpc/filter/LogMatcher.h>
#include <bcos-utilities/BoostLog.h>
#include <bcos-utilities/DataConvertUtility.h>

using namespace bcos;
using namespace bcos::rpc;
using namespace bcos::protocol;

uint32_t LogMatcher::matches(
FilterRequest::ConstPtr _params, bcos::protocol::Block::ConstPtr _block, Json::Value& _result)
Expand All @@ -24,6 +26,10 @@ uint32_t LogMatcher::matches(FilterRequest::ConstPtr _params, bcos::crypto::Hash
{
uint32_t count = 0;
auto blockNumber = _receipt->blockNumber();
if (_receipt->status() != int32_t(TransactionStatus::None))
{
return 0;
}
auto mutableReceipt = const_cast<bcos::protocol::TransactionReceipt*>(_receipt.get());
auto logEntries = mutableReceipt->takeLogEntries();
for (size_t i = 0; i < logEntries.size(); i++)
Expand Down
22 changes: 14 additions & 8 deletions bcos-rpc/bcos-rpc/web3jsonrpc/endpoints/EthEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,39 +350,45 @@ task::Task<void> EthEndpoint::getCode(const Json::Value& request, Json::Value& r
<< LOG_KV("blockTag", blockTag) << LOG_KV("blockNumber", blockNumber);
}
auto const scheduler = m_nodeService->scheduler();
bcos::bytes code;
struct Awaitable
{
bcos::scheduler::SchedulerInterface::Ptr m_scheduler;
std::string& m_address;
std::variant<Error::Ptr, bcos::bytes> m_result{};
bcos::bytes& m_code;
Error::Ptr m_error = nullptr;
constexpr static bool await_ready() noexcept { return false; }
void await_suspend(std::coroutine_handle<> handle) noexcept
{
m_scheduler->getCode(m_address, [this, handle](auto&& error, auto&& code) {
if (error)
{
m_result.emplace<Error::Ptr>(std::forward<decltype(error)>(error));
m_error = std::move(error);
}
else
{
m_result.emplace<bcos::bytes>(std::forward<decltype(code)>(code));
m_code = std::move(code);
}
handle.resume();
});
}
bcos::bytes await_resume()
void await_resume()
{
if (std::holds_alternative<Error::Ptr>(m_result))
if (m_error)
{
BOOST_THROW_EXCEPTION(*std::get<Error::Ptr>(m_result));
BOOST_THROW_EXCEPTION(*m_error);
}
return std::get<bcos::bytes>(m_result);
}
};
auto const code = co_await Awaitable{
// Note: Awaitable must be declared as a local variable,
// and then co_await the local variable,
// otherwise the object managed by the Awaitable variable will become invalid.
Awaitable awaitable{
.m_scheduler = scheduler,
.m_address = addressStr,
.m_code = code,
};
co_await awaitable;
Json::Value result = toHexStringWithPrefix(code);
buildJsonContent(result, response);
co_return;
Expand Down
79 changes: 53 additions & 26 deletions bcos-scheduler/src/SchedulerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,44 +121,71 @@ void SchedulerManager::reset(std::function<void(Error::Ptr&&)> callback)
void SchedulerManager::getCode(
std::string_view contract, std::function<void(Error::Ptr, bcos::bytes)> callback)
{
auto [ok, message] = checkAndInit();

if (!ok)
try
{
callback(BCOS_ERROR_UNIQUE_PTR(SchedulerError::ExecutorNotEstablishedError, message), {});
return;
}
auto [ok, message] = checkAndInit();

auto _holdSchedulerCallback = [schedulerHolder = m_scheduler, callback = std::move(callback)](
bcos::Error::Ptr&& error, bcos::bytes bytes) {
SCHEDULER_LOG(TRACE) << "Release scheduler holder"
<< LOG_KV("ptr count", schedulerHolder.use_count());
callback(std::move(error), std::move(bytes));
};
if (!ok)
{
callback(
BCOS_ERROR_UNIQUE_PTR(SchedulerError::ExecutorNotEstablishedError, message), {});
return;
}

auto _holdSchedulerCallback = [schedulerHolder = m_scheduler, callback =
std::move(callback)](
bcos::Error::Ptr&& error, bcos::bytes bytes) {
SCHEDULER_LOG(TRACE) << "Release scheduler holder"
<< LOG_KV("ptr count", schedulerHolder.use_count());
callback(std::move(error), std::move(bytes));
};


m_scheduler->getCode(contract, std::move(_holdSchedulerCallback));
m_scheduler->getCode(contract, std::move(_holdSchedulerCallback));
}
catch (std::exception const& e)
{
SCHEDULER_LOG(WARNING) << LOG_DESC("SchedulerManager getCode failed")
<< LOG_KV("codeAddr", contract)
<< LOG_KV("error", boost::diagnostic_information(e));
if (!callback)
{
return;
}
callback(BCOS_ERROR_PTR(-1, boost::diagnostic_information(e)), bcos::bytes());
}
}

void SchedulerManager::getABI(
std::string_view contract, std::function<void(Error::Ptr, std::string)> callback)
{
auto [ok, message] = checkAndInit();

if (!ok)
try
{
callback(BCOS_ERROR_UNIQUE_PTR(SchedulerError::ExecutorNotEstablishedError, message), {});
return;
}
auto [ok, message] = checkAndInit();

auto _holdSchedulerCallback = [schedulerHolder = m_scheduler, callback = std::move(callback)](
bcos::Error::Ptr&& error, std::string str) {
SCHEDULER_LOG(TRACE) << "Release scheduler holder"
<< LOG_KV("ptr count", schedulerHolder.use_count());
callback(std::move(error), std::move(str));
};
if (!ok)
{
callback(
BCOS_ERROR_UNIQUE_PTR(SchedulerError::ExecutorNotEstablishedError, message), {});
return;
}

m_scheduler->getABI(contract, std::move(_holdSchedulerCallback));
auto _holdSchedulerCallback = [schedulerHolder = m_scheduler, callback =
std::move(callback)](
bcos::Error::Ptr&& error, std::string str) {
SCHEDULER_LOG(TRACE) << "Release scheduler holder"
<< LOG_KV("ptr count", schedulerHolder.use_count());
callback(std::move(error), std::move(str));
};

m_scheduler->getABI(contract, std::move(_holdSchedulerCallback));
}
catch (std::exception const& e)
{
SCHEDULER_LOG(WARNING) << LOG_DESC("getABI exception") << LOG_KV("contract", contract)
<< LOG_KV("error", boost::diagnostic_information(e));
callback(BCOS_ERROR_UNIQUE_PTR(-1, boost::diagnostic_information(e)), {});
}
}

void SchedulerManager::preExecuteBlock(
Expand Down

0 comments on commit e24682c

Please sign in to comment.