From 548c00514cd15ad5467f86e8cd7a3ec9ae33bbec Mon Sep 17 00:00:00 2001 From: Aleksey Feoktistov <aleksey.feoktistov@demlabs.net> Date: Sat, 2 Apr 2022 10:56:07 +0000 Subject: [PATCH] features-5238 --- modules/global-db/dap_chain_global_db.c | 2 +- modules/type/blocks/dap_chain_block_cache.c | 1 + modules/type/blocks/dap_chain_cs_blocks.c | 9 +++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/global-db/dap_chain_global_db.c b/modules/global-db/dap_chain_global_db.c index f96f89b1fc..967bde4e42 100644 --- a/modules/global-db/dap_chain_global_db.c +++ b/modules/global-db/dap_chain_global_db.c @@ -673,7 +673,7 @@ dap_store_obj_t *l_store_obj; l_store_obj = (dap_store_obj_t *)a_store_data; for(int i = a_objs_count; i--; l_store_obj++) { - if (l_store_obj->type == DAP_DB$K_OPTYPE_ADD && !l_res) + if (l_store_obj->type == DAP_DB$K_OPTYPE_DEL && !l_res) // delete info about the deleted entry from the base if one present global_db_gr_del_del(l_store_obj->key, l_store_obj->group); else if (l_store_obj->type == DAP_DB$K_OPTYPE_ADD && l_res >= 0) diff --git a/modules/type/blocks/dap_chain_block_cache.c b/modules/type/blocks/dap_chain_block_cache.c index cfcd30fd02..c629009055 100644 --- a/modules/type/blocks/dap_chain_block_cache.c +++ b/modules/type/blocks/dap_chain_block_cache.c @@ -62,6 +62,7 @@ dap_chain_block_cache_t * dap_chain_block_cache_new(dap_chain_cs_blocks_t *a_blo l_block_cache->block = a_block; l_block_cache->block_size= a_block_size; l_block_cache->_inheritor = a_blocks; + l_block_cache->ts_created = a_block->hdr.ts_created; if (dap_chain_block_cache_update(l_block_cache)) { log_it(L_WARNING, "Block cache can't be created, possible cause corrupted block inside"); DAP_DELETE(l_block_cache); diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c index 75a435d2b7..317f41073b 100644 --- a/modules/type/blocks/dap_chain_cs_blocks.c +++ b/modules/type/blocks/dap_chain_cs_blocks.c @@ -231,6 +231,7 @@ int dap_chain_cs_blocks_new(dap_chain_t * a_chain, dap_config_t * a_chain_config l_cs_blocks_pvt->block_size_maximum = 10 * 1024 * 1024; // 10 Mb l_cs_blocks_pvt->fill_timeout = dap_config_get_item_uint64_default(a_chain_config, "blocks", "fill_timeout", 60) * 1000; // 1 min + l_cs_blocks_pvt->blocks_count = 0; return 0; } @@ -556,7 +557,7 @@ static int s_cli_blocks(int a_argc, char ** a_argv, char **a_str_reply) HASH_ITER(hh,PVT(l_blocks)->block_cache_first,l_block_cache, l_block_cache_tmp ) { char l_buf[50]; - ctime_r(&l_block_cache->ts_created, l_buf); + ctime_r(&l_block_cache->block->hdr.ts_created, l_buf); dap_string_append_printf(l_str_tmp,"\t%s: ts_create=%s", l_block_cache->block_hash_str, l_buf); } @@ -686,6 +687,7 @@ static int s_add_atom_to_blocks(dap_chain_cs_blocks_t * a_blocks, dap_ledger_t * //All correct, no matter for result pthread_rwlock_wrlock( &PVT(a_blocks)->rwlock ); HASH_ADD(hh, PVT(a_blocks)->blocks,block_hash,sizeof (a_block_cache->block_hash), a_block_cache); + PVT(a_blocks)->blocks_count++; if (! (PVT(a_blocks)->block_cache_first ) ) PVT(a_blocks)->block_cache_first = a_block_cache; if (PVT(a_blocks)->block_cache_last) @@ -736,6 +738,7 @@ static void s_bft_consensus_setup(dap_chain_cs_blocks_t * a_blocks) if(l_block_cache->next) l_block_cache->next->prev = l_block_cache->prev; HASH_DEL(PVT(a_blocks)->blocks,l_block_cache); + PVT(a_blocks)->blocks_count--; pthread_rwlock_unlock(& PVT(a_blocks)->rwlock); dap_chain_block_chunks_add(PVT(a_blocks)->chunks,l_block_cache); } @@ -1043,8 +1046,10 @@ static dap_chain_atom_ptr_t s_callback_atom_iter_get_next( dap_chain_atom_iter_t a_atom_iter->cur_item = l_cur_cache = l_cur_cache->next; if (l_cur_cache){ a_atom_iter->cur = l_cur_cache->block; + a_atom_iter->cur_size = l_cur_cache->block_size; + a_atom_iter->cur_hash = &l_cur_cache->block_hash; if(a_atom_size) - *a_atom_size=a_atom_iter->cur_size = l_cur_cache->block_size; + *a_atom_size = l_cur_cache->block_size; return l_cur_cache->block; } else { -- GitLab