Skip to content

Commit

Permalink
Add facility and test for checking if Axion upgrade is enabled
Browse files Browse the repository at this point in the history
Summary: This can be used for activating changes going into the next upgrade.

Test Plan: `ninja check`

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Subscribers: deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D6780
  • Loading branch information
jasonbcox authored and ftrader committed Jul 11, 2020
1 parent d0750a1 commit edda65d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/consensus/activation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,13 @@ bool IsPhononEnabled(const Consensus::Params &params,
return pindexPrev->GetMedianTimePast() >=
gArgs.GetArg("-phononactivationtime", params.phononActivationTime);
}

bool IsAxionEnabled(const Consensus::Params &params,
const CBlockIndex *pindexPrev) {
if (pindexPrev == nullptr) {
return false;
}

return pindexPrev->GetMedianTimePast() >=
gArgs.GetArg("-axionactivationtime", params.axionActivationTime);
}
4 changes: 4 additions & 0 deletions src/consensus/activation.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ bool IsGravitonEnabled(const Consensus::Params &params,
bool IsPhononEnabled(const Consensus::Params &params,
const CBlockIndex *pindexPrev);

/** Check if November 15th, 2020 protocol upgrade has activated. */
bool IsAxionEnabled(const Consensus::Params &params,
const CBlockIndex *pindexPrev);

#endif // BITCOIN_CONSENSUS_ACTIVATION_H
6 changes: 5 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,11 @@ void SetupServerArgs() {
// GUI args. These will be overwritten by SetupUIArgs for the GUI
"-allowselfsignedrootcertificates", "-choosedatadir", "-lang=<lang>",
"-min", "-resetguisettings", "-rootcertificates=<file>", "-splash",
"-uiplatform"};
"-uiplatform",
// TODO remove after the May 2020 upgrade
"-phononactivationtime",
// TODO remove after the November 2020 upgrade
"-axionactivationtime"};

// Set all of the args and their help
// When adding new options to the categories, please keep and ensure alphabetical ordering.
Expand Down
26 changes: 26 additions & 0 deletions src/test/activation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,30 @@ BOOST_AUTO_TEST_CASE(isphononenabled) {
BOOST_CHECK(IsPhononEnabled(params, &blocks.back()));
}

BOOST_AUTO_TEST_CASE(isaxionenabled) {
CBlockIndex prev;

const Consensus::Params &params = Params().GetConsensus();
const auto activation =
gArgs.GetArg("-axionactivationtime", params.axionActivationTime);
SetMockTime(activation - 1000000);

BOOST_CHECK(!IsAxionEnabled(params, nullptr));

std::array<CBlockIndex, 12> blocks;
for (size_t i = 1; i < blocks.size(); ++i) {
blocks[i].pprev = &blocks[i - 1];
}
BOOST_CHECK(!IsAxionEnabled(params, &blocks.back()));

SetMTP(blocks, activation - 1);
BOOST_CHECK(!IsAxionEnabled(params, &blocks.back()));

SetMTP(blocks, activation);
BOOST_CHECK(IsAxionEnabled(params, &blocks.back()));

SetMTP(blocks, activation + 1);
BOOST_CHECK(IsAxionEnabled(params, &blocks.back()));
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit edda65d

Please sign in to comment.