diff --git a/modules/chain/dap_chain_cell.c b/modules/chain/dap_chain_cell.c index 4c170e500d477d56f8af6349f9c2b37555caf310..4e15e63cd8c36f2961e9bb61ec55cae65a1a7622 100644 --- a/modules/chain/dap_chain_cell.c +++ b/modules/chain/dap_chain_cell.c @@ -114,7 +114,7 @@ dap_chain_cell_t * dap_chain_cell_create_fill(dap_chain_t * a_chain, dap_chain_c l_size = ftell(l_file); log_it(L_MSG, "[!] Initial size of %s is %lu", file_storage_path, l_size); fseek(l_file, 0, SEEK_SET); - if ( l_size && MAP_FAILED == (l_map = mmap(NULL, l_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(l_file), 0)) ) { + if ( MAP_FAILED == (l_map = mmap(NULL, l_size ? l_size : dap_page_roundup(DAP_MAPPED_VOLUME_LIMIT), PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(l_file), 0)) ) { log_it(L_ERROR, "Chain cell \"%s\" 0x%016"DAP_UINT64_FORMAT_X" cannot be mapped, errno %d", file_storage_path, a_cell_id.uint64, errno); fclose(l_file); pthread_rwlock_unlock(&a_chain->cell_rwlock); @@ -449,8 +449,10 @@ ssize_t dap_chain_cell_file_append(dap_chain_cell_t *a_cell, const void *a_atom, if (!a_atom || !a_atom_size) { a_cell->file_storage = freopen(a_cell->file_storage_path, "w+b", a_cell->file_storage); log_it(L_MSG, "[!] Rewinding file %s", a_cell->file_storage_path); - a_cell->map = a_cell->map_pos = a_cell->map_range_bounds->data; - a_cell->map_end = a_cell->map_range_bounds->next->data; + if (a_cell->chain->is_mapped && a_cell->map_range_bounds) { + a_cell->map = a_cell->map_pos = a_cell->map_range_bounds->data; + a_cell->map_end = a_cell->map_range_bounds->next->data; + } if ( s_file_write_header(a_cell) ) { log_it(L_ERROR, "Chain cell \"%s\" 0x%016"DAP_UINT64_FORMAT_X": can't fill header", a_cell->file_storage_path, a_cell->id.uint64); diff --git a/modules/net/dap_chain_net_decree.c b/modules/net/dap_chain_net_decree.c index e58b850ee502b2ec087c8c864a692274805ce529..5cbd602d151202599ff0f9af1309175b396efbed 100644 --- a/modules/net/dap_chain_net_decree.c +++ b/modules/net/dap_chain_net_decree.c @@ -105,7 +105,7 @@ int dap_chain_net_decree_deinit(dap_chain_net_t *a_net) struct decree_hh *l_decree_hh, *l_tmp; HASH_ITER(hh, s_decree_hh, l_decree_hh, l_tmp) { HASH_DEL(s_decree_hh, l_decree_hh); - if ( !dap_chain_find_by_id(a_net->pub.id, l_decree_hh->decree->header.common_decree_params.chain_id)->is_mapped ) + if ( !dap_chain_find_by_id(a_decree->header.common_decree_params.net_id, l_decree_hh->decree->header.common_decree_params.chain_id)->is_mapped ) DAP_DELETE(l_decree_hh->decree); DAP_DELETE(l_decree_hh); } diff --git a/modules/type/dag/dap_chain_cs_dag.c b/modules/type/dag/dap_chain_cs_dag.c index 961e0312dabfd4cc8c1578d42b11349fa16f5675..ddbdce1eb0d620aa9f6e198a23ca8d48b17d26b5 100644 --- a/modules/type/dag/dap_chain_cs_dag.c +++ b/modules/type/dag/dap_chain_cs_dag.c @@ -305,7 +305,7 @@ static void s_dap_chain_cs_dag_threshold_free(dap_chain_cs_dag_t *a_dag) { l_el->hash = l_current->hash; HASH_ADD(hh, l_pvt->removed_events_from_treshold, hash, sizeof(dap_chain_hash_fast_t), l_el); char *l_hash_dag = dap_hash_fast_to_str_new(&l_current->hash); - if (!l_current->mapped_region) + if (!a_dag->chain->is_mapped && !l_current->mapped_region) DAP_DELETE(l_current->event); HASH_DEL(l_pvt->events_treshold, l_current); DAP_DELETE(l_current); @@ -317,7 +317,7 @@ static void s_dap_chain_cs_dag_threshold_free(dap_chain_cs_dag_t *a_dag) { HASH_ITER(hh, l_pvt->events_treshold_conflicted, l_current, l_tmp) { if (l_current->ts_added < l_time_cut_off) { char *l_hash_dag = dap_hash_fast_to_str_new(&l_current->hash); - if (!l_current->mapped_region) + if (!a_dag->chain->is_mapped && !l_current->mapped_region) DAP_DELETE(l_current->event); HASH_DEL(l_pvt->events_treshold_conflicted, l_current); DAP_DELETE(l_current); @@ -337,23 +337,27 @@ static void s_dap_chain_cs_dag_purge(dap_chain_t *a_chain) // Clang bug at this, l_event_current should change at every loop cycle HASH_ITER(hh, l_dag_pvt->events, l_event_current, l_event_tmp) { HASH_DEL(l_dag_pvt->events, l_event_current); - if (!l_event_current->mapped_region) - DAP_DELETE(l_event_current); + if (!a_chain->is_mapped && !l_event_current->mapped_region) + DAP_DELETE(l_event_current->event); + DAP_DELETE(l_event_current); } HASH_ITER(hh, l_dag_pvt->events_lasts_unlinked, l_event_current, l_event_tmp) { HASH_DEL(l_dag_pvt->events_lasts_unlinked, l_event_current); - if (!l_event_current->mapped_region) - DAP_DELETE(l_event_current); + if (!a_chain->is_mapped && !l_event_current->mapped_region) + DAP_DELETE(l_event_current->event); + DAP_DELETE(l_event_current); } HASH_ITER(hh, l_dag_pvt->events_treshold, l_event_current, l_event_tmp) { HASH_DEL(l_dag_pvt->events_treshold, l_event_current); - if (!l_event_current->mapped_region) - DAP_DELETE(l_event_current); + if (!a_chain->is_mapped && !l_event_current->mapped_region) + DAP_DELETE(l_event_current->event); + DAP_DELETE(l_event_current); } HASH_ITER(hh, l_dag_pvt->events_treshold_conflicted, l_event_current, l_event_tmp) { HASH_DEL(l_dag_pvt->events_treshold_conflicted, l_event_current); - if (!l_event_current->mapped_region) - DAP_DELETE(l_event_current); + if (!a_chain->is_mapped && !l_event_current->mapped_region) + DAP_DELETE(l_event_current->event); + DAP_DELETE(l_event_current); } pthread_mutex_unlock(&l_dag_pvt->events_mutex); dap_chain_cell_delete_all(a_chain);