Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparations for v7 #161

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/CryptoNoteCore/Blockchain.cpp
Expand Up @@ -371,6 +371,7 @@ Blockchain::Blockchain(
m_upgradeDetectorV4(currency, m_blocks, BLOCK_MAJOR_VERSION_4, logger),
m_upgradeDetectorV5(currency, m_blocks, BLOCK_MAJOR_VERSION_5, logger),
m_upgradeDetectorV6(currency, m_blocks, BLOCK_MAJOR_VERSION_6, logger),
m_upgradeDetectorV7(currency, m_blocks, BLOCK_MAJOR_VERSION_7, logger),
m_checkpoints(logger),
m_paymentIdIndex(blockchainIndexesEnabled),
m_timestampIndex(blockchainIndexesEnabled),
Expand Down Expand Up @@ -546,7 +547,8 @@ bool Blockchain::init(const std::string &config_folder, bool load_existing)
|| !m_upgradeDetectorV3.init()
|| !m_upgradeDetectorV4.init()
|| !m_upgradeDetectorV5.init()
|| !m_upgradeDetectorV6.init()) {
|| !m_upgradeDetectorV6.init()
|| !m_upgradeDetectorV7.init()) {
logger(ERROR, BRIGHT_RED)
<< "Failed to initialize upgrade detector. "
<< "Trying self healing procedure.";
Expand Down Expand Up @@ -600,6 +602,15 @@ bool Blockchain::init(const std::string &config_folder, bool load_existing)
<< ". Rollback blockchain to height=" << upgradeHeight;
rollbackBlockchainTo(upgradeHeight);
reinitUpgradeDetectors = true;
} else if (!checkUpgradeHeight(m_upgradeDetectorV7)) {
uint32_t upgradeHeight = m_upgradeDetectorV7.upgradeHeight();
logger(WARNING, BRIGHT_YELLOW)
<< "Invalid block version at " << upgradeHeight + 1
<< ": real=" << static_cast<int>(m_blocks[upgradeHeight + 1].bl.majorVersion)
<< " expected=" << static_cast<int>(m_upgradeDetectorV7.targetVersion())
<< ". Rollback blockchain to height=" << upgradeHeight;
rollbackBlockchainTo(upgradeHeight);
reinitUpgradeDetectors = true;
}

if (reinitUpgradeDetectors
Expand All @@ -608,6 +619,7 @@ bool Blockchain::init(const std::string &config_folder, bool load_existing)
|| !m_upgradeDetectorV4.init()
|| !m_upgradeDetectorV5.init()
|| !m_upgradeDetectorV6.init()
|| !m_upgradeDetectorV7.init()
)
) {
logger(ERROR, BRIGHT_RED) << "Failed to initialize upgrade detector";
Expand Down Expand Up @@ -1064,7 +1076,9 @@ uint64_t Blockchain::getCoinsInCirculation()

uint8_t Blockchain::getBlockMajorVersionForHeight(uint32_t height) const
{
if (height > m_upgradeDetectorV6.upgradeHeight()) {
if (height > m_upgradeDetectorV7.upgradeHeight()) {
return m_upgradeDetectorV7.targetVersion();
} else if (height > m_upgradeDetectorV6.upgradeHeight()) {
return m_upgradeDetectorV6.targetVersion();
} else if (height > m_upgradeDetectorV5.upgradeHeight()) {
return m_upgradeDetectorV5.targetVersion();
Expand Down Expand Up @@ -2973,6 +2987,7 @@ bool Blockchain::pushBlock(
m_upgradeDetectorV4.blockPushed();
m_upgradeDetectorV5.blockPushed();
m_upgradeDetectorV6.blockPushed();
m_upgradeDetectorV7.blockPushed();

update_next_cumulative_size_limit();

Expand Down Expand Up @@ -3014,6 +3029,7 @@ void Blockchain::popBlock()
m_upgradeDetectorV4.blockPopped();
m_upgradeDetectorV5.blockPopped();
m_upgradeDetectorV6.blockPopped();
m_upgradeDetectorV7.blockPopped();
}

bool Blockchain::pushTransaction(
Expand Down
1 change: 1 addition & 0 deletions lib/CryptoNoteCore/Blockchain.h
Expand Up @@ -336,6 +336,7 @@ class Blockchain : public CryptoNote::ITransactionValidator
UpgradeDetector m_upgradeDetectorV4;
UpgradeDetector m_upgradeDetectorV5;
UpgradeDetector m_upgradeDetectorV6;
UpgradeDetector m_upgradeDetectorV7;

PaymentIdIndex m_paymentIdIndex;
TimestampBlocksIndex m_timestampIndex;
Expand Down
5 changes: 5 additions & 0 deletions lib/CryptoNoteCore/Core.cpp
Expand Up @@ -699,6 +699,11 @@ bool core::get_block_template(
m_currency.upgradeHeight(BLOCK_MAJOR_VERSION_6) == UpgradeDetectorBase::UNDEF_HEIGHT
? BLOCK_MINOR_VERSION_1
: BLOCK_MINOR_VERSION_0;
} else if (b.majorVersion >= BLOCK_MAJOR_VERSION_7) {
b.minorVersion =
m_currency.upgradeHeight(BLOCK_MAJOR_VERSION_7) == UpgradeDetectorBase::UNDEF_HEIGHT
? BLOCK_MINOR_VERSION_1
: BLOCK_MINOR_VERSION_0;
}

b.previousBlockHash = get_tail_id();
Expand Down
2 changes: 1 addition & 1 deletion lib/CryptoNoteCore/CryptoNoteSerialization.cpp
Expand Up @@ -426,7 +426,7 @@ void serialize(ParentBlockSerializer &pbs, ISerializer &serializer)
void serializeBlockHeader(BlockHeader &header, ISerializer &serializer)
{
serializer(header.majorVersion, "major_version");
if (header.majorVersion > BLOCK_MAJOR_VERSION_6) {
if (header.majorVersion > BLOCK_MAJOR_VERSION_7) {
throw std::runtime_error("Wrong major version");
}

Expand Down
11 changes: 10 additions & 1 deletion lib/CryptoNoteCore/Currency.cpp
Expand Up @@ -64,6 +64,7 @@ bool Currency::init()
m_upgradeHeightV4 = 70;
m_upgradeHeightV5 = 80;
m_upgradeHeightV6 = 100;
m_upgradeHeightV7 = 1000;
m_governancePercent = 10;
m_governanceHeightStart = 1;
m_governanceHeightEnd = 100;
Expand Down Expand Up @@ -122,7 +123,9 @@ size_t Currency::blockGrantedFullRewardZoneByBlockVersion(uint8_t blockMajorVers

uint32_t Currency::upgradeHeight(uint8_t majorVersion) const
{
if (majorVersion == BLOCK_MAJOR_VERSION_6) {
if (majorVersion == BLOCK_MAJOR_VERSION_7) {
return m_upgradeHeightV7;
} else if (majorVersion == BLOCK_MAJOR_VERSION_6) {
return m_upgradeHeightV6;
} else if (majorVersion == BLOCK_MAJOR_VERSION_5) {
return m_upgradeHeightV5;
Expand Down Expand Up @@ -744,6 +747,9 @@ difficulty_type Currency::nextDifficulty(uint32_t height,
currentSolveTime, lazy_stat_cb);
}

/*
TODO: are we still gonna use our difficultyV6 algorithm for v7?
*/
if (blockMajorVersion >= BLOCK_MAJOR_VERSION_6) {
return nextDifficultyV6(blockMajorVersion, timestamps, cumulativeDifficulties, height);
} else if (blockMajorVersion >= BLOCK_MAJOR_VERSION_5) {
Expand Down Expand Up @@ -1261,6 +1267,8 @@ bool Currency::checkProofOfWork(
case BLOCK_MAJOR_VERSION_5:
// fall through
case BLOCK_MAJOR_VERSION_6:
// fall through
case BLOCK_MAJOR_VERSION_7:
return checkProofOfWorkV1(context, block, currentDiffic, proofOfWork);
case BLOCK_MAJOR_VERSION_2:
// fall through
Expand Down Expand Up @@ -1377,6 +1385,7 @@ CurrencyBuilder::CurrencyBuilder(Logging::ILogger &log)
upgradeHeightV4(parameters::UPGRADE_HEIGHT_V4);
upgradeHeightV5(parameters::UPGRADE_HEIGHT_V5);
upgradeHeightV6(parameters::UPGRADE_HEIGHT_V6);
upgradeHeightV7(parameters::UPGRADE_HEIGHT_V7);
upgradeVotingThreshold(parameters::UPGRADE_VOTING_THRESHOLD);
upgradeVotingWindow(parameters::UPGRADE_VOTING_WINDOW);
upgradeWindow(parameters::UPGRADE_WINDOW);
Expand Down
6 changes: 6 additions & 0 deletions lib/CryptoNoteCore/Currency.h
Expand Up @@ -350,6 +350,7 @@ class Currency
uint32_t m_upgradeHeightV4;
uint32_t m_upgradeHeightV5;
uint32_t m_upgradeHeightV6;
uint32_t m_upgradeHeightV7;
unsigned int m_upgradeVotingThreshold;
uint32_t m_upgradeVotingWindow;
uint32_t m_upgradeWindow;
Expand Down Expand Up @@ -592,6 +593,11 @@ class CurrencyBuilder : boost::noncopyable
m_currency.m_upgradeHeightV6 = static_cast<uint32_t>(val);
return *this;
}
CurrencyBuilder &upgradeHeightV7(uint64_t val)
{
m_currency.m_upgradeHeightV7 = static_cast<uint32_t>(val);
return *this;
}
CurrencyBuilder &upgradeVotingThreshold(unsigned int val);
CurrencyBuilder &upgradeVotingWindow(size_t val)
{
Expand Down
4 changes: 3 additions & 1 deletion lib/Global/Checkpoints.h
Expand Up @@ -60,7 +60,9 @@ const std::initializer_list<CheckpointData> CHECKPOINTS = {
{ 975000,"d86c71508ea2fda4847d518f779fbf1fc55782daea6d1ad299cab813a1415224"},
{1000000,"e9bce0d6277580f91d8ee00e21145830e64085a194862e76e8c26c9ae3541f1a"},
{1025000,"50ef509ed1f4ab13810c06c2cd5f59cf5ed6367771d465044be0497263cd7773"},
{1068800,"0dc4a71306fee724178a6c0f2e2354bc6c502058d8d2ce0d350dc9c617932022"}
{1050000,"f1263795721167f0608494a15257678e18e0f2a87ffa8e9171e465832d583575"},
{1075000,"7a15c2a628a3d09f7aec04ba8f6b9398849c9697f1723d98de3adc191c5a7cb0"},
{1097000,"15eabab1449e78da3c7bb57ae7522f4c4f6d3e2bfde5dbce35f66a0d9dc3c851"}
};

} // namespace CryptoNote
2 changes: 2 additions & 0 deletions lib/Global/CryptoNoteConfig.h
Expand Up @@ -143,6 +143,7 @@ const uint32_t UPGRADE_HEIGHT_V3 = 46000;
const uint32_t UPGRADE_HEIGHT_V4 = 110520;
const uint32_t UPGRADE_HEIGHT_V5 = 250720;
const uint32_t UPGRADE_HEIGHT_V6 = 700000;
const uint32_t UPGRADE_HEIGHT_V7 = 1000000000; //tba

const unsigned UPGRADE_VOTING_THRESHOLD = 90; // percent
const uint32_t UPGRADE_VOTING_WINDOW = EXPECTED_NUMBER_OF_BLOCKS_PER_DAY; // blocks
Expand Down Expand Up @@ -179,6 +180,7 @@ const uint8_t BLOCK_MAJOR_VERSION_3 = 3;
const uint8_t BLOCK_MAJOR_VERSION_4 = 4;
const uint8_t BLOCK_MAJOR_VERSION_5 = 5;
const uint8_t BLOCK_MAJOR_VERSION_6 = 6;
const uint8_t BLOCK_MAJOR_VERSION_7 = 7;

const uint8_t BLOCK_MINOR_VERSION_0 = 0;
const uint8_t BLOCK_MINOR_VERSION_1 = 1;
Expand Down
6 changes: 3 additions & 3 deletions lib/Global/version.h.in
Expand Up @@ -5,9 +5,9 @@
#define PROJECT_SITE "@PROJECT_VENDOR_URL@"
#define PROJECT_COPYRIGHT "@PROJECT_COPYRIGHT@"
#define APP_VER_MAJOR 6
#define APP_VER_MINOR 0
#define APP_VER_REV 9
#define APP_VER_BUILD 6120
#define APP_VER_MINOR 1
#define APP_VER_REV 0
#define APP_VER_BUILD 6125

#define BUILD_COMMIT_ID "@PROJECT_GIT_COMMIT_ID@"
#define PROJECT_VERSION STR(APP_VER_MAJOR) "." STR(APP_VER_MINOR) "." STR(APP_VER_REV)
Expand Down