From 54a8be1a7c54fcc1ba13410f2e6abbbbd648ce7d Mon Sep 17 00:00:00 2001 From: Garand Tyson Date: Thu, 10 Oct 2024 16:23:59 -0700 Subject: [PATCH] Better test coverage --- src/bucket/BucketManagerImpl.cpp | 1 - src/ledger/LedgerManagerImpl.cpp | 69 ++- src/main/SettingsUpgradeUtils.cpp | 20 + ...ger-close-meta-v1-protocol-23-soroban.json | 456 +++++++++--------- .../ledger-close-meta-v1-protocol-23.json | 12 +- src/transactions/FeeBumpTransactionFrame.cpp | 6 + src/transactions/FeeBumpTransactionFrame.h | 1 + .../InvokeHostFunctionOpFrame.cpp | 21 +- src/transactions/RestoreFootprintOpFrame.cpp | 3 +- src/transactions/TransactionFrame.cpp | 10 +- src/transactions/TransactionFrame.h | 1 + src/transactions/TransactionFrameBase.h | 1 + .../test/InvokeHostFunctionTests.cpp | 249 +++++++--- .../test/TransactionTestFrame.cpp | 6 + src/transactions/test/TransactionTestFrame.h | 1 + 15 files changed, 514 insertions(+), 343 deletions(-) diff --git a/src/bucket/BucketManagerImpl.cpp b/src/bucket/BucketManagerImpl.cpp index 3770328c1a..fcb0cab6ad 100644 --- a/src/bucket/BucketManagerImpl.cpp +++ b/src/bucket/BucketManagerImpl.cpp @@ -1683,7 +1683,6 @@ BucketManagerImpl::getSearchableLiveBucketListSnapshot() std::shared_ptr BucketManagerImpl::getSearchableHotArchiveBucketListSnapshot() { - releaseAssert(mApp.getConfig().isUsingBucketListDB()); // Any other threads must maintain their own snapshot releaseAssert(threadIsMain()); if (!mSearchableHotArchiveBucketListSnapshot) diff --git a/src/ledger/LedgerManagerImpl.cpp b/src/ledger/LedgerManagerImpl.cpp index 22f2c7e967..ec38842418 100644 --- a/src/ledger/LedgerManagerImpl.cpp +++ b/src/ledger/LedgerManagerImpl.cpp @@ -1685,50 +1685,47 @@ LedgerManagerImpl::transferLedgerEntriesToBucketList( if (blEnabled && protocolVersionStartsFrom(initialLedgerVers, SOROBAN_PROTOCOL_VERSION)) { + auto ttlKeys = ltx.getAllTTLKeysWithoutSealing(); + auto deletedPersistentDataKeys = + ltx.getAllDeletedPersistentContractDataKeysWithoutSealing(); + auto createdPersistentDataKeys = + ltx.getAllCreatedPersistentContractDataKeysWithoutSealing(); + LedgerTxn ltxEvictions(ltx); + + auto evictedEntries = + mApp.getBucketManager().resolveBackgroundEvictionScan( + ltxEvictions, lh.ledgerSeq, ttlKeys, initialLedgerVers); + + if (protocolVersionStartsFrom( + initialLedgerVers, + Bucket::FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION)) { - auto deletedPersistentDataKeys = - ltx.getAllDeletedPersistentContractDataKeysWithoutSealing(); - auto createdPersistentDataKeys = - ltx.getAllCreatedPersistentContractDataKeysWithoutSealing(); - LedgerTxn ltxEvictions(ltx); + auto createdVec = + std::vector(createdPersistentDataKeys.begin(), + createdPersistentDataKeys.end()); + auto deletedVec = + std::vector(deletedPersistentDataKeys.begin(), + deletedPersistentDataKeys.end()); + mApp.getBucketManager().addHotArchiveBatch( + mApp, lh, evictedEntries.second, createdVec, deletedVec); - auto evictedEntries = - mApp.getBucketManager().resolveBackgroundEvictionScan( - ltxEvictions, lh.ledgerSeq, keys, initialLedgerVers); - - if (protocolVersionStartsFrom( - initialLedgerVers, - Bucket::FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION)) + if (ledgerCloseMeta) { - auto createdVec = std::vector( - createdPersistentDataKeys.begin(), - createdPersistentDataKeys.end()); - auto deletedVec = std::vector( - deletedPersistentDataKeys.begin(), - deletedPersistentDataKeys.end()); - mApp.getBucketManager().addHotArchiveBatch( - mApp, lh, evictedEntries.second, createdVec, - deletedVec); - } - - if (ledgerCloseMeta) - { - ledgerCloseMeta->populateEvictedEntries(evictedEntries); - } + ledgerCloseMeta->populateEvictedEntries(evictedEntries); } - else - { + } + else + { - if (ledgerCloseMeta) - { - ledgerCloseMeta->populateEvictedEntriesLegacy( - ltxEvictions.getChanges()); - } + if (ledgerCloseMeta) + { + ledgerCloseMeta->populateEvictedEntriesLegacy( + ltxEvictions.getChanges()); } - - ltxEvictions.commit(); } + ltxEvictions.commit(); + getSorobanNetworkConfigInternal().maybeSnapshotBucketListSize( lh.ledgerSeq, ltx, mApp); } diff --git a/src/main/SettingsUpgradeUtils.cpp b/src/main/SettingsUpgradeUtils.cpp index 1b241dadf2..298b3702a7 100644 --- a/src/main/SettingsUpgradeUtils.cpp +++ b/src/main/SettingsUpgradeUtils.cpp @@ -13,6 +13,10 @@ getWasmRestoreTx(PublicKey const& publicKey, SequenceNumber seqNum) TransactionEnvelope txEnv; txEnv.type(ENVELOPE_TYPE_TX); +#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION + txEnv.v1().tx.ext.sorobanData().ext.v(1); +#endif + auto& tx = txEnv.v1().tx; tx.sourceAccount = toMuxedAccount(publicKey); tx.fee = 100'000'000; @@ -49,6 +53,10 @@ getWasmRestoreTx(PublicKey const& publicKey, SequenceNumber seqNum) tx.ext.sorobanData().resources = restoreResources; tx.ext.sorobanData().resourceFee = 55'000'000; +#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION + tx.ext.sorobanData().ext.v(1); +#endif + return {txEnv, contractCodeLedgerKey}; } @@ -96,6 +104,10 @@ getUploadTx(PublicKey const& publicKey, SequenceNumber seqNum) tx.ext.sorobanData().resources = uploadResources; tx.ext.sorobanData().resourceFee = 55'000'000; +#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION + tx.ext.sorobanData().ext.v(1); +#endif + return {txEnv, contractCodeLedgerKey}; } @@ -180,6 +192,10 @@ getCreateTx(PublicKey const& publicKey, LedgerKey const& contractCodeLedgerKey, tx.ext.sorobanData().resources = uploadResources; tx.ext.sorobanData().resourceFee = 15'000'000; +#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION + tx.ext.sorobanData().ext.v(1); +#endif + return {txEnv, contractSourceRefLedgerKey, contractID}; } @@ -274,6 +290,10 @@ getInvokeTx(PublicKey const& publicKey, LedgerKey const& contractCodeLedgerKey, tx.ext.sorobanData().resources = invokeResources; tx.ext.sorobanData().resourceFee = 65'000'000; +#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION + tx.ext.sorobanData().ext.v(1); +#endif + ConfigUpgradeSetKey key; key.contentHash = upgradeHash; key.contractID = contractID; diff --git a/src/testdata/ledger-close-meta-v1-protocol-23-soroban.json b/src/testdata/ledger-close-meta-v1-protocol-23-soroban.json index b9b25cc33d..28129129ee 100644 --- a/src/testdata/ledger-close-meta-v1-protocol-23-soroban.json +++ b/src/testdata/ledger-close-meta-v1-protocol-23-soroban.json @@ -6,24 +6,24 @@ "v": 0 }, "ledgerHeader": { - "hash": "75dfe352d173553bc7f3beb7b40eba12c3bc499828002856fe7380cf6bc31db3", + "hash": "0df2ae22423e7c911902bdd1b387d0c4f4964b7c7af76df0e1f1f3a954d2dcb1", "header": { "ledgerVersion": 23, - "previousLedgerHash": "89aded764da0eb6015a399598527197fffa82b4cdbb207ab647dc0dc924e26be", + "previousLedgerHash": "ec831e454c9b5abe3a8f86c6722e1c1941e8b5669702ce73960566ce0703a3c2", "scpValue": { - "txSetHash": "487f8bbdbc19af0cbc88ec00b3e9c50b89881f8c64a86f3325543f4e90671059", + "txSetHash": "dd507a3251ca286285959aee6156152f15b52e5fc46742a047e9c93d39dbb27e", "closeTime": 1451692800, "upgrades": [], "ext": { "v": "STELLAR_VALUE_SIGNED", "lcValueSignature": { "nodeID": "GDDOUW25MRFLNXQMN3OODP6JQEXSGLMHAFZV4XPQ2D3GA4QFIDMEJG2O", - "signature": "78a3be3bc98e9210346c508ea7a56a8879d7cdf0733f984d0b0fafd517f2e8cf327f4e4e6243aa66a3f883d6b94233372b0d6af58d3cf93e1031154090ed9508" + "signature": "0587c6e47b6ec9a9d00833af90202a130842e866e25b6436730994a65ce73a8f83c402bccbd1c9a364d08d2d76c4db1a1074752b7ce41177939de31972a63200" } } }, - "txSetResultHash": "c0396efee573ec17a97a59bd16ddbd4b34d40f10267e95fe3af166a617cb43e6", - "bucketListHash": "4044eed589f90739ff6a007b83c5eceb715acd0e1897e0b257eb3d87c274c224", + "txSetResultHash": "6bab0ddd0b6deec3328aa98685f78f0ac172c87d1bb3365344209ca9e59c2f87", + "bucketListHash": "dde7b6e6bf0d7228ce944e382e54cb48a7a4d0941e37f7b4e0d149f81c84bcb2", "ledgerSeq": 28, "totalCoins": 1000000000000000000, "feePool": 804593, @@ -49,7 +49,7 @@ "txSet": { "v": 1, "v1TxSet": { - "previousLedgerHash": "89aded764da0eb6015a399598527197fffa82b4cdbb207ab647dc0dc924e26be", + "previousLedgerHash": "ec831e454c9b5abe3a8f86c6722e1c1941e8b5669702ce73960566ce0703a3c2", "phases": [ { "v": 0, @@ -508,19 +508,18 @@ "txProcessing": [ { "result": { - "transactionHash": "ccf577b22534829f757fc83a2d76bdaeea44e3d79a48b72067cf8e3ac3e9357b", + "transactionHash": "7a4e118eada547afae378dde799a5cb300438dbc4b42a7b51c545edbf56f4c3e", "result": { - "feeCharged": 106784, + "feeCharged": 60566, "result": { "code": "txSUCCESS", "results": [ { "code": "opINNER", "tr": { - "type": "INVOKE_HOST_FUNCTION", - "invokeHostFunctionResult": { - "code": "INVOKE_HOST_FUNCTION_SUCCESS", - "success": "cbbc48750debb8535093b3deaf88ac7f4cff87425576a58de2bac754acdb4616" + "type": "EXTEND_FOOTPRINT_TTL", + "extendFootprintTTLResult": { + "code": "EXTEND_FOOTPRINT_TTL_SUCCESS" } } } @@ -535,13 +534,13 @@ { "type": "LEDGER_ENTRY_STATE", "state": { - "lastModifiedLedgerSeq": 10, + "lastModifiedLedgerSeq": 9, "data": { "type": "ACCOUNT", "account": { - "accountID": "GDWWCIR2FIWTY2D3CEDXZYRTRNTFZCC5PBCGC6XPMKCLUV7BRG2AT3RD", + "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", "balance": 400000000, - "seqNum": 42949672960, + "seqNum": 38654705664, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -565,9 +564,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GDWWCIR2FIWTY2D3CEDXZYRTRNTFZCC5PBCGC6XPMKCLUV7BRG2AT3RD", - "balance": 399873265, - "seqNum": 42949672960, + "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", + "balance": 398999900, + "seqNum": 38654705664, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -599,9 +598,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GDWWCIR2FIWTY2D3CEDXZYRTRNTFZCC5PBCGC6XPMKCLUV7BRG2AT3RD", - "balance": 399873265, - "seqNum": 42949672960, + "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", + "balance": 398999900, + "seqNum": 38654705664, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -625,9 +624,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GDWWCIR2FIWTY2D3CEDXZYRTRNTFZCC5PBCGC6XPMKCLUV7BRG2AT3RD", - "balance": 399873265, - "seqNum": 42949672961, + "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", + "balance": 398999900, + "seqNum": 38654705665, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -673,25 +672,30 @@ { "changes": [ { - "type": "LEDGER_ENTRY_CREATED", - "created": { + "type": "LEDGER_ENTRY_STATE", + "state": { + "lastModifiedLedgerSeq": 6, + "data": { + "type": "TTL", + "ttl": { + "keyHash": "091ddece931776a53f93869b82c24e132cc12d00d961fac09bc3b9cb9021c62d", + "liveUntilLedgerSeq": 10006 + } + }, + "ext": { + "v": 0 + } + } + }, + { + "type": "LEDGER_ENTRY_UPDATED", + "updated": { "lastModifiedLedgerSeq": 28, "data": { - "type": "CONTRACT_DATA", - "contractData": { - "ext": { - "v": 0 - }, - "contract": "CAA3QKIP2SNVXUJTB4HKOGF55JTSSMQGED3FZYNHMNSXYV3DRRMAWA3Y", - "key": { - "type": "SCV_SYMBOL", - "sym": "key" - }, - "durability": "PERSISTENT", - "val": { - "type": "SCV_U64", - "u64": 42 - } + "type": "TTL", + "ttl": { + "keyHash": "091ddece931776a53f93869b82c24e132cc12d00d961fac09bc3b9cb9021c62d", + "liveUntilLedgerSeq": 10028 } }, "ext": { @@ -700,14 +704,30 @@ } }, { - "type": "LEDGER_ENTRY_CREATED", - "created": { + "type": "LEDGER_ENTRY_STATE", + "state": { + "lastModifiedLedgerSeq": 6, + "data": { + "type": "TTL", + "ttl": { + "keyHash": "60313f9b273db0b14c3e503cf6cc152dd14a0c57e5e81a23e86b4e27a23a2c06", + "liveUntilLedgerSeq": 10006 + } + }, + "ext": { + "v": 0 + } + } + }, + { + "type": "LEDGER_ENTRY_UPDATED", + "updated": { "lastModifiedLedgerSeq": 28, "data": { "type": "TTL", "ttl": { - "keyHash": "764f4e59e20ac1a357f9f26ab0eaf46d196ab74822db44f039353a6f114864aa", - "liveUntilLedgerSeq": 47 + "keyHash": "60313f9b273db0b14c3e503cf6cc152dd14a0c57e5e81a23e86b4e27a23a2c06", + "liveUntilLedgerSeq": 10028 } }, "ext": { @@ -726,9 +746,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GDWWCIR2FIWTY2D3CEDXZYRTRNTFZCC5PBCGC6XPMKCLUV7BRG2AT3RD", - "balance": 399873265, - "seqNum": 42949672961, + "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", + "balance": 398999900, + "seqNum": 38654705665, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -776,9 +796,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GDWWCIR2FIWTY2D3CEDXZYRTRNTFZCC5PBCGC6XPMKCLUV7BRG2AT3RD", - "balance": 399893216, - "seqNum": 42949672961, + "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", + "balance": 399939434, + "seqNum": 38654705665, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -826,7 +846,8 @@ }, "events": [], "returnValue": { - "type": "SCV_VOID" + "type": "SCV_BOOL", + "b": "FALSE" }, "diagnosticEvents": [] } @@ -835,9 +856,9 @@ }, { "result": { - "transactionHash": "826c09db23c8efae9c9a8291c690c32c74782fdacf3c6c7f61d3f6622c35e9fd", + "transactionHash": "16e22c43e107e363ba604b2b458eb213b70c0a3df283042ec1722cdc351118e3", "result": { - "feeCharged": 61619, + "feeCharged": 42963, "result": { "code": "txFAILED", "results": [ @@ -846,7 +867,7 @@ "tr": { "type": "INVOKE_HOST_FUNCTION", "invokeHostFunctionResult": { - "code": "INVOKE_HOST_FUNCTION_TRAPPED" + "code": "INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED" } } } @@ -861,13 +882,13 @@ { "type": "LEDGER_ENTRY_STATE", "state": { - "lastModifiedLedgerSeq": 11, + "lastModifiedLedgerSeq": 12, "data": { "type": "ACCOUNT", "account": { - "accountID": "GAM4XNEHJUHN7VE3ZWJI23R2WS3SJS2BTUHZAC6XICXLXO2HPX4QI2IR", + "accountID": "GA2NXNEE2MHWGQP5XXACPYG2BDZFPKGYPFNST5V3ZZN75NSLQAEXX7CU", "balance": 400000000, - "seqNum": 47244640256, + "seqNum": 51539607552, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -891,9 +912,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GAM4XNEHJUHN7VE3ZWJI23R2WS3SJS2BTUHZAC6XICXLXO2HPX4QI2IR", - "balance": 399898381, - "seqNum": 47244640256, + "accountID": "GA2NXNEE2MHWGQP5XXACPYG2BDZFPKGYPFNST5V3ZZN75NSLQAEXX7CU", + "balance": 398956045, + "seqNum": 51539607552, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -925,9 +946,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GAM4XNEHJUHN7VE3ZWJI23R2WS3SJS2BTUHZAC6XICXLXO2HPX4QI2IR", - "balance": 399898381, - "seqNum": 47244640256, + "accountID": "GA2NXNEE2MHWGQP5XXACPYG2BDZFPKGYPFNST5V3ZZN75NSLQAEXX7CU", + "balance": 398956045, + "seqNum": 51539607552, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -951,9 +972,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GAM4XNEHJUHN7VE3ZWJI23R2WS3SJS2BTUHZAC6XICXLXO2HPX4QI2IR", - "balance": 399898381, - "seqNum": 47244640257, + "accountID": "GA2NXNEE2MHWGQP5XXACPYG2BDZFPKGYPFNST5V3ZZN75NSLQAEXX7CU", + "balance": 398956045, + "seqNum": 51539607553, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1004,9 +1025,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GAM4XNEHJUHN7VE3ZWJI23R2WS3SJS2BTUHZAC6XICXLXO2HPX4QI2IR", - "balance": 399898381, - "seqNum": 47244640257, + "accountID": "GA2NXNEE2MHWGQP5XXACPYG2BDZFPKGYPFNST5V3ZZN75NSLQAEXX7CU", + "balance": 398956045, + "seqNum": 51539607553, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1054,9 +1075,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GAM4XNEHJUHN7VE3ZWJI23R2WS3SJS2BTUHZAC6XICXLXO2HPX4QI2IR", - "balance": 399938381, - "seqNum": 47244640257, + "accountID": "GA2NXNEE2MHWGQP5XXACPYG2BDZFPKGYPFNST5V3ZZN75NSLQAEXX7CU", + "balance": 399957037, + "seqNum": 51539607553, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1114,18 +1135,19 @@ }, { "result": { - "transactionHash": "742cd3385bedce54d59e1d9751a34e91beafeb9f6afcbded05f2e016e8b51b2c", + "transactionHash": "ccf577b22534829f757fc83a2d76bdaeea44e3d79a48b72067cf8e3ac3e9357b", "result": { - "feeCharged": 51555, + "feeCharged": 106784, "result": { "code": "txSUCCESS", "results": [ { "code": "opINNER", "tr": { - "type": "RESTORE_FOOTPRINT", - "restoreFootprintResult": { - "code": "RESTORE_FOOTPRINT_SUCCESS" + "type": "INVOKE_HOST_FUNCTION", + "invokeHostFunctionResult": { + "code": "INVOKE_HOST_FUNCTION_SUCCESS", + "success": "cbbc48750debb8535093b3deaf88ac7f4cff87425576a58de2bac754acdb4616" } } } @@ -1140,13 +1162,13 @@ { "type": "LEDGER_ENTRY_STATE", "state": { - "lastModifiedLedgerSeq": 8, + "lastModifiedLedgerSeq": 10, "data": { "type": "ACCOUNT", "account": { - "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", + "accountID": "GDWWCIR2FIWTY2D3CEDXZYRTRNTFZCC5PBCGC6XPMKCLUV7BRG2AT3RD", "balance": 400000000, - "seqNum": 34359738368, + "seqNum": 42949672960, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1170,9 +1192,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", - "balance": 398999900, - "seqNum": 34359738368, + "accountID": "GDWWCIR2FIWTY2D3CEDXZYRTRNTFZCC5PBCGC6XPMKCLUV7BRG2AT3RD", + "balance": 399873265, + "seqNum": 42949672960, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1204,9 +1226,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", - "balance": 398999900, - "seqNum": 34359738368, + "accountID": "GDWWCIR2FIWTY2D3CEDXZYRTRNTFZCC5PBCGC6XPMKCLUV7BRG2AT3RD", + "balance": 399873265, + "seqNum": 42949672960, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1230,9 +1252,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", - "balance": 398999900, - "seqNum": 34359738369, + "accountID": "GDWWCIR2FIWTY2D3CEDXZYRTRNTFZCC5PBCGC6XPMKCLUV7BRG2AT3RD", + "balance": 399873265, + "seqNum": 42949672961, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1278,14 +1300,25 @@ { "changes": [ { - "type": "LEDGER_ENTRY_STATE", - "state": { - "lastModifiedLedgerSeq": 7, + "type": "LEDGER_ENTRY_CREATED", + "created": { + "lastModifiedLedgerSeq": 28, "data": { - "type": "TTL", - "ttl": { - "keyHash": "4791962cd1e2c7b8f8af3f96514f9777f0156a48261fb885a571a7f69b33a058", - "liveUntilLedgerSeq": 26 + "type": "CONTRACT_DATA", + "contractData": { + "ext": { + "v": 0 + }, + "contract": "CAA3QKIP2SNVXUJTB4HKOGF55JTSSMQGED3FZYNHMNSXYV3DRRMAWA3Y", + "key": { + "type": "SCV_SYMBOL", + "sym": "key" + }, + "durability": "PERSISTENT", + "val": { + "type": "SCV_U64", + "u64": 42 + } } }, "ext": { @@ -1294,13 +1327,13 @@ } }, { - "type": "LEDGER_ENTRY_UPDATED", - "updated": { + "type": "LEDGER_ENTRY_CREATED", + "created": { "lastModifiedLedgerSeq": 28, "data": { "type": "TTL", "ttl": { - "keyHash": "4791962cd1e2c7b8f8af3f96514f9777f0156a48261fb885a571a7f69b33a058", + "keyHash": "764f4e59e20ac1a357f9f26ab0eaf46d196ab74822db44f039353a6f114864aa", "liveUntilLedgerSeq": 47 } }, @@ -1320,9 +1353,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", - "balance": 398999900, - "seqNum": 34359738369, + "accountID": "GDWWCIR2FIWTY2D3CEDXZYRTRNTFZCC5PBCGC6XPMKCLUV7BRG2AT3RD", + "balance": 399873265, + "seqNum": 42949672961, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1370,9 +1403,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", - "balance": 399948445, - "seqNum": 34359738369, + "accountID": "GDWWCIR2FIWTY2D3CEDXZYRTRNTFZCC5PBCGC6XPMKCLUV7BRG2AT3RD", + "balance": 399893216, + "seqNum": 42949672961, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1420,8 +1453,7 @@ }, "events": [], "returnValue": { - "type": "SCV_BOOL", - "b": "FALSE" + "type": "SCV_VOID" }, "diagnosticEvents": [] } @@ -1430,18 +1462,18 @@ }, { "result": { - "transactionHash": "7a4e118eada547afae378dde799a5cb300438dbc4b42a7b51c545edbf56f4c3e", + "transactionHash": "826c09db23c8efae9c9a8291c690c32c74782fdacf3c6c7f61d3f6622c35e9fd", "result": { - "feeCharged": 60566, + "feeCharged": 61619, "result": { - "code": "txSUCCESS", + "code": "txFAILED", "results": [ { "code": "opINNER", "tr": { - "type": "EXTEND_FOOTPRINT_TTL", - "extendFootprintTTLResult": { - "code": "EXTEND_FOOTPRINT_TTL_SUCCESS" + "type": "INVOKE_HOST_FUNCTION", + "invokeHostFunctionResult": { + "code": "INVOKE_HOST_FUNCTION_TRAPPED" } } } @@ -1456,13 +1488,13 @@ { "type": "LEDGER_ENTRY_STATE", "state": { - "lastModifiedLedgerSeq": 9, + "lastModifiedLedgerSeq": 11, "data": { "type": "ACCOUNT", "account": { - "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", + "accountID": "GAM4XNEHJUHN7VE3ZWJI23R2WS3SJS2BTUHZAC6XICXLXO2HPX4QI2IR", "balance": 400000000, - "seqNum": 38654705664, + "seqNum": 47244640256, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1486,9 +1518,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", - "balance": 398999900, - "seqNum": 38654705664, + "accountID": "GAM4XNEHJUHN7VE3ZWJI23R2WS3SJS2BTUHZAC6XICXLXO2HPX4QI2IR", + "balance": 399898381, + "seqNum": 47244640256, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1520,9 +1552,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", - "balance": 398999900, - "seqNum": 38654705664, + "accountID": "GAM4XNEHJUHN7VE3ZWJI23R2WS3SJS2BTUHZAC6XICXLXO2HPX4QI2IR", + "balance": 399898381, + "seqNum": 47244640256, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1546,9 +1578,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", - "balance": 398999900, - "seqNum": 38654705665, + "accountID": "GAM4XNEHJUHN7VE3ZWJI23R2WS3SJS2BTUHZAC6XICXLXO2HPX4QI2IR", + "balance": 399898381, + "seqNum": 47244640257, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1590,76 +1622,7 @@ } } ], - "operations": [ - { - "changes": [ - { - "type": "LEDGER_ENTRY_STATE", - "state": { - "lastModifiedLedgerSeq": 6, - "data": { - "type": "TTL", - "ttl": { - "keyHash": "091ddece931776a53f93869b82c24e132cc12d00d961fac09bc3b9cb9021c62d", - "liveUntilLedgerSeq": 10006 - } - }, - "ext": { - "v": 0 - } - } - }, - { - "type": "LEDGER_ENTRY_UPDATED", - "updated": { - "lastModifiedLedgerSeq": 28, - "data": { - "type": "TTL", - "ttl": { - "keyHash": "091ddece931776a53f93869b82c24e132cc12d00d961fac09bc3b9cb9021c62d", - "liveUntilLedgerSeq": 10028 - } - }, - "ext": { - "v": 0 - } - } - }, - { - "type": "LEDGER_ENTRY_STATE", - "state": { - "lastModifiedLedgerSeq": 6, - "data": { - "type": "TTL", - "ttl": { - "keyHash": "60313f9b273db0b14c3e503cf6cc152dd14a0c57e5e81a23e86b4e27a23a2c06", - "liveUntilLedgerSeq": 10006 - } - }, - "ext": { - "v": 0 - } - } - }, - { - "type": "LEDGER_ENTRY_UPDATED", - "updated": { - "lastModifiedLedgerSeq": 28, - "data": { - "type": "TTL", - "ttl": { - "keyHash": "60313f9b273db0b14c3e503cf6cc152dd14a0c57e5e81a23e86b4e27a23a2c06", - "liveUntilLedgerSeq": 10028 - } - }, - "ext": { - "v": 0 - } - } - } - ] - } - ], + "operations": [], "txChangesAfter": [ { "type": "LEDGER_ENTRY_STATE", @@ -1668,9 +1631,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", - "balance": 398999900, - "seqNum": 38654705665, + "accountID": "GAM4XNEHJUHN7VE3ZWJI23R2WS3SJS2BTUHZAC6XICXLXO2HPX4QI2IR", + "balance": 399898381, + "seqNum": 47244640257, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1718,9 +1681,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", - "balance": 399939434, - "seqNum": 38654705665, + "accountID": "GAM4XNEHJUHN7VE3ZWJI23R2WS3SJS2BTUHZAC6XICXLXO2HPX4QI2IR", + "balance": 399938381, + "seqNum": 47244640257, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1778,18 +1741,18 @@ }, { "result": { - "transactionHash": "16e22c43e107e363ba604b2b458eb213b70c0a3df283042ec1722cdc351118e3", + "transactionHash": "742cd3385bedce54d59e1d9751a34e91beafeb9f6afcbded05f2e016e8b51b2c", "result": { - "feeCharged": 42963, + "feeCharged": 51555, "result": { - "code": "txFAILED", + "code": "txSUCCESS", "results": [ { "code": "opINNER", "tr": { - "type": "INVOKE_HOST_FUNCTION", - "invokeHostFunctionResult": { - "code": "INVOKE_HOST_FUNCTION_RESOURCE_LIMIT_EXCEEDED" + "type": "RESTORE_FOOTPRINT", + "restoreFootprintResult": { + "code": "RESTORE_FOOTPRINT_SUCCESS" } } } @@ -1804,13 +1767,13 @@ { "type": "LEDGER_ENTRY_STATE", "state": { - "lastModifiedLedgerSeq": 12, + "lastModifiedLedgerSeq": 8, "data": { "type": "ACCOUNT", "account": { - "accountID": "GA2NXNEE2MHWGQP5XXACPYG2BDZFPKGYPFNST5V3ZZN75NSLQAEXX7CU", + "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", "balance": 400000000, - "seqNum": 51539607552, + "seqNum": 34359738368, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1834,9 +1797,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GA2NXNEE2MHWGQP5XXACPYG2BDZFPKGYPFNST5V3ZZN75NSLQAEXX7CU", - "balance": 398956045, - "seqNum": 51539607552, + "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", + "balance": 398999900, + "seqNum": 34359738368, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1868,9 +1831,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GA2NXNEE2MHWGQP5XXACPYG2BDZFPKGYPFNST5V3ZZN75NSLQAEXX7CU", - "balance": 398956045, - "seqNum": 51539607552, + "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", + "balance": 398999900, + "seqNum": 34359738368, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1894,9 +1857,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GA2NXNEE2MHWGQP5XXACPYG2BDZFPKGYPFNST5V3ZZN75NSLQAEXX7CU", - "balance": 398956045, - "seqNum": 51539607553, + "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", + "balance": 398999900, + "seqNum": 34359738369, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1938,7 +1901,44 @@ } } ], - "operations": [], + "operations": [ + { + "changes": [ + { + "type": "LEDGER_ENTRY_STATE", + "state": { + "lastModifiedLedgerSeq": 7, + "data": { + "type": "TTL", + "ttl": { + "keyHash": "4791962cd1e2c7b8f8af3f96514f9777f0156a48261fb885a571a7f69b33a058", + "liveUntilLedgerSeq": 26 + } + }, + "ext": { + "v": 0 + } + } + }, + { + "type": "LEDGER_ENTRY_UPDATED", + "updated": { + "lastModifiedLedgerSeq": 28, + "data": { + "type": "TTL", + "ttl": { + "keyHash": "4791962cd1e2c7b8f8af3f96514f9777f0156a48261fb885a571a7f69b33a058", + "liveUntilLedgerSeq": 47 + } + }, + "ext": { + "v": 0 + } + } + } + ] + } + ], "txChangesAfter": [ { "type": "LEDGER_ENTRY_STATE", @@ -1947,9 +1947,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GA2NXNEE2MHWGQP5XXACPYG2BDZFPKGYPFNST5V3ZZN75NSLQAEXX7CU", - "balance": 398956045, - "seqNum": 51539607553, + "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", + "balance": 398999900, + "seqNum": 34359738369, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -1997,9 +1997,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GA2NXNEE2MHWGQP5XXACPYG2BDZFPKGYPFNST5V3ZZN75NSLQAEXX7CU", - "balance": 399957037, - "seqNum": 51539607553, + "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", + "balance": 399948445, + "seqNum": 34359738369, "numSubEntries": 0, "inflationDest": null, "flags": 0, diff --git a/src/testdata/ledger-close-meta-v1-protocol-23.json b/src/testdata/ledger-close-meta-v1-protocol-23.json index 85b97a53ac..164bfe461b 100644 --- a/src/testdata/ledger-close-meta-v1-protocol-23.json +++ b/src/testdata/ledger-close-meta-v1-protocol-23.json @@ -6,24 +6,24 @@ "v": 0 }, "ledgerHeader": { - "hash": "b829e9a443e77642a4dd7cdcfc76a021770ca0d6ae862d9e50fabd9b842f95d0", + "hash": "df0caa7841395c80b0f7b3dec4f13e5058a406fd0cb0959375c6830ea311e32e", "header": { "ledgerVersion": 23, - "previousLedgerHash": "dab1a34dcf3dd9d44f7685628d3d23e18f236f8d0f7e5681bb41c32f4facf23b", + "previousLedgerHash": "238186da4a6e457877adec84246cbb50dd054cc81cd913ef97cffb492ff6ac74", "scpValue": { - "txSetHash": "0961b0ad46b7ca0f1160567bf513ddcec87e6f8b46267bed5f67330ac9b0835f", + "txSetHash": "6755cddd3f4b967d42930b3eb84bbd991ccf2f0ddec05fc85f24e77dcd6746d7", "closeTime": 0, "upgrades": [], "ext": { "v": "STELLAR_VALUE_SIGNED", "lcValueSignature": { "nodeID": "GDDOUW25MRFLNXQMN3OODP6JQEXSGLMHAFZV4XPQ2D3GA4QFIDMEJG2O", - "signature": "3414f4512273da4c9782cea39a8019fe99c79e764f41b225ad8bbaf93f65cee4d15981291a91fcba86a9768353b857866d1a27bf755a3498aa7743a647615703" + "signature": "2d46696da63265a28b3055ccc9cdb2aa32d1008f4732f130dcda8842235a2419ac5432290892243f636563e42fa9b3829f31b8daef8b1e1142de52a770c3130f" } } }, "txSetResultHash": "249b974bacf8b5c4a8f0b5598194c1b9eca64af0b5c1506daa871c1533b6baac", - "bucketListHash": "39e4ca7061db01c89f4f6aea5c98cf3a07c33290d8cbdf5c35fc3e47f41310fd", + "bucketListHash": "5ba9bbd81fb831cf30cf89b221629d376e563373bc6b56e1c44e82adca5e427f", "ledgerSeq": 7, "totalCoins": 1000000000000000000, "feePool": 800, @@ -49,7 +49,7 @@ "txSet": { "v": 1, "v1TxSet": { - "previousLedgerHash": "dab1a34dcf3dd9d44f7685628d3d23e18f236f8d0f7e5681bb41c32f4facf23b", + "previousLedgerHash": "238186da4a6e457877adec84246cbb50dd054cc81cd913ef97cffb492ff6ac74", "phases": [ { "v": 0, diff --git a/src/transactions/FeeBumpTransactionFrame.cpp b/src/transactions/FeeBumpTransactionFrame.cpp index 44a55e5ea9..975ed188c3 100644 --- a/src/transactions/FeeBumpTransactionFrame.cpp +++ b/src/transactions/FeeBumpTransactionFrame.cpp @@ -55,6 +55,12 @@ FeeBumpTransactionFrame::sorobanResources() const } #ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION +bool +FeeBumpTransactionFrame::hasSorobanProofs() const +{ + return mInnerTx->hasSorobanProofs(); +} + xdr::xvector const& FeeBumpTransactionFrame::sorobanProofs() const { diff --git a/src/transactions/FeeBumpTransactionFrame.h b/src/transactions/FeeBumpTransactionFrame.h index 6b8fcda749..e1c32bbfaf 100644 --- a/src/transactions/FeeBumpTransactionFrame.h +++ b/src/transactions/FeeBumpTransactionFrame.h @@ -141,6 +141,7 @@ class FeeBumpTransactionFrame : public TransactionFrameBase virtual bool XDRProvidesValidFee() const override; #ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION + bool hasSorobanProofs() const override; xdr::xvector const& sorobanProofs() const override; #endif }; diff --git a/src/transactions/InvokeHostFunctionOpFrame.cpp b/src/transactions/InvokeHostFunctionOpFrame.cpp index d8ce55adff..e0d5b78c57 100644 --- a/src/transactions/InvokeHostFunctionOpFrame.cpp +++ b/src/transactions/InvokeHostFunctionOpFrame.cpp @@ -408,20 +408,12 @@ InvokeHostFunctionOpFrame::doApply( ltx.getHeader().ledgerVersion, Bucket::FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION)) { + auto hotArchive = + bm.getSearchableHotArchiveBucketListSnapshot(); + auto hotArchiveEntry = hotArchive->load(lk); - std::shared_ptr hotArchiveEntry = - nullptr; -#ifdef BUILD_TESTS - if (appConfig.isUsingBucketListDB()) -#endif - { - auto hotArchive = - bm.getSearchableHotArchiveBucketListSnapshot(); - hotArchiveEntry = hotArchive->load(lk); - } - - // Entries require proofs only if an ARCHIVED entry exists - // in the hot archive + // Entries require proofs only if an ARCHIVED entry + // exists in the hot archive if (hotArchiveEntry && hotArchiveEntry->type() != HOT_ARCHIVE_DELETED) { @@ -793,7 +785,8 @@ InvokeHostFunctionOpFrame::doCheckValidForSoroban( ledgerVersion, Bucket::FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION)) { - if (!checkCreationProofValidity(mParentTx.sorobanProofs())) + if (!mParentTx.hasSorobanProofs() || + !checkCreationProofValidity(mParentTx.sorobanProofs())) { sorobanData.pushValidationTimeDiagnosticError( appConfig, SCE_VALUE, SCEC_INVALID_INPUT, diff --git a/src/transactions/RestoreFootprintOpFrame.cpp b/src/transactions/RestoreFootprintOpFrame.cpp index bf99978e62..2bd518837c 100644 --- a/src/transactions/RestoreFootprintOpFrame.cpp +++ b/src/transactions/RestoreFootprintOpFrame.cpp @@ -281,7 +281,8 @@ RestoreFootprintOpFrame::doCheckValidForSoroban( ledgerVersion, Bucket::FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION)) { - if (!checkRestorationProofValidity(mParentTx.sorobanProofs())) + if (!mParentTx.hasSorobanProofs() || + !checkRestorationProofValidity(mParentTx.sorobanProofs())) { sorobanData.pushValidationTimeDiagnosticError( appConfig, SCE_VALUE, SCEC_INVALID_INPUT, diff --git a/src/transactions/TransactionFrame.cpp b/src/transactions/TransactionFrame.cpp index aaa51ca2ec..7c74b951f9 100644 --- a/src/transactions/TransactionFrame.cpp +++ b/src/transactions/TransactionFrame.cpp @@ -428,10 +428,16 @@ TransactionFrame::sorobanResources() const } #ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION +bool +TransactionFrame::hasSorobanProofs() const +{ + return isSoroban() && mEnvelope.v1().tx.ext.sorobanData().ext.v() == 1; +} + xdr::xvector const& TransactionFrame::sorobanProofs() const { - releaseAssertOrThrow(isSoroban()); + releaseAssertOrThrow(hasSorobanProofs()); return mEnvelope.v1().tx.ext.sorobanData().ext.proofs(); } #endif @@ -1672,7 +1678,7 @@ TransactionFrame::applyOperations(SignatureChecker& signatureChecker, { processOpLedgerEntryChanges(op, changes); } - operationMetas.emplace_back(ltxOp.getChanges()); + operationMetas.emplace_back(changes); } if (txRes || diff --git a/src/transactions/TransactionFrame.h b/src/transactions/TransactionFrame.h index efa2f9a936..8745a0e227 100644 --- a/src/transactions/TransactionFrame.h +++ b/src/transactions/TransactionFrame.h @@ -288,6 +288,7 @@ class TransactionFrame : public TransactionFrameBase virtual bool XDRProvidesValidFee() const override; #ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION + bool hasSorobanProofs() const override; xdr::xvector const& sorobanProofs() const override; #endif diff --git a/src/transactions/TransactionFrameBase.h b/src/transactions/TransactionFrameBase.h index bba4859041..b14ab9dbf8 100644 --- a/src/transactions/TransactionFrameBase.h +++ b/src/transactions/TransactionFrameBase.h @@ -115,6 +115,7 @@ class TransactionFrameBase virtual bool XDRProvidesValidFee() const = 0; #ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION + virtual bool hasSorobanProofs() const = 0; virtual xdr::xvector const& sorobanProofs() const = 0; #endif }; diff --git a/src/transactions/test/InvokeHostFunctionTests.cpp b/src/transactions/test/InvokeHostFunctionTests.cpp index 191d14fa3b..a7202aadd3 100644 --- a/src/transactions/test/InvokeHostFunctionTests.cpp +++ b/src/transactions/test/InvokeHostFunctionTests.cpp @@ -1196,15 +1196,27 @@ TEST_CASE_VERSIONS("refund still happens on bad auth", "[tx][soroban]") auto a1PostTxBalance = a1.getBalance(); - bool afterV20 = protocolVersionStartsFrom( - getLclProtocolVersion(test.getApp()), ProtocolVersion::V_21); - - auto fee = afterV20 ? 62697 : 39288; + uint64_t txFeeWithRefund = 0; + if (protocolVersionStartsFrom(getLclProtocolVersion(test.getApp()), + ProtocolVersion::V_23)) + { + // Slightly larger TX size due to proofs + txFeeWithRefund = 62'706; + } + else if (protocolVersionStartsFrom(getLclProtocolVersion(test.getApp()), + ProtocolVersion::V_21)) + { + txFeeWithRefund = 62'697; + } + else + { + txFeeWithRefund = 39'288; + } // The initial fee charge is based on DEFAULT_TEST_RESOURCE_FEE, which // is 1'000'000, so the difference would be much higher if the refund // did not happen. - REQUIRE(a1PreTxBalance - a1PostTxBalance == fee); + REQUIRE(a1PreTxBalance - a1PostTxBalance == txFeeWithRefund); }); } @@ -1233,10 +1245,23 @@ TEST_CASE_VERSIONS("refund test with closeLedger", "[tx][soroban][feebump]") auto r = closeLedger(test.getApp(), {tx}); checkTx(0, r, txSUCCESS); - bool afterV20 = protocolVersionStartsFrom( - getLclProtocolVersion(test.getApp()), ProtocolVersion::V_21); + uint64_t txFeeWithRefund = 0; + if (protocolVersionStartsFrom(getLclProtocolVersion(test.getApp()), + ProtocolVersion::V_23)) + { + // Slightly larger TX size due to proofs + txFeeWithRefund = 82'762; + } + else if (protocolVersionStartsFrom(getLclProtocolVersion(test.getApp()), + ProtocolVersion::V_21)) + { + txFeeWithRefund = 82'753; + } + else + { + txFeeWithRefund = 59'344; + } - auto txFeeWithRefund = afterV20 ? 82'753 : 59'344; REQUIRE(a1.getBalance() == a1StartingBalance - txFeeWithRefund); // DEFAULT_TEST_RESOURCE_FEE is added onto the calculated soroban @@ -1291,7 +1316,23 @@ TEST_CASE_VERSIONS("refund is sent to fee-bump source", bool afterV20 = protocolVersionStartsFrom( getLclProtocolVersion(test.getApp()), ProtocolVersion::V_21); - auto const txFeeWithRefund = afterV20 ? 82'853 : 59'444; + uint64_t txFeeWithRefund = 0; + if (protocolVersionStartsFrom(getLclProtocolVersion(test.getApp()), + ProtocolVersion::V_23)) + { + // Slightly larger TX size due to proofs + txFeeWithRefund = 82'862; + } + else if (protocolVersionStartsFrom(getLclProtocolVersion(test.getApp()), + ProtocolVersion::V_21)) + { + txFeeWithRefund = 82'853; + } + else + { + txFeeWithRefund = 59'444; + } + auto const feeCharged = afterV20 ? txFeeWithRefund : 1'040'971; REQUIRE( @@ -2650,15 +2691,9 @@ TEST_CASE_VERSIONS("entry eviction", "[tx][soroban][archival]") REQUIRE(evicted); } +#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION SECTION("persistent entry meta") { - if (protocolVersionIsBefore( - cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION, - Bucket::FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION)) - { - return; - } - auto persistentInvocation = client.getContract().prepareInvocation( "put_persistent", {makeSymbolSCVal("key"), makeU64SCVal(123)}, client.writeKeySpec("key", ContractDataDurability::PERSISTENT)); @@ -2686,64 +2721,164 @@ TEST_CASE_VERSIONS("entry eviction", "[tx][soroban][archival]") closeLedgerOn(test.getApp(), i, 2, 1, 2016); } + if (protocolVersionStartsFrom( + cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION, + Bucket::FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION)) { LedgerTxn ltx(test.getApp().getLedgerTxnRoot()); REQUIRE(!ltx.load(persistentKey)); } - XDRInputFileStream in; - in.open(metaPath); - LedgerCloseMeta lcm; - bool evicted = false; - while (in.readOne(lcm)) + SECTION("eviction meta") { - REQUIRE(lcm.v() == 1); - if (lcm.v1().ledgerHeader.header.ledgerSeq == evictionLedger) + XDRInputFileStream in; + in.open(metaPath); + LedgerCloseMeta lcm; + bool evicted = false; + while (in.readOne(lcm)) { - // Only support persistent eviction meta >= p23 - if (protocolVersionStartsFrom( - cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION, - Bucket:: - FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION)) + REQUIRE(lcm.v() == 1); + if (lcm.v1().ledgerHeader.header.ledgerSeq == + evictionLedger) { - // TLL should be in "deleted" key section (called - // evictedTemporaryLedgerKeys for legacy reasons). - REQUIRE(lcm.v1().evictedTemporaryLedgerKeys.size() == + // Only support persistent eviction meta >= p23 + if (protocolVersionStartsFrom( + cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION, + Bucket:: + FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION)) + { + // TLL should be in "deleted" key section (called + // evictedTemporaryLedgerKeys for legacy reasons). + REQUIRE( + lcm.v1().evictedTemporaryLedgerKeys.size() == 1); - REQUIRE(lcm.v1().evictedTemporaryLedgerKeys.front() == + REQUIRE( + lcm.v1().evictedTemporaryLedgerKeys.front() == getTTLKey(persistentKey)); - REQUIRE( - lcm.v1().evictedPersistentLedgerEntries.size() == - 1); - REQUIRE( - lcm.v1().evictedPersistentLedgerEntries.front() == - persistentLE); - evicted = true; + REQUIRE( + lcm.v1() + .evictedPersistentLedgerEntries.size() == + 1); + REQUIRE( + lcm.v1() + .evictedPersistentLedgerEntries.front() == + persistentLE); + evicted = true; + } + else + { + REQUIRE( + lcm.v1().evictedTemporaryLedgerKeys.empty()); + REQUIRE( + lcm.v1() + .evictedPersistentLedgerEntries.empty()); + evicted = false; + } + + break; } - else + } + + if (protocolVersionStartsFrom( + cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION, + Bucket::FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION)) + { + REQUIRE(evicted); + } + else + { + REQUIRE(!evicted); + } + } + + SECTION("Restoration Meta") + { + test.invokeRestoreOp({persistentKey}, 20'048); + auto targetRestorationLedger = test.getLCLSeq(); + + XDRInputFileStream in; + in.open(metaPath); + LedgerCloseMeta lcm; + bool restoreMeta = false; + + LedgerKeySet keysToRestore = {persistentKey, + getTTLKey(persistentKey)}; + while (in.readOne(lcm)) + { + REQUIRE(lcm.v() == 1); + if (lcm.v1().ledgerHeader.header.ledgerSeq == + targetRestorationLedger) { REQUIRE(lcm.v1().evictedTemporaryLedgerKeys.empty()); REQUIRE( lcm.v1().evictedPersistentLedgerEntries.empty()); - evicted = false; - } - break; + REQUIRE(lcm.v1().txProcessing.size() == 1); + auto txMeta = lcm.v1().txProcessing.front(); + REQUIRE( + txMeta.txApplyProcessing.v3().operations.size() == + 1); + + REQUIRE(txMeta.txApplyProcessing.v3() + .operations[0] + .changes.size() == 2); + for (auto const& change : txMeta.txApplyProcessing.v3() + .operations[0] + .changes) + { + + // Only support persistent eviction meta >= p23 + LedgerKey lk; + if (protocolVersionStartsFrom( + cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION, + Bucket:: + FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION)) + { + REQUIRE(change.type() == + LedgerEntryChangeType:: + LEDGER_ENTRY_RESTORED); + lk = LedgerEntryKey(change.restored()); + REQUIRE(keysToRestore.find(lk) != + keysToRestore.end()); + keysToRestore.erase(lk); + } + else + { + if (change.type() == + LedgerEntryChangeType::LEDGER_ENTRY_STATE) + { + lk = LedgerEntryKey(change.state()); + REQUIRE(lk == getTTLKey(persistentKey)); + keysToRestore.erase(lk); + } + else + { + REQUIRE(change.type() == + LedgerEntryChangeType:: + LEDGER_ENTRY_UPDATED); + lk = LedgerEntryKey(change.updated()); + REQUIRE(lk == getTTLKey(persistentKey)); + + // While we will see the TTL key twice, + // remove the TTL key in the path above and + // the persistent key here to make the check + // easier + keysToRestore.erase(persistentKey); + } + } + } + + restoreMeta = true; + break; + } } - } - if (protocolVersionStartsFrom( - cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION, - Bucket::FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION)) - { - REQUIRE(evicted); - } - else - { - REQUIRE(!evicted); + REQUIRE(restoreMeta); + REQUIRE(keysToRestore.empty()); } } +#endif SECTION( "Create temp entry with same key as an expired entry on eviction " @@ -2774,7 +2909,7 @@ TEST_CASE_VERSIONS("entry eviction", "[tx][soroban][archival]") } }; - test({20, 21, 22 + test({22 #ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION , 23 @@ -3103,7 +3238,7 @@ TEST_CASE("persistent entry archival filters", "[soroban][archival]") TEST_CASE("settings upgrade command line utils", "[tx][soroban][upgrades]") { VirtualClock clock; - auto cfg = getTestConfig(0, Config::TESTDB_IN_MEMORY_NO_OFFERS); + auto cfg = getTestConfig(0, Config::TESTDB_IN_MEMORY); cfg.ENABLE_SOROBAN_DIAGNOSTIC_EVENTS = true; auto app = createTestApplication(clock, cfg); auto root = TestAccount::createRoot(*app); @@ -3407,6 +3542,10 @@ TEST_CASE("settings upgrade command line utils", "[tx][soroban][upgrades]") sha256(xdr::xdr_to_opaque(app->getNetworkID(), ENVELOPE_TYPE_TX, txEnv.v1().tx)))); +#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION + txEnv.v1().tx.ext.sorobanData().ext.v(1); +#endif + auto const& rawTx = TransactionFrameBase::makeTransactionFromWire( app->getNetworkID(), txEnv); auto tx = TransactionTestFrame::fromTxFrame(rawTx); diff --git a/src/transactions/test/TransactionTestFrame.cpp b/src/transactions/test/TransactionTestFrame.cpp index 47b3f39fd5..2acc837431 100644 --- a/src/transactions/test/TransactionTestFrame.cpp +++ b/src/transactions/test/TransactionTestFrame.cpp @@ -330,6 +330,12 @@ TransactionTestFrame::sorobanResources() const } #ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION +bool +TransactionTestFrame::hasSorobanProofs() const +{ + return mTransactionFrame->hasSorobanProofs(); +} + xdr::xvector const& TransactionTestFrame::sorobanProofs() const { diff --git a/src/transactions/test/TransactionTestFrame.h b/src/transactions/test/TransactionTestFrame.h index 018bcb8d7e..7216f59e11 100644 --- a/src/transactions/test/TransactionTestFrame.h +++ b/src/transactions/test/TransactionTestFrame.h @@ -142,6 +142,7 @@ class TransactionTestFrame : public TransactionFrameBase } #ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION + bool hasSorobanProofs() const override; xdr::xvector const& sorobanProofs() const override; #endif };