diff --git a/dap-sdk b/dap-sdk index d47eb91e22d192264c83e3071de865186d08c022..13684a1f796bc8ee2cc15f925782113a1040855c 160000 --- a/dap-sdk +++ b/dap-sdk @@ -1 +1 @@ -Subproject commit d47eb91e22d192264c83e3071de865186d08c022 +Subproject commit 13684a1f796bc8ee2cc15f925782113a1040855c diff --git a/modules/consensus/esbocs/dap_chain_cs_esbocs.c b/modules/consensus/esbocs/dap_chain_cs_esbocs.c index 9b1e629107767a4294f513b3998a33875343a9ec..f839eca6fb70962bdee80a494ea025c490089914 100644 --- a/modules/consensus/esbocs/dap_chain_cs_esbocs.c +++ b/modules/consensus/esbocs/dap_chain_cs_esbocs.c @@ -729,6 +729,15 @@ int dap_chain_esbocs_set_min_validators_count(dap_chain_t *a_chain, uint16_t a_n return 0; } +int dap_chain_esbocs_get_min_validators_count(dap_chain_net_id_t a_net_id) +{ + dap_chain_esbocs_session_t *l_session; + DL_FOREACH(s_session_items, l_session) + if (l_session->chain->net_id.uint64 == a_net_id.uint64) + return PVT(l_session->esbocs)->min_validators_count; + return -1; +} + int dap_chain_esbocs_set_signs_struct_check(dap_chain_t *a_chain, bool a_enable) { dap_return_val_if_fail(a_chain && !strcmp(dap_chain_get_cs_type(a_chain), DAP_CHAIN_ESBOCS_CS_TYPE_STR), -1); @@ -873,7 +882,8 @@ static dap_list_t *s_get_validators_list(dap_chain_esbocs_t *a_esbocs, dap_hash_ for (size_t l_current_vld_cnt = 0; l_current_vld_cnt < l_need_vld_cnt; l_current_vld_cnt++) { uint256_t l_raw_result; uint256_t l_chosen_weight = dap_pseudo_random_get(l_total_weight, &l_raw_result); - if (false) { //PVT(a_session->esbocs)->debug) { +#if DAP_ESBOCS_PRNG_DEBUG + if (l_esbocs_pvt->debug) { unsigned l_strlen = 1024, l_off = 0; const char *l_chosen_weight_str, *l_total_weight_str, *l_raw_result_str; char l_str[l_strlen]; @@ -888,6 +898,7 @@ static dap_list_t *s_get_validators_list(dap_chain_esbocs_t *a_esbocs, dap_hash_ l_off += snprintf(l_str + l_off, l_strlen - l_off, "by number %s", l_raw_result_str); log_it(L_MSG, "%s", l_str); } +#endif dap_list_t *l_chosen = NULL; uint256_t l_cur_weight = uint256_0; for (dap_list_t *it = l_validators; it; it = it->next) { diff --git a/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h b/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h index bd009e34b125c2eac26c81315a10a16800def6d7..5a99570e8ba8fcc13714422ddb36179ac177e934 100644 --- a/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h +++ b/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h @@ -268,5 +268,6 @@ bool dap_chain_esbocs_remove_validator_from_clusters(dap_chain_net_id_t a_net_id uint256_t dap_chain_esbocs_get_collecting_level(dap_chain_t *a_chain); dap_enc_key_t *dap_chain_esbocs_get_sign_key(dap_chain_t *a_chain); int dap_chain_esbocs_set_min_validators_count(dap_chain_t *a_chain, uint16_t a_new_value); +int dap_chain_esbocs_get_min_validators_count(dap_chain_net_id_t a_net_id); int dap_chain_esbocs_set_emergency_validator(dap_chain_t *a_chain, bool a_add, uint32_t a_sign_type, dap_hash_fast_t *a_validator_hash); int dap_chain_esbocs_set_signs_struct_check(dap_chain_t *a_chain, bool a_enable); diff --git a/modules/net/dap_chain_net_decree.c b/modules/net/dap_chain_net_decree.c index 616e9558aadd0334dd93347c079ea3752bd3c8c8..c96ccaf73e8625175509fc78fc8e77fa90a68d44 100644 --- a/modules/net/dap_chain_net_decree.c +++ b/modules/net/dap_chain_net_decree.c @@ -445,15 +445,23 @@ static int s_common_decree_handler(dap_chain_datum_decree_t *a_decree, dap_chain break; dap_chain_net_srv_stake_key_delegate(a_net, &l_addr, &l_hash, l_value, &l_node_addr); break; - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_INVALIDATE: + case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_INVALIDATE: { if (dap_chain_datum_decree_get_stake_signing_addr(a_decree, &l_addr)){ log_it(L_WARNING,"Can't get signing address from decree."); return -105; } + + uint16_t l_current_count = dap_chain_net_srv_stake_get_total_keys(a_net->pub.id, NULL); + uint16_t l_min_count = dap_chain_esbocs_get_min_validators_count(a_net->pub.id); + if (l_current_count == l_min_count) { + log_it(L_WARNING, "Can't invalidate validator cause min validators count %hu will become less than total count for net %s", + l_current_count, a_net->pub.name); + return -116; + } if (!a_apply) break; dap_chain_net_srv_stake_key_invalidate(&l_addr); - break; + } break; case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_MIN_VALUE: if (dap_chain_datum_decree_get_stake_min_value(a_decree, &l_value)){ log_it(L_WARNING,"Can't get min stake value from decree."); @@ -463,7 +471,7 @@ static int s_common_decree_handler(dap_chain_datum_decree_t *a_decree, dap_chain break; dap_chain_net_srv_stake_set_allowed_min_value(a_net->pub.id, l_value); break; - case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_MIN_VALIDATORS_COUNT: + case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_STAKE_MIN_VALIDATORS_COUNT: { if (dap_chain_datum_decree_get_stake_min_signers_count(a_decree, &l_value)){ log_it(L_WARNING,"Can't get min stake value from decree."); return -105; @@ -477,10 +485,17 @@ static int s_common_decree_handler(dap_chain_datum_decree_t *a_decree, dap_chain log_it(L_WARNING, "Can't apply this decree to specified chain"); return -115; } + uint16_t l_decree_count = (uint16_t)dap_chain_uint256_to(l_value); + uint16_t l_current_count = dap_chain_net_srv_stake_get_total_keys(a_net->pub.id, NULL); + if (l_decree_count > l_current_count) { + log_it(L_WARNING, "Minimum validators count by decree %hu is greater than total validators count %hu in network %s", + l_decree_count, l_current_count, a_net->pub.name); + return -116; + } if (!a_apply) break; - dap_chain_esbocs_set_min_validators_count(l_chain, (uint16_t)dap_chain_uint256_to(l_value)); - break; + dap_chain_esbocs_set_min_validators_count(l_chain, l_decree_count); + } break; case DAP_CHAIN_DATUM_DECREE_COMMON_SUBTYPE_BAN: { if (dap_chain_datum_decree_get_ban_addr(a_decree, &l_ban_addr)) { log_it(L_WARNING, "Can't get ban address from decree.");