Skip to content

Commit

Permalink
Add feature flags and GrandCentral fork (#1538)
Browse files Browse the repository at this point in the history
* Add Grand Central fork

* Add feature gates
  • Loading branch information
Bushstar authored Nov 1, 2022
1 parent 888d93c commit 94e6b97
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class CMainParams : public CChainParams {
consensus.FortCanningSpringHeight = 2033000; // July 6, 2022.
consensus.FortCanningGreatWorldHeight = 2212000; // Sep 7th, 2022.
consensus.FortCanningEpilogueHeight = 2257500; // Sep 22nd, 2022.
consensus.GrandCentralHeight = std::numeric_limits<int>::max();

consensus.pos.diffLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
// consensus.pos.nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
Expand Down Expand Up @@ -377,6 +378,7 @@ class CTestNetParams : public CChainParams {
consensus.FortCanningSpringHeight = 1086000;
consensus.FortCanningGreatWorldHeight = 1223000;
consensus.FortCanningEpilogueHeight = 1244000;
consensus.GrandCentralHeight = std::numeric_limits<int>::max();

consensus.pos.diffLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
// consensus.pos.nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
Expand Down Expand Up @@ -571,6 +573,7 @@ class CDevNetParams : public CChainParams {
consensus.FortCanningSpringHeight = std::numeric_limits<int>::max();
consensus.FortCanningGreatWorldHeight = std::numeric_limits<int>::max();
consensus.FortCanningEpilogueHeight = std::numeric_limits<int>::max();
consensus.GrandCentralHeight = std::numeric_limits<int>::max();

consensus.pos.diffLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.pos.nTargetTimespan = 5 * 60; // 5 min == 10 blocks
Expand Down Expand Up @@ -757,6 +760,7 @@ class CRegTestParams : public CChainParams {
consensus.FortCanningSpringHeight = 10000000;
consensus.FortCanningGreatWorldHeight = 10000000;
consensus.FortCanningEpilogueHeight = 10000000;
consensus.GrandCentralHeight = 10000000;

consensus.pos.diffLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.pos.nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
Expand Down Expand Up @@ -982,6 +986,7 @@ void SetupCommonArgActivationParams(Consensus::Params &consensus) {
UpdateHeightValidation("Fort Canning Great World", "-fortcanninggreatworldheight", consensus.FortCanningGreatWorldHeight);
UpdateHeightValidation("Fort Canning Great World", "-greatworldheight", consensus.FortCanningGreatWorldHeight);
UpdateHeightValidation("Fort Canning Epilogue", "-fortcanningepilogueheight", consensus.FortCanningEpilogueHeight);
UpdateHeightValidation("Grand Central", "-grandcentralheight", consensus.GrandCentralHeight);

if (gArgs.GetBoolArg("-simulatemainnet", false)) {
consensus.pos.nTargetTimespan = 5 * 60; // 5 min == 10 blocks
Expand Down
1 change: 1 addition & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct Params {
int FortCanningSpringHeight;
int FortCanningGreatWorldHeight;
int FortCanningEpilogueHeight;
int GrandCentralHeight;

/** Foundation share after AMK, normalized to COIN = 100% */
CAmount foundationShareDFIP1;
Expand Down
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ void SetupServerArgs()
gArgs.AddArg("-fortcanninggreatworldheight", "Fort Canning Great World fork activation height (regtest only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-greatworldheight", "Alias for Fort Canning Great World fork activation height (regtest only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-fortcanningepilogueheight", "Alias for Fort Canning Epilogue fork activation height (regtest only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-grandcentralheight", "Grand Central fork activation height (regtest only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-jellyfish_regtest", "Configure the regtest network for jellyfish testing", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
gArgs.AddArg("-regtest-skip-loan-collateral-validation", "Skip loan collateral check for jellyfish testing", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
gArgs.AddArg("-simulatemainnet", "Configure the regtest network to mainnet target timespan and spacing ", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
Expand Down
31 changes: 30 additions & 1 deletion src/masternodes/govvariables/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const std::map<std::string, uint8_t>& ATTRIBUTES::allowedParamIDs() {
// Note: DFIP2206F is currently in beta testing
// for testnet. May not be enabled on mainnet until testing is complete.
{"dfip2206f", ParamIDs::DFIP2206F},
{"feature", ParamIDs::Feature},
};
return params;
}
Expand All @@ -103,6 +104,7 @@ const std::map<uint8_t, std::string>& ATTRIBUTES::displayParamsIDs() {
{ParamIDs::DFIP2206F, "dfip2206f"},
{ParamIDs::TokenID, "token"},
{ParamIDs::Economy, "economy"},
{ParamIDs::Feature, "feature"},
};
return params;
}
Expand Down Expand Up @@ -158,6 +160,11 @@ const std::map<uint8_t, std::map<std::string, uint8_t>>& ATTRIBUTES::allowedKeys
{"dusd_interest_burn", DFIPKeys::DUSDInterestBurn},
{"dusd_loan_burn", DFIPKeys::DUSDLoanBurn},
{"start_block", DFIPKeys::StartBlock},
{"gov-unset", DFIPKeys::GovUnset},
{"gov-foundation", DFIPKeys::GovFoundation},
{"mn-setrewardaddress", DFIPKeys::MNSetRewardAddress},
{"mn-setoperatoraddress", DFIPKeys::MNSetOperatorAddress},
{"mn-setowneraddress", DFIPKeys::MNSetOwnerAddress},
}
},
};
Expand Down Expand Up @@ -204,6 +211,11 @@ const std::map<uint8_t, std::map<uint8_t, std::string>>& ATTRIBUTES::displayKeys
{DFIPKeys::DUSDInterestBurn, "dusd_interest_burn"},
{DFIPKeys::DUSDLoanBurn, "dusd_loan_burn"},
{DFIPKeys::StartBlock, "start_block"},
{DFIPKeys::GovUnset, "gov-unset"},
{DFIPKeys::GovFoundation, "gov-foundation"},
{DFIPKeys::MNSetRewardAddress, "mn-setrewardaddress"},
{DFIPKeys::MNSetOperatorAddress, "mn-setoperatoraddress"},
{DFIPKeys::MNSetOwnerAddress, "mn-setowneraddress"},
}
},
{
Expand Down Expand Up @@ -378,6 +390,11 @@ const std::map<uint8_t, std::map<uint8_t,
{DFIPKeys::DUSDInterestBurn, VerifyBool},
{DFIPKeys::DUSDLoanBurn, VerifyBool},
{DFIPKeys::StartBlock, VerifyInt64},
{DFIPKeys::GovUnset, VerifyBool},
{DFIPKeys::GovFoundation, VerifyBool},
{DFIPKeys::MNSetRewardAddress, VerifyBool},
{DFIPKeys::MNSetOperatorAddress, VerifyBool},
{DFIPKeys::MNSetOwnerAddress, VerifyBool},
}
},
{
Expand Down Expand Up @@ -546,6 +563,14 @@ Res ATTRIBUTES::ProcessVariable(const std::string& key, const std::string& value
typeKey != DFIPKeys::DUSDLoanBurn) {
return Res::Err("Unsupported type for DFIP2206A {%d}", typeKey);
}
} else if (typeId == ParamIDs::Feature) {
if (typeKey != DFIPKeys::GovUnset &&
typeKey != DFIPKeys::GovFoundation &&
typeKey != DFIPKeys::MNSetRewardAddress &&
typeKey != DFIPKeys::MNSetOperatorAddress &&
typeKey != DFIPKeys::MNSetOwnerAddress) {
return Res::Err("Unsupported type for Feature {%d}", typeKey);
}
} else {
return Res::Err("Unsupported Param ID");
}
Expand Down Expand Up @@ -1052,7 +1077,11 @@ Res ATTRIBUTES::Validate(const CCustomCSView & view) const
break;

case AttributeTypes::Param:
if (attrV0->typeId == ParamIDs::DFIP2206F || attrV0->key == DFIPKeys::StartBlock || attrV0->typeId == ParamIDs::DFIP2206A) {
if (attrV0->typeId == ParamIDs::Feature) {
if (view.GetLastHeight() < Params().GetConsensus().GrandCentralHeight) {
return Res::Err("Cannot be set before GrandCentralHeight");
}
} else if (attrV0->typeId == ParamIDs::DFIP2206F || attrV0->key == DFIPKeys::StartBlock || attrV0->typeId == ParamIDs::DFIP2206A) {
if (view.GetLastHeight() < Params().GetConsensus().FortCanningSpringHeight) {
return Res::Err("Cannot be set before FortCanningSpringHeight");
}
Expand Down
6 changes: 6 additions & 0 deletions src/masternodes/govvariables/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum ParamIDs : uint8_t {
Economy = 'e',
DFIP2206A = 'f',
DFIP2206F = 'g',
Feature = 'h',
};

enum OracleIDs : uint8_t {
Expand Down Expand Up @@ -59,6 +60,11 @@ enum DFIPKeys : uint8_t {
DUSDInterestBurn = 'g',
DUSDLoanBurn = 'h',
StartBlock = 'i',
GovUnset = 'j',
GovFoundation = 'k',
MNSetRewardAddress = 'l',
MNSetOperatorAddress = 'm',
MNSetOwnerAddress = 'n',
};

enum TokenKeys : uint8_t {
Expand Down
7 changes: 7 additions & 0 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ class CCustomMetadataParseVisitor
return Res::Ok();
}

Res isPostGrandCentralFork() const {
if(static_cast<int>(height) < consensus.GrandCentralHeight) {
return Res::Err("called before GrandCentral height");
}
return Res::Ok();
}

template<typename T>
Res serialize(T& obj) const {
CDataStream ss(metadata, SER_NETWORK, PROTOCOL_VERSION);
Expand Down
1 change: 1 addition & 0 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
BuriedForkDescPushBack(softforks, "fortcanningspring", consensusParams.FortCanningSpringHeight);
BuriedForkDescPushBack(softforks, "fortcanninggreatworld", consensusParams.FortCanningGreatWorldHeight);
BuriedForkDescPushBack(softforks, "fortcanningepilogue", consensusParams.FortCanningEpilogueHeight);
BuriedForkDescPushBack(softforks, "grandcentral", consensusParams.GrandCentralHeight);
BIP9SoftForkDescPushBack(softforks, "testdummy", consensusParams, Consensus::DEPLOYMENT_TESTDUMMY);
obj.pushKV("softforks", softforks);

Expand Down
1 change: 1 addition & 0 deletions test/functional/rpc_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def _test_getblockchaininfo(self):
'fortcanningspring': {'type': 'buried', 'active': False, 'height': 10000000},
'fortcanninggreatworld': {'type': 'buried', 'active': False, 'height': 10000000},
'fortcanningepilogue': {'type': 'buried', 'active': False, 'height': 10000000},
'grandcentral': {'type': 'buried', 'active': False, 'height': 10000000},
'testdummy': {
'type': 'bip9',
'bip9': {
Expand Down

0 comments on commit 94e6b97

Please sign in to comment.