Skip to content

Commit

Permalink
remove config.genesis config default set (#3174)
Browse files Browse the repository at this point in the history
1. remove config.genesis default value set and check it valid 
2. fix pro&max deploy problem
Signed-off-by: wenlinli <1574249665@qq.com>
  • Loading branch information
wenlinlee authored Nov 28, 2022
1 parent 9c1733c commit f4d724f
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 25 deletions.
90 changes: 72 additions & 18 deletions bcos-tool/bcos-tool/NodeConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ NodeConfig::NodeConfig(KeyFactory::Ptr _keyFactory)
{}

void NodeConfig::loadConfig(
boost::property_tree::ptree const& _pt, bool _enforceMemberID, bool _enforceChainConfig)
boost::property_tree::ptree const& _pt, bool _enforceMemberID, bool _enforceChainConfig, bool _enforceGroupId)
{
// if version < 3.1.0, config.ini include chainConfig
if (_enforceChainConfig ||
if (_enforceChainConfig ||
(m_compatibilityVersion < (uint32_t)bcos::protocol::BlockVersion::V3_1_VERSION &&
m_compatibilityVersion >= (uint32_t)bcos::protocol::BlockVersion::MIN_VERSION))
{
loadChainConfig(_pt);
loadChainConfig(_pt, _enforceGroupId);
}
loadCertConfig(_pt);
loadRpcConfig(_pt);
Expand All @@ -87,7 +87,7 @@ void NodeConfig::loadGenesisConfig(boost::property_tree::ptree const& _genesisCo
m_compatibilityVersion = toVersionNumber(m_compatibilityVersionStr);
if (m_compatibilityVersion >= (uint32_t)bcos::protocol::BlockVersion::V3_1_VERSION)
{
loadChainConfig(_genesisConfig);
loadChainConfig(_genesisConfig, true);
}
loadLedgerConfig(_genesisConfig);
loadExecutorConfig(_genesisConfig);
Expand Down Expand Up @@ -504,11 +504,22 @@ void NodeConfig::loadTxPoolConfig(boost::property_tree::ptree const& _pt)
<< LOG_KV("txsExpirationTime(ms)", m_txsExpirationTime);
}

void NodeConfig::loadChainConfig(boost::property_tree::ptree const& _pt)
void NodeConfig::loadChainConfig(boost::property_tree::ptree const& _pt, bool _enforceGroupId)
{
m_smCryptoType = _pt.get<bool>("chain.sm_crypto", false);
m_groupId = _pt.get<std::string>("chain.group_id", "group0");
m_chainId = _pt.get<std::string>("chain.chain_id", "chain0");
try
{
m_smCryptoType = _pt.get<bool>("chain.sm_crypto");
if (_enforceGroupId)
{
m_groupId = _pt.get<std::string>("chain.group_id");
}
m_chainId = _pt.get<std::string>("chain.chain_id");
}
catch (std::exception const& e)
{
BOOST_THROW_EXCEPTION(InvalidConfig() << errinfo_comment(
"config.genesis chain.sm_crypto/chain.group_id/chain.chain_id is null, please set it!"));
}
if (!isalNumStr(m_chainId))
{
BOOST_THROW_EXCEPTION(
Expand Down Expand Up @@ -685,18 +696,26 @@ void NodeConfig::loadConsensusConfig(boost::property_tree::ptree const& _pt)
void NodeConfig::loadLedgerConfig(boost::property_tree::ptree const& _genesisConfig)
{
// consensus type
m_consensusType = _genesisConfig.get<std::string>("consensus.consensus_type", "pbft");
try
{
m_consensusType = _genesisConfig.get<std::string>("consensus.consensus_type");
}
catch (std::exception const& e)
{
BOOST_THROW_EXCEPTION(InvalidConfig() << errinfo_comment(
"consensus.consensus_type is null, please set it!"));
}
// blockTxCountLimit
auto blockTxCountLimit =
checkAndGetValue(_genesisConfig, "consensus.block_tx_count_limit", "1000");
checkAndGetValue(_genesisConfig, "consensus.block_tx_count_limit");
if (blockTxCountLimit <= 0)
{
BOOST_THROW_EXCEPTION(InvalidConfig() << errinfo_comment(
"Please set consensus.block_tx_count_limit to positive!"));
}
m_ledgerConfig->setBlockTxCountLimit(blockTxCountLimit);
// txGasLimit
auto txGasLimit = checkAndGetValue(_genesisConfig, "tx.gas_limit", "3000000000");
auto txGasLimit = checkAndGetValue(_genesisConfig, "tx.gas_limit");
if (txGasLimit <= TX_GAS_LIMIT_MIN)
{
BOOST_THROW_EXCEPTION(
Expand All @@ -707,7 +726,7 @@ void NodeConfig::loadLedgerConfig(boost::property_tree::ptree const& _genesisCon
m_txGasLimit = txGasLimit;
// the compatibility version
m_compatibilityVersionStr = _genesisConfig.get<std::string>(
"version.compatibility_version", bcos::protocol::RC4_VERSION_STR);
"version.compatibility_version");
// must call here to check the compatibility_version
m_compatibilityVersion = toVersionNumber(m_compatibilityVersionStr);
// sealerList
Expand All @@ -719,7 +738,7 @@ void NodeConfig::loadLedgerConfig(boost::property_tree::ptree const& _genesisCon
m_ledgerConfig->setConsensusNodeList(*consensusNodeList);

// leaderSwitchPeriod
auto consensusLeaderPeriod = checkAndGetValue(_genesisConfig, "consensus.leader_period", "1");
auto consensusLeaderPeriod = checkAndGetValue(_genesisConfig, "consensus.leader_period");
if (consensusLeaderPeriod <= 0)
{
BOOST_THROW_EXCEPTION(
Expand Down Expand Up @@ -834,9 +853,17 @@ void NodeConfig::generateGenesisData()

void NodeConfig::loadExecutorConfig(boost::property_tree::ptree const& _genesisConfig)
{
m_isWasm = _genesisConfig.get<bool>("executor.is_wasm", false);
m_isAuthCheck = _genesisConfig.get<bool>("executor.is_auth_check", false);
m_isSerialExecute = _genesisConfig.get<bool>("executor.is_serial_execute", false);
try
{
m_isWasm = _genesisConfig.get<bool>("executor.is_wasm");
m_isAuthCheck = _genesisConfig.get<bool>("executor.is_auth_check");
m_isSerialExecute = _genesisConfig.get<bool>("executor.is_serial_execute");
}
catch (std::exception const& e)
{
BOOST_THROW_EXCEPTION(InvalidConfig() << errinfo_comment(
"executor.is_wasm/executor.is_auth_check/executor.is_serial_execute is null, please set it!"));
}
if (m_isWasm && !m_isSerialExecute)
{
if (m_compatibilityVersion >= (uint32_t)bcos::protocol::BlockVersion::V3_1_VERSION)
Expand All @@ -861,8 +888,20 @@ void NodeConfig::loadExecutorConfig(boost::property_tree::ptree const& _genesisC
<< LOG_DESC(
"loadExecutorConfig wasm auth is not supported for now");
}
try
{
m_authAdminAddress = _genesisConfig.get<std::string>("executor.auth_admin_account");

m_authAdminAddress = _genesisConfig.get<std::string>("executor.auth_admin_account", "");
}
catch (std::exception const& e)
{
if(m_isAuthCheck)
{
BOOST_THROW_EXCEPTION(InvalidConfig() << errinfo_comment(
"executor.auth_admin_account is null, "
"please set correct auth_admin_account"));
}
}
NodeConfig_LOG(INFO) << METRIC << LOG_DESC("loadExecutorConfig") << LOG_KV("isWasm", m_isWasm)
<< LOG_KV("isAuthCheck", m_isAuthCheck)
<< LOG_KV("authAdminAccount", m_authAdminAddress)
Expand All @@ -886,9 +925,24 @@ int64_t NodeConfig::checkAndGetValue(boost::property_tree::ptree const& _pt,
}
}

int64_t NodeConfig::checkAndGetValue(boost::property_tree::ptree const& _pt, std::string const& _key)
{
try
{
auto value = _pt.get<std::string>(_key);
return boost::lexical_cast<int64_t>(value);
}
catch (std::exception const& e)
{
BOOST_THROW_EXCEPTION(InvalidConfig() << errinfo_comment(
"Invalid value for configuration " + _key +
", please set the value with a valid number"));
}
}

bool NodeConfig::isValidPort(int port)
{
if (port <= 1024 || port > 65535)
return false;
return true;
}
}
11 changes: 6 additions & 5 deletions bcos-tool/bcos-tool/NodeConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ class NodeConfig
virtual ~NodeConfig() = default;

virtual void loadConfig(std::string const& _configPath, bool _enforceMemberID = true,
bool enforceChainConfig = false)
bool enforceChainConfig = false, bool enforceGroupId = true)
{
boost::property_tree::ptree iniConfig;
boost::property_tree::read_ini(_configPath, iniConfig);
loadConfig(iniConfig, _enforceMemberID, enforceChainConfig);
loadConfig(iniConfig, _enforceMemberID, enforceChainConfig, enforceGroupId);
}
virtual void loadServiceConfig(boost::property_tree::ptree const& _pt);
virtual void loadRpcServiceConfig(boost::property_tree::ptree const& _pt);
Expand Down Expand Up @@ -92,7 +92,7 @@ class NodeConfig
}

virtual void loadConfig(boost::property_tree::ptree const& _pt, bool _enforceMemberID = true,
bool _enforceChainConfig = false);
bool _enforceChainConfig = false, bool _enforceGroupId = true);
virtual void loadGenesisConfig(boost::property_tree::ptree const& _genesisConfig);

// the txpool configurations
Expand Down Expand Up @@ -223,7 +223,7 @@ class NodeConfig
const std::string& _clientPrx, std::vector<tars::TC_Endpoint>& _endPoints);

protected:
virtual void loadChainConfig(boost::property_tree::ptree const& _pt);
virtual void loadChainConfig(boost::property_tree::ptree const& _pt, bool _enforceGroupId);
virtual void loadRpcConfig(boost::property_tree::ptree const& _pt);
virtual void loadGatewayConfig(boost::property_tree::ptree const& _pt);
virtual void loadCertConfig(boost::property_tree::ptree const& _pt);
Expand Down Expand Up @@ -372,5 +372,6 @@ class NodeConfig

// others config
int m_sendTxTimeout = -1;
int64_t checkAndGetValue(const boost::property_tree::ptree& _pt, const std::string& _key);
};
} // namespace bcos::tool
} // namespace bcos::tool
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void GatewayInitializer::init(std::string const& _configPath)

GATEWAYSERVICE_LOG(INFO) << LOG_DESC("load nodeConfig");
auto nodeConfig = std::make_shared<bcos::tool::NodeConfig>();
nodeConfig->loadConfig(_configPath, false, true);
nodeConfig->loadConfig(_configPath, false, true, false);

boost::property_tree::ptree pt;
boost::property_tree::read_ini(_configPath, pt);
Expand Down
2 changes: 1 addition & 1 deletion fisco-bcos-tars-service/RpcService/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class RpcServiceApp : public tars::Application
// !!! Notice:
auto nodeConfig = std::make_shared<bcos::tool::NodeConfig>(
std::make_shared<bcos::crypto::KeyFactoryImpl>());
nodeConfig->loadConfig(m_iniConfigPath, false, false);
nodeConfig->loadConfig(m_iniConfigPath, false, true, false);
if (nodeConfig->rpcSmSsl())
{
addConfig("sm_ca.crt");
Expand Down

0 comments on commit f4d724f

Please sign in to comment.