Skip to content

Commit

Permalink
Merge pull request EOSIO#150 from enumivo/staging2
Browse files Browse the repository at this point in the history
Staging2
  • Loading branch information
Enumivo authored May 25, 2018
2 parents af319a5 + 48d506b commit a7d3fae
Show file tree
Hide file tree
Showing 40 changed files with 3,744 additions and 814 deletions.
2 changes: 1 addition & 1 deletion contracts/enumivo.bios/enumivo.bios.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace enumivo {
require_auth( _self );
char buffer[action_data_size()];
read_action_data( buffer, sizeof(buffer) ); // should be the same data as enumivo::pack(schedule)
set_active_producers(buffer, sizeof(buffer));
set_proposed_producers(buffer, sizeof(buffer));
}

void reqauth( action_name from ) {
Expand Down
10 changes: 10 additions & 0 deletions contracts/enumivo.system/enumivo.system.abi
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@
"fields": [
{"name":"from", "type":"account_name"}
]
},{
"name": "setparams",
"base": "",
"fields": [
{"name":"params", "type":"enumivo_parameters"}
]
}
],
"actions": [{
Expand Down Expand Up @@ -488,6 +494,10 @@
"name": "reqauth",
"type": "require_auth",
"ricardian_contract": ""
},{
"name": "setparams",
"type": "setparams",
"ricardian_contract": ""
}],
"tables": [{
"name": "producers",
Expand Down
8 changes: 8 additions & 0 deletions contracts/enumivo.system/enumivo.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ namespace enumivosystem {
set_resource_limits( newact, 0, 0, 0 );
}

void system_contract::setparams( const enumivo_parameters& params ) {
require_auth( N(enumivo) );
(enumivosystem::enumivo_parameters&)(_gstate) = params;
enumivo_assert( 3 <= _gstate.max_authority_depth, "max_authority_depth should be at least 3" );
set_blockchain_parameters( params );
}

} /// enumivo.system


Expand All @@ -183,4 +190,5 @@ ENUMIVO_ABI( enumivosystem::system_contract,
//this file
(bidname)
(setpriv)
(setparams)
)
2 changes: 2 additions & 0 deletions contracts/enumivo.system/enumivo.system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ namespace enumivosystem {

void regproxy( const account_name proxy, bool isproxy );

void setparams( const enumivo_parameters& params );

// functions defined in producer_pay.cpp
void claimrewards( const account_name& owner );

Expand Down
10 changes: 5 additions & 5 deletions contracts/enumivo.system/voting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace enumivosystem {
* @pre authority of producer to register
*
*/
void system_contract::regproducer( const account_name producer, const enumivo::public_key& producer_key, const std::string& url, uint16_t location ) {
void system_contract::regproducer( const account_name producer, const enumivo::public_key& producer_key, const std::string& url, uint16_t location ) {
enumivo_assert( url.size() < 512, "url too long" );
require_auth( producer );

Expand Down Expand Up @@ -96,7 +96,7 @@ namespace enumivosystem {

top_producers.emplace_back( std::pair<enumivo::producer_key,uint16_t>({{it->owner, it->producer_key}, it->location}));
}



/// sort by producer name
Expand All @@ -114,7 +114,7 @@ namespace enumivosystem {

if( new_id != _gstate.last_producer_schedule_id ) {
_gstate.last_producer_schedule_id = new_id;
set_active_producers( packed_schedule.data(), packed_schedule.size() );
set_proposed_producers( packed_schedule.data(), packed_schedule.size() );
}
_gstate.last_producer_schedule_update = block_time;
}
Expand All @@ -133,7 +133,7 @@ namespace enumivosystem {
* @pre voter must have previously staked some ENU for voting
* @pre voter->staked must be up to date
*
* @post every producer previously voted for will have vote reduced by previous vote weight
* @post every producer previously voted for will have vote reduced by previous vote weight
* @post every producer newly voted for will have vote increased by new vote amount
* @post prior proxy will proxied_vote_weight decremented by previous vote weight
* @post new proxy will proxied_vote_weight incremented by new vote weight
Expand Down Expand Up @@ -245,7 +245,7 @@ namespace enumivosystem {
/**
* An account marked as a proxy can vote with the weight of other accounts which
* have selected it as a proxy. Other accounts must refresh their voteproducer to
* update the proxy's weight.
* update the proxy's weight.
*
* @param isproxy - true if proxy wishes to vote on behalf of others, false otherwise
* @pre proxy must have something staked (existing row in voters table)
Expand Down
9 changes: 8 additions & 1 deletion contracts/enumivolib/privileged.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ extern "C" {

void set_resource_limits( account_name account, int64_t ram_bytes, int64_t net_weight, int64_t cpu_weight );

bool set_active_producers( char *producer_data, uint32_t producer_data_size );
/**
* Propose the new active producer schedule
* @param producer_data - packed data of produce_keys in the appropriate producer schedule order
* @param producer_data_size - size of the data buffer
*
* @return -1 if proposing a new producer schedule was unsuccessful, otherwise returns the version of the new proposed schedule
*/
int64_t set_proposed_producers( char *producer_data, uint32_t producer_data_size );

bool is_privileged( account_name account );

Expand Down
7 changes: 6 additions & 1 deletion enumivo_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
export LLVM_DIR=${HOME}/opt/wasm/lib/cmake/llvm
export CMAKE=${HOME}/opt/cmake/bin/cmake
export PATH=${HOME}/opt/mongodb/bin:$PATH
export BOOST_ROOT="${HOME}/opt/boost_1_66_0"
;;
"CentOS Linux")
FILE="${PWD}/scripts/enumivo_build_centos.sh"
Expand All @@ -152,41 +153,45 @@
export LLVM_DIR=${HOME}/opt/wasm/lib/cmake/llvm
export CMAKE=${HOME}/opt/cmake/bin/cmake
export PATH=${HOME}/opt/mongodb/bin:$PATH
export BOOST_ROOT="${HOME}/opt/boost_1_66_0"
;;
"elementary OS")
FILE="${PWD}/scripts/enumivo_build_ubuntu.sh"
CXX_COMPILER=clang++-4.0
C_COMPILER=clang-4.0
MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf
export PATH=${HOME}/opt/mongodb/bin:$PATH
export BOOST_ROOT="${HOME}/opt/boost_1_66_0"
;;
"Fedora")
FILE="${PWD}/scripts/enumivo_build_fedora.sh"
CXX_COMPILER=g++
C_COMPILER=gcc
MONGOD_CONF=/etc/mongod.conf
export LLVM_DIR=${HOME}/opt/wasm/lib/cmake/llvm
export BOOST_ROOT="${HOME}/opt/boost_1_66_0"
;;
"Linux Mint")
FILE="${PWD}/scripts/enumivo_build_ubuntu.sh"
CXX_COMPILER=clang++-4.0
C_COMPILER=clang-4.0
MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf
export PATH=${HOME}/opt/mongodb/bin:$PATH
export BOOST_ROOT="${HOME}/opt/boost_1_67_0"
;;
"Ubuntu")
FILE="${PWD}/scripts/enumivo_build_ubuntu.sh"
CXX_COMPILER=clang++-4.0
C_COMPILER=clang-4.0
MONGOD_CONF=${HOME}/opt/mongodb/mongod.conf
export PATH=${HOME}/opt/mongodb/bin:$PATH
export BOOST_ROOT="${HOME}/opt/boost_1_67_0"
;;
*)
printf "\\n\\tUnsupported Linux Distribution. Exiting now.\\n\\n"
exit 1
esac

export BOOST_ROOT="${HOME}/opt/boost_1_66_0"
OPENSSL_ROOT_DIR=/usr/include/openssl
WASM_ROOT="${HOME}/opt/wasm"
fi
Expand Down
15 changes: 15 additions & 0 deletions libraries/chain/block_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ namespace enumivo { namespace chain {
optional<signed_block> bad_block;
uint32_t block_num = 0;

block_id_type previous;

while( pos < end_pos ) {
signed_block tmp;

Expand All @@ -319,6 +321,19 @@ namespace enumivo { namespace chain {
break;
}

auto id = tmp.id();
if( block_header::num_from_id(previous) + 1 != block_header::num_from_id(id) ) {
elog( "Block ${num} (${id}) skips blocks. Previous block in block log is block ${prev_num} (${previous})",
("num", block_header::num_from_id(id))("id", id)
("prev_num", block_header::num_from_id(previous))("previous", previous) );
}
if( previous != tmp.previous ) {
elog( "Block ${num} (${id}) does not link back to previous block. "
"Expected previous: ${expected}. Actual previous: ${actual}.",
("num", block_header::num_from_id(id))("id", id)("expected", previous)("actual", tmp.previous) );
}
previous = id;

uint64_t tmp_pos = std::numeric_limits<uint64_t>::max();
if( (static_cast<uint64_t>(old_block_stream.tellg()) + sizeof(pos)) <= end_pos ) {
old_block_stream.read( reinterpret_cast<char*>(&tmp_pos), sizeof(tmp_pos) );
Expand Down
5 changes: 4 additions & 1 deletion libraries/chain/chain_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ namespace enumivo { namespace chain {
"min transaction cpu usage cannot exceed max transaction cpu usage" );
ENU_ASSERT( max_transaction_cpu_usage < (max_block_cpu_usage - min_transaction_cpu_usage), action_validate_exception,
"max transaction cpu usage must be at less than the difference between the max block cpu usage and the min transaction cpu usage" );
}

ENU_ASSERT( 1 <= max_authority_depth, action_validate_exception,
"max authority depth should be at least 1" );
}

} } // namespace enumivo::chain
12 changes: 7 additions & 5 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1218,17 +1218,17 @@ void controller::pop_block() {
my->pop_block();
}

bool controller::set_proposed_producers( vector<producer_key> producers ) {
int64_t controller::set_proposed_producers( vector<producer_key> producers ) {
const auto& gpo = get_global_properties();
auto cur_block_num = head_block_num() + 1;

if( gpo.proposed_schedule_block_num.valid() ) {
if( *gpo.proposed_schedule_block_num != cur_block_num )
return false; // there is already a proposed schedule set in a previous block, wait for it to become pending
return -1; // there is already a proposed schedule set in a previous block, wait for it to become pending

if( std::equal( producers.begin(), producers.end(),
gpo.proposed_schedule.producers.begin(), gpo.proposed_schedule.producers.end() ) )
return false; // the proposed producer schedule does not change
return -1; // the proposed producer schedule does not change
}

producer_schedule_type sch;
Expand All @@ -1249,15 +1249,17 @@ bool controller::set_proposed_producers( vector<producer_key> producers ) {
}

if( std::equal( producers.begin(), producers.end(), begin, end ) )
return false; // the producer schedule would not change
return -1; // the producer schedule would not change

sch.producers = std::move(producers);

int64_t version = sch.version;

my->db.modify( gpo, [&]( auto& gp ) {
gp.proposed_schedule_block_num = cur_block_num;
gp.proposed_schedule = std::move(sch);
});
return true;
return version;
}

const producer_schedule_type& controller::active_producers()const {
Expand Down
21 changes: 10 additions & 11 deletions libraries/chain/fork_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ namespace enumivo { namespace chain {
fc::read_file_contents( fork_db_dat, content );

fc::datastream<const char*> ds( content.data(), content.size() );
vector<block_state> states;
fc::raw::unpack( ds, states );

for( auto& s : states ) {
unsigned_int size; fc::raw::unpack( ds, size );
for( uint32_t i = 0, n = size.value; i < n; ++i ) {
block_state s;
fc::raw::unpack( ds, s );
set( std::make_shared<block_state>( move( s ) ) );
}
block_id_type head_id;
Expand All @@ -80,20 +80,19 @@ namespace enumivo { namespace chain {
if( my->index.size() == 0 ) return;

fc::datastream<size_t> ps;
vector<block_state> states;
states.reserve( my->index.size() );
for( const auto& s : my->index ) {
states.push_back( *s );
}

auto fork_db_dat = my->datadir / config::forkdb_filename;
std::ofstream out( fork_db_dat.generic_string().c_str(), std::ios::out | std::ios::binary | std::ofstream::trunc );
fc::raw::pack( out, states );
uint32_t num_blocks_in_fork_db = my->index.size();
fc::raw::pack( out, unsigned_int{num_blocks_in_fork_db} );
for( const auto& s : my->index ) {
fc::raw::pack( out, *s );
}
if( my->head )
fc::raw::pack( out, my->head->id );
else
fc::raw::pack( out, block_id_type() );
idump((states.size()));
idump((num_blocks_in_fork_db));


/// we don't normally indicate the head block as irreversible
Expand Down
6 changes: 3 additions & 3 deletions libraries/chain/include/enumivo/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ const static uint32_t default_context_free_discount_net_usage_num = 20; // TO
const static uint32_t default_context_free_discount_net_usage_den = 100;
const static uint32_t transaction_id_net_usage = 32; // 32 bytes for the size of a transaction id

const static uint32_t default_max_block_cpu_usage = 100'000; /// max block cpu usage in microseconds
const static uint32_t default_target_block_cpu_usage_pct = 5 * percent_1; /// target 1000 TPS
const static uint32_t default_max_transaction_cpu_usage = default_max_block_cpu_usage / 2; /// max trx cpu usage in microseconds
const static uint32_t default_max_block_cpu_usage = 200'000; /// max block cpu usage in microseconds
const static uint32_t default_target_block_cpu_usage_pct = percent_1; /// target 1000 TPS
const static uint32_t default_max_transaction_cpu_usage = 3*default_max_block_cpu_usage/4; /// max trx cpu usage in microseconds
const static uint32_t default_min_transaction_cpu_usage = 100; /// min trx cpu usage in microseconds (10000 TPS equiv)

const static uint32_t default_max_trx_lifetime = 60*60; // 1 hour
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/enumivo/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace enumivo { namespace chain {
void validate_expiration( const transaction& t )const;
void validate_tapos( const transaction& t )const;

bool set_proposed_producers( vector<producer_key> producers );
int64_t set_proposed_producers( vector<producer_key> producers );

bool skip_auth_check()const;

Expand Down
1 change: 1 addition & 0 deletions libraries/chain/transaction_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ namespace enumivo { namespace chain {
void transaction_context::checktime()const {
auto now = fc::time_point::now();
if( BOOST_UNLIKELY( now > _deadline ) ) {
// edump((now-start)(now-pseudo_start));
if( billed_cpu_time_us > 0 || deadline_exception_code == deadline_exception::code_value ) {
ENU_THROW( deadline_exception, "deadline exceeded", ("now", now)("deadline", _deadline)("start", start) );
} else if( deadline_exception_code == block_cpu_usage_exceeded::code_value ) {
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/wasm_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class privileged_api : public context_aware_api {
context.control.get_resource_limits_manager().get_account_limits( account, ram_bytes, net_weight, cpu_weight);
}

bool set_active_producers( array_ptr<char> packed_producer_schedule, size_t datalen) {
int64_t set_proposed_producers( array_ptr<char> packed_producer_schedule, size_t datalen) {
datastream<const char*> ds( packed_producer_schedule, datalen );
vector<producer_key> producers;
fc::raw::unpack(ds, producers);
Expand Down Expand Up @@ -1684,7 +1684,7 @@ REGISTER_INTRINSICS(privileged_api,
(activate_feature, void(int64_t) )
(get_resource_limits, void(int64_t,int,int,int) )
(set_resource_limits, void(int64_t,int64_t,int64_t,int64_t) )
(set_active_producers, int(int,int) )
(set_proposed_producers, int64_t(int,int) )
(get_blockchain_parameters_packed, int(int, int) )
(set_blockchain_parameters_packed, void(int,int) )
(is_privileged, int(int64_t) )
Expand Down
Loading

0 comments on commit a7d3fae

Please sign in to comment.