Skip to content

Commit

Permalink
chore: increase gas limit
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrankovi committed Dec 2, 2024
1 parent 9cbf49a commit 2bc913f
Show file tree
Hide file tree
Showing 21 changed files with 102 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@
},
"cornus_hf": {
"block_num": 100,
"delegation_locking_period": 5
"delegation_locking_period": 5,
"dag_gas_limit": "0x1908B100",
"pbft_gas_limit": "0x7d2b7500"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@
},
"cornus_hf": {
"block_num": 0,
"delegation_locking_period": 5
"delegation_locking_period": 5,
"dag_gas_limit": "0x1908B100",
"pbft_gas_limit": "0x7d2b7500"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,9 @@
},
"cornus_hf": {
"block_num": -1,
"delegation_locking_period": 163459
"delegation_locking_period": 163459,
"dag_gas_limit": "0x1908B100",
"pbft_gas_limit": "0x7d2b7500"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@
"dag_blocks_size": "0x32",
"ghost_path_move_back": "0x0",
"lambda_ms": "0x5DC",
"gas_limit": "0x7d2b7500"
"gas_limit": "0x12C684C0"
},
"dag": {
"block_proposer": {
"shard": 1
},
"gas_limit": "0x1908B100"
"gas_limit": "0x1E0A6E0"
},
"sortition": {
"changes_count_for_average": 10,
Expand Down Expand Up @@ -156,7 +156,9 @@
},
"cornus_hf": {
"block_num": -1,
"delegation_locking_period": 5
"delegation_locking_period": 5,
"dag_gas_limit": "0x1908B100",
"pbft_gas_limit": "0x7d2b7500"
}
}
}
2 changes: 2 additions & 0 deletions libraries/config/include/config/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ struct FullNodeConfig {
bool enable_test_rpc = false;
bool enable_debug = false;
uint32_t final_chain_cache_in_blocks = 5;
uint64_t propose_dag_gas_limit = 0x1E0A6E0;
uint64_t propose_pbft_gas_limit = 0x12C684C0;

// config values that limits transactions pool
uint32_t transactions_pool_size = kDefaultTransactionPoolSize;
Expand Down
1 change: 1 addition & 0 deletions libraries/config/include/config/genesis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct GenesisConfig {
bytes rlp() const;
blk_hash_t genesisHash() const;
void updateBlocksPerYear();
std::pair<uint64_t, uint64_t> getGasLimits(uint64_t block_number) const;
};

Json::Value enc_json(GenesisConfig const& obj);
Expand Down
23 changes: 13 additions & 10 deletions libraries/config/include/config/hardfork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ struct FicusHardforkConfig {
Json::Value enc_json(const FicusHardforkConfig& obj);
void dec_json(const Json::Value& json, FicusHardforkConfig& obj);

struct CornusHardforkConfig {
uint64_t block_num = -1;
uint32_t delegation_locking_period = 5; // number of blocks
uint64_t dag_gas_limit = 0;
uint64_t pbft_gas_limit = 0;

HAS_RLP_FIELDS
};
Json::Value enc_json(const CornusHardforkConfig& obj);
void dec_json(const Json::Value& json, CornusHardforkConfig& obj);

// Keeping it for next HF
// struct BambooRedelegation {
// taraxa::addr_t validator;
Expand All @@ -90,15 +101,6 @@ void dec_json(const Json::Value& json, FicusHardforkConfig& obj);
// Json::Value enc_json(const BambooHardfork& obj);
// void dec_json(const Json::Value& json, BambooHardfork& obj);

struct CornusHardforkConfig {
uint64_t block_num = -1;
uint32_t delegation_locking_period = 5; // number of blocks

HAS_RLP_FIELDS
};
Json::Value enc_json(const CornusHardforkConfig& obj);
void dec_json(const Json::Value& json, CornusHardforkConfig& obj);

struct HardforksConfig {
// disable it by default (set to max uint64)
uint64_t fix_redelegate_block_num = -1;
Expand Down Expand Up @@ -141,9 +143,10 @@ struct HardforksConfig {

// Cornus hf - support multiple undelegations from the same validator at the same time
// - change of delegation locking period
// - change gas limit
CornusHardforkConfig cornus_hf;

bool isCornusHardfork(uint64_t block_number) const { return block_number >= cornus_hf.block_num; }
bool isOnCornusHardfork(uint64_t block_number) const { return block_number >= cornus_hf.block_num; }

HAS_RLP_FIELDS
};
Expand Down
19 changes: 19 additions & 0 deletions libraries/config/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +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);

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 @@ -199,6 +202,22 @@ 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
11 changes: 9 additions & 2 deletions libraries/config/src/genesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ GenesisConfig::GenesisConfig() {
pbft.committee_size = 5;
pbft.dag_blocks_size = 100;
pbft.ghost_path_move_back = 1;
pbft.gas_limit = 60000000;
pbft.gas_limit = 315000000;

// DAG config
dag.gas_limit = 10000000;
dag.gas_limit = 315000000;

// DPOS config
auto& dpos = state.dpos;
Expand Down Expand Up @@ -129,4 +129,11 @@ bytes GenesisConfig::rlp() const {

blk_hash_t GenesisConfig::genesisHash() const { return dev::sha3(rlp()); }

std::pair<uint64_t, uint64_t> GenesisConfig::getGasLimits(uint64_t block_number) const {
if (state.hardforks.isOnCornusHardfork(block_number)) {
return {state.hardforks.cornus_hf.dag_gas_limit, state.hardforks.cornus_hf.pbft_gas_limit};
}
return {dag.gas_limit, pbft.gas_limit};
}

} // namespace taraxa
6 changes: 5 additions & 1 deletion libraries/config/src/hardfork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,19 @@ Json::Value enc_json(const CornusHardforkConfig& obj) {
Json::Value json(Json::objectValue);
json["block_num"] = dev::toJS(obj.block_num);
json["delegation_locking_period"] = dev::toJS(obj.delegation_locking_period);
json["dag_gas_limit"] = dev::toJS(obj.dag_gas_limit);
json["pbft_gas_limit"] = dev::toJS(obj.pbft_gas_limit);
return json;
}

void dec_json(const Json::Value& json, CornusHardforkConfig& obj) {
obj.block_num = json["block_num"].isUInt64() ? dev::getUInt(json["block_num"]) : uint64_t(-1);
obj.delegation_locking_period = dev::getUInt(json["delegation_locking_period"]);
obj.dag_gas_limit = dev::getUInt(json["dag_gas_limit"]);
obj.pbft_gas_limit = dev::getUInt(json["pbft_gas_limit"]);
}

RLP_FIELDS_DEFINE(CornusHardforkConfig, block_num, delegation_locking_period)
RLP_FIELDS_DEFINE(CornusHardforkConfig, block_num, delegation_locking_period, dag_gas_limit, pbft_gas_limit)

Json::Value enc_json(const HardforksConfig& obj) {
Json::Value json(Json::objectValue);
Expand Down
3 changes: 1 addition & 2 deletions libraries/core_libs/consensus/include/dag/dag_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ class DagManager : public std::enable_shared_from_this<DagManager> {
const uint32_t cache_delete_step_ = 100;
ExpirationCacheMap<blk_hash_t, std::shared_ptr<DagBlock>> seen_blocks_;
std::shared_ptr<final_chain::FinalChain> final_chain_;
const uint64_t kPbftGasLimit;
const HardforksConfig kHardforks;
const GenesisConfig kGenesis;
const uint64_t kValidatorMaxVote;

LOG_OBJECTS_DEFINE
Expand Down
3 changes: 2 additions & 1 deletion libraries/core_libs/consensus/include/pbft/pbft_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,10 @@ class PbftManager {
/**
* @brief Check a block weight of gas estimation
* @param dag_blocks dag blocks
* @param period period
* @return true if total weight of gas estimation is less or equal to gas limit. Otherwise return false
*/
bool checkBlockWeight(const std::vector<std::shared_ptr<DagBlock>> &dag_blocks) const;
bool checkBlockWeight(const std::vector<std::shared_ptr<DagBlock>> &dag_blocks, PbftPeriod period) const;

blk_hash_t getLastPbftBlockHash();

Expand Down
6 changes: 3 additions & 3 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.genesis.pbft.gas_limit),
kDagGasLimit(config.genesis.dag.gas_limit),
kPbftGasLimit(config.propose_pbft_gas_limit),
kDagGasLimit(config.propose_dag_gas_limit),
kHardforks(config.genesis.state.hardforks),
kValidatorMaxVote(config.genesis.state.dpos.validator_maximum_stake /
config.genesis.state.dpos.vote_eligibility_balance_step) {
Expand Down Expand Up @@ -117,7 +117,7 @@ bool DagBlockProposer::proposeDagBlock() {
}
}

auto [transactions, estimations] = getShardedTrxs(*proposal_period, dag_mgr_->getDagConfig().gas_limit);
auto [transactions, estimations] = getShardedTrxs(*proposal_period, kDagGasLimit);
if (transactions.empty()) {
last_propose_level_ = propose_level;
num_tries_ = 0;
Expand Down
19 changes: 10 additions & 9 deletions libraries/core_libs/consensus/src/dag/dag_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ DagManager::DagManager(const FullNodeConfig &config, addr_t node_addr, std::shar
dag_expiry_limit_(config.dag_expiry_limit),
seen_blocks_(cache_max_size_, cache_delete_step_),
final_chain_(std::move(final_chain)),
kPbftGasLimit(config.genesis.pbft.gas_limit),
kHardforks(config.genesis.state.hardforks),
kGenesis(config.genesis),
kValidatorMaxVote(config.genesis.state.dpos.validator_maximum_stake /
config.genesis.state.dpos.vote_eligibility_balance_step) {
LOG_OBJECTS_CREATE("DAGMGR");
Expand Down Expand Up @@ -512,7 +511,7 @@ void DagManager::recoverDag() {
try {
uint64_t max_vote_count = 0;
const auto vote_count = final_chain_->dposEligibleVoteCount(*propose_period, blk->getSender());
if (*propose_period < kHardforks.magnolia_hf.block_num) {
if (*propose_period < kGenesis.state.hardforks.magnolia_hf.block_num) {
max_vote_count = final_chain_->dposEligibleTotalVoteCount(*propose_period);
} else {
max_vote_count = kValidatorMaxVote;
Expand Down Expand Up @@ -673,7 +672,7 @@ std::pair<DagManager::VerifyBlockReturnType, SharedTransactions> DagManager::ver
const auto proposal_period_hash = db_->getPeriodBlockHash(*propose_period);
uint64_t max_vote_count = 0;
const auto vote_count = final_chain_->dposEligibleVoteCount(*propose_period, blk->getSender());
if (*propose_period < kHardforks.magnolia_hf.block_num) {
if (*propose_period < kGenesis.state.hardforks.magnolia_hf.block_num) {
max_vote_count = final_chain_->dposEligibleTotalVoteCount(*propose_period);
} else {
max_vote_count = kValidatorMaxVote;
Expand Down Expand Up @@ -715,14 +714,16 @@ std::pair<DagManager::VerifyBlockReturnType, SharedTransactions> DagManager::ver
return {VerifyBlockReturnType::IncorrectTransactionsEstimation, {}};
}

if (total_block_weight > getDagConfig().gas_limit) {
LOG(log_er_) << "BlockTooBig. DAG block " << blk->getHash() << " gas_limit: " << getDagConfig().gas_limit
const auto [dag_gas_limit, pbft_gas_limit] = kGenesis.getGasLimits(*propose_period);

if (total_block_weight > dag_gas_limit) {
LOG(log_er_) << "BlockTooBig. DAG block " << blk->getHash() << " gas_limit: " << dag_gas_limit
<< " total_block_weight " << total_block_weight << " current period "
<< final_chain_->lastBlockNumber();
return {VerifyBlockReturnType::BlockTooBig, {}};
}

if ((blk->getTips().size() + 1) > kPbftGasLimit / getDagConfig().gas_limit) {
if ((blk->getTips().size() + 1) > pbft_gas_limit / dag_gas_limit) {
for (const auto &t : blk->getTips()) {
const auto tip_blk = getDagBlock(t);
if (tip_blk == nullptr) {
Expand All @@ -731,8 +732,8 @@ std::pair<DagManager::VerifyBlockReturnType, SharedTransactions> DagManager::ver
}
block_gas_estimation += tip_blk->getGasEstimation();
}
if (block_gas_estimation > kPbftGasLimit) {
LOG(log_er_) << "BlockTooBig. DAG block " << blk->getHash() << " with tips has limit: " << kPbftGasLimit
if (block_gas_estimation > pbft_gas_limit) {
LOG(log_er_) << "BlockTooBig. DAG block " << blk->getHash() << " with tips has limit: " << pbft_gas_limit
<< " block_gas_estimation " << block_gas_estimation << " current period "
<< final_chain_->lastBlockNumber();
return {VerifyBlockReturnType::BlockTooBig, {}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ std::optional<h256> FinalChain::finalChainHash(EthBlockNumber n) const {
return {};
}

if (kConfig.genesis.state.hardforks.isCornusHardfork(n)) {
if (kConfig.genesis.state.hardforks.isOnCornusHardfork(n)) {
return header->hash;
}
return header->state_root;
Expand Down
12 changes: 8 additions & 4 deletions libraries/core_libs/consensus/src/pbft/pbft_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,8 @@ PbftManager::proposePbftBlock() {
}
const auto &dag_block_weight = dag_blk->getGasEstimation();

if (total_weight + dag_block_weight > kGenesisConfig.pbft.gas_limit) {
const auto [dag_gas_limit, pbft_gas_limit] = kGenesisConfig.getGasLimits(current_pbft_period);
if (total_weight + dag_block_weight > pbft_gas_limit) {
break;
}
total_weight += dag_block_weight;
Expand Down Expand Up @@ -1553,7 +1554,7 @@ bool PbftManager::validatePbftBlock(const std::shared_ptr<PbftBlock> &pbft_block
auto prev_pbft_block = pbft_chain_->getPbftBlockInChain(last_pbft_block_hash);
auto ghost = dag_mgr_->getGhostPath(prev_pbft_block.getPivotDagBlockHash());
if (ghost.size() > 1 && anchor_hash != ghost[1]) {
if (!checkBlockWeight(anchor_dag_block_order_cache_[anchor_hash])) {
if (!checkBlockWeight(anchor_dag_block_order_cache_[anchor_hash], block_period)) {
LOG(log_er_) << "PBFT block " << pbft_block_hash << " weight exceeded max limit";
anchor_dag_block_order_cache_.erase(anchor_hash);
return false;
Expand Down Expand Up @@ -2155,11 +2156,14 @@ void PbftManager::periodDataQueuePush(PeriodData &&period_data, dev::p2p::NodeID

size_t PbftManager::periodDataQueueSize() const { return sync_queue_.size(); }

bool PbftManager::checkBlockWeight(const std::vector<std::shared_ptr<DagBlock>> &dag_blocks) const {
bool PbftManager::checkBlockWeight(const std::vector<std::shared_ptr<DagBlock>> &dag_blocks, PbftPeriod period) const {
const u256 total_weight =
std::accumulate(dag_blocks.begin(), dag_blocks.end(), u256(0),
[](u256 value, const auto &dag_block) { return value + dag_block->getGasEstimation(); });
if (total_weight > kGenesisConfig.pbft.gas_limit) {
auto pbft_gas_limit = kGenesisConfig.state.hardforks.isOnCornusHardfork(period)
? kGenesisConfig.state.hardforks.cornus_hf.pbft_gas_limit
: kGenesisConfig.pbft.gas_limit;
if (total_weight > pbft_gas_limit) {
return false;
}
return true;
Expand Down
1 change: 1 addition & 0 deletions tests/dag_block_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ TEST_F(DagBlockMgrTest, too_big_dag_block) {
// make config
auto node_cfgs = make_node_cfgs(1, 1, 20);
node_cfgs.front().genesis.dag.gas_limit = 500000;
node_cfgs.front().propose_dag_gas_limit = 500000;

auto node = create_nodes(node_cfgs).front();
auto db = node->getDB();
Expand Down
7 changes: 6 additions & 1 deletion tests/pbft_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ TEST_F(PbftManagerWithDagCreation, dag_generation) {
TEST_F(PbftManagerWithDagCreation, limit_dag_block_size) {
auto node_cfgs = make_node_cfgs(1, 1, 5, true);
node_cfgs.front().genesis.dag.gas_limit = 500000;
node_cfgs.front().propose_dag_gas_limit = 500000;
makeNodeFromConfig(node_cfgs);
deployContract();

Expand Down Expand Up @@ -596,6 +597,8 @@ TEST_F(PbftManagerWithDagCreation, limit_pbft_block) {
auto node_cfgs = make_node_cfgs(1, 1, 5, true);
node_cfgs.front().genesis.dag.gas_limit = 500000;
node_cfgs.front().genesis.pbft.gas_limit = 1100000;
node_cfgs.front().propose_dag_gas_limit = 500000;
node_cfgs.front().propose_pbft_gas_limit = 1100000;
makeNodeFromConfig(node_cfgs);

deployContract();
Expand Down Expand Up @@ -631,6 +634,8 @@ TEST_F(PbftManagerWithDagCreation, produce_overweighted_block) {
auto node_cfgs = make_node_cfgs(1, 1, 5, true);
auto dag_gas_limit = node_cfgs.front().genesis.dag.gas_limit = 500000;
node_cfgs.front().genesis.pbft.gas_limit = 1100000;
node_cfgs.front().propose_dag_gas_limit = 500000;
node_cfgs.front().propose_pbft_gas_limit = 1100000;
makeNodeFromConfig(node_cfgs);

deployContract();
Expand Down Expand Up @@ -665,7 +670,7 @@ TEST_F(PbftManagerWithDagCreation, produce_overweighted_block) {
const auto period = node->getFinalChain()->lastBlockNumber();
auto period_data = node->getDB()->getPeriodData(period);
ASSERT_TRUE(period_data.has_value());
EXPECT_FALSE(node->getPbftManager()->checkBlockWeight(period_data->dag_blocks));
EXPECT_FALSE(node->getPbftManager()->checkBlockWeight(period_data->dag_blocks, period));
}

TEST_F(PbftManagerWithDagCreation, proposed_blocks) {
Expand Down
Loading

0 comments on commit 2bc913f

Please sign in to comment.