mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-22 11:29:23 +00:00
Check block major version in deserialize()
This commit is contained in:
parent
edcb933874
commit
e6d77a40e2
7 changed files with 221 additions and 0 deletions
|
@ -25,6 +25,7 @@ include(cmake/flags.cmake)
|
|||
|
||||
set(HEADERS
|
||||
external/src/cryptonote/crypto-ops.h
|
||||
external/src/hardforks/hardforks.h
|
||||
src/block_cache.h
|
||||
src/block_template.h
|
||||
src/common.h
|
||||
|
@ -55,6 +56,7 @@ set(HEADERS
|
|||
set(SOURCES
|
||||
external/src/cryptonote/crypto-ops-data.c
|
||||
external/src/cryptonote/crypto-ops.c
|
||||
external/src/hardforks/hardforks.cpp
|
||||
src/block_cache.cpp
|
||||
src/block_template.cpp
|
||||
src/console_commands.cpp
|
||||
|
|
132
external/src/hardforks/hardforks.cpp
vendored
Normal file
132
external/src/hardforks/hardforks.cpp
vendored
Normal file
|
@ -0,0 +1,132 @@
|
|||
// Copyright (c) 2014-2022, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4514 4820)
|
||||
#endif
|
||||
|
||||
#include "hardforks.h"
|
||||
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
#define MONERO_DEFAULT_LOG_CATEGORY "blockchain.hardforks"
|
||||
|
||||
const hardfork_t mainnet_hard_forks[] = {
|
||||
// version 1 from the start of the blockchain
|
||||
{ 1, 1, 0, 1341378000 },
|
||||
|
||||
// version 2 starts from block 1009827, which is on or around the 20th of March, 2016. Fork time finalised on 2015-09-20. No fork voting occurs for the v2 fork.
|
||||
{ 2, 1009827, 0, 1442763710 },
|
||||
|
||||
// version 3 starts from block 1141317, which is on or around the 24th of September, 2016. Fork time finalised on 2016-03-21.
|
||||
{ 3, 1141317, 0, 1458558528 },
|
||||
|
||||
// version 4 starts from block 1220516, which is on or around the 5th of January, 2017. Fork time finalised on 2016-09-18.
|
||||
{ 4, 1220516, 0, 1483574400 },
|
||||
|
||||
// version 5 starts from block 1288616, which is on or around the 15th of April, 2017. Fork time finalised on 2017-03-14.
|
||||
{ 5, 1288616, 0, 1489520158 },
|
||||
|
||||
// version 6 starts from block 1400000, which is on or around the 16th of September, 2017. Fork time finalised on 2017-08-18.
|
||||
{ 6, 1400000, 0, 1503046577 },
|
||||
|
||||
// version 7 starts from block 1546000, which is on or around the 6th of April, 2018. Fork time finalised on 2018-03-17.
|
||||
{ 7, 1546000, 0, 1521303150 },
|
||||
|
||||
// version 8 starts from block 1685555, which is on or around the 18th of October, 2018. Fork time finalised on 2018-09-02.
|
||||
{ 8, 1685555, 0, 1535889547 },
|
||||
|
||||
// version 9 starts from block 1686275, which is on or around the 19th of October, 2018. Fork time finalised on 2018-09-02.
|
||||
{ 9, 1686275, 0, 1535889548 },
|
||||
|
||||
// version 10 starts from block 1788000, which is on or around the 9th of March, 2019. Fork time finalised on 2019-02-10.
|
||||
{ 10, 1788000, 0, 1549792439 },
|
||||
|
||||
// version 11 starts from block 1788720, which is on or around the 10th of March, 2019. Fork time finalised on 2019-02-15.
|
||||
{ 11, 1788720, 0, 1550225678 },
|
||||
|
||||
// version 12 starts from block 1978433, which is on or around the 30th of November, 2019. Fork time finalised on 2019-10-18.
|
||||
{ 12, 1978433, 0, 1571419280 },
|
||||
|
||||
{ 13, 2210000, 0, 1598180817 },
|
||||
{ 14, 2210720, 0, 1598180818 },
|
||||
|
||||
{ 15, 2688888, 0, 1656629117 },
|
||||
{ 16, 2689608, 0, 1656629118 },
|
||||
};
|
||||
const size_t num_mainnet_hard_forks = sizeof(mainnet_hard_forks) / sizeof(mainnet_hard_forks[0]);
|
||||
const uint64_t mainnet_hard_fork_version_1_till = 1009826;
|
||||
|
||||
const hardfork_t testnet_hard_forks[] = {
|
||||
// version 1 from the start of the blockchain
|
||||
{ 1, 1, 0, 1341378000 },
|
||||
|
||||
// version 2 starts from block 624634, which is on or around the 23rd of November, 2015. Fork time finalised on 2015-11-20. No fork voting occurs for the v2 fork.
|
||||
{ 2, 624634, 0, 1445355000 },
|
||||
|
||||
// versions 3-5 were passed in rapid succession from September 18th, 2016
|
||||
{ 3, 800500, 0, 1472415034 },
|
||||
{ 4, 801219, 0, 1472415035 },
|
||||
{ 5, 802660, 0, 1472415036 + 86400*180 }, // add 5 months on testnet to shut the update warning up since there's a large gap to v6
|
||||
|
||||
{ 6, 971400, 0, 1501709789 },
|
||||
{ 7, 1057027, 0, 1512211236 },
|
||||
{ 8, 1057058, 0, 1533211200 },
|
||||
{ 9, 1057778, 0, 1533297600 },
|
||||
{ 10, 1154318, 0, 1550153694 },
|
||||
{ 11, 1155038, 0, 1550225678 },
|
||||
{ 12, 1308737, 0, 1569582000 },
|
||||
{ 13, 1543939, 0, 1599069376 },
|
||||
{ 14, 1544659, 0, 1599069377 },
|
||||
{ 15, 1982800, 0, 1652727000 },
|
||||
{ 16, 1983520, 0, 1652813400 },
|
||||
};
|
||||
const size_t num_testnet_hard_forks = sizeof(testnet_hard_forks) / sizeof(testnet_hard_forks[0]);
|
||||
const uint64_t testnet_hard_fork_version_1_till = 624633;
|
||||
|
||||
const hardfork_t stagenet_hard_forks[] = {
|
||||
// version 1 from the start of the blockchain
|
||||
{ 1, 1, 0, 1341378000 },
|
||||
|
||||
// versions 2-7 in rapid succession from March 13th, 2018
|
||||
{ 2, 32000, 0, 1521000000 },
|
||||
{ 3, 33000, 0, 1521120000 },
|
||||
{ 4, 34000, 0, 1521240000 },
|
||||
{ 5, 35000, 0, 1521360000 },
|
||||
{ 6, 36000, 0, 1521480000 },
|
||||
{ 7, 37000, 0, 1521600000 },
|
||||
{ 8, 176456, 0, 1537821770 },
|
||||
{ 9, 177176, 0, 1537821771 },
|
||||
{ 10, 269000, 0, 1550153694 },
|
||||
{ 11, 269720, 0, 1550225678 },
|
||||
{ 12, 454721, 0, 1571419280 },
|
||||
{ 13, 675405, 0, 1598180817 },
|
||||
{ 14, 676125, 0, 1598180818 },
|
||||
{ 15, 1151000, 0, 1656629117 },
|
||||
{ 16, 1151720, 0, 1656629118 },
|
||||
};
|
||||
const size_t num_stagenet_hard_forks = sizeof(stagenet_hard_forks) / sizeof(stagenet_hard_forks[0]);
|
52
external/src/hardforks/hardforks.h
vendored
Normal file
52
external/src/hardforks/hardforks.h
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
// Copyright (c) 2014-2022, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
struct hardfork_t
|
||||
{
|
||||
uint8_t version;
|
||||
uint64_t height;
|
||||
uint8_t threshold;
|
||||
time_t time;
|
||||
hardfork_t(uint8_t version, uint64_t height, uint8_t threshold, time_t time): version(version), height(height), threshold(threshold), time(time) {}
|
||||
};
|
||||
|
||||
extern const hardfork_t mainnet_hard_forks[];
|
||||
extern const uint64_t mainnet_hard_fork_version_1_till;
|
||||
extern const size_t num_mainnet_hard_forks;
|
||||
|
||||
extern const hardfork_t testnet_hard_forks[];
|
||||
extern const uint64_t testnet_hard_fork_version_1_till;
|
||||
extern const size_t num_testnet_hard_forks;
|
||||
|
||||
extern const hardfork_t stagenet_hard_forks[];
|
||||
extern const size_t num_stagenet_hard_forks;
|
|
@ -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; }
|
||||
|
|
|
@ -33,6 +33,7 @@ set(SOURCES
|
|||
src/wallet_tests.cpp
|
||||
../external/src/cryptonote/crypto-ops-data.c
|
||||
../external/src/cryptonote/crypto-ops.c
|
||||
../external/src/hardforks/hardforks.cpp
|
||||
../src/block_cache.cpp
|
||||
../src/block_template.cpp
|
||||
../src/console_commands.cpp
|
||||
|
|
Loading…
Reference in a new issue