Skip to content

Commit

Permalink
Merge pull request #651 from eosnetworkfoundation/elmato/add-admin-ac…
Browse files Browse the repository at this point in the history
…tions

[0.5] Add admin actions
  • Loading branch information
elmato committed Sep 6, 2023
2 parents a9df91a + 00f1133 commit 250f741
Show file tree
Hide file tree
Showing 14 changed files with 1,209 additions and 382 deletions.
4 changes: 4 additions & 0 deletions contract/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 contract/include/evm_runtime/evm_contract.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ class [[eosio::contract]] evm_contract : public contract
/// @return true if all garbage has been collected
[[eosio::action]] bool gc(uint32_t max);

#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 contract/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 contract/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/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 contract/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.5.1")

Expand Down Expand Up @@ -84,5 +90,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=46080)
target_link_options(evm_runtime PUBLIC --stack-size=45360)
endif()
Loading

0 comments on commit 250f741

Please sign in to comment.