Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #71 from nervosnetwork/perf
Browse files Browse the repository at this point in the history
perf: remove some helpless debug_print_data
  • Loading branch information
TheWaWaR authored Aug 5, 2021
2 parents 13bfaaf + c4b37c4 commit 2e3e1a4
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 21 deletions.
2 changes: 0 additions & 2 deletions c/other_contracts.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ int recover_account(gw_context_t* ctx,
return ERROR_RECOVER_ACCOUNT;
}
}
debug_print_data("script", script, script_len);
*output = (uint8_t *)malloc(32);
if (*output == NULL) {
ckb_debug("malloc failed");
Expand Down Expand Up @@ -137,4 +136,3 @@ int eth_to_godwoken_addr(gw_context_t* ctx,
}

#endif /* #define OTHER_CONTRACTS_H_ */

15 changes: 0 additions & 15 deletions c/polyjuice.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ int parse_args(struct evmc_message* msg, uint128_t* gas_price,
value.bytes[31 - i] = args[offset + i];
}
offset += 16;
debug_print_data("[value]", value.bytes, 32);

/* args[48..52] */
uint32_t input_size = *((uint32_t*)(args + offset));
Expand All @@ -203,7 +202,6 @@ int parse_args(struct evmc_message* msg, uint128_t* gas_price,

/* args[52..52+input_size] */
uint8_t* input_data = args + offset;
debug_print_data("[input_data]", input_data, input_size);

int ret;
evmc_address sender{0};
Expand Down Expand Up @@ -285,7 +283,6 @@ int load_account_code(gw_context_t* gw_ctx, uint32_t account_id,
debug_print_int("[load_account_code] sys_load failed", ret);
return ret;
}
debug_print_data("[load_account_code] data_hash", data_hash, 32);

bool is_data_hash_zero = true;
for (size_t i = 0; i < 32; i++) {
Expand All @@ -302,11 +299,6 @@ int load_account_code(gw_context_t* gw_ctx, uint32_t account_id,

uint64_t old_code_size = *code_size;
ret = gw_ctx->sys_load_data(gw_ctx, data_hash, code_size, offset, code);
debug_print_data("code data", code, *code_size > 100 ? 100 : *code_size);
if (*code_size > 100) {
ckb_debug("...data...");
debug_print_int("[load_account_code] code_size", *code_size);
}
if (ret != 0) {
ckb_debug("[load_account_code] sys_load_data failed");
return ret;
Expand Down Expand Up @@ -480,7 +472,6 @@ size_t copy_code(struct evmc_host_context* context, const evmc_address* address,
context->error_code = ret;
return 0;
}
debug_print_data("code slice", buffer_data, buffer_size);
ckb_debug("END copy_code");
return 0;
}
Expand Down Expand Up @@ -551,7 +542,6 @@ struct evmc_result call(struct evmc_host_context* context,
ckb_debug("BEGIN call");
debug_print_int("msg.gas", msg->gas);
debug_print_int("msg.depth", msg->depth);
debug_print_data("msg.input_data", msg->input_data, msg->input_size);
debug_print_int("msg.kind", msg->kind);
debug_print_data("call.sender", msg->sender.bytes, 20);
debug_print_data("call.destination", msg->destination.bytes, 20);
Expand Down Expand Up @@ -594,7 +584,6 @@ struct evmc_result call(struct evmc_host_context* context,
return res;
}
res.status_code = EVMC_SUCCESS;
debug_print_data("output data", res.output_data, res.output_size);
} else {
ret = handle_message(gw_ctx, context->from_id, context->to_id, &context->destination, msg, &res);
if (is_fatal_error(ret)) {
Expand Down Expand Up @@ -634,7 +623,6 @@ void emit_log(struct evmc_host_context* context, const evmc_address* address,
const uint8_t* data, size_t data_size,
const evmc_bytes32 topics[], size_t topics_count) {
ckb_debug("BEGIN emit_log");
debug_print_data("log.data", data, data_size);
/*
output[ 0..20] = callee_contract.address
output[20..24] = data_size_u32
Expand Down Expand Up @@ -792,7 +780,6 @@ int create_new_account(gw_context_t* ctx,
debug_print_int("from_id", from_id);
debug_print_int("nonce", nonce);
rlp_encode_sender_and_nonce(&msg->sender, nonce, data, &data_len);
debug_print_data("rlp data", data, data_len);
} else if (msg->kind == EVMC_CREATE2) {
/* CREATE2 contract account script.args[36..36+20] content before hash
Include:
Expand Down Expand Up @@ -902,7 +889,6 @@ int execute_in_evmone(gw_context_t* ctx,
/* Execute the code in EVM */
debug_print_int("[execute_in_evmone] code size", code_size);
debug_print_int("[execute_in_evmone] input_size", msg->input_size);
debug_print_data("[execute_in_evmone] msg.input_data", msg->input_data, msg->input_size);
*res = vm->execute(vm, &interface, &context, EVMC_MAX_REVISION, msg, code_data, code_size);
if (res->status_code != EVMC_SUCCESS && res->status_code != EVMC_REVERT) {
res->output_data = NULL;
Expand Down Expand Up @@ -1117,7 +1103,6 @@ int handle_message(gw_context_t* ctx,
memcpy(res->create_address.bytes, msg.destination.bytes, 20);
}

debug_print_data("[handle_message] output data", res->output_data, res->output_size);
debug_print_int("[handle_message] output size", res->output_size);
debug_print_int("[handle_message] gas left", res->gas_left);
uint32_t used_memory;
Expand Down
3 changes: 0 additions & 3 deletions c/polyjuice_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ int build_script(const uint8_t code_hash[32], const uint8_t hash_type,
}
memcpy(args_seg.ptr, (uint8_t*)(&args_len), 4);
memcpy(args_seg.ptr + 4, args, args_len);
debug_print_data("script.args", args, args_len);
debug_print_data("script.code_hash", code_hash, 32);
debug_print_int("script.hash_type", hash_type);

mol_builder_t script_builder;
Expand All @@ -76,7 +74,6 @@ int build_script(const uint8_t code_hash[32], const uint8_t hash_type,

*script_seg = script_res.seg;

debug_print_data("script ", script_seg->ptr, script_seg->size);
if (MolReader_Script_verify(script_seg, false) != MOL_OK) {
ckb_debug("built an invalid script");
return FATAL_POLYJUICE;
Expand Down
1 change: 0 additions & 1 deletion polyjuice-tests/fuzz/ckb_syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ static int inline __internal_syscall(long n, long _a0, long _a1, long _a2,
// mock syscall(GW_SYS_LOG, account_id, service_flag, data_length, data, 0, 0)
case GW_SYS_LOG: // TODO: @see emit_evm_result_log
dbg_print("[GW_SYS_LOG] service_flag[%d] account[%d] ", (uint8_t)_a1, _a1);
// TODO: debug_print_data("GW_SYS_LOG", (uint32_t)_a3, (uint8_t *)_a2);
return 0;

// mock syscall(GW_SYS_PAY_FEE, payer_addr, short_addr_len, sudt_id, &amount, 0, 0)
Expand Down

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions polyjuice-tests/src/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub(crate) mod parse_log_event;
pub(crate) mod selfdestruct;
pub(crate) mod simple_storage;
pub(crate) mod simple_transfer;
pub(crate) mod simple_wallet;
// The account polyjuice want to create already created by meta_contract
pub(crate) mod account_already_exists;

Expand Down
46 changes: 46 additions & 0 deletions polyjuice-tests/src/test_cases/simple_wallet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! Deploy muti-sign-wallet Contract
//! See https://github.com/Flouse/godwoken-examples/blob/contracts/packages/polyjuice/contracts/WalletSimple.sol/WalletSimple.json
use crate::helper::{self, CKB_SUDT_ACCOUNT_ID};
use gw_common::state::State;
use gw_generator::traits::StateExt;

const BIN_CODE: &str = include_str!("./evm-contracts/SimpleWallet.bin");

#[test]
fn test_simple_wallet() {
let (store, mut state, generator, creator_account_id) = helper::setup();
let block_producer_script = helper::build_eth_l2_script([0x99u8; 20]);
let block_producer_id = state
.create_account_from_script(block_producer_script)
.unwrap();

let from_script = helper::build_eth_l2_script([1u8; 20]);
let from_script_hash = from_script.hash();
let from_short_address = &from_script_hash[0..20];
let from_id = state.create_account_from_script(from_script).unwrap();
state
.mint_sudt(CKB_SUDT_ACCOUNT_ID, from_short_address, 20000000)
.unwrap();
let mut block_number = 0;

// Deploy Contract
block_number += 1;
let _run_result = helper::deploy(
&generator,
&store,
&mut state,
creator_account_id,
from_id,
BIN_CODE,
122000,
0,
block_producer_id,
block_number,
);
let account_script = helper::new_account_script(&mut state, creator_account_id, from_id, false);
let _contract_account_id = state
.get_account_id_by_script_hash(&account_script.hash().into())
.unwrap()
.unwrap();
}

0 comments on commit 2e3e1a4

Please sign in to comment.