Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return constant reference in value_promoter #760

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/evm_runtime/config_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ struct config_wrapper {
void update_consensus_parameters(eosio::asset ram_price_mb, uint64_t gas_price);
void update_consensus_parameters2(std::optional<uint64_t> gas_txnewaccount, std::optional<uint64_t> gas_newaccount, std::optional<uint64_t> gas_txcreate, std::optional<uint64_t> gas_codedeposit, std::optional<uint64_t> gas_sset);

consensus_parameter_data_type get_consensus_param();
std::pair<consensus_parameter_data_type, bool> get_consensus_param_and_maybe_promote();
const consensus_parameter_data_type& get_consensus_param();
std::pair<const consensus_parameter_data_type&, bool> get_consensus_param_and_maybe_promote();

void set_token_contract(eosio::name token_contract); // only set during init
eosio::name get_token_contract() const;
Expand Down
20 changes: 9 additions & 11 deletions include/evm_runtime/value_promoter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,27 @@
};

#define VALUE_PROMOTER_IMPL(T)\
T get_value(time_point_sec genesis_time, time_point current_time)const {\
T current_value = cached_value;\
const T& get_value(time_point_sec genesis_time, time_point current_time)const {\
if(pending_value.has_value() && pending_value->is_active(genesis_time, current_time)) {\
current_value = pending_value->value;\
return pending_value->value;\
}\
return current_value;\
return cached_value;\
}\
std::pair<T, bool> get_value_and_maybe_promote(time_point_sec genesis_time, time_point current_time) {\
T current_value = cached_value;\
std::pair<const T&, bool> get_value_and_maybe_promote(time_point_sec genesis_time, time_point current_time) {\
bool promoted = false;\
if(pending_value.has_value() && pending_value->is_active(genesis_time, current_time)) {\
current_value = pending_value->value;\
promote_pending();\
promoted = true;\
}\
return std::pair<T, bool>(current_value, promoted);\
return std::pair<const T&, bool>(cached_value, promoted);\
}\
template <typename Visitor>\
void update(Visitor&& visitor_fn, time_point_sec genesis_time, time_point current_time) {\
auto value = get_value_and_maybe_promote(genesis_time, current_time);\
visitor_fn(value.first);\
auto tmp = get_value_and_maybe_promote(genesis_time, current_time);\
T value = tmp.first;\
visitor_fn(value);\
pending_value.emplace(T##_pending{\
.value = value.first,\
.value = value,\
.time = current_time\
});\
}\
Expand Down
4 changes: 2 additions & 2 deletions src/config_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,13 @@ void config_wrapper::update_consensus_parameters2(std::optional<uint64_t> gas_tx
set_dirty();
}

consensus_parameter_data_type config_wrapper::get_consensus_param() {
const consensus_parameter_data_type& config_wrapper::get_consensus_param() {
// should not happen
eosio::check(_cached_config.consensus_parameter.has_value(), "consensus_parameter not exist");
return _cached_config.consensus_parameter->get_value(_cached_config.genesis_time, get_current_time());
}

std::pair<consensus_parameter_data_type, bool> config_wrapper::get_consensus_param_and_maybe_promote() {
std::pair<const consensus_parameter_data_type&, bool> config_wrapper::get_consensus_param_and_maybe_promote() {

// should not happen
eosio::check(_cached_config.consensus_parameter.has_value(), "consensus_parameter not exist");
Expand Down