Skip to content

Commit fa612aa

Browse files
committed
use the version to determine the fork instead of the block height
1 parent 1f0e6ac commit fa612aa

7 files changed

Lines changed: 15 additions & 25 deletions

File tree

src/cryptonote_basic/cryptonote_basic_impl.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,13 @@ namespace cryptonote {
8181
return CRYPTONOTE_MAX_TX_SIZE;
8282
}
8383
//-----------------------------------------------------------------------------------------------
84-
//bool get_block_reward(size_t median_weight, size_t current_block_weight, uint64_t already_generated_coins, uint64_t &reward, uint8_t version) {
85-
bool get_block_reward(size_t median_weight, size_t current_block_weight, uint64_t already_generated_coins, uint64_t &reward, uint8_t version, bool fork) {
84+
bool get_block_reward(size_t median_weight, size_t current_block_weight, uint64_t already_generated_coins, uint64_t &reward, uint8_t version) {
8685
static_assert(DIFFICULTY_TARGET_V2%60==0&&DIFFICULTY_TARGET_V1%60==0,"difficulty targets must be a multiple of 60");
8786
const int target = version < 2 ? DIFFICULTY_TARGET_V1 : DIFFICULTY_TARGET_V2;
8887
const int target_minutes = target / 60;
8988
const int emission_speed_factor = EMISSION_SPEED_FACTOR_PER_MINUTE - (target_minutes-1);
9089

91-
// uint64_t base_reward = version < 0xa7 ? (MONEY_SUPPLY - already_generated_coins) >> emission_speed_factor : MONERO_BLOCK_REWARD;
92-
uint64_t base_reward = fork ? MONERO_BLOCK_REWARD : (MONEY_SUPPLY - already_generated_coins) >> emission_speed_factor;
90+
uint64_t base_reward = version < 0xa7 ? (MONEY_SUPPLY - already_generated_coins) >> emission_speed_factor : MONERO_BLOCK_REWARD;
9391
if (base_reward < FINAL_SUBSIDY_PER_MINUTE*target_minutes)
9492
{
9593
base_reward = FINAL_SUBSIDY_PER_MINUTE*target_minutes;

src/cryptonote_basic/cryptonote_basic_impl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ namespace cryptonote {
8888
/************************************************************************/
8989
size_t get_min_block_weight(uint8_t version);
9090
size_t get_max_tx_size();
91-
//bool get_block_reward(size_t median_weight, size_t current_block_weight, uint64_t already_generated_coins, uint64_t &reward, uint8_t version);
92-
bool get_block_reward(size_t median_weight, size_t current_block_weight, uint64_t already_generated_coins, uint64_t &reward, uint8_t version, bool fork);
91+
bool get_block_reward(size_t median_weight, size_t current_block_weight, uint64_t already_generated_coins, uint64_t &reward, uint8_t version);
9392
uint8_t get_account_address_checksum(const public_address_outer_blob& bl);
9493
uint8_t get_account_integrated_address_checksum(const public_integrated_address_outer_blob& bl);
9594

src/cryptonote_core/blockchain.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ static const struct {
108108
// version 6 starts from block 1400000, which is on or around the 16th of September, 2017. Fork time finalised on 2017-08-18.
109109
{ 6, 1400000, 0, 1503046577 },
110110

111-
// version 0xa7 starts from block 1881040 , timestamp after block 1876000 + 1week
112-
// { 0xa7, 1881040, 0, 1561887557 + 7 * 24 * 60 * 60 },
111+
// version 0xa7 starts from block 1906800
112+
{ 0xa7, 1996800, 0, 1565587533 },
113113
};
114114
static const uint64_t mainnet_hard_fork_version_1_till = 1009826;
115115

@@ -1284,8 +1284,7 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
12841284

12851285
std::vector<uint64_t> last_blocks_weights;
12861286
get_last_n_blocks_weights(last_blocks_weights, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
1287-
bool fork = height >= TEST_NEW_BLOCK_REWARD_HEIGHT;
1288-
if (!get_block_reward(epee::misc_utils::median(last_blocks_weights), cumulative_block_weight, already_generated_coins, base_reward, version, fork))
1287+
if (!get_block_reward(epee::misc_utils::median(last_blocks_weights), cumulative_block_weight, already_generated_coins, base_reward, version))
12891288
{
12901289
MERROR_VER("block weight " << cumulative_block_weight << " is bigger than allowed for this blockchain");
12911290
return false;
@@ -1319,6 +1318,7 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
13191318
if (m_fundctl.funding_enabled(height))
13201319
{
13211320
// bool ret = fundctl.check_block_funding(miner_reward_amount, funding_amount, base_reward + fee);
1321+
bool fork = height >= DIFFICULTY_ADJUST_HEIGHT;
13221322
bool ret = m_fundctl.check_block_funding(miner_reward_amount, funding_amount, base_reward + fee, fork);
13231323
MINFO("miner_reward_amount=" << miner_reward_amount << ", funding_amount=" << funding_amount << ", money_in_use=" << (base_reward + fee));
13241324
CHECK_AND_ASSERT_MES(ret, false, "check reward failed");
@@ -1519,8 +1519,7 @@ bool Blockchain::create_block_template(block& b, const crypto::hash *from_block,
15191519

15201520
size_t txs_weight;
15211521
uint64_t fee;
1522-
bool fork = height >= TEST_NEW_BLOCK_REWARD_HEIGHT;
1523-
if (!m_tx_pool.fill_block_template(b, median_weight, already_generated_coins, txs_weight, fee, expected_reward, b.major_version, fork))
1522+
if (!m_tx_pool.fill_block_template(b, median_weight, already_generated_coins, txs_weight, fee, expected_reward, b.major_version))
15241523
{
15251524
return false;
15261525
}
@@ -3331,8 +3330,7 @@ bool Blockchain::check_fee(size_t tx_weight, uint64_t fee) const
33313330
median = m_current_block_cumul_weight_limit / 2;
33323331
const uint64_t blockchain_height = m_db->height();
33333332
already_generated_coins = blockchain_height ? m_db->get_block_already_generated_coins(blockchain_height - 1) : 0;
3334-
bool fork = blockchain_height >= TEST_NEW_BLOCK_REWARD_HEIGHT;
3335-
if (!get_block_reward(median, 1, already_generated_coins, base_reward, version, fork))
3333+
if (!get_block_reward(median, 1, already_generated_coins, base_reward, version))
33363334
return false;
33373335
}
33383336

@@ -3398,8 +3396,7 @@ uint64_t Blockchain::get_dynamic_base_fee_estimate(uint64_t grace_blocks) const
33983396

33993397
uint64_t already_generated_coins = db_height ? m_db->get_block_already_generated_coins(db_height - 1) : 0;
34003398
uint64_t base_reward;
3401-
bool fork = db_height >= TEST_NEW_BLOCK_REWARD_HEIGHT;
3402-
if (!get_block_reward(median, 1, already_generated_coins, base_reward, version, fork))
3399+
if (!get_block_reward(median, 1, already_generated_coins, base_reward, version))
34033400
{
34043401
MERROR("Failed to determine block reward, using placeholder " << print_money(BLOCK_REWARD_OVERESTIMATE) << " as a high bound");
34053402
base_reward = BLOCK_REWARD_OVERESTIMATE;

src/cryptonote_core/blockfunding.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
#include "cryptonote_basic/verification_context.h"
3939
#include "crypto/hash.h"
4040

41-
// just for test
42-
#define TEST_NEW_BLOCK_REWARD_HEIGHT 1995000
43-
4441
namespace cryptonote{
4542
class BlockFunding
4643
{

src/cryptonote_core/cryptonote_tx_utils.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ namespace cryptonote
9797
CHECK_AND_ASSERT_MES(fundctl.init(nettype), false, "init fundctl failed");
9898

9999
uint64_t block_reward;
100-
bool fork = height >= TEST_NEW_BLOCK_REWARD_HEIGHT;
101-
if(!get_block_reward(median_weight, current_block_weight, already_generated_coins, block_reward, hard_fork_version, fork))
100+
if(!get_block_reward(median_weight, current_block_weight, already_generated_coins, block_reward, hard_fork_version))
102101
{
103102
LOG_PRINT_L0("Block is too big");
104103
return false;

src/cryptonote_core/tx_pool.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ namespace cryptonote
11661166
}
11671167
//---------------------------------------------------------------------------------
11681168
//TODO: investigate whether boolean return is appropriate
1169-
bool tx_memory_pool::fill_block_template(block &bl, size_t median_weight, uint64_t already_generated_coins, size_t &total_weight, uint64_t &fee, uint64_t &expected_reward, uint8_t version, bool fork)
1169+
bool tx_memory_pool::fill_block_template(block &bl, size_t median_weight, uint64_t already_generated_coins, size_t &total_weight, uint64_t &fee, uint64_t &expected_reward, uint8_t version)
11701170
{
11711171
CRITICAL_REGION_LOCAL(m_transactions_lock);
11721172
CRITICAL_REGION_LOCAL1(m_blockchain);
@@ -1176,7 +1176,7 @@ namespace cryptonote
11761176
fee = 0;
11771177

11781178
//baseline empty block
1179-
get_block_reward(median_weight, total_weight, already_generated_coins, best_coinbase, version, fork);
1179+
get_block_reward(median_weight, total_weight, already_generated_coins, best_coinbase, version);
11801180

11811181

11821182
size_t max_total_weight_pre_v5 = (130 * median_weight) / 100 - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE;
@@ -1212,7 +1212,7 @@ namespace cryptonote
12121212
// If we're getting lower coinbase tx,
12131213
// stop including more tx
12141214
uint64_t block_reward;
1215-
if(!get_block_reward(median_weight, total_weight + meta.weight, already_generated_coins, block_reward, version, fork))
1215+
if(!get_block_reward(median_weight, total_weight + meta.weight, already_generated_coins, block_reward, version))
12161216
{
12171217
LOG_PRINT_L2(" would exceed maximum block weight");
12181218
continue;

src/cryptonote_core/tx_pool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ namespace cryptonote
229229
*
230230
* @return true
231231
*/
232-
bool fill_block_template(block &bl, size_t median_weight, uint64_t already_generated_coins, size_t &total_weight, uint64_t &fee, uint64_t &expected_reward, uint8_t version, bool fork);
232+
bool fill_block_template(block &bl, size_t median_weight, uint64_t already_generated_coins, size_t &total_weight, uint64_t &fee, uint64_t &expected_reward, uint8_t version);
233233

234234
/**
235235
* @brief get a list of all transactions in the pool

0 commit comments

Comments
 (0)