From 5f2f09f8717374dc3dc4786bfb26d42fe66237c2 Mon Sep 17 00:00:00 2001 From: Roman Khlopkov <roman.khlopkov@demlabs.net> Date: Fri, 31 Mar 2023 12:15:16 +0300 Subject: [PATCH] [*] Invalidate tx fix, esbocs validators choose fix, srv_stake keylist refactoring --- modules/common/dap_chain_datum.c | 15 ++- .../consensus/esbocs/dap_chain_cs_esbocs.c | 3 +- .../dap_chain_net_srv_stake_pos_delegate.c | 25 ++-- modules/type/dag/dap_chain_cs_dag.c | 111 ++++++++---------- 4 files changed, 81 insertions(+), 73 deletions(-) diff --git a/modules/common/dap_chain_datum.c b/modules/common/dap_chain_datum.c index 16132d7a8a..5c92997c54 100644 --- a/modules/common/dap_chain_datum.c +++ b/modules/common/dap_chain_datum.c @@ -438,7 +438,7 @@ bool dap_chain_datum_dump_tx(dap_chain_datum_tx_t *a_datum, l_hash_str = dap_enc_base58_encode_hash_to_str(l_hash_tmp); dap_string_append_printf(a_str_out, "\t\t\t unit: 0x%08x\n" "\t\t\t pkey: %s\n" - "\t\t\t max price: %s (%s) \n", + "\t\t\t max price: %s (%s)\n", ((dap_chain_tx_out_cond_t*)item)->subtype.srv_pay.unit.uint32, l_hash_str, l_coins_str, @@ -449,12 +449,21 @@ bool dap_chain_datum_dump_tx(dap_chain_datum_tx_t *a_datum, } break; case DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_STAKE_POS_DELEGATE: { dap_chain_node_addr_t *l_signer_node_addr = &((dap_chain_tx_out_cond_t*)item)->subtype.srv_stake_pos_delegate.signer_node_addr; - char *l_addr_str = dap_chain_addr_to_str(&((dap_chain_tx_out_cond_t*)item)->subtype.srv_stake_pos_delegate.signing_addr); + dap_chain_addr_t *l_signing_addr = &((dap_chain_tx_out_cond_t*)item)->subtype.srv_stake_pos_delegate.signing_addr; + char *l_addr_str = dap_chain_addr_to_str(l_signing_addr); + l_hash_tmp = &l_signing_addr->data.hash_fast; + if (!dap_strcmp(a_hash_out_type, "hex")) + l_hash_str = dap_chain_hash_fast_to_str_new(l_hash_tmp); + else + l_hash_str = dap_enc_base58_encode_hash_to_str(l_hash_tmp); dap_string_append_printf(a_str_out, "\t\t\t signing_addr: %s\n" - "\t\t\t : signer_node_addr: "NODE_ADDR_FP_STR, + "\t\t\t with pkey hash %s\n" + "\t\t\t signer_node_addr: "NODE_ADDR_FP_STR"\n", l_addr_str, + l_hash_str, NODE_ADDR_FP_ARGS(l_signer_node_addr)); DAP_DELETE(l_addr_str); + DAP_DELETE(l_hash_str); } break; case DAP_CHAIN_TX_OUT_COND_SUBTYPE_SRV_XCHANGE: { char *l_value_str = dap_chain_balance_print(((dap_chain_tx_out_cond_t*)item)->subtype.srv_xchange.buy_value); diff --git a/modules/consensus/esbocs/dap_chain_cs_esbocs.c b/modules/consensus/esbocs/dap_chain_cs_esbocs.c index ad37664318..caa34e1816 100644 --- a/modules/consensus/esbocs/dap_chain_cs_esbocs.c +++ b/modules/consensus/esbocs/dap_chain_cs_esbocs.c @@ -325,11 +325,10 @@ static void *s_callback_list_copy(const void *a_validator, UNUSED_ARG void *a_da static void *s_callback_list_form(const void *a_srv_validator, UNUSED_ARG void *a_data) { - dap_chain_esbocs_validator_t *l_validator = DAP_NEW(dap_chain_esbocs_validator_t); + dap_chain_esbocs_validator_t *l_validator = DAP_NEW_Z(dap_chain_esbocs_validator_t); l_validator->node_addr = ((dap_chain_net_srv_stake_item_t *)a_srv_validator)->node_addr; l_validator->signing_addr = ((dap_chain_net_srv_stake_item_t *)a_srv_validator)->signing_addr; l_validator->weight = ((dap_chain_net_srv_stake_item_t *)a_srv_validator)->value; - l_validator->is_synced = false; return l_validator; } 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 9427113863..6f3164d042 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 @@ -309,7 +309,7 @@ static dap_chain_datum_tx_t *s_stake_tx_create(dap_chain_net_t * a_net, dap_chai log_it(L_ERROR, "Can't compose the transaction input"); goto tx_fail; } - // add 'in' items to delegate + // add 'in' items to pay fee uint256_t l_value_fee_items = dap_chain_datum_tx_add_in_item_list(&l_tx, l_list_fee_out); dap_list_free_full(l_list_fee_out, NULL); if (!EQUAL_256(l_value_fee_items, l_fee_transfer)) { @@ -581,6 +581,15 @@ static dap_chain_datum_tx_t *s_stake_tx_invalidate(dap_chain_net_t *a_net, dap_h // add 'in' item to buy from conditional transaction dap_chain_datum_tx_add_in_cond_item(&l_tx, a_tx_hash, l_prev_cond_idx, 0); + // add 'in' items to pay fee + uint256_t l_value_fee_items = dap_chain_datum_tx_add_in_item_list(&l_tx, l_list_fee_out); + dap_list_free_full(l_list_fee_out, NULL); + if (!EQUAL_256(l_value_fee_items, l_fee_transfer)) { + log_it(L_ERROR, "Can't compose the transaction input"); + dap_chain_datum_tx_delete(l_tx); + return NULL; + } + // add 'out_ext' item if (dap_chain_datum_tx_add_out_ext_item(&l_tx, &l_owner_addr, l_tx_out_cond->header.value, l_delegated_ticker) == -1) { dap_chain_datum_tx_delete(l_tx); @@ -1034,12 +1043,12 @@ static int s_cli_srv_stake_order(int a_argc, char **a_argv, int a_arg_index, cha static void s_srv_stake_print(dap_chain_net_srv_stake_item_t *a_stake, dap_string_t *a_string) { char *l_tx_hash_str = dap_chain_hash_fast_to_str_new(&a_stake->tx_hash); - char *l_signing_addr_str = dap_chain_addr_to_str(&a_stake->signing_addr); - char *l_balance = dap_chain_balance_print(a_stake->value); - dap_string_append_printf(a_string, "%s %s %s\n", l_tx_hash_str, l_balance, l_signing_addr_str); + char *l_pkey_hash_str = dap_chain_hash_fast_to_str_new(&a_stake->signing_addr.data.hash_fast); + char *l_balance = dap_chain_balance_to_coins(a_stake->value); + dap_string_append_printf(a_string, "%s\t%s\t%s\n", l_pkey_hash_str, l_balance, l_tx_hash_str); DAP_DELETE(l_balance); DAP_DELETE(l_tx_hash_str); - DAP_DELETE(l_signing_addr_str); + DAP_DELETE(l_pkey_hash_str); } static int s_cli_srv_stake(int a_argc, char **a_argv, char **a_str_reply) @@ -1268,7 +1277,7 @@ static int s_cli_srv_stake(int a_argc, char **a_argv, char **a_str_reply) return -21; } } - dap_string_t *l_reply_str = dap_string_new(""); + dap_string_t *l_reply_str = dap_string_new("Pkey hash\t\t\tStake value\tTx hash\n"); if (l_stake) s_srv_stake_print(l_stake, l_reply_str); else @@ -1278,8 +1287,8 @@ static int s_cli_srv_stake(int a_argc, char **a_argv, char **a_str_reply) } s_srv_stake_print(l_stake, l_reply_str); } - if (!l_reply_str->len) { - dap_string_append(l_reply_str, "No transaction found"); + if (!HASH_CNT(hh, s_srv_stake->itemlist)) { + dap_string_append(l_reply_str, "No keys found"); } *a_str_reply = dap_string_free(l_reply_str, false); } break; diff --git a/modules/type/dag/dap_chain_cs_dag.c b/modules/type/dag/dap_chain_cs_dag.c index 8344824edc..dc373219da 100644 --- a/modules/type/dag/dap_chain_cs_dag.c +++ b/modules/type/dag/dap_chain_cs_dag.c @@ -1604,75 +1604,66 @@ static int s_cli_dag(int argc, char ** argv, char **a_str_reply) DAP_DELETE(l_event_hash_base58_str); // dap_chain_net_sync_gdb(l_net); }break; - case SUBCMD_EVENT_DUMP:{ + case SUBCMD_EVENT_DUMP: { dap_chain_cs_dag_event_round_item_t * l_round_item = NULL; dap_chain_cs_dag_event_t * l_event = NULL; // dap_chain_cs_dag_event_round_info_t l_event_round_info; size_t l_event_size = 0; - if ( l_from_events_str ){ - if ( strcmp(l_from_events_str,"round.new") == 0 ){ - const char * l_gdb_group_events = l_dag->gdb_group_events_round_new; - size_t l_round_item_size = 0; - l_round_item = (dap_chain_cs_dag_event_round_item_t *)dap_global_db_get_sync(l_gdb_group_events, - l_event_hash_str, &l_round_item_size, NULL, NULL); - if (l_round_item) { - l_event_size = l_round_item->event_size; - l_event = (dap_chain_cs_dag_event_t *)l_round_item->event_n_signs; - } - }else if ( strncmp(l_from_events_str,"round.",6) == 0){ - - }else if ( strcmp(l_from_events_str,"events_lasts") == 0){ - dap_chain_cs_dag_event_item_t * l_event_item = NULL; - pthread_rwlock_rdlock(&PVT(l_dag)->events_rwlock); - HASH_FIND(hh,PVT(l_dag)->events_lasts_unlinked,&l_event_hash,sizeof(l_event_hash),l_event_item); - pthread_rwlock_unlock(&PVT(l_dag)->events_rwlock); - if ( l_event_item ) - l_event = l_event_item->event; - else { - ret = -23; - dap_cli_server_cmd_set_reply_text(a_str_reply, - "Can't find event %s in events_last table\n", l_event_hash_str); - break; - } - }else if ( strcmp(l_from_events_str,"events") == 0){ - dap_chain_cs_dag_event_item_t * l_event_item = NULL; - pthread_rwlock_rdlock(&PVT(l_dag)->events_rwlock); - HASH_FIND(hh,PVT(l_dag)->events,&l_event_hash,sizeof(l_event_hash),l_event_item); - pthread_rwlock_unlock(&PVT(l_dag)->events_rwlock); - if ( l_event_item ) { - l_event = l_event_item->event; - l_event_size = l_event_item->event_size; - } else { - ret = -24; - dap_cli_server_cmd_set_reply_text(a_str_reply, - "Can't find event %s in events table\n", l_event_hash_str); - break; - } - }else if ( strcmp(l_from_events_str,"threshold") == 0){ - dap_chain_cs_dag_event_item_t * l_event_item = NULL; - pthread_rwlock_rdlock(&PVT(l_dag)->events_rwlock); - HASH_FIND(hh,PVT(l_dag)->events_treshold,&l_event_hash,sizeof(l_event_hash),l_event_item); - pthread_rwlock_unlock(&PVT(l_dag)->events_rwlock); - if (l_event_item) - l_event = l_event_item->event; - else { - ret = -23; - dap_cli_server_cmd_set_reply_text(a_str_reply, - "Can't find event %s in threshold table\n", l_event_hash_str); - break; - } - }else { - ret = -22; + if (l_from_events_str && strcmp(l_from_events_str,"round.new") == 0) { + const char * l_gdb_group_events = l_dag->gdb_group_events_round_new; + size_t l_round_item_size = 0; + l_round_item = (dap_chain_cs_dag_event_round_item_t *)dap_global_db_get_sync(l_gdb_group_events, + l_event_hash_str, &l_round_item_size, NULL, NULL); + if (l_round_item) { + l_event_size = l_round_item->event_size; + l_event = (dap_chain_cs_dag_event_t *)l_round_item->event_n_signs; + } + } else if (l_from_events_str && strcmp(l_from_events_str,"events_lasts") == 0) { + dap_chain_cs_dag_event_item_t * l_event_item = NULL; + pthread_rwlock_rdlock(&PVT(l_dag)->events_rwlock); + HASH_FIND(hh,PVT(l_dag)->events_lasts_unlinked,&l_event_hash,sizeof(l_event_hash),l_event_item); + pthread_rwlock_unlock(&PVT(l_dag)->events_rwlock); + if ( l_event_item ) + l_event = l_event_item->event; + else { + ret = -23; dap_cli_server_cmd_set_reply_text(a_str_reply, - "Wrong events_from option \"%s\", need one of variant: events, round.new, events_lasts, round.0x0123456789ABCDEF, threshold", l_from_events_str); + "Can't find event %s in events_last table\n", l_event_hash_str); + break; + } + } else if (!l_from_events_str || strcmp(l_from_events_str,"events") == 0) { + dap_chain_cs_dag_event_item_t * l_event_item = NULL; + pthread_rwlock_rdlock(&PVT(l_dag)->events_rwlock); + HASH_FIND(hh,PVT(l_dag)->events,&l_event_hash,sizeof(l_event_hash),l_event_item); + pthread_rwlock_unlock(&PVT(l_dag)->events_rwlock); + if ( l_event_item ) { + l_event = l_event_item->event; + l_event_size = l_event_item->event_size; + } else { + ret = -24; + dap_cli_server_cmd_set_reply_text(a_str_reply, + "Can't find event %s in events table\n", l_event_hash_str); + break; + } + } else if (l_from_events_str && strcmp(l_from_events_str,"threshold") == 0) { + dap_chain_cs_dag_event_item_t * l_event_item = NULL; + pthread_rwlock_rdlock(&PVT(l_dag)->events_rwlock); + HASH_FIND(hh,PVT(l_dag)->events_treshold,&l_event_hash,sizeof(l_event_hash),l_event_item); + pthread_rwlock_unlock(&PVT(l_dag)->events_rwlock); + if (l_event_item) + l_event = l_event_item->event; + else { + ret = -23; + dap_cli_server_cmd_set_reply_text(a_str_reply, + "Can't find event %s in threshold table\n", l_event_hash_str); break; - } } else { - ret = -21; + ret = -22; dap_cli_server_cmd_set_reply_text(a_str_reply, - "No events_from option"); + "Wrong events_from option \"%s\", need one of variant: events, round.new, events_lasts, threshold", l_from_events_str); break; + } if ( l_event ){ dap_string_t * l_str_tmp = dap_string_new(NULL); @@ -1759,7 +1750,7 @@ static int s_cli_dag(int argc, char ** argv, char **a_str_reply) ret=-10; } DAP_DELETE(l_round_item); - }break; + } break; case SUBCMD_EVENT_LIST:{ if (l_from_events_str && strcmp(l_from_events_str,"round.new") == 0) { char * l_gdb_group_events = DAP_CHAIN_CS_DAG(l_chain)->gdb_group_events_round_new; -- GitLab