From e7e375c975a70ade3bf13060a4b0320897a37e3f Mon Sep 17 00:00:00 2001
From: Roman Khlopkov <roman.khlopkov@demlabs.net>
Date: Thu, 6 Apr 2023 19:34:12 +0300
Subject: [PATCH] [*] Esbocs validators mix fix

---
 .../consensus/esbocs/dap_chain_cs_esbocs.c    | 21 +++++++++----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/modules/consensus/esbocs/dap_chain_cs_esbocs.c b/modules/consensus/esbocs/dap_chain_cs_esbocs.c
index 2ae7838de2..2895393ec3 100644
--- a/modules/consensus/esbocs/dap_chain_cs_esbocs.c
+++ b/modules/consensus/esbocs/dap_chain_cs_esbocs.c
@@ -357,14 +357,6 @@ static dap_list_t *s_get_validators_list(dap_chain_esbocs_session_t *a_session,
             dap_list_free_full(l_validators, NULL);
             return NULL;
         }
-        //size_t n = (size_t)l_esbocs_pvt->min_validators_count * 3;
-        size_t l_consensus_optimum = (size_t)l_esbocs_pvt->min_validators_count * 2 - 1;//(n / 2) + (n % 2);
-        size_t l_need_vld_cnt = MIN(l_validators_count, l_consensus_optimum);
-        if (l_validators_count == l_need_vld_cnt) {
-            l_ret = dap_list_copy_deep(l_validators, s_callback_list_form, NULL);
-            dap_list_free_full(l_validators, NULL);
-            return l_ret;
-        }
 
         // TODO: make dap_chain_net_srv_stake_get_total_weight() call
         uint256_t l_total_weight = uint256_0;
@@ -377,6 +369,11 @@ static dap_list_t *s_get_validators_list(dap_chain_esbocs_session_t *a_session,
                 return NULL;
             }
         }
+
+        //size_t n = (size_t)l_esbocs_pvt->min_validators_count * 3;
+        size_t l_consensus_optimum = (size_t)l_esbocs_pvt->min_validators_count * 2 - 1;//(n / 2) + (n % 2);
+        size_t l_need_vld_cnt = MIN(l_validators_count, l_consensus_optimum);
+
         dap_pseudo_random_seed(*(uint256_t *)a_seed_hash);
         for (uint64_t i = 0; i < a_skip_count * l_need_vld_cnt; i++)
             dap_pseudo_random_get(uint256_0);
@@ -384,10 +381,12 @@ static dap_list_t *s_get_validators_list(dap_chain_esbocs_session_t *a_session,
             uint256_t l_chosen_weight = dap_pseudo_random_get(l_total_weight);
             if (PVT(a_session->esbocs)->debug) {
                 char *l_chosen_weignt_str = dap_chain_balance_print(l_chosen_weight);
+                char *l_total_weight_str = dap_chain_balance_print(l_total_weight);
                 char *l_seed_hash_str = dap_hash_fast_to_str_new(&a_session->cur_round.last_block_hash);
-                log_it(L_MSG, "Round seed %s, sync attempt %"DAP_UINT64_FORMAT_U", chosen weight %s",
-                                l_seed_hash_str, a_session->cur_round.sync_attempt, l_chosen_weignt_str);
+                log_it(L_MSG, "Round seed %s, sync attempt %"DAP_UINT64_FORMAT_U", chosen weight %s from %s",
+                                l_seed_hash_str, a_session->cur_round.sync_attempt, l_chosen_weignt_str, l_total_weight_str);
                 DAP_DELETE(l_chosen_weignt_str);
+                DAP_DELETE(l_total_weight_str);
                 DAP_DELETE(l_seed_hash_str);
             }
             dap_list_t *l_chosen = NULL;
@@ -516,7 +515,7 @@ static void s_session_round_new(dap_chain_esbocs_session_t *a_session)
     if (dap_hash_fast_is_blank(&a_session->cur_round.last_block_hash) ||
             !dap_hash_fast_compare(&l_last_block_hash, &a_session->cur_round.last_block_hash)) {
         a_session->cur_round.last_block_hash = l_last_block_hash;
-        a_session->cur_round.sync_attempt = 100;
+        a_session->cur_round.sync_attempt = 1;
     }
     a_session->cur_round.validators_list = s_get_validators_list(a_session, &l_last_block_hash,
                                                                  a_session->cur_round.sync_attempt - 1);
-- 
GitLab