Skip to content

Commit

Permalink
Merge pull request EOSIO#112 from enumivo/staging
Browse files Browse the repository at this point in the history
merge eosio master
  • Loading branch information
Enumivo authored May 16, 2018
2 parents d6e5248 + 8bd56a9 commit b7bc86e
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 163 deletions.
2 changes: 1 addition & 1 deletion Docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ docker volume rm enuwallet-data-volume
### Docker Hub

Docker Hub image available from [docker hub](https://hub.docker.com/r/eosio/eos/).
Replace the `docker-compose.yaml` file with the content below
Create a new `docker-compose.yaml` file with the content below

```bash
version: "3"
Expand Down
8 changes: 1 addition & 7 deletions contracts/enumivo.system/enumivo.system.abi
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,7 @@
{"name":"max_block_cpu_usage", "type": "uint64"},
{"name":"target_block_cpu_usage_pct", "type": "uint32"},
{"name":"max_transaction_cpu_usage", "type":"uint32"},
{"name":"base_per_transaction_cpu_usage", "type":"uint32"},
{"name":"base_per_action_cpu_usage", "type":"uint32"},
{"name":"base_setcode_cpu_usage", "type":"uint32"},
{"name":"per_signature_cpu_usage", "type":"uint32"},
{"name":"cpu_usage_leeway", "type":"uint32"},
{"name":"context_free_discount_cpu_usage_num", "type":"uint32"},
{"name":"context_free_discount_cpu_usage_den", "type":"uint32"},
{"name":"min_transaction_cpu_usage", "type":"uint32"},
{"name":"max_transaction_lifetime", "type":"uint32"},
{"name":"deferred_trx_expiration_window", "type":"uint32"},
{"name":"max_transaction_delay", "type":"uint32"},
Expand Down
12 changes: 2 additions & 10 deletions contracts/enumivolib/privileged.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ namespace eosio {
uint32_t max_block_cpu_usage;
uint32_t target_block_cpu_usage_pct;
uint32_t max_transaction_cpu_usage;
uint32_t base_per_transaction_cpu_usage;
uint32_t base_per_action_cpu_usage;
uint32_t base_setcode_cpu_usage;
uint32_t per_signature_cpu_usage;
uint32_t cpu_usage_leeway;
uint32_t context_free_discount_cpu_usage_num;
uint32_t context_free_discount_cpu_usage_den;
uint32_t min_transaction_cpu_usage;

uint32_t max_transaction_lifetime;
uint32_t deferred_trx_expiration_window;
Expand All @@ -39,9 +33,7 @@ namespace eosio {
(context_free_discount_net_usage_num)(context_free_discount_net_usage_den)

(max_block_cpu_usage)(target_block_cpu_usage_pct)
(max_transaction_cpu_usage)(base_per_transaction_cpu_usage)
(base_per_action_cpu_usage)(base_setcode_cpu_usage)(per_signature_cpu_usage)(cpu_usage_leeway)
(context_free_discount_cpu_usage_num)(context_free_discount_cpu_usage_den)
(max_transaction_cpu_usage)(min_transaction_cpu_usage)

(max_transaction_lifetime)(deferred_trx_expiration_window)(max_transaction_delay)
(max_inline_action_size)(max_inline_action_depth)
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ struct controller_impl {

try {
auto onbtrx = std::make_shared<transaction_metadata>( get_on_block_transaction() );
push_transaction( onbtrx, fc::time_point::maximum(), true, config::default_min_transaction_cpu_usage_us);
push_transaction( onbtrx, fc::time_point::maximum(), true, self.get_global_properties().configuration.min_transaction_cpu_usage );
} catch ( ... ) {
ilog( "on block transaction failed, but shouldn't impact block generation, system contract needs update" );
}
Expand Down
23 changes: 5 additions & 18 deletions libraries/chain/include/enumivo/chain/chain_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,10 @@ struct chain_config {
uint32_t context_free_discount_net_usage_num; ///< the numerator for the discount on net usage of context-free data
uint32_t context_free_discount_net_usage_den; ///< the denominator for the discount on net usage of context-free data

uint32_t max_block_cpu_usage; ///< the maxiumum cpu usage in instructions for a block
uint32_t max_block_cpu_usage; ///< the maxiumum billable cpu usage (in microseconds) for a block
uint32_t target_block_cpu_usage_pct; ///< the target percent (1% == 100, 100%= 10,000) of maximum cpu usage; exceeding this triggers congestion handling
uint32_t max_transaction_cpu_usage; ///< the maximum objectively measured cpu usage that the chain will allow regardless of account limits
uint32_t base_per_transaction_cpu_usage; ///< the base amount of cpu usage billed for a transaction to cover incidentals
uint32_t base_per_action_cpu_usage; ///< the base amount of cpu usage billed for an action to cover incidentals
uint32_t base_setcode_cpu_usage; ///< the base amount of cpu usage billed for a setcode action to cover compilation/etc
uint32_t per_signature_cpu_usage; ///< the cpu usage billed for every signature on a transaction
uint32_t cpu_usage_leeway;
uint32_t context_free_discount_cpu_usage_num; ///< the numerator for the discount on cpu usage of context-free actions
uint32_t context_free_discount_cpu_usage_den; ///< the denominator for the discount on cpu usage of context-free actions
uint32_t max_transaction_cpu_usage; ///< the maximum billable cpu usage (in microseconds) that the chain will allow regardless of account limits
uint32_t min_transaction_cpu_usage; ///< the minimum billable cpu usage (in microseconds) that the chain requires

uint32_t max_transaction_lifetime; ///< the maximum number of seconds that an input transaction's expiration can be ahead of the time of the block in which it is first included
uint32_t deferred_trx_expiration_window; ///< the number of seconds after the time a deferred transaction can first execute until it expires
Expand All @@ -56,12 +50,7 @@ struct chain_config {
<< "Max Block CPU Usage: " << c.max_block_cpu_usage << ", "
<< "Target Block CPU Usage Percent: " << ((double)c.target_block_cpu_usage_pct / (double)config::percent_1) << "%, "
<< "Max Transaction CPU Usage: " << c.max_transaction_cpu_usage << ", "
<< "Base Per-Transaction CPU Usage: " << c.base_per_transaction_cpu_usage << ", "
<< "Base Per-Action CPU Usage: " << c.base_per_action_cpu_usage << ", "
<< "Base Setcode CPU Usage: " << c.base_setcode_cpu_usage << ", "
<< "Per-Signature CPU Usage: " << c.per_signature_cpu_usage << ", "
<< "CPU Usage Leeway: " << c.cpu_usage_leeway << ", "
<< "Context-Free Action CPU Usage Discount: " << (double)c.context_free_discount_cpu_usage_num * 100.0 / (double)c.context_free_discount_cpu_usage_den << "% , "
<< "Min Transaction CPU Usage: " << c.min_transaction_cpu_usage << ", "

<< "Max Transaction Lifetime: " << c.max_transaction_lifetime << ", "
<< "Deferred Transaction Expiration Window: " << c.deferred_trx_expiration_window << ", "
Expand All @@ -84,9 +73,7 @@ FC_REFLECT(eosio::chain::chain_config,
(context_free_discount_net_usage_num)(context_free_discount_net_usage_den)

(max_block_cpu_usage)(target_block_cpu_usage_pct)
(max_transaction_cpu_usage)(base_per_transaction_cpu_usage)
(base_per_action_cpu_usage)(base_setcode_cpu_usage)(per_signature_cpu_usage)(cpu_usage_leeway)
(context_free_discount_cpu_usage_num)(context_free_discount_cpu_usage_den)
(max_transaction_cpu_usage)(min_transaction_cpu_usage)

(max_transaction_lifetime)(deferred_trx_expiration_window)(max_transaction_delay)
(max_inline_action_size)(max_inline_action_depth)
Expand Down
18 changes: 2 additions & 16 deletions libraries/chain/include/enumivo/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,17 @@ const static uint32_t transaction_id_net_usage = 32; // 32

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;
const static uint32_t default_min_transaction_cpu_usage_us = 100; /// 10000 TPS equiv
const static uint32_t default_base_per_transaction_cpu_usage = 512; // TODO: is this reasonable?
const static uint32_t default_base_per_action_cpu_usage = 1024;
const static uint32_t default_base_setcode_cpu_usage = 2 * 1024 * 1024; /// overbilling cpu usage for setcode to cover incidental
const static uint32_t default_per_signature_cpu_usage = 100 * 1024; // TODO: is this reasonable?
const static uint32_t default_cpu_usage_leeway = 2048; // TODO: is this reasonable?
const static uint32_t default_context_free_discount_cpu_usage_num = 20;
const static uint32_t default_context_free_discount_cpu_usage_den = 100;
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_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
const static uint32_t default_deferred_trx_expiration_window = 10*60; // 10 minutes
//static const uint32_t deferred_trx_expiration_window_ms = 10*60*1000l; // TODO: make 10 minutes configurable by system
const static uint32_t default_max_trx_delay = 45*24*3600; // 45 days
const static uint32_t default_max_inline_action_size = 4 * 1024; // 4 KB
const static uint16_t default_max_inline_action_depth = 4;
const static uint16_t default_max_auth_depth = 6;
const static uint32_t default_max_gen_trx_count = 16;

const static uint32_t base_check_authorization_cpu_per_authorization = 64; // TODO: is this reasonable?
const static uint32_t base_authority_checker_cpu_per_permission = 128; // TODO: is this reasonable?
const static uint32_t resource_processing_cpu_overhead_per_billed_account = 256; // TODO: is this reasonable?
const static uint32_t determine_payers_cpu_overhead_per_authorization = 64; // TODO: is this reasonable?
const static uint32_t ram_usage_validation_overhead_per_account = 64; // TODO: is this reasonable?

const static uint32_t fixed_net_overhead_of_packed_trx = 16; // TODO: is this reasonable?

const static uint32_t fixed_overhead_shared_vector_ram_bytes = 16; ///< overhead accounts for fixed portion of size of shared_vector field
Expand Down
8 changes: 1 addition & 7 deletions libraries/chain/include/enumivo/chain/genesis_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@ struct genesis_state {
.max_block_cpu_usage = config::default_max_block_cpu_usage,
.target_block_cpu_usage_pct = config::default_target_block_cpu_usage_pct,
.max_transaction_cpu_usage = config::default_max_transaction_cpu_usage,
.base_per_transaction_cpu_usage = config::default_base_per_transaction_cpu_usage,
.base_per_action_cpu_usage = config::default_base_per_action_cpu_usage,
.base_setcode_cpu_usage = config::default_base_setcode_cpu_usage,
.per_signature_cpu_usage = config::default_per_signature_cpu_usage,
.cpu_usage_leeway = config::default_cpu_usage_leeway,
.context_free_discount_cpu_usage_num = config::default_context_free_discount_cpu_usage_num,
.context_free_discount_cpu_usage_den = config::default_context_free_discount_cpu_usage_den,
.min_transaction_cpu_usage = config::default_min_transaction_cpu_usage,

.max_transaction_lifetime = config::default_max_trx_lifetime,
.deferred_trx_expiration_window = config::default_deferred_trx_expiration_window,
Expand Down
10 changes: 9 additions & 1 deletion libraries/chain/include/enumivo/chain/transaction_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ namespace eosio { namespace chain {
inline void add_net_usage( uint64_t u ) { net_usage += u; check_net_usage(); }

void check_net_usage()const;

void checktime()const;

void pause_billing_timer();
void resume_billing_timer();

void add_ram_usage( account_name account, int64_t ram_delta );

private:
Expand Down Expand Up @@ -86,8 +90,12 @@ namespace eosio { namespace chain {
uint64_t& net_usage; /// reference to trace->net_usage

fc::microseconds objective_duration_limit;
bool objective_duration_limit_due_to_block = true;
fc::time_point _deadline = fc::time_point::maximum();
int64_t deadline_exception_code = block_cpu_usage_exceeded::code_value;
int64_t billing_timer_exception_code = block_cpu_usage_exceeded::code_value;
fc::time_point pseudo_start;
fc::microseconds billed_time;
fc::microseconds billing_timer_duration_limit;
};

} }
10 changes: 8 additions & 2 deletions libraries/chain/include/enumivo/chain/wasm_interface_private.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <enumivo/chain/webassembly/binaryen.hpp>
#include <enumivo/chain/webassembly/runtime_interface.hpp>
#include <enumivo/chain/wasm_eosio_injection.hpp>
#include <enumivo/chain/transaction_context.hpp>

#include "IR/Module.h"
#include "Runtime/Intrinsics.h"
Expand All @@ -28,7 +29,7 @@ namespace eosio { namespace chain {
else
FC_THROW("wasm_interface_impl fall through");
}

std::vector<uint8_t> parse_initial_memory(const Module& module) {
std::vector<uint8_t> mem_image;

Expand All @@ -47,9 +48,13 @@ namespace eosio { namespace chain {
return mem_image;
}

std::unique_ptr<wasm_instantiated_module_interface>& get_instantiated_module(const digest_type& code_id, const shared_string& code) {
std::unique_ptr<wasm_instantiated_module_interface>& get_instantiated_module( const digest_type& code_id,
const shared_string& code,
transaction_context& trx_context )
{
auto it = instantiation_cache.find(code_id);
if(it == instantiation_cache.end()) {
trx_context.pause_billing_timer();
IR::Module module;
try {
Serialization::MemoryInputStream stream((const U8*)code.data(), code.size());
Expand All @@ -70,6 +75,7 @@ namespace eosio { namespace chain {
ENU_ASSERT(false, wasm_serialization_error, e.message.c_str());
}
it = instantiation_cache.emplace(code_id, runtime_interface->instantiate_module((const char*)bytes.data(), bytes.size(), parse_initial_memory(module))).first;
trx_context.resume_billing_timer();
}
return it->second;
}
Expand Down
Loading

0 comments on commit b7bc86e

Please sign in to comment.