From 8698f9004f36e220008e2ff193f26a9e4bf6a402 Mon Sep 17 00:00:00 2001 From: "roman.khlopkov" <roman.khlopkov@demlabs.net> Date: Thu, 18 Jan 2024 20:02:32 +0300 Subject: [PATCH] [*] Seed mode fix --- modules/type/dag/dap_chain_cs_dag.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/modules/type/dag/dap_chain_cs_dag.c b/modules/type/dag/dap_chain_cs_dag.c index 6bb75e5b6f..4d18c349e9 100644 --- a/modules/type/dag/dap_chain_cs_dag.c +++ b/modules/type/dag/dap_chain_cs_dag.c @@ -664,18 +664,26 @@ static bool s_chain_callback_datums_pool_proc(dap_chain_t *a_chain, dap_chain_da size_t l_hashes_size = l_dag->is_single_line ? 1 : l_dag->datum_add_hashes_count, l_hashes_linked = 0; + if (!l_hashes_size) { + log_it(L_ERROR, "Configuration mismatch, no hashed to be linked", l_datum_hash_str); + return false; + } dap_chain_hash_fast_t *l_hashes = l_hashes_size ? DAP_NEW_STACK_SIZE(dap_chain_hash_fast_t, l_hashes_size * sizeof(dap_chain_hash_fast_t)) : NULL; + if (!l_hashes) { + log_it(L_CRITICAL, "Stack limit reached"); + return false; + } /* Prepare round */ - if (l_hashes && l_hashes_size) { - pthread_mutex_lock(&PVT(l_dag)->events_mutex); - if (!HASH_COUNT(PVT(l_dag)->events_lasts_unlinked)) { - pthread_mutex_unlock(&PVT(l_dag)->events_mutex); - log_it(L_INFO, "Nothing to link"); + pthread_mutex_lock(&PVT(l_dag)->events_mutex); + if (!HASH_COUNT(PVT(l_dag)->events_lasts_unlinked)) { + pthread_mutex_unlock(&PVT(l_dag)->events_mutex); + log_it(L_INFO, "Nothing to link"); + if (!l_seed_mode) return false; - } + } else { /* We'll use modification-safe iteration thru the additional hashtable thus the chosen events will not repeat */ #define always_true(ev) true dap_chain_cs_dag_event_item_t *l_tmp = NULL, *l_cur_ev, *l_tmp_ev; -- GitLab