diff --git a/include/xrpl/ledger/helpers/EscrowHelpers.h b/include/xrpl/ledger/helpers/EscrowHelpers.h index 27ed155545..059a1f0d35 100644 --- a/include/xrpl/ledger/helpers/EscrowHelpers.h +++ b/include/xrpl/ledger/helpers/EscrowHelpers.h @@ -256,7 +256,7 @@ escrowUnlockApplyHelper( } template -static uint32_t +static int32_t calculateAdditionalReserve(T const& finishFunction) { if (!finishFunction) diff --git a/src/libxrpl/tx/Transactor.cpp b/src/libxrpl/tx/Transactor.cpp index 59fdc9749c..c319f63b5b 100644 --- a/src/libxrpl/tx/Transactor.cpp +++ b/src/libxrpl/tx/Transactor.cpp @@ -1208,11 +1208,14 @@ Transactor::checkMultiSign( //------------------------------------------------------------------------------ static void -removeUnfundedOffers(ApplyView& view, std::vector const& offers, beast::Journal viewJ) +removeUnfundedOffers( + ApplyView& view, + std::vector> const& offers, + beast::Journal viewJ) { int removed = 0; - for (auto const& index : offers) + for (auto const& [index, _] : offers) { if (auto const sleOffer = view.peek(keylet::offer(index))) { @@ -1227,12 +1230,12 @@ removeUnfundedOffers(ApplyView& view, std::vector const& offers, beast: static void removeExpiredNFTokenOffers( ApplyView& view, - std::vector const& offers, + std::vector> const& offers, beast::Journal viewJ) { std::size_t removed = 0; - for (auto const& index : offers) + for (auto const& [index, _] : offers) { if (auto const offer = view.peek(keylet::nftokenOffer(index))) { @@ -1244,9 +1247,12 @@ removeExpiredNFTokenOffers( } static void -removeExpiredCredentials(ApplyView& view, std::vector const& creds, beast::Journal viewJ) +removeExpiredCredentials( + ApplyView& view, + std::vector> const& creds, + beast::Journal viewJ) { - for (auto const& index : creds) + for (auto const& [index, _] : creds) { if (auto const sle = view.peek(keylet::credential(index))) { @@ -1263,14 +1269,14 @@ removeExpiredCredentials(ApplyView& view, std::vector const& creds, bea static void modifyWasmDataFields( ApplyView& view, - std::vector> const& wasmObjects, + std::vector> const& wasmObjects, beast::Journal viewJ) { - for (auto const& [index, data] : wasmObjects) + for (auto const& [index, after] : wasmObjects) { if (auto const sle = view.peek(keylet::escrow(index))) { - sle->setFieldVL(sfData, data); + sle->setFieldVL(sfData, after->getFieldVL(sfData)); view.update(sle); } } @@ -1279,7 +1285,7 @@ modifyWasmDataFields( static void removeDeletedTrustLines( ApplyView& view, - std::vector const& trustLines, + std::vector> const& trustLines, beast::Journal viewJ) { if (trustLines.size() > kMaxDeletableAmmTrustLines) @@ -1289,7 +1295,7 @@ removeDeletedTrustLines( return; } - for (auto const& index : trustLines) + for (auto const& [index, _] : trustLines) { if (auto const sleState = view.peek({ltRIPPLE_STATE, index}); !isTesSuccess(deleteAMMTrustLine(view, sleState, std::nullopt, viewJ))) @@ -1478,7 +1484,7 @@ Transactor::processPersistentChanges(TER result, XRPAmount fee) // re-applied after the context is reset. auto const typesToCollect = typesForResult(result); - std::map> deletedObjects; + std::map>> deletedObjects; if (!typesToCollect.empty()) { ctx_.visit( @@ -1502,7 +1508,7 @@ Transactor::processPersistentChanges(TER result, XRPAmount fee) after->getFieldAmount(sfTakerPays)) return; - deletedObjects[type].push_back(index); + deletedObjects[type].push_back({index, after}); } } } diff --git a/src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp b/src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp index 21127326e1..b95245257a 100644 --- a/src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp +++ b/src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp @@ -92,8 +92,11 @@ EscrowCreate::checkExtraFeatures(PreflightContext const& ctx) // Only require featureMPTokensV1 when the escrow amount is an MPT and // fixCleanup3_2_0 is active; XRP/IOU escrows are unaffected by this gate. if (ctx.rules.enabled(fixCleanup3_2_0) && ctx.tx[sfAmount].holds()) - return ctx.rules.enabled(featureMPTokensV1); - return true; + if (!ctx.rules.enabled(featureMPTokensV1)) + return false; + + return (!ctx.tx.isFieldPresent(sfBytecode) && !ctx.tx.isFieldPresent(sfData)) || + ctx.rules.enabled(featureSmartEscrow); } template @@ -141,13 +144,6 @@ EscrowCreate::calculateBaseFee(ReadView const& view, STTx const& tx) return txnFees; } -bool -EscrowCreate::checkExtraFeatures(PreflightContext const& ctx) -{ - return (!ctx.tx.isFieldPresent(sfBytecode) && !ctx.tx.isFieldPresent(sfData)) || - ctx.rules.enabled(featureSmartEscrow); -} - NotTEC EscrowCreate::preflight(PreflightContext const& ctx) { @@ -215,7 +211,7 @@ EscrowCreate::preflight(PreflightContext const& ctx) return temMALFORMED; } auto const data = ctx.tx.getFieldVL(sfData); - if (data.size() > maxWasmDataLength) + if (data.size() > kMaxWasmDataLength) { JLOG(ctx.j.debug()) << "EscrowCreate.Data bad size " << data.size(); return temMALFORMED; @@ -225,14 +221,14 @@ EscrowCreate::preflight(PreflightContext const& ctx) if (ctx.tx.isFieldPresent(sfBytecode)) { auto const fees(ctx.registry.get().getFees()); - if (fees.extensionSizeLimit == 0 || fees.extensionComputeLimit == 0) + if (fees.bytecodeSizeLimit == 0 || fees.gasLimit == 0) { JLOG(ctx.j.debug()) << "WASM runtime deactivated by fee voting"; return temTEMP_DISABLED; } auto const code = ctx.tx.getFieldVL(sfBytecode); - if (code.empty() || code.size() > fees.extensionSizeLimit) + if (code.empty() || code.size() > fees.bytecodeSizeLimit) { JLOG(ctx.j.debug()) << "EscrowCreate.Bytecode bad size " << code.size(); return temMALFORMED; diff --git a/src/libxrpl/tx/transactors/escrow/EscrowFinish.cpp b/src/libxrpl/tx/transactors/escrow/EscrowFinish.cpp index b741b8c816..a847dded69 100644 --- a/src/libxrpl/tx/transactors/escrow/EscrowFinish.cpp +++ b/src/libxrpl/tx/transactors/escrow/EscrowFinish.cpp @@ -78,9 +78,8 @@ EscrowFinish::checkExtraFeatures(PreflightContext const& ctx) return false; if (ctx.tx.isFieldPresent(sfGas) && !ctx.rules.enabled(featureSmartEscrow)) - { return false; - } + return true; } @@ -101,7 +100,7 @@ EscrowFinish::preflight(PreflightContext const& ctx) if (auto const allowance = ctx.tx[~sfGas]; allowance) { auto const fees(ctx.registry.get().getFees()); - if (fees.extensionComputeLimit == 0) + if (fees.bytecodeSizeLimit == 0) { JLOG(ctx.j.debug()) << "WASM runtime deactivated by fee voting"; return temTEMP_DISABLED; @@ -110,7 +109,7 @@ EscrowFinish::preflight(PreflightContext const& ctx) { return temBAD_LIMIT; } - if (*allowance > fees.extensionComputeLimit) + if (*allowance > fees.bytecodeSizeLimit) { JLOG(ctx.j.debug()) << "Gas too large: " << *allowance; return temBAD_LIMIT; @@ -423,7 +422,7 @@ EscrowFinish::doApply() if (auto const& data = ledgerDataProvider.getData(); data.has_value()) { - if (data->size() > maxWasmDataLength) + if (data->size() > kMaxWasmDataLength) { // should already be checked in the updateData host function return tecINTERNAL; // LCOV_EXCL_LINE @@ -451,8 +450,8 @@ EscrowFinish::doApply() } else { - JLOG(j_.debug()) << "WASM Failure: " + transHuman(re.error()); - return re.error(); + JLOG(j_.debug()) << "WASM Failure: " + transHuman(re.error().ter); + return re.error().ter; } } diff --git a/src/test/app/EscrowSmart_test.cpp b/src/test/app/EscrowSmart_test.cpp index 159fc4b0b8..21754e5d40 100644 --- a/src/test/app/EscrowSmart_test.cpp +++ b/src/test/app/EscrowSmart_test.cpp @@ -99,7 +99,7 @@ struct EscrowSmart_test : public beast::unit_test::Suite Env env( *this, envconfig([](std::unique_ptr cfg) { - cfg->FEES.extension_size_limit = 10; // 10 bytes + cfg->fees.bytecodeSizeLimit = 10; // 10 bytes return cfg; }), features); @@ -125,7 +125,7 @@ struct EscrowSmart_test : public beast::unit_test::Suite *this, envconfig([](std::unique_ptr cfg) { // WASM runtime disabled - cfg->FEES.extension_compute_limit = 0; + cfg->fees.gasLimit = 0; return cfg; }), features); @@ -149,7 +149,7 @@ struct EscrowSmart_test : public beast::unit_test::Suite Env env( *this, envconfig([](std::unique_ptr cfg) { - cfg->FEES.extension_size_limit = 0; // WASM upload disabled + cfg->fees.bytecodeSizeLimit = 0; // WASM upload disabled return cfg; }), features); @@ -202,8 +202,8 @@ struct EscrowSmart_test : public beast::unit_test::Suite auto const escrowCreate = escrow::create(alice, carol, XRP(500)); - // string of length maxWasmDataLength * 2 + 2 - std::string const longData((maxWasmDataLength + 1) * 2, 'B'); + // string of length kMaxWasmDataLength * 2 + 2 + std::string const longData((kMaxWasmDataLength + 1) * 2, 'B'); env(escrowCreate, escrow::Data(longData), escrow::Bytecode(kLedgerSqnWasmHex), @@ -216,7 +216,7 @@ struct EscrowSmart_test : public beast::unit_test::Suite Env env( *this, envconfig([](std::unique_ptr cfg) { - cfg->START_UP = StartUpType::Fresh; + cfg->startUp = StartUpType::Fresh; return cfg; }), features); @@ -374,7 +374,7 @@ struct EscrowSmart_test : public beast::unit_test::Suite Env env( *this, envconfig([](std::unique_ptr cfg) { - cfg->FEES.extension_compute_limit = 1'000; // in gas + cfg->fees.gasLimit = 1'000; // in gas return cfg; }), features); @@ -397,7 +397,7 @@ struct EscrowSmart_test : public beast::unit_test::Suite using namespace test::jtx; using namespace std::chrono; Env env{*this, envconfig([](std::unique_ptr cfg) { - cfg->FEES.extension_compute_limit = 0; + cfg->fees.gasLimit = 0; return cfg; })}; @@ -890,7 +890,7 @@ struct EscrowSmart_test : public beast::unit_test::Suite Env env( *this, envconfig([](std::unique_ptr cfg) { - cfg->FEES.gas_price = 1'000'000; // in gas + cfg->fees.gasPrice = 1'000'000; // in gas return cfg; }), features); @@ -1135,7 +1135,7 @@ struct EscrowSmart_test : public beast::unit_test::Suite return Env( *this, envconfig([&sizeLimit](std::unique_ptr cfg) { - cfg->FEES.extension_size_limit = *sizeLimit; + cfg->fees.bytecodeSizeLimit = *sizeLimit; return cfg; }), features); diff --git a/src/test/jtx/impl/envconfig.cpp b/src/test/jtx/impl/envconfig.cpp index 9b880d5c5a..d9ca366bd8 100644 --- a/src/test/jtx/impl/envconfig.cpp +++ b/src/test/jtx/impl/envconfig.cpp @@ -21,7 +21,7 @@ setupConfigForUnitTests(Config& cfg) using namespace jtx; // Default fees to old values, so tests don't have to worry about changes in // Config.h - // NOTE: For new `FEES` fields, you need to wait for the first flag ledger + // NOTE: For new `fees` fields, you need to wait for the first flag ledger // to close for the values to be activated. cfg.fees.referenceFee = UNIT_TEST_REFERENCE_FEE; cfg.fees.accountReserve = XRP(200).value().xrp().drops(); diff --git a/src/tests/libxrpl/helpers/TestServiceRegistry.h b/src/tests/libxrpl/helpers/TestServiceRegistry.h index a1b0ea2a2a..ed70cc6f5b 100644 --- a/src/tests/libxrpl/helpers/TestServiceRegistry.h +++ b/src/tests/libxrpl/helpers/TestServiceRegistry.h @@ -75,8 +75,8 @@ class TestServiceRegistry : public ServiceRegistry defaultFees() { Fees fees{XRPAmount{10}, XRPAmount{10 * kDropsPerXrp}, XRPAmount{2 * kDropsPerXrp}}; - fees.extensionComputeLimit = 1'000'000; - fees.extensionSizeLimit = 100'000; + fees.gasLimit = 1'000'000; + fees.bytecodeSizeLimit = 100'000; fees.gasPrice = 1'000'000; return fees; } diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index c864df1452..b90f74cf15 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -824,15 +824,15 @@ public: { XRPL_ASSERT(config_, "xrpl::ApplicationImp::getFees : non-null config"); - auto const& f1(config_->FEES); + auto const& f1(config_->fees); Fees f2; - f2.base = f1.reference_fee; - f2.reserve = f1.account_reserve; - f2.increment = f1.owner_reserve; - f2.extensionComputeLimit = f1.extension_compute_limit; - f2.extensionSizeLimit = f1.extension_size_limit; - f2.gasPrice = f1.gas_price; + f2.base = f1.referenceFee; + f2.reserve = f1.accountReserve; + f2.increment = f1.ownerReserve; + f2.gasLimit = f1.gasLimit; + f2.bytecodeSizeLimit = f1.bytecodeSizeLimit; + f2.gasPrice = f1.gasPrice; return f2; }