@@ -859,10 +859,10 @@ difficulty_type Blockchain::get_difficulty_for_next_block() {
859859 return (difficulty_type)120000000 ;
860860 }
861861
862- // Stagenet will start with difficulty of 1 KH /s
862+ // Stagenet will start with difficulty of 33.3 H /s
863863 if (m_nettype == STAGENET && (uint64_t )height >= 20 &&
864864 (uint64_t )height <= 20 + (uint64_t )DIFFICULTY_BLOCKS_COUNT) {
865- return (difficulty_type)40000 ;
865+ return (difficulty_type)4000 ;
866866 }
867867
868868 // Testnet will start with difficulty of 16 KH/s
@@ -1441,72 +1441,59 @@ bool Blockchain::validate_diardi_miner_v2(const block &b) {
14411441 b.miner_tx .vin [0 ].type () != typeid (txin_gen))
14421442 ? m_db->height ()
14431443 : boost::get<txin_gen>(b.miner_tx .vin [0 ]).height ;
1444- bool isDiardiBlock = (version >= 13 && block_height % 4 == 0 );
14451444
1446- if (!isDiardiBlock ) {
1445+ if (!(version >= 13 && block_height % 4 == 0 ) ) {
14471446 return true ;
14481447 }
14491448
14501449 std::list<std::string> diardi_miners_list = diardi_addresses_v2 (m_nettype);
1451-
1452- std::string tM;
1453- std::string dM;
14541450 std::string vM;
1451+ cryptonote::address_parse_info pVm;
14551452
1456- cryptonote::address_parse_info temp_miner_address;
1457- cryptonote::address_parse_info diardi_miner_address;
1458-
1459- for (auto const &sM : diardi_miners_list) {
1460- cryptonote::get_account_address_from_str (temp_miner_address, m_nettype, tM);
1461- cryptonote::get_account_address_from_str (diardi_miner_address, m_nettype,
1462- sM );
1453+ for (auto const & sM : diardi_miners_list) {
1454+ public_key pKey = boost::get<txout_to_key>(b.miner_tx .vout .back ().target ).key ;
1455+ if (validate_diardi_reward_key (block_height, sM , 0 , pKey, m_nettype)) {
1456+ vM = sM ;
1457+ cryptonote::get_account_address_from_str (pVm, m_nettype, vM);
1458+ break ;
1459+ }
1460+ }
14631461
1464- if (temp_miner_address.address == diardi_miner_address.address ) {
1465- if (temp_miner_address.address .m_view_public_key ==
1466- diardi_miner_address.address .m_view_public_key ) {
1467- crypto::hash sig_data = get_sig_data (block_height);
1468- crypto::signature signature = b.signature ;
1469- crypto::public_key o_pspendkey =
1470- diardi_miner_address.address .m_spend_public_key ;
1462+ if (vM.empty ()) {
1463+ return true ;
1464+ }
14711465
1472- vM = sM ;
1466+ crypto::hash sig_data = get_sig_data (block_height);
1467+ crypto::signature signature = b.signature ;
14731468
1474- if (!crypto::check_signature (sig_data, o_pspendkey , signature)) {
1475- LOG_PRINT_L1 (" Diardi: Miner Signature incorrect" );
1476- return false ;
1477- }
1469+ if (!crypto::check_signature (sig_data, pVm. address . m_spend_public_key , signature)) {
1470+ LOG_PRINT_L1 (" Diardi: Miner signature incorrect" );
1471+ return false ;
1472+ }
14781473
1479- cryptonote::block oDb;
1480- bool oOb = false ;
1481- bool getOldBlock = get_block_by_hash (
1474+ cryptonote::block oDb;
1475+ bool oOb = false ;
1476+ bool getOldBlock = get_block_by_hash (
14821477 m_db->get_block_hash_from_height ((block_height - 4 )), oDb, &oOb);
14831478
1484- if (!getOldBlock) {
1485- LOG_PRINT_L1 (" Diardi: Could not get old block" );
1486- return false ;
1487- }
1488-
1489- if (check_last_diardi_miner (this , vM, m_nettype)) {
1490- LOG_PRINT_L1 (" Diardi: Miner already mined a block < 4 blocks ago" );
1491- return false ;
1492- }
1479+ if (!getOldBlock) {
1480+ LOG_PRINT_L1 (" Diardi: Could not get old block" );
1481+ return false ;
1482+ }
14931483
1494- return true ;
1495- }
1496- }
1484+ if ( check_last_diardi_miner ( this , vM, m_nettype)) {
1485+ LOG_PRINT_L1 ( " Diardi: Miner already mined a block < 4 blocks ago " );
1486+ return false ;
14971487 }
14981488
1499- LOG_PRINT_L1 (" Diardi: Miner not in list" );
1500- return false ;
1489+ return true ;
15011490}
15021491// ------------------------------------------------------------------
15031492// This function validates the miner transaction reward
1504- bool Blockchain::validate_miner_transaction (const block &b,
1505- size_t cumulative_block_weight,
1506- uint64_t fee, uint64_t &base_reward,
1507- uint64_t already_generated_coins,
1508- bool &partial_block_reward,
1509- uint8_t version) {
1493+ bool Blockchain::validate_miner_transaction (
1494+ const block &b, size_t cumulative_block_weight, uint64_t fee,
1495+ uint64_t &base_reward, uint64_t already_generated_coins,
1496+ bool &partial_block_reward, uint8_t version, bool &last_diardi_mined) {
15101497 LOG_PRINT_L3 (" Blockchain::" << __func__);
15111498 // validate reward
15121499 uint64_t money_in_use = 0 ;
@@ -1544,33 +1531,6 @@ bool Blockchain::validate_miner_transaction(const block &b,
15441531 return false ;
15451532 }
15461533
1547- if ((version >= 2 ) && (version <= 12 ) && (block_height >= 16 )) {
1548- std::string diardi_maintainer_address;
1549- diardi_maintainer_address = diardi_index_to_reward_v1 (block_height);
1550-
1551- if (already_generated_coins != 0 ) {
1552- uint64_t diardi_reward = get_diardi_reward (block_height, base_reward);
1553- if (b.miner_tx .vout .back ().amount != diardi_reward) {
1554- MERROR (" Diardi V1 reward amount incorrect. Should be: "
1555- << print_money (diardi_reward)
1556- << " , is: " << print_money (b.miner_tx .vout .back ().amount ));
1557- return false ;
1558- }
1559-
1560- if (m_nettype == cryptonote::MAINNET) {
1561- if (!validate_diardi_reward_key (
1562- block_height, diardi_maintainer_address,
1563- b.miner_tx .vout .size () - 1 ,
1564- boost::get<txout_to_key>(b.miner_tx .vout .back ().target ).key )) {
1565- MERROR (" Diardi V1 reward public key incorrect." );
1566- return false ;
1567- }
1568- } else {
1569- return true ;
1570- }
1571- }
1572- }
1573-
15741534 if (base_reward + fee < money_in_use) {
15751535 MERROR_VER (" coinbase transaction spend too much money ("
15761536 << print_money (money_in_use) << " ). Block reward is "
@@ -1601,6 +1561,73 @@ bool Blockchain::validate_miner_transaction(const block &b,
16011561 partial_block_reward = true ;
16021562 base_reward = money_in_use - fee;
16031563 }
1564+
1565+ if ((version >= 2 ) && (version <= 12 ) && (block_height >= 16 )) {
1566+ std::string diardi_maintainer_address;
1567+ diardi_maintainer_address = diardi_index_to_reward_v1 (block_height);
1568+
1569+ if (already_generated_coins != 0 ) {
1570+ uint64_t diardi_reward = get_diardi_reward (block_height, base_reward);
1571+ if (b.miner_tx .vout .back ().amount != diardi_reward) {
1572+ MERROR (" Diardi V1 reward amount incorrect. Should be: "
1573+ << print_money (diardi_reward)
1574+ << " , is: " << print_money (b.miner_tx .vout .back ().amount ));
1575+ return false ;
1576+ }
1577+
1578+ if (m_nettype == cryptonote::MAINNET) {
1579+ if (!validate_diardi_reward_key (
1580+ block_height, diardi_maintainer_address,
1581+ b.miner_tx .vout .size () - 1 ,
1582+ boost::get<txout_to_key>(b.miner_tx .vout .back ().target ).key )) {
1583+ MERROR (" Diardi V1 reward public key incorrect." );
1584+ return false ;
1585+ }
1586+ } else {
1587+ return true ;
1588+ }
1589+ }
1590+ }
1591+
1592+ if (version >= HF_VERSION_DIARDI_V2 && m_db->height () % 4 == 0 ) {
1593+ std::string vM;
1594+ std::list<std::string> diardi_miners_list = diardi_addresses_v2 (m_nettype);
1595+ cryptonote::address_parse_info diardi_miner_address;
1596+
1597+ for (auto const &sM : diardi_miners_list) {
1598+ if (validate_diardi_reward_key (
1599+ m_db->height (), sM , b.miner_tx .vout .size () - 1 ,
1600+ boost::get<txout_to_key>(b.miner_tx .vout .back ().target ).key ,
1601+ m_nettype)) {
1602+ vM = sM ;
1603+ break ;
1604+ }
1605+ }
1606+
1607+ if (vM.empty ()) {
1608+ MERROR (" Diardi: V2 reward public key incorrect" );
1609+ return false ;
1610+ }
1611+
1612+ cryptonote::get_account_address_from_str (diardi_miner_address, m_nettype,
1613+ vM);
1614+
1615+ crypto::hash sig_data = get_sig_data (m_db->height ());
1616+ crypto::signature signature = b.signature ;
1617+ if (!crypto::check_signature (
1618+ sig_data, diardi_miner_address.address .m_spend_public_key ,
1619+ signature)) {
1620+ MERROR (" Diardi: Block signature incorrect" );
1621+ return false ;
1622+ }
1623+
1624+ if (check_last_diardi_miner (this , vM, m_nettype)) {
1625+ last_diardi_mined = true ;
1626+ MERROR (" Diardi: Cannot mine 2 diardi blocks in a row" );
1627+ return false ;
1628+ }
1629+ }
1630+
16041631 return true ;
16051632}
16061633// ------------------------------------------------------------------
@@ -4712,12 +4739,18 @@ bool Blockchain::handle_block_to_main_chain(const block &bl,
47124739 blockchain_height
47134740 ? m_db->get_block_already_generated_coins (blockchain_height - 1 )
47144741 : 0 ;
4715- if (!validate_miner_transaction (bl, cumulative_block_weight, fee_summary,
4716- base_reward, already_generated_coins,
4717- bvc.m_partial_block_reward ,
4718- m_hardfork->get_current_version ())) {
4719- MERROR_VER (" Block with id: " << id << " has incorrect miner transaction" );
4720- bvc.m_verifivation_failed = true ;
4742+ bool last_diardi_miner = false ;
4743+ if (!validate_miner_transaction (
4744+ bl, cumulative_block_weight, fee_summary, base_reward,
4745+ already_generated_coins, bvc.m_partial_block_reward ,
4746+ m_hardfork->get_current_version (), last_diardi_miner)) {
4747+ if (last_diardi_miner) {
4748+ bvc.m_last_diardi_mined = true ;
4749+ } else {
4750+ MERROR_VER (" Block with id: " << id << " has incorrect miner transaction" );
4751+ bvc.m_verifivation_failed = true ;
4752+ }
4753+
47214754 return_tx_to_pool (txs);
47224755 goto leave;
47234756 }
@@ -5030,10 +5063,11 @@ bool Blockchain::add_new_block(const block &bl,
50305063 }
50315064
50325065 if (!validate_diardi_miner_v2 (bl)) {
5033- LOG_PRINT_L1 (" Diardi validation failed for block with id <" << id << " >" );
5066+ LOG_PRINT_L1 (" Diardi: validation failed for block with id <" << id
5067+ << " >" );
50345068 bvc.m_added_to_main_chain = false ;
50355069 m_blocks_txs_check.clear ();
5036- return true ;
5070+ return false ;
50375071 }
50385072
50395073 // check that block refers to chain tail
0 commit comments