未验证 提交 2877bd76 编写于 作者: A arhag 提交者: GitHub

Merge pull request #3340 from EOSIO/contracts-console

chain_plugin parameter --contracts-console added #3339
......@@ -16,18 +16,16 @@ using boost::container::flat_set;
namespace eosio { namespace chain {
static inline void print_debug(account_name receiver, const action_trace& ar) {
if(fc::logger::get(DEFAULT_LOGGER).is_enabled(fc::log_level::debug)) {
if (!ar.console.empty()) {
auto prefix = fc::format_string(
"\n[(${a},${n})->${r}]",
fc::mutable_variant_object()
("a", ar.act.account)
("n", ar.act.name)
("r", receiver));
dlog(prefix + ": CONSOLE OUTPUT BEGIN =====================\n"
+ ar.console
+ prefix + ": CONSOLE OUTPUT END =====================" );
}
if (!ar.console.empty()) {
auto prefix = fc::format_string(
"\n[(${a},${n})->${r}]",
fc::mutable_variant_object()
("a", ar.act.account)
("n", ar.act.name)
("r", receiver));
dlog(prefix + ": CONSOLE OUTPUT BEGIN =====================\n"
+ ar.console
+ prefix + ": CONSOLE OUTPUT END =====================" );
}
}
......@@ -75,7 +73,9 @@ action_trace apply_context::exec_one()
trx_context.executed.emplace_back( move(r) );
print_debug(receiver, t);
if ( control.contracts_console() ) {
print_debug(receiver, t);
}
reset_console();
......
......@@ -1283,6 +1283,10 @@ bool controller::skip_auth_check()const {
return my->replaying_irreversible && !my->conf.force_all_checks;
}
bool controller::contracts_console()const {
return my->conf.contracts_console;
}
const apply_handler* controller::find_apply_handler( account_name receiver, account_name scope, action_name act ) const
{
auto native_handler_scope = my->apply_handlers.find( receiver );
......
......@@ -42,6 +42,7 @@ namespace eosio { namespace chain {
uint64_t reversible_cache_size = chain::config::default_reversible_cache_size;
bool read_only = false;
bool force_all_checks = false;
bool contracts_console = false;
genesis_state genesis;
wasm_interface::vm_type wasm_runtime = chain::config::default_wasm_runtime;
......@@ -151,6 +152,7 @@ namespace eosio { namespace chain {
bool skip_auth_check()const;
bool contracts_console()const;
signal<void(const block_state_ptr&)> accepted_block_header;
signal<void(const block_state_ptr&)> accepted_block;
......@@ -208,6 +210,7 @@ FC_REFLECT( eosio::chain::controller::config,
(reversible_cache_size)
(read_only)
(force_all_checks)
(contracts_console)
(genesis)
(wasm_runtime)
)
......@@ -977,68 +977,85 @@ class action_api : public context_aware_api {
class console_api : public context_aware_api {
public:
console_api( apply_context& ctx )
:context_aware_api(ctx,true){}
: context_aware_api(ctx,true)
, ignore(!ctx.control.contracts_console()) {}
// Kept as intrinsic rather than implementing on WASM side (using prints_l and strlen) because strlen is faster on native side.
void prints(null_terminated_ptr str) {
context.console_append<const char*>(str);
if ( !ignore ) {
context.console_append<const char*>(str);
}
}
void prints_l(array_ptr<const char> str, size_t str_len ) {
context.console_append(string(str, str_len));
if ( !ignore ) {
context.console_append(string(str, str_len));
}
}
void printi(int64_t val) {
context.console_append(val);
if ( !ignore ) {
context.console_append(val);
}
}
void printui(uint64_t val) {
context.console_append(val);
if ( !ignore ) {
context.console_append(val);
}
}
void printi128(const __int128& val) {
bool is_negative = (val < 0);
unsigned __int128 val_magnitude;
if ( !ignore ) {
bool is_negative = (val < 0);
unsigned __int128 val_magnitude;
if( is_negative )
val_magnitude = static_cast<unsigned __int128>(-val); // Works even if val is at the lowest possible value of a int128_t
else
val_magnitude = static_cast<unsigned __int128>(val);
if( is_negative )
val_magnitude = static_cast<unsigned __int128>(-val); // Works even if val is at the lowest possible value of a int128_t
else
val_magnitude = static_cast<unsigned __int128>(val);
fc::uint128_t v(val_magnitude>>64, static_cast<uint64_t>(val_magnitude) );
fc::uint128_t v(val_magnitude>>64, static_cast<uint64_t>(val_magnitude) );
if( is_negative ) {
context.console_append("-");
}
if( is_negative ) {
context.console_append("-");
}
context.console_append(fc::variant(v).get_string());
context.console_append(fc::variant(v).get_string());
}
}
void printui128(const unsigned __int128& val) {
fc::uint128_t v(val>>64, static_cast<uint64_t>(val) );
context.console_append(fc::variant(v).get_string());
if ( !ignore ) {
fc::uint128_t v(val>>64, static_cast<uint64_t>(val) );
context.console_append(fc::variant(v).get_string());
}
}
void printsf( float val ) {
// Assumes float representation on native side is the same as on the WASM side
auto& console = context.get_console_stream();
auto orig_prec = console.precision();
if ( !ignore ) {
// Assumes float representation on native side is the same as on the WASM side
auto& console = context.get_console_stream();
auto orig_prec = console.precision();
console.precision( std::numeric_limits<float>::digits10 );
context.console_append(val);
console.precision( std::numeric_limits<float>::digits10 );
context.console_append(val);
console.precision( orig_prec );
console.precision( orig_prec );
}
}
void printdf( double val ) {
// Assumes double representation on native side is the same as on the WASM side
auto& console = context.get_console_stream();
auto orig_prec = console.precision();
if ( !ignore ) {
// Assumes double representation on native side is the same as on the WASM side
auto& console = context.get_console_stream();
auto orig_prec = console.precision();
console.precision( std::numeric_limits<double>::digits10 );
context.console_append(val);
console.precision( std::numeric_limits<double>::digits10 );
context.console_append(val);
console.precision( orig_prec );
console.precision( orig_prec );
}
}
void printqf( const float128_t& val ) {
......@@ -1054,25 +1071,34 @@ class console_api : public context_aware_api {
* having to deal with long doubles at all.
*/
auto& console = context.get_console_stream();
auto orig_prec = console.precision();
if ( !ignore ) {
auto& console = context.get_console_stream();
auto orig_prec = console.precision();
console.precision( std::numeric_limits<long double>::digits10 );
console.precision( std::numeric_limits<long double>::digits10 );
extFloat80_t val_approx;
f128M_to_extF80M(&val, &val_approx);
context.console_append( *(long double*)(&val_approx) );
extFloat80_t val_approx;
f128M_to_extF80M(&val, &val_approx);
context.console_append( *(long double*)(&val_approx) );
console.precision( orig_prec );
console.precision( orig_prec );
}
}
void printn(const name& value) {
context.console_append(value.to_string());
if ( !ignore ) {
context.console_append(value.to_string());
}
}
void printhex(array_ptr<const char> data, size_t data_len ) {
context.console_append(fc::to_hex(data, data_len));
if ( !ignore ) {
context.console_append(fc::to_hex(data, data_len));
}
}
private:
bool ignore;
};
#define DB_API_METHOD_WRAPPERS_SIMPLE_SECONDARY(IDX, TYPE)\
......
......@@ -314,6 +314,7 @@ namespace eosio { namespace testing {
vcfg.state_dir = tempdir.path() / std::string("v_").append(config::default_state_dir_name);
vcfg.state_size = 1024*1024*8;
vcfg.reversible_cache_size = 1024*1024*8;
vcfg.contracts_console = false;
vcfg.genesis.initial_timestamp = fc::time_point::from_iso_string("2020-01-01T00:00:00.000");
vcfg.genesis.initial_key = get_public_key( config::system_account_name, "active" );
......
......@@ -41,6 +41,7 @@ namespace eosio { namespace testing {
cfg.state_dir = tempdir.path() / config::default_state_dir_name;
cfg.state_size = 1024*1024*8;
cfg.reversible_cache_size = 1024*1024*8;
cfg.contracts_console = true;
cfg.genesis.initial_timestamp = fc::time_point::from_iso_string("2020-01-01T00:00:00.000");
cfg.genesis.initial_key = get_public_key( config::system_account_name, "active" );
......
......@@ -140,6 +140,8 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip
"clear chain state database, recover as many blocks as possible from the block log, and then replay those blocks")
("delete-all-blocks", bpo::bool_switch()->default_value(false),
"clear chain state database and block log")
("contracts-console", bpo::bool_switch()->default_value(false),
"print contract's output to console")
;
}
......@@ -204,7 +206,8 @@ void chain_plugin::plugin_initialize(const variables_map& options) {
if( my->wasm_runtime )
my->chain_config->wasm_runtime = *my->wasm_runtime;
my->chain_config->force_all_checks = options.at("force-all-checks").as<bool>();
my->chain_config->force_all_checks = options.at("force-all-checks").as<bool>();
my->chain_config->contracts_console = options.at("contracts-console").as<bool>();
if( options.at("delete-all-blocks").as<bool>() ) {
ilog("Deleting state database and blocks");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册