Skip to content

Commit

Permalink
Fixed inter ledger restore bug in p23 (#4639)
Browse files Browse the repository at this point in the history
# 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)
  • Loading branch information
graydon authored Feb 4, 2025
2 parents 39caa20 + 3c7360a commit 036c3fc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/transactions/InvokeHostFunctionOpFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,11 @@ InvokeHostFunctionOpFrame::doApply(
// If ttlLtxe doesn't exist, this is a new Soroban entry
// Starting in protocol 23, we must check the Hot Archive for
// new keys. If a new key is actually archived, fail the op.
if (isPersistentEntry(lk) &&
protocolVersionStartsFrom(
ltx.getHeader().ledgerVersion,
HotArchiveBucket::
FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION))
else if (isPersistentEntry(lk) &&
protocolVersionStartsFrom(
ltx.getHeader().ledgerVersion,
HotArchiveBucket::
FIRST_PROTOCOL_SUPPORTING_PERSISTENT_EVICTION))
{
auto archiveEntry = hotArchive->load(lk);
if (archiveEntry)
Expand Down
31 changes: 31 additions & 0 deletions src/transactions/test/InvokeHostFunctionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3124,6 +3124,37 @@ TEST_CASE("persistent entry archival", "[tx][soroban][archival]")
// Restored entries are deleted from Hot Archive
REQUIRE(!hotArchive->load(lk));
}

SECTION("key accessible after restore in same ledger")
{
auto writeSrcAccount = test.getRoot().create("src", 500000000);

SorobanResources restoreResources;
restoreResources.footprint.readWrite = {lk};
restoreResources.instructions = 0;
restoreResources.readBytes = 10'000;
restoreResources.writeBytes = 10'000;

auto resourceFee = 300'000 + 40'000;
auto restoreTx =
test.createRestoreTx(restoreResources, 1'000, resourceFee);

auto writeInvocation = client.getContract().prepareInvocation(
"put_persistent", {makeSymbolSCVal("key"), makeU64SCVal(200)},
client.writeKeySpec("key", ContractDataDurability::PERSISTENT));

auto writeTx =
writeInvocation.withExactNonRefundableResourceFee().createTx(
&writeSrcAccount);

closeLedger(test.getApp(), {restoreTx, writeTx},
/*strictOrder=*/true);

// Restore should succeed and entry value should be updated since
// writeTx comes after restore
REQUIRE(test.isEntryLive(lk, test.getLCLSeq()));
client.get("key", ContractDataDurability::PERSISTENT, 200);
}
};

SECTION("eviction")
Expand Down
6 changes: 4 additions & 2 deletions test-tx-meta-baseline-next/InvokeHostFunctionTests.json
Original file line number Diff line number Diff line change
Expand Up @@ -1344,8 +1344,10 @@
"bKDF6V5IzTo=",
"bKDF6V5IzTo="
],
"persistent entry archival|eviction" : [ "bKDF6V5IzTo=", "bKDF6V5IzTo=" ],
"persistent entry archival|expiration without eviction" : [ "bKDF6V5IzTo=", "bKDF6V5IzTo=" ],
"persistent entry archival|eviction" : [ "bKDF6V5IzTo=", "bKDF6V5IzTo=", "bKDF6V5IzTo=" ],
"persistent entry archival|eviction|key accessible after restore in same ledger" : [ "iLiZOFVcRzA=" ],
"persistent entry archival|expiration without eviction" : [ "bKDF6V5IzTo=", "bKDF6V5IzTo=", "bKDF6V5IzTo=" ],
"persistent entry archival|expiration without eviction|key accessible after restore in same ledger" : [ "iLiZOFVcRzA=" ],
"refund account merged" : [ "bKDF6V5IzTo=", "398Rd+u+jdE=", "b4KxXJCxvM0=", "7/h1q7KjqKA=" ],
"refund is sent to fee-bump source|protocol version 20" : [ "bKDF6V5IzTo=", "JRiUwIP1h2Q=", "LyDINL0VaLk=" ],
"refund is sent to fee-bump source|protocol version 21" : [ "bKDF6V5IzTo=", "JRiUwIP1h2Q=", "LyDINL0VaLk=" ],
Expand Down

0 comments on commit 036c3fc

Please sign in to comment.