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

[0.5 -> main] Add admin actions #654

Merged
merged 10 commits into from
Sep 6, 2023
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ option(WITH_LOGTIME
option(WITH_LARGE_STACK
"Build with 50MB of stack size, needed for unit tests" OFF)

option(WITH_ADMIN_ACTIONS
"Enables admin actions" ON)

ExternalProject_Add(
evm_runtime_project
SOURCE_DIR ${CMAKE_SOURCE_DIR}/src
Expand All @@ -25,6 +28,7 @@ ExternalProject_Add(
-DWITH_TEST_ACTIONS=${WITH_TEST_ACTIONS}
-DWITH_LOGTIME=${WITH_LOGTIME}
-DWITH_LARGE_STACK=${WITH_LARGE_STACK}
-DWITH_ADMIN_ACTIONS=${WITH_ADMIN_ACTIONS}
UPDATE_COMMAND ""
PATCH_COMMAND ""
TEST_COMMAND ""
Expand Down
9 changes: 9 additions & 0 deletions include/evm_runtime/evm_contract.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ class [[eosio::contract]] evm_contract : public contract

[[eosio::action]] void assertnonce(eosio::name account, uint64_t next_nonce);

#ifdef WITH_ADMIN_ACTIONS
[[eosio::action]] void rmgcstore(uint64_t id);
[[eosio::action]] void setkvstore(uint64_t account_id, const bytes& key, const std::optional<bytes>& value);
[[eosio::action]] void rmaccount(uint64_t id);
[[eosio::action]] void addevmbal(uint64_t id, const bytes& delta, bool subtract);
[[eosio::action]] void addopenbal(name account, const bytes& delta, bool subtract);
[[eosio::action]] void freezeaccnt(uint64_t id, bool value);
#endif

#ifdef WITH_TEST_ACTIONS
[[eosio::action]] void testtx(const std::optional<bytes>& orlptx, const evm_runtime::test::block_info& bi);
[[eosio::action]] void
Expand Down
3 changes: 2 additions & 1 deletion include/evm_runtime/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ struct state : State {
name _self;
name _ram_payer;
bool _read_only;
bool _allow_frozen;
mutable std::map<evmc::address, uint64_t> addr2id;
mutable std::map<bytes32, bytes> addr2code;
mutable db_stats stats;
std::optional<config2> _config2;

explicit state(name self, name ram_payer, bool read_only=false) : _self(self), _ram_payer(ram_payer), _read_only{read_only}{}
explicit state(name self, name ram_payer, bool read_only=false, bool allow_frozen=true) : _self(self), _ram_payer(ram_payer), _read_only{read_only}, _allow_frozen{allow_frozen}{}
virtual ~state() override;

uint64_t get_next_account_id();
Expand Down
23 changes: 21 additions & 2 deletions include/evm_runtime/tables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,36 @@
#include <eosio/fixed_bytes.hpp>
#include <eosio/asset.hpp>
#include <eosio/singleton.hpp>
#include <eosio/binary_extension.hpp>

#include <evm_runtime/types.hpp>
#include <silkworm/core/common/base.hpp>
namespace evm_runtime {

using namespace eosio;
struct [[eosio::table]] [[eosio::contract("evm_contract")]] account {
enum class flag : uint32_t {
frozen = 0x1
};

uint64_t id;
bytes eth_address;
uint64_t nonce;
bytes balance;
std::optional<uint64_t> code_id;
std::optional<uint64_t> code_id;
binary_extension<uint32_t> flags=0;

void set_flag(flag f) {
flags.value() |= static_cast<uint32_t>(f);
}

void clear_flag(flag f) {
flags.value() &= ~static_cast<uint32_t>(f);
}

inline bool has_flag(flag f)const {
return (flags.value() & static_cast<uint32_t>(f) != 0);
}

uint64_t primary_key()const { return id; }

Expand All @@ -28,7 +47,7 @@ struct [[eosio::table]] [[eosio::contract("evm_contract")]] account {
return res;
}

EOSLIB_SERIALIZE(account, (id)(eth_address)(nonce)(balance)(code_id));
EOSLIB_SERIALIZE(account, (id)(eth_address)(nonce)(balance)(code_id)(flags));
};

typedef multi_index< "account"_n, account,
Expand Down
8 changes: 7 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ list(APPEND SOURCES
)
if (WITH_TEST_ACTIONS)
add_compile_definitions(WITH_TEST_ACTIONS)
list(APPEND SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test_actions.cpp)
endif()

if (WITH_LOGTIME)
add_compile_definitions(WITH_LOGTIME)
endif()

if (WITH_ADMIN_ACTIONS)
add_compile_definitions(WITH_ADMIN_ACTIONS)
list(APPEND SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/admin_actions.cpp)
endif()

add_compile_definitions(ANTELOPE)
add_compile_definitions(PROJECT_VERSION="0.6.0")

Expand Down Expand Up @@ -85,5 +91,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=38240)
target_link_options(evm_runtime PUBLIC --stack-size=37600)
endif()
Loading