diff --git a/dap-sdk/net/client/dap_client.c b/dap-sdk/net/client/dap_client.c index d992fe2d8ec45b19c64b2f9581ff6a9cfdad7db0..89d098685ebe254624151aa3682b8fed7db2578a 100644 --- a/dap-sdk/net/client/dap_client.c +++ b/dap-sdk/net/client/dap_client.c @@ -194,7 +194,7 @@ void dap_client_set_auth_cert_unsafe(dap_client_t * a_client, dap_cert_t *a_cert void dap_client_delete_unsafe(dap_client_t * a_client) { if ( DAP_CLIENT_PVT(a_client)->refs_count ==0 ){ - dap_client_pvt_delete( DAP_CLIENT_PVT(a_client) ); + dap_client_pvt_delete_unsafe( DAP_CLIENT_PVT(a_client) ); pthread_mutex_destroy(&a_client->mutex); DAP_DEL_Z(a_client) } else @@ -240,7 +240,7 @@ static void s_go_stage_on_client_worker_unsafe(dap_worker_t * a_worker,void * a_ if (!l_client || l_client->_internal != l_client_pvt) { log_it(L_WARNING,"Client is NULL or corrupted, why? Refs %u", l_client_pvt->refs_count); if ( l_client_pvt->refs_count ==0 ){ - dap_client_pvt_delete( l_client_pvt ); + dap_client_pvt_delete_unsafe(l_client_pvt); } else l_client_pvt->is_to_delete = true; return; diff --git a/dap-sdk/net/client/dap_client_pvt.c b/dap-sdk/net/client/dap_client_pvt.c index 1c722b920415e1274260b59c5b5190f384bf0069..3d688955bee2e636ffe6d012c4c7f6d2148a195c 100644 --- a/dap-sdk/net/client/dap_client_pvt.c +++ b/dap-sdk/net/client/dap_client_pvt.c @@ -161,10 +161,10 @@ void dap_client_pvt_new(dap_client_pvt_t * a_client_pvt) /** - * @brief dap_client_pvt_delete + * @brief dap_client_pvt_delete_unsafe * @param a_client_pvt */ -void dap_client_pvt_delete(dap_client_pvt_t * a_client_pvt) +void dap_client_pvt_delete_unsafe(dap_client_pvt_t * a_client_pvt) { assert(a_client_pvt); diff --git a/dap-sdk/net/client/include/dap_client_pvt.h b/dap-sdk/net/client/include/dap_client_pvt.h index 5dc2f3f0e5e0514e06198bc365a7e9b8b65954ac..81af1d0618fc580d240688e23caef24267d39c4c 100644 --- a/dap-sdk/net/client/include/dap_client_pvt.h +++ b/dap-sdk/net/client/include/dap_client_pvt.h @@ -116,7 +116,7 @@ void dap_client_pvt_request_enc(dap_client_pvt_t * a_client_internal, const char dap_client_callback_int_t a_error_proc); void dap_client_pvt_new(dap_client_pvt_t * a_client_internal); -void dap_client_pvt_delete(dap_client_pvt_t * a_client_pvt); +void dap_client_pvt_delete_unsafe(dap_client_pvt_t * a_client_pvt); int dap_client_pvt_hh_add_unsafe(dap_client_pvt_t* a_client_pvt); int dap_client_pvt_hh_del_unsafe(dap_client_pvt_t *a_client_pvt); diff --git a/dap-sdk/net/core/dap_events.c b/dap-sdk/net/core/dap_events.c index accb805fec84b4394ead6b5ee0aafeedf0b2ac5b..85637f01faeeab6a6db109ceb18869c5bddbc5c3 100644 --- a/dap-sdk/net/core/dap_events.c +++ b/dap-sdk/net/core/dap_events.c @@ -298,7 +298,7 @@ void dap_events_delete( dap_events_t *a_events ) void dap_events_remove_and_delete_socket_unsafe(dap_events_t *a_events, dap_events_socket_t *a_socket, bool a_preserve_inheritor) { (void) a_events; - int l_sock = a_socket->socket; +// int l_sock = a_socket->socket; // if( a_socket->type == DESCRIPTOR_TYPE_TIMER) // log_it(L_DEBUG,"Remove timer %d", l_sock); diff --git a/dap-sdk/net/core/dap_worker.c b/dap-sdk/net/core/dap_worker.c index cd389832d2f8b41a527d3436b7941e0f57c8d49d..639378351697c921139fcbefce0c8d82bab81e4c 100644 --- a/dap-sdk/net/core/dap_worker.c +++ b/dap-sdk/net/core/dap_worker.c @@ -202,7 +202,6 @@ void *dap_worker_thread(void *arg) time_t l_cur_time = time( NULL); for(size_t n = 0; n < l_sockets_max; n++) { - bool l_flag_hup, l_flag_rdhup, l_flag_read, l_flag_write, l_flag_error, l_flag_nval, l_flag_msg, l_flag_pri; #ifdef DAP_EVENTS_CAPS_EPOLL l_cur = (dap_events_socket_t *) l_epoll_events[n].data.ptr; @@ -280,8 +279,8 @@ void *dap_worker_thread(void *arg) #else #error "Unimplemented fetch esocket after poll" #endif - if(!l_cur) { - log_it(L_ERROR, "dap_events_socket NULL"); + if(!l_cur || (l_cur->worker && l_cur->worker != l_worker)) { + log_it(L_WARNING, "dap_events_socket was destroyed earlier"); continue; } if(s_debug_reactor) { diff --git a/modules/chain/dap_chain_ledger.c b/modules/chain/dap_chain_ledger.c index dc82cdf9c85eb73dbada1bd9021c6012478b30d3..a1c92bc115f5bfecc02ba34445ee3f60abee9de1 100644 --- a/modules/chain/dap_chain_ledger.c +++ b/modules/chain/dap_chain_ledger.c @@ -1178,7 +1178,7 @@ int dap_chain_ledger_token_emission_add_check(dap_ledger_t *a_ledger, byte_t *a_ if (!dap_sign_verify_size(l_sign, l_emission_size)) { break; } - if (dap_sign_verify(l_sign, &l_emission->hdr, sizeof(l_emission))) { + if (dap_sign_verify(l_sign, &l_emission->hdr, sizeof(l_emission)) == 1) { l_aproves++; break; } @@ -1193,13 +1193,13 @@ int dap_chain_ledger_token_emission_add_check(dap_ledger_t *a_ledger, byte_t *a_ if(s_debug_more) log_it(L_WARNING, "Emission of %"DAP_UINT64_FORMAT_U" datoshi of %s:%s is wrong: only %u valid aproves when %u need", l_emission->hdr.value, a_ledger->net_name, l_emission->hdr.ticker, l_aproves, l_aproves_valid ); - ret = -1; + ret = -3; } } }else{ if(s_debug_more) log_it(L_WARNING,"Can't find token declaration %s:%s thats pointed in token emission datum", a_ledger->net_name, l_emission->hdr.ticker); - ret = DAP_CHAIN_CS_VERIFY_CODE_TX_NO_PREVIOUS; + ret = DAP_CHAIN_CS_VERIFY_CODE_TX_NO_TOKEN; } }break; default:{} diff --git a/modules/chain/include/dap_chain_ledger.h b/modules/chain/include/dap_chain_ledger.h index 524d3bc49bb722df1817799653c5e871bb6c55b3..79daa4659fe046c574fbd1b03cdc56b0b6f8e8b2 100644 --- a/modules/chain/include/dap_chain_ledger.h +++ b/modules/chain/include/dap_chain_ledger.h @@ -57,6 +57,8 @@ typedef bool (* dap_chain_ledger_verificator_callback_t)(dap_chain_tx_out_cond_t #define DAP_CHAIN_CS_VERIFY_CODE_TX_NO_PREVIOUS -111 // Error code for no emission for a transaction (candidate to threshold) #define DAP_CHAIN_CS_VERIFY_CODE_TX_NO_EMISSION -112 +// Error code for no token for an emission (candidate to threshold) +#define DAP_CHAIN_CS_VERIFY_CODE_TX_NO_TOKEN -113 #define DAP_CHAIN_LEDGER_TOKENS_STR "tokens" #define DAP_CHAIN_LEDGER_EMISSIONS_STR "emissions" diff --git a/modules/global-db/dap_chain_global_db.c b/modules/global-db/dap_chain_global_db.c index 89d1fbd18ad9ab89166f48dffea62acc494ab387..7d714677cbc2ced25c5fce0325cb60d9b0d3e241 100644 --- a/modules/global-db/dap_chain_global_db.c +++ b/modules/global-db/dap_chain_global_db.c @@ -330,13 +330,9 @@ uint8_t * dap_chain_global_db_get(const char *a_key, size_t *a_data_len_out) */ static bool global_db_gr_del_add(char *a_key,const char *a_group, time_t a_timestamp) { - dap_store_obj_t store_data; - memset(&store_data, 0, sizeof(dap_store_obj_t)); + dap_store_obj_t store_data = {}; store_data.type = 'a'; store_data.key = a_key; - // no data - store_data.value = NULL; - store_data.value_len = 0; // group = parent group + '.del' store_data.group = dap_strdup_printf("%s.del", a_group); store_data.timestamp = a_timestamp; @@ -621,7 +617,7 @@ bool dap_chain_global_db_gr_del(char *a_key,const char *a_group) unlock(); if(l_res >= 0) { // add to Del group - global_db_gr_del_add(dap_strdup(a_key), store_data.group, store_data.timestamp); + global_db_gr_del_add(dap_strdup(a_key), store_data.group, time(NULL)); } // do not add to history if l_res=1 (already deleted) if (!l_res) { diff --git a/modules/modules_dynamic/cdb/dap_modules_dynamic_cdb.c b/modules/modules_dynamic/cdb/dap_modules_dynamic_cdb.c index f3fcc8923cd88dfb516c620c9b97f3ade27bf467..7e5472cfacc952ccc9f92a8ae49d180888f9fb89 100644 --- a/modules/modules_dynamic/cdb/dap_modules_dynamic_cdb.c +++ b/modules/modules_dynamic/cdb/dap_modules_dynamic_cdb.c @@ -29,7 +29,7 @@ #include <dlfcn.h> #endif -#define LOG_TAG "dap_http" +#define LOG_TAG "dap_modules_dynamic" static const char * s_default_path_modules = "var/modules"; static void *s_cdb_handle = NULL; diff --git a/modules/net/dap_chain_node.c b/modules/net/dap_chain_node.c index e6ec10bb3fc89e52d43cdd62c25f0680633f2c80..07532845a57ab326bea30f2ded8acbe00c24a4a4 100644 --- a/modules/net/dap_chain_node.c +++ b/modules/net/dap_chain_node.c @@ -225,7 +225,7 @@ dap_chain_node_info_t* dap_chain_node_info_read( dap_chain_net_t * a_net,dap_cha return node_info; }*/ -int dap_chain_node_mempool_process(dap_chain_t *a_chain, dap_chain_node_role_t a_role, dap_chain_datum_t *a_datum) +int dap_chain_node_mempool_process(dap_chain_t *a_chain, dap_chain_datum_t *a_datum) { bool l_need_process = false; for (uint16_t j = 0; j < a_chain->autoproc_datum_types_count; j++) { @@ -236,16 +236,7 @@ int dap_chain_node_mempool_process(dap_chain_t *a_chain, dap_chain_node_role_t a } if (!l_need_process) return -1; - if (a_datum->header.type_id == DAP_CHAIN_DATUM_TX) { - dap_chain_datum_tx_t *l_tx = (dap_chain_datum_tx_t *)a_datum->data; - dap_chain_tx_in_t *l_tx_in = (dap_chain_tx_in_t *)dap_chain_datum_tx_item_get(l_tx, NULL, TX_ITEM_TYPE_IN, NULL); - // Is not it a base transaction? - if (l_tx_in && !dap_hash_fast_is_blank(&l_tx_in->header.tx_prev_hash)) { - if (a_role.enums == NODE_ROLE_ROOT) { - return -1; - } - } - } + // Auth signs for emissions already verified by this callback return (int)a_chain->callback_add_datums(a_chain, &a_datum, 1); } @@ -292,7 +283,7 @@ bool dap_chain_node_mempool_autoproc_init() if (!l_objs[i].value_len) continue; dap_chain_datum_t *l_datum = (dap_chain_datum_t *)l_objs[i].value; - if (dap_chain_node_mempool_process(l_chain, l_role, l_datum) >= 0) { + if (dap_chain_node_mempool_process(l_chain, l_datum) >= 0) { // Delete processed objects dap_chain_global_db_gr_del(dap_strdup(l_objs[i].key), l_gdb_group_mempool); } @@ -332,8 +323,7 @@ void dap_chain_node_mempool_autoproc_notify(void *a_arg, const char a_op_code, c char *l_gdb_group_str = dap_chain_net_get_gdb_group_mempool(l_chain); if (!strcmp(a_group, l_gdb_group_str)) { dap_chain_datum_t *l_datum = (dap_chain_datum_t *)a_value; - dap_chain_node_role_t l_role = dap_chain_net_get_role(l_net); - if (dap_chain_node_mempool_process(l_chain, l_role, l_datum) >= 0) { + if (dap_chain_node_mempool_process(l_chain, l_datum) >= 0) { dap_chain_global_db_gr_del(dap_strdup(a_key), l_gdb_group_str); } } diff --git a/modules/net/dap_chain_node_client.c b/modules/net/dap_chain_node_client.c index 3128e8d2dd529e5e93d3dba7384143cbca2a74d4..d7af958a2e1e11bf75995954d345c2ef340800d3 100644 --- a/modules/net/dap_chain_node_client.c +++ b/modules/net/dap_chain_node_client.c @@ -741,6 +741,17 @@ void dap_chain_node_client_close(dap_chain_node_client_t *a_client) char l_node_addr_str[INET_ADDRSTRLEN] = {}; inet_ntop(AF_INET, &a_client->info->hdr.ext_addr_v4, l_node_addr_str, INET_ADDRSTRLEN); log_it(L_INFO, "Closing node client to uplink %s:%d", l_node_addr_str, a_client->info->hdr.ext_port); + dap_stream_ch_t *l_ch = dap_stream_ch_find_by_uuid_unsafe(a_client->stream_worker, a_client->ch_chain_uuid); + if (l_ch) { + dap_stream_ch_chain_t *l_ch_chain = DAP_STREAM_CH_CHAIN(l_ch); + l_ch_chain->callback_notify_packet_in = NULL; + l_ch_chain->callback_notify_packet_out = NULL; + } + l_ch = dap_stream_ch_find_by_uuid_unsafe(a_client->stream_worker, a_client->ch_chain_net_uuid); + if (l_ch) { + dap_stream_ch_chain_net_t *l_ch_chain_net = DAP_STREAM_CH_CHAIN_NET(l_ch); + l_ch_chain_net->notify_callback = NULL; + } // clean client dap_client_pvt_t *l_client_pvt = dap_client_pvt_find(a_client->client->pvt_uuid); if (l_client_pvt) { diff --git a/modules/net/include/dap_chain_node.h b/modules/net/include/dap_chain_node.h index 6b6a810667a10eec933d95262cdc46dcc79d23a4..f8fdcc6af4c28d9881b63c2f28c083b17b98fb54 100644 --- a/modules/net/include/dap_chain_node.h +++ b/modules/net/include/dap_chain_node.h @@ -144,7 +144,7 @@ inline static char* dap_chain_node_addr_to_hash_str(dap_chain_node_addr_t *addre return a_key; } -int dap_chain_node_mempool_process(dap_chain_t *a_chain, dap_chain_node_role_t a_role, dap_chain_datum_t *a_datum); +int dap_chain_node_mempool_process(dap_chain_t *a_chain, dap_chain_datum_t *a_datum); bool dap_chain_node_mempool_autoproc_init(); void dap_chain_node_mempool_autoproc_deinit(); void dap_chain_node_mempool_autoproc_notify(void *a_arg, const char a_op_code, const char *a_group,