@@ -827,11 +827,13 @@ bool Blockchain::get_block_by_hash(const crypto::hash &h, block &blk, bool *orph
827
827
// last DIFFICULTY_BLOCKS_COUNT blocks and passes them to next_difficulty,
828
828
// returning the result of that call. Ignores the genesis block, and can use
829
829
// less blocks than desired if there aren't enough.
830
- difficulty_type Blockchain::get_difficulty_for_next_block ()
830
+ difficulty_type Blockchain::get_difficulty_for_next_block () {
831
+ return get_difficulty_for_next_blockV2 (true );
832
+ }
833
+ difficulty_type Blockchain::get_difficulty_for_next_blockV2 (bool isDiardiMiner)
831
834
{
832
835
uint64_t current_height = m_db->height ();
833
836
uint8_t hard_fork_version = get_ideal_hard_fork_version (current_height);
834
-
835
837
if (m_fixed_difficulty)
836
838
{
837
839
return m_db->height () ? m_fixed_difficulty : 1 ;
@@ -1374,6 +1376,56 @@ bool Blockchain::validate_diardi_miner_v2(const block& b) {
1374
1376
return true ;
1375
1377
}
1376
1378
// ------------------------------------------------------------------
1379
+ // Validate existing is a block mined by diardi ops or not
1380
+ // 1. Check is a diaradi block returns true if it isn't
1381
+ // 2. Check if block is diardi miner return false if it isn't
1382
+ // 3. Check for block 4 behind return false if not valid
1383
+ // 4. Chweck if miner is mining 4 blocks behind return false if is
1384
+ // 5. Will return true if pass all checks
1385
+ bool Blockchain::validate_miner_diardiV2 (const block& b) {
1386
+ LOG_PRINT_L3 (" Blockchain::" << __func__);
1387
+
1388
+ uint8_t version = b.major_version ;
1389
+ uint64_t block_height = (b.miner_tx .vin .size () < 1 || b.miner_tx .vin [0 ].type () != typeid (txin_gen)) ? m_db->height () : boost::get<txin_gen>(b.miner_tx .vin [0 ]).height ;
1390
+ bool isDiardiBlock = (version >= 13 && block_height % 4 == 0 );
1391
+ if (!isDiardiBlock) return true ;
1392
+
1393
+ std::list<std::string> diardi_miners_list = diardi_addresses_v2 (m_nettype);
1394
+ std::string vM;
1395
+ public_key diardiKey;
1396
+ for (auto const & sM : diardi_miners_list) {
1397
+ public_key pKey = boost::get<txout_to_key>(b.miner_tx .vout .back ().target ).key ;
1398
+ if (validate_diardi_reward_key (block_height, sM , b.miner_tx .vout .size () - 1 , pKey, m_nettype))
1399
+ {
1400
+ vM = sM ;
1401
+ diardiKey = pKey;
1402
+ break ;
1403
+ }
1404
+ }
1405
+
1406
+ if (vM.empty ()) {
1407
+ return false ;
1408
+ }
1409
+
1410
+ uint64_t pDh = block_height - 4 ;
1411
+
1412
+ crypto::hash oDh = crypto::null_hash;
1413
+ oDh = m_db->get_block_hash_from_height (pDh);
1414
+
1415
+ cryptonote::block oDb;
1416
+ bool oOb = false ;
1417
+
1418
+ bool getOldBlock = get_block_by_hash (oDh, oDb, &oOb);
1419
+
1420
+ if (!getOldBlock) return true ;
1421
+
1422
+ if (validate_diardi_reward_key (pDh, vM, oDb.miner_tx .vout .size () - 1 , boost::get<txout_to_key>(oDb.miner_tx .vout .back ().target ).key , m_nettype)) {
1423
+ return false ;
1424
+ }
1425
+
1426
+ return true ;
1427
+ }
1428
+ // ------------------------------------------------------------------
1377
1429
// This function validates the miner transaction reward
1378
1430
bool Blockchain::validate_miner_transaction (const block& b, size_t cumulative_block_weight, uint64_t fee, uint64_t & base_reward, uint64_t already_generated_coins, bool &partial_block_reward, uint8_t version)
1379
1431
{
@@ -1394,6 +1446,7 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
1394
1446
}
1395
1447
1396
1448
uint64_t median_weight;
1449
+ uint64_t block_height = m_db->height ();
1397
1450
if (version >= HF_VERSION_EFFECTIVE_SHORT_TERM_MEDIAN_IN_PENALTY)
1398
1451
{
1399
1452
median_weight = m_current_block_cumul_weight_median;
@@ -1404,25 +1457,25 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
1404
1457
get_last_n_blocks_weights (last_blocks_weights, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
1405
1458
median_weight = epee::misc_utils::median (last_blocks_weights);
1406
1459
}
1407
- if (!get_block_reward (median_weight, cumulative_block_weight, already_generated_coins, base_reward, version, m_db-> height () ))
1460
+ if (!get_block_reward (median_weight, cumulative_block_weight, already_generated_coins, base_reward, version, block_height ))
1408
1461
{
1409
1462
MERROR_VER (" block weight " << cumulative_block_weight << " is bigger than allowed for this blockchain" );
1410
1463
return false ;
1411
1464
}
1412
1465
1413
- if ((version >= 2 ) && (version <= 12 ) && (m_db-> height () >= 16 )) {
1466
+ if ((version >= 2 ) && (version <= 12 ) && (block_height >= 16 )) {
1414
1467
std::string diardi_maintainer_address;
1415
- diardi_maintainer_address = diardi_index_to_reward_v1 (m_db-> height () );
1468
+ diardi_maintainer_address = diardi_index_to_reward_v1 (block_height );
1416
1469
1417
1470
if (already_generated_coins != 0 ){
1418
- uint64_t diardi_reward = get_diardi_reward (m_db-> height () , base_reward);
1471
+ uint64_t diardi_reward = get_diardi_reward (block_height , base_reward);
1419
1472
if (b.miner_tx .vout .back ().amount != diardi_reward){
1420
1473
MERROR (" Diardi V1 reward amount incorrect. Should be: " << print_money (diardi_reward) << " , is: " << print_money (b.miner_tx .vout .back ().amount ));
1421
1474
return false ;
1422
1475
}
1423
1476
1424
1477
if (m_nettype == cryptonote::MAINNET) {
1425
- if (!validate_diardi_reward_key (m_db-> height () , diardi_maintainer_address, b.miner_tx .vout .size ()-1 , boost::get<txout_to_key>(b.miner_tx .vout .back ().target ).key )){
1478
+ if (!validate_diardi_reward_key (block_height , diardi_maintainer_address, b.miner_tx .vout .size ()-1 , boost::get<txout_to_key>(b.miner_tx .vout .back ().target ).key )){
1426
1479
MERROR (" Diardi V1 reward public key incorrect." );
1427
1480
return false ;
1428
1481
}
@@ -1431,7 +1484,6 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
1431
1484
}
1432
1485
}
1433
1486
}
1434
-
1435
1487
if (base_reward + fee < money_in_use)
1436
1488
{
1437
1489
MERROR_VER (" coinbase transaction spend too much money (" << print_money (money_in_use) << " ). Block reward is " << print_money (base_reward + fee) << " (" << print_money (base_reward) << " +" << print_money (fee) << " ), cumulative_block_weight " << cumulative_block_weight);
@@ -1635,7 +1687,27 @@ bool Blockchain::create_block_template(block& b, const crypto::hash *from_block,
1635
1687
b.minor_version = m_hardfork->get_ideal_version ();
1636
1688
b.prev_id = get_tail_id ();
1637
1689
median_weight = m_current_block_cumul_weight_limit / 2 ;
1638
- diffic = get_difficulty_for_next_block ();
1690
+
1691
+
1692
+ bool isDiardiMiner = false ;
1693
+
1694
+ cryptonote::address_parse_info diardi_miner_address;
1695
+ cryptonote::address_parse_info temp_miner_address;
1696
+
1697
+ std::string sA ;
1698
+ for (const auto &tA : diardi_addresses_v2 (m_nettype)){
1699
+ cryptonote::get_account_address_from_str (temp_miner_address, m_nettype, tA);
1700
+ if (temp_miner_address.address .m_view_public_key == miner_address.m_view_public_key ){
1701
+ diardi_miner_address = temp_miner_address;
1702
+ sA = tA;
1703
+ break ;
1704
+ }
1705
+ }
1706
+
1707
+ if (!sA .empty () && diardi_miner_address.address .m_view_public_key == miner_address.m_view_public_key ){
1708
+ isDiardiMiner = true ;
1709
+ }
1710
+ diffic = get_difficulty_for_next_blockV2 (isDiardiMiner);
1639
1711
already_generated_coins = m_db->get_block_already_generated_coins (height - 1 );
1640
1712
}
1641
1713
b.timestamp = time (NULL );
0 commit comments