Skip to content

Commit

Permalink
fix: propose gas limit validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrankovi committed Dec 3, 2024
1 parent fed6fc0 commit 51c06a8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 39 deletions.
4 changes: 1 addition & 3 deletions libraries/config/include/config/config_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ Json::Value getConfigData(Json::Value root, const std::vector<std::string> &path
std::string getConfigDataAsString(const Json::Value &root, const std::vector<std::string> &path, bool optional = false,
const std::string &value = {});

uint32_t getConfigDataAsUInt(const Json::Value &root, const std::vector<std::string> &path, bool optional = false,
uint64_t getConfigDataAsUInt(const Json::Value &root, const std::vector<std::string> &path, bool optional = false,
uint32_t value = 0);

uint64_t getConfigDataAsUInt64(const Json::Value &root, const std::vector<std::string> &path);

bool getConfigDataAsBoolean(const Json::Value &root, const std::vector<std::string> &path, bool optional = false,
bool value = false);

Expand Down
26 changes: 5 additions & 21 deletions libraries/config/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ std::vector<logger::Config> FullNodeConfig::loadLoggingConfigs(const Json::Value
output.target = log_path;
output.file_name = (log_path / getConfigDataAsString(o, {"file_name"})).string();
output.format = getConfigDataAsString(o, {"format"});
output.max_size = getConfigDataAsUInt64(o, {"max_size"});
output.rotation_size = getConfigDataAsUInt64(o, {"rotation_size"});
output.max_size = getConfigDataAsUInt(o, {"max_size"});
output.rotation_size = getConfigDataAsUInt(o, {"rotation_size"});
output.time_based_rotation = getConfigDataAsString(o, {"time_based_rotation"});
}
logging.outputs.push_back(output);
Expand Down Expand Up @@ -108,9 +108,9 @@ FullNodeConfig::FullNodeConfig(const Json::Value &string_or_object, const Json::
genesis = GenesisConfig();
}

propose_dag_gas_limit = getConfigDataAsUInt(root, {"propose_dag_gas_limit"}, true, propose_dag_gas_limit);
propose_pbft_gas_limit = getConfigDataAsUInt(root, {"propose_pbft_gas_limit"}, true, propose_pbft_gas_limit);

propose_dag_gas_limit = getConfigDataAsUInt(root, {"propose_dag_gas_limit"}, false, propose_dag_gas_limit);
propose_pbft_gas_limit = getConfigDataAsUInt(root, {"propose_pbft_gas_limit"}, false, propose_pbft_gas_limit);
is_light_node = getConfigDataAsBoolean(root, {"is_light_node"}, true, is_light_node);
const auto min_light_node_history = (genesis.state.dpos.blocks_per_year * kDefaultLightNodeHistoryDays) / 365;
light_node_history = getConfigDataAsUInt(root, {"light_node_history"}, true, min_light_node_history);
Expand Down Expand Up @@ -202,22 +202,6 @@ void FullNodeConfig::validate() const {
throw ConfigException("transactions_pool_size cannot be smaller than " + std::to_string(kMinTransactionPoolSize));
}

if (genesis.pbft.gas_limit < propose_pbft_gas_limit ||
(genesis.state.hardforks.cornus_hf.block_num != uint64_t(-1) &&
genesis.state.hardforks.cornus_hf.pbft_gas_limit < propose_pbft_gas_limit)) {
throw ConfigException("Propose pbft gas limit:" + std::to_string(propose_pbft_gas_limit) +
" greater than max allowed pbft gas limit:" + std::to_string(genesis.pbft.gas_limit) + ":" +
std::to_string(genesis.state.hardforks.cornus_hf.pbft_gas_limit));
}

if (genesis.dag.gas_limit < propose_dag_gas_limit ||
(genesis.state.hardforks.cornus_hf.block_num != uint64_t(-1) &&
genesis.state.hardforks.cornus_hf.dag_gas_limit < propose_dag_gas_limit)) {
throw ConfigException("Propose dag gas limit:" + std::to_string(propose_pbft_gas_limit) +
" greater than max allowed pbft gas limit:" + std::to_string(genesis.pbft.gas_limit) + ":" +
std::to_string(genesis.state.hardforks.cornus_hf.pbft_gas_limit));
}

// TODO: add validation of other config values
}

Expand Down
13 changes: 3 additions & 10 deletions libraries/config/src/config_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <json/reader.h>
#include <json/value.h>
#include <stddef.h>
#include "libdevcore/CommonJS.h"

#include <fstream>

Expand Down Expand Up @@ -44,14 +45,14 @@ std::string getConfigDataAsString(const Json::Value &root, const std::vector<std
}
}

uint32_t getConfigDataAsUInt(const Json::Value &root, const std::vector<std::string> &path, bool optional,
uint64_t getConfigDataAsUInt(const Json::Value &root, const std::vector<std::string> &path, bool optional,
uint32_t value) {
try {
Json::Value ret = getConfigData(root, path, optional);
if (ret.isNull()) {
return value;
} else {
return ret.asUInt();
return dev::getUInt(ret);
}
} catch (Json::Exception &e) {
if (optional) {
Expand All @@ -61,14 +62,6 @@ uint32_t getConfigDataAsUInt(const Json::Value &root, const std::vector<std::str
}
}

uint64_t getConfigDataAsUInt64(const Json::Value &root, const std::vector<std::string> &path) {
try {
return getConfigData(root, path).asUInt64();
} catch (Json::Exception &e) {
throw ConfigException(getConfigErr(path) + e.what());
}
}

bool getConfigDataAsBoolean(const Json::Value &root, const std::vector<std::string> &path, bool optional, bool value) {
try {
Json::Value ret = getConfigData(root, path, optional);
Expand Down
6 changes: 3 additions & 3 deletions libraries/config/src/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ DdosProtectionConfig dec_ddos_protection_config_json(const Json::Value &json) {
ddos_protection.packets_stats_time_period_ms =
std::chrono::milliseconds{getConfigDataAsUInt(json, {"packets_stats_time_period_ms"})};
ddos_protection.peer_max_packets_processing_time_us =
std::chrono::microseconds{getConfigDataAsUInt64(json, {"peer_max_packets_processing_time_us"})};
std::chrono::microseconds{getConfigDataAsUInt(json, {"peer_max_packets_processing_time_us"})};
ddos_protection.peer_max_packets_queue_size_limit =
getConfigDataAsUInt64(json, {"peer_max_packets_queue_size_limit"});
ddos_protection.max_packets_queue_size = getConfigDataAsUInt64(json, {"max_packets_queue_size"});
getConfigDataAsUInt(json, {"peer_max_packets_queue_size_limit"});
ddos_protection.max_packets_queue_size = getConfigDataAsUInt(json, {"max_packets_queue_size"});
return ddos_protection;
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/core_libs/consensus/src/dag/dag_block_proposer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ DagBlockProposer::DagBlockProposer(const FullNodeConfig& config, std::shared_ptr
node_sk_(config.node_secret),
vrf_sk_(config.vrf_secret),
vrf_pk_(vrf_wrapper::getVrfPublicKey(vrf_sk_)),
kPbftGasLimit(config.propose_pbft_gas_limit),
kDagGasLimit(config.propose_dag_gas_limit),
kPbftGasLimit(std::min(config.propose_pbft_gas_limit, config.genesis.getGasLimits(final_chain_->lastBlockNumber()).second)),
kDagGasLimit(std::min(config.propose_dag_gas_limit, config.genesis.getGasLimits(final_chain_->lastBlockNumber()).first)),
kHardforks(config.genesis.state.hardforks),
kValidatorMaxVote(config.genesis.state.dpos.validator_maximum_stake /
config.genesis.state.dpos.vote_eligibility_balance_step) {
Expand Down

0 comments on commit 51c06a8

Please sign in to comment.