From 63f084f04181ad4d93505ad9604b208b1578260e Mon Sep 17 00:00:00 2001 From: kyonRay Date: Wed, 17 Jan 2024 20:48:28 +0800 Subject: [PATCH] (config,utilities): fix rpc max version to v2, fix ioservice remove_timer coredump. --- .../bcos-framework/protocol/GlobalConfig.h | 2 +- bcos-ledger/src/libledger/LedgerImpl.h | 17 ++-- bcos-utilities/bcos-utilities/IOServicePool.h | 5 +- .../client/LedgerClientImpl.h | 44 ++++++----- .../client/P2PClientImpl.h | 78 +++++++++---------- 5 files changed, 76 insertions(+), 70 deletions(-) diff --git a/bcos-framework/bcos-framework/protocol/GlobalConfig.h b/bcos-framework/bcos-framework/protocol/GlobalConfig.h index c93fb8453d..32b7d46abb 100644 --- a/bcos-framework/bcos-framework/protocol/GlobalConfig.h +++ b/bcos-framework/bcos-framework/protocol/GlobalConfig.h @@ -50,7 +50,7 @@ class GlobalConfig // rpcService && SDK c_supportedProtocols.insert({ProtocolModuleID::RpcService, std::make_shared( - ProtocolModuleID::RpcService, ProtocolVersion::V0, ProtocolVersion::V1)}); + ProtocolModuleID::RpcService, ProtocolVersion::V0, ProtocolVersion::V2)}); // executorService c_supportedProtocols.insert({ProtocolModuleID::ExecutorService, std::make_shared( diff --git a/bcos-ledger/src/libledger/LedgerImpl.h b/bcos-ledger/src/libledger/LedgerImpl.h index edd98ce41b..04d2a3003c 100644 --- a/bcos-ledger/src/libledger/LedgerImpl.h +++ b/bcos-ledger/src/libledger/LedgerImpl.h @@ -449,10 +449,10 @@ class LedgerImpl : public bcos::concepts::ledger::LedgerBase - requires std::same_as || - std::same_as - task::Task getBlockData( - std::string_view blockNumberKey, bcos::concepts::block::Block auto& block) + requires std::same_as || + std::same_as + task::Task getBlockData( + std::string_view blockNumberKey, bcos::concepts::block::Block auto& block) { LEDGER_LOG(DEBUG) << "getBlockData transactions or receipts: " << blockNumberKey; @@ -462,10 +462,11 @@ class LedgerImpl : public bcos::concepts::ledger::LedgerBase 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) diff --git a/bcos-utilities/bcos-utilities/IOServicePool.h b/bcos-utilities/bcos-utilities/IOServicePool.h index 5e2ebdaa3f..7c1a49f7dc 100644 --- a/bcos-utilities/bcos-utilities/IOServicePool.h +++ b/bcos-utilities/bcos-utilities/IOServicePool.h @@ -59,10 +59,9 @@ class IOServicePool // one io_context per thread for (const auto& ioService : m_ioServices) { - auto weakService = std::weak_ptr(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(); }); } diff --git a/lightnode/fisco-bcos-lightnode/client/LedgerClientImpl.h b/lightnode/fisco-bcos-lightnode/client/LedgerClientImpl.h index ab4be4ad75..503c12cad1 100644 --- a/lightnode/fisco-bcos-lightnode/client/LedgerClientImpl.h +++ b/lightnode/fisco-bcos-lightnode/client/LedgerClientImpl.h @@ -14,13 +14,15 @@ #include #include #include +#include #include #include -#include namespace bcos::ledger { -struct GetBlockFailed: public bcos::error::Exception {}; +struct GetBlockFailed : public bcos::error::Exception +{ +}; class LedgerClientImpl : public bcos::concepts::ledger::LedgerBase { friend bcos::concepts::ledger::LedgerBase; @@ -76,10 +78,10 @@ class LedgerClientImpl : public bcos::concepts::ledger::LedgerBase(request.onlyHeader), ...); // if nodeList is empty, return - if(nodeList.size() == 0){ + if (nodeList.size() == 0) + { response.block = {}; std::swap(response.block, block); co_return; @@ -117,14 +120,15 @@ class LedgerClientImpl : public bcos::concepts::ledger::LedgerBasehex()); - 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); @@ -228,22 +232,24 @@ class LedgerClientImpl : public bcos::concepts::ledger::LedgerBase 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; diff --git a/lightnode/fisco-bcos-lightnode/client/P2PClientImpl.h b/lightnode/fisco-bcos-lightnode/client/P2PClientImpl.h index 54a7471142..42a059a149 100644 --- a/lightnode/fisco-bcos-lightnode/client/P2PClientImpl.h +++ b/lightnode/fisco-bcos-lightnode/client/P2PClientImpl.h @@ -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 { @@ -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; } @@ -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 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 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()