Check block major version in deserialize()
This commit is contained in:
@@ -84,6 +84,7 @@ int PoolBlock::deserialize(const uint8_t* data, size_t size, const SideChain& si
|
||||
EXPECT_BYTE(TXIN_GEN);
|
||||
|
||||
READ_VARINT(m_txinGenHeight);
|
||||
if (m_majorVersion != sidechain.network_major_version(m_txinGenHeight)) return __LINE__;
|
||||
if (unlock_height != m_txinGenHeight + MINER_REWARD_UNLOCK_TIME) return __LINE__;
|
||||
|
||||
std::vector<uint8_t> outputs_blob;
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "params.h"
|
||||
#include "json_parsers.h"
|
||||
#include "crypto.h"
|
||||
#include "hardforks/hardforks.h"
|
||||
#include <rapidjson/document.h>
|
||||
#include <rapidjson/istreamwrapper.h>
|
||||
#include <fstream>
|
||||
@@ -1044,6 +1045,37 @@ double SideChain::get_reward_share(const Wallet& w) const
|
||||
return total_reward ? (static_cast<double>(reward) / static_cast<double>(total_reward)) : 0.0;
|
||||
}
|
||||
|
||||
uint64_t SideChain::network_major_version(uint64_t height) const
|
||||
{
|
||||
const hardfork_t* hard_forks;
|
||||
size_t num_hard_forks;
|
||||
|
||||
switch (m_networkType)
|
||||
{
|
||||
case NetworkType::Mainnet:
|
||||
default:
|
||||
hard_forks = mainnet_hard_forks;
|
||||
num_hard_forks = num_mainnet_hard_forks;
|
||||
break;
|
||||
|
||||
case NetworkType::Testnet:
|
||||
hard_forks = testnet_hard_forks;
|
||||
num_hard_forks = num_testnet_hard_forks;
|
||||
break;
|
||||
|
||||
case NetworkType::Stagenet:
|
||||
hard_forks = stagenet_hard_forks;
|
||||
num_hard_forks = num_stagenet_hard_forks;
|
||||
break;
|
||||
}
|
||||
|
||||
uint64_t result = 1;
|
||||
for (size_t i = 1; (i < num_hard_forks) && (height >= hard_forks[i].height); ++i) {
|
||||
result = hard_forks[i].version;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
difficulty_type SideChain::total_hashes() const
|
||||
{
|
||||
const PoolBlock* tip = m_chainTip;
|
||||
|
||||
@@ -65,6 +65,7 @@ public:
|
||||
const std::vector<uint8_t>& consensus_id() const { return m_consensusId; }
|
||||
uint64_t chain_window_size() const { return m_chainWindowSize; }
|
||||
NetworkType network_type() const { return m_networkType; }
|
||||
uint64_t network_major_version(uint64_t height) const;
|
||||
FORCEINLINE difficulty_type difficulty() const { ReadLock lock(m_curDifficultyLock); return m_curDifficulty; }
|
||||
difficulty_type total_hashes() const;
|
||||
uint64_t block_time() const { return m_targetBlockTime; }
|
||||
|
||||
Reference in New Issue
Block a user