Skip to content

Commit

Permalink
Merge pull request EOSIO#203 from enumivo/staging
Browse files Browse the repository at this point in the history
104
  • Loading branch information
Enumivo authored Jun 16, 2018
2 parents bcf89ad + 063c2c0 commit e3c67c4
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set( CXX_STANDARD_REQUIRED ON)

set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_PATCH 2)
set(VERSION_PATCH 4)

set( CLI_CLIENT_EXECUTABLE_NAME enucli )
set( GUI_CLIENT_EXECUTABLE_NAME enumivo )
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ Enumivo currently supports the following operating systems:

# Resources
1. [Enumivo Website](https://enumivo.org)
2. [Enumivo Blog](https://enumivo.com/blogs/blog/4-enumivo-community-blog/)
3. [Community Telegram Group](https://t.me/enumivochat)
2. [Enumivo Forum](https://enumivo.com)
3. [Community Telegram Group](https://t.me/enumivochat)
7 changes: 6 additions & 1 deletion contracts/enu.system/delegate_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,14 @@ namespace enumivosystem {
enumivo_assert( quant.amount > 0, "must purchase a positive amount" );

auto fee = quant;
fee.amount = ( fee.amount + 199 ) / 200; /// .5% fee
fee.amount = ( fee.amount + 199 ) / 200; /// .5% fee (round up)
// fee.amount cannot be 0 since that is only possible if quant.amount is 0 which is not allowed by the assert above.
// If quant.amount == 1, then fee.amount == 1,
// otherwise if quant.amount > 1, then 0 < fee.amount < quant.amount.
auto quant_after_fee = quant;
quant_after_fee.amount -= fee.amount;
// quant_after_fee.amount should be > 0 if quant.amount > 1.
// If quant.amount == 1, then quant_after_fee.amount == 0 and the next inline transfer will fail causing the buyram action to fail.

INLINE_ACTION_SENDER(enumivo::token, transfer)( N(enu.token), {payer,N(active)},
{ payer, N(enu.ram), quant_after_fee, std::string("buy ram") } );
Expand Down
5 changes: 1 addition & 4 deletions contracts/enu.system/enu.system.abi
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,7 @@
{"name":"staked", "type":"int64"},
{"name":"last_vote_weight", "type":"float64"},
{"name":"proxied_vote_weight", "type":"float64"},
{"name":"is_proxy", "type":"bool"},
{"name":"deferred_trx_id", "type":"uint32"},
{"name":"last_unstake_time", "type":"time_point_sec"},
{"name":"unstaking", "type":"asset"}
{"name":"is_proxy", "type":"bool"}
]
},{
"name": "claimrewards",
Expand Down
8 changes: 4 additions & 4 deletions contracts/enu.system/enu.system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ namespace enumivosystem {
bool is_proxy = 0; /// whether the voter is a proxy for others


uint32_t deferred_trx_id = 0; /// the ID of the 3-day delay deferred transaction
time last_unstake_time = 0; /// the time when the deferred_trx_id was sent
enumivo::asset unstaking; /// the total unstaking (pending 3 day delay)
uint32_t reserved1 = 0;
time reserved2 = 0;
enumivo::asset reserved3;

uint64_t primary_key()const { return owner; }

// explicit serialization macro is not necessary, used here only to improve compilation time
ENULIB_SERIALIZE( voter_info, (owner)(proxy)(producers)(staked)(last_vote_weight)(proxied_vote_weight)(is_proxy)(deferred_trx_id)(last_unstake_time)(unstaking) )
ENULIB_SERIALIZE( voter_info, (owner)(proxy)(producers)(staked)(last_vote_weight)(proxied_vote_weight)(is_proxy)(reserved1)(reserved2)(reserved3) )
};

typedef enumivo::multi_index< N(voters), voter_info> voters_table;
Expand Down
46 changes: 41 additions & 5 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ namespace enumivo {

shared_ptr<tcp::resolver> resolver;

bool use_socket_read_watermark = false;

channels::transaction_ack::channel_type::handle incoming_transaction_ack_subscription;

void connect( connection_ptr c );
Expand Down Expand Up @@ -489,6 +491,7 @@ namespace enumivo {
socket_ptr socket;

fc::message_buffer<1024*1024> pending_message_buffer;
fc::optional<std::size_t> outstanding_read_bytes;
vector<char> blk_buffer;

struct queued_write {
Expand Down Expand Up @@ -2106,14 +2109,34 @@ namespace enumivo {
return;
}
connection_wptr weak_conn = conn;
conn->socket->async_read_some
(conn->pending_message_buffer.get_buffer_sequence_for_boost_async_read(),
[this,weak_conn]( boost::system::error_code ec, std::size_t bytes_transferred ) {

std::size_t minimum_read = conn->outstanding_read_bytes ? *conn->outstanding_read_bytes : message_header_size;

if (use_socket_read_watermark) {
const size_t max_socket_read_watermark = 4096;
std::size_t socket_read_watermark = std::min<std::size_t>(minimum_read, max_socket_read_watermark);
boost::asio::socket_base::receive_low_watermark read_watermark_opt(socket_read_watermark);
conn->socket->set_option(read_watermark_opt);
}

auto completion_handler = [minimum_read](boost::system::error_code ec, std::size_t bytes_transferred) -> std::size_t {
if (ec || bytes_transferred >= minimum_read ) {
return 0;
} else {
return minimum_read - bytes_transferred;
}
};

boost::asio::async_read(*conn->socket,
conn->pending_message_buffer.get_buffer_sequence_for_boost_async_read(), completion_handler,
[this,weak_conn]( boost::system::error_code ec, std::size_t bytes_transferred ) {
auto conn = weak_conn.lock();
if (!conn) {
return;
}

conn->outstanding_read_bytes.reset();

try {
if( !ec ) {
if (bytes_transferred > conn->pending_message_buffer.bytes_to_write()) {
Expand All @@ -2126,6 +2149,7 @@ namespace enumivo {
uint32_t bytes_in_buffer = conn->pending_message_buffer.bytes_to_read();

if (bytes_in_buffer < message_header_size) {
conn->outstanding_read_bytes.emplace(message_header_size - bytes_in_buffer);
break;
} else {
uint32_t message_length;
Expand All @@ -2136,13 +2160,22 @@ namespace enumivo {
close(conn);
return;
}
if (bytes_in_buffer >= message_length + message_header_size) {

auto total_message_bytes = message_length + message_header_size;

if (bytes_in_buffer >= total_message_bytes) {
conn->pending_message_buffer.advance_read_ptr(message_header_size);
if (!conn->process_next_message(*this, message_length)) {
return;
}
} else {
conn->pending_message_buffer.add_space(message_length + message_header_size - bytes_in_buffer);
auto outstanding_message_bytes = total_message_bytes - bytes_in_buffer;
auto available_buffer_bytes = conn->pending_message_buffer.bytes_to_write();
if (outstanding_message_bytes > available_buffer_bytes) {
conn->pending_message_buffer.add_space( outstanding_message_bytes - available_buffer_bytes );
}

conn->outstanding_read_bytes.emplace(outstanding_message_bytes);
break;
}
}
Expand Down Expand Up @@ -2891,6 +2924,7 @@ namespace enumivo {
"True to require exact match of peer network version.")
( "sync-fetch-span", bpo::value<uint32_t>()->default_value(def_sync_fetch_span), "number of blocks to retrieve in a chunk from any individual peer during synchronization")
( "max-implicit-request", bpo::value<uint32_t>()->default_value(def_max_just_send), "maximum sizes of transaction or block messages that are sent without first sending a notice")
( "use-socket-read-watermark", bpo::value<bool>()->default_value(false), "Enable expirimental socket read watermark optimization")
( "peer-log-format", bpo::value<string>()->default_value( "[\"${_name}\" ${_ip}:${_port}]" ),
"The string used to format peers when logging messages about them. Variables are escaped with ${<variable name>}.\n"
"Available Variables:\n"
Expand Down Expand Up @@ -2927,6 +2961,8 @@ namespace enumivo {
my->num_clients = 0;
my->started_sessions = 0;

my->use_socket_read_watermark = options.at("use-socket-read-watermark").as<bool>();

my->resolver = std::make_shared<tcp::resolver>( std::ref( app().get_io_service() ) );
if(options.count("p2p-listen-endpoint")) {
my->p2p_address = options.at("p2p-listen-endpoint").as< string >();
Expand Down
2 changes: 1 addition & 1 deletion plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() {
continue;
}

if (trx->packed_trx.expiration() > pbs->header.timestamp.to_time_point()) {
if (trx->packed_trx.expiration() < pbs->header.timestamp.to_time_point()) {
// expired, drop it
chain.drop_unapplied_transaction(trx);
continue;
Expand Down
40 changes: 35 additions & 5 deletions programs/enucli/help_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,38 @@ auto smatch_to_variant(const std::smatch& smatch) {
const char* error_advice_name_type_exception = R"=====(Name should be less than 13 characters and only contains the following symbol .12345abcdefghijklmnopqrstuvwxyz)=====";
const char* error_advice_public_key_type_exception = R"=====(Public key should be encoded in base58 and starts with ENU prefix)=====";
const char* error_advice_private_key_type_exception = R"=====(Private key should be encoded in base58 WIF)=====";
const char* error_advice_authority_type_exception = R"=====(Ensure that your authority JSON follows the right authority structure!
You can refer to contracts/enulib/native.hpp for reference)=====";
const char* error_advice_authority_type_exception = R"=====(Ensure that your authority JSON is valid follows the following format!
{
"threshold": <INTEGER [1-2^32): the threshold that must be met to satisfy this authority>,
"keys": [ <keys must be alpha-numerically sorted by their string representations and unique>
...
{
"key": <STRING: Enumivo compatible Public Key>,
"weight": <INTEGER [1-2^16): a signature from this key contributes this to satisfying the threshold>
}
...
],
"accounts": [ <accounts must be alpha-numerically sorted by their permission (actor, then permission) and unique>
...
{
"permission": {
"actor": <STRING: account name of the delegated signer>,
"permission": <STRING: permission level on the account that must be satisfied>,
},
"weight": <INTEGER [1-2^16): satisfying the delegation contributes this to satisfying the threshold>
}
...
],
"waits": [ <waits must be sorted by wait_sec, largest first, and be unique>
...
{
"wait_sec": <INTEGER [1-2^32): seconds of delay which qualifies as passing this wait>
"weight": <INTEGER [1-2^16): satisfying the delay contributes this to satisfying the threshold>
}
...
]
}
)=====";
const char* error_advice_action_type_exception = R"=====(Ensure that your action JSON follows the contract's abi!)=====";
const char* error_advice_transaction_type_exception = R"=====(Ensure that your transaction JSON follows the right transaction format!
You can refer to contracts/enulib/transaction.hpp for reference)=====";
Expand Down Expand Up @@ -212,12 +242,12 @@ const std::map<int64_t, std::string> error_advice = {
{ account_query_exception::code_value, error_advice_account_query_exception },
{ contract_table_query_exception::code_value, error_advice_contract_table_query_exception },
{ contract_query_exception::code_value, error_advice_contract_query_exception },

{ tx_irrelevant_sig::code_value, error_advice_tx_irrelevant_sig },
{ unsatisfied_authorization::code_value, error_advice_unsatisfied_authorization },
{ missing_auth_exception::code_value, error_advice_missing_auth_exception },
{ irrelevant_auth_exception::code_value, error_advice_irrelevant_auth_exception },

{ missing_chain_api_plugin_exception::code_value, error_advice_missing_chain_api_plugin_exception },
{ missing_wallet_api_plugin_exception::code_value, error_advice_missing_wallet_api_plugin_exception },
{ missing_history_api_plugin_exception::code_value, error_advice_missing_history_api_plugin_exception },
Expand All @@ -234,7 +264,7 @@ const std::map<int64_t, std::string> error_advice = {
namespace enumivo { namespace client { namespace help {

bool print_recognized_errors(const fc::exception& e, const bool verbose_errors) {
// enu recognized error code is from 3000000
// enu recognized error code is from 3000000
// refer to libraries/chain/include/enumivo/chain/exceptions.hpp
if (e.code() >= chain_exception::code_value) {
std::string advice, explanation, stack_trace;
Expand Down
11 changes: 4 additions & 7 deletions programs/enucli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ FC_DECLARE_EXCEPTION( localized_exception, 10000000, "an error occured" );

string url = "http://localhost:8888/";
string wallet_url = "http://localhost:8900/";
int64_t wallet_unlock_timeout = 0;
bool no_verify = false;
vector<string> headers;

Expand Down Expand Up @@ -554,7 +553,9 @@ authority parse_json_authority_or_key(const std::string& authorityJsonOrFile) {
return authority(public_key_type(authorityJsonOrFile));
} ENU_RETHROW_EXCEPTIONS(public_key_type_exception, "Invalid public key: ${public_key}", ("public_key", authorityJsonOrFile))
} else {
return parse_json_authority(authorityJsonOrFile);
auto result = parse_json_authority(authorityJsonOrFile);
ENU_ASSERT( enumivo::chain::validate(result), authority_type_exception, "Authority failed validation! ensure that keys, accounts, and waits are sorted and that the threshold is valid and satisfiable!");
return result;
}
}

Expand Down Expand Up @@ -714,7 +715,7 @@ void ensure_enuwallet_running(CLI::App* app) {
if (app->get_subcommand("create")->got_subcommand("key")) // create key does not require wallet
return;
if (auto* subapp = app->get_subcommand("system")) {
if (subapp->got_subcommand("listproducers") || subapp->got_subcommand("listbw")) // system list* do not require wallet
if (subapp->got_subcommand("listproducers") || subapp->got_subcommand("listbw") || subapp->got_subcommand("bidnameinfo")) // system list* do not require wallet
return;
}

Expand Down Expand Up @@ -745,9 +746,6 @@ void ensure_enuwallet_running(CLI::App* app) {

vector<std::string> pargs;
pargs.push_back("--http-server-address=" + lo_address + ":" + std::to_string(resolved_url.resolved_port));
if (wallet_unlock_timeout > 0) {
pargs.push_back("--unlock-timeout=" + fc::to_string(wallet_unlock_timeout));
}

::boost::process::child enuwallet(binPath, pargs,
bp::std_in.close(),
Expand Down Expand Up @@ -2183,7 +2181,6 @@ int main( int argc, char** argv ) {
auto unlockWallet = wallet->add_subcommand("unlock", localized("Unlock wallet"), false);
unlockWallet->add_option("-n,--name", wallet_name, localized("The name of the wallet to unlock"));
unlockWallet->add_option("--password", wallet_pw, localized("The password returned by wallet create"));
unlockWallet->add_option( "--unlock-timeout", wallet_unlock_timeout, localized("The timeout for unlocked wallet in seconds"));
unlockWallet->set_callback([&wallet_name, &wallet_pw] {
if( wallet_pw.size() == 0 ) {
std::cout << localized("password: ");
Expand Down
3 changes: 0 additions & 3 deletions unittests/enu_system_tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,6 @@ inline fc::mutable_variant_object voter( account_name acct ) {
//("last_vote_weight", double(0))
("proxied_vote_weight", double(0))
("is_proxy", 0)
("deferred_trx_id", 0)
("last_unstake_time", fc::time_point_sec() )
("unstaking", asset() )
;
}

Expand Down

0 comments on commit e3c67c4

Please sign in to comment.