Skip to content

Commit

Permalink
Fix upgrade validation (#4485)
Browse files Browse the repository at this point in the history
# Description

Fix the upgrade validation to handle settings upgrades for the previous
protocol. Also rewrote the condition so our test cases will catch this
issue next time settings are added.

<!---

Describe what this pull request does, which issue it's resolving
(usually applicable for code changes).

--->

# Checklist
- [ ] Reviewed the
[contributing](https://github.com/stellar/stellar-core/blob/master/CONTRIBUTING.md#submitting-changes)
document
- [ ] Rebased on top of master (no merge commits)
- [ ] Ran `clang-format` v8.0.0 (via `make format` or the Visual Studio
extension)
- [ ] Compiles
- [ ] Ran all tests
- [ ] If change impacts performance, include supporting evidence per the
[performance
document](https://github.com/stellar/stellar-core/blob/master/performance-eval/performance-eval.md)
  • Loading branch information
sisuresh authored Sep 25, 2024
2 parents 810e474 + 8b45ec6 commit 0256109
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/ledger/NetworkConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2047,11 +2047,25 @@ bool
SorobanNetworkConfig::isValidCostParams(ContractCostParams const& params,
uint32_t ledgerVersion)
{
auto numberOfCostTypes =
protocolVersionIsBefore(ledgerVersion, ProtocolVersion::V_21)
? static_cast<uint32_t>(ContractCostType::ChaCha20DrawBytes) + 1
: xdr::xdr_traits<ContractCostType>::enum_values().size();
if (params.size() != numberOfCostTypes)
auto getNumCostTypes = [](uint32_t ledgerVersion) -> uint32_t {
if (protocolVersionIsBefore(ledgerVersion, ProtocolVersion::V_21))
{
return static_cast<uint32_t>(ContractCostType::ChaCha20DrawBytes) +
1;
}
else if (protocolVersionIsBefore(ledgerVersion, ProtocolVersion::V_22))
{
return static_cast<uint32_t>(
ContractCostType::VerifyEcdsaSecp256r1Sig) +
1;
}
else
{
return static_cast<uint32_t>(ContractCostType::Bls12381FrInv) + 1;
}
};

if (params.size() != getNumCostTypes(ledgerVersion))
{
return false;
}
Expand Down

0 comments on commit 0256109

Please sign in to comment.