diff --git a/modules/chain/dap_chain.c b/modules/chain/dap_chain.c index 04a3a2aa456e353a54551a8a048c24a6d0381358..953b3bd2fa67436160376ad997e8b418f8a8f12d 100644 --- a/modules/chain/dap_chain.c +++ b/modules/chain/dap_chain.c @@ -720,6 +720,7 @@ struct chain_thread_notifier { void *callback_arg; dap_chain_t *chain; dap_chain_cell_id_t cell_id; + dap_hash_fast_t hash; void *atom; size_t atom_size; }; @@ -728,7 +729,7 @@ static bool s_notify_atom_on_thread(void *a_arg) { struct chain_thread_notifier *l_arg = a_arg; assert(l_arg->atom && l_arg->callback); - l_arg->callback(l_arg->callback_arg, l_arg->chain, l_arg->cell_id, l_arg->atom, l_arg->atom_size); + l_arg->callback(l_arg->callback_arg, l_arg->chain, l_arg->cell_id, &l_arg->hash, l_arg->atom, l_arg->atom_size); if ( !l_arg->chain->is_mapped ) DAP_DELETE(l_arg->atom); DAP_DELETE(l_arg); @@ -796,7 +797,7 @@ const char* dap_chain_get_path(dap_chain_t *a_chain) return DAP_CHAIN_PVT(a_chain)->file_storage_dir; } -void dap_chain_atom_notify(dap_chain_cell_t *a_chain_cell, const uint8_t *a_atom, size_t a_atom_size) { +void dap_chain_atom_notify(dap_chain_cell_t *a_chain_cell, dap_hash_fast_t *a_hash, const uint8_t *a_atom, size_t a_atom_size) { if ( !a_chain_cell->chain->atom_notifiers ) return; dap_list_t *l_iter; @@ -810,7 +811,8 @@ void dap_chain_atom_notify(dap_chain_cell_t *a_chain_cell, const uint8_t *a_atom *l_arg = (struct chain_thread_notifier) { .callback = l_notifier->callback, .callback_arg = l_notifier->arg, .chain = a_chain_cell->chain, .cell_id = a_chain_cell->id, - .atom = a_chain_cell->chain->is_mapped ? a_atom : DAP_DUP_SIZE(a_atom, a_atom_size), + .hash = *a_hash, + .atom = a_chain_cell->chain->is_mapped ? (byte_t*)a_atom : DAP_DUP_SIZE(a_atom, a_atom_size), .atom_size = a_atom_size }; dap_proc_thread_callback_add_pri(NULL, s_notify_atom_on_thread, l_arg, DAP_QUEUE_MSG_PRIORITY_LOW); } diff --git a/modules/chain/include/dap_chain.h b/modules/chain/include/dap_chain.h index 76def40e457ffacd4b9b23b1452cde56beccb63c..f0c360640563ecfd161b013d67cee6561e4aca15 100644 --- a/modules/chain/include/dap_chain.h +++ b/modules/chain/include/dap_chain.h @@ -110,7 +110,7 @@ typedef dap_chain_atom_ptr_t (*dap_chain_callback_block_find_by_hash_t)(dap_chai typedef dap_chain_atom_ptr_t * (*dap_chain_callback_atom_iter_get_atoms_t)(dap_chain_atom_iter_t * ,size_t* ,size_t**); typedef size_t (*dap_chain_callback_add_datums_t)(dap_chain_t * , dap_chain_datum_t **, size_t ); -typedef void (*dap_chain_callback_notify_t)(void *a_arg, dap_chain_t *a_chain, dap_chain_cell_id_t a_id, void *a_atom, size_t a_atom_size); //change in chain happened +typedef void (*dap_chain_callback_notify_t)(void *a_arg, dap_chain_t *a_chain, dap_chain_cell_id_t a_id, dap_chain_hash_fast_t *a_atom_hash, void *a_atom, size_t a_atom_size); //change in chain happened typedef uint64_t (*dap_chain_callback_get_count)(dap_chain_t *a_chain); typedef dap_list_t *(*dap_chain_callback_get_list)(dap_chain_t *a_chain, size_t a_count, size_t a_page, bool a_reverse); @@ -252,7 +252,7 @@ dap_chain_t *dap_chain_load_from_cfg(const char *a_chain_net_name, dap_chain_net void dap_chain_delete(dap_chain_t * a_chain); void dap_chain_add_callback_notify(dap_chain_t * a_chain, dap_chain_callback_notify_t a_callback, void * a_arg); -void dap_chain_atom_notify(dap_chain_cell_t *a_chain_cell, const uint8_t *a_atom, size_t a_atom_size); +void dap_chain_atom_notify(dap_chain_cell_t *a_chain_cell, dap_hash_fast_t *a_hash, const uint8_t *a_atom, size_t a_atom_size); void dap_chain_atom_add_from_threshold(dap_chain_t *a_chain); dap_chain_atom_ptr_t dap_chain_get_atom_by_hash(dap_chain_t * a_chain, dap_chain_hash_fast_t * a_atom_hash, size_t * a_atom_size); bool dap_chain_get_atom_last_hash_num(dap_chain_t *a_chain, dap_chain_cell_id_t a_cell_id, dap_hash_fast_t *a_atom_hash, uint64_t *a_atom_num); diff --git a/modules/consensus/esbocs/dap_chain_cs_esbocs.c b/modules/consensus/esbocs/dap_chain_cs_esbocs.c index b4cbb481ec3e1285ce1c0758cb412c3541999519..566f77eefa820b9c20101db95710c3180d4d93f5 100644 --- a/modules/consensus/esbocs/dap_chain_cs_esbocs.c +++ b/modules/consensus/esbocs/dap_chain_cs_esbocs.c @@ -413,7 +413,7 @@ void dap_chain_esbocs_add_block_collect(dap_chain_block_cache_t *a_block_cache, } static void s_new_atom_notifier(void *a_arg, dap_chain_t *a_chain, dap_chain_cell_id_t a_id, - void *a_atom, dap_chain_hash_fast_t *a_atom_hash, size_t a_atom_size) + dap_chain_hash_fast_t *a_atom_hash, void *a_atom, size_t a_atom_size) { dap_chain_esbocs_session_t *l_session = a_arg; assert(l_session->chain == a_chain); diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c index ed77c8a7fb55bc4645f48f40b3625af3a2e32952..07b1d8375b5e63c17b30078213fb66a534dd41ae 100644 --- a/modules/type/blocks/dap_chain_cs_blocks.c +++ b/modules/type/blocks/dap_chain_cs_blocks.c @@ -1507,10 +1507,9 @@ static dap_chain_atom_verify_res_t s_callback_atom_add(dap_chain_t * a_chain, da { dap_chain_cs_blocks_t * l_blocks = DAP_CHAIN_CS_BLOCKS(a_chain); dap_chain_block_t * l_block = (dap_chain_block_t *) a_atom; - size_t l_block_size = a_atom_size; dap_chain_hash_fast_t l_block_hash; - dap_hash_fast(l_block, l_block_size, &l_block_hash); + dap_hash_fast(l_block, a_atom_size, &l_block_hash); dap_chain_block_cache_t * l_block_cache = NULL; pthread_rwlock_wrlock(& PVT(l_blocks)->rwlock); @@ -1535,7 +1534,7 @@ static dap_chain_atom_verify_res_t s_callback_atom_add(dap_chain_t * a_chain, da } ret = ATOM_PASS; } - if ( !(l_block_cache = dap_chain_block_cache_new(&l_block_hash, l_block, l_block_size, + if ( !(l_block_cache = dap_chain_block_cache_new(&l_block_hash, l_block, a_atom_size, PVT(l_blocks)->blocks_count + 1, !a_chain->is_mapped)) ) { log_it(L_DEBUG, "... corrupted block"); @@ -1547,7 +1546,7 @@ static dap_chain_atom_verify_res_t s_callback_atom_add(dap_chain_t * a_chain, da ++PVT(l_blocks)->blocks_count; debug_if(s_debug_more, L_DEBUG, "Verified atom %p: ACCEPTED", a_atom); s_add_atom_datums(l_blocks, l_block_cache); - dap_chain_atom_notify(l_cell, l_block, a_atom_size); + dap_chain_atom_notify(l_cell, &l_block_cache->block_hash, (byte_t*)l_block, a_atom_size); dap_chain_atom_add_from_threshold(a_chain); break; } diff --git a/modules/type/dag/dap_chain_cs_dag.c b/modules/type/dag/dap_chain_cs_dag.c index 07756772ce34fb553b68095f6da7f4dfad9d9827..0d34f54c50eb43739c1017bd50337b1c997d0bf1 100644 --- a/modules/type/dag/dap_chain_cs_dag.c +++ b/modules/type/dag/dap_chain_cs_dag.c @@ -547,7 +547,7 @@ static dap_chain_atom_verify_res_t s_chain_callback_atom_add(dap_chain_t * a_cha } else HASH_ADD(hh, PVT(l_dag)->events, hash, sizeof(l_event_item->hash), l_event_item); s_dag_events_lasts_process_new_last_event(l_dag, l_event_item); - dap_chain_atom_notify(l_cell, l_event_item->event, l_event_item->event_size); + dap_chain_atom_notify(l_cell, &l_event_item->hash, (const byte_t*)l_event_item->event, l_event_item->event_size); dap_chain_atom_add_from_threshold(a_chain); } break; default: @@ -980,7 +980,7 @@ dap_chain_cs_dag_event_item_t* s_dag_proc_treshold(dap_chain_cs_dag_t * a_dag) HASH_ADD(hh, PVT(a_dag)->events, hash, sizeof(l_event_item->hash), l_event_item); s_dag_events_lasts_process_new_last_event(a_dag, l_event_item); debug_if(s_debug_more, L_INFO, "... moved from threshold to chain"); - dap_chain_atom_notify(l_cell, l_event_item->event, l_event_item->event_size); + dap_chain_atom_notify(l_cell, &l_event_item->hash, (byte_t*)l_event_item->event, l_event_item->event_size); res = true; } else { // TODO clear other threshold items linked with this one diff --git a/modules/type/none/dap_chain_cs_none.c b/modules/type/none/dap_chain_cs_none.c index 8a570258a693dd2b16ec333878a79e001fa9ac18..f76440baafe884c0dce476b4d306219004df105a 100644 --- a/modules/type/none/dap_chain_cs_none.c +++ b/modules/type/none/dap_chain_cs_none.c @@ -330,7 +330,7 @@ static dap_chain_atom_verify_res_t s_nonconsensus_callback_atom_add(dap_chain_t dap_list_t *l_iter; DL_FOREACH(a_chain->atom_notifiers, l_iter) { dap_chain_atom_notifier_t *l_notifier = (dap_chain_atom_notifier_t*)l_iter->data; - l_notifier->callback(l_notifier->arg, a_chain, (dap_chain_cell_id_t){ }, (void*)l_datum, l_datum_size); + l_notifier->callback(l_notifier->arg, a_chain, (dap_chain_cell_id_t){ }, &l_hash_item->datum_data_hash, (void*)l_datum, l_datum_size); } } return ATOM_ACCEPT;