diff --git a/modules/type/blocks/dap_chain_cs_blocks.c b/modules/type/blocks/dap_chain_cs_blocks.c index 43623741f63d91337d74dd1268433c41c01fc12f..b18d0f101462ccaa28797bb02652d6f01352e37e 100644 --- a/modules/type/blocks/dap_chain_cs_blocks.c +++ b/modules/type/blocks/dap_chain_cs_blocks.c @@ -66,6 +66,7 @@ typedef struct dap_chain_cs_blocks_pvt dap_chain_block_cache_t * block_cache_first; // Mapped area start dap_chain_block_cache_t * block_cache_last; // Last block in mapped area dap_chain_hash_fast_t genesis_block_hash; + dap_chain_hash_fast_t static_genesis_block_hash; uint64_t blocks_count; uint64_t difficulty; @@ -244,7 +245,13 @@ int dap_chain_cs_blocks_new(dap_chain_t * a_chain, dap_config_t * a_chain_config } } l_cs_blocks_pvt->is_celled = dap_config_get_item_bool_default(a_chain_config,"blocks","is_celled",false); - + const char * l_static_genesis_blocks_hash_str = dap_config_get_item_str_default(a_chain_config,"blocks","static_genesis_block",NULL); + if ( l_static_genesis_blocks_hash_str ){ + int lhr; + if ( (lhr= dap_chain_hash_fast_from_str(l_static_genesis_blocks_hash_str,&l_cs_blocks_pvt->static_genesis_block_hash) )!= 0 ){ + log_it( L_ERROR, "Can't read hash from static_genesis_block \"%s\", ret code %d ", l_static_genesis_blocks_hash_str, lhr); + } + } l_cs_blocks_pvt->chunks = dap_chain_block_chunks_create(l_cs_blocks); l_cs_blocks_pvt->fill_timeout = dap_config_get_item_uint64_default(a_chain_config, "blocks", "fill_timeout", 60) * 1000; // 1 min @@ -1093,6 +1100,8 @@ static dap_chain_atom_verify_res_t s_callback_atom_verify(dap_chain_t * a_chain, dap_chain_hash_fast_t l_block_anchor_hash = {0}; uint64_t l_nonce = 0; uint64_t l_nonce2 = 0; + dap_chain_hash_fast_t l_block_hash; + dap_chain_block_meta_extract(l_meta, l_meta_count, &l_block_prev_hash, &l_block_anchor_hash, @@ -1112,10 +1121,17 @@ static dap_chain_atom_verify_res_t s_callback_atom_verify(dap_chain_t * a_chain, // genesis or seed mode if (l_is_genesis) { if (!l_blocks_pvt->blocks) { + dap_hash_fast(l_block, a_atom_size, &l_block_hash); if (s_seed_mode) log_it(L_NOTICE, "Accepting new genesis block"); - else + + else if(dap_hash_fast_compare(&l_block_hash,&l_blocks_pvt->static_genesis_block_hash) + &&!dap_hash_fast_is_blank(&l_block_hash)) log_it(L_NOTICE, "Accepting static genesis block"); + else{ + log_it(L_WARNING,"Cant accept genesis block: seed mode not enabled or hash mismatch with static genesis block in configuration"); + return ATOM_REJECT; + } } else { log_it(L_WARNING,"Cant accept genesis block: already present data in blockchain"); return ATOM_REJECT;