Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions src/ledger/ImmutableLedgerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ CheckValidLedgerViewWrapper::CheckValidLedgerViewWrapper(
{
}

CheckValidLedgerViewWrapper::CheckValidLedgerViewWrapper(
std::unique_ptr<AbstractLedgerView const> getter)
: mGetter(std::move(getter))
{
}

LedgerHeaderWrapper
CheckValidLedgerViewWrapper::getLedgerHeader() const
{
Expand Down Expand Up @@ -356,6 +362,66 @@ ImmutableLedgerView::executeWithMaybeInnerSnapshot(
"ImmutableLedgerView has no nested snapshots");
}

SorobanPreApplyLedgerView::SorobanPreApplyLedgerView(
std::shared_ptr<LedgerHeader const> header,
UpdatedEntryGetter getUpdatedEntry, ApplyLedgerView const& lclView)
: mHeader(std::move(header))
, mGetUpdatedEntry(std::move(getUpdatedEntry))
, mLclView(lclView)
{
releaseAssert(mGetUpdatedEntry);
}

LedgerHeaderWrapper
SorobanPreApplyLedgerView::getLedgerHeader() const
{
return LedgerHeaderWrapper(mHeader);
}

LedgerEntryWrapper
SorobanPreApplyLedgerView::getAccount(AccountID const& account) const
{
return load(accountKey(account));
}

LedgerEntryWrapper
SorobanPreApplyLedgerView::getAccount(LedgerHeaderWrapper const& header,
TransactionFrame const& tx) const
{
return getAccount(tx.getSourceID());
}

LedgerEntryWrapper
SorobanPreApplyLedgerView::getAccount(LedgerHeaderWrapper const& header,
TransactionFrame const& tx,
AccountID const& accountID) const
{
return getAccount(accountID);
}
Comment thread
dmkozh marked this conversation as resolved.

LedgerEntryWrapper
SorobanPreApplyLedgerView::load(LedgerKey const& key) const
{
auto updatedEntry = mGetUpdatedEntry(key);
if (updatedEntry)
{
// Modified in this ledger, so this is the authoritative version.
// A null entry means it has been deleted.
return LedgerEntryWrapper(*updatedEntry);
}
// Not modified in this ledger, so the last closed ledger snapshot is
// up to date.
return LedgerEntryWrapper(mLclView.loadLiveEntry(key));
}

void
SorobanPreApplyLedgerView::executeWithMaybeInnerSnapshot(
std::function<void(CheckValidLedgerViewWrapper const& ledgerView)> f) const
{
throw std::runtime_error("SorobanPreApplyLedgerView::"
"executeWithMaybeInnerSnapshot is not supported");
}

// === Live BucketList wrapper methods ===

std::shared_ptr<LedgerEntry const>
Expand Down
48 changes: 48 additions & 0 deletions src/ledger/ImmutableLedgerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ledger/NetworkConfig.h"
#include "util/NonCopyable.h"
#include <functional>
#include <optional>
#include <variant>

namespace stellar
Expand Down Expand Up @@ -219,6 +220,51 @@ class ApplyLedgerView : private ImmutableLedgerView,
using ImmutableLedgerView::scanLiveEntriesOfType;
};

// A ledger view used by the read-only phase of the Soroban pre-apply.
//
// It's a thin wrapper around the entries updated so far in the current ledger,
// and the LCL view, which allows the pre-apply phase to observe the changes
// that happened in the classic phase.
//
// Lookups are first attempted among the updated entries, and only then in the
// LCL view.
class SorobanPreApplyLedgerView : public AbstractLedgerView
{
public:
// A function for retrieving a ledger entry by key from an incomprehensive
// set of ledger entries (i.e. the entries that have been updated so far in
// the ledger).
// `nullopt` represents that the entry is not present in the updated set.
// When optional is non-nullopt, `nullptr` entry represents a deleted entry,
// and a non-null `shared_ptr` represents an existing updated entry.
using UpdatedEntryGetter =
Comment thread
dmkozh marked this conversation as resolved.
std::function<std::optional<std::shared_ptr<LedgerEntry const>>(
LedgerKey const&)>;

// Creates a view from the provided LCL view and a getter for the entries
// that have been updated so far in the ledger.
SorobanPreApplyLedgerView(std::shared_ptr<LedgerHeader const> header,
UpdatedEntryGetter getUpdatedEntry,
ApplyLedgerView const& lclView);

LedgerHeaderWrapper getLedgerHeader() const override;
LedgerEntryWrapper getAccount(AccountID const& account) const override;
LedgerEntryWrapper getAccount(LedgerHeaderWrapper const& header,
TransactionFrame const& tx) const override;
LedgerEntryWrapper getAccount(LedgerHeaderWrapper const& header,
TransactionFrame const& tx,
AccountID const& accountID) const override;
LedgerEntryWrapper load(LedgerKey const& key) const override;
void executeWithMaybeInnerSnapshot(
std::function<void(CheckValidLedgerViewWrapper const&)> f)
const override;

private:
std::shared_ptr<LedgerHeader const> mHeader;
UpdatedEntryGetter mGetUpdatedEntry;
ApplyLedgerView mLclView;
};

// A helper class to create and query read-only snapshots
// Automatically decides whether to create a BucketList (recommended), or SQL
// snapshot (deprecated, but currently supported)
Expand All @@ -235,6 +281,8 @@ class CheckValidLedgerViewWrapper : public NonMovableOrCopyable
CheckValidLedgerViewWrapper(AbstractLedgerTxn& ltx);
CheckValidLedgerViewWrapper(Application& app);
explicit CheckValidLedgerViewWrapper(ImmutableLedgerView const& ledgerView);
explicit CheckValidLedgerViewWrapper(
std::unique_ptr<AbstractLedgerView const> getter);
#ifdef BUILD_TESTS
// Set by overlay-only mode call sites so commonValid skips the seqnum
// equality check: on-disk seqnums are frozen at genesis while
Expand Down
26 changes: 16 additions & 10 deletions src/ledger/InternalLedgerEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ InternalLedgerKey::makeMaxSeqNumToApplyKey(AccountID const& sourceAccount)
InternalLedgerKey&
InternalLedgerKey::operator=(InternalLedgerKey const& glk)
{
if (this == &glk)
{
return *this;
}

type(glk.type());
assign(glk);
return *this;
Expand All @@ -191,9 +196,9 @@ InternalLedgerKey::~InternalLedgerKey()
size_t
InternalLedgerKey::hash() const
{
if (mHash != 0)
if (mHash)
{
return mHash;
return *mHash;
}
size_t res;
switch (type())
Expand Down Expand Up @@ -225,7 +230,6 @@ void
InternalLedgerKey::assign(InternalLedgerKey const& glk)
{
releaseAssert(glk.type() == mType);
mHash = glk.mHash;
switch (mType)
{
case InternalLedgerEntryType::LEDGER_ENTRY:
Expand All @@ -243,13 +247,13 @@ InternalLedgerKey::assign(InternalLedgerKey const& glk)
default:
abort();
}
mHash = glk.mHash;
}

void
InternalLedgerKey::assign(InternalLedgerKey&& glk)
{
releaseAssert(glk.type() == mType);
mHash = glk.mHash;
switch (mType)
{
case InternalLedgerEntryType::LEDGER_ENTRY:
Expand All @@ -267,6 +271,8 @@ InternalLedgerKey::assign(InternalLedgerKey&& glk)
default:
abort();
}
mHash = glk.mHash;
glk.mHash.reset();
}

void
Expand All @@ -289,7 +295,7 @@ InternalLedgerKey::construct()
default:
abort();
}
mHash = 0;
mHash.reset();
}

void
Expand All @@ -312,7 +318,7 @@ InternalLedgerKey::destruct()
default:
abort();
}
mHash = 0;
mHash.reset();
}

void
Expand Down Expand Up @@ -345,7 +351,7 @@ LedgerKey&
InternalLedgerKey::ledgerKeyRef()
{
checkDiscriminant(InternalLedgerEntryType::LEDGER_ENTRY);
mHash = 0;
mHash.reset();
return mLedgerKey;
}

Expand All @@ -360,7 +366,7 @@ SponsorshipKey&
InternalLedgerKey::sponsorshipKeyRef()
{
checkDiscriminant(InternalLedgerEntryType::SPONSORSHIP);
mHash = 0;
mHash.reset();
return mSponsorshipKey;
}

Expand All @@ -375,7 +381,7 @@ SponsorshipCounterKey&
InternalLedgerKey::sponsorshipCounterKeyRef()
{
checkDiscriminant(InternalLedgerEntryType::SPONSORSHIP_COUNTER);
mHash = 0;
mHash.reset();
return mSponsorshipCounterKey;
}

Expand All @@ -390,7 +396,7 @@ MaxSeqNumToApplyKey&
InternalLedgerKey::maxSeqNumToApplyKeyRef()
{
checkDiscriminant(InternalLedgerEntryType::MAX_SEQ_NUM_TO_APPLY);
mHash = 0;
mHash.reset();
return mMaxSeqNumToApplyKey;
}

Expand Down
3 changes: 2 additions & 1 deletion src/ledger/InternalLedgerEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "xdr/Stellar-ledger-entries.h"
#include "xdr/Stellar-ledger.h"
#include <optional>

namespace stellar
{
Expand Down Expand Up @@ -36,7 +37,7 @@ struct MaxSeqNumToApplyKey
class InternalLedgerKey
{
private:
size_t mutable mHash;
std::optional<size_t> mutable mHash;
InternalLedgerEntryType mType;
union
{
Expand Down
1 change: 1 addition & 0 deletions src/simulation/LoadGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,7 @@ GeneratedLoadConfig::copySorobanNetworkConfigToUpgradeConfig(

upgradeCfg.txMaxContractEventsSizeBytes =
updatedConfig.txMaxContractEventsSizeBytes();
upgradeCfg.feeContractEvents1KB = updatedConfig.feeContractEventsSize1KB();

upgradeCfg.ledgerMaxTransactionsSizeBytes =
updatedConfig.ledgerMaxTransactionSizesBytes();
Expand Down
5 changes: 5 additions & 0 deletions src/simulation/TxGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,11 @@ TxGenerator::getConfigUpgradeSetFromLoadConfig(
setting.contractEvents().txMaxContractEventsSizeBytes =
*upgradeCfg.txMaxContractEventsSizeBytes;
}
if (upgradeCfg.feeContractEvents1KB.has_value())
{
setting.contractEvents().feeContractEvents1KB =
*upgradeCfg.feeContractEvents1KB;
}
break;
case CONFIG_SETTING_CONTRACT_BANDWIDTH_V0:
if (upgradeCfg.ledgerMaxTransactionsSizeBytes.has_value())
Expand Down
1 change: 1 addition & 0 deletions src/simulation/TxGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct SorobanUpgradeConfig

// Contract events settings.
std::optional<uint32_t> txMaxContractEventsSizeBytes{};
std::optional<int64_t> feeContractEvents1KB{};

// Bandwidth related data settings for contracts
std::optional<uint32_t> ledgerMaxTransactionsSizeBytes{};
Expand Down
39 changes: 26 additions & 13 deletions src/transactions/FeeBumpTransactionFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,52 @@ FeeBumpTransactionFrame::FeeBumpTransactionFrame(
#endif

void
FeeBumpTransactionFrame::preParallelApply(
AppConnector& app, AbstractLedgerTxn& ltx, TransactionMetaBuilder& meta,
MutableTransactionResultBase& txResult,
FeeBumpTransactionFrame::preParallelApplyReadOnly(
AppConnector& app, CheckValidLedgerViewWrapper const& ls,
TransactionMetaBuilder& meta, MutableTransactionResultBase& txResult,
SorobanNetworkConfig const& sorobanConfig) const
{
try
{
LedgerTxn ltxTx(ltx);
removeOneTimeSignerKeyFromFeeSource(ltxTx);
meta.pushTxChangesBefore(ltxTx);
ltxTx.commit();
mInnerTx->preParallelApplyReadOnlyWithOptionallyChargedFee(
/*chargeFee=*/false, app, ls, meta, txResult, sorobanConfig,
getContentsHash());
}
catch (std::exception& e)
{
printErrorAndAbort("Exception in preParallelApply ", e.what());
printErrorAndAbort("Exception during read-only preParallelApply: ",
e.what());
}
catch (...)
{
printErrorAndAbort("Unknown exception in preParallelApply");
printErrorAndAbort(
"Unknown exception during read-only preParallelApply");
}
}

void
FeeBumpTransactionFrame::preParallelApplyWrite(
AppConnector& app, AbstractLedgerTxn& ltx, TransactionMetaBuilder& meta,
MutableTransactionResultBase const& txResult) const
{
try
{
mInnerTx->preParallelApply(/*chargeFee=*/false, app, ltx, meta,
txResult, sorobanConfig, getContentsHash());
{
LedgerTxn ltxTx(ltx);
removeOneTimeSignerKeyFromFeeSource(ltxTx);
meta.pushTxChangesBefore(ltxTx);
ltxTx.commit();
}
mInnerTx->preParallelApplyWrite(app, ltx, meta, txResult);
}
catch (std::exception& e)
{
printErrorAndAbort("Exception during preParallelApply: ", e.what());
printErrorAndAbort("Exception during preParallelApply writes: ",
e.what());
}
catch (...)
{
printErrorAndAbort("Unknown exception during preParallelApply");
printErrorAndAbort("Unknown exception during preParallelApply writes");
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/transactions/FeeBumpTransactionFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,14 @@ class FeeBumpTransactionFrame : public TransactionFrameBase

~FeeBumpTransactionFrame() override = default;

void
preParallelApply(AppConnector& app, AbstractLedgerTxn& ltx,
TransactionMetaBuilder& meta,
MutableTransactionResultBase& txResult,
SorobanNetworkConfig const& sorobanConfig) const override;
void preParallelApplyReadOnly(
AppConnector& app, CheckValidLedgerViewWrapper const& ls,
TransactionMetaBuilder& meta, MutableTransactionResultBase& txResult,
SorobanNetworkConfig const& sorobanConfig) const override;

void preParallelApplyWrite(
AppConnector& app, AbstractLedgerTxn& ltx, TransactionMetaBuilder& meta,
MutableTransactionResultBase const& txResult) const override;

std::optional<ParallelTxSuccessVal> parallelApply(
AppConnector& app, ThreadParallelApplyLedgerState const& threadState,
Expand Down
Loading
Loading