diff --git a/cmake/OS_Detection.cmake b/cmake/OS_Detection.cmake index 0bd3437ef0f6904a882d16cfff697a6eb0568624..ca52af1043fc5ea8061a33057a3cb77e499dd65c 100644 --- a/cmake/OS_Detection.cmake +++ b/cmake/OS_Detection.cmake @@ -167,8 +167,11 @@ if(WIN32) set(_CCOPT "-mconsole -static -std=gnu11 ${CFLAGS_WARNINGS} -g3 -ggdb -fno-strict-aliasing -fno-eliminate-unused-debug-symbols -pg") set(_LOPT "-mconsole -static -pg") else() - add_definitions ("-DNDEBUG") - set(_CCOPT "-static -std=gnu11 ${CFLAGS_WARNINGS} -O3 -fno-ident -ffast-math -fno-strict-aliasing -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all") + set(_CCOPT "-static -std=gnu11 ${CFLAGS_WARNINGS} -O3 -fPIC -fno-ident -ffast-math -fno-strict-aliasing -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections") + if(NOT DAP_DBG_INFO) + add_definitions ("-DNDEBUG") + set(_CCOPT "${_CCOPT} -Wl,--strip-all") + endif() endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT} ") diff --git a/modules/chain/dap_chain_ledger.c b/modules/chain/dap_chain_ledger.c index db1d8ec5a646c0ed0d3cae0c2be257949f534296..31c96901aa2315b07341d6a2eeef7f1077b51ab7 100644 --- a/modules/chain/dap_chain_ledger.c +++ b/modules/chain/dap_chain_ledger.c @@ -235,7 +235,7 @@ typedef struct dap_chain_ledger_tx_bound { dap_chain_tx_in_t *tx_cur_in; dap_chain_tx_in_cond_t *tx_cur_in_cond; dap_chain_tx_in_ems_t *tx_cur_in_ems; - } in; + } in; union { dap_chain_tx_out_old_t *tx_prev_out; // 256 @@ -328,8 +328,7 @@ typedef struct dap_ledger_private { struct timespec tps_end_time; size_t tps_count; // Threshold fee - dap_timerfd_t *threshold_txs_free_timer; - dap_timerfd_t *threshold_emissions_free_timer; + dap_interval_timer_t threshold_txs_free_timer, threshold_emissions_free_timer; } dap_ledger_private_t; #define PVT(a) ( (dap_ledger_private_t* ) a->_internal ) @@ -2291,7 +2290,7 @@ static void s_load_cache_gdb_loaded_spent_txs_callback(dap_global_db_context_t * return; } dap_chain_hash_fast_from_str(a_values[i].key, &l_tx_spent_item->tx_hash_fast); - l_tx_spent_item->cache_data = *(typeof(((dap_chain_ledger_tx_spent_item_t*)0)->cache_data)*)a_values[i].value; + l_tx_spent_item->cache_data = *(typeof(l_tx_spent_item->cache_data)*)a_values[i].value; HASH_ADD(hh, l_ledger_pvt->spent_items, tx_hash_fast, sizeof(dap_chain_hash_fast_t), l_tx_spent_item); } @@ -3372,7 +3371,7 @@ dap_hash_fast_t *dap_chain_ledger_get_final_chain_tx_hash(dap_ledger_t *a_ledger /** * Check whether used 'out' items (local function) */ -static bool s_ledger_tx_hash_is_used_out_item(dap_chain_ledger_tx_item_t *a_item, int a_idx_out) +static bool s_ledger_tx_hash_is_used_out_item(dap_chain_ledger_tx_item_t *a_item, int a_idx_out, dap_hash_fast_t *a_out_spender_hash) { if (!a_item || !a_item->cache_data.n_outs) { //log_it(L_DEBUG, "list_cached_item is NULL"); @@ -3384,10 +3383,10 @@ static bool s_ledger_tx_hash_is_used_out_item(dap_chain_ledger_tx_item_t *a_item } assert(a_idx_out < MAX_OUT_ITEMS); // if there are used 'out' items - if(a_item->cache_data.n_outs_used > 0) { - dap_hash_fast_t *l_hash_used = &(a_item->cache_data.tx_hash_spent_fast[a_idx_out]); - if(!dap_hash_fast_is_blank(l_hash_used)) - return true; + if ((a_item->cache_data.n_outs_used > 0) && !dap_hash_fast_is_blank(&(a_item->cache_data.tx_hash_spent_fast[a_idx_out]))) { + if (a_out_spender_hash) + *a_out_spender_hash = a_item->cache_data.tx_hash_spent_fast[a_idx_out]; + return true; } return false; } @@ -3592,7 +3591,7 @@ int dap_chain_ledger_tx_cache_check(dap_ledger_t *a_ledger, dap_chain_datum_tx_t log_it(L_ERROR, "Memory allocation error in %s, line %d", __PRETTY_FUNCTION__, __LINE__); if ( l_list_bound_items ) dap_list_free_full(l_list_bound_items, NULL); - if (l_list_tx_out) + if (l_list_tx_out) dap_list_free(l_list_tx_out); HASH_ITER(hh, l_values_from_prev_tx, l_value_cur, l_tmp) { HASH_DEL(l_values_from_prev_tx, l_value_cur); @@ -3818,8 +3817,12 @@ int dap_chain_ledger_tx_cache_check(dap_ledger_t *a_ledger, dap_chain_datum_tx_t // 2. Check if out in previous transaction has spent int l_idx = (l_cond_type == TX_ITEM_TYPE_IN) ? l_tx_in->header.tx_out_prev_idx : l_tx_in_cond->header.tx_out_prev_idx; - if (s_ledger_tx_hash_is_used_out_item(l_item_out, l_idx)) { + dap_hash_fast_t l_spender; + if (s_ledger_tx_hash_is_used_out_item(l_item_out, l_idx, &l_spender)) { l_err_num = DAP_CHAIN_LEDGER_TX_CACHE_CHECK_OUT_ITEM_ALREADY_USED; + char l_hash[DAP_CHAIN_HASH_FAST_STR_SIZE]; + dap_chain_hash_fast_to_str(&l_spender, l_hash, sizeof(l_hash)); + debug_if(s_debug_more, L_INFO, "'Out' item of previous tx %s already spent by %s", l_tx_prev_hash_str, l_hash); break; } @@ -4562,7 +4565,7 @@ static inline int s_tx_add(dap_ledger_t *a_ledger, dap_chain_datum_tx_t *a_tx, d size_t l_tx_size = dap_chain_datum_tx_get_size(l_prev_item_out->tx); size_t l_tx_cache_sz = l_tx_size + sizeof(l_prev_item_out->cache_data); uint8_t *l_tx_cache = DAP_NEW_Z_SIZE(uint8_t, l_tx_cache_sz); - memcpy(l_tx_cache, &l_prev_item_out->cache_data, sizeof(l_prev_item_out->cache_data)); + *(typeof(l_prev_item_out->cache_data)*)l_tx_cache = l_prev_item_out->cache_data; memcpy(l_tx_cache + sizeof(l_prev_item_out->cache_data), l_prev_item_out->tx, l_tx_size); char *l_tx_i_hash = dap_chain_hash_fast_to_str_new(&l_prev_item_out->tx_hash_fast); l_cache_used_outs[i] = (dap_store_obj_t) { @@ -5076,12 +5079,12 @@ size_t dap_chain_ledger_count_tps(dap_ledger_t *a_ledger, struct timespec *a_ts_ /** * Check whether used 'out' items */ -bool dap_chain_ledger_tx_hash_is_used_out_item(dap_ledger_t *a_ledger, dap_chain_hash_fast_t *a_tx_hash, int a_idx_out) +bool dap_chain_ledger_tx_hash_is_used_out_item(dap_ledger_t *a_ledger, dap_chain_hash_fast_t *a_tx_hash, int a_idx_out, dap_hash_fast_t *a_out_spender) { dap_chain_ledger_tx_item_t *l_item_out = NULL; //dap_chain_datum_tx_t *l_tx = s_find_datum_tx_by_hash(a_ledger, a_tx_hash, &l_item_out); - return s_ledger_tx_hash_is_used_out_item(l_item_out, a_idx_out); + return s_ledger_tx_hash_is_used_out_item(l_item_out, a_idx_out, a_out_spender); } /** @@ -5160,7 +5163,7 @@ uint256_t dap_chain_ledger_calc_balance_full(dap_ledger_t *a_ledger, const dap_c { // if transaction has the out item with requested addr if (!memcmp(a_addr, &l_tx_out->addr, sizeof(dap_chain_addr_t))) { // if 'out' item not used & transaction is valid - if(!s_ledger_tx_hash_is_used_out_item(l_iter_current, l_out_idx_tmp) && + if(!s_ledger_tx_hash_is_used_out_item(l_iter_current, l_out_idx_tmp, NULL) && dap_chain_datum_tx_verify_sign(l_cur_tx)) { // uint128_t l_add = dap_chain_uint128_from(l_tx_out->header.value); // balance = dap_uint128_add(balance, l_add); @@ -5178,7 +5181,7 @@ uint256_t dap_chain_ledger_calc_balance_full(dap_ledger_t *a_ledger, const dap_c { // if transaction has the out item with requested addr if (!memcmp(a_addr, &l_tx_out->addr, sizeof(dap_chain_addr_t))) { // if 'out' item not used & transaction is valid - if(!s_ledger_tx_hash_is_used_out_item(l_iter_current, l_out_idx_tmp) && + if(!s_ledger_tx_hash_is_used_out_item(l_iter_current, l_out_idx_tmp, NULL) && dap_chain_datum_tx_verify_sign(l_cur_tx)) { SUM_256_256(balance, l_tx_out->header.value, &balance); } @@ -5193,7 +5196,7 @@ uint256_t dap_chain_ledger_calc_balance_full(dap_ledger_t *a_ledger, const dap_c { // if transaction has the out item with requested addr if (!memcmp(a_addr, &l_tx_out->addr, sizeof(dap_chain_addr_t))) { // if 'out' item not used & transaction is valid - if(!s_ledger_tx_hash_is_used_out_item(l_iter_current, l_out_idx_tmp) && + if(!s_ledger_tx_hash_is_used_out_item(l_iter_current, l_out_idx_tmp, NULL) && dap_chain_datum_tx_verify_sign(l_cur_tx)) { SUM_256_256(balance, l_tx_out->header.value, &balance); } @@ -5525,7 +5528,7 @@ dap_list_t *dap_chain_ledger_get_list_tx_outs_with_val(dap_ledger_t *a_ledger, c continue; } // Check whether used 'out' items - if (!dap_chain_ledger_tx_hash_is_used_out_item (a_ledger, &l_tx_cur_hash, l_out_idx_tmp)) { + if (!dap_chain_ledger_tx_hash_is_used_out_item (a_ledger, &l_tx_cur_hash, l_out_idx_tmp, NULL)) { dap_chain_tx_used_out_item_t *l_item = DAP_NEW_Z(dap_chain_tx_used_out_item_t); if ( !l_item ) { if (l_list_used_out) @@ -5574,7 +5577,7 @@ int dap_chain_ledger_verificator_add(dap_chain_tx_out_cond_subtype_t a_subtype, l_new_verificator = DAP_NEW(dap_chain_ledger_verificator_t); if ( !l_new_verificator ) { log_it(L_ERROR, "Memory allocation error in %s, line %d", __PRETTY_FUNCTION__, __LINE__); - return -1; + return -1; } l_new_verificator->subtype = (int)a_subtype; l_new_verificator->callback = a_callback; diff --git a/modules/chain/include/dap_chain_ledger.h b/modules/chain/include/dap_chain_ledger.h index 54426f5ad4f036bc13b194ba16a8f85891d674ac..1237447ab25ea09d679a8c8c259d77e73dd82842 100644 --- a/modules/chain/include/dap_chain_ledger.h +++ b/modules/chain/include/dap_chain_ledger.h @@ -290,7 +290,7 @@ void dap_chain_ledger_set_tps_start_time(dap_ledger_t *a_ledger); /** * Check whether used 'out' items */ -bool dap_chain_ledger_tx_hash_is_used_out_item(dap_ledger_t *a_ledger, dap_chain_hash_fast_t *a_tx_hash, int a_idx_out); +bool dap_chain_ledger_tx_hash_is_used_out_item(dap_ledger_t *a_ledger, dap_chain_hash_fast_t *a_tx_hash, int a_idx_out, dap_hash_fast_t *a_out_spender); /** * Calculate balance of addr diff --git a/modules/channel/chain-net-srv/dap_stream_ch_chain_net_srv.c b/modules/channel/chain-net-srv/dap_stream_ch_chain_net_srv.c index 9db68b80a12c372b6de57355da877ad311050de1..aab1161c33eb9fa4b2b26b0a9eac6b50ebd9a37b 100644 --- a/modules/channel/chain-net-srv/dap_stream_ch_chain_net_srv.c +++ b/modules/channel/chain-net-srv/dap_stream_ch_chain_net_srv.c @@ -372,11 +372,26 @@ static void s_grace_period_start(dap_chain_net_srv_grace_t *a_grace) } l_tx = a_grace->usage->is_waiting_new_tx_cond ? NULL : dap_chain_ledger_tx_find_by_hash(l_ledger, &a_grace->usage->tx_cond_hash); - if ( ! l_tx ){ // No tx cond transaction, start grace-period + if (!l_tx) { // No tx cond transaction, start grace-period a_grace->usage->is_grace = true; - l_price = DAP_DUP(a_grace->usage->service->pricelist); + DL_FOREACH(a_grace->usage->service->pricelist, l_price) { + switch (l_price->units_uid.enm) { + case SERV_UNIT_MB: + case SERV_UNIT_SEC: + case SERV_UNIT_DAY: + case SERV_UNIT_KB: + case SERV_UNIT_B: + log_it(L_MSG, "Proper unit type %s found among available prices", + dap_chain_srv_unit_enum_to_str(l_price->units_uid.enm)); + break; + default: + continue; + } + break; // proper price found, thus we exit from the loop + } if (!l_price) { - log_it(L_ERROR, "Memory allocation error in %s, line %d", __PRETTY_FUNCTION__, __LINE__); + log_it(L_ERROR, "Price with proper unit type not found, check available orders and/or pricelists"); + l_err.code = DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_RESPONSE_ERROR_CODE_CANT_ADD_USAGE; s_grace_error(a_grace, l_err); return; } @@ -390,7 +405,6 @@ static void s_grace_period_start(dap_chain_net_srv_grace_t *a_grace) usages_in_grace_t *l_item = DAP_NEW_Z_SIZE(usages_in_grace_t, sizeof(usages_in_grace_t)); if (!l_item) { log_it(L_ERROR, "Memory allocation error in %s, line %d", __PRETTY_FUNCTION__, __LINE__); - DAP_DEL_Z(l_price); s_grace_error(a_grace, l_err); return; } @@ -425,12 +439,17 @@ static void s_grace_period_start(dap_chain_net_srv_grace_t *a_grace) return; } - const char * l_ticker = NULL; - l_ticker = dap_chain_ledger_tx_get_token_ticker_by_hash(l_ledger, &a_grace->usage->tx_cond_hash); + const char *l_ticker = dap_chain_ledger_tx_get_token_ticker_by_hash(l_ledger, &a_grace->usage->tx_cond_hash); + if (!l_ticker) { + char l_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE] = { '\0' }; + dap_hash_fast_to_str(&a_grace->usage->tx_cond_hash, l_hash_str, sizeof(l_hash_str)); + log_it( L_ERROR, "Token ticker not found for tx cond hash %s", l_hash_str); + l_err.code = DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_RESPONSE_ERROR_CODE_TX_COND_NOT_FOUND; + s_grace_error(a_grace, l_err); + return; + } dap_stpcpy(a_grace->usage->token_ticker, l_ticker); - - dap_chain_net_srv_price_t *l_price_tmp; DL_FOREACH(a_grace->usage->service->pricelist, l_price_tmp) { if (l_price_tmp && l_price_tmp->net->pub.id.uint64 == a_grace->usage->net->pub.id.uint64 @@ -500,7 +519,8 @@ static bool s_grace_period_finish(usages_in_grace_t *a_grace_item) } if (l_grace->usage->price && !l_grace->usage->receipt_next){ // if first grace delete price and set actual - DAP_DEL_Z(l_grace->usage->price); + l_grace->usage->price = NULL; + } if (l_grace->usage->is_waiting_new_tx_cond){ diff --git a/modules/net/dap_chain_net.c b/modules/net/dap_chain_net.c index 657d45aea1cd10624c270d1c2aaf8cc902c3556b..cec6a1f15e0e1868728301602775df32af91db66 100644 --- a/modules/net/dap_chain_net.c +++ b/modules/net/dap_chain_net.c @@ -642,11 +642,14 @@ dap_chain_node_info_t *dap_get_balancer_link_from_cfg(dap_chain_net_t *a_net) if (!l_ret) DAP_DELETE(l_remote_node_info); return l_ret; - } else + } else{ log_it(L_WARNING,"Can't find node info for node addr "NODE_ADDR_FP_STR, NODE_ADDR_FP_ARGS(l_remote_addr)); + return NULL; + } }else{ log_it(L_WARNING,"Can't find alias info for seed alias %s",l_net_pvt->seed_aliases[i]); + return NULL; } } else if (l_net_pvt->bootstrap_nodes_count) { i = rand() % l_net_pvt->bootstrap_nodes_count; diff --git a/modules/net/dap_chain_net_tx.c b/modules/net/dap_chain_net_tx.c index da3e6beef32bdc331233aa4705b8192c906f6f92..e88bb9ba56dd71cce3fc6d4e64d192135244ff07 100644 --- a/modules/net/dap_chain_net_tx.c +++ b/modules/net/dap_chain_net_tx.c @@ -636,7 +636,7 @@ dap_chain_datum_tx_t *dap_chain_net_get_tx_by_hash(dap_chain_net_t *a_net, dap_c case TX_SEARCH_TYPE_NET_UNSPENT: case TX_SEARCH_TYPE_CELL_UNSPENT: return dap_chain_ledger_tx_find_by_hash(l_ledger, a_tx_hash); - default:; + default: break; } return NULL; } diff --git a/modules/net/dap_chain_node_cli_cmd_tx.c b/modules/net/dap_chain_node_cli_cmd_tx.c index 94222ad44cc5185df4639ea4b668d609bf72cfa0..c19532858ae61bf590a0414f6eeda7aeba7f181b 100644 --- a/modules/net/dap_chain_node_cli_cmd_tx.c +++ b/modules/net/dap_chain_node_cli_cmd_tx.c @@ -99,13 +99,36 @@ static bool s_dap_chain_datum_tx_out_data(dap_chain_datum_tx_t *a_datum, const char *a_hash_out_type, dap_chain_hash_fast_t *a_tx_hash) { - const char *l_ticker = NULL; - if (a_ledger) { - l_ticker = dap_chain_ledger_tx_get_token_ticker_by_hash(a_ledger, a_tx_hash); - if (!l_ticker) - return false; - } + const char *l_ticker = a_ledger + ? dap_chain_ledger_tx_get_token_ticker_by_hash(a_ledger, a_tx_hash) + : NULL; + if (!l_ticker) + return false; dap_chain_datum_dump_tx(a_datum, l_ticker, a_str_out, a_hash_out_type, a_tx_hash); + dap_list_t *l_out_items = dap_chain_datum_tx_items_get(a_datum, TX_ITEM_TYPE_OUT_ALL, NULL); + int l_out_idx = 0; + dap_string_append_printf(a_str_out, "Spenders:\r\n"); + bool l_spent = false; + for (dap_list_t *l_item = l_out_items; l_item; l_item = l_item->next, ++l_out_idx) { + switch (*(dap_chain_tx_item_type_t*)l_item->data) { + case TX_ITEM_TYPE_OUT: + case TX_ITEM_TYPE_OUT_OLD: + case TX_ITEM_TYPE_OUT_EXT: { + dap_hash_fast_t l_spender = { }; + if ((l_spent = dap_chain_ledger_tx_hash_is_used_out_item(a_ledger, a_tx_hash, l_out_idx, &l_spender))) { + char l_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE] = { '\0' }; + dap_hash_fast_to_str(&l_spender, l_hash_str, sizeof(l_hash_str)); + dap_string_append_printf(a_str_out, + "\tout item %d is spent by tx %s\r\n", + l_out_idx, l_hash_str); + } + break; + } + default: + break; + } + } + dap_string_append_printf(a_str_out, l_spent ? "\r\n\r\n" : "\tall yet unspent\r\n\r\n"); return true; } @@ -749,13 +772,11 @@ int com_ledger(int a_argc, char ** a_argv, char **a_str_reply) dap_list_t *l_txs_list = dap_chain_ledger_get_txs(l_ledger, l_tx_count, 1, true); for (dap_list_t *iter = l_txs_list; iter; iter = dap_list_next(iter)) { dap_chain_datum_tx_t *l_tx = iter->data; - size_t l_tx_size = dap_chain_datum_tx_get_size(l_tx); - dap_hash_fast_t l_tx_hash = {0}; - dap_hash_fast(l_tx, l_tx_size, &l_tx_hash); - const char *l_tx_ticker = dap_chain_ledger_tx_get_token_ticker_by_hash(l_ledger, &l_tx_hash); - dap_chain_datum_dump_tx(l_tx, l_tx_ticker, l_str_ret, l_hash_out_type, &l_tx_hash); + dap_hash_fast_t l_tx_hash = { }; + dap_hash_fast(l_tx, dap_chain_datum_tx_get_size(l_tx), &l_tx_hash); + s_dap_chain_datum_tx_out_data(l_tx, l_ledger, l_str_ret, l_hash_out_type, &l_tx_hash); } - dap_list_free1(l_txs_list); + dap_list_free(l_txs_list); } } else { if(l_addr) @@ -769,10 +790,9 @@ int com_ledger(int a_argc, char ** a_argv, char **a_str_reply) dap_chain_datum_tx_t *l_tx = dap_chain_ledger_tx_find_by_hash(l_ledger,&l_tx_hash); if(l_tx){ size_t l_tx_size = dap_chain_datum_tx_get_size(l_tx); - dap_hash_fast_t l_tx_hash = {0}; + dap_hash_fast_t l_tx_hash = { }; dap_hash_fast(l_tx, l_tx_size, &l_tx_hash); - const char *l_tx_ticker = dap_chain_ledger_tx_get_token_ticker_by_hash(l_ledger, &l_tx_hash); - dap_chain_datum_dump_tx(l_tx,l_tx_ticker,l_str_ret,l_hash_out_type,&l_tx_hash); + s_dap_chain_datum_tx_out_data(l_tx, l_ledger, l_str_ret, l_hash_out_type, &l_tx_hash); dap_string_append_printf(l_str_ret, "history for tx hash %s:\n%s\n", l_tx_hash_str, l_str_out ? l_str_out : " empty"); } diff --git a/modules/service/stake/dap_chain_net_srv_stake_lock.c b/modules/service/stake/dap_chain_net_srv_stake_lock.c index 825b38db34b569a3f00e3e0472c2d00ced363891..2b01281942e0997574f6d853b75db883855499aa 100644 --- a/modules/service/stake/dap_chain_net_srv_stake_lock.c +++ b/modules/service/stake/dap_chain_net_srv_stake_lock.c @@ -405,7 +405,7 @@ static enum error_code s_cli_take(int a_argc, char **a_argv, int a_arg_index, da if (l_tx_out_cond->header.subtype != DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_STAKE_LOCK) return NO_VALID_SUBTYPE_ERROR; - if (dap_chain_ledger_tx_hash_is_used_out_item(l_ledger, &l_tx_hash, l_prev_cond_idx)) { + if (dap_chain_ledger_tx_hash_is_used_out_item(l_ledger, &l_tx_hash, l_prev_cond_idx, NULL)) { return IS_USED_OUT_ERROR; } diff --git a/modules/service/stake/dap_chain_net_srv_stake_pos_delegate.c b/modules/service/stake/dap_chain_net_srv_stake_pos_delegate.c index 667cb00c7158666cc624b6099c45ab773acedd87..7bb6e3d805698f932bbd02ea2d253bcb5bd7fbcf 100644 --- a/modules/service/stake/dap_chain_net_srv_stake_pos_delegate.c +++ b/modules/service/stake/dap_chain_net_srv_stake_pos_delegate.c @@ -539,8 +539,11 @@ dap_chain_datum_decree_t *dap_chain_net_srv_stake_decree_approve(dap_chain_net_t log_it(L_WARNING, "Requested conditional transaction has no requires conditional output"); return NULL; } - if (dap_chain_ledger_tx_hash_is_used_out_item(l_ledger, a_stake_tx_hash, l_prev_cond_idx)) { - log_it(L_WARNING, "Requested conditional transaction is already used out"); + dap_hash_fast_t l_spender_hash = { }; + if (dap_chain_ledger_tx_hash_is_used_out_item(l_ledger, a_stake_tx_hash, l_prev_cond_idx, &l_spender_hash)) { + char l_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE]; + dap_chain_hash_fast_to_str(&l_spender_hash, l_hash_str, sizeof(l_hash_str)); + log_it(L_WARNING, "Requested conditional transaction is already used out by %s", l_hash_str); return NULL; } char l_delegated_ticker[DAP_CHAIN_TICKER_SIZE_MAX]; @@ -704,8 +707,11 @@ static dap_chain_datum_tx_t *s_stake_tx_invalidate(dap_chain_net_t *a_net, dap_h log_it(L_WARNING, "Requested conditional transaction has no requires conditional output"); return NULL; } - if (dap_chain_ledger_tx_hash_is_used_out_item(l_ledger, a_tx_hash, l_prev_cond_idx)) { - log_it(L_WARNING, "Requested conditional transaction is already used out"); + dap_hash_fast_t l_spender_hash = { }; + if (dap_chain_ledger_tx_hash_is_used_out_item(l_ledger, a_tx_hash, l_prev_cond_idx, &l_spender_hash)) { + char l_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE]; + dap_chain_hash_fast_to_str(&l_spender_hash, l_hash_str, sizeof(l_hash_str)); + log_it(L_WARNING, "Requested conditional transaction is already used out by %s", l_hash_str); return NULL; } // Get sign item @@ -1274,7 +1280,7 @@ static void s_get_tx_filter_callback(dap_chain_net_t* a_net, dap_chain_datum_tx_ &l_out_idx_tmp))) { dap_hash_fast(a_tx, dap_chain_datum_tx_get_size(a_tx), &l_datum_hash); - if (!dap_chain_ledger_tx_hash_is_used_out_item(a_net->pub.ledger, &l_datum_hash, l_out_idx_tmp)) { + if (!dap_chain_ledger_tx_hash_is_used_out_item(a_net->pub.ledger, &l_datum_hash, l_out_idx_tmp, NULL)) { dap_chain_net_srv_stake_item_t *l_stake = NULL; HASH_FIND(ht, s_srv_stake->tx_itemlist, &l_datum_hash, sizeof(dap_hash_fast_t), l_stake); if(!l_stake){ diff --git a/modules/service/vpn/dap_chain_net_srv_vpn.c b/modules/service/vpn/dap_chain_net_srv_vpn.c index 78b816991304cffddbc4708c6689f7498262d642..bf8c5871a6bea4967f8b53d955173ab029151a13 100644 --- a/modules/service/vpn/dap_chain_net_srv_vpn.c +++ b/modules/service/vpn/dap_chain_net_srv_vpn.c @@ -962,14 +962,12 @@ static int s_callback_response_success(dap_chain_net_srv_t * a_srv, uint32_t a_u l_usage_client->usage_id = a_usage_id; if (!l_usage_active->is_free){ - l_usage_client->receipt = DAP_NEW_SIZE(dap_chain_datum_tx_receipt_t,l_receipt_size); + l_usage_client->receipt = DAP_DUP_SIZE(l_receipt, l_receipt_size); if (!l_usage_client->receipt) { log_it(L_ERROR, "Memory allocation error in %s, line %d", __PRETTY_FUNCTION__, __LINE__); DAP_DEL_Z(l_usage_client); return -1; } - - memcpy(l_usage_client->receipt, l_receipt, l_receipt_size); } pthread_rwlock_wrlock(&s_clients_rwlock); HASH_ADD(hh, s_clients,usage_id,sizeof(a_usage_id),l_usage_client); diff --git a/modules/service/xchange/dap_chain_net_srv_xchange.c b/modules/service/xchange/dap_chain_net_srv_xchange.c index b293315120a3bfe07b7c886a56e02f1de3864b46..3266cd644301ba1b84bed2f5b4a76c9612ee0a1a 100644 --- a/modules/service/xchange/dap_chain_net_srv_xchange.c +++ b/modules/service/xchange/dap_chain_net_srv_xchange.c @@ -593,7 +593,7 @@ static dap_chain_datum_tx_t *s_xchange_tx_create_exchange(dap_chain_net_srv_xcha log_it(L_WARNING, "Requested transaction has no conditional output"); return NULL; } - if (dap_chain_ledger_tx_hash_is_used_out_item(l_ledger, &a_price->tx_hash, l_prev_cond_idx)) { + if (dap_chain_ledger_tx_hash_is_used_out_item(l_ledger, &a_price->tx_hash, l_prev_cond_idx, NULL)) { log_it(L_WARNING, "Requested conditional transaction is already used out"); return NULL; } @@ -788,7 +788,7 @@ static bool s_xchange_tx_invalidate(dap_chain_net_srv_xchange_price_t *a_price, int l_prev_cond_idx = 0; dap_chain_tx_out_cond_t *l_tx_out_cond = dap_chain_datum_tx_out_cond_get(l_cond_tx, DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_XCHANGE, &l_prev_cond_idx); - if (dap_chain_ledger_tx_hash_is_used_out_item(l_ledger, &a_price->tx_hash, l_prev_cond_idx)) { + if (dap_chain_ledger_tx_hash_is_used_out_item(l_ledger, &a_price->tx_hash, l_prev_cond_idx, NULL)) { log_it(L_WARNING, "Requested conditional transaction is already used out"); dap_chain_datum_tx_delete(l_tx); return false; @@ -1483,7 +1483,7 @@ static int s_tx_check_for_open_close(dap_chain_net_t * a_net, dap_chain_datum_tx dap_chain_tx_out_cond_t *l_out_cond_item = dap_chain_datum_tx_out_cond_get(a_tx, DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_XCHANGE, &l_cond_idx); if (l_out_cond_item) { - if(dap_chain_ledger_tx_hash_is_used_out_item(a_net->pub.ledger, &l_tx_hash, l_cond_idx)) + if(dap_chain_ledger_tx_hash_is_used_out_item(a_net->pub.ledger, &l_tx_hash, l_cond_idx, NULL)) return 1; // If its SRV_XCHANGE and spent its closed else return 2; // If its SRV_XCHANGE and not spent its open @@ -1522,7 +1522,7 @@ static void s_string_append_tx_cond_info( dap_string_t * a_reply_str, dap_chain_ bool l_is_cond_out = false; if ( l_out_cond_item && (l_out_cond_item->header.subtype == DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_XCHANGE) ) { - bool l_is_closed = dap_chain_ledger_tx_hash_is_used_out_item(a_net->pub.ledger, &l_tx_hash, l_cond_idx); + bool l_is_closed = dap_chain_ledger_tx_hash_is_used_out_item(a_net->pub.ledger, &l_tx_hash, l_cond_idx, NULL); uint256_t l_value_from = l_out_cond_item->header.value; uint256_t l_value_to = l_out_cond_item->subtype.srv_xchange.buy_value; @@ -1614,7 +1614,7 @@ dap_chain_tx_out_cond_t *l_out_cond_item; if (a_opt_status) /* 1 - closed, 2 - open */ { - l_rc = dap_chain_ledger_tx_hash_is_used_out_item(a_net->pub.ledger, &l_hash, l_item_idx); + l_rc = dap_chain_ledger_tx_hash_is_used_out_item(a_net->pub.ledger, &l_hash, l_item_idx, NULL); if ( a_opt_status ) { @@ -1941,7 +1941,7 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, char **a_str_reply) char *l_value_to_str = dap_chain_balance_to_coins(l_value_to); char *l_value_from_str = dap_chain_balance_to_coins(l_value_from); - l_rc = dap_chain_ledger_tx_hash_is_used_out_item(l_net->pub.ledger, &l_tx_hash, l_prev_cond_idx); + l_rc = dap_chain_ledger_tx_hash_is_used_out_item(l_net->pub.ledger, &l_tx_hash, l_prev_cond_idx, NULL); if ((l_opt_status == 1 && !l_rc) || /* Select close only */ (l_opt_status == 2 && l_rc)) /* Select open only */ @@ -2065,7 +2065,7 @@ static int s_cli_srv_xchange(int a_argc, char **a_argv, char **a_str_reply) dap_chain_tx_out_cond_t *l_out_cond_item = dap_chain_datum_tx_out_cond_get(l_tx, DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_XCHANGE, &l_cond_idx); if (l_out_cond_item && - dap_chain_ledger_tx_hash_is_used_out_item(l_net->pub.ledger, l_tx_hash, l_cond_idx)) { + dap_chain_ledger_tx_hash_is_used_out_item(l_net->pub.ledger, l_tx_hash, l_cond_idx, NULL)) { uint256_t l_value_sell = l_out_cond_item->header.value; uint256_t l_value_buy = l_out_cond_item->subtype.srv_xchange.buy_value; if( l_direction == 1){ diff --git a/modules/type/blocks/dap_chain_block_cache.c b/modules/type/blocks/dap_chain_block_cache.c index cb8641e52b4e90853d1c395cf6a6acc40e364089..c37ee74624b2ce759739ee40971e3fe9d89998e5 100644 --- a/modules/type/blocks/dap_chain_block_cache.c +++ b/modules/type/blocks/dap_chain_block_cache.c @@ -177,7 +177,7 @@ dap_list_t * dap_chain_block_get_list_tx_cond_outs_with_val(dap_ledger_t *a_ledg //Check whether used 'out' items dap_hash_fast_t *l_tx_hash = a_block_cache->datum_hash + i; - if (!dap_chain_ledger_tx_hash_is_used_out_item (a_ledger, l_tx_hash, l_out_idx_tmp)) { + if (!dap_chain_ledger_tx_hash_is_used_out_item (a_ledger, l_tx_hash, l_out_idx_tmp, NULL)) { dap_chain_tx_used_out_item_t *l_item = DAP_NEW_Z(dap_chain_tx_used_out_item_t); if (!l_item) { log_it(L_ERROR, "Memory allocation error in %s, line %d", __PRETTY_FUNCTION__, __LINE__); diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c index 17a0f46877b91846d214d3da94e7a596fea4f900..8b0b302c7dd1843c033508c903cdf47a05398bee 100644 --- a/modules/type/blocks/dap_chain_cs_blocks.c +++ b/modules/type/blocks/dap_chain_cs_blocks.c @@ -674,7 +674,7 @@ static int s_cli_blocks(int a_argc, char ** a_argv, char **a_str_reply) int l_out_idx_tmp = 0; if (NULL == dap_chain_datum_tx_out_cond_get(l_tx, DAP_CHAIN_TX_OUT_COND_SUBTYPE_FEE, &l_out_idx_tmp)) continue; - if (!dap_chain_ledger_tx_hash_is_used_out_item(l_net->pub.ledger, l_block_cache->datum_hash + i, l_out_idx_tmp)) { + if (!dap_chain_ledger_tx_hash_is_used_out_item(l_net->pub.ledger, l_block_cache->datum_hash + i, l_out_idx_tmp, NULL)) { fl_found = true; break; }