Skip to content

Commit

Permalink
<fix>(config,utilities): fix rpc max version to v2, fix ioservice rem…
Browse files Browse the repository at this point in the history
…ove_timer coredump.
  • Loading branch information
kyonRay committed Jan 17, 2024
1 parent 9913615 commit 63f084f
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 70 deletions.
2 changes: 1 addition & 1 deletion bcos-framework/bcos-framework/protocol/GlobalConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class GlobalConfig
// rpcService && SDK
c_supportedProtocols.insert({ProtocolModuleID::RpcService,
std::make_shared<ProtocolInfo>(
ProtocolModuleID::RpcService, ProtocolVersion::V0, ProtocolVersion::V1)});
ProtocolModuleID::RpcService, ProtocolVersion::V0, ProtocolVersion::V2)});
// executorService
c_supportedProtocols.insert({ProtocolModuleID::ExecutorService,
std::make_shared<ProtocolInfo>(
Expand Down
17 changes: 9 additions & 8 deletions bcos-ledger/src/libledger/LedgerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,10 @@ class LedgerImpl : public bcos::concepts::ledger::LedgerBase<LedgerImpl<Hasher,
}

template <class Type>
requires std::same_as<Type, concepts::ledger::TRANSACTIONS> ||
std::same_as<Type, concepts::ledger::RECEIPTS>
task::Task<void> getBlockData(
std::string_view blockNumberKey, bcos::concepts::block::Block auto& block)
requires std::same_as<Type, concepts::ledger::TRANSACTIONS> ||
std::same_as<Type, concepts::ledger::RECEIPTS>
task::Task<void> getBlockData(
std::string_view blockNumberKey, bcos::concepts::block::Block auto& block)
{
LEDGER_LOG(DEBUG) << "getBlockData transactions or receipts: " << blockNumberKey;

Expand All @@ -462,10 +462,11 @@ class LedgerImpl : public bcos::concepts::ledger::LedgerBase<LedgerImpl<Hasher,
co_return;
}

auto hashesRange = block.transactionsMetaData | RANGES::views::transform([
](typename decltype(block.transactionsMetaData)::value_type const& metaData) -> auto& {
return metaData.hash;
});
auto hashesRange =
block.transactionsMetaData |
RANGES::views::transform(
[](typename decltype(block.transactionsMetaData)::value_type const& metaData)
-> auto& { return metaData.hash; });
auto outputSize = RANGES::size(block.transactionsMetaData);

if constexpr (std::is_same_v<Type, concepts::ledger::TRANSACTIONS>)
Expand Down
5 changes: 2 additions & 3 deletions bcos-utilities/bcos-utilities/IOServicePool.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ class IOServicePool
// one io_context per thread
for (const auto& ioService : m_ioServices)
{
auto weakService = std::weak_ptr<IOService>(ioService);
m_threads.emplace_back([weakService]() {
// https://github.com/chriskohlhoff/asio/issues/932#issuecomment-968103444
m_threads.emplace_back([ioService]() {
bcos::pthread_setThreadName("ioService");
auto ioService = weakService.lock();
ioService->run();
});
}
Expand Down
44 changes: 25 additions & 19 deletions lightnode/fisco-bcos-lightnode/client/LedgerClientImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
#include <boost/throw_exception.hpp>
#include <algorithm>
#include <iterator>
#include <random>
#include <stdexcept>
#include <type_traits>
#include <random>

namespace bcos::ledger
{
struct GetBlockFailed: public bcos::error::Exception {};
struct GetBlockFailed : public bcos::error::Exception
{
};
class LedgerClientImpl : public bcos::concepts::ledger::LedgerBase<LedgerClientImpl>
{
friend bcos::concepts::ledger::LedgerBase<LedgerClientImpl>;
Expand Down Expand Up @@ -76,10 +78,10 @@ class LedgerClientImpl : public bcos::concepts::ledger::LedgerBase<LedgerClientI
}
else
{
std::swap(response.block, block);
LIGHTNODE_LOG(DEBUG) << LOG_DESC("lightNodeGetBlock")
<< LOG_KV("BlockNumber", blockNumber);
co_return;
std::swap(response.block, block);
LIGHTNODE_LOG(DEBUG)
<< LOG_DESC("lightNodeGetBlock") << LOG_KV("BlockNumber", blockNumber);
co_return;
}
}

Expand All @@ -101,7 +103,8 @@ class LedgerClientImpl : public bcos::concepts::ledger::LedgerBase<LedgerClientI

(processGetBlockFlags<Flags>(request.onlyHeader), ...);
// if nodeList is empty, return
if(nodeList.size() == 0){
if (nodeList.size() == 0)
{
response.block = {};
std::swap(response.block, block);
co_return;
Expand All @@ -117,14 +120,15 @@ class LedgerClientImpl : public bcos::concepts::ledger::LedgerBase<LedgerClientI
++nodeIDIt;
}
auto nodeID = *nodeIDIt;
LIGHTNODE_LOG(TRACE) << LOG_DESC("lightNode getBlockByNodeList")
<< LOG_KV("step", step) << LOG_KV("nodeID", nodeID->hex());
co_await p2p().sendMessageByNodeID(bcos::protocol::LIGHTNODE_GET_BLOCK, nodeID, request, response);
if(response.error.errorCode)
LIGHTNODE_LOG(TRACE) << LOG_DESC("lightNode getBlockByNodeList") << LOG_KV("step", step)
<< LOG_KV("nodeID", nodeID->hex());
co_await p2p().sendMessageByNodeID(
bcos::protocol::LIGHTNODE_GET_BLOCK, nodeID, request, response);
if (response.error.errorCode)
{
LIGHTNODE_LOG(WARNING) << "getBlock failed, request nodeID: " << nodeID->hex()
<< "response errorCode: " << response.error.errorCode
<< " " << response.error.errorMessage;
<< "response errorCode: " << response.error.errorCode << " "
<< response.error.errorMessage;
response.block = {};
}
std::swap(response.block, block);
Expand Down Expand Up @@ -228,22 +232,24 @@ class LedgerClientImpl : public bcos::concepts::ledger::LedgerBase<LedgerClientI
std::map<crypto::NodeIDPtr, bcos::protocol::BlockNumber> allPeersStatus;

auto nodeIDs = co_await p2p().getAllNodeID();
LIGHTNODE_LOG(DEBUG) << "Got all peers status from remote, nodeIDs size: " << nodeIDs.size();
for(auto& nodeID : nodeIDs){
LIGHTNODE_LOG(DEBUG) << "Got all peers status from remote, nodeIDs size: "
<< nodeIDs.size();
for (auto& nodeID : nodeIDs)
{
co_await p2p().sendMessageByNodeID(
protocol::LIGHTNODE_GET_STATUS, nodeID, request, response);

if (response.error.errorCode)
{
LIGHTNODE_LOG(WARNING) << "Get status failed, errorCode: " << response.error.errorCode
<< " " << response.error.errorMessage;
LIGHTNODE_LOG(WARNING)
<< "Get status failed, errorCode: " << response.error.errorCode << " "
<< response.error.errorMessage;
BOOST_THROW_EXCEPTION(std::runtime_error(response.error.errorMessage));
}
allPeersStatus[nodeID] = response.blockNumber;

LIGHTNODE_LOG(DEBUG) << "Got status from remote, nodeID: " << nodeID->hex()
<< "blockNumber :"
<< response.blockNumber;
<< "blockNumber :" << response.blockNumber;
}

co_return allPeersStatus;
Expand Down
78 changes: 39 additions & 39 deletions lightnode/fisco-bcos-lightnode/client/P2PClientImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class P2PClientImpl
{
bcos::concepts::serialize::decode(data, m_response);
LIGHTNODE_LOG(DEBUG) << LOG_DESC("P2P client receive message success: ")
<< LOG_KV("data size",data.size());
<< LOG_KV("data size", data.size());
}
else
{
Expand Down Expand Up @@ -208,7 +208,7 @@ class P2PClientImpl
struct Awaitable
{
Awaitable(bcos::gateway::GatewayInterface::Ptr& gateway, std::string& groupID)
: m_gateway(gateway), m_groupID(groupID)
: m_gateway(gateway), m_groupID(groupID)
{}

constexpr bool await_ready() const noexcept { return false; }
Expand All @@ -217,44 +217,44 @@ class P2PClientImpl
bcos::concepts::getRef(m_gateway).asyncGetPeers(
[this, m_handle = handle](Error::Ptr error, const gateway::GatewayInfo::Ptr&,
const gateway::GatewayInfosPtr& peerGatewayInfos) mutable {
if (error)
{
m_error = std::move(error);
}
else
{
if (!peerGatewayInfos->empty())
{
std::set<std::string> nodeIDs;
for (const auto& peerGatewayInfo : *peerGatewayInfos)
{
auto nodeIDInfo = peerGatewayInfo->nodeIDInfo();
auto nodeInfo = nodeIDInfo.find(m_groupID);
if (error)
{
m_error = std::move(error);
}
else
{
if (!peerGatewayInfos->empty())
{
std::set<std::string> nodeIDs;
for (const auto& peerGatewayInfo : *peerGatewayInfos)
{
auto nodeIDInfo = peerGatewayInfo->nodeIDInfo();
auto nodeInfo = nodeIDInfo.find(m_groupID);

if (nodeInfo != nodeIDInfo.end() && !nodeInfo->second.empty())
{
for (auto& it : nodeInfo->second)
{
if (it.second ==
bcos::protocol::NodeType::CONSENSUS_NODE ||
it.second ==
bcos::protocol::NodeType::OBSERVER_NODE)
{
nodeIDs.insert(it.first);
LIGHTNODE_LOG(TRACE)
<< LOG_KV("NodeID:", it.first)
<< LOG_KV("nodeType:", it.second);
}
}
}
}
if (!nodeIDs.empty())
{
m_nodeIDList = std::move(nodeIDs);
}
}
}
m_handle.resume();
if (nodeInfo != nodeIDInfo.end() && !nodeInfo->second.empty())
{
for (auto& it : nodeInfo->second)
{
if (it.second ==
bcos::protocol::NodeType::CONSENSUS_NODE ||
it.second ==
bcos::protocol::NodeType::OBSERVER_NODE)
{
nodeIDs.insert(it.first);
LIGHTNODE_LOG(TRACE)
<< LOG_KV("NodeID:", it.first)
<< LOG_KV("nodeType:", it.second);
}
}
}
}
if (!nodeIDs.empty())
{
m_nodeIDList = std::move(nodeIDs);
}
}
}
m_handle.resume();
});
}
void await_resume()
Expand Down

0 comments on commit 63f084f

Please sign in to comment.