Skip to content

Commit

Permalink
Merge branch 'release-3.2.4' into release-3.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyShi22 authored Nov 3, 2023
2 parents a71289b + 07038cf commit 04f1c0b
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 67 deletions.
3 changes: 3 additions & 0 deletions bcos-executor/src/precompiled/SystemConfigPrecompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ using namespace bcos::executor;
using namespace bcos::ledger;
using namespace bcos::protocol;

using namespace std::string_view_literals;

const char* const SYSCONFIG_METHOD_SET_STR = "setValueByKey(string,string)";
const char* const SYSCONFIG_METHOD_GET_STR = "getValueByKey(string)";

Expand All @@ -46,6 +48,7 @@ SystemConfigPrecompiled::SystemConfigPrecompiled() : Precompiled(GlobalHashImpl:
getFuncSelector(SYSCONFIG_METHOD_SET_STR, GlobalHashImpl::g_hashImpl);
name2Selector[SYSCONFIG_METHOD_GET_STR] =
getFuncSelector(SYSCONFIG_METHOD_GET_STR, GlobalHashImpl::g_hashImpl);

auto defaultCmp = [](std::string_view _key, int64_t _value, int64_t _minValue) {
if (_value < _minValue)
{
Expand Down
6 changes: 4 additions & 2 deletions bcos-executor/src/precompiled/common/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,11 @@ uint32_t bcos::precompiled::getParamFunc(bytesConstRef _param)
}

uint32_t bcos::precompiled::getFuncSelectorByFunctionName(
std::string const& _functionName, const crypto::Hash::Ptr& _hashImpl)
std::string_view _functionName, const crypto::Hash::Ptr& _hashImpl)
{
uint32_t func = *(uint32_t*)(_hashImpl->hash(_functionName).ref().getCroppedData(0, 4).data());
auto hash = _hashImpl->hash(
bytesConstRef((const unsigned char*)_functionName.data(), _functionName.size()));
uint32_t func = *(uint32_t*)hash.ref().getCroppedData(0, 4).data();
uint32_t selector = ((func & 0x000000FF) << 24) | ((func & 0x0000FF00) << 8) |
((func & 0x00FF0000) >> 8) | ((func & 0xFF000000) >> 24);
return selector;
Expand Down
2 changes: 1 addition & 1 deletion bcos-executor/src/precompiled/common/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ uint32_t getFuncSelector(std::string const& _functionName,
void clearName2SelectCache();
uint32_t getParamFunc(bytesConstRef _param);
uint32_t getFuncSelectorByFunctionName(
std::string const& _functionName, const crypto::Hash::Ptr& _hashImpl);
std::string_view _functionName, const crypto::Hash::Ptr& _hashImpl);

bcos::precompiled::ContractStatus getContractStatus(
std::shared_ptr<bcos::executor::TransactionExecutive> _executive,
Expand Down
24 changes: 18 additions & 6 deletions bcos-framework/bcos-framework/multigroup/ChainNodeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "bcos-framework/protocol/Protocol.h"
#include "bcos-framework/protocol/ProtocolInfo.h"
#include "bcos-framework/protocol/ServiceDesc.h"
#include "bcos-utilities/Ranges.h"
#include <bcos-utilities/Common.h>
#include <memory>
namespace bcos
Expand All @@ -48,7 +49,7 @@ class ChainNodeInfo
m_nodeCryptoType = (NodeCryptoType)_type;
}

virtual ~ChainNodeInfo() {}
virtual ~ChainNodeInfo() = default;

virtual std::string const& nodeName() const { return m_nodeName; }
virtual NodeCryptoType const& nodeCryptoType() const { return m_nodeCryptoType; }
Expand Down Expand Up @@ -94,10 +95,7 @@ class ChainNodeInfo
bcos::protocol::NodeType nodeType() const { return m_nodeType; }

bcos::protocol::ProtocolInfo::ConstPtr nodeProtocol() const { return m_nodeProtocol; }
void setNodeProtocol(bcos::protocol::ProtocolInfo&& _protocol)
{
*m_nodeProtocol = std::move(_protocol);
}
void setNodeProtocol(bcos::protocol::ProtocolInfo&& _protocol) { *m_nodeProtocol = _protocol; }

void setNodeProtocol(bcos::protocol::ProtocolInfo const& _protocol)
{
Expand All @@ -113,7 +111,19 @@ class ChainNodeInfo
void setCompatibilityVersion(uint32_t _version) { m_compatibilityVersion = _version; }
uint32_t compatibilityVersion() const { return m_compatibilityVersion; }

protected:
auto const& featureKeys() const { return m_featureKeys; }
void setFeatureKeys(RANGES::input_range auto&& featureKeys)
requires std::same_as<std::decay_t<RANGES::range_value_t<decltype(featureKeys)>>,
std::string>
{
m_featureKeys.clear();
for (auto&& key : featureKeys)
{
m_featureKeys.emplace_back(std::forward<decltype(key)>(key));
}
}

private:
bool m_microService = false;
// the node name
std::string m_nodeName;
Expand All @@ -132,6 +142,8 @@ class ChainNodeInfo
// the node protocol
bcos::protocol::ProtocolInfo::Ptr m_nodeProtocol;

std::vector<std::string> m_featureKeys;

// the system version
uint32_t m_compatibilityVersion;

Expand Down
41 changes: 25 additions & 16 deletions bcos-framework/bcos-framework/multigroup/GroupInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@
#pragma once
#include "ChainNodeInfoFactory.h"
#include "GroupTypeDef.h"
namespace bcos
{
namespace group
#include <utility>
namespace bcos::group
{
class GroupInfo
{
public:
using Ptr = std::shared_ptr<GroupInfo>;
GroupInfo() = default;
GroupInfo(std::string const& _chainID, std::string const& _groupID)
: m_chainID(_chainID), m_groupID(_groupID)
GroupInfo(std::string _chainID, std::string _groupID)
: m_chainID(std::move(_chainID)), m_groupID(std::move(_groupID))
{}
virtual ~GroupInfo() {}
virtual ~GroupInfo() = default;

virtual std::string const& genesisConfig() const { return m_genesisConfig; }
virtual std::string const& iniConfig() const { return m_iniConfig; }
Expand All @@ -60,7 +59,7 @@ class GroupInfo
{
UpgradableGuard l(x_nodeInfos);
auto const& nodeName = _nodeInfo->nodeName();
if (m_nodeInfos.count(nodeName))
if (m_nodeInfos.contains(nodeName))
{
return false;
}
Expand All @@ -73,7 +72,7 @@ class GroupInfo
{
WriteGuard l(x_nodeInfos);
auto const& nodeName = _nodeInfo->nodeName();
if (m_nodeInfos.count(nodeName))
if (m_nodeInfos.contains(nodeName))
{
*(m_nodeInfos[nodeName]) = *_nodeInfo;
return;
Expand All @@ -84,7 +83,7 @@ class GroupInfo
virtual bool removeNodeInfo(std::string const& _nodeName)
{
UpgradableGuard l(x_nodeInfos);
if (!m_nodeInfos.count(_nodeName))
if (!m_nodeInfos.contains(_nodeName))
{
return false;
}
Expand All @@ -101,8 +100,19 @@ class GroupInfo
return m_nodeInfos.size();
}

// return copied nodeInfos to ensure thread-safe
auto nodeInfos() { return m_nodeInfos; }
auto nodeInfos() const
{
ReadGuard l(x_nodeInfos);
return m_nodeInfos;
}

// Use range with lock
auto nodeInfoList() const
{
return m_nodeInfos |
RANGES::views::transform([lock = std::make_shared<ReadGuard>(x_nodeInfos)](
auto const& pair) -> auto& { return pair; });
}

bcos::group::ChainNodeInfoFactory::Ptr chainNodeInfoFactory() const
{
Expand All @@ -111,15 +121,15 @@ class GroupInfo

void setChainNodeInfoFactory(bcos::group::ChainNodeInfoFactory::Ptr _chainNodeInfoFactory)
{
m_chainNodeInfoFactory = _chainNodeInfoFactory;
m_chainNodeInfoFactory = std::move(_chainNodeInfoFactory);
}

bool wasm() const { return m_wasm; }
bool smCryptoType() const { return m_smCryptoType; }
virtual void setWasm(bool _wasm) { m_wasm = _wasm; }
virtual void setSmCryptoType(bool _smCryptoType) { m_smCryptoType = _smCryptoType; }

protected:
private:
bool m_wasm{false};
bool m_smCryptoType{false};

Expand All @@ -136,7 +146,7 @@ class GroupInfo
mutable SharedMutex x_nodeInfos;
};

inline std::string printGroupInfo(GroupInfo::Ptr _groupInfo)
inline std::string printGroupInfo(const GroupInfo::Ptr& _groupInfo)
{
if (!_groupInfo)
{
Expand All @@ -147,5 +157,4 @@ inline std::string printGroupInfo(GroupInfo::Ptr _groupInfo)
<< LOG_KV("nodeSize", _groupInfo->nodesNum());
return oss.str();
}
} // namespace group
} // namespace bcos
} // namespace bcos::group
2 changes: 1 addition & 1 deletion bcos-rpc/bcos-rpc/Rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void Rpc::notifyGroupInfo(bcos::group::GroupInfo::Ptr _groupInfo)
continue;
}
Json::Value groupInfoJson;
groupInfoToJson(groupInfoJson, _groupInfo);
groupInfoToJson(groupInfoJson, *_groupInfo);
auto response = groupInfoJson.toStyledString();
auto message = m_wsService->messageFactory()->buildMessage();
message->setPacketType(bcos::protocol::MessageType::GROUP_NOTIFY);
Expand Down
16 changes: 8 additions & 8 deletions bcos-rpc/bcos-rpc/groupmgr/GroupManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class GroupManager : public std::enable_shared_from_this<GroupManager>
bcos::protocol::BlockNumber _blockNumber)
{
UpgradableGuard l(x_groupBlockInfos);
if (m_groupBlockInfos.count(_groupID))
if (m_groupBlockInfos.contains(_groupID))
{
// expired block
if (m_groupBlockInfos[_groupID] > _blockNumber)
Expand All @@ -112,23 +112,23 @@ class GroupManager : public std::enable_shared_from_this<GroupManager>
}
// has already in the m_nodesWithLatestBlockNumber
if (m_groupBlockInfos[_groupID] == _blockNumber &&
m_nodesWithLatestBlockNumber.count(_groupID) &&
m_nodesWithLatestBlockNumber[_groupID].count(_nodeName))
m_nodesWithLatestBlockNumber.contains(_groupID) &&
m_nodesWithLatestBlockNumber[_groupID].contains(_nodeName))
{
return;
}
}
UpgradeGuard ul(l);
bcos::protocol::BlockNumber oldBlockNumber = 0;
if (m_groupBlockInfos.count(_groupID))
if (m_groupBlockInfos.contains(_groupID))
{
oldBlockNumber = m_groupBlockInfos[_groupID];
}
if (!m_nodesWithLatestBlockNumber.count(_groupID))
if (!m_nodesWithLatestBlockNumber.contains(_groupID))
{
m_nodesWithLatestBlockNumber[_groupID] = std::set<std::string>();
}
if (!m_groupBlockInfos.count(_groupID))
if (!m_groupBlockInfos.contains(_groupID))
{
m_groupBlockInfos[_groupID] = _blockNumber;
}
Expand Down Expand Up @@ -156,12 +156,12 @@ class GroupManager : public std::enable_shared_from_this<GroupManager>
std::function<void(std::string const&, std::string const&, bcos::protocol::BlockNumber)>
_blockNumberNotifier)
{
m_blockNumberNotifier = _blockNumberNotifier;
m_blockNumberNotifier = std::move(_blockNumberNotifier);
}
virtual bcos::protocol::BlockNumber getBlockNumberByGroup(const std::string& _groupID);

protected:
GroupManager(std::string const& _chainID) : m_chainID(_chainID) {}
GroupManager(std::string _chainID) : m_chainID(std::move(_chainID)) {}

bool updateGroupServices(bcos::group::GroupInfo::Ptr _groupInfo, bool _enforceUpdate);
bool updateNodeService(std::string const& _groupID, bcos::group::ChainNodeInfo::Ptr _nodeInfo,
Expand Down
45 changes: 16 additions & 29 deletions bcos-rpc/bcos-rpc/jsonrpc/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,13 @@

#define RPC_IMPL_LOG(LEVEL) BCOS_LOG(LEVEL) << "[RPC][JSONRPC]"

namespace bcos
namespace bcos::rpc
{
namespace rpc
{
struct NodeInfo
{
std::string version;
std::string supportedVersion;
std::string nodeID;
std::string chainID;
std::string groupID;
std::string agency;
std::string buildTime;
std::string gitCommitHash;
bool isWasm;
bool isSM;
};

class JsonRpcException : public std::exception
{
public:
JsonRpcException(int32_t _code, std::string const& _msg) : m_code(_code), m_msg(_msg) {}
const char* what() const noexcept override { return m_msg.c_str(); }

public:
int32_t code() const noexcept { return m_code; }
std::string msg() const noexcept { return m_msg; }

Expand Down Expand Up @@ -132,18 +114,24 @@ inline void nodeInfoToJson(Json::Value& _response, bcos::group::ChainNodeInfo::P
protocolResponse["minSupportedVersion"] = protocol->minVersion();
protocolResponse["maxSupportedVersion"] = protocol->maxVersion();
protocolResponse["compatibilityVersion"] = _nodeInfo->compatibilityVersion();

auto featureKeys = Json::Value(Json::arrayValue);
for (auto const& key : _nodeInfo->featureKeys())
{
featureKeys.append(key);
}
_response["featureKeys"] = std::move(featureKeys);
_response["protocol"] = protocolResponse;
}

inline void groupInfoToJson(Json::Value& _response, bcos::group::GroupInfo::Ptr _groupInfo)
inline void groupInfoToJson(Json::Value& _response, bcos::group::GroupInfo const& _groupInfo)
{
_response["chainID"] = _groupInfo->chainID();
_response["groupID"] = _groupInfo->groupID();
_response["genesisConfig"] = _groupInfo->genesisConfig();
_response["iniConfig"] = _groupInfo->iniConfig();
_response["chainID"] = _groupInfo.chainID();
_response["groupID"] = _groupInfo.groupID();
_response["genesisConfig"] = _groupInfo.genesisConfig();
_response["iniConfig"] = _groupInfo.iniConfig();
_response["nodeList"] = Json::Value(Json::arrayValue);
auto nodeInfos = _groupInfo->nodeInfos();
for (auto const& it : nodeInfos)
for (auto const& it : _groupInfo.nodeInfoList())
{
Json::Value nodeInfoResponse;
nodeInfoToJson(nodeInfoResponse, it.second);
Expand All @@ -157,9 +145,8 @@ inline void groupInfoListToJson(
for (const auto& groupInfo : _groupInfoList)
{
Json::Value item;
groupInfoToJson(item, groupInfo);
groupInfoToJson(item, *groupInfo);
_response.append(item);
}
}
} // namespace rpc
} // namespace bcos
} // namespace bcos::rpc
2 changes: 1 addition & 1 deletion bcos-rpc/bcos-rpc/jsonrpc/JsonRpcImpl_2_0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ void JsonRpcImpl_2_0::getGroupInfo(std::string_view _groupID, RespFunc _respFunc
if (groupInfo)
{
// can only recover the deleted group
groupInfoToJson(response, groupInfo);
groupInfoToJson(response, *groupInfo);
}
_respFunc(nullptr, response);
}
Expand Down
3 changes: 0 additions & 3 deletions bcos-rpc/bcos-rpc/jsonrpc/JsonRpcImpl_2_0.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ class JsonRpcImpl_2_0 : public JsonRpcInterface,

void getGroupBlockNumber(RespFunc _respFunc) override;

void setNodeInfo(const NodeInfo& _nodeInfo) { m_nodeInfo = _nodeInfo; }
NodeInfo nodeInfo() const { return m_nodeInfo; }
GroupManager::Ptr groupManager() { return m_groupManager; }

int sendTxTimeout() const { return m_sendTxTimeout; }
Expand Down Expand Up @@ -161,7 +159,6 @@ class JsonRpcImpl_2_0 : public JsonRpcInterface,
bcos::gateway::GatewayInterface::Ptr m_gatewayInterface;
std::shared_ptr<boostssl::ws::WsService> m_wsService;

NodeInfo m_nodeInfo;
// Note: here clientID must non-empty for the rpc will set clientID as source for the tx for
// tx-notify and the scheduler will not notify the tx-result if the tx source is empty
std::string m_clientID = "localRpc";
Expand Down
4 changes: 4 additions & 0 deletions libinitializer/PBFTInitializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @date 2021-06-10
*/
#include "PBFTInitializer.h"
#include "bcos-framework/ledger/Features.h"
#include <bcos-framework/election/FailOverTypeDef.h>
#include <bcos-framework/protocol/GlobalConfig.h>
#include <bcos-framework/storage/KVStorageHelper.h>
Expand Down Expand Up @@ -169,6 +170,9 @@ void PBFTInitializer::initChainNodeInfo(
auto nodeProtocolInfo = g_BCOSConfig.protocolInfo(ProtocolModuleID::NodeService);
m_nodeInfo->setNodeProtocol(*nodeProtocolInfo);
m_nodeInfo->setCompatibilityVersion(m_pbft->compatibilityVersion());
m_nodeInfo->setFeatureKeys(
ledger::Features::featureKeys() |
RANGES::views::transform([](std::string_view view) { return std::string(view); }));
m_groupInfo->appendNodeInfo(m_nodeInfo);
INITIALIZER_LOG(INFO) << LOG_DESC("PBFTInitializer::initChainNodeInfo")
<< LOG_KV("nodeType", m_nodeInfo->nodeType())
Expand Down

0 comments on commit 04f1c0b

Please sign in to comment.