diff --git a/modules/net/dap_chain_node_cli.c b/modules/net/dap_chain_node_cli.c index 95d4be85a746e76546a2a536c84026eb8806d5cd..f32e91190eb3fcef1889cf31ac179dac8baba8d6 100644 --- a/modules/net/dap_chain_node_cli.c +++ b/modules/net/dap_chain_node_cli.c @@ -241,6 +241,9 @@ int dap_chain_node_cli_init(dap_config_t * g_config) dap_cli_server_cmd_add ("mempool_proc", com_mempool_proc, "Proc mempool entrie with specified hash for selected chain network", "mempool_proc -net <net_name> -datum <datum hash>\n"); + dap_cli_server_cmd_add ("mempool_proc_all", com_mempool_proc_all, "Proc mempool all entries for selected chain network", + "mempool_proc_all -net <net_name> -chain <chain_name>\n"); + dap_cli_server_cmd_add ("mempool_delete", com_mempool_delete, "Delete datum with hash <datum hash> for selected chain network", "mempool_delete -net <net_name> -datum <datum hash>\n"); diff --git a/modules/net/dap_chain_node_cli_cmd.c b/modules/net/dap_chain_node_cli_cmd.c index 18251a8d0074bc795bba2a5c1be94129ce4207ad..a5169014f6787da88e304957834bb6f22f31941a 100644 --- a/modules/net/dap_chain_node_cli_cmd.c +++ b/modules/net/dap_chain_node_cli_cmd.c @@ -2816,6 +2816,90 @@ int com_mempool_proc(int a_argc, char **a_argv, char **a_str_reply) return ret; } +/** + * @breif com_mempool_proc_all + * @param argc + * @param argv + * @param a_str_reply + * @return + */ +int com_mempool_proc_all(int argc, char ** argv, char ** a_str_reply) { + dap_chain_net_t *l_net = NULL; + dap_chain_t *l_chain = NULL; + int arg_index = 1; + + dap_chain_node_cli_cmd_values_parse_net_chain(&arg_index, argc, argv, a_str_reply, &l_chain, &l_net); + if (!l_net || !l_chain) + return -1; + char * l_gdb_group_mempool = dap_chain_net_get_gdb_group_mempool_new(l_chain); + + if(!l_gdb_group_mempool) { + dap_cli_server_cmd_set_reply_text(a_str_reply, "%s.%s: chain not found\n", l_net->pub.name, + l_chain->name); + } + + size_t l_objs_count = 0; + size_t l_objs_addr = 0; + dap_global_db_obj_t *l_objs = dap_global_db_get_all_sync(l_gdb_group_mempool, &l_objs_count); + size_t l_processed_datums = 0; + size_t l_skip_datums = 0; + log_it(L_NOTICE, "Start massive processing"); + for(size_t i = 0; i < l_objs_count; i++) { + dap_chain_datum_t *l_datum = (dap_chain_datum_t*)l_objs[i].value; + size_t l_datum_size = l_objs[i].value_len; + size_t l_datum_size2= l_datum? dap_chain_datum_size( l_datum): 0; + if (l_datum_size != l_datum_size2 ){ + l_skip_datums++; + log_it(L_DEBUG, "It is not possible to process the datum, the size of the datum calculated using the " + "function does not match the size of the data received from the GDB."); + break; + }else{ + char buf[80] = {'\0'}; + char buf_ctime[60] = {'\0'}; + dap_hash_fast_t l_hf = {0}; + dap_time_t l_ts_create = (dap_time_t)l_datum->header.ts_create; + const char *l_type = NULL; + DAP_DATUM_TYPE_STR(l_datum->header.type_id, l_type); + dap_hash_fast(l_datum, l_datum_size, &l_hf); + dap_chain_hash_fast_to_str(&l_hf, &buf, 80); + log_it(L_NOTICE, "\thash %s: type_id=%s ts_create=%s data_size=%u\n", &buf, l_type, + dap_ctime_r(&l_ts_create, buf_ctime), l_datum->header.data_size); + int l_verify_datum = dap_chain_net_verify_datum_for_add(l_net, l_datum) ; + if (l_verify_datum != 0){ + l_skip_datums++; + log_it(L_NOTICE, "\t\tError! Datum doesn't pass verifications (code %d) examine node log files.\n", + l_verify_datum); + continue; + }else{ + if (l_chain->callback_add_datums){ + if (l_chain->callback_add_datums(l_chain, &l_datum, 1) ==0 ){ + log_it(L_NOTICE, "\t\tError! Datum doesn't pass verifications, examine node log files.\n"); + l_skip_datums++; + continue; + }else{ + log_it(L_NOTICE, "\t\tDatum processed well. \n"); + l_processed_datums++; + if (!dap_global_db_del_sync(&buf, l_gdb_group_mempool)){ + log_it(L_WARNING, "\t\tWarning! Can't delete datum from mempool! \n"); + }else + log_it(L_NOTICE, "\t\t Removed datum from mempool.\n"); + } + }else{ + log_it(L_NOTICE, "\t\tError! Can't move to no-concensus chains from mempool.\n"); + l_skip_datums++; + continue; + } + } + } + } + dap_cli_server_cmd_set_reply_text(a_str_reply, "The entire mempool has been processed in %s.%s. " + "Total items were %zu of which %zu accepted %zu rejected.", + l_net->pub.name, l_chain->name, l_objs_count, l_processed_datums, + l_skip_datums); + + return 0; +} + /** * @brief * diff --git a/modules/net/include/dap_chain_node_cli_cmd.h b/modules/net/include/dap_chain_node_cli_cmd.h index 3fb2307f1e29e71213e2577c8a581e2ead51e391..d42ec094552825ba43eea95400ae9eed04c8befe 100644 --- a/modules/net/include/dap_chain_node_cli_cmd.h +++ b/modules/net/include/dap_chain_node_cli_cmd.h @@ -141,6 +141,7 @@ int cmd_gdb_export(int a_argc, char **a_argv, char **a_str_reply); int com_mempool_delete(int a_argc, char **a_argv, char **a_str_reply); int com_mempool_list(int a_argc, char **a_argv, char **a_str_reply); int com_mempool_proc(int a_argc, char **a_argv, char **a_str_reply); +int com_mempool_proc_all(int argc, char ** argv, char ** a_str_reply); int com_mempool_check(int a_argc, char **a_argv, char **a_str_reply); /** * Place public CA into the mempool