From 20948ea6aec27acf45ff1df03a258f7f400dee1d Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Fri, 20 Sep 2024 09:10:39 -0700 Subject: [PATCH] fix settings protocol upgrade path --- src/ledger/NetworkConfig.cpp | 18 ++++++++++++++---- .../test/InvokeHostFunctionTests.cpp | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/ledger/NetworkConfig.cpp b/src/ledger/NetworkConfig.cpp index 46ecd10e3b..4665653dbe 100644 --- a/src/ledger/NetworkConfig.cpp +++ b/src/ledger/NetworkConfig.cpp @@ -346,8 +346,11 @@ updateCpuCostParamsEntryForV21(AbstractLedgerTxn& ltxRoot) .data.configSetting() .contractCostParamsCpuInsns(); + // Resize to fit the last cost type added in v21 + params.resize( + static_cast(ContractCostType::VerifyEcdsaSecp256r1Sig) + 1); + auto const& vals = xdr::xdr_traits::enum_values(); - params.resize(static_cast(vals.size())); // While we loop over the full ContractCostType enum, we only set the range for (auto val : vals) @@ -448,7 +451,9 @@ updateCpuCostParamsEntryForV22(AbstractLedgerTxn& ltxRoot) .contractCostParamsCpuInsns(); auto const& vals = xdr::xdr_traits::enum_values(); - params.resize(static_cast(vals.size())); + + // Resize to fit the last cost type added in v22 + params.resize(static_cast(ContractCostType::Bls12381FrInv) + 1); // While we loop over the full ContractCostType enum, we only set the // entries that have either been updated, or newly created in p22 @@ -770,8 +775,11 @@ updateMemCostParamsEntryForV21(AbstractLedgerTxn& ltxRoot) .data.configSetting() .contractCostParamsMemBytes(); + // Resize to fit the last cost type added in v21 + params.resize( + static_cast(ContractCostType::VerifyEcdsaSecp256r1Sig) + 1); + auto const& vals = xdr::xdr_traits::enum_values(); - params.resize(static_cast(vals.size())); for (auto val : vals) { @@ -873,7 +881,9 @@ updateMemCostParamsEntryForV22(AbstractLedgerTxn& ltxRoot) .contractCostParamsMemBytes(); auto const& vals = xdr::xdr_traits::enum_values(); - params.resize(static_cast(vals.size())); + + // Resize to fit the last cost type added in v22 + params.resize(static_cast(ContractCostType::Bls12381FrInv) + 1); for (auto val : vals) { diff --git a/src/transactions/test/InvokeHostFunctionTests.cpp b/src/transactions/test/InvokeHostFunctionTests.cpp index 88abeffb9e..1c3e54f8b9 100644 --- a/src/transactions/test/InvokeHostFunctionTests.cpp +++ b/src/transactions/test/InvokeHostFunctionTests.cpp @@ -1207,6 +1207,7 @@ TEST_CASE_VERSIONS("refund still happens on bad auth", "[tx][soroban]") TEST_CASE_VERSIONS("refund test with closeLedger", "[tx][soroban][feebump]") { Config cfg = getTestConfig(); + cfg.ENABLE_SOROBAN_DIAGNOSTIC_EVENTS = true; VirtualClock clock; auto app = createTestApplication(clock, cfg);