From c49a72f1ce5f99f8cf27c469f77742844d591154 Mon Sep 17 00:00:00 2001 From: wowario Date: Sun, 9 May 2021 21:55:34 +0300 Subject: [PATCH] fixed coinbase unlock 288 blks --- src/cryptonote_config.h | 3 +++ src/cryptonote_core/blockchain.cpp | 15 +++++++-------- src/cryptonote_core/cryptonote_tx_utils.cpp | 7 +++++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index d8bf8f729..ab58852ed 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -40,6 +40,8 @@ #define CRYPTONOTE_MAX_TX_SIZE 1000000 #define CRYPTONOTE_MAX_TX_PER_BLOCK 0x10000000 #define CRYPTONOTE_PUBLIC_ADDRESS_TEXTBLOB_VER 0 +#define CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V2 288 +#define CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW 60 #define CURRENT_TRANSACTION_VERSION 2 #define CURRENT_BLOCK_MAJOR_VERSION 7 #define CURRENT_BLOCK_MINOR_VERSION 7 @@ -191,6 +193,7 @@ #define HF_VERSION_CLSAG 16 #define HF_VERSION_DETERMINISTIC_UNLOCK_TIME 16 #define HF_VERSION_DYNAMIC_UNLOCK 16 +#define HF_VERSION_FIXED_UNLOCK 18 #define PER_KB_FEE_QUANTIZATION_DECIMALS 8 diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 1c63d1b6e..763b6a62b 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -1423,12 +1423,11 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height, } MDEBUG("Miner tx hash: " << get_transaction_hash(b.miner_tx)); - // Dynamic unlock time from HF 16 - // To calculate unlock window, get the block hash at height-1337, convert the - // first 3 characters from hexadecimal to decimal, multiply by 2, and then add 288. - // Unlock minimum 1 day (288 blocks), maximum is ~29 days ((4095*2)+288 = 8478 blocks) - // unlock time = unlock_window + height - if (hf_version >= HF_VERSION_DYNAMIC_UNLOCK) + if (hf_version >= HF_VERSION_FIXED_UNLOCK) + { + CHECK_AND_ASSERT_MES(b.miner_tx.unlock_time == height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V2, false, "coinbase transaction transaction has the wrong unlock time=" + << b.miner_tx.unlock_time << ", expected " << height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V2); + } else if (hf_version < HF_VERSION_FIXED_UNLOCK && hf_version >= HF_VERSION_DYNAMIC_UNLOCK) { uint64_t N = m_nettype == MAINNET ? 1337 : 5; crypto::hash blk_id = get_block_id_by_height(height-N); @@ -1445,8 +1444,8 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height, "\nblk_height: " << height-N << ", blk_id: " << blk_id << "\nhex_str: " << hex_str << ", blk_num: " << blk_num); } else { - CHECK_AND_ASSERT_MES(b.miner_tx.unlock_time == height + 60, false, "coinbase transaction transaction has the wrong unlock time=" - << b.miner_tx.unlock_time << ", expected " << height + 60); + CHECK_AND_ASSERT_MES(b.miner_tx.unlock_time == height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW, false, "coinbase transaction transaction has the wrong unlock time=" + << b.miner_tx.unlock_time << ", expected " << height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW); } //check outs overflow diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp index b0af0d96d..e555ce295 100644 --- a/src/cryptonote_core/cryptonote_tx_utils.cpp +++ b/src/cryptonote_core/cryptonote_tx_utils.cpp @@ -167,7 +167,10 @@ namespace cryptonote tx.version = 1; //lock - if (hard_fork_version >= HF_VERSION_DYNAMIC_UNLOCK) + if (hard_fork_version >= HF_VERSION_FIXED_UNLOCK) + { + tx.unlock_time = height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW_V2; + } else if (hard_fork_version < HF_VERSION_FIXED_UNLOCK && hard_fork_version >= HF_VERSION_DYNAMIC_UNLOCK) { uint64_t N = m_nettype == MAINNET ? 1337 : 5; crypto::hash blk_id = pb->get_block_id_by_height(height-N); @@ -176,7 +179,7 @@ namespace cryptonote uint64_t unlock_window = blk_num + 288; tx.unlock_time = height + unlock_window; } else { - tx.unlock_time = height + 60; + tx.unlock_time = height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW; } tx.vin.push_back(in);