提交 4ac9898f 编写于 作者: A Anton Perkov

chain_plugin parameter --contracts-console added #3339

上级 2ca45172
...@@ -16,18 +16,16 @@ using boost::container::flat_set; ...@@ -16,18 +16,16 @@ using boost::container::flat_set;
namespace eosio { namespace chain { namespace eosio { namespace chain {
static inline void print_debug(account_name receiver, const action_trace& ar) { 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()) {
if (!ar.console.empty()) { auto prefix = fc::format_string(
auto prefix = fc::format_string( "\n[(${a},${n})->${r}]",
"\n[(${a},${n})->${r}]", fc::mutable_variant_object()
fc::mutable_variant_object() ("a", ar.act.account)
("a", ar.act.account) ("n", ar.act.name)
("n", ar.act.name) ("r", receiver));
("r", receiver)); dlog(prefix + ": CONSOLE OUTPUT BEGIN =====================\n"
dlog(prefix + ": CONSOLE OUTPUT BEGIN =====================\n" + ar.console
+ ar.console + prefix + ": CONSOLE OUTPUT END =====================" );
+ prefix + ": CONSOLE OUTPUT END =====================" );
}
} }
} }
...@@ -75,7 +73,9 @@ action_trace apply_context::exec_one() ...@@ -75,7 +73,9 @@ action_trace apply_context::exec_one()
trx_context.executed.emplace_back( move(r) ); trx_context.executed.emplace_back( move(r) );
print_debug(receiver, t); if ( control.contracts_console() ) {
print_debug(receiver, t);
}
reset_console(); reset_console();
......
...@@ -1283,6 +1283,10 @@ bool controller::skip_auth_check()const { ...@@ -1283,6 +1283,10 @@ bool controller::skip_auth_check()const {
return my->replaying_irreversible && !my->conf.force_all_checks; 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 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 ); auto native_handler_scope = my->apply_handlers.find( receiver );
......
...@@ -42,6 +42,7 @@ namespace eosio { namespace chain { ...@@ -42,6 +42,7 @@ namespace eosio { namespace chain {
uint64_t shared_memory_size = chain::config::default_shared_memory_size; uint64_t shared_memory_size = chain::config::default_shared_memory_size;
bool read_only = false; bool read_only = false;
bool force_all_checks = false; bool force_all_checks = false;
bool contracts_console = false;
genesis_state genesis; genesis_state genesis;
wasm_interface::vm_type wasm_runtime = chain::config::default_wasm_runtime; wasm_interface::vm_type wasm_runtime = chain::config::default_wasm_runtime;
...@@ -151,6 +152,7 @@ namespace eosio { namespace chain { ...@@ -151,6 +152,7 @@ namespace eosio { namespace chain {
bool skip_auth_check()const; 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_header;
signal<void(const block_state_ptr&)> accepted_block; signal<void(const block_state_ptr&)> accepted_block;
...@@ -206,6 +208,7 @@ FC_REFLECT( eosio::chain::controller::config, ...@@ -206,6 +208,7 @@ FC_REFLECT( eosio::chain::controller::config,
(reversible_cache_size) (reversible_cache_size)
(shared_memory_dir)(shared_memory_size)(read_only) (shared_memory_dir)(shared_memory_size)(read_only)
(force_all_checks) (force_all_checks)
(contracts_console)
(genesis) (genesis)
(wasm_runtime) (wasm_runtime)
) )
...@@ -977,68 +977,85 @@ class action_api : public context_aware_api { ...@@ -977,68 +977,85 @@ class action_api : public context_aware_api {
class console_api : public context_aware_api { class console_api : public context_aware_api {
public: public:
console_api( apply_context& ctx ) 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. // 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) { 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 ) { 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) { void printi(int64_t val) {
context.console_append(val); if ( !ignore ) {
context.console_append(val);
}
} }
void printui(uint64_t val) { void printui(uint64_t val) {
context.console_append(val); if ( !ignore ) {
context.console_append(val);
}
} }
void printi128(const __int128& val) { void printi128(const __int128& val) {
bool is_negative = (val < 0); if ( !ignore ) {
unsigned __int128 val_magnitude; bool is_negative = (val < 0);
unsigned __int128 val_magnitude;
if( is_negative ) if( is_negative )
val_magnitude = static_cast<unsigned __int128>(-val); // Works even if val is at the lowest possible value of a int128_t val_magnitude = static_cast<unsigned __int128>(-val); // Works even if val is at the lowest possible value of a int128_t
else else
val_magnitude = static_cast<unsigned __int128>(val); 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 ) { if( is_negative ) {
context.console_append("-"); 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) { void printui128(const unsigned __int128& val) {
fc::uint128_t v(val>>64, static_cast<uint64_t>(val) ); if ( !ignore ) {
context.console_append(fc::variant(v).get_string()); fc::uint128_t v(val>>64, static_cast<uint64_t>(val) );
context.console_append(fc::variant(v).get_string());
}
} }
void printsf( float val ) { void printsf( float val ) {
// Assumes float representation on native side is the same as on the WASM side if ( !ignore ) {
auto& console = context.get_console_stream(); // Assumes float representation on native side is the same as on the WASM side
auto orig_prec = console.precision(); auto& console = context.get_console_stream();
auto orig_prec = console.precision();
console.precision( std::numeric_limits<float>::digits10 ); console.precision( std::numeric_limits<float>::digits10 );
context.console_append(val); context.console_append(val);
console.precision( orig_prec ); console.precision( orig_prec );
}
} }
void printdf( double val ) { void printdf( double val ) {
// Assumes double representation on native side is the same as on the WASM side if ( !ignore ) {
auto& console = context.get_console_stream(); // Assumes double representation on native side is the same as on the WASM side
auto orig_prec = console.precision(); auto& console = context.get_console_stream();
auto orig_prec = console.precision();
console.precision( std::numeric_limits<double>::digits10 ); console.precision( std::numeric_limits<double>::digits10 );
context.console_append(val); context.console_append(val);
console.precision( orig_prec ); console.precision( orig_prec );
}
} }
void printqf( const float128_t& val ) { void printqf( const float128_t& val ) {
...@@ -1054,25 +1071,34 @@ class console_api : public context_aware_api { ...@@ -1054,25 +1071,34 @@ class console_api : public context_aware_api {
* having to deal with long doubles at all. * having to deal with long doubles at all.
*/ */
auto& console = context.get_console_stream(); if ( !ignore ) {
auto orig_prec = console.precision(); 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; extFloat80_t val_approx;
f128M_to_extF80M(&val, &val_approx); f128M_to_extF80M(&val, &val_approx);
context.console_append( *(long double*)(&val_approx) ); context.console_append( *(long double*)(&val_approx) );
console.precision( orig_prec ); console.precision( orig_prec );
}
} }
void printn(const name& value) { 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 ) { 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)\ #define DB_API_METHOD_WRAPPERS_SIMPLE_SECONDARY(IDX, TYPE)\
......
...@@ -41,6 +41,7 @@ namespace eosio { namespace testing { ...@@ -41,6 +41,7 @@ namespace eosio { namespace testing {
cfg.shared_memory_dir = tempdir.path() / "shared"; cfg.shared_memory_dir = tempdir.path() / "shared";
cfg.shared_memory_size = 1024*1024*8; cfg.shared_memory_size = 1024*1024*8;
cfg.reversible_cache_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_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" ); cfg.genesis.initial_key = get_public_key( config::system_account_name, "active" );
......
...@@ -139,6 +139,8 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip ...@@ -139,6 +139,8 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip
"clear chain database, recover as many blocks as possible from the block log, and then replay those blocks") "clear chain database, recover as many blocks as possible from the block log, and then replay those blocks")
("resync-blockchain", bpo::bool_switch()->default_value(false), ("resync-blockchain", bpo::bool_switch()->default_value(false),
"clear chain database and block log") "clear chain database and block log")
("contracts-console", bpo::bool_switch()->default_value(false),
"print contract's output to console")
; ;
} }
...@@ -201,7 +203,8 @@ void chain_plugin::plugin_initialize(const variables_map& options) { ...@@ -201,7 +203,8 @@ void chain_plugin::plugin_initialize(const variables_map& options) {
if( my->wasm_runtime ) if( my->wasm_runtime )
my->chain_config->wasm_runtime = *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("resync-blockchain").as<bool>() ) { if( options.at("resync-blockchain").as<bool>() ) {
ilog("Resync requested: wiping database and blocks"); ilog("Resync requested: wiping database and blocks");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册