-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add support for storage and overhead price #750
Merged
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
229be9d
Add support for storage and overhead price
elmato 48ad835
Merge remote-tracking branch 'origin/main' into elmato/add-overhead-s…
elmato bd1b6a0
Use value_promoter to handle evm_version, consensus_parameter, overhe…
elmato 800309d
Update silkworm with v3 support
elmato 2eab90b
github: Use cdt 4.0.1
elmato 9bcabe9
fix contract.yml
elmato 8625534
Use MACROS to implement value_promoter to circumvent cdt limitations …
elmato 867ce30
Use queue mechanism when changing gas_prices
elmato 86f48e5
Check price queue is empty when switching to v3
elmato 2ebca8f
Add --fix-missing when installing cdt and leap deb packages
elmato 46604b2
apt-get update and apt-get upgrade to contract workflow
elmato d50cf93
Fix contract workflow
elmato File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#pragma once | ||
#include <evm_runtime/value_promoter.hpp> | ||
|
||
#include <eosio/eosio.hpp> | ||
#include <eosio/fixed_bytes.hpp> | ||
|
@@ -8,9 +9,11 @@ | |
|
||
#include <evm_runtime/types.hpp> | ||
#include <evm_runtime/runtime_config.hpp> | ||
|
||
#include <eosevm/block_mapping.hpp> | ||
|
||
#include <silkworm/core/common/base.hpp> | ||
|
||
namespace evm_runtime { | ||
|
||
using namespace eosio; | ||
|
@@ -243,95 +246,14 @@ struct [[eosio::table]] [[eosio::contract("evm_contract")]] config2 | |
EOSLIB_SERIALIZE(config2, (next_account_id)); | ||
}; | ||
|
||
struct evm_version_type { | ||
struct pending { | ||
uint64_t version; | ||
time_point time; | ||
|
||
bool is_active(time_point_sec genesis_time, time_point current_time)const { | ||
eosevm::block_mapping bm(genesis_time.sec_since_epoch()); | ||
auto current_block_num = bm.timestamp_to_evm_block_num(current_time.time_since_epoch().count()); | ||
auto pending_block_num = bm.timestamp_to_evm_block_num(time.time_since_epoch().count()); | ||
return current_block_num > pending_block_num; | ||
} | ||
}; | ||
|
||
uint64_t get_version(time_point_sec genesis_time, time_point current_time)const { | ||
uint64_t current_version = cached_version; | ||
if(pending_version.has_value() && pending_version->is_active(genesis_time, current_time)) { | ||
current_version = pending_version->version; | ||
} | ||
return current_version; | ||
} | ||
|
||
std::pair<uint64_t, bool> get_version_and_maybe_promote(time_point_sec genesis_time, time_point current_time) { | ||
uint64_t current_version = cached_version; | ||
bool promoted = false; | ||
if(pending_version.has_value() && pending_version->is_active(genesis_time, current_time)) { | ||
current_version = pending_version->version; | ||
promote_pending(); | ||
promoted = true; | ||
} | ||
return std::make_pair(current_version, promoted); | ||
} | ||
|
||
void promote_pending() { | ||
eosio::check(pending_version.has_value(), "no pending version"); | ||
cached_version = pending_version.value().version; | ||
pending_version.reset(); | ||
} | ||
|
||
std::optional<pending> pending_version; | ||
uint64_t cached_version=0; | ||
struct gas_prices { | ||
uint64_t overhead_price{0}; | ||
uint64_t storage_price{0}; | ||
}; | ||
|
||
struct pending_consensus_parameter_data_type { | ||
consensus_parameter_data_type data; | ||
time_point pending_time; | ||
}; | ||
struct consensus_parameter_type { | ||
|
||
consensus_parameter_data_type current; | ||
std::optional<pending_consensus_parameter_data_type> pending; | ||
|
||
bool is_pending_active(time_point_sec genesis_time, time_point current_time)const { | ||
if (!pending.has_value()) return false; | ||
eosevm::block_mapping bm(genesis_time.sec_since_epoch()); | ||
auto current_block_num = bm.timestamp_to_evm_block_num(current_time.time_since_epoch().count()); | ||
auto pending_block_num = bm.timestamp_to_evm_block_num(pending->pending_time.time_since_epoch().count()); | ||
return current_block_num > pending_block_num; | ||
} | ||
|
||
// Reference invalidated by get_consensus_param_and_maybe_promote and update_consensus_param. | ||
const consensus_parameter_data_type& get_consensus_param( | ||
time_point_sec genesis_time, time_point current_time) const { | ||
if (is_pending_active(genesis_time, current_time)) { | ||
return pending->data; | ||
} | ||
return current; | ||
} | ||
|
||
std::pair<const consensus_parameter_data_type &, bool> get_consensus_param_and_maybe_promote( | ||
time_point_sec genesis_time, time_point current_time) { | ||
if (is_pending_active(genesis_time, current_time)) { | ||
current = pending->data; | ||
pending.reset(); | ||
// don't use make_pair as it create ref to temp objects | ||
return std::pair<const consensus_parameter_data_type &, bool>(current, true); | ||
} | ||
return std::pair<const consensus_parameter_data_type &, bool>(current, false); | ||
} | ||
|
||
template <typename Visitor> | ||
void update_consensus_param(Visitor visitor_fn, time_point current_time) { | ||
consensus_parameter_data_type new_pending = (pending.has_value() ? pending->data : current); | ||
std::visit(visitor_fn, new_pending); | ||
pending = pending_consensus_parameter_data_type{ | ||
.data = new_pending, | ||
.pending_time = current_time | ||
}; | ||
} | ||
}; | ||
VALUE_PROMOTER(uint64_t); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about |
||
VALUE_PROMOTER_REV(consensus_parameter_data_type); | ||
VALUE_PROMOTER(gas_prices); | ||
|
||
struct [[eosio::table]] [[eosio::contract("evm_contract")]] config | ||
{ | ||
|
@@ -342,12 +264,13 @@ struct [[eosio::table]] [[eosio::contract("evm_contract")]] config | |
uint64_t gas_price = 0; | ||
uint32_t miner_cut = 0; | ||
uint32_t status = 0; // <- bit mask values from status_flags | ||
binary_extension<evm_version_type> evm_version; | ||
binary_extension<consensus_parameter_type> consensus_parameter; | ||
binary_extension<value_promoter_uint64_t> evm_version; | ||
binary_extension<value_promoter_consensus_parameter_data_type> consensus_parameter; | ||
binary_extension<eosio::name> token_contract; // <- default(unset) means eosio.token | ||
binary_extension<uint32_t> queue_front_block; | ||
binary_extension<value_promoter_gas_prices> gas_prices; | ||
|
||
EOSLIB_SERIALIZE(config, (version)(chainid)(genesis_time)(ingress_bridge_fee)(gas_price)(miner_cut)(status)(evm_version)(consensus_parameter)(token_contract)(queue_front_block)); | ||
EOSLIB_SERIALIZE(config, (version)(chainid)(genesis_time)(ingress_bridge_fee)(gas_price)(miner_cut)(status)(evm_version)(consensus_parameter)(token_contract)(queue_front_block)(gas_prices)); | ||
}; | ||
|
||
struct [[eosio::table]] [[eosio::contract("evm_contract")]] price_queue | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#pragma once | ||
#include <eosio/time.hpp> | ||
#include <eosio/print.hpp> | ||
#include <eosevm/block_mapping.hpp> | ||
|
||
#define VALUE_PROMOTER_PENDING(T)\ | ||
struct T##_pending {\ | ||
T value;\ | ||
time_point time;\ | ||
bool is_active(time_point_sec genesis_time, time_point current_time)const {\ | ||
eosevm::block_mapping bm(genesis_time.sec_since_epoch());\ | ||
auto current_block_num = bm.timestamp_to_evm_block_num(current_time.time_since_epoch().count());\ | ||
auto pending_block_num = bm.timestamp_to_evm_block_num(time.time_since_epoch().count());\ | ||
return current_block_num > pending_block_num;\ | ||
}\ | ||
}; | ||
|
||
#define VALUE_PROMOTER_IMPL(T)\ | ||
T get_value(time_point_sec genesis_time, time_point current_time)const {\ | ||
T current_value = cached_value;\ | ||
if(pending_value.has_value() && pending_value->is_active(genesis_time, current_time)) {\ | ||
current_value = pending_value->value;\ | ||
}\ | ||
return current_value;\ | ||
}\ | ||
std::pair<T, bool> get_value_and_maybe_promote(time_point_sec genesis_time, time_point current_time) {\ | ||
T current_value = cached_value;\ | ||
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);\ | ||
}\ | ||
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);\ | ||
pending_value.emplace(T##_pending{\ | ||
.value = value.first,\ | ||
.time = current_time\ | ||
});\ | ||
}\ | ||
void promote_pending() {\ | ||
eosio::check(pending_value.has_value(), "no pending value");\ | ||
cached_value = pending_value.value().value;\ | ||
pending_value.reset();\ | ||
} | ||
|
||
#define VALUE_PROMOTER(T)\ | ||
VALUE_PROMOTER_PENDING(T);\ | ||
struct value_promoter_##T {\ | ||
std::optional<T##_pending> pending_value;\ | ||
T cached_value = T{};\ | ||
VALUE_PROMOTER_IMPL(T)\ | ||
}; | ||
|
||
#define VALUE_PROMOTER_REV(T)\ | ||
VALUE_PROMOTER_PENDING(T);\ | ||
struct value_promoter_##T {\ | ||
T cached_value = T{};\ | ||
std::optional<T##_pending> pending_value;\ | ||
VALUE_PROMOTER_IMPL(T)\ | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe rename to gas_prices_type to make it consistent with consensus_parameter_data_type
Also, consider change the name "gas_prices" everywhere to avoid confusion with gas_price (no s)