diff --git a/dap-sdk b/dap-sdk index 9039cd7c25ac035c1651a14492b90f7a87a82c8d..02a8df370be77507ea281fc19d8fcc49114e31f3 160000 --- a/dap-sdk +++ b/dap-sdk @@ -1 +1 @@ -Subproject commit 9039cd7c25ac035c1651a14492b90f7a87a82c8d +Subproject commit 02a8df370be77507ea281fc19d8fcc49114e31f3 diff --git a/modules/chain/dap_chain.c b/modules/chain/dap_chain.c index d6ea5cb8544df48284d4b5654fe24d491aa77950..092c934b0290463f7ff25d2441034d4829159298 100644 --- a/modules/chain/dap_chain.c +++ b/modules/chain/dap_chain.c @@ -113,7 +113,7 @@ dap_chain_t *dap_chain_create(const char *a_chain_net_name, const char *a_chain_ .name = dap_strdup(a_chain_name), .net_name = dap_strdup(a_chain_net_name), .cell_rwlock = PTHREAD_RWLOCK_INITIALIZER, - .atom_notifiers = NULL + .atom_notificators = NULL }; dap_chain_pvt_t *l_chain_pvt = DAP_NEW_Z(dap_chain_pvt_t); if (!l_chain_pvt) { @@ -166,7 +166,7 @@ void dap_chain_delete(dap_chain_t * a_chain) a_chain->id.uint64, a_chain->net_id.uint64); } pthread_rwlock_unlock(&s_chain_items_rwlock); - dap_list_free_full(a_chain->atom_notifiers, NULL); + dap_list_free_full(a_chain->atom_notificators, NULL); DAP_DEL_Z(a_chain->name); DAP_DEL_Z(a_chain->net_name); if (DAP_CHAIN_PVT(a_chain)){ @@ -663,16 +663,16 @@ void dap_chain_add_callback_notify(dap_chain_t * a_chain, dap_chain_callback_not log_it(L_ERROR, "NULL callback passed to dap_chain_add_callback_notify()"); return; } - dap_chain_atom_notifier_t * l_notifier = DAP_NEW_Z(dap_chain_atom_notifier_t); - if (l_notifier == NULL){ - log_it(L_ERROR, "Can't allocate memory for notifier in dap_chain_add_callback_notify()"); + dap_chain_atom_notificator_t * l_notificator = DAP_NEW_Z(dap_chain_atom_notificator_t); + if (l_notificator == NULL){ + log_it(L_ERROR, "Can't allocate memory for notificator in dap_chain_add_callback_notify()"); return; } - l_notifier->callback = a_callback; - l_notifier->arg = a_callback_arg; + l_notificator->callback = a_callback; + l_notificator->arg = a_callback_arg; pthread_rwlock_wrlock(&a_chain->rwlock); - a_chain->atom_notifiers = dap_list_append(a_chain->atom_notifiers, l_notifier); + a_chain->atom_notificators = dap_list_append(a_chain->atom_notificators, l_notificator); pthread_rwlock_unlock(&a_chain->rwlock); } @@ -720,11 +720,11 @@ ssize_t dap_chain_atom_save(dap_chain_t *a_chain, const uint8_t *a_atom, size_t } } ssize_t l_res = dap_chain_cell_file_append(l_cell, a_atom, a_atom_size); - if (a_chain->atom_notifiers) { + if (a_chain->atom_notificators) { 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, l_cell->id, (void*)a_atom, a_atom_size); + DL_FOREACH(a_chain->atom_notificators, l_iter) { + dap_chain_atom_notificator_t *l_notificator = (dap_chain_atom_notificator_t*)l_iter->data; + l_notificator->callback(l_notificator->arg, a_chain, l_cell->id, (void*)a_atom, a_atom_size); } } if (a_chain->callback_atom_add_from_treshold) { @@ -775,25 +775,11 @@ int dap_cert_chain_file_save(dap_chain_datum_t *datum, char *net_name) int l_ret = dap_cert_file_save(cert, cert_path_c); dap_cert_delete(cert); DAP_DELETE(cert_path_c); -// if ( access( l_cert_path, F_OK ) != -1 ) { -// log_it (L_ERROR, "File %s is already exists.", l_cert_path); -// return -1; -// } else return l_ret; } -const char* dap_chain_get_path(dap_chain_t *a_chain){ +const char* dap_chain_get_path(dap_chain_t *a_chain) +{ return DAP_CHAIN_PVT(a_chain)->file_storage_dir; } -void dap_chain_add_mempool_notify_callback(dap_chain_t *a_chain, dap_store_obj_callback_notify_t a_callback, void *a_cb_arg) -{ - dap_chain_gdb_notifier_t *l_notifier = DAP_NEW(dap_chain_gdb_notifier_t); - if (!l_notifier) { - log_it(L_CRITICAL, "Memory allocation error"); - return; - } - l_notifier->callback = a_callback; - l_notifier->cb_arg = a_cb_arg; - DAP_CHAIN_PVT(a_chain)->mempool_notifires = dap_list_append(DAP_CHAIN_PVT(a_chain)->mempool_notifires, l_notifier); -} diff --git a/modules/chain/dap_chain_ledger.c b/modules/chain/dap_chain_ledger.c index 5f8a2aa8a8dfc4bcc977393d49d2c49adfccae98..61dcf4d4841f0a4c46fe07c8981ffd168607a965 100644 --- a/modules/chain/dap_chain_ledger.c +++ b/modules/chain/dap_chain_ledger.c @@ -269,10 +269,10 @@ typedef struct dap_ledger_cache_str_item { bool found; } dap_ledger_cache_str_item_t; -typedef struct dap_chain_ledger_tx_notifier { +typedef struct dap_chain_ledger_tx_notificator { dap_chain_ledger_tx_add_notify_t callback; void *arg; -} dap_chain_ledger_tx_notifier_t; +} dap_chain_ledger_tx_notificator_t; typedef struct dap_chain_ledger_bridged_tx_notificator { dap_chain_ledger_bridged_tx_notify_t callback; @@ -317,7 +317,7 @@ typedef struct dap_ledger_private { //Notificators dap_list_t *bridged_tx_notificators; - dap_list_t *tx_add_notifiers; + dap_list_t *tx_add_notificators; bool load_mode; bool cached; @@ -4763,15 +4763,15 @@ static inline int s_tx_add(dap_ledger_t *a_ledger, dap_chain_datum_tx_t *a_tx, d l_tx_item, s_sort_ledger_tx_item); // tx_hash_fast: name of key field if(a_safe_call) pthread_rwlock_unlock(&l_ledger_pvt->ledger_rwlock); // Callable callback - dap_list_t *l_notifier; - DL_FOREACH(PVT(a_ledger)->tx_add_notifiers, l_notifier) { - dap_chain_ledger_tx_notifier_t *l_notify = (dap_chain_ledger_tx_notifier_t*)l_notifier->data; + dap_list_t *l_notificator; + DL_FOREACH(PVT(a_ledger)->tx_add_notificators, l_notificator) { + dap_chain_ledger_tx_notificator_t *l_notify = (dap_chain_ledger_tx_notificator_t*)l_notificator->data; l_notify->callback(l_notify->arg, a_ledger, l_tx_item->tx); } if (l_cross_network) { - dap_list_t *l_notifier; - DL_FOREACH(PVT(a_ledger)->bridged_tx_notificators, l_notifier) { - dap_chain_ledger_bridged_tx_notificator_t *l_notify = l_notifier->data; + dap_list_t *l_notificator; + DL_FOREACH(PVT(a_ledger)->bridged_tx_notificators, l_notificator) { + dap_chain_ledger_bridged_tx_notificator_t *l_notify = l_notificator->data; l_notify->callback(a_ledger, a_tx, a_tx_hash, l_notify->arg); } } @@ -5734,28 +5734,28 @@ void dap_chain_ledger_tx_add_notify(dap_ledger_t *a_ledger, dap_chain_ledger_tx_ log_it(L_ERROR, "NULL callback passed to dap_chain_ledger_tx_add_notify()"); return; } - dap_chain_ledger_tx_notifier_t *l_notifier = DAP_NEW(dap_chain_ledger_tx_notifier_t); - if (!l_notifier){ - log_it(L_ERROR, "Can't allocate memory for notifier in dap_chain_ledger_tx_add_notify()"); + dap_chain_ledger_tx_notificator_t *l_notificator = DAP_NEW(dap_chain_ledger_tx_notificator_t); + if (!l_notificator){ + log_it(L_ERROR, "Can't allocate memory for notificator in dap_chain_ledger_tx_add_notify()"); return; } - l_notifier->callback = a_callback; - l_notifier->arg = a_arg; - PVT(a_ledger)->tx_add_notifiers = dap_list_append(PVT(a_ledger)->tx_add_notifiers, l_notifier); + l_notificator->callback = a_callback; + l_notificator->arg = a_arg; + PVT(a_ledger)->tx_add_notificators = dap_list_append(PVT(a_ledger)->tx_add_notificators, l_notificator); } void dap_chain_ledger_bridged_tx_notify_add(dap_ledger_t *a_ledger, dap_chain_ledger_bridged_tx_notify_t a_callback, void *a_arg) { if (!a_ledger || !a_callback) return; - dap_chain_ledger_bridged_tx_notificator_t *l_notifier = DAP_NEW_Z(dap_chain_ledger_bridged_tx_notificator_t); - if (!l_notifier) { - log_it(L_ERROR, "Can't allocate memory for notifier in dap_chain_ledger_tx_add_notify()"); + dap_chain_ledger_bridged_tx_notificator_t *l_notificator = DAP_NEW_Z(dap_chain_ledger_bridged_tx_notificator_t); + if (!l_notificator) { + log_it(L_ERROR, "Can't allocate memory for notificator in dap_chain_ledger_tx_add_notify()"); return; } - l_notifier->callback = a_callback; - l_notifier->arg = a_arg; - PVT(a_ledger)->bridged_tx_notificators = dap_list_append(PVT(a_ledger)->bridged_tx_notificators , l_notifier); + l_notificator->callback = a_callback; + l_notificator->arg = a_arg; + PVT(a_ledger)->bridged_tx_notificators = dap_list_append(PVT(a_ledger)->bridged_tx_notificators , l_notificator); } bool dap_chain_ledger_cache_enabled(dap_ledger_t *a_ledger) diff --git a/modules/chain/include/dap_chain.h b/modules/chain/include/dap_chain.h index faaae495e2860c9873252a8dbcf1df20edc776ae..3bb4fb224b94b5b649fd2539333e7e1e3dfda007 100644 --- a/modules/chain/include/dap_chain.h +++ b/modules/chain/include/dap_chain.h @@ -203,7 +203,7 @@ typedef struct dap_chain { dap_chain_callback_load_from_gdb callback_load_from_gdb; - dap_list_t *atom_notifiers; + dap_list_t *atom_notificators; // dap_chain_callback_notify_t callback_notify; // void *callback_notify_arg; @@ -216,24 +216,17 @@ typedef struct dap_chain { void * _inheritor; // inheritor object } dap_chain_t; -typedef struct dap_chain_atom_notifier { +typedef struct dap_chain_atom_notificator { dap_chain_callback_notify_t callback; void *arg; -} dap_chain_atom_notifier_t; +} dap_chain_atom_notificator_t; -typedef struct dap_chain_gdb_notifier { - dap_store_obj_callback_notify_t callback; - void *cb_arg; -} dap_chain_gdb_notifier_t; - -typedef struct dap_chain_pvt -{ +typedef struct dap_chain_pvt { dap_chain_t * chain; char * file_storage_dir; char * cs_name; bool cs_started; int celled; - dap_list_t *mempool_notifires; bool need_reorder; } dap_chain_pvt_t; @@ -272,4 +265,4 @@ bool dap_chain_get_atom_last_hash(dap_chain_t *a_chain, dap_hash_fast_t *a_atom_ ssize_t dap_chain_atom_save(dap_chain_t *a_chain, const uint8_t *a_atom, size_t a_atom_size, dap_chain_cell_id_t a_cell_id); int dap_cert_chain_file_save(dap_chain_datum_t *datum, char *net_name); const char* dap_chain_get_path(dap_chain_t *a_chain); -void dap_chain_add_mempool_notify_callback(dap_chain_t *a_chain, dap_store_obj_callback_notify_t a_callback, void *a_cb_arg); + diff --git a/modules/consensus/esbocs/dap_chain_cs_esbocs.c b/modules/consensus/esbocs/dap_chain_cs_esbocs.c index ec1fb8d891289911f25b662bb2e648384328a7ca..bcfea3ed21d9d2e3fd88cb7e3537537401f28272 100644 --- a/modules/consensus/esbocs/dap_chain_cs_esbocs.c +++ b/modules/consensus/esbocs/dap_chain_cs_esbocs.c @@ -84,7 +84,7 @@ static int s_callback_block_verify(dap_chain_cs_blocks_t *a_blocks, dap_chain_bl static uint256_t s_callback_get_minimum_fee(dap_chain_t *a_chain); static dap_enc_key_t *s_callback_get_sign_key(dap_chain_t *a_chain); static void s_callback_set_min_validators_count(dap_chain_t *a_chain, uint16_t a_new_value); -static void s_db_change_notifier(dap_global_db_instance_t *a_dbi, dap_store_obj_t *a_obj, void * a_arg); +static void s_db_change_notificator(dap_store_obj_t *a_obj, void * a_arg); static int s_cli_esbocs(int argc, char ** argv, char **str_reply); @@ -291,7 +291,7 @@ lb_err: return l_ret; } -static void s_new_atom_notifier(void *a_arg, UNUSED_ARG dap_chain_t *a_chain, UNUSED_ARG dap_chain_cell_id_t a_id, +static void s_new_atom_notificator(void *a_arg, UNUSED_ARG dap_chain_t *a_chain, UNUSED_ARG dap_chain_cell_id_t a_id, UNUSED_ARG void* a_atom, UNUSED_ARG size_t a_atom_size) { dap_chain_esbocs_session_t *l_session = a_arg; @@ -329,47 +329,14 @@ static int s_callback_created(dap_chain_t *a_chain, dap_config_t *a_chain_net_cf log_it(L_NOTICE, "No sign certificate provided for net %s, can't sign any blocks. This node can't be a consensus validator", a_chain->net_name); return -3; } - size_t l_esbocs_sign_pub_key_size = 0; - uint8_t *l_esbocs_sign_pub_key = dap_enc_key_serialize_pub_key(l_esbocs_pvt->blocks_sign_key, &l_esbocs_sign_pub_key_size); - - //Find order minimum fee dap_chain_net_t *l_net = dap_chain_net_by_id(a_chain->net_id); - char * l_gdb_group_str = dap_chain_net_srv_order_get_gdb_group(l_net); - size_t l_orders_count = 0; - dap_global_db_obj_t * l_orders = dap_global_db_get_all_sync(l_gdb_group_str, &l_orders_count); - DAP_DELETE(l_gdb_group_str); - dap_chain_net_srv_order_t *l_order_service = NULL; - for (size_t i = 0; i < l_orders_count; i++) { - if (l_orders[i].value_len < sizeof(dap_chain_net_srv_order_t)) { - log_it(L_ERROR, "Too small order %s with size %zu", l_orders[i].key, l_orders[i].value_len); - continue; - } - dap_chain_net_srv_order_t *l_order = (dap_chain_net_srv_order_t *)l_orders[i].value; - if (l_order->srv_uid.uint64 != DAP_CHAIN_NET_SRV_STAKE_POS_DELEGATE_ID) - continue; - dap_sign_t *l_order_sign = (dap_sign_t*)(l_order->ext_n_sign + l_order->ext_size); - uint8_t *l_order_sign_pkey = dap_sign_get_pkey(l_order_sign, NULL); - if (memcmp(l_esbocs_sign_pub_key, l_order_sign_pkey, l_esbocs_sign_pub_key_size) != 0) - continue; - if (!l_order_service) - l_order_service = l_order; - else if (l_order_service->ts_created < l_order->ts_created) - l_order_service = l_order; - } - if (l_order_service) - l_esbocs_pvt->minimum_fee = l_order_service->price; - dap_global_db_objs_delete(l_orders, l_orders_count); - - if (IS_ZERO_256(l_esbocs_pvt->minimum_fee)) { - log_it(L_ERROR, "No valid order found was signed by this validator deledgated key. Switch off validator mode."); - return -4; - } dap_chain_node_role_t l_role = dap_chain_net_get_role(l_net); if (l_role.enums > NODE_ROLE_MASTER) { log_it(L_NOTICE, "Node role is lower than master role, so this node can't be a consensus validator"); return -5; } - + size_t l_esbocs_sign_pub_key_size = 0; + uint8_t *l_esbocs_sign_pub_key = dap_enc_key_serialize_pub_key(l_esbocs_pvt->blocks_sign_key, &l_esbocs_sign_pub_key_size); dap_chain_addr_t l_my_signing_addr; dap_chain_addr_fill_from_key(&l_my_signing_addr, l_esbocs_pvt->blocks_sign_key, a_chain->net_id); if (!l_esbocs_pvt->poa_mode) { @@ -398,9 +365,9 @@ static int s_callback_created(dap_chain_t *a_chain, dap_config_t *a_chain_net_cf l_session->db_cluster = dap_global_db_cluster_add(dap_global_db_instance_get_default(), l_sync_group, l_sync_group, 72 * 3600, true, - s_db_change_notifier, l_session, DAP_GDB_MEMBER_ROLE_NOBODY, DAP_CLUSTER_ROLE_AUTONOMIC); DAP_DELETE(l_sync_group); + dap_global_db_cluster_add_notify_callback(l_session->db_cluster, s_db_change_notificator, l_session); dap_list_t *l_validators = dap_chain_net_srv_stake_get_validators(a_chain->net_id, false); for (dap_list_t *it = l_validators; it; it = it->next) { @@ -408,13 +375,44 @@ static int s_callback_created(dap_chain_t *a_chain, dap_config_t *a_chain_net_cf dap_global_db_cluster_member_add(l_session->db_cluster, l_addr, DAP_GDB_MEMBER_ROLE_ROOT); dap_chain_net_add_validator_to_clusters(l_net, l_addr); } + //Find order minimum fee + char * l_gdb_group_str = dap_chain_net_srv_order_get_gdb_group(l_net); + size_t l_orders_count = 0; + dap_global_db_obj_t * l_orders = dap_global_db_get_all_sync(l_gdb_group_str, &l_orders_count); + DAP_DELETE(l_gdb_group_str); + dap_chain_net_srv_order_t *l_order_service = NULL; + for (size_t i = 0; i < l_orders_count; i++) { + if (l_orders[i].value_len < sizeof(dap_chain_net_srv_order_t)) { + log_it(L_ERROR, "Too small order %s with size %zu", l_orders[i].key, l_orders[i].value_len); + continue; + } + dap_chain_net_srv_order_t *l_order = (dap_chain_net_srv_order_t *)l_orders[i].value; + if (l_order->srv_uid.uint64 != DAP_CHAIN_NET_SRV_STAKE_POS_DELEGATE_ID) + continue; + dap_sign_t *l_order_sign = (dap_sign_t*)(l_order->ext_n_sign + l_order->ext_size); + uint8_t *l_order_sign_pkey = dap_sign_get_pkey(l_order_sign, NULL); + if (memcmp(l_esbocs_sign_pub_key, l_order_sign_pkey, l_esbocs_sign_pub_key_size) != 0) + continue; + if (!l_order_service) + l_order_service = l_order; + else if (l_order_service->ts_created < l_order->ts_created) + l_order_service = l_order; + } + if (l_order_service) + l_esbocs_pvt->minimum_fee = l_order_service->price; + dap_global_db_objs_delete(l_orders, l_orders_count); + + if (IS_ZERO_256(l_esbocs_pvt->minimum_fee)) { + log_it(L_ERROR, "No valid order found was signed by this validator deledgated key. Switch off validator mode."); + return -4; + } pthread_mutexattr_t l_mutex_attr; pthread_mutexattr_init(&l_mutex_attr); pthread_mutexattr_settype(&l_mutex_attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&l_session->mutex, &l_mutex_attr); pthread_mutexattr_destroy(&l_mutex_attr); dap_stream_ch_chain_voting_in_callback_add(l_session, s_session_packet_in); - dap_chain_add_callback_notify(a_chain, s_new_atom_notifier, l_session); + dap_chain_add_callback_notify(a_chain, s_new_atom_notificator, l_session); s_session_round_new(l_session); log_it(L_INFO, "Init session for net:%s, chain:%s", a_chain->net_name, a_chain->name); @@ -1375,7 +1373,7 @@ static void s_session_candidate_precommit(dap_chain_esbocs_session_t *a_session, a_session->chain->net_name, a_session->chain->name, a_session->cur_round.id, a_message->hdr.attempt_num, l_candidate_hash_str); s_session_round_finish(a_session, l_store); - // ATTENTION: New round will be started by incoming atom notifier event + // ATTENTION: New round will be started by incoming atom notificator event } DAP_DEL_Z(l_candidate_hash_str); } @@ -1754,7 +1752,7 @@ static void s_session_directive_process(dap_chain_esbocs_session_t *a_session, d s_message_send(a_session, l_type, a_directive_hash, NULL, 0, a_session->cur_round.all_validators); } -static void s_db_change_notifier(dap_global_db_instance_t *a_dbi, dap_store_obj_t *a_obj, void *a_arg) +static void s_db_change_notificator(dap_store_obj_t *a_obj, void *a_arg) { dap_chain_esbocs_session_t *l_session = a_arg; dap_chain_addr_t *l_validator_addr = dap_chain_addr_from_str(a_obj->key); @@ -1790,12 +1788,12 @@ static int s_session_directive_apply(dap_chain_esbocs_directive_t *a_directive, const char *l_directive_hash_str = dap_chain_hash_fast_to_str_new(a_directive_hash); const char *l_key_hash_str = dap_chain_hash_fast_to_str_new(&l_key_addr->data.hash_fast); if (l_status == 1 && a_directive->type == DAP_CHAIN_ESBOCS_DIRECTIVE_KICK) { - // Offline will be set in gdb notifier for aim of sync supporting + // Offline will be set in gdb notificator for aim of sync supporting dap_global_db_set(l_penalty_group, l_key_str, NULL, 0, false, NULL, 0); log_it(L_MSG, "Applied %s directive to exclude validator %s with pkey hash %s from consensus", l_directive_hash_str, l_key_str, l_key_hash_str); } else if (l_status == -1 && a_directive->type == DAP_CHAIN_ESBOCS_DIRECTIVE_LIFT) { - // Online will be set in gdb notifier for aim of sync supporting + // Online will be set in gdb notificator for aim of sync supporting dap_global_db_del(l_penalty_group, l_key_str, NULL, 0); log_it(L_MSG, "Applied %s directive to include validator %s with pkey hash %s in consensus", l_directive_hash_str, l_key_str, l_key_hash_str); diff --git a/modules/net/dap_chain_net.c b/modules/net/dap_chain_net.c index 0eba2af78dd5155847ca12962534d31b3e3bff29..274c3b7ab4ec601263b11d1a9721db16c0a175a7 100644 --- a/modules/net/dap_chain_net.c +++ b/modules/net/dap_chain_net.c @@ -189,11 +189,8 @@ typedef struct dap_chain_net_pvt{ dap_interval_timer_t main_timer; pthread_mutex_t uplinks_mutex; - dap_list_t *gdb_notifiers; - - //Global DB clusters for different access groups. - dap_global_db_cluster_t *zerochain_cluster; - dap_global_db_cluster_t *mempool_cluster; + //Global DB clusters for different access groups. Notification with cluster contents changing + dap_global_db_cluster_t *mempool_clusters; // List of chains mempools dap_global_db_cluster_t *orders_cluster; dap_global_db_cluster_t *nodes_cluster; } dap_chain_net_pvt_t; @@ -246,7 +243,7 @@ static bool s_net_states_proc(dap_proc_thread_t *a_thread, void *a_arg); struct json_object *s_net_states_json_collect(dap_chain_net_t * l_net); static void s_net_states_notify(dap_chain_net_t * l_net); - +static void s_nodelist_change_notify(dap_store_obj_t *a_obj, void *a_arg); //static void s_net_proc_kill( dap_chain_net_t * a_net ); static int s_net_init(const char * a_net_name, uint16_t a_acl_idx); @@ -392,55 +389,6 @@ dap_chain_net_state_t dap_chain_net_get_target_state(dap_chain_net_t *a_net) return l_ret; } -/** - * @brief set s_srv_callback_notify - * - * @param a_callback dap_global_db_obj_callback_notify_t callback function - */ -void dap_chain_net_add_gdb_notify_callback(dap_chain_net_t *a_net, dap_store_obj_callback_notify_t a_callback, void *a_cb_arg) -{ - dap_chain_gdb_notifier_t *l_notifier = DAP_NEW(dap_chain_gdb_notifier_t); - if (!l_notifier) { - log_it(L_CRITICAL, "Memory allocation error"); - return; - } - l_notifier->callback = a_callback; - l_notifier->cb_arg = a_cb_arg; - PVT(a_net)->gdb_notifiers = dap_list_append(PVT(a_net)->gdb_notifiers, l_notifier); -} - -static void s_network_change_notify(dap_global_db_instance_t *a_dbi, dap_store_obj_t *a_obj, void *a_arg) -{ - if (!a_obj || !a_arg) - return; - dap_chain_net_t *l_net = (dap_chain_net_t *)a_arg; - for (dap_list_t *it = PVT(l_net)->gdb_notifiers; it; it = it->next) { - dap_chain_gdb_notifier_t *el = (dap_chain_gdb_notifier_t *)it->data; - if (!el) - continue; - if (el->callback) - el->callback(a_dbi, a_obj, el->cb_arg); - } - dap_chain_t *l_chain; - DL_FOREACH(l_net->pub.chains, l_chain) { - if (!l_chain) { - continue; - } - char *l_gdb_group_str = dap_chain_net_get_gdb_group_mempool_new(l_chain); - if (!strcmp(a_obj->group, l_gdb_group_str)) { - for (dap_list_t *it = DAP_CHAIN_PVT(l_chain)->mempool_notifires; it; it = it->next) { - dap_chain_gdb_notifier_t *el = (dap_chain_gdb_notifier_t *)it->data; - if (!el) - continue; - if (el->callback) - el->callback(a_dbi, a_obj, el->cb_arg); - } - } - DAP_DELETE(l_gdb_group_str); - } - -} - dap_chain_node_info_t *dap_get_balancer_link_from_cfg(dap_chain_net_t *a_net) { dap_chain_net_pvt_t *l_net_pvt = a_net ? PVT(a_net) : NULL; @@ -2219,8 +2167,6 @@ int s_net_init(const char * a_net_name, uint16_t a_acl_idx) } } - dap_chain_net_node_list_init(); - PVT(l_net)->bootstrap_nodes_count = 0; PVT(l_net)->bootstrap_nodes_addrs = DAP_NEW_SIZE(struct in_addr, l_bootstrap_nodes_len * sizeof(struct in_addr)); PVT(l_net)->bootstrap_nodes_ports = DAP_NEW_SIZE(uint16_t, l_bootstrap_nodes_len * sizeof(uint16_t)); @@ -2521,40 +2467,30 @@ int s_net_load(dap_chain_net_t *a_net) l_net_pvt->balancer_http = !dap_config_get_item_bool_default(l_cfg, "general", "use_dns_links", false); // Init GlobalDB clusters for mempool, service and nodes (with aliases) - // Zerochain mempool cluster - char *l_gdb_mempool_mask = dap_strdup_printf("%s.chain-%s.mempool", l_net->pub.gdb_groups_prefix, l_net->pub.chains->name); - l_net_pvt->zerochain_cluster = dap_global_db_cluster_add(dap_global_db_instance_get_default(), - l_net->pub.name, l_gdb_mempool_mask, - DAP_CHAIN_NET_MEMPOOL_TTL, true, - s_network_change_notify, l_net, - DAP_GDB_MEMBER_ROLE_USER, - DAP_CLUSTER_ROLE_EMBEDDED); - if (!l_net_pvt->zerochain_cluster) { - log_it(L_ERROR, "Can't initialize zerochain cluster for network %s", l_net->pub.name); - return -1; - } - dap_chain_net_add_poa_certs_to_cluster(l_net, l_net_pvt->zerochain_cluster); - DAP_DELETE(l_gdb_mempool_mask); - // Other chains mempool cluster - l_gdb_mempool_mask = dap_strdup_printf("%s.*.mempool", l_net->pub.gdb_groups_prefix); - l_net_pvt->mempool_cluster = dap_global_db_cluster_add(dap_global_db_instance_get_default(), - l_net->pub.name, l_gdb_mempool_mask, - DAP_CHAIN_NET_MEMPOOL_TTL, true, - s_network_change_notify, l_net, - DAP_GDB_MEMBER_ROLE_USER, - DAP_CLUSTER_ROLE_EMBEDDED); - if (!l_net_pvt->mempool_cluster) { - log_it(L_ERROR, "Can't initialize mempool cluster for network %s", l_net->pub.name); - return -1; + char *l_gdb_groups_mask = NULL; + DL_FOREACH(l_net->pub.chains, l_chain) { + // Personal chain mempool cluster for each chain + l_gdb_groups_mask = dap_strdup_printf("%s.chain-%s.mempool", l_net->pub.gdb_groups_prefix, l_chain->name); + dap_global_db_cluster_t *l_cluster = dap_global_db_cluster_add( + dap_global_db_instance_get_default(), + l_net->pub.name, l_gdb_groups_mask, + DAP_CHAIN_NET_MEMPOOL_TTL, true, + DAP_GDB_MEMBER_ROLE_USER, + DAP_CLUSTER_ROLE_EMBEDDED); + if (!l_cluster) { + log_it(L_ERROR, "Can't initialize mempool cluster for network %s", l_net->pub.name); + return -1; + } + dap_chain_net_add_poa_certs_to_cluster(l_net, l_cluster); + DAP_DELETE(l_gdb_groups_mask); + if (l_net->pub.chains == l_chain) + l_net_pvt->mempool_clusters = l_cluster; } - dap_chain_net_add_poa_certs_to_cluster(l_net, l_net_pvt->mempool_cluster); - DAP_DELETE(l_gdb_mempool_mask); // Service orders cluster - l_gdb_mempool_mask = dap_strdup_printf("%s.service.orders", l_net->pub.gdb_groups_prefix); + l_gdb_groups_mask = dap_strdup_printf("%s.service.orders", l_net->pub.gdb_groups_prefix); l_net_pvt->orders_cluster = dap_global_db_cluster_add(dap_global_db_instance_get_default(), - l_net->pub.name, l_gdb_mempool_mask, + l_net->pub.name, l_gdb_groups_mask, 0, true, - s_network_change_notify, l_net, DAP_GDB_MEMBER_ROLE_GUEST, DAP_CLUSTER_ROLE_EMBEDDED); if (!l_net_pvt->orders_cluster) { @@ -2562,15 +2498,14 @@ int s_net_load(dap_chain_net_t *a_net) return -1; } dap_chain_net_add_poa_certs_to_cluster(l_net, l_net_pvt->orders_cluster); - DAP_DELETE(l_gdb_mempool_mask); + DAP_DELETE(l_gdb_groups_mask); // Nodes and its aliases cluster l_net->pub.gdb_nodes = dap_strdup_printf("%s.nodes",l_net->pub.gdb_groups_prefix); l_net->pub.gdb_nodes_aliases = dap_strdup_printf("%s.nodes.aliases",l_net->pub.gdb_groups_prefix); - l_gdb_mempool_mask = dap_strdup_printf("%s.nodes*", l_net->pub.gdb_groups_prefix); + l_gdb_groups_mask = dap_strdup_printf("%s.nodes*", l_net->pub.gdb_groups_prefix); l_net_pvt->nodes_cluster = dap_global_db_cluster_add(dap_global_db_instance_get_default(), - l_net->pub.name, l_gdb_mempool_mask, + l_net->pub.name, l_gdb_groups_mask, 0, true, - s_network_change_notify, l_net, DAP_GDB_MEMBER_ROLE_GUEST, DAP_CLUSTER_ROLE_EMBEDDED); if (!l_net_pvt->nodes_cluster) { @@ -2578,7 +2513,8 @@ int s_net_load(dap_chain_net_t *a_net) return -1; } dap_chain_net_add_poa_certs_to_cluster(l_net, l_net_pvt->nodes_cluster); - DAP_DELETE(l_gdb_mempool_mask); + dap_chain_net_add_nodelist_notify_callback(l_net, s_nodelist_change_notify, l_net); + DAP_DELETE(l_gdb_groups_mask); DL_FOREACH(l_net->pub.chains, l_chain) if (l_chain->callback_created) @@ -2611,6 +2547,47 @@ int s_net_load(dap_chain_net_t *a_net) return 0; } +void dap_chain_add_mempool_notify_callback(dap_chain_t *a_chain, dap_store_obj_callback_notify_t a_callback, void *a_cb_arg) +{ + dap_chain_net_t *l_net = dap_chain_net_by_id(a_chain->net_id); + dap_global_db_cluster_t *l_mempool = PVT(l_net)->mempool_clusters; + dap_chain_t *l_chain; + DL_FOREACH(l_net->pub.chains, l_chain) { + if (l_chain == a_chain) + dap_global_db_cluster_add_notify_callback(l_mempool, a_callback, a_cb_arg); + assert(l_mempool); + l_mempool = l_mempool->next; + } +} + +static void s_nodelist_change_notify(dap_store_obj_t *a_obj, void *a_arg) +{ + dap_chain_net_t *l_net = a_arg; + dap_return_if_fail(a_obj->type == DAP_GLOBAL_DB_OPTYPE_ADD && !dap_strcmp(l_net->pub.gdb_nodes, a_obj->group)); + dap_chain_node_info_t *l_node_info = (dap_chain_node_info_t *)a_obj->value; + assert(dap_chain_node_info_get_size(l_node_info) == a_obj->value_len); + char l_node_ipv4_str[INET_ADDRSTRLEN]={ '\0' }, l_node_ipv6_str[INET6_ADDRSTRLEN]={ '\0' }; + inet_ntop(AF_INET, &l_node_info->hdr.ext_addr_v4, l_node_ipv4_str, INET_ADDRSTRLEN); + inet_ntop(AF_INET6, &l_node_info->hdr.ext_addr_v6, l_node_ipv6_str, INET6_ADDRSTRLEN); + char l_ts[128] = { '\0' }; + dap_gbd_time_to_str_rfc822(l_ts, sizeof(l_ts), a_obj->timestamp); + + log_it(L_MSG, "Add node "NODE_ADDR_FP_STR" ipv4 %s(ipv6 %s):%s at %s to network\n", + NODE_ADDR_FP_ARGS_S(l_node_info->hdr.address), + l_node_ipv4_str, dap_itoa(l_node_info->hdr.ext_port), + l_ts, l_net->pub.name); +} + +void dap_chain_net_add_nodelist_notify_callback(dap_chain_net_t *a_net, dap_store_obj_callback_notify_t a_callback, void *a_cb_arg) +{ + dap_global_db_cluster_add_notify_callback(PVT(a_net)->nodes_cluster, a_callback, a_cb_arg); +} + +void dap_chain_net_srv_order_add_notify_callback(dap_chain_net_t *a_net, dap_store_obj_callback_notify_t a_callback, void *a_cb_arg) +{ + dap_global_db_cluster_add_notify_callback(PVT(a_net)->orders_cluster, a_callback, a_cb_arg); +} + int dap_chain_net_add_poa_certs_to_cluster(dap_chain_net_t *a_net, dap_global_db_cluster_t *a_cluster) { dap_return_val_if_fail(a_net && a_cluster, -1); @@ -2624,7 +2601,8 @@ int dap_chain_net_add_poa_certs_to_cluster(dap_chain_net_t *a_net, dap_global_db bool dap_chain_net_add_validator_to_clusters(dap_chain_net_t *a_net, dap_stream_node_addr_t *a_addr) { - bool l_ret = dap_global_db_cluster_member_add(PVT(a_net)->mempool_cluster, a_addr, DAP_GDB_MEMBER_ROLE_ROOT); + // Zerochain is always first, so clusters->next is mainchain cluster + bool l_ret = dap_global_db_cluster_member_add(PVT(a_net)->mempool_clusters->next, a_addr, DAP_GDB_MEMBER_ROLE_ROOT); return !l_ret ? false : dap_global_db_cluster_member_add(PVT(a_net)->orders_cluster, a_addr, DAP_GDB_MEMBER_ROLE_USER); } diff --git a/modules/net/dap_chain_net_node_list.c b/modules/net/dap_chain_net_node_list.c index 8e01e8dec2f8b945584346d4c5005f289e58d499..509e6dca1ff2009bb5a20a002683199945f6fd15 100644 --- a/modules/net/dap_chain_net_node_list.c +++ b/modules/net/dap_chain_net_node_list.c @@ -254,45 +254,3 @@ int dap_chain_net_node_list_request(dap_chain_net_t *a_net, dap_chain_node_info_ s_node_list_request_deinit(l_node_list_request); return ret; } -static void s_node_list_callback_notify(dap_global_db_instance_t *a_dbi, dap_store_obj_t *a_obj, void *a_arg) -{ - if (!a_arg || !a_obj || !a_obj->key) - return; - dap_chain_net_t *l_net = (dap_chain_net_t *)a_arg; - assert(l_net); - size_t l_size_obj_need = (sizeof(dap_chain_node_info_t)); - - if (!dap_strcmp(a_obj->group, l_net->pub.gdb_nodes)) { - if (a_obj->value && a_obj->type == DAP_GLOBAL_DB_OPTYPE_ADD) { - dap_chain_node_info_t *l_node_info = (dap_chain_node_info_t *)a_obj->value; - size_t l_size_obj = dap_chain_node_info_get_size(l_node_info); - if (l_size_obj_need == l_size_obj) { - char l_node_ipv4_str[INET_ADDRSTRLEN]={ '\0' }, l_node_ipv6_str[INET6_ADDRSTRLEN]={ '\0' }; - inet_ntop(AF_INET, &l_node_info->hdr.ext_addr_v4, l_node_ipv4_str, INET_ADDRSTRLEN); - inet_ntop(AF_INET6, &l_node_info->hdr.ext_addr_v6, l_node_ipv6_str, INET6_ADDRSTRLEN); - char l_ts[128] = { '\0' }; - dap_gbd_time_to_str_rfc822(l_ts, sizeof(l_ts), a_obj->timestamp); - - log_it(L_MSG, "Add node "NODE_ADDR_FP_STR" %s %s at %s\n", - NODE_ADDR_FP_ARGS_S(l_node_info->hdr.address), - l_node_ipv4_str, dap_itoa(l_node_info->hdr.ext_port), - l_ts); - } else { - dap_global_db_del_sync(a_obj->group, a_obj->key); - log_it(L_NOTICE, "Wrong size! data size %lu need - (%lu) %s removed ",l_size_obj, - l_size_obj_need, a_obj->key); - } - } - } -} - -int dap_chain_net_node_list_init() -{ - uint16_t l_net_count = 0; - dap_chain_net_t **l_net_list = dap_chain_net_list(&l_net_count); - for (uint16_t i = 0; i < l_net_count; i++) { - dap_chain_net_add_gdb_notify_callback(l_net_list[i], s_node_list_callback_notify, l_net_list[i]); - } - return 0; -} - diff --git a/modules/net/include/dap_chain_net.h b/modules/net/include/dap_chain_net.h index 48dce658f92f88acf5a1e5e1827512154fec5ce4..2610d62eb62baee70523cc104f560a62233fa1b1 100644 --- a/modules/net/include/dap_chain_net.h +++ b/modules/net/include/dap_chain_net.h @@ -183,7 +183,9 @@ dap_chain_net_t **dap_chain_net_list(uint16_t *a_size); int dap_chain_net_verify_datum_for_add(dap_chain_t *a_chain, dap_chain_datum_t *a_datum, dap_hash_fast_t *a_datum_hash); char *dap_chain_net_verify_datum_err_code_to_str(dap_chain_datum_t *a_datum, int a_code); -void dap_chain_net_add_gdb_notify_callback(dap_chain_net_t *a_net, dap_store_obj_callback_notify_t a_callback, void *a_cb_arg); +void dap_chain_add_mempool_notify_callback(dap_chain_t *a_chain, dap_store_obj_callback_notify_t a_callback, void *a_cb_arg); +void dap_chain_net_add_nodelist_notify_callback(dap_chain_net_t *a_net, dap_store_obj_callback_notify_t a_callback, void *a_cb_arg); +void dap_chain_net_srv_order_add_notify_callback(dap_chain_net_t *a_net, dap_store_obj_callback_notify_t a_callback, void *a_cb_arg); /** * @brief dap_chain_datum_list diff --git a/modules/net/srv/dap_chain_net_srv_order.c b/modules/net/srv/dap_chain_net_srv_order.c index a36bf37f8e2160b695aa16f8c345efdb3cc589b1..810d334befdd7969e66fd389f8d7cf344d571378 100644 --- a/modules/net/srv/dap_chain_net_srv_order.c +++ b/modules/net/srv/dap_chain_net_srv_order.c @@ -63,70 +63,12 @@ struct dap_order_notify { void *cb_arg; }; -static dap_list_t *s_order_notify_callbacks = NULL; -static void s_srv_order_callback_notify(dap_global_db_instance_t *a_dbi, dap_store_obj_t *a_obj, void *a_arg); - -static dap_timerfd_t *s_timer_order_check_decree_sign = NULL; -static void s_srv_order_check_decree_sign_timer() { - uint32_t l_unverified_orders_lifetime = dap_config_get_item_uint32_default(g_config, "srv", "unverified_orders_lifetime", 21600); - dap_time_t l_time_cut_off = dap_time_now(); - l_time_cut_off -= l_unverified_orders_lifetime; // 6 Hours; - uint16_t l_net_count = 0; - dap_chain_net_t **l_net_list = dap_chain_net_list(&l_net_count); - for (uint16_t i = 0; i < l_net_count; i++) { - if (dap_chain_net_get_role(l_net_list[i]).enums == NODE_ROLE_MASTER) { - char *l_order_group = dap_chain_net_srv_order_get_gdb_group(l_net_list[i]); - size_t l_order_count = 0; - dap_global_db_obj_t *l_orders = dap_global_db_get_all_sync(l_order_group, &l_order_count); - for (size_t j = 0; j < l_order_count; j++) { - dap_chain_net_srv_order_t *l_order = (dap_chain_net_srv_order_t *) (l_orders[j].value); - if (!l_order) - continue; - if (l_order->ts_created < l_time_cut_off) { - dap_sign_t *l_sign = (dap_sign_t *) (l_order->ext_n_sign + l_order->ext_size); - dap_hash_fast_t l_sign_pkey_hash = {0}; - dap_sign_get_pkey_hash(l_sign, &l_sign_pkey_hash); - dap_chain_addr_t l_signed_addr = {0}; - dap_chain_addr_fill(&l_signed_addr, l_sign->header.type, &l_sign_pkey_hash, l_net_list[i]->pub.id); - if (!dap_chain_net_srv_stake_key_delegated(&l_signed_addr)) { - char *l_pkey_hash_str = dap_hash_fast_to_str_new(&l_sign_pkey_hash); - log_it(L_NOTICE, "Order %s signed by the non-delegated public key %s. Order deleted", - l_orders[j].key, - l_pkey_hash_str); - DAP_DELETE(l_pkey_hash_str); - dap_global_db_del(l_order_group, l_orders[j].key, NULL, NULL); - } - } - } - dap_global_db_objs_delete(l_orders, l_order_count); - DAP_DELETE(l_order_group); - } - } - DAP_DELETE(l_net_list); -} - /** * @brief dap_chain_net_srv_order_init * @return */ int dap_chain_net_srv_order_init() { - uint16_t l_net_count = 0; - dap_chain_net_t **l_net_list = dap_chain_net_list(&l_net_count); - for (uint16_t i = 0; i < l_net_count; i++) { - dap_chain_net_add_gdb_notify_callback(l_net_list[i], s_srv_order_callback_notify, l_net_list[i]); - } - //geoip_info_t *l_ipinfo = chain_net_geoip_get_ip_info("8.8.8.8"); - if (!dap_config_get_item_bool_default(g_config, "srv", "allow_unverified_orders", true)) { - uint32_t l_unverified_orders_lifetime = dap_config_get_item_uint32_default(g_config, "srv", "unverified_orders_lifetime", 21600); // 6 Hours - s_timer_order_check_decree_sign = dap_interval_timer_create(l_unverified_orders_lifetime * 1000, - (dap_timer_callback_t)s_srv_order_check_decree_sign_timer, - NULL); - } else { - log_it(L_DEBUG, "A mode is enabled that disables verification that the signature was put by " - "the node by the validator."); - } - DAP_DELETE(l_net_list); return 0; } @@ -135,7 +77,7 @@ int dap_chain_net_srv_order_init() */ void dap_chain_net_srv_order_deinit() { - dap_list_free_full(s_order_notify_callbacks, NULL); + } size_t dap_chain_net_srv_order_get_size(dap_chain_net_srv_order_t *a_order) @@ -638,74 +580,7 @@ void dap_chain_net_srv_order_dump_to_string(dap_chain_net_srv_order_t *a_order,d dap_string_append_printf(a_str_out, " pkey: %s\n", l_sign_pkey_hash_str); dap_string_append_printf(a_str_out, " units: %zu\n", a_order->units); DAP_DELETE(l_sign_pkey_hash_str); - // order state -/* { - int l_order_state = get_order_state(a_order->node_addr); - // if order is not tested - if(l_order_state == -1) - dap_string_append_printf(a_str_out, " \"State\":\"unknown\"\n"); - // if order off-line - else if(l_order_state == 1) - dap_string_append_printf(a_str_out, " \"State\":\"available\"\n"); - // if order on-line - else - dap_string_append_printf(a_str_out, " \"State\":\"not available\"\n"); - }*/ DAP_DELETE(l_hash_str); DAP_DELETE(l_ext_out); } } - -static void s_srv_order_callback_notify(dap_global_db_instance_t *a_dbi, dap_store_obj_t *a_obj, void *a_arg) -{ - if (!a_arg || !a_obj || !a_obj->key) - return; - dap_chain_net_t *l_net = (dap_chain_net_t *)a_arg; - assert(l_net); - char *l_gdb_group_str = dap_chain_net_srv_order_get_gdb_group(l_net); - - if (!dap_strcmp(a_obj->group, l_gdb_group_str)) { - for (dap_list_t *it = s_order_notify_callbacks; it; it = it->next) { - struct dap_order_notify *l_notifier = (struct dap_order_notify *)it->data; - if ((l_notifier->net == NULL || l_notifier->net == l_net) && - l_notifier->callback) { - l_notifier->callback(a_dbi, a_obj, l_notifier->cb_arg); - } - } - bool l_allow_unsigned_orders = dap_config_get_item_bool_default(g_config, "srv", "allow_unsigned_orders", false); - if (a_obj->value && a_obj->type == DAP_GLOBAL_DB_OPTYPE_ADD) { - dap_chain_net_srv_order_t *l_order = (dap_chain_net_srv_order_t *)a_obj->value; - if (l_order->version != 3) { - log_it(L_NOTICE, "Order %s removed version != 3.", a_obj->key); - dap_global_db_del_sync(a_obj->group, a_obj->key); - } else { - if (l_allow_unsigned_orders) { - log_it(L_DEBUG, "The mode that disables verification of the order signature is enabled."); - } else { - dap_sign_t *l_sign = (dap_sign_t *) (l_order->ext_n_sign + l_order->ext_size); - size_t l_max_size = a_obj->value_len - sizeof(dap_chain_net_srv_order_t) - l_order->ext_size; - int l_verify = dap_sign_verify_all(l_sign, l_max_size, l_order, - sizeof(dap_chain_net_srv_order_t) + l_order->ext_size); - if (l_verify) { - log_it(L_ERROR, "Order unverified, err %d", l_verify); - dap_global_db_del_sync(a_obj->group, a_obj->key); - } - } - } - } - } - DAP_DELETE(l_gdb_group_str); -} - -void dap_chain_net_srv_order_add_notify_callback(dap_chain_net_t *a_net, dap_store_obj_callback_notify_t a_callback, void *a_cb_arg) -{ - struct dap_order_notify *l_notifier = DAP_NEW(struct dap_order_notify); - if (!l_notifier) { - log_it(L_CRITICAL, "Memory allocation error"); - return; - } - l_notifier->net = a_net; - l_notifier->callback = a_callback; - l_notifier->cb_arg = a_cb_arg; - s_order_notify_callbacks = dap_list_append(s_order_notify_callbacks, l_notifier); -} diff --git a/modules/net/srv/include/dap_chain_net_srv_order.h b/modules/net/srv/include/dap_chain_net_srv_order.h index 46e12790aa8bc11a8bac3874a6c2d926757a419e..e2c7e4122561f4a849ae34cc8353a654f2985b8a 100644 --- a/modules/net/srv/include/dap_chain_net_srv_order.h +++ b/modules/net/srv/include/dap_chain_net_srv_order.h @@ -169,13 +169,3 @@ DAP_STATIC_INLINE char * dap_chain_net_srv_order_get_gdb_group(dap_chain_net_t * { return a_net ? dap_strdup_printf("%s.service.orders",a_net->pub.gdb_groups_prefix) : NULL; } - -/** -* @brief dap_chain_net_srv_order_get_gdb_group_mempool -* @param l_chain -* @return -*/ -DAP_STATIC_INLINE char * dap_chain_net_srv_order_get_nodelist_group(dap_chain_net_t * a_net) -{ - return a_net ? dap_strdup_printf("%s.service.orders.static_nodelist",a_net->pub.gdb_groups_prefix) : NULL; -} diff --git a/modules/service/datum/dap_chain_net_srv_datum.c b/modules/service/datum/dap_chain_net_srv_datum.c index 3c18fe87ad38a2c831d5e89c57d4def373123f7b..190df48fdd2a8f6821eda60c3d6e9510ae5e81e0 100644 --- a/modules/service/datum/dap_chain_net_srv_datum.c +++ b/modules/service/datum/dap_chain_net_srv_datum.c @@ -36,7 +36,7 @@ static dap_chain_net_srv_t *s_srv_datum = NULL; static int s_srv_datum_cli(int argc, char ** argv, char **a_str_reply); -void s_order_notficator(dap_global_db_instance_t *a_dbi, dap_store_obj_t *a_obj, void *a_arg); +void s_order_notficator(dap_store_obj_t *a_obj, void *a_arg); int dap_chain_net_srv_datum_init() { @@ -195,7 +195,7 @@ static int s_srv_datum_cli(int argc, char ** argv, char **a_str_reply) { * @param a_value * @param a_value_len */ -void s_order_notficator(dap_global_db_instance_t *a_dbi, dap_store_obj_t *a_obj, void *a_arg) +void s_order_notficator(dap_store_obj_t *a_obj, void *a_arg) { if (a_obj->type == DAP_GLOBAL_DB_OPTYPE_DEL) return; diff --git a/modules/type/dag/dap_chain_cs_dag.c b/modules/type/dag/dap_chain_cs_dag.c index 003da1bff4121295607cd0a98e211052e2206698..93c5224e6a99baf1bd510f0c02a1bf685830cb9d 100644 --- a/modules/type/dag/dap_chain_cs_dag.c +++ b/modules/type/dag/dap_chain_cs_dag.c @@ -183,7 +183,7 @@ void dap_chain_cs_dag_deinit(void) } -static void s_round_changes_notify(dap_global_db_instance_t *a_dbi, dap_store_obj_t *a_obj, void *a_arg) +static void s_round_changes_notify(dap_store_obj_t *a_obj, void *a_arg) { dap_chain_cs_dag_t *l_dag = (dap_chain_cs_dag_t *)a_arg; assert(l_dag); @@ -203,14 +203,12 @@ static bool s_dag_rounds_events_iter(dap_global_db_instance_t *a_dbi, const size_t a_values_current, const size_t a_values_count, dap_store_obj_t *a_values, void *a_arg) { - UNUSED(a_group); - UNUSED(a_values_current); dap_return_val_if_pass(a_rc != DAP_GLOBAL_DB_RC_SUCCESS, false); for (size_t i = 0; i < a_values_count; i++) { dap_store_obj_t *l_obj_cur = a_values + i; l_obj_cur->type = DAP_GLOBAL_DB_OPTYPE_ADD; - s_round_changes_notify(a_dbi, a_values + i, a_arg); + s_round_changes_notify(a_values + i, a_arg); } return true; } @@ -324,8 +322,8 @@ static int s_chain_cs_dag_new(dap_chain_t * a_chain, dap_config_t * a_chain_cfg) l_net->pub.gdb_groups_prefix, a_chain->name, 0LLU); dap_global_db_cluster_t *l_dag_cluster = dap_global_db_cluster_add(dap_global_db_instance_get_default(), l_dag->gdb_group_events_round_new, l_dag->gdb_group_events_round_new, - 900, true, s_round_changes_notify, l_dag, - DAP_GDB_MEMBER_ROLE_NOBODY, DAP_CLUSTER_ROLE_AUTONOMIC); + 900, true, DAP_GDB_MEMBER_ROLE_NOBODY, DAP_CLUSTER_ROLE_AUTONOMIC); + dap_global_db_cluster_add_notify_callback(l_dag_cluster, s_round_changes_notify, l_dag); dap_chain_net_add_poa_certs_to_cluster(l_net, l_dag_cluster); byte_t *l_current_round = dap_global_db_get_sync(l_dag->gdb_group_events_round_new, DAG_ROUND_CURRENT_KEY, NULL, NULL, NULL); l_dag->round_current = l_current_round ? *(uint64_t*)l_current_round : 0; diff --git a/modules/type/none/dap_chain_cs_none.c b/modules/type/none/dap_chain_cs_none.c index f06e892f69c19013ca14ce565b07f4965521834c..3e0da73b6be965599ac89316ead333a09c7fe939 100644 --- a/modules/type/none/dap_chain_cs_none.c +++ b/modules/type/none/dap_chain_cs_none.c @@ -115,13 +115,13 @@ static void s_nonconsensus_callback_purge(dap_chain_t *a_chain) } -static void s_nonconsensus_callback_mempool_notify(dap_global_db_instance_t UNUSED_ARG *a_dbi, dap_store_obj_t *a_obj, void *a_arg) +static void s_nonconsensus_callback_mempool_notify(dap_store_obj_t *a_obj, void *a_arg) { if (a_obj->type == DAP_GLOBAL_DB_OPTYPE_ADD) dap_chain_node_mempool_process_all(a_arg, false); } -static void s_changes_callback_notify(dap_global_db_instance_t UNUSED_ARG *a_dbi, dap_store_obj_t *a_obj, void *a_arg) +static void s_changes_callback_notify(dap_store_obj_t *a_obj, void *a_arg) { dap_return_if_fail(a_obj->type == DAP_GLOBAL_DB_OPTYPE_ADD && a_obj->value_len && a_obj->value); dap_chain_t *l_chain = a_arg; @@ -159,14 +159,15 @@ static int s_cs_callback_new(dap_chain_t *a_chain, dap_config_t UNUSED_ARG *a_ch l_nochain_priv->group_datums = dap_chain_net_get_gdb_group_nochain_new(a_chain); // Add group prefix that will be tracking all changes - if (dap_global_db_cluster_add(dap_global_db_instance_get_default(), l_net->pub.name, - l_nochain_priv->group_datums, 0, true, - s_changes_callback_notify, a_chain, - DAP_GDB_MEMBER_ROLE_USER, DAP_CLUSTER_ROLE_EMBEDDED)) { + dap_global_db_cluster_t *l_nonconsensus_cluster = + dap_global_db_cluster_add(dap_global_db_instance_get_default(), l_net->pub.name, + l_nochain_priv->group_datums, 0, true, + DAP_GDB_MEMBER_ROLE_USER, DAP_CLUSTER_ROLE_EMBEDDED); + if (!l_nonconsensus_cluster) { log_it(L_ERROR, "Can't create global DB cluster for synchronization"); return -3; } - + dap_global_db_cluster_add_notify_callback(l_nonconsensus_cluster, s_changes_callback_notify, a_chain); dap_chain_add_mempool_notify_callback(a_chain, s_nonconsensus_callback_mempool_notify, a_chain); pthread_cond_init(&l_nochain_priv->load_cond, NULL); @@ -369,11 +370,11 @@ static dap_chain_atom_verify_res_t s_nonconsensus_callback_atom_add(dap_chain_t dap_hash_fast(l_datum->data,l_datum->header.data_size,&l_hash_item->datum_data_hash ); dap_chain_hash_fast_to_str(&l_hash_item->datum_data_hash, l_hash_item->key, sizeof(l_hash_item->key)); DL_APPEND(l_nochain_priv->hash_items, l_hash_item); - if (!l_nochain_priv->is_load_mode && a_chain->atom_notifiers) { + if (!l_nochain_priv->is_load_mode && a_chain->atom_notificators) { 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); + DL_FOREACH(a_chain->atom_notificators, l_iter) { + dap_chain_atom_notificator_t *l_notificator = (dap_chain_atom_notificator_t*)l_iter->data; + l_notificator->callback(l_notificator->arg, a_chain, (dap_chain_cell_id_t){ }, (void*)l_datum, l_datum_size); } } return ATOM_ACCEPT;