From ba7f452f12bf07d0abbfe77569742b4125698ae4 Mon Sep 17 00:00:00 2001 From: "roman.padenkov" <roman.padenkov@demlabs.net> Date: Thu, 27 Apr 2023 17:40:07 +0700 Subject: [PATCH] change out valuet for validator check func --- .../include/dap_stream_ch_chain_net.h | 2 + .../dap_chain_net_srv_stake_pos_delegate.c | 71 ++++++++++--------- .../dap_chain_net_srv_stake_pos_delegate.h | 5 +- 3 files changed, 44 insertions(+), 34 deletions(-) diff --git a/modules/channel/chain-net/include/dap_stream_ch_chain_net.h b/modules/channel/chain-net/include/dap_stream_ch_chain_net.h index caf3267e84..cbe5538cd4 100644 --- a/modules/channel/chain-net/include/dap_stream_ch_chain_net.h +++ b/modules/channel/chain-net/include/dap_stream_ch_chain_net.h @@ -49,6 +49,8 @@ typedef struct dap_stream_ch_chain_rnd{ uint8_t flags;//0 bit -autoproc; 1 bit - find order; 2 bit - auto online; 3 bit - auto update; 6 bit - data sign; 7 bit - find cert; uint32_t sign_size; //uint8_t data[10]; + uint8_t sign_correct; + uint8_t overall_correct; }DAP_ALIGN_PACKED header; byte_t sign[]; } DAP_ALIGN_PACKED dap_stream_ch_chain_rnd_t; diff --git a/modules/service/stake_pos_delegate/dap_chain_net_srv_stake_pos_delegate.c b/modules/service/stake_pos_delegate/dap_chain_net_srv_stake_pos_delegate.c index d9d5f2bccc..e55baf732e 100644 --- a/modules/service/stake_pos_delegate/dap_chain_net_srv_stake_pos_delegate.c +++ b/modules/service/stake_pos_delegate/dap_chain_net_srv_stake_pos_delegate.c @@ -35,7 +35,7 @@ #include "dap_chain_cs_block_poa.h" #include "dap_chain_cs_dag_poa.h" #include "dap_chain_net_srv_stake_pos_delegate.h" -#include "dap_stream_ch_chain_net.h" + #include "rand/dap_rand.h" #include "dap_chain_node_client.h" #include "dap_stream_ch_chain_net_pkt.h" @@ -1156,8 +1156,8 @@ static int callback_compare_tx_list(const void * a_datum1, const void * a_datum2 return -1; } -void dap_chain_net_srv_stake_check_validator(dap_chain_net_t * a_net, - dap_hash_fast_t *a_tx_hash, int a_time_connect, int a_time_respone,char **a_str_reply) +bool dap_chain_net_srv_stake_check_validator(dap_chain_net_t * a_net, dap_hash_fast_t *a_tx_hash, dap_stream_ch_chain_rnd_t * out_data, + int a_time_connect, int a_time_respone,char **a_str_reply) { char *l_key = NULL; size_t l_node_info_size = 0; @@ -1167,6 +1167,7 @@ void dap_chain_net_srv_stake_check_validator(dap_chain_net_t * a_net, dap_ledger_t *l_ledger = dap_chain_ledger_by_net_name(a_net->pub.name); dap_chain_datum_tx_t *l_tx = dap_chain_ledger_tx_find_by_hash(l_ledger, a_tx_hash); dap_chain_node_addr_t *l_signer_node_addr = NULL; + bool l_overall_correct = false; int l_prev_cond_idx = 0; dap_chain_tx_out_cond_t *l_tx_out_cond = dap_chain_datum_tx_out_cond_get(l_tx, @@ -1174,7 +1175,7 @@ void dap_chain_net_srv_stake_check_validator(dap_chain_net_t * a_net, if (!l_tx_out_cond) { dap_cli_server_cmd_set_reply_text(a_str_reply, "Requested conditional transaction has no requires conditional output"); log_it(L_WARNING, "Requested conditional transaction has no requires conditional output"); - return; + return false; } l_signer_node_addr = &l_tx_out_cond->subtype.srv_stake_pos_delegate.signer_node_addr; @@ -1183,7 +1184,7 @@ void dap_chain_net_srv_stake_check_validator(dap_chain_net_t * a_net, { dap_cli_server_cmd_set_reply_text(a_str_reply, "can't calculate hash of addr"); log_it(L_WARNING, "can't calculate hash of addr"); - return; + return false; } // read node @@ -1193,7 +1194,7 @@ void dap_chain_net_srv_stake_check_validator(dap_chain_net_t * a_net, dap_cli_server_cmd_set_reply_text(a_str_reply, "node not found in base"); log_it(L_WARNING, "node not found in base"); DAP_DELETE(l_key); - return; + return false; } size_t node_info_size_must_be = dap_chain_node_info_get_size(l_remote_node_info); @@ -1203,7 +1204,7 @@ void dap_chain_net_srv_stake_check_validator(dap_chain_net_t * a_net, log_it(L_WARNING, "node has bad size in base=%zu (must be %zu)", l_node_info_size, node_info_size_must_be); DAP_DELETE(l_remote_node_info); DAP_DELETE(l_key); - return; + return false; } DAP_DELETE(l_key); // start connect @@ -1211,7 +1212,7 @@ void dap_chain_net_srv_stake_check_validator(dap_chain_net_t * a_net, if(!l_node_client) { dap_cli_server_cmd_set_reply_text(a_str_reply, "can't connect"); DAP_DELETE(l_remote_node_info); - return; + return false; } // wait connected size_t rc = dap_chain_node_client_wait(l_node_client, NODE_CLIENT_STATE_ESTABLISHED, a_time_connect); @@ -1220,7 +1221,7 @@ void dap_chain_net_srv_stake_check_validator(dap_chain_net_t * a_net, // clean client struct dap_chain_node_client_close_mt(l_node_client); DAP_DELETE(l_remote_node_info); - return; + return false; } log_it(L_NOTICE, "Stream connection established"); @@ -1237,7 +1238,7 @@ void dap_chain_net_srv_stake_check_validator(dap_chain_net_t * a_net, log_it(L_WARNING, "Can't send DAP_STREAM_CH_CHAIN_NET_PKT_TYPE_NODE_VALIDATOR_READY_REQUEST packet"); dap_chain_node_client_close_mt(l_node_client); DAP_DELETE(l_remote_node_info); - return; + return false; } rc = dap_chain_node_client_wait(l_node_client, NODE_CLIENT_STATE_VALID_READY, a_time_respone); @@ -1253,30 +1254,15 @@ void dap_chain_net_srv_stake_check_validator(dap_chain_net_t * a_net, if (l_sign_correct) l_sign_correct = dap_sign_verify_all(l_sign, validators_data->header.sign_size, l_test_data, sizeof(l_test_data)); } - bool l_overall_correct = l_sign_correct && validators_data->header.flags == 0xCF; - dap_cli_server_cmd_set_reply_text(a_str_reply, - "-------------------------------------------------\n" - "VERSION \t | %s \n" - "AUTO_PROC \t | %s \n" - "ORDER \t\t | %s \n" - "AUTO_ONLINE \t | %s \n" - "AUTO_UPDATE \t | %s \n" - "DATA_SIGNED \t | %s \n" - "FOUND CERT \t | %s\n" - "SIGN CORRECT \t | %s\n" - "SUMMARY \t | %s\n", - validators_data->header.version, - (validators_data->header.flags & A_PROC)?"true":"false", - (validators_data->header.flags & F_ORDR)?"true":"false", - (validators_data->header.flags & A_ONLN)?"true":"false", - (validators_data->header.flags & A_UPDT)?"true":"false", - (validators_data->header.flags & D_SIGN)?"true":"false", - (validators_data->header.flags & F_CERT)?"true":"false", - l_sign_correct ? "true":"false", - l_overall_correct ? "Validator ready" : "There are unresolved issues"); + l_overall_correct = l_sign_correct && validators_data->header.flags == 0xCF; + + memcpy(out_data,validators_data,sizeof(dap_stream_ch_chain_rnd_t)); + out_data->header.sign_correct = l_sign_correct ? 1 : 0; + out_data->header.overall_correct = l_overall_correct ? 1 : 0; } dap_chain_node_client_close_mt(l_node_client); DAP_DELETE(l_remote_node_info); + return l_overall_correct; } static int s_cli_srv_stake(int a_argc, char **a_argv, char **a_str_reply) @@ -1329,6 +1315,7 @@ static int s_cli_srv_stake(int a_argc, char **a_argv, char **a_str_reply) const char * str_tx_hash = NULL; dap_chain_net_t * l_net = NULL; dap_hash_fast_t l_tx = {}; + dap_stream_ch_chain_rnd_t l_out = {0}; dap_cli_server_cmd_find_option_val(a_argv, l_arg_index, a_argc, "-net", &l_netst); dap_cli_server_cmd_find_option_val(a_argv, l_arg_index, a_argc, "-tx", &str_tx_hash); @@ -1347,7 +1334,27 @@ static int s_cli_srv_stake(int a_argc, char **a_argv, char **a_str_reply) return -3; } - dap_chain_net_srv_stake_check_validator(l_net, &l_tx, 7000, 10000, a_str_reply); + dap_chain_net_srv_stake_check_validator(l_net, &l_tx, &l_out, 7000, 10000, a_str_reply); + dap_cli_server_cmd_set_reply_text(a_str_reply, + "-------------------------------------------------\n" + "VERSION \t | %s \n" + "AUTO_PROC \t | %s \n" + "ORDER \t\t | %s \n" + "AUTO_ONLINE \t | %s \n" + "AUTO_UPDATE \t | %s \n" + "DATA_SIGNED \t | %s \n" + "FOUND CERT \t | %s\n" + "SIGN CORRECT \t | %s\n" + "SUMMARY \t | %s\n", + l_out.header.version, + (l_out.header.flags & A_PROC)?"true":"false", + (l_out.header.flags & F_ORDR)?"true":"false", + (l_out.header.flags & A_ONLN)?"true":"false", + (l_out.header.flags & A_UPDT)?"true":"false", + (l_out.header.flags & D_SIGN)?"true":"false", + (l_out.header.flags & F_CERT)?"true":"false", + l_out.header.sign_correct ? "true":"false", + l_out.header.overall_correct ? "Validator ready" : "There are unresolved issues"); } break; diff --git a/modules/service/stake_pos_delegate/include/dap_chain_net_srv_stake_pos_delegate.h b/modules/service/stake_pos_delegate/include/dap_chain_net_srv_stake_pos_delegate.h index 3fc8c55f17..33759cc197 100644 --- a/modules/service/stake_pos_delegate/include/dap_chain_net_srv_stake_pos_delegate.h +++ b/modules/service/stake_pos_delegate/include/dap_chain_net_srv_stake_pos_delegate.h @@ -28,6 +28,7 @@ #include "dap_chain_net_srv.h" #include "dap_chain_net_srv_order.h" #include "dap_math_ops.h" +#include "dap_stream_ch_chain_net.h" #define DAP_CHAIN_NET_SRV_STAKE_POS_DELEGATE_ID 0x13 @@ -80,8 +81,8 @@ void dap_chain_net_srv_stake_get_fee_validators_str(dap_chain_net_t *a_net, dap_ int dap_chain_net_srv_stake_load_cache(dap_chain_net_t *a_net); void dap_chain_net_srv_stake_purge(dap_chain_net_t *a_net); -void dap_chain_net_srv_stake_check_validator(dap_chain_net_t * a_net, - dap_hash_fast_t *a_tx_hash, int a_time_connect, int a_time_respone, char **a_str_reply); +bool dap_chain_net_srv_stake_check_validator(dap_chain_net_t * a_net,dap_hash_fast_t *a_tx_hash, dap_stream_ch_chain_rnd_t * out_data, + int a_time_connect, int a_time_respone, char **a_str_reply); dap_chain_datum_decree_t *dap_chain_net_srv_stake_decree_approve(dap_chain_net_t *a_net, dap_hash_fast_t *a_stake_tx_hash, dap_cert_t *a_cert); -- GitLab