From 28a88161aff85c5c8a305cb6d481fdd3992e63de Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 13 Jun 2023 10:30:16 -0700 Subject: [PATCH 1/9] Bump expiration op --- src/transactions/BumpExpirationOpFrame.cpp | 173 ++++++++++++++++++ src/transactions/BumpExpirationOpFrame.h | 53 ++++++ src/transactions/OperationFrame.cpp | 3 + src/transactions/TransactionFrame.cpp | 5 +- .../test/InvokeHostFunctionTests.cpp | 56 +++++- 5 files changed, 287 insertions(+), 3 deletions(-) create mode 100644 src/transactions/BumpExpirationOpFrame.cpp create mode 100644 src/transactions/BumpExpirationOpFrame.h diff --git a/src/transactions/BumpExpirationOpFrame.cpp b/src/transactions/BumpExpirationOpFrame.cpp new file mode 100644 index 0000000000..a1e09c4216 --- /dev/null +++ b/src/transactions/BumpExpirationOpFrame.cpp @@ -0,0 +1,173 @@ +// Copyright 2023 Stellar Development Foundation and contributors. Licensed +// under the Apache License, Version 2.0. See the COPYING file at the root +// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 + +#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION +#include "transactions/BumpExpirationOpFrame.h" + +namespace stellar +{ + +struct BumpExpirationMetrics +{ + medida::MetricsRegistry& mMetrics; + + size_t mLedgerWriteByte{0}; + + BumpExpirationMetrics(medida::MetricsRegistry& metrics) : mMetrics(metrics) + { + } + + ~BumpExpirationMetrics() + { + mMetrics + .NewMeter({"soroban", "bump-exp-op", "write-ledger-byte"}, "byte") + .Mark(mLedgerWriteByte); + } +}; + +BumpExpirationOpFrame::BumpExpirationOpFrame(Operation const& op, + OperationResult& res, + TransactionFrame& parentTx) + : OperationFrame(op, res, parentTx) + , mBumpExpirationOp(mOperation.body.bumpExpirationOp()) +{ +} + +ThresholdLevel +BumpExpirationOpFrame::getThresholdLevel() const +{ + return ThresholdLevel::LOW; +} + +bool +BumpExpirationOpFrame::isOpSupported(LedgerHeader const& header) const +{ + return header.ledgerVersion >= 20; +} + +bool +BumpExpirationOpFrame::doApply(AbstractLedgerTxn& ltx) +{ + throw std::runtime_error("BumpExpirationOpFrame::doApply needs Config"); +} + +bool +BumpExpirationOpFrame::doApply(Application& app, AbstractLedgerTxn& ltx, + Hash const& sorobanBasePrngSeed) +{ + BumpExpirationMetrics metrics(app.getMetrics()); + + auto const& resources = mParentTx.sorobanResources(); + auto const& footprint = resources.footprint; + + UnorderedMap originalExpirations; + + for (auto const& lk : footprint.readOnly) + { + // When we move to use EXPIRATION_EXTENSIONS, this should become a + // loadWithoutRecord, and the metrics should be updated. + auto ltxe = ltx.load(lk); + if (ltxe) + { + auto keySize = xdr::xdr_size(lk); + auto entrySize = xdr::xdr_size(ltxe.current()); + metrics.mLedgerWriteByte += keySize; + metrics.mLedgerWriteByte += entrySize; + + // Divide the limit by 2 for the metadata check since the previous + // state is also included in the meta. + if (resources.extendedMetaDataSizeBytes / 2 < + metrics.mLedgerWriteByte || + resources.readBytes < metrics.mLedgerWriteByte || + resources.writeBytes < metrics.mLedgerWriteByte) + { + innerResult().code(BUMP_EXPIRATION_RESOURCE_LIMIT_EXCEEDED); + return false; + } + + originalExpirations.emplace(LedgerEntryKey(ltxe.current()), + getExpirationLedger(ltxe.current())); + + auto ledgerSeq = ltx.loadHeader().current().ledgerSeq; + uint32_t bumpTo = UINT32_MAX; + if (UINT32_MAX - ledgerSeq > mBumpExpirationOp.ledgersToExpire()) + { + bumpTo = ledgerSeq + mBumpExpirationOp.ledgersToExpire(); + } + + if (getExpirationLedger(ltxe.current()) < bumpTo) + { + setExpirationLedger(ltxe.current(), bumpTo); + } + } + } + + mParentTx.pushInitialExpirations(std::move(originalExpirations)); + + innerResult().code(BUMP_EXPIRATION_SUCCESS); + return true; +} + +bool +BumpExpirationOpFrame::doCheckValid(SorobanNetworkConfig const& config, + uint32_t ledgerVersion) +{ + auto const& footprint = mParentTx.sorobanResources().footprint; + if (!footprint.readWrite.empty()) + { + innerResult().code(BUMP_EXPIRATION_MALFORMED); + return false; + } + + for (auto const& lk : footprint.readOnly) + { + if (!isSorobanEntry(lk)) + { + innerResult().code(BUMP_EXPIRATION_MALFORMED); + return false; + } + } + + // check for duplicates + UnorderedSet set; + for (auto const& lk : footprint.readOnly) + { + if (!set.emplace(lk).second) + { + innerResult().code(BUMP_EXPIRATION_MALFORMED); + return false; + } + } + + if (mBumpExpirationOp.ledgersToExpire() > + config.stateExpirationSettings().maxEntryExpiration) + { + innerResult().code(BUMP_EXPIRATION_MALFORMED); + return false; + } + + return true; +} + +bool +BumpExpirationOpFrame::doCheckValid(uint32_t ledgerVersion) +{ + throw std::runtime_error( + "BumpExpirationOpFrame::doCheckValid needs Config"); +} + +void +BumpExpirationOpFrame::insertLedgerKeysToPrefetch( + UnorderedSet& keys) const +{ +} + +bool +BumpExpirationOpFrame::isSoroban() const +{ + return true; +} +} + +#endif // ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION diff --git a/src/transactions/BumpExpirationOpFrame.h b/src/transactions/BumpExpirationOpFrame.h new file mode 100644 index 0000000000..d0556ed97e --- /dev/null +++ b/src/transactions/BumpExpirationOpFrame.h @@ -0,0 +1,53 @@ +#pragma once + +// Copyright 2023 Stellar Development Foundation and contributors. Licensed +// under the Apache License, Version 2.0. See the COPYING file at the root +// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 + +#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION +#include "transactions/OperationFrame.h" +#include "xdr/Stellar-transaction.h" + +namespace stellar +{ +class AbstractLedgerTxn; + +class BumpExpirationOpFrame : public OperationFrame +{ + BumpExpirationResult& + innerResult() + { + return mResult.tr().bumpExpirationResult(); + } + + BumpExpirationOp const& mBumpExpirationOp; + + public: + BumpExpirationOpFrame(Operation const& op, OperationResult& res, + TransactionFrame& parentTx); + + ThresholdLevel getThresholdLevel() const override; + + bool isOpSupported(LedgerHeader const& header) const override; + + bool doApply(AbstractLedgerTxn& ltx) override; + bool doApply(Application& app, AbstractLedgerTxn& ltx, + Hash const& sorobanBasePrngSeed) override; + + bool doCheckValid(SorobanNetworkConfig const& config, + uint32_t ledgerVersion) override; + bool doCheckValid(uint32_t ledgerVersion) override; + + void + insertLedgerKeysToPrefetch(UnorderedSet& keys) const override; + + static BumpExpirationOpResultCode + getInnerCode(OperationResult const& res) + { + return res.tr().bumpExpirationResult().code(); + } + + virtual bool isSoroban() const override; +}; +} +#endif // ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION diff --git a/src/transactions/OperationFrame.cpp b/src/transactions/OperationFrame.cpp index 6783244244..15d069cc35 100644 --- a/src/transactions/OperationFrame.cpp +++ b/src/transactions/OperationFrame.cpp @@ -5,6 +5,7 @@ #include "transactions/OperationFrame.h" #include "transactions/AllowTrustOpFrame.h" #include "transactions/BeginSponsoringFutureReservesOpFrame.h" +#include "transactions/BumpExpirationOpFrame.h" #include "transactions/BumpSequenceOpFrame.h" #include "transactions/ChangeTrustOpFrame.h" #include "transactions/ClaimClaimableBalanceOpFrame.h" @@ -118,6 +119,8 @@ OperationFrame::makeHelper(Operation const& op, OperationResult& res, #ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION case INVOKE_HOST_FUNCTION: return std::make_shared(op, res, tx); + case BUMP_EXPIRATION: + return std::make_shared(op, res, tx); #endif default: ostringstream err; diff --git a/src/transactions/TransactionFrame.cpp b/src/transactions/TransactionFrame.cpp index 38594360bb..279edbbd81 100644 --- a/src/transactions/TransactionFrame.cpp +++ b/src/transactions/TransactionFrame.cpp @@ -1667,6 +1667,8 @@ TransactionFrame::applyExpirationBumps(Application& app, AbstractLedgerTxn& ltx) } } + bool isBumpOp = + mOperations.front()->getOperation().body.type() == BUMP_EXPIRATION; // TODO: Write expiration extension entries instead of witing whole entry for (auto const& key : resources.footprint.readOnly) { @@ -1674,7 +1676,8 @@ TransactionFrame::applyExpirationBumps(Application& app, AbstractLedgerTxn& ltx) if (lte && isSorobanDataEntry(lte.current().data)) { // Must enforce minimum expirations on write - bump(lte.current(), autoBumpEnabled(lte.current()), true); + bump(lte.current(), autoBumpEnabled(lte.current()) && !isBumpOp, + true); } } diff --git a/src/transactions/test/InvokeHostFunctionTests.cpp b/src/transactions/test/InvokeHostFunctionTests.cpp index 2376a26711..2f2f0fe254 100644 --- a/src/transactions/test/InvokeHostFunctionTests.cpp +++ b/src/transactions/test/InvokeHostFunctionTests.cpp @@ -602,6 +602,31 @@ TEST_CASE("contract storage", "[tx][soroban]") true, type); }; + auto bumpOp = [&](uint32_t bumpAmount, + xdr::xvector const& readOnly) { + Operation bumpOp; + bumpOp.body.type(BUMP_EXPIRATION); + bumpOp.body.bumpExpirationOp().ledgersToExpire() = bumpAmount; + + SorobanResources bumpResources; + bumpResources.footprint.readOnly = readOnly; + bumpResources.instructions = 200'000; + bumpResources.readBytes = 1000; + bumpResources.writeBytes = 5000; + bumpResources.extendedMetaDataSizeBytes = 6000; + + // submit operation + auto root = TestAccount::createRoot(*app); + auto tx = + sorobanTransactionFrameFromOps(app->getNetworkID(), root, {bumpOp}, + {}, bumpResources, 100'000, 1'200); + LedgerTxn ltx(app->getLedgerTxnRoot()); + TransactionMetaFrame txm(ltx.loadHeader().current().ledgerVersion); + REQUIRE(tx->checkValid(*app, ltx, 0, 0, 0)); + REQUIRE(tx->apply(*app, ltx, txm)); + ltx.commit(); + }; + auto delWithFootprint = [&](std::string const& key, xdr::xvector const& readOnly, xdr::xvector const& readWrite, @@ -787,8 +812,6 @@ TEST_CASE("contract storage", "[tx][soroban]") } } - // TODO: uncomment this when we implement the bump_contract_data host - // function SECTION("manual bump") { put("key", 0, ContractDataType::PERSISTENT); @@ -800,6 +823,35 @@ TEST_CASE("contract storage", "[tx][soroban]") bump("key", ContractDataType::PERSISTENT, 5'000); checkContractDataExpiration("key", ContractDataType::PERSISTENT, 10'000 + autoBump + lcl); + + put("key2", 0, ContractDataType::PERSISTENT); + bump("key2", ContractDataType::PERSISTENT, 5'000); + checkContractDataExpiration("key2", ContractDataType::PERSISTENT, + 5'000 + lcl); + + put("key3", 0, ContractDataType::PERSISTENT); + bump("key3", ContractDataType::PERSISTENT, 50'000); + checkContractDataExpiration("key3", ContractDataType::PERSISTENT, + 50'000 + lcl); + + // Bump to live 10100 ledger from now + bumpOp(10100, + {contractDataKey(contractID, makeSymbol("key"), + ContractDataType::PERSISTENT, DATA_ENTRY), + contractDataKey(contractID, makeSymbol("key2"), + ContractDataType::PERSISTENT, DATA_ENTRY), + contractDataKey(contractID, makeSymbol("key3"), + ContractDataType::PERSISTENT, DATA_ENTRY)}); + + checkContractDataExpiration("key", ContractDataType::PERSISTENT, + 10'000 + lcl + 100); + checkContractDataExpiration("key2", ContractDataType::PERSISTENT, + 10'000 + lcl + 100); + + // No change for key3 since expiration is already past 10100 ledgers + // from now + checkContractDataExpiration("key3", ContractDataType::PERSISTENT, + 50'000 + lcl); } SECTION("max expiration") From 084c5181f2576d88471478cdc46063a042eae142 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 13 Jun 2023 15:34:19 -0700 Subject: [PATCH 2/9] Use medium thresholds for bump and invoke ops --- src/transactions/BumpExpirationOpFrame.cpp | 6 ------ src/transactions/BumpExpirationOpFrame.h | 2 -- src/transactions/InvokeHostFunctionOpFrame.cpp | 6 ------ src/transactions/InvokeHostFunctionOpFrame.h | 2 -- 4 files changed, 16 deletions(-) diff --git a/src/transactions/BumpExpirationOpFrame.cpp b/src/transactions/BumpExpirationOpFrame.cpp index a1e09c4216..5156b798fc 100644 --- a/src/transactions/BumpExpirationOpFrame.cpp +++ b/src/transactions/BumpExpirationOpFrame.cpp @@ -34,12 +34,6 @@ BumpExpirationOpFrame::BumpExpirationOpFrame(Operation const& op, { } -ThresholdLevel -BumpExpirationOpFrame::getThresholdLevel() const -{ - return ThresholdLevel::LOW; -} - bool BumpExpirationOpFrame::isOpSupported(LedgerHeader const& header) const { diff --git a/src/transactions/BumpExpirationOpFrame.h b/src/transactions/BumpExpirationOpFrame.h index d0556ed97e..0fe13e2da8 100644 --- a/src/transactions/BumpExpirationOpFrame.h +++ b/src/transactions/BumpExpirationOpFrame.h @@ -26,8 +26,6 @@ class BumpExpirationOpFrame : public OperationFrame BumpExpirationOpFrame(Operation const& op, OperationResult& res, TransactionFrame& parentTx); - ThresholdLevel getThresholdLevel() const override; - bool isOpSupported(LedgerHeader const& header) const override; bool doApply(AbstractLedgerTxn& ltx) override; diff --git a/src/transactions/InvokeHostFunctionOpFrame.cpp b/src/transactions/InvokeHostFunctionOpFrame.cpp index 623c5f9fb2..64b9d5ae88 100644 --- a/src/transactions/InvokeHostFunctionOpFrame.cpp +++ b/src/transactions/InvokeHostFunctionOpFrame.cpp @@ -101,12 +101,6 @@ InvokeHostFunctionOpFrame::InvokeHostFunctionOpFrame(Operation const& op, { } -ThresholdLevel -InvokeHostFunctionOpFrame::getThresholdLevel() const -{ - return ThresholdLevel::LOW; -} - bool InvokeHostFunctionOpFrame::isOpSupported(LedgerHeader const& header) const { diff --git a/src/transactions/InvokeHostFunctionOpFrame.h b/src/transactions/InvokeHostFunctionOpFrame.h index c4634815a8..5e9d39d813 100644 --- a/src/transactions/InvokeHostFunctionOpFrame.h +++ b/src/transactions/InvokeHostFunctionOpFrame.h @@ -34,8 +34,6 @@ class InvokeHostFunctionOpFrame : public OperationFrame InvokeHostFunctionOpFrame(Operation const& op, OperationResult& res, TransactionFrame& parentTx); - ThresholdLevel getThresholdLevel() const override; - bool isOpSupported(LedgerHeader const& header) const override; bool doApply(AbstractLedgerTxn& ltx) override; From 730d07df223fd8ecca38c5b55c33dd783d80efc9 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Wed, 14 Jun 2023 15:48:35 -0700 Subject: [PATCH 3/9] No duplicates in footprint --- src/transactions/BumpExpirationOpFrame.cpp | 11 --------- src/transactions/TransactionFrame.cpp | 27 +++++++++++++++++++--- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/transactions/BumpExpirationOpFrame.cpp b/src/transactions/BumpExpirationOpFrame.cpp index 5156b798fc..4878441148 100644 --- a/src/transactions/BumpExpirationOpFrame.cpp +++ b/src/transactions/BumpExpirationOpFrame.cpp @@ -123,17 +123,6 @@ BumpExpirationOpFrame::doCheckValid(SorobanNetworkConfig const& config, } } - // check for duplicates - UnorderedSet set; - for (auto const& lk : footprint.readOnly) - { - if (!set.emplace(lk).second) - { - innerResult().code(BUMP_EXPIRATION_MALFORMED); - return false; - } - } - if (mBumpExpirationOp.ledgersToExpire() > config.stateExpirationSettings().maxEntryExpiration) { diff --git a/src/transactions/TransactionFrame.cpp b/src/transactions/TransactionFrame.cpp index 279edbbd81..8602c1b43c 100644 --- a/src/transactions/TransactionFrame.cpp +++ b/src/transactions/TransactionFrame.cpp @@ -928,21 +928,42 @@ TransactionFrame::commonValidPreSeqNum(Application& app, AbstractLedgerTxn& ltx, getResult().result.code(txSOROBAN_RESOURCE_LIMIT_EXCEEDED); return false; } + + auto const& sorobanData = mEnvelope.v1().tx.ext.sorobanData(); // Full fee has to be greater than the resource fee or // tx-specified refundable fee. if (getFullFee() < mSorobanResourceFee->fee || - getFullFee() < mEnvelope.v1().tx.ext.sorobanData().refundableFee) + getFullFee() < sorobanData.refundableFee) { getResult().result.code(txINSUFFICIENT_FEE); return false; } // Refundable fee shouldn't exceed tx-specified refundable fee. - if (mEnvelope.v1().tx.ext.sorobanData().refundableFee < - mSorobanResourceFee->refundable_fee) + if (sorobanData.refundableFee < mSorobanResourceFee->refundable_fee) { getResult().result.code(txINSUFFICIENT_FEE); return false; } + + // check for duplicates + UnorderedSet set; + auto checkDuplicates = + [&](xdr::xvector const& keys) -> bool { + for (auto const& lk : keys) + { + if (!set.emplace(lk).second) + { + getResult().result.code(txMALFORMED); + return false; + } + } + }; + + if (!checkDuplicates(sorobanData.resources.footprint.readOnly) || + !checkDuplicates(sorobanData.resources.footprint.readWrite)) + { + return false; + } } #endif auto header = ltx.loadHeader(); From b50708668914804689f088d33fc4c90d52a62afd Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 20 Jun 2023 16:23:09 -0700 Subject: [PATCH 4/9] xdr rename --- ...cpp => BumpFootprintExpirationOpFrame.cpp} | 50 +++++++++---------- ...ame.h => BumpFootprintExpirationOpFrame.h} | 14 +++--- src/transactions/OperationFrame.cpp | 6 +-- src/transactions/TransactionFrame.cpp | 2 +- .../test/InvokeHostFunctionTests.cpp | 4 +- 5 files changed, 38 insertions(+), 38 deletions(-) rename src/transactions/{BumpExpirationOpFrame.cpp => BumpFootprintExpirationOpFrame.cpp} (63%) rename src/transactions/{BumpExpirationOpFrame.h => BumpFootprintExpirationOpFrame.h} (74%) diff --git a/src/transactions/BumpExpirationOpFrame.cpp b/src/transactions/BumpFootprintExpirationOpFrame.cpp similarity index 63% rename from src/transactions/BumpExpirationOpFrame.cpp rename to src/transactions/BumpFootprintExpirationOpFrame.cpp index 4878441148..8c41ece0fc 100644 --- a/src/transactions/BumpExpirationOpFrame.cpp +++ b/src/transactions/BumpFootprintExpirationOpFrame.cpp @@ -3,54 +3,54 @@ // of this distribution or at http://www.apache.org/licenses/LICENSE-2.0 #ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION -#include "transactions/BumpExpirationOpFrame.h" +#include "transactions/BumpFootprintExpirationOpFrame.h" namespace stellar { -struct BumpExpirationMetrics +struct BumpFootprintExpirationMetrics { medida::MetricsRegistry& mMetrics; size_t mLedgerWriteByte{0}; - BumpExpirationMetrics(medida::MetricsRegistry& metrics) : mMetrics(metrics) + BumpFootprintExpirationMetrics(medida::MetricsRegistry& metrics) : mMetrics(metrics) { } - ~BumpExpirationMetrics() + ~BumpFootprintExpirationMetrics() { mMetrics - .NewMeter({"soroban", "bump-exp-op", "write-ledger-byte"}, "byte") + .NewMeter({"soroban", "bump-fprint-exp-op", "write-ledger-byte"}, "byte") .Mark(mLedgerWriteByte); } }; -BumpExpirationOpFrame::BumpExpirationOpFrame(Operation const& op, +BumpFootprintExpirationOpFrame::BumpFootprintExpirationOpFrame(Operation const& op, OperationResult& res, TransactionFrame& parentTx) : OperationFrame(op, res, parentTx) - , mBumpExpirationOp(mOperation.body.bumpExpirationOp()) + , mBumpFootprintExpirationOp(mOperation.body.bumpFootprintExpirationOp()) { } bool -BumpExpirationOpFrame::isOpSupported(LedgerHeader const& header) const +BumpFootprintExpirationOpFrame::isOpSupported(LedgerHeader const& header) const { return header.ledgerVersion >= 20; } bool -BumpExpirationOpFrame::doApply(AbstractLedgerTxn& ltx) +BumpFootprintExpirationOpFrame::doApply(AbstractLedgerTxn& ltx) { - throw std::runtime_error("BumpExpirationOpFrame::doApply needs Config"); + throw std::runtime_error("BumpFootprintExpirationOpFrame::doApply needs Config"); } bool -BumpExpirationOpFrame::doApply(Application& app, AbstractLedgerTxn& ltx, +BumpFootprintExpirationOpFrame::doApply(Application& app, AbstractLedgerTxn& ltx, Hash const& sorobanBasePrngSeed) { - BumpExpirationMetrics metrics(app.getMetrics()); + BumpFootprintExpirationMetrics metrics(app.getMetrics()); auto const& resources = mParentTx.sorobanResources(); auto const& footprint = resources.footprint; @@ -76,7 +76,7 @@ BumpExpirationOpFrame::doApply(Application& app, AbstractLedgerTxn& ltx, resources.readBytes < metrics.mLedgerWriteByte || resources.writeBytes < metrics.mLedgerWriteByte) { - innerResult().code(BUMP_EXPIRATION_RESOURCE_LIMIT_EXCEEDED); + innerResult().code(BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED); return false; } @@ -85,9 +85,9 @@ BumpExpirationOpFrame::doApply(Application& app, AbstractLedgerTxn& ltx, auto ledgerSeq = ltx.loadHeader().current().ledgerSeq; uint32_t bumpTo = UINT32_MAX; - if (UINT32_MAX - ledgerSeq > mBumpExpirationOp.ledgersToExpire()) + if (UINT32_MAX - ledgerSeq > mBumpFootprintExpirationOp.ledgersToExpire()) { - bumpTo = ledgerSeq + mBumpExpirationOp.ledgersToExpire(); + bumpTo = ledgerSeq + mBumpFootprintExpirationOp.ledgersToExpire(); } if (getExpirationLedger(ltxe.current()) < bumpTo) @@ -99,18 +99,18 @@ BumpExpirationOpFrame::doApply(Application& app, AbstractLedgerTxn& ltx, mParentTx.pushInitialExpirations(std::move(originalExpirations)); - innerResult().code(BUMP_EXPIRATION_SUCCESS); + innerResult().code(BUMP_FOOTPRINT_EXPIRATION_SUCCESS); return true; } bool -BumpExpirationOpFrame::doCheckValid(SorobanNetworkConfig const& config, +BumpFootprintExpirationOpFrame::doCheckValid(SorobanNetworkConfig const& config, uint32_t ledgerVersion) { auto const& footprint = mParentTx.sorobanResources().footprint; if (!footprint.readWrite.empty()) { - innerResult().code(BUMP_EXPIRATION_MALFORMED); + innerResult().code(BUMP_FOOTPRINT_EXPIRATION_MALFORMED); return false; } @@ -118,15 +118,15 @@ BumpExpirationOpFrame::doCheckValid(SorobanNetworkConfig const& config, { if (!isSorobanEntry(lk)) { - innerResult().code(BUMP_EXPIRATION_MALFORMED); + innerResult().code(BUMP_FOOTPRINT_EXPIRATION_MALFORMED); return false; } } - if (mBumpExpirationOp.ledgersToExpire() > + if (mBumpFootprintExpirationOp.ledgersToExpire() > config.stateExpirationSettings().maxEntryExpiration) { - innerResult().code(BUMP_EXPIRATION_MALFORMED); + innerResult().code(BUMP_FOOTPRINT_EXPIRATION_MALFORMED); return false; } @@ -134,20 +134,20 @@ BumpExpirationOpFrame::doCheckValid(SorobanNetworkConfig const& config, } bool -BumpExpirationOpFrame::doCheckValid(uint32_t ledgerVersion) +BumpFootprintExpirationOpFrame::doCheckValid(uint32_t ledgerVersion) { throw std::runtime_error( - "BumpExpirationOpFrame::doCheckValid needs Config"); + "BumpFootprintExpirationOpFrame::doCheckValid needs Config"); } void -BumpExpirationOpFrame::insertLedgerKeysToPrefetch( +BumpFootprintExpirationOpFrame::insertLedgerKeysToPrefetch( UnorderedSet& keys) const { } bool -BumpExpirationOpFrame::isSoroban() const +BumpFootprintExpirationOpFrame::isSoroban() const { return true; } diff --git a/src/transactions/BumpExpirationOpFrame.h b/src/transactions/BumpFootprintExpirationOpFrame.h similarity index 74% rename from src/transactions/BumpExpirationOpFrame.h rename to src/transactions/BumpFootprintExpirationOpFrame.h index 0fe13e2da8..6b3b3ec907 100644 --- a/src/transactions/BumpExpirationOpFrame.h +++ b/src/transactions/BumpFootprintExpirationOpFrame.h @@ -12,18 +12,18 @@ namespace stellar { class AbstractLedgerTxn; -class BumpExpirationOpFrame : public OperationFrame +class BumpFootprintExpirationOpFrame : public OperationFrame { - BumpExpirationResult& + BumpFootprintExpirationResult& innerResult() { - return mResult.tr().bumpExpirationResult(); + return mResult.tr().bumpFootprintExpirationResult(); } - BumpExpirationOp const& mBumpExpirationOp; + BumpFootprintExpirationOp const& mBumpFootprintExpirationOp; public: - BumpExpirationOpFrame(Operation const& op, OperationResult& res, + BumpFootprintExpirationOpFrame(Operation const& op, OperationResult& res, TransactionFrame& parentTx); bool isOpSupported(LedgerHeader const& header) const override; @@ -39,10 +39,10 @@ class BumpExpirationOpFrame : public OperationFrame void insertLedgerKeysToPrefetch(UnorderedSet& keys) const override; - static BumpExpirationOpResultCode + static BumpFootprintExpirationResultCode getInnerCode(OperationResult const& res) { - return res.tr().bumpExpirationResult().code(); + return res.tr().bumpFootprintExpirationResult().code(); } virtual bool isSoroban() const override; diff --git a/src/transactions/OperationFrame.cpp b/src/transactions/OperationFrame.cpp index 15d069cc35..dc093da5a1 100644 --- a/src/transactions/OperationFrame.cpp +++ b/src/transactions/OperationFrame.cpp @@ -5,7 +5,7 @@ #include "transactions/OperationFrame.h" #include "transactions/AllowTrustOpFrame.h" #include "transactions/BeginSponsoringFutureReservesOpFrame.h" -#include "transactions/BumpExpirationOpFrame.h" +#include "transactions/BumpFootprintExpirationOpFrame.h" #include "transactions/BumpSequenceOpFrame.h" #include "transactions/ChangeTrustOpFrame.h" #include "transactions/ClaimClaimableBalanceOpFrame.h" @@ -119,8 +119,8 @@ OperationFrame::makeHelper(Operation const& op, OperationResult& res, #ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION case INVOKE_HOST_FUNCTION: return std::make_shared(op, res, tx); - case BUMP_EXPIRATION: - return std::make_shared(op, res, tx); + case BUMP_FOOTPRINT_EXPIRATION: + return std::make_shared(op, res, tx); #endif default: ostringstream err; diff --git a/src/transactions/TransactionFrame.cpp b/src/transactions/TransactionFrame.cpp index 8602c1b43c..abe5a8e0c9 100644 --- a/src/transactions/TransactionFrame.cpp +++ b/src/transactions/TransactionFrame.cpp @@ -1689,7 +1689,7 @@ TransactionFrame::applyExpirationBumps(Application& app, AbstractLedgerTxn& ltx) } bool isBumpOp = - mOperations.front()->getOperation().body.type() == BUMP_EXPIRATION; + mOperations.front()->getOperation().body.type() == BUMP_FOOTPRINT_EXPIRATION; // TODO: Write expiration extension entries instead of witing whole entry for (auto const& key : resources.footprint.readOnly) { diff --git a/src/transactions/test/InvokeHostFunctionTests.cpp b/src/transactions/test/InvokeHostFunctionTests.cpp index 2f2f0fe254..6b70bd2ddd 100644 --- a/src/transactions/test/InvokeHostFunctionTests.cpp +++ b/src/transactions/test/InvokeHostFunctionTests.cpp @@ -605,8 +605,8 @@ TEST_CASE("contract storage", "[tx][soroban]") auto bumpOp = [&](uint32_t bumpAmount, xdr::xvector const& readOnly) { Operation bumpOp; - bumpOp.body.type(BUMP_EXPIRATION); - bumpOp.body.bumpExpirationOp().ledgersToExpire() = bumpAmount; + bumpOp.body.type(BUMP_FOOTPRINT_EXPIRATION); + bumpOp.body.bumpFootprintExpirationOp().ledgersToExpire() = bumpAmount; SorobanResources bumpResources; bumpResources.footprint.readOnly = readOnly; From e0f5bfda87593a3cd2ca196e9e550843da75e434 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 20 Jun 2023 16:24:27 -0700 Subject: [PATCH 5/9] bump env --- Cargo.lock | 36 +++++++++++++++++---------- src/protocol-next/xdr | 2 +- src/rust/Cargo.toml | 6 ++--- src/rust/src/host-dep-tree-curr.txt | 12 ++++----- src/transactions/TransactionFrame.cpp | 1 + 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b556a47ccb..fccd345bed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -837,14 +837,14 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "soroban-env-common" version = "0.0.16" -source = "git+https://github.com/stellar/rs-soroban-env?rev=16bdf376278e1f6322beebad0a11e3c484b1eef9#16bdf376278e1f6322beebad0a11e3c484b1eef9" +source = "git+https://github.com/stellar/rs-soroban-env?rev=44009d67f6a7b85c0aafc363a8539fc8217bcb9a#44009d67f6a7b85c0aafc363a8539fc8217bcb9a" dependencies = [ "crate-git-revision", "ethnum", - "soroban-env-macros 0.0.16 (git+https://github.com/stellar/rs-soroban-env?rev=16bdf376278e1f6322beebad0a11e3c484b1eef9)", + "soroban-env-macros 0.0.16 (git+https://github.com/stellar/rs-soroban-env?rev=44009d67f6a7b85c0aafc363a8539fc8217bcb9a)", "soroban-wasmi", "static_assertions", - "stellar-xdr", + "stellar-xdr 0.0.16 (git+https://github.com/stellar/rs-stellar-xdr?rev=dfb98415a08abe2c8a05a44ec237d53164198215)", ] [[package]] @@ -857,13 +857,13 @@ dependencies = [ "soroban-env-macros 0.0.16 (git+https://github.com/stellar/rs-soroban-env?rev=e6e02dc4b5cf946028e51603883bd81ca38ce519)", "soroban-wasmi", "static_assertions", - "stellar-xdr", + "stellar-xdr 0.0.16 (git+https://github.com/stellar/rs-stellar-xdr?rev=f7b43ea2a4a36a87ebde2cb6050ea4bd7540df21)", ] [[package]] name = "soroban-env-host" version = "0.0.16" -source = "git+https://github.com/stellar/rs-soroban-env?rev=16bdf376278e1f6322beebad0a11e3c484b1eef9#16bdf376278e1f6322beebad0a11e3c484b1eef9" +source = "git+https://github.com/stellar/rs-soroban-env?rev=44009d67f6a7b85c0aafc363a8539fc8217bcb9a#44009d67f6a7b85c0aafc363a8539fc8217bcb9a" dependencies = [ "backtrace", "curve25519-dalek", @@ -879,8 +879,8 @@ dependencies = [ "rand_chacha", "sha2 0.9.9", "sha3", - "soroban-env-common 0.0.16 (git+https://github.com/stellar/rs-soroban-env?rev=16bdf376278e1f6322beebad0a11e3c484b1eef9)", - "soroban-native-sdk-macros 0.0.16 (git+https://github.com/stellar/rs-soroban-env?rev=16bdf376278e1f6322beebad0a11e3c484b1eef9)", + "soroban-env-common 0.0.16 (git+https://github.com/stellar/rs-soroban-env?rev=44009d67f6a7b85c0aafc363a8539fc8217bcb9a)", + "soroban-native-sdk-macros 0.0.16 (git+https://github.com/stellar/rs-soroban-env?rev=44009d67f6a7b85c0aafc363a8539fc8217bcb9a)", "soroban-wasmi", "static_assertions", "stellar-strkey", @@ -915,14 +915,14 @@ dependencies = [ [[package]] name = "soroban-env-macros" version = "0.0.16" -source = "git+https://github.com/stellar/rs-soroban-env?rev=16bdf376278e1f6322beebad0a11e3c484b1eef9#16bdf376278e1f6322beebad0a11e3c484b1eef9" +source = "git+https://github.com/stellar/rs-soroban-env?rev=44009d67f6a7b85c0aafc363a8539fc8217bcb9a#44009d67f6a7b85c0aafc363a8539fc8217bcb9a" dependencies = [ "itertools", "proc-macro2", "quote", "serde", "serde_json", - "stellar-xdr", + "stellar-xdr 0.0.16 (git+https://github.com/stellar/rs-stellar-xdr?rev=dfb98415a08abe2c8a05a44ec237d53164198215)", "syn 2.0.18", "thiserror", ] @@ -937,7 +937,7 @@ dependencies = [ "quote", "serde", "serde_json", - "stellar-xdr", + "stellar-xdr 0.0.16 (git+https://github.com/stellar/rs-stellar-xdr?rev=f7b43ea2a4a36a87ebde2cb6050ea4bd7540df21)", "syn 2.0.18", "thiserror", ] @@ -945,7 +945,7 @@ dependencies = [ [[package]] name = "soroban-native-sdk-macros" version = "0.0.16" -source = "git+https://github.com/stellar/rs-soroban-env?rev=16bdf376278e1f6322beebad0a11e3c484b1eef9#16bdf376278e1f6322beebad0a11e3c484b1eef9" +source = "git+https://github.com/stellar/rs-soroban-env?rev=44009d67f6a7b85c0aafc363a8539fc8217bcb9a#44009d67f6a7b85c0aafc363a8539fc8217bcb9a" dependencies = [ "itertools", "proc-macro2", @@ -967,7 +967,7 @@ dependencies = [ [[package]] name = "soroban-test-wasms" version = "0.0.16" -source = "git+https://github.com/stellar/rs-soroban-env?rev=e6e02dc4b5cf946028e51603883bd81ca38ce519#e6e02dc4b5cf946028e51603883bd81ca38ce519" +source = "git+https://github.com/stellar/rs-soroban-env?rev=44009d67f6a7b85c0aafc363a8539fc8217bcb9a#44009d67f6a7b85c0aafc363a8539fc8217bcb9a" [[package]] name = "soroban-wasmi" @@ -1024,7 +1024,7 @@ dependencies = [ "cxx", "log", "rustc-simple-version", - "soroban-env-host 0.0.16 (git+https://github.com/stellar/rs-soroban-env?rev=16bdf376278e1f6322beebad0a11e3c484b1eef9)", + "soroban-env-host 0.0.16 (git+https://github.com/stellar/rs-soroban-env?rev=44009d67f6a7b85c0aafc363a8539fc8217bcb9a)", "soroban-env-host 0.0.16 (git+https://github.com/stellar/rs-soroban-env?rev=e6e02dc4b5cf946028e51603883bd81ca38ce519)", "soroban-test-wasms", ] @@ -1038,6 +1038,16 @@ dependencies = [ "thiserror", ] +[[package]] +name = "stellar-xdr" +version = "0.0.16" +source = "git+https://github.com/stellar/rs-stellar-xdr?rev=dfb98415a08abe2c8a05a44ec237d53164198215#dfb98415a08abe2c8a05a44ec237d53164198215" +dependencies = [ + "base64", + "crate-git-revision", + "hex", +] + [[package]] name = "stellar-xdr" version = "0.0.16" diff --git a/src/protocol-next/xdr b/src/protocol-next/xdr index 25363a72e9..0769d7a558 160000 --- a/src/protocol-next/xdr +++ b/src/protocol-next/xdr @@ -1 +1 @@ -Subproject commit 25363a72e9bbbb6621d888dde3b36c0a196fb84d +Subproject commit 0769d7a5581265da6f270f5bfd1ff7018f176c75 diff --git a/src/rust/Cargo.toml b/src/rust/Cargo.toml index c0aaea7967..d816f53cf7 100644 --- a/src/rust/Cargo.toml +++ b/src/rust/Cargo.toml @@ -27,7 +27,7 @@ rustc-simple-version = "0.1.0" version = "0.0.16" git = "https://github.com/stellar/rs-soroban-env" package = "soroban-env-host" -rev = "e6e02dc4b5cf946028e51603883bd81ca38ce519" +rev = "44009d67f6a7b85c0aafc363a8539fc8217bcb9a" # This copy of the soroban host is _optional_ and only enabled during protocol # transitions. When transitioning from protocol N to N+1, the `curr` copy @@ -51,11 +51,11 @@ optional = true version = "0.0.16" git = "https://github.com/stellar/rs-soroban-env" package = "soroban-env-host" -rev = "16bdf376278e1f6322beebad0a11e3c484b1eef9" +rev = "e6e02dc4b5cf946028e51603883bd81ca38ce519" [dependencies.soroban-test-wasms] git = "https://github.com/stellar/rs-soroban-env" -rev = "e6e02dc4b5cf946028e51603883bd81ca38ce519" +rev = "44009d67f6a7b85c0aafc363a8539fc8217bcb9a" [dependencies.cargo-lock] git = "https://github.com/rustsec/rustsec" diff --git a/src/rust/src/host-dep-tree-curr.txt b/src/rust/src/host-dep-tree-curr.txt index 4e3c61d022..85000a242f 100644 --- a/src/rust/src/host-dep-tree-curr.txt +++ b/src/rust/src/host-dep-tree-curr.txt @@ -1,4 +1,4 @@ -soroban-env-host 0.0.16 git+https://github.com/stellar/rs-soroban-env?rev=e6e02dc4b5cf946028e51603883bd81ca38ce519#e6e02dc4b5cf946028e51603883bd81ca38ce519 +soroban-env-host 0.0.16 git+https://github.com/stellar/rs-soroban-env?rev=44009d67f6a7b85c0aafc363a8539fc8217bcb9a#44009d67f6a7b85c0aafc363a8539fc8217bcb9a ├── stellar-strkey 0.0.7 git+https://github.com/stellar/rs-stellar-strkey?rev=e6ba45c60c16de28c7522586b80ed0150157df73#e6ba45c60c16de28c7522586b80ed0150157df73 │ ├── thiserror 1.0.40 checksum:978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac │ │ └── thiserror-impl 1.0.40 checksum:f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f @@ -25,14 +25,14 @@ soroban-env-host 0.0.16 git+https://github.com/stellar/rs-soroban-env?rev=e6e02d │ │ └── downcast-rs 1.2.0 checksum:9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650 │ ├── smallvec 1.10.0 checksum:a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0 │ └── intx 0.1.0 checksum:f6f38a50a899dc47a6d0ed5508e7f601a2e34c3a85303514b5d137f3c10a0c75 -├── soroban-native-sdk-macros 0.0.16 git+https://github.com/stellar/rs-soroban-env?rev=e6e02dc4b5cf946028e51603883bd81ca38ce519#e6e02dc4b5cf946028e51603883bd81ca38ce519 +├── soroban-native-sdk-macros 0.0.16 git+https://github.com/stellar/rs-soroban-env?rev=44009d67f6a7b85c0aafc363a8539fc8217bcb9a#44009d67f6a7b85c0aafc363a8539fc8217bcb9a │ ├── syn 2.0.18 checksum:32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e │ ├── quote 1.0.28 checksum:1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488 │ ├── proc-macro2 1.0.60 checksum:dec2b086b7a862cf4de201096214fa870344cf922b2b30c167badb3af3195406 │ └── itertools 0.10.5 checksum:b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473 │ └── either 1.8.1 checksum:7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91 -├── soroban-env-common 0.0.16 git+https://github.com/stellar/rs-soroban-env?rev=e6e02dc4b5cf946028e51603883bd81ca38ce519#e6e02dc4b5cf946028e51603883bd81ca38ce519 -│ ├── stellar-xdr 0.0.16 git+https://github.com/stellar/rs-stellar-xdr?rev=f7b43ea2a4a36a87ebde2cb6050ea4bd7540df21#f7b43ea2a4a36a87ebde2cb6050ea4bd7540df21 +├── soroban-env-common 0.0.16 git+https://github.com/stellar/rs-soroban-env?rev=44009d67f6a7b85c0aafc363a8539fc8217bcb9a#44009d67f6a7b85c0aafc363a8539fc8217bcb9a +│ ├── stellar-xdr 0.0.16 git+https://github.com/stellar/rs-stellar-xdr?rev=dfb98415a08abe2c8a05a44ec237d53164198215#dfb98415a08abe2c8a05a44ec237d53164198215 │ │ ├── hex 0.4.3 checksum:7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70 │ │ ├── crate-git-revision 0.0.4 checksum:f998aef136a4e7833b0e4f0fc0939a59c40140b28e0ffbf524ad84fb2cc568c8 │ │ │ ├── serde_json 1.0.97 checksum:bdf3bf93142acad5821c99197022e170842cdbc1c30482b98750c688c640842a @@ -48,10 +48,10 @@ soroban-env-host 0.0.16 git+https://github.com/stellar/rs-soroban-env?rev=e6e02d │ │ └── base64 0.13.1 checksum:9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8 │ ├── static_assertions 1.1.0 checksum:a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f │ ├── soroban-wasmi 0.30.0-soroban git+https://github.com/stellar/wasmi?rev=1a2bc7f#1a2bc7f3801c565c2dab22021255a164c05a7f76 -│ ├── soroban-env-macros 0.0.16 git+https://github.com/stellar/rs-soroban-env?rev=e6e02dc4b5cf946028e51603883bd81ca38ce519#e6e02dc4b5cf946028e51603883bd81ca38ce519 +│ ├── soroban-env-macros 0.0.16 git+https://github.com/stellar/rs-soroban-env?rev=44009d67f6a7b85c0aafc363a8539fc8217bcb9a#44009d67f6a7b85c0aafc363a8539fc8217bcb9a │ │ ├── thiserror 1.0.40 checksum:978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac │ │ ├── syn 2.0.18 checksum:32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e -│ │ ├── stellar-xdr 0.0.16 git+https://github.com/stellar/rs-stellar-xdr?rev=f7b43ea2a4a36a87ebde2cb6050ea4bd7540df21#f7b43ea2a4a36a87ebde2cb6050ea4bd7540df21 +│ │ ├── stellar-xdr 0.0.16 git+https://github.com/stellar/rs-stellar-xdr?rev=dfb98415a08abe2c8a05a44ec237d53164198215#dfb98415a08abe2c8a05a44ec237d53164198215 │ │ ├── serde_json 1.0.97 checksum:bdf3bf93142acad5821c99197022e170842cdbc1c30482b98750c688c640842a │ │ ├── serde 1.0.164 checksum:9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d │ │ ├── quote 1.0.28 checksum:1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488 diff --git a/src/transactions/TransactionFrame.cpp b/src/transactions/TransactionFrame.cpp index abe5a8e0c9..b41d5bada7 100644 --- a/src/transactions/TransactionFrame.cpp +++ b/src/transactions/TransactionFrame.cpp @@ -957,6 +957,7 @@ TransactionFrame::commonValidPreSeqNum(Application& app, AbstractLedgerTxn& ltx, return false; } } + return true; }; if (!checkDuplicates(sorobanData.resources.footprint.readOnly) || From 8e7ab4a097df7a141a4437b7a4d4c6bc271ca5d4 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 20 Jun 2023 16:24:34 -0700 Subject: [PATCH 6/9] make format --- .../BumpFootprintExpirationOpFrame.cpp | 30 +++++++++++-------- .../BumpFootprintExpirationOpFrame.h | 2 +- src/transactions/TransactionFrame.cpp | 4 +-- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/transactions/BumpFootprintExpirationOpFrame.cpp b/src/transactions/BumpFootprintExpirationOpFrame.cpp index 8c41ece0fc..e87d903c92 100644 --- a/src/transactions/BumpFootprintExpirationOpFrame.cpp +++ b/src/transactions/BumpFootprintExpirationOpFrame.cpp @@ -14,21 +14,22 @@ struct BumpFootprintExpirationMetrics size_t mLedgerWriteByte{0}; - BumpFootprintExpirationMetrics(medida::MetricsRegistry& metrics) : mMetrics(metrics) + BumpFootprintExpirationMetrics(medida::MetricsRegistry& metrics) + : mMetrics(metrics) { } ~BumpFootprintExpirationMetrics() { mMetrics - .NewMeter({"soroban", "bump-fprint-exp-op", "write-ledger-byte"}, "byte") + .NewMeter({"soroban", "bump-fprint-exp-op", "write-ledger-byte"}, + "byte") .Mark(mLedgerWriteByte); } }; -BumpFootprintExpirationOpFrame::BumpFootprintExpirationOpFrame(Operation const& op, - OperationResult& res, - TransactionFrame& parentTx) +BumpFootprintExpirationOpFrame::BumpFootprintExpirationOpFrame( + Operation const& op, OperationResult& res, TransactionFrame& parentTx) : OperationFrame(op, res, parentTx) , mBumpFootprintExpirationOp(mOperation.body.bumpFootprintExpirationOp()) { @@ -43,12 +44,14 @@ BumpFootprintExpirationOpFrame::isOpSupported(LedgerHeader const& header) const bool BumpFootprintExpirationOpFrame::doApply(AbstractLedgerTxn& ltx) { - throw std::runtime_error("BumpFootprintExpirationOpFrame::doApply needs Config"); + throw std::runtime_error( + "BumpFootprintExpirationOpFrame::doApply needs Config"); } bool -BumpFootprintExpirationOpFrame::doApply(Application& app, AbstractLedgerTxn& ltx, - Hash const& sorobanBasePrngSeed) +BumpFootprintExpirationOpFrame::doApply(Application& app, + AbstractLedgerTxn& ltx, + Hash const& sorobanBasePrngSeed) { BumpFootprintExpirationMetrics metrics(app.getMetrics()); @@ -76,7 +79,8 @@ BumpFootprintExpirationOpFrame::doApply(Application& app, AbstractLedgerTxn& ltx resources.readBytes < metrics.mLedgerWriteByte || resources.writeBytes < metrics.mLedgerWriteByte) { - innerResult().code(BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED); + innerResult().code( + BUMP_FOOTPRINT_EXPIRATION_RESOURCE_LIMIT_EXCEEDED); return false; } @@ -85,9 +89,11 @@ BumpFootprintExpirationOpFrame::doApply(Application& app, AbstractLedgerTxn& ltx auto ledgerSeq = ltx.loadHeader().current().ledgerSeq; uint32_t bumpTo = UINT32_MAX; - if (UINT32_MAX - ledgerSeq > mBumpFootprintExpirationOp.ledgersToExpire()) + if (UINT32_MAX - ledgerSeq > + mBumpFootprintExpirationOp.ledgersToExpire()) { - bumpTo = ledgerSeq + mBumpFootprintExpirationOp.ledgersToExpire(); + bumpTo = + ledgerSeq + mBumpFootprintExpirationOp.ledgersToExpire(); } if (getExpirationLedger(ltxe.current()) < bumpTo) @@ -105,7 +111,7 @@ BumpFootprintExpirationOpFrame::doApply(Application& app, AbstractLedgerTxn& ltx bool BumpFootprintExpirationOpFrame::doCheckValid(SorobanNetworkConfig const& config, - uint32_t ledgerVersion) + uint32_t ledgerVersion) { auto const& footprint = mParentTx.sorobanResources().footprint; if (!footprint.readWrite.empty()) diff --git a/src/transactions/BumpFootprintExpirationOpFrame.h b/src/transactions/BumpFootprintExpirationOpFrame.h index 6b3b3ec907..10057c8dda 100644 --- a/src/transactions/BumpFootprintExpirationOpFrame.h +++ b/src/transactions/BumpFootprintExpirationOpFrame.h @@ -24,7 +24,7 @@ class BumpFootprintExpirationOpFrame : public OperationFrame public: BumpFootprintExpirationOpFrame(Operation const& op, OperationResult& res, - TransactionFrame& parentTx); + TransactionFrame& parentTx); bool isOpSupported(LedgerHeader const& header) const override; diff --git a/src/transactions/TransactionFrame.cpp b/src/transactions/TransactionFrame.cpp index b41d5bada7..fa70c715cd 100644 --- a/src/transactions/TransactionFrame.cpp +++ b/src/transactions/TransactionFrame.cpp @@ -1689,8 +1689,8 @@ TransactionFrame::applyExpirationBumps(Application& app, AbstractLedgerTxn& ltx) } } - bool isBumpOp = - mOperations.front()->getOperation().body.type() == BUMP_FOOTPRINT_EXPIRATION; + bool isBumpOp = mOperations.front()->getOperation().body.type() == + BUMP_FOOTPRINT_EXPIRATION; // TODO: Write expiration extension entries instead of witing whole entry for (auto const& key : resources.footprint.readOnly) { From efc4468d230b0e13cdd2b81a4d029f114bb4d67f Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 20 Jun 2023 16:39:46 -0700 Subject: [PATCH 7/9] Update ledger close meta --- .../ledger-close-meta-v1-protocol-20.json | 804 +++++++++--------- 1 file changed, 402 insertions(+), 402 deletions(-) diff --git a/src/testdata/ledger-close-meta-v1-protocol-20.json b/src/testdata/ledger-close-meta-v1-protocol-20.json index b482017310..9b87d8928b 100644 --- a/src/testdata/ledger-close-meta-v1-protocol-20.json +++ b/src/testdata/ledger-close-meta-v1-protocol-20.json @@ -3,24 +3,24 @@ "v": 1, "v1": { "ledgerHeader": { - "hash": "adff3e23543ebda3336a627fbdf9ae0ac79b6ebc5cb8973532abc89232cbb773", + "hash": "e5820e8d08b10df479dc1938d6649147bf2077316b2e13db7870a0cc51223dc3", "header": { "ledgerVersion": 20, - "previousLedgerHash": "c5188dcd46434af3412fe6f3f8b4cc3b247d5da8bd710eafed01dc68672b9401", + "previousLedgerHash": "556ff1a476f291e6d3cb9079c5dfe8192168d16369e9a78c5e2e6d63e13dc8b3", "scpValue": { - "txSetHash": "c841c840ce21860b6ab8d0a4cb026a4e1a59bbd3b73b7264b41c0f620c43239e", + "txSetHash": "14dea3a1de99ce036d95de8b3daf8bbc85b3bbfd12ae428fcb0def7911ed1f6d", "closeTime": 0, "upgrades": [], "ext": { "v": "STELLAR_VALUE_SIGNED", "lcValueSignature": { "nodeID": "GDDOUW25MRFLNXQMN3OODP6JQEXSGLMHAFZV4XPQ2D3GA4QFIDMEJG2O", - "signature": "957b35f4da81383c63faa5f7b5f5c4d93566aa1ec8a98e9b8d9441c65b29738cb5970b8327626ad683a254cb0760a4e1b2d8286b6dc240dcaac23f621d6a490f" + "signature": "1b1f61d972b4d5cea09df2b9918356dc9752cfd44dac6d78809c9356f1e9d5f5bbfea4183283048fbc7cc971754a8e1e25b8bf158626740d8d4468c53871af03" } } }, - "txSetResultHash": "cd1398cda325d4eada631301e6501421cda30fd0b43da3e5d0ffb26caf073b0a", - "bucketListHash": "cad4a9a9306753682ab157d12d102aa5669716b6c78fcbc131e4eed9dcb4421c", + "txSetResultHash": "cf65fee29665ff0c2a6910b24c420a487a7416ccd79c683b48aac1d45ad21faa", + "bucketListHash": "3fd2406e9f9642e3e483ad61bc78ca9a9ac5df265bd7db624ceea3d17e6bbc24", "ledgerSeq": 6, "totalCoins": 1000000000000000000, "feePool": 800, @@ -46,7 +46,7 @@ "txSet": { "v": 1, "v1TxSet": { - "previousLedgerHash": "c5188dcd46434af3412fe6f3f8b4cc3b247d5da8bd710eafed01dc68672b9401", + "previousLedgerHash": "556ff1a476f291e6d3cb9079c5dfe8192168d16369e9a78c5e2e6d63e13dc8b3", "phases": [ { "v": 0, @@ -182,43 +182,22 @@ "txProcessing": [ { "result": { - "transactionHash": "66efe325ead9f52082c8908b7813bd96793fd5ff0f1e50fdc50b23f68938dd4d", + "transactionHash": "0db2322d85e9d8ea2421559922bb6107429650ebdad304c907480853d465c10d", "result": { - "feeCharged": 300, + "feeCharged": 100, "result": { - "code": "txFEE_BUMP_INNER_SUCCESS", - "innerResultPair": { - "transactionHash": "5ab197acffd4b32d320df39b2b1f76246e2279fa8070c6c690cca1343e5e7e0b", - "result": { - "feeCharged": 200, - "result": { - "code": "txSUCCESS", - "results": [ - { - "code": "opINNER", - "tr": { - "type": "PAYMENT", - "paymentResult": { - "code": "PAYMENT_SUCCESS" - } - } - }, - { - "code": "opINNER", - "tr": { - "type": "PAYMENT", - "paymentResult": { - "code": "PAYMENT_SUCCESS" - } - } - } - ] - }, - "ext": { - "v": 0 + "code": "txSUCCESS", + "results": [ + { + "code": "opINNER", + "tr": { + "type": "PAYMENT", + "paymentResult": { + "code": "PAYMENT_SUCCESS" + } } } - } + ] }, "ext": { "v": 0 @@ -229,13 +208,13 @@ { "type": "LEDGER_ENTRY_STATE", "state": { - "lastModifiedLedgerSeq": 3, + "lastModifiedLedgerSeq": 4, "data": { "type": "ACCOUNT", "account": { - "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", - "balance": 400000000, - "seqNum": 12884901888, + "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", + "balance": 999999998999989700, + "seqNum": 3, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -243,7 +222,31 @@ "thresholds": "01000000", "signers": [], "ext": { - "v": 0 + "v": 1, + "v1": { + "liabilities": { + "buying": 0, + "selling": 0 + }, + "ext": { + "v": 2, + "v2": { + "numSponsored": 0, + "numSponsoring": 0, + "signerSponsoringIDs": [], + "ext": { + "v": 3, + "v3": { + "ext": { + "v": 0 + }, + "seqLedger": 4, + "seqTime": 0 + } + } + } + } + } } } }, @@ -259,9 +262,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", - "balance": 399999700, - "seqNum": 12884901888, + "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", + "balance": 999999998999989600, + "seqNum": 3, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -269,7 +272,31 @@ "thresholds": "01000000", "signers": [], "ext": { - "v": 0 + "v": 1, + "v1": { + "liabilities": { + "buying": 0, + "selling": 0 + }, + "ext": { + "v": 2, + "v2": { + "numSponsored": 0, + "numSponsoring": 0, + "signerSponsoringIDs": [], + "ext": { + "v": 3, + "v3": { + "ext": { + "v": 0 + }, + "seqLedger": 4, + "seqTime": 0 + } + } + } + } + } } } }, @@ -293,61 +320,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", - "balance": 399999700, - "seqNum": 12884901888, - "numSubEntries": 0, - "inflationDest": null, - "flags": 0, - "homeDomain": "", - "thresholds": "01000000", - "signers": [], - "ext": { - "v": 0 - } - } - }, - "ext": { - "v": 0 - } - } - }, - { - "type": "LEDGER_ENTRY_UPDATED", - "updated": { - "lastModifiedLedgerSeq": 6, - "data": { - "type": "ACCOUNT", - "account": { - "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", - "balance": 399999700, - "seqNum": 12884901888, - "numSubEntries": 0, - "inflationDest": null, - "flags": 0, - "homeDomain": "", - "thresholds": "01000000", - "signers": [], - "ext": { - "v": 0 - } - } - }, - "ext": { - "v": 0 - } - } - }, - { - "type": "LEDGER_ENTRY_STATE", - "state": { - "lastModifiedLedgerSeq": 4, - "data": { - "type": "ACCOUNT", - "account": { - "accountID": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q", - "balance": 200010000, - "seqNum": 17179869184, + "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", + "balance": 999999998999989600, + "seqNum": 3, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -355,7 +330,31 @@ "thresholds": "01000000", "signers": [], "ext": { - "v": 0 + "v": 1, + "v1": { + "liabilities": { + "buying": 0, + "selling": 0 + }, + "ext": { + "v": 2, + "v2": { + "numSponsored": 0, + "numSponsoring": 0, + "signerSponsoringIDs": [], + "ext": { + "v": 3, + "v3": { + "ext": { + "v": 0 + }, + "seqLedger": 4, + "seqTime": 0 + } + } + } + } + } } } }, @@ -371,9 +370,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q", - "balance": 200010000, - "seqNum": 17179869185, + "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", + "balance": 999999998999989600, + "seqNum": 4, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -421,20 +420,45 @@ { "type": "LEDGER_ENTRY_STATE", "state": { - "lastModifiedLedgerSeq": 5, + "lastModifiedLedgerSeq": 6, "data": { - "type": "TRUSTLINE", - "trustLine": { - "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", - "asset": { - "assetCode": "CUR1", - "issuer": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q" - }, - "balance": 0, - "limit": 100, - "flags": 1, + "type": "ACCOUNT", + "account": { + "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", + "balance": 999999998999989600, + "seqNum": 4, + "numSubEntries": 0, + "inflationDest": null, + "flags": 0, + "homeDomain": "", + "thresholds": "01000000", + "signers": [], "ext": { - "v": 0 + "v": 1, + "v1": { + "liabilities": { + "buying": 0, + "selling": 0 + }, + "ext": { + "v": 2, + "v2": { + "numSponsored": 0, + "numSponsoring": 0, + "signerSponsoringIDs": [], + "ext": { + "v": 3, + "v3": { + "ext": { + "v": 0 + }, + "seqLedger": 6, + "seqTime": 0 + } + } + } + } + } } } }, @@ -448,18 +472,43 @@ "updated": { "lastModifiedLedgerSeq": 6, "data": { - "type": "TRUSTLINE", - "trustLine": { - "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", - "asset": { - "assetCode": "CUR1", - "issuer": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q" - }, - "balance": 50, - "limit": 100, - "flags": 1, + "type": "ACCOUNT", + "account": { + "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", + "balance": 999999998999988600, + "seqNum": 4, + "numSubEntries": 0, + "inflationDest": null, + "flags": 0, + "homeDomain": "", + "thresholds": "01000000", + "signers": [], "ext": { - "v": 0 + "v": 1, + "v1": { + "liabilities": { + "buying": 0, + "selling": 0 + }, + "ext": { + "v": 2, + "v2": { + "numSponsored": 0, + "numSponsoring": 0, + "signerSponsoringIDs": [], + "ext": { + "v": 3, + "v3": { + "ext": { + "v": 0 + }, + "seqLedger": 6, + "seqTime": 0 + } + } + } + } + } } } }, @@ -467,28 +516,49 @@ "v": 0 } } - } - ] - }, - { - "changes": [ + }, { "type": "LEDGER_ENTRY_STATE", "state": { - "lastModifiedLedgerSeq": 6, + "lastModifiedLedgerSeq": 5, "data": { - "type": "TRUSTLINE", - "trustLine": { + "type": "ACCOUNT", + "account": { "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", - "asset": { - "assetCode": "CUR1", - "issuer": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q" - }, - "balance": 50, - "limit": 100, - "flags": 1, + "balance": 399999900, + "seqNum": 8589934593, + "numSubEntries": 1, + "inflationDest": null, + "flags": 0, + "homeDomain": "", + "thresholds": "01000000", + "signers": [], "ext": { - "v": 0 + "v": 1, + "v1": { + "liabilities": { + "buying": 0, + "selling": 0 + }, + "ext": { + "v": 2, + "v2": { + "numSponsored": 0, + "numSponsoring": 0, + "signerSponsoringIDs": [], + "ext": { + "v": 3, + "v3": { + "ext": { + "v": 0 + }, + "seqLedger": 5, + "seqTime": 0 + } + } + } + } + } } } }, @@ -502,18 +572,43 @@ "updated": { "lastModifiedLedgerSeq": 6, "data": { - "type": "TRUSTLINE", - "trustLine": { + "type": "ACCOUNT", + "account": { "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", - "asset": { - "assetCode": "CUR1", - "issuer": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q" - }, - "balance": 100, - "limit": 100, - "flags": 1, + "balance": 400000900, + "seqNum": 8589934593, + "numSubEntries": 1, + "inflationDest": null, + "flags": 0, + "homeDomain": "", + "thresholds": "01000000", + "signers": [], "ext": { - "v": 0 + "v": 1, + "v1": { + "liabilities": { + "buying": 0, + "selling": 0 + }, + "ext": { + "v": 2, + "v2": { + "numSponsored": 0, + "numSponsoring": 0, + "signerSponsoringIDs": [], + "ext": { + "v": 3, + "v3": { + "ext": { + "v": 0 + }, + "seqLedger": 5, + "seqTime": 0 + } + } + } + } + } } } }, @@ -542,22 +637,43 @@ }, { "result": { - "transactionHash": "0db2322d85e9d8ea2421559922bb6107429650ebdad304c907480853d465c10d", + "transactionHash": "66efe325ead9f52082c8908b7813bd96793fd5ff0f1e50fdc50b23f68938dd4d", "result": { - "feeCharged": 100, + "feeCharged": 300, "result": { - "code": "txSUCCESS", - "results": [ - { - "code": "opINNER", - "tr": { - "type": "PAYMENT", - "paymentResult": { - "code": "PAYMENT_SUCCESS" - } + "code": "txFEE_BUMP_INNER_SUCCESS", + "innerResultPair": { + "transactionHash": "5ab197acffd4b32d320df39b2b1f76246e2279fa8070c6c690cca1343e5e7e0b", + "result": { + "feeCharged": 200, + "result": { + "code": "txSUCCESS", + "results": [ + { + "code": "opINNER", + "tr": { + "type": "PAYMENT", + "paymentResult": { + "code": "PAYMENT_SUCCESS" + } + } + }, + { + "code": "opINNER", + "tr": { + "type": "PAYMENT", + "paymentResult": { + "code": "PAYMENT_SUCCESS" + } + } + } + ] + }, + "ext": { + "v": 0 } } - ] + } }, "ext": { "v": 0 @@ -568,13 +684,13 @@ { "type": "LEDGER_ENTRY_STATE", "state": { - "lastModifiedLedgerSeq": 4, + "lastModifiedLedgerSeq": 3, "data": { "type": "ACCOUNT", "account": { - "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", - "balance": 999999998999989700, - "seqNum": 3, + "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", + "balance": 400000000, + "seqNum": 12884901888, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -582,31 +698,7 @@ "thresholds": "01000000", "signers": [], "ext": { - "v": 1, - "v1": { - "liabilities": { - "buying": 0, - "selling": 0 - }, - "ext": { - "v": 2, - "v2": { - "numSponsored": 0, - "numSponsoring": 0, - "signerSponsoringIDs": [], - "ext": { - "v": 3, - "v3": { - "ext": { - "v": 0 - }, - "seqLedger": 4, - "seqTime": 0 - } - } - } - } - } + "v": 0 } } }, @@ -622,9 +714,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", - "balance": 999999998999989600, - "seqNum": 3, + "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", + "balance": 399999700, + "seqNum": 12884901888, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -632,31 +724,7 @@ "thresholds": "01000000", "signers": [], "ext": { - "v": 1, - "v1": { - "liabilities": { - "buying": 0, - "selling": 0 - }, - "ext": { - "v": 2, - "v2": { - "numSponsored": 0, - "numSponsoring": 0, - "signerSponsoringIDs": [], - "ext": { - "v": 3, - "v3": { - "ext": { - "v": 0 - }, - "seqLedger": 4, - "seqTime": 0 - } - } - } - } - } + "v": 0 } } }, @@ -680,9 +748,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", - "balance": 999999998999989600, - "seqNum": 3, + "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", + "balance": 399999700, + "seqNum": 12884901888, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -690,31 +758,7 @@ "thresholds": "01000000", "signers": [], "ext": { - "v": 1, - "v1": { - "liabilities": { - "buying": 0, - "selling": 0 - }, - "ext": { - "v": 2, - "v2": { - "numSponsored": 0, - "numSponsoring": 0, - "signerSponsoringIDs": [], - "ext": { - "v": 3, - "v3": { - "ext": { - "v": 0 - }, - "seqLedger": 4, - "seqTime": 0 - } - } - } - } - } + "v": 0 } } }, @@ -730,9 +774,61 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", - "balance": 999999998999989600, - "seqNum": 4, + "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", + "balance": 399999700, + "seqNum": 12884901888, + "numSubEntries": 0, + "inflationDest": null, + "flags": 0, + "homeDomain": "", + "thresholds": "01000000", + "signers": [], + "ext": { + "v": 0 + } + } + }, + "ext": { + "v": 0 + } + } + }, + { + "type": "LEDGER_ENTRY_STATE", + "state": { + "lastModifiedLedgerSeq": 4, + "data": { + "type": "ACCOUNT", + "account": { + "accountID": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q", + "balance": 200010000, + "seqNum": 17179869184, + "numSubEntries": 0, + "inflationDest": null, + "flags": 0, + "homeDomain": "", + "thresholds": "01000000", + "signers": [], + "ext": { + "v": 0 + } + } + }, + "ext": { + "v": 0 + } + } + }, + { + "type": "LEDGER_ENTRY_UPDATED", + "updated": { + "lastModifiedLedgerSeq": 6, + "data": { + "type": "ACCOUNT", + "account": { + "accountID": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q", + "balance": 200010000, + "seqNum": 17179869185, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -780,45 +876,20 @@ { "type": "LEDGER_ENTRY_STATE", "state": { - "lastModifiedLedgerSeq": 6, + "lastModifiedLedgerSeq": 5, "data": { - "type": "ACCOUNT", - "account": { - "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", - "balance": 999999998999989600, - "seqNum": 4, - "numSubEntries": 0, - "inflationDest": null, - "flags": 0, - "homeDomain": "", - "thresholds": "01000000", - "signers": [], + "type": "TRUSTLINE", + "trustLine": { + "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", + "asset": { + "assetCode": "CUR1", + "issuer": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q" + }, + "balance": 0, + "limit": 100, + "flags": 1, "ext": { - "v": 1, - "v1": { - "liabilities": { - "buying": 0, - "selling": 0 - }, - "ext": { - "v": 2, - "v2": { - "numSponsored": 0, - "numSponsoring": 0, - "signerSponsoringIDs": [], - "ext": { - "v": 3, - "v3": { - "ext": { - "v": 0 - }, - "seqLedger": 6, - "seqTime": 0 - } - } - } - } - } + "v": 0 } } }, @@ -832,43 +903,18 @@ "updated": { "lastModifiedLedgerSeq": 6, "data": { - "type": "ACCOUNT", - "account": { - "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", - "balance": 999999998999988600, - "seqNum": 4, - "numSubEntries": 0, - "inflationDest": null, - "flags": 0, - "homeDomain": "", - "thresholds": "01000000", - "signers": [], + "type": "TRUSTLINE", + "trustLine": { + "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", + "asset": { + "assetCode": "CUR1", + "issuer": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q" + }, + "balance": 50, + "limit": 100, + "flags": 1, "ext": { - "v": 1, - "v1": { - "liabilities": { - "buying": 0, - "selling": 0 - }, - "ext": { - "v": 2, - "v2": { - "numSponsored": 0, - "numSponsoring": 0, - "signerSponsoringIDs": [], - "ext": { - "v": 3, - "v3": { - "ext": { - "v": 0 - }, - "seqLedger": 6, - "seqTime": 0 - } - } - } - } - } + "v": 0 } } }, @@ -876,49 +922,28 @@ "v": 0 } } - }, + } + ] + }, + { + "changes": [ { "type": "LEDGER_ENTRY_STATE", "state": { - "lastModifiedLedgerSeq": 5, + "lastModifiedLedgerSeq": 6, "data": { - "type": "ACCOUNT", - "account": { + "type": "TRUSTLINE", + "trustLine": { "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", - "balance": 399999900, - "seqNum": 8589934593, - "numSubEntries": 1, - "inflationDest": null, - "flags": 0, - "homeDomain": "", - "thresholds": "01000000", - "signers": [], + "asset": { + "assetCode": "CUR1", + "issuer": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q" + }, + "balance": 50, + "limit": 100, + "flags": 1, "ext": { - "v": 1, - "v1": { - "liabilities": { - "buying": 0, - "selling": 0 - }, - "ext": { - "v": 2, - "v2": { - "numSponsored": 0, - "numSponsoring": 0, - "signerSponsoringIDs": [], - "ext": { - "v": 3, - "v3": { - "ext": { - "v": 0 - }, - "seqLedger": 5, - "seqTime": 0 - } - } - } - } - } + "v": 0 } } }, @@ -932,43 +957,18 @@ "updated": { "lastModifiedLedgerSeq": 6, "data": { - "type": "ACCOUNT", - "account": { + "type": "TRUSTLINE", + "trustLine": { "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", - "balance": 400000900, - "seqNum": 8589934593, - "numSubEntries": 1, - "inflationDest": null, - "flags": 0, - "homeDomain": "", - "thresholds": "01000000", - "signers": [], + "asset": { + "assetCode": "CUR1", + "issuer": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q" + }, + "balance": 100, + "limit": 100, + "flags": 1, "ext": { - "v": 1, - "v1": { - "liabilities": { - "buying": 0, - "selling": 0 - }, - "ext": { - "v": 2, - "v2": { - "numSponsored": 0, - "numSponsoring": 0, - "signerSponsoringIDs": [], - "ext": { - "v": 3, - "v3": { - "ext": { - "v": 0 - }, - "seqLedger": 5, - "seqTime": 0 - } - } - } - } - } + "v": 0 } } }, From 55e223baca78ccc36c129ae60d0cc3e964f78c17 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Wed, 21 Jun 2023 09:45:53 -0700 Subject: [PATCH 8/9] Fix flaky test --- src/herder/test/UpgradesTests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/herder/test/UpgradesTests.cpp b/src/herder/test/UpgradesTests.cpp index 52d6f0498c..9794d266dc 100644 --- a/src/herder/test/UpgradesTests.cpp +++ b/src/herder/test/UpgradesTests.cpp @@ -3000,7 +3000,7 @@ TEST_CASE("upgrade to generalized tx set in network", "[upgrades][overlay]") } return loadGenDone.count() > currLoadGenCount; }, - 10 * Herder::EXP_LEDGER_TIMESPAN_SECONDS, false); + 11 * Herder::EXP_LEDGER_TIMESPAN_SECONDS, false); // Make sure upgrade has happened. REQUIRE(upgradeLedger); From b5386da372ad0e010c6a44ef6873c431d43b261e Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Wed, 21 Jun 2023 11:03:58 -0700 Subject: [PATCH 9/9] Fix more tests --- src/ledger/test/LedgerTestUtils.cpp | 42 +++++++++++++++++++ src/ledger/test/LedgerTestUtils.h | 3 ++ .../test/InvokeHostFunctionTests.cpp | 6 +-- src/transactions/test/TxEnvelopeTests.cpp | 20 ++++++--- 4 files changed, 62 insertions(+), 9 deletions(-) diff --git a/src/ledger/test/LedgerTestUtils.cpp b/src/ledger/test/LedgerTestUtils.cpp index 39f3525e64..f69f7ad835 100644 --- a/src/ledger/test/LedgerTestUtils.cpp +++ b/src/ledger/test/LedgerTestUtils.cpp @@ -14,6 +14,7 @@ #ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION #include "xdr/Stellar-contract.h" #endif +#include "ledger/NetworkConfig.h" #include "xdr/Stellar-ledger-entries.h" #include #include @@ -348,6 +349,24 @@ makeValid(ContractDataEntry& cde) cde.body.data().flags = 0; int t = cde.type; cde.type = static_cast(std::abs(t % 3)); + + LedgerEntry le; + le.data.type(CONTRACT_DATA); + le.data.contractData() = cde; + + auto key = LedgerEntryKey(le); + if (xdr::xdr_size(key) > + InitialSorobanNetworkConfig::MAX_CONTRACT_DATA_KEY_SIZE_BYTES) + { + // make the key small to prevent hitting the limit + static const uint32_t key_limit = + InitialSorobanNetworkConfig::MAX_CONTRACT_DATA_KEY_SIZE_BYTES - 50; + auto small_bytes = + autocheck::generator>()(5); + SCVal val(SCV_BYTES); + val.bytes().assign(small_bytes.begin(), small_bytes.end()); + cde.key = val; + } } void @@ -617,6 +636,29 @@ generateValidLedgerEntryKeysWithExclusions( return keys; } +std::vector +generateValidUniqueLedgerEntryKeysWithExclusions( + std::unordered_set const& excludedTypes, size_t n) +{ + UnorderedSet keys; + std::vector res; + keys.reserve(n); + res.reserve(n); + while (keys.size() < n) + { + auto entry = generateValidLedgerEntryWithExclusions(excludedTypes, n); + auto key = LedgerEntryKey(entry); + if (keys.find(key) != keys.end()) + { + continue; + } + + keys.insert(key); + res.emplace_back(key); + } + return res; +} + LedgerEntry generateValidLedgerEntryWithTypes( std::unordered_set const& types, size_t b) diff --git a/src/ledger/test/LedgerTestUtils.h b/src/ledger/test/LedgerTestUtils.h index d2923eb14a..afca79741a 100644 --- a/src/ledger/test/LedgerTestUtils.h +++ b/src/ledger/test/LedgerTestUtils.h @@ -46,6 +46,9 @@ std::vector generateValidUniqueLedgerEntries(size_t n); std::vector generateValidLedgerEntryKeysWithExclusions( std::unordered_set const& excludedTypes, size_t n); +std::vector generateValidUniqueLedgerEntryKeysWithExclusions( + std::unordered_set const& excludedTypes, size_t n); + LedgerEntry generateValidLedgerEntryWithExclusions( std::unordered_set const& excludedTypes, size_t b = 3); std::vector generateValidLedgerEntriesWithExclusions( diff --git a/src/transactions/test/InvokeHostFunctionTests.cpp b/src/transactions/test/InvokeHostFunctionTests.cpp index 6b70bd2ddd..605b423b25 100644 --- a/src/transactions/test/InvokeHostFunctionTests.cpp +++ b/src/transactions/test/InvokeHostFunctionTests.cpp @@ -610,10 +610,10 @@ TEST_CASE("contract storage", "[tx][soroban]") SorobanResources bumpResources; bumpResources.footprint.readOnly = readOnly; - bumpResources.instructions = 200'000; + bumpResources.instructions = 0; bumpResources.readBytes = 1000; - bumpResources.writeBytes = 5000; - bumpResources.extendedMetaDataSizeBytes = 6000; + bumpResources.writeBytes = 1000; + bumpResources.extendedMetaDataSizeBytes = 1000; // submit operation auto root = TestAccount::createRoot(*app); diff --git a/src/transactions/test/TxEnvelopeTests.cpp b/src/transactions/test/TxEnvelopeTests.cpp index c319d27d74..e56a261942 100644 --- a/src/transactions/test/TxEnvelopeTests.cpp +++ b/src/transactions/test/TxEnvelopeTests.cpp @@ -12,6 +12,7 @@ #include "ledger/LedgerTxnEntry.h" #include "ledger/LedgerTxnHeader.h" #include "ledger/NetworkConfig.h" +#include "ledger/test/LedgerTestUtils.h" #include "lib/catch.hpp" #include "lib/json/json.h" #include "main/Application.h" @@ -2529,11 +2530,18 @@ TEST_CASE("soroban transaction validation", "[tx][envelope][soroban]") resources.writeBytes = InitialSorobanNetworkConfig::TX_MAX_WRITE_BYTES; resources.extendedMetaDataSizeBytes = InitialSorobanNetworkConfig::TX_MAX_EXTENDED_META_DATA_SIZE_BYTES; - resources.footprint.readOnly.resize( - InitialSorobanNetworkConfig::TX_MAX_READ_LEDGER_ENTRIES - - InitialSorobanNetworkConfig::TX_MAX_WRITE_LEDGER_ENTRIES); - resources.footprint.readWrite.resize( - InitialSorobanNetworkConfig::TX_MAX_WRITE_LEDGER_ENTRIES); + + auto keys = + LedgerTestUtils::generateValidUniqueLedgerEntryKeysWithExclusions( + {}, InitialSorobanNetworkConfig::TX_MAX_READ_LEDGER_ENTRIES); + + resources.footprint.readWrite.assign( + keys.begin(), + keys.begin() + + InitialSorobanNetworkConfig::TX_MAX_WRITE_LEDGER_ENTRIES); + resources.footprint.readOnly.assign( + keys.begin() + InitialSorobanNetworkConfig::TX_MAX_WRITE_LEDGER_ENTRIES, + keys.end()); SECTION("instructions exceeded") { resources.instructions += 1; @@ -2578,7 +2586,7 @@ TEST_CASE("soroban transaction validation", "[tx][envelope][soroban]") ihf.type(HOST_FUNCTION_TYPE_INVOKE_CONTRACT); SCVal largeVal(SCV_BYTES); largeVal.bytes().resize(InitialSorobanNetworkConfig::TX_MAX_SIZE_BYTES - - 2000); + 3000); ihf.invokeContract().push_back(largeVal); SECTION("near limit") {