| 24 | using util::SplitString; |
| 25 | |
| 26 | static void HandleDeploymentArgs(const ArgsManager& args, CChainParams::DeploymentOptions& options) |
| 27 | { |
| 28 | for (const std::string& arg : args.GetArgs("-testactivationheight")) { |
| 29 | const auto found{arg.find('@')}; |
| 30 | if (found == std::string::npos) { |
| 31 | throw std::runtime_error(strprintf("Invalid format (%s) for -testactivationheight=name@height.", arg)); |
| 32 | } |
| 33 | |
| 34 | const auto value{arg.substr(found + 1)}; |
| 35 | const auto height{ToIntegral<int32_t>(value)}; |
| 36 | if (!height || *height < 0 || *height >= std::numeric_limits<int>::max()) { |
| 37 | throw std::runtime_error(strprintf("Invalid height value (%s) for -testactivationheight=name@height.", arg)); |
| 38 | } |
| 39 | |
| 40 | const auto deployment_name{arg.substr(0, found)}; |
| 41 | if (const auto buried_deployment = GetBuriedDeployment(deployment_name)) { |
| 42 | options.activation_heights[*buried_deployment] = *height; |
| 43 | } else { |
| 44 | throw std::runtime_error(strprintf("Invalid name (%s) for -testactivationheight=name@height.", arg)); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | for (const std::string& strDeployment : args.GetArgs("-vbparams")) { |
| 49 | std::vector<std::string> vDeploymentParams = SplitString(strDeployment, ':'); |
| 50 | if (vDeploymentParams.size() < 3 || 4 < vDeploymentParams.size()) { |
| 51 | throw std::runtime_error("Version bits parameters malformed, expecting deployment:start:end[:min_activation_height]"); |
| 52 | } |
| 53 | CChainParams::VersionBitsParameters vbparams{}; |
| 54 | const auto start_time{ToIntegral<int64_t>(vDeploymentParams[1])}; |
| 55 | if (!start_time) { |
| 56 | throw std::runtime_error(strprintf("Invalid nStartTime (%s)", vDeploymentParams[1])); |
| 57 | } |
| 58 | vbparams.start_time = *start_time; |
| 59 | const auto timeout{ToIntegral<int64_t>(vDeploymentParams[2])}; |
| 60 | if (!timeout) { |
| 61 | throw std::runtime_error(strprintf("Invalid nTimeout (%s)", vDeploymentParams[2])); |
| 62 | } |
| 63 | vbparams.timeout = *timeout; |
| 64 | if (vDeploymentParams.size() >= 4) { |
| 65 | const auto min_activation_height{ToIntegral<int64_t>(vDeploymentParams[3])}; |
| 66 | if (!min_activation_height) { |
| 67 | throw std::runtime_error(strprintf("Invalid min_activation_height (%s)", vDeploymentParams[3])); |
| 68 | } |
| 69 | vbparams.min_activation_height = *min_activation_height; |
| 70 | } else { |
| 71 | vbparams.min_activation_height = 0; |
| 72 | } |
| 73 | bool found = false; |
| 74 | for (int j=0; j < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) { |
| 75 | if (vDeploymentParams[0] == VersionBitsDeploymentInfo[j].name) { |
| 76 | options.version_bits_parameters[Consensus::DeploymentPos(j)] = vbparams; |
| 77 | found = true; |
| 78 | LogInfo("Setting version bits activation parameters for %s to start=%ld, timeout=%ld, min_activation_height=%d", |
| 79 | vDeploymentParams[0], vbparams.start_time, vbparams.timeout, vbparams.min_activation_height); |
| 80 | break; |
| 81 | } |
| 82 | } |
| 83 | if (!found) { |
no test coverage detected