Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
Merge branch 'get-resource-limits-fix' into metric3
Browse files Browse the repository at this point in the history
  • Loading branch information
arhag committed Aug 1, 2018
1 parent b1f3662 commit 776ae6f
Show file tree
Hide file tree
Showing 27 changed files with 211 additions and 425 deletions.
27 changes: 17 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
cmake_minimum_required(VERSION 3.5)
project(eosio_contracts VERSION 1.1.0)
project(eosio_contracts VERSION 1.1.1)

set(EOSIO_DEPENDENCY "1.1")
set(EOSIO_WASMSDK_DEPENDENCY "1.1")

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(TEST_BUILD_TYPE "Debug")
set(CMAKE_BUILD_TYPE "Release")
else()
set(TEST_BUILD_TYPE ${CMAKE_BUILD_TYPE})
endif()
if(CXX_COMPILER STREQUAL "" OR NOT CXX_COMPILER)
set(CXX_COMPILER ${CMAKE_CXX_COMPILER})
endif()

if(EOSIO_INSTALL_PREFIX STREQUAL "" OR NOT EOSIO_INSTALL_PREFIX)
set(EOSIO_INSTALL_PREFIX "/usr/local")
if(EOSIO_ROOT STREQUAL "" OR NOT EOSIO_ROOT)
set(EOSIO_ROOT "/usr/local/eosio")
endif()

# if no wasm root is given use default path
if(WASM_ROOT STREQUAL "" OR NOT WASM_ROOT)
set(WASM_ROOT ${CMAKE_INSTALL_PREFIX})
if(EOSIO_WASMSDK_ROOT STREQUAL "" OR NOT EOSIO_WASMSDK_ROOT)
set(EOSIO_WASMSDK_ROOT "/usr/local/eosio.wasmsdk")
endif()

list(APPEND CMAKE_MODULE_PATH ${WASM_ROOT}/lib/cmake)
list(APPEND CMAKE_MODULE_PATH ${EOSIO_WASMSDK_ROOT}/lib/cmake)
include(EosioWasmToolchain)

### Check the version of wasmsdk
string(FIND "${EOSIO_WASMSDK_VERSION}" "${EOSIO_WASMSDK_DEPENDENCY}" output)

if (NOT "${output}" EQUAL 0)
message(FATAL_ERROR "Incorrect EOSIO.WasmSDK version, please use version ${EOSIO_WASMSDK_DEPENDENCY}.x")
endif()

include_directories(AFTER ${BOOST_ROOT}/include)
add_subdirectory(eosio.msig)
add_subdirectory(eosio.sudo)
add_subdirectory(eosio.system)
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# eosio.contracts

## Version : 1.1.0
## Version : 1.1.1

The design of the EOSIO blockchain calls for a number of smart contracts that are run at a privileged permission level in order to support functions such as block producer registration and voting, token staking for CPU and network bandwidth, RAM purchasing, multi-sig, etc. These smart contracts are referred to as the system, token, msig and sudo contracts.

This repository contains examples of these priviledged contracts that are useful when depoying, managing, and/or using an EOSIO blockchain. They are provided for reference purposes:
This repository contains examples of these privileged contracts that are useful when deploying, managing, and/or using an EOSIO blockchain. They are provided for reference purposes:

* [eosio.system](https://github.com/eosio/eosio.contracts/tree/master/eosio.system)

* [eosio.msig](https://github.com/eosio/eosio.contracts/tree/master/eosio.msig)
* [eosio.sudo](https://github.com/eosio/eosio.contracts/tree/master/eosio.sudo)
The following unpriviledged contract(s) are also part of the system.

The following unprivileged contract(s) are also part of the system.
* [eosio.token](https://github.com/eosio/eosio.contracts/tree/master/eosio.token)

Dependencies:
Expand Down
4 changes: 2 additions & 2 deletions UnitTestsExternalProject.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ include(GNUInstallDirs)

ExternalProject_Add(
contracts_unit_tests
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${TEST_BUILD_TYPE} -DROOT_DIR=${CMAKE_SOURCE_DIR} -DEOSIO_INSTALL_PREFIX=${EOSIO_INSTALL_PREFIX} -DOPENSSL_INSTALL_PREFIX=${OPENSSL_ROOT} -DSECP256K1_INSTALL_LIB=${SECP256K1_ROOT} -DBOOST_ROOT=${BOOST_ROOT}/include -DCMAKE_CXX_COMPILER=${CXX_COMPILER}
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${TEST_BUILD_TYPE} -DEOSIO_ROOT=${EOSIO_ROOT} -DEOSIO_DEPENDENCY=${EOSIO_DEPENDENCY}

SOURCE_DIR ${CMAKE_SOURCE_DIR}/tests
BINARY_DIR ${CMAKE_SOURCE_DIR}/build/tests
BINARY_DIR ${CMAKE_BINARY_DIR}/tests
BUILD_ALWAYS 1
TEST_COMMAND ""
INSTALL_COMMAND ""
Expand Down
51 changes: 1 addition & 50 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,9 @@ printf "\t=========== Building eosio.contracts ===========\n\n"
RED='\033[0;31m'
NC='\033[0m'

#if [ ! -d "/usr/local/eosio" ]; then
# printf "${RED}Error, please ensure that eosio is installed correctly!\n\n${NC}"
# exit -1
#fi

if [ ! -d "/usr/local/eosio.wasmsdk" ]; then
printf "${RED}Error, please ensure that eosio.wasmsdk is installed correctly!\n\n${NC}"
exit -1
fi

unamestr=`uname`
if [[ "${unamestr}" == 'Darwin' ]]; then
BOOST=/usr/local
CXX_COMPILER=g++
else
BOOST=~/opt/boost
OS_NAME=$( cat /etc/os-release | grep ^NAME | cut -d'=' -f2 | sed 's/\"//gI' )

case "$OS_NAME" in
"Amazon Linux AMI")
CXX_COMPILER=g++
C_COMPILER=gcc
;;
"CentOS Linux")
CXX_COMPILER=g++
C_COMPILER=gcc
;;
"elementary OS")
CXX_COMPILER=clang++-4.0
C_COMPILER=clang-4.0
;;
"Fedora")
CXX_COMPILER=g++
C_COMPILER=gcc
;;
"Linux Mint")
CXX_COMPILER=clang++-4.0
C_COMPILER=clang-4.0
;;
"Ubuntu")
CXX_COMPILER=clang++-4.0
C_COMPILER=clang-4.0
;;
*)
printf "\\n\\tUnsupported Linux Distribution. Exiting now.\\n\\n"
exit 1
esac
fi

CORES=`getconf _NPROCESSORS_ONLN`
mkdir -p build
pushd build &> /dev/null
cmake -DCXX_COMPILER="${CXX_COMPILER}" -DBOOST_ROOT="${BOOST}" -DEOSIO_INSTALL_PREFIX=/usr/local ../
cmake ../
make -j${CORES}
popd &> /dev/null
4 changes: 2 additions & 2 deletions eosio.msig/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/abi/eosio.msig.abi" "${CMAKE_CURRENT_SOURCE_DIR}/bin/eosio.msig" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/abi/eosio.msig.abi" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY)

add_executable(eosio.msig.wasm ${CMAKE_CURRENT_SOURCE_DIR}/src/eosio.msig.cpp)
target_include_directories(eosio.msig.wasm
Expand All @@ -7,6 +7,6 @@ target_include_directories(eosio.msig.wasm

set_target_properties(eosio.msig.wasm
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/eosio.msig")
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")

#install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${WASM_ROOT}/eosio.wasmsdk/include)
2 changes: 0 additions & 2 deletions eosio.msig/bin/eosio.msig/.gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions eosio.msig/build.sh

This file was deleted.

4 changes: 2 additions & 2 deletions eosio.sudo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ target_include_directories(eosio.sudo.wasm

set_target_properties(eosio.sudo.wasm
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/eosio.sudo")
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/abi/eosio.sudo.abi" "${CMAKE_CURRENT_SOURCE_DIR}/bin/eosio.sudo" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/abi/eosio.sudo.abi" "${CMAKE__CURRENT_BINARY_DIR}" COPYONLY)
#install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${WASM_ROOT}/eosio.wasmsdk/include)
2 changes: 0 additions & 2 deletions eosio.sudo/bin/eosio.sudo/.gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions eosio.sudo/build.sh

This file was deleted.

4 changes: 2 additions & 2 deletions eosio.system/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ target_include_directories(eosio.system.wasm

set_target_properties(eosio.system.wasm
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/eosio.system")
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/abi/eosio.system.abi" "${CMAKE_CURRENT_SOURCE_DIR}/bin/eosio.system" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/abi/eosio.system.abi" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY)

#install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${WASM_ROOT}/eosio.wasmsdk/include)
2 changes: 0 additions & 2 deletions eosio.system/bin/eosio.system/.gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions eosio.system/build.sh

This file was deleted.

18 changes: 11 additions & 7 deletions eosio.system/src/delegate_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace eosiosystem {

static constexpr time refund_delay = 3*24*3600;
static constexpr time refund_expiration_time = 3600;
static constexpr int64_t ram_gift_bytes = 1400;

struct user_resources {
account_name owner;
Expand Down Expand Up @@ -86,7 +87,7 @@ namespace eosiosystem {
* This action will buy an exact amount of ram and bill the payer the current market price.
*/
void system_contract::buyrambytes( account_name payer, account_name receiver, uint32_t bytes ) {

auto itr = _rammarket.find(S(4,RAMCORE));
auto tmp = *itr;
auto eosout = tmp.convert( asset(bytes,S(0,RAM)), CORE_SYMBOL );
Expand Down Expand Up @@ -152,7 +153,7 @@ namespace eosiosystem {
res.ram_bytes += bytes_out;
});
}
set_resource_limits( res_itr->owner, res_itr->ram_bytes, res_itr->net_weight.amount, res_itr->cpu_weight.amount );
set_resource_limits( res_itr->owner, res_itr->ram_bytes + ram_gift_bytes, res_itr->net_weight.amount, res_itr->cpu_weight.amount );
}


Expand All @@ -179,7 +180,7 @@ namespace eosiosystem {
/// the cast to int64_t of bytes is safe because we certify bytes is <= quota which is limited by prior purchases
tokens_out = es.convert( asset(bytes,S(0,RAM)), CORE_SYMBOL);
});

eosio_assert( tokens_out.amount > 1, "token amount received from selling ram is too low" );

_gstate.total_ram_bytes_reserved -= static_cast<decltype(_gstate.total_ram_bytes_reserved)>(bytes); // bytes > 0 is asserted above
Expand All @@ -191,7 +192,7 @@ namespace eosiosystem {
userres.modify( res_itr, account, [&]( auto& res ) {
res.ram_bytes -= bytes;
});
set_resource_limits( res_itr->owner, res_itr->ram_bytes, res_itr->net_weight.amount, res_itr->cpu_weight.amount );
set_resource_limits( res_itr->owner, res_itr->ram_bytes + ram_gift_bytes, res_itr->net_weight.amount, res_itr->cpu_weight.amount );

INLINE_ACTION_SENDER(eosio::token, transfer)( N(eosio.token), {{N(eosio.ram),N(active)},{account,N(active)}},
{ N(eosio.ram), account, asset(tokens_out), std::string("sell ram") } );
Expand Down Expand Up @@ -270,7 +271,10 @@ namespace eosiosystem {
eosio_assert( asset(0) <= tot_itr->net_weight, "insufficient staked total net bandwidth" );
eosio_assert( asset(0) <= tot_itr->cpu_weight, "insufficient staked total cpu bandwidth" );

set_resource_limits( receiver, tot_itr->ram_bytes, tot_itr->net_weight.amount, tot_itr->cpu_weight.amount );
int64_t ram_bytes, net, cpu;
get_resource_limits( receiver, &ram_bytes, &net, &cpu );

set_resource_limits( receiver, std::max( tot_itr->ram_bytes + ram_gift_bytes, ram_bytes ), tot_itr->net_weight.amount, tot_itr->cpu_weight.amount );

if ( tot_itr->net_weight == asset(0) && tot_itr->cpu_weight == asset(0) && tot_itr->ram_bytes == 0 ) {
totals_tbl.erase( tot_itr );
Expand All @@ -286,8 +290,8 @@ namespace eosiosystem {
auto net_balance = stake_net_delta;
auto cpu_balance = stake_cpu_delta;
bool need_deferred_trx = false;


// net and cpu are same sign by assertions in delegatebw and undelegatebw
// redundant assertion also at start of changebw to protect against misuse of changebw
bool is_undelegating = (net_balance.amount + cpu_balance.amount ) < 0;
Expand Down
2 changes: 1 addition & 1 deletion eosio.system/src/producer_pay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace eosiosystem {
if( (timestamp.slot - _gstate.last_name_close.slot) > blocks_per_day ) {
name_bid_table bids(_self,_self);
auto idx = bids.get_index<N(highbid)>();
auto highest = idx.begin();
auto highest = idx.lower_bound( std::numeric_limits<uint64_t>::max()/2 );
if( highest != idx.end() &&
highest->high_bid > 0 &&
highest->last_bid_time < (current_time() - useconds_per_day) &&
Expand Down
4 changes: 2 additions & 2 deletions eosio.token/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ target_include_directories(eosio.token.wasm

set_target_properties(eosio.token.wasm
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin/eosio.token")
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/abi/eosio.token.abi" "${CMAKE_CURRENT_SOURCE_DIR}/bin/eosio.token" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/abi/eosio.token.abi" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY)
#install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${WASM_ROOT}/eosio.wasmsdk/include)
2 changes: 1 addition & 1 deletion eosio.token/abi/eosio.token.abi
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"base": "",
"fields": [
{"name":"owner", "type":"account_name"},
{"name":"symbol", "type":"symbol"},
{"name":"symbol", "type":"symbol"}
]
},{
"name": "account",
Expand Down
2 changes: 0 additions & 2 deletions eosio.token/bin/eosio.token/.gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions eosio.token/build.sh

This file was deleted.

Loading

0 comments on commit 776ae6f

Please sign in to comment.