Merge pull request #5832 from therealyingtong/miner-latest-height

Use height of latest network upgrade in -mineraddress validation.
This commit is contained in:
str4d 2022-04-08 03:01:20 +01:00 committed by GitHub
commit 5f60f33daf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 2 deletions

View File

@ -25,6 +25,15 @@ namespace Consensus {
return NetworkUpgradeState(nHeight, *this, idx) == UPGRADE_ACTIVE;
}
int Params::HeightOfLatestSettledUpgrade() const {
for (auto idxInt = Consensus::MAX_NETWORK_UPGRADES - 1; idxInt > Consensus::BASE_SPROUT; idxInt--) {
if (vUpgrades[idxInt].hashActivationBlock.has_value()) {
return vUpgrades[idxInt].nActivationHeight;
}
}
return 0;
}
bool Params::FeatureRequired(const Consensus::ConsensusFeature feature) const {
return vRequiredFeatures.count(feature) > 0;
}

View File

@ -237,6 +237,12 @@ struct Params {
*/
bool NetworkUpgradeActive(int nHeight, Consensus::UpgradeIndex idx) const;
/**
* Returns the activation height of the latest settled upgrade, as defined
* in <https://zips.z.cash/protocol/protocol.pdf#blockchain>.
*/
int HeightOfLatestSettledUpgrade() const;
bool FutureTimestampSoftForkActive(int nHeight) const;
bool FeatureActive(int nHeight, Consensus::ConsensusFeature feature) const;

View File

@ -1099,9 +1099,11 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
#ifdef ENABLE_MINING
if (mapArgs.count("-mineraddress")) {
auto addr = keyIO.DecodePaymentAddress(mapArgs["-mineraddress"]);
if (!(addr.has_value() && std::visit(ExtractMinerAddress(chainparams.GetConsensus(), 0), addr.value()).has_value())) {
auto consensus = chainparams.GetConsensus();
int height = consensus.HeightOfLatestSettledUpgrade();
if (!(addr.has_value() && std::visit(ExtractMinerAddress(consensus, height), addr.value()).has_value())) {
return InitError(strprintf(
_("Invalid address for -mineraddress=<addr>: '%s' (must be a Sapling or transparent P2PKH address)"),
_("Invalid address for -mineraddress=<addr>: '%s' (must be a Sapling or transparent P2PKH address, or a Unified Address containing a valid receiver for the most recent settled network upgrade.)"),
mapArgs["-mineraddress"]));
}
}