Skip to content

Commit

Permalink
Remove Sorban bucket invariant special case
Browse files Browse the repository at this point in the history
  • Loading branch information
SirTyson committed Jul 27, 2023
1 parent 60a8c64 commit fadfcbe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 36 deletions.
45 changes: 10 additions & 35 deletions src/bucket/Bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -919,44 +919,19 @@ mergeCasesWithEqualKeys(MergeCounters& mc, BucketInputIterator& oi,

if (newEntry.type() == INITENTRY)
{
// For all entries except TEMPORARY entries, the only legal new-is-INIT
// case is merging a delete+create to an update. For TEMPORARY entries,
// an INIT entry may merge with another INIT entry as long as the older
// INIT entry is expired. Because merging occurs on a background thread
// and different validators may start a merge at different times, it is
// not possible to accurately know the current ledgerSeq or to know if a
// given TEMPORARY entry has expired. Due to this, we don't check this
// invariant for TEMPORARY entries

// TODO: Add invariant check for TEMPORARY entries based on ledgerSeq
// when the given bucket started to merge
// The only legal new-is-INIT case is merging a delete+create to an
// update.
if (oldEntry.type() != DEADENTRY)
{
#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION
if (auto type = oldEntry.liveEntry().data.type();
type == CONTRACT_DATA || type == CONTRACT_CODE)
{
// Treat merge as if old entry did not exist
++mc.mNewEntriesDefaultAccepted;
Bucket::checkProtocolLegality(newEntry, protocolVersion);
countNewEntryType(mc, newEntry);
maybePut(out, newEntry, shadowIterators,
keepShadowedLifecycleEntries, mc);
}
else
#endif
throw std::runtime_error(
"Malformed bucket: old non-DEAD + new INIT.");
}
else
{
BucketEntry newLive;
newLive.type(LIVEENTRY);
newLive.liveEntry() = newEntry.liveEntry();
++mc.mNewInitEntriesMergedWithOldDead;
maybePut(out, newLive, shadowIterators,
keepShadowedLifecycleEntries, mc);
throw std::runtime_error(
"Malformed bucket: old non-DEAD + new INIT.");
}
BucketEntry newLive;
newLive.type(LIVEENTRY);
newLive.liveEntry() = newEntry.liveEntry();
++mc.mNewInitEntriesMergedWithOldDead;
maybePut(out, newLive, shadowIterators, keepShadowedLifecycleEntries,
mc);
}
else if (oldEntry.type() == INITENTRY)
{
Expand Down
2 changes: 1 addition & 1 deletion src/herder/test/UpgradesTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ TEST_CASE("config upgrades applied to ledger", "[soroban][upgrades]")
LedgerKey key(CONFIG_SETTING);
key.configSetting().configSettingID =
ConfigSettingID::CONFIG_SETTING_CONTRACT_LEDGER_COST_V0;
auto le = ltx2.loadWithoutRecord(key, false).current();
auto le = ltx2.loadWithoutRecord(key).current();
auto configSetting = le.data.configSetting();
configSetting.contractLedgerCost().txMaxWriteBytes = upgradeVal;

Expand Down

0 comments on commit fadfcbe

Please sign in to comment.