Skip to content

Commit

Permalink
Allow enqueue_gas_price to be called multiple times on the same block
Browse files Browse the repository at this point in the history
  • Loading branch information
elmato committed Apr 22, 2024
1 parent 3fd8004 commit b9b7cc6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ target_compile_options(evm_runtime PUBLIC --no-missing-ricardian-clause)
if (WITH_LARGE_STACK)
target_link_options(evm_runtime PUBLIC --stack-size=50000000)
else()
target_link_options(evm_runtime PUBLIC --stack-size=35088)
target_link_options(evm_runtime PUBLIC --stack-size=34896)
endif()
17 changes: 16 additions & 1 deletion src/config_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,25 @@ void config_wrapper::set_gas_price(uint64_t gas_price) {
void config_wrapper::enqueue_gas_price(uint64_t gas_price) {
price_queue_table queue(_self, _self.value);
auto time = eosio::current_time_point() + eosio::seconds(grace_period_seconds);
auto time_us = time.elapsed.count();

auto it = queue.end();
if( it != queue.begin()) {
--it;
eosio::check(time_us >= it->time, "internal error");
if(it->time == time_us) {
queue.modify(*it, eosio::same_payer, [&](auto& el) {
el.price = gas_price;
});
return;
}
}

queue.emplace(_self, [&](auto& el) {
el.time = time.elapsed.count();
el.time = time_us;
el.price = gas_price;
});

}

void config_wrapper::process_price_queue() {
Expand Down
1 change: 0 additions & 1 deletion tests/basic_evm_tester.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#include <deque>
#include <eosio/chain/abi_serializer.hpp>
#include <eosio/testing/tester.hpp>
#include <eosio/chain/fixed_bytes.hpp>
Expand Down
14 changes: 12 additions & 2 deletions tests/gas_fee_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,20 @@ try {

produce_blocks(100);

// Queue change of gas_price to 20Gwei
setfeeparams({.gas_price = 2*ten_gwei});
// Queue change of gas_price to 30Gwei
setfeeparams({.gas_price = 3*ten_gwei});
auto t2 = control->pending_block_time()+fc::seconds(price_queue_grace_period);

q = get_price_queue();
BOOST_CHECK_EQUAL(q.size(), 2);
BOOST_CHECK_EQUAL(q[0].time, t1.time_since_epoch().count());
BOOST_CHECK_EQUAL(q[0].price, ten_gwei);
BOOST_CHECK_EQUAL(q[1].time, t2.time_since_epoch().count());
BOOST_CHECK_EQUAL(q[1].price, 3*ten_gwei);

// Overwrite queue change (same block) 20Gwei
setfeeparams({.gas_price = 2*ten_gwei});

q = get_price_queue();
BOOST_CHECK_EQUAL(q.size(), 2);
BOOST_CHECK_EQUAL(q[0].time, t1.time_since_epoch().count());
Expand Down

0 comments on commit b9b7cc6

Please sign in to comment.