Skip to content

Commit

Permalink
fixInnerObjTemplate2 amendment:
Browse files Browse the repository at this point in the history
Apply inner object templates to all remaining (non-AMM)
inner objects.

Adds a unit test for applying the template to sfMajorities.
Other remaining inner objects showed no problems having
templates applied.
  • Loading branch information
scottschurr committed Feb 13, 2024
1 parent da68651 commit b696435
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 200 deletions.
3 changes: 2 additions & 1 deletion src/ripple/app/ledger/Ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,8 @@ Ledger::updateNegativeUNL()

if (hasToDisable)
{
newNUnl.emplace_back(sfDisabledValidator);
newNUnl.push_back(
STObject::makeInnerObject(sfDisabledValidator, rules()));
newNUnl.back().setFieldVL(
sfPublicKey, sle->getFieldVL(sfValidatorToDisable));
newNUnl.back().setFieldU32(sfFirstLedgerSequence, seq());
Expand Down
9 changes: 5 additions & 4 deletions src/ripple/app/tx/impl/Change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,12 @@ Change::applyAmendment()
if (gotMajority)
{
// This amendment now has a majority
newMajorities.push_back(STObject(sfMajority));
newMajorities.push_back(
STObject::makeInnerObject(sfMajority, view().rules()));
auto& entry = newMajorities.back();
entry.emplace_back(STUInt256(sfAmendment, amendment));
entry.emplace_back(STUInt32(
sfCloseTime, view().parentCloseTime().time_since_epoch().count()));
entry[sfAmendment] = amendment;
entry[sfCloseTime] =
view().parentCloseTime().time_since_epoch().count();

if (!ctx_.app.getAmendmentTable().isSupported(amendment))
{
Expand Down
3 changes: 2 additions & 1 deletion src/ripple/app/tx/impl/SetSignerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,11 @@ SetSignerList::writeSignersToSLE(
ctx_.view().rules().enabled(featureExpandedSignerList);

// Create the SignerListArray one SignerEntry at a time.
Rules const& rules = view().rules();
STArray toLedger(signers_.size());
for (auto const& entry : signers_)
{
toLedger.emplace_back(sfSignerEntry);
toLedger.push_back(STObject::makeInnerObject(sfSignerEntry, rules));
STObject& obj = toLedger.back();
obj.reserve(2);
obj.setAccountID(sfAccount, entry.account);
Expand Down
7 changes: 4 additions & 3 deletions src/ripple/app/tx/impl/XChainBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ applyClaimAttestations(

// update the claim id
sleClaimID->setFieldArray(
sfXChainClaimAttestations, curAtts.toSTArray());
sfXChainClaimAttestations, curAtts.toSTArray(view.rules()));
psb.update(sleClaimID);

return ScopeResult{
Expand Down Expand Up @@ -1097,7 +1097,8 @@ applyCreateAccountAttestations(
if (!sleClaimID)
return Unexpected(tecINTERNAL);
sleClaimID->setFieldArray(
sfXChainCreateAccountAttestations, curAtts.toSTArray());
sfXChainCreateAccountAttestations,
curAtts.toSTArray(view.rules()));
psb.update(sleClaimID);
}
return ScopeResult{newAttResult, createCID, curAtts};
Expand Down Expand Up @@ -1152,7 +1153,7 @@ applyCreateAccountAttestations(
(*createdSleClaimID)[sfXChainAccountCreateCount] =
attBegin->createCount;
createdSleClaimID->setFieldArray(
sfXChainCreateAccountAttestations, curAtts.toSTArray());
sfXChainCreateAccountAttestations, curAtts.toSTArray(view.rules()));

// Add to owner directory of the door account
auto const page = psb.dirInsert(
Expand Down
3 changes: 2 additions & 1 deletion src/ripple/protocol/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace detail {
// Feature.cpp. Because it's only used to reserve storage, and determine how
// large to make the FeatureBitset, it MAY be larger. It MUST NOT be less than
// the actual number of amendments. A LogicError on startup will verify this.
static constexpr std::size_t numFeatures = 67;
static constexpr std::size_t numFeatures = 68;

/** Amendments that this server supports and the default voting behavior.
Whether they are enabled depends on the Rules defined in the validated
Expand Down Expand Up @@ -354,6 +354,7 @@ extern uint256 const featureDID;
extern uint256 const fixFillOrKill;
extern uint256 const fixNFTokenReserve;
extern uint256 const fixInnerObjTemplate;
extern uint256 const fixInnerObjTemplate2;

} // namespace ripple

Expand Down
10 changes: 5 additions & 5 deletions src/ripple/protocol/XChainAttestations.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ struct AttestationClaim : AttestationBase
explicit AttestationClaim(Json::Value const& v);

[[nodiscard]] STObject
toSTObject() const;
toSTObject(Rules const& rules) const;

// return true if the two attestations attest to the same thing
[[nodiscard]] bool
Expand Down Expand Up @@ -211,7 +211,7 @@ struct AttestationCreateAccount : AttestationBase
AccountID const& toCreate_);

[[nodiscard]] STObject
toSTObject() const;
toSTObject(Rules const& rules) const;

// return true if the two attestations attest to the same thing
[[nodiscard]] bool
Expand Down Expand Up @@ -317,7 +317,7 @@ struct XChainClaimAttestation
match(MatchFields const& rhs) const;

[[nodiscard]] STObject
toSTObject() const;
toSTObject(Rules const& rules) const;

friend bool
operator==(
Expand Down Expand Up @@ -364,7 +364,7 @@ struct XChainCreateAccountAttestation
explicit XChainCreateAccountAttestation(Json::Value const& v);

[[nodiscard]] STObject
toSTObject() const;
toSTObject(Rules const& rules) const;

AttestationMatch
match(MatchFields const& rhs) const;
Expand Down Expand Up @@ -407,7 +407,7 @@ class XChainAttestationsBase
explicit XChainAttestationsBase(STArray const& arr);

[[nodiscard]] STArray
toSTArray() const;
toSTArray(Rules const& rules) const;

typename AttCollection::const_iterator
begin() const;
Expand Down
5 changes: 3 additions & 2 deletions src/ripple/protocol/impl/Feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,10 @@ REGISTER_FEATURE(AMM, Supported::yes, VoteBehavior::De
REGISTER_FEATURE(XChainBridge, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FIX (fixDisallowIncomingV1, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FEATURE(DID, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FIX(fixFillOrKill, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FIX (fixFillOrKill, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FIX (fixNFTokenReserve, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FIX(fixInnerObjTemplate, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FIX (fixInnerObjTemplate, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FIX (fixInnerObjTemplate2, Supported::yes, VoteBehavior::DefaultNo);

// The following amendments are obsolete, but must remain supported
// because they could potentially get enabled.
Expand Down
9 changes: 8 additions & 1 deletion src/ripple/protocol/impl/STObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ STObject
STObject::makeInnerObject(SField const& name, Rules const& rules)
{
STObject obj{name};
if (rules.enabled(fixInnerObjTemplate))

// The if is complicated because inner object templates were added in
// two phases:
// 1. fixInnerObjTemplate added templates to two AMM inner objects.
// 2. fixInnerObjTemplate2 added templates to the remaining inner objects.
bool const isAMMObj = name == sfAuctionSlot || name == sfVoteEntry;
if ((rules.enabled(fixInnerObjTemplate) && isAMMObj) ||
(rules.enabled(fixInnerObjTemplate2) && !isAMMObj))
{
if (SOTemplate const* elements =
InnerObjectFormats::getInstance().findSOTemplateBySField(name))
Expand Down
23 changes: 13 additions & 10 deletions src/ripple/protocol/impl/XChainAttestations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,10 @@ AttestationClaim::AttestationClaim(Json::Value const& v)
}

STObject
AttestationClaim::toSTObject() const
AttestationClaim::toSTObject(Rules const& rules) const
{
STObject o{sfXChainClaimAttestationCollectionElement};
STObject o = STObject::makeInnerObject(
sfXChainClaimAttestationCollectionElement, rules);
addHelper(o);
o[sfXChainClaimID] = claimID;
if (dst)
Expand Down Expand Up @@ -343,9 +344,10 @@ AttestationCreateAccount::AttestationCreateAccount(
}

STObject
AttestationCreateAccount::toSTObject() const
AttestationCreateAccount::toSTObject(Rules const& rules) const
{
STObject o{sfXChainCreateAccountAttestationCollectionElement};
STObject o = STObject::makeInnerObject(
sfXChainCreateAccountAttestationCollectionElement, rules);
addHelper(o);

o[sfXChainAccountCreateCount] = createCount;
Expand Down Expand Up @@ -495,9 +497,9 @@ XChainClaimAttestation::XChainClaimAttestation(
}

STObject
XChainClaimAttestation::toSTObject() const
XChainClaimAttestation::toSTObject(Rules const& rules) const
{
STObject o{sfXChainClaimProofSig};
STObject o = STObject::makeInnerObject(sfXChainClaimProofSig, rules);
o[sfAttestationSignerAccount] =
STAccount{sfAttestationSignerAccount, keyAccount};
o[sfPublicKey] = publicKey;
Expand Down Expand Up @@ -607,9 +609,10 @@ XChainCreateAccountAttestation::XChainCreateAccountAttestation(
}

STObject
XChainCreateAccountAttestation::toSTObject() const
XChainCreateAccountAttestation::toSTObject(Rules const& rules) const
{
STObject o{sfXChainCreateAccountProofSig};
STObject o =
STObject::makeInnerObject(sfXChainCreateAccountProofSig, rules);

o[sfAttestationSignerAccount] =
STAccount{sfAttestationSignerAccount, keyAccount};
Expand Down Expand Up @@ -745,11 +748,11 @@ XChainAttestationsBase<TAttestation>::XChainAttestationsBase(STArray const& arr)

template <class TAttestation>
STArray
XChainAttestationsBase<TAttestation>::toSTArray() const
XChainAttestationsBase<TAttestation>::toSTArray(Rules const& rules) const
{
STArray r{TAttestation::ArrayFieldName, attestations_.size()};
for (auto const& e : attestations_)
r.emplace_back(e.toSTObject());
r.emplace_back(e.toSTObject(rules));
return r;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ripple/rpc/impl/TransactionSign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ transactionSignFor(
auto& sttx = preprocResult.second;
{
// Make the signer object that we'll inject.
STObject signer(sfSigner);
STObject signer = STObject::makeInnerObject(sfSigner, ledger->rules());
signer[sfAccount] = *signerAccountID;
signer.setFieldVL(sfTxnSignature, multiSignature);
signer.setFieldVL(sfSigningPubKey, multiSignPubKey.slice());
Expand Down
Loading

0 comments on commit b696435

Please sign in to comment.