From f09f6ea54a3026fed27db5644503d440653c9508 Mon Sep 17 00:00:00 2001 From: Garand Tyson Date: Wed, 9 Oct 2024 23:49:38 -0700 Subject: [PATCH] added restore tx meta --- src/transactions/FeeBumpTransactionFrame.cpp | 2 ++ src/transactions/TransactionFrame.cpp | 34 +++++++++++++++++++ .../test/InvokeHostFunctionTests.cpp | 3 +- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/transactions/FeeBumpTransactionFrame.cpp b/src/transactions/FeeBumpTransactionFrame.cpp index 63c97b276f..44a55e5ea9 100644 --- a/src/transactions/FeeBumpTransactionFrame.cpp +++ b/src/transactions/FeeBumpTransactionFrame.cpp @@ -54,11 +54,13 @@ FeeBumpTransactionFrame::sorobanResources() const return mInnerTx->sorobanResources(); } +#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION xdr::xvector const& FeeBumpTransactionFrame::sorobanProofs() const { return mInnerTx->sorobanProofs(); } +#endif FeeBumpTransactionFrame::FeeBumpTransactionFrame( Hash const& networkID, TransactionEnvelope const& envelope) diff --git a/src/transactions/TransactionFrame.cpp b/src/transactions/TransactionFrame.cpp index b2ed3cb4d6..aaa51ca2ec 100644 --- a/src/transactions/TransactionFrame.cpp +++ b/src/transactions/TransactionFrame.cpp @@ -56,6 +56,32 @@ namespace // Limit to the maximum resource fee allowed for transaction, // roughly 112 million lumens. int64_t const MAX_RESOURCE_FEE = 1LL << 50; + +// Starting in protocol 23, some operation meta needs to be modified +// to be consumed by downstream systems. In particular, restoration is +// logically a new entry creation from the perspective of ltx and stellar-core +// as a whole, but this change type is reclassified to LEDGER_ENTRY_RESTORED +// for easier consumption downstream. +void +processOpLedgerEntryChanges(std::shared_ptr op, + LedgerEntryChanges& changes) +{ + if (op->getOperation().body.type() != RESTORE_FOOTPRINT) + { + return; + } + + for (auto& change : changes) + { + if (change.type() == LEDGER_ENTRY_CREATED) + { + auto le = change.created(); + change.type(LEDGER_ENTRY_RESTORED); + change.restored() = le; + } + } +} + } // namespace using namespace std; @@ -1638,6 +1664,14 @@ TransactionFrame::applyOperations(SignatureChecker& signatureChecker, // The operation meta will be empty if the transaction // doesn't succeed so we may as well not do any work in that // case + auto changes = ltxOp.getChanges(); + + if (protocolVersionStartsFrom( + ledgerVersion, + Bucket::FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION)) + { + processOpLedgerEntryChanges(op, changes); + } operationMetas.emplace_back(ltxOp.getChanges()); } diff --git a/src/transactions/test/InvokeHostFunctionTests.cpp b/src/transactions/test/InvokeHostFunctionTests.cpp index f3364936d9..191d14fa3b 100644 --- a/src/transactions/test/InvokeHostFunctionTests.cpp +++ b/src/transactions/test/InvokeHostFunctionTests.cpp @@ -2914,8 +2914,7 @@ TEST_CASE("state archival operation errors", "[tx][soroban][archival]") } #ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION -TEST_CASE("evicted persistent entries" - "[tx][soroban][archival]") +TEST_CASE("evicted persistent entries", "[tx][soroban][archival]") { auto test = [](bool requireProofs) { auto cfg = getTestConfig();