Skip to content

Commit 036c3fc

Browse files
authored
Fixed inter ledger restore bug in p23 (#4639)
# Description Resolves #4638 Fixes a bug where an entry restored from the Hot Archive BucketList could not be used by later transactions applied in the same ledger. # Checklist - [x] Reviewed the [contributing](https://github.com/stellar/stellar-core/blob/master/CONTRIBUTING.md#submitting-changes) document - [x] Rebased on top of master (no merge commits) - [x] Ran `clang-format` v8.0.0 (via `make format` or the Visual Studio extension) - [x] Compiles - [x] Ran all tests - [ ] If change impacts performance, include supporting evidence per the [performance document](https://github.com/stellar/stellar-core/blob/master/performance-eval/performance-eval.md)
2 parents 39caa20 + 3c7360a commit 036c3fc

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

src/transactions/InvokeHostFunctionOpFrame.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,11 @@ InvokeHostFunctionOpFrame::doApply(
408408
// If ttlLtxe doesn't exist, this is a new Soroban entry
409409
// Starting in protocol 23, we must check the Hot Archive for
410410
// new keys. If a new key is actually archived, fail the op.
411-
if (isPersistentEntry(lk) &&
412-
protocolVersionStartsFrom(
413-
ltx.getHeader().ledgerVersion,
414-
HotArchiveBucket::
415-
FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION))
411+
else if (isPersistentEntry(lk) &&
412+
protocolVersionStartsFrom(
413+
ltx.getHeader().ledgerVersion,
414+
HotArchiveBucket::
415+
FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION))
416416
{
417417
auto archiveEntry = hotArchive->load(lk);
418418
if (archiveEntry)

src/transactions/test/InvokeHostFunctionTests.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3124,6 +3124,37 @@ TEST_CASE("persistent entry archival", "[tx][soroban][archival]")
31243124
// Restored entries are deleted from Hot Archive
31253125
REQUIRE(!hotArchive->load(lk));
31263126
}
3127+
3128+
SECTION("key accessible after restore in same ledger")
3129+
{
3130+
auto writeSrcAccount = test.getRoot().create("src", 500000000);
3131+
3132+
SorobanResources restoreResources;
3133+
restoreResources.footprint.readWrite = {lk};
3134+
restoreResources.instructions = 0;
3135+
restoreResources.readBytes = 10'000;
3136+
restoreResources.writeBytes = 10'000;
3137+
3138+
auto resourceFee = 300'000 + 40'000;
3139+
auto restoreTx =
3140+
test.createRestoreTx(restoreResources, 1'000, resourceFee);
3141+
3142+
auto writeInvocation = client.getContract().prepareInvocation(
3143+
"put_persistent", {makeSymbolSCVal("key"), makeU64SCVal(200)},
3144+
client.writeKeySpec("key", ContractDataDurability::PERSISTENT));
3145+
3146+
auto writeTx =
3147+
writeInvocation.withExactNonRefundableResourceFee().createTx(
3148+
&writeSrcAccount);
3149+
3150+
closeLedger(test.getApp(), {restoreTx, writeTx},
3151+
/*strictOrder=*/true);
3152+
3153+
// Restore should succeed and entry value should be updated since
3154+
// writeTx comes after restore
3155+
REQUIRE(test.isEntryLive(lk, test.getLCLSeq()));
3156+
client.get("key", ContractDataDurability::PERSISTENT, 200);
3157+
}
31273158
};
31283159

31293160
SECTION("eviction")

test-tx-meta-baseline-next/InvokeHostFunctionTests.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,8 +1344,10 @@
13441344
"bKDF6V5IzTo=",
13451345
"bKDF6V5IzTo="
13461346
],
1347-
"persistent entry archival|eviction" : [ "bKDF6V5IzTo=", "bKDF6V5IzTo=" ],
1348-
"persistent entry archival|expiration without eviction" : [ "bKDF6V5IzTo=", "bKDF6V5IzTo=" ],
1347+
"persistent entry archival|eviction" : [ "bKDF6V5IzTo=", "bKDF6V5IzTo=", "bKDF6V5IzTo=" ],
1348+
"persistent entry archival|eviction|key accessible after restore in same ledger" : [ "iLiZOFVcRzA=" ],
1349+
"persistent entry archival|expiration without eviction" : [ "bKDF6V5IzTo=", "bKDF6V5IzTo=", "bKDF6V5IzTo=" ],
1350+
"persistent entry archival|expiration without eviction|key accessible after restore in same ledger" : [ "iLiZOFVcRzA=" ],
13491351
"refund account merged" : [ "bKDF6V5IzTo=", "398Rd+u+jdE=", "b4KxXJCxvM0=", "7/h1q7KjqKA=" ],
13501352
"refund is sent to fee-bump source|protocol version 20" : [ "bKDF6V5IzTo=", "JRiUwIP1h2Q=", "LyDINL0VaLk=" ],
13511353
"refund is sent to fee-bump source|protocol version 21" : [ "bKDF6V5IzTo=", "JRiUwIP1h2Q=", "LyDINL0VaLk=" ],

0 commit comments

Comments
 (0)