Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch Amendment #5060

Open
wants to merge 84 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
879aba5
featureBatch rough draft
dangell7 Jul 10, 2024
46fd68f
clang-format
dangell7 Jul 10, 2024
c57ace7
add atomic swap
dangell7 Jul 17, 2024
91d9909
Merge branch 'develop' into feature-batch
dangell7 Jul 17, 2024
f37377d
add batch `bsig`
dangell7 Jul 17, 2024
b3136a2
[fold] clang-format
dangell7 Jul 17, 2024
5e919eb
[fold] remove `tapRETRY`
dangell7 Jul 27, 2024
1225a61
[fold] remove comments
dangell7 Jul 27, 2024
304ff3e
[fold] fix invariant workaround
dangell7 Jul 27, 2024
aded948
[fold] fix applyTransaction workaround
dangell7 Jul 27, 2024
82d4943
[fold] remove test template
dangell7 Jul 27, 2024
eaf7893
[fold] update logging
dangell7 Jul 27, 2024
ca39807
[fold] remove log
dangell7 Jul 27, 2024
dd71073
clang-format
dangell7 Jul 27, 2024
26518a5
[fold] remove workaround
dangell7 Jul 27, 2024
3ceb05c
update atomic
dangell7 Jul 30, 2024
12324f1
refactor & OpenView `revert()`
dangell7 Jul 31, 2024
e9f045b
[fold] clang-format
dangell7 Jul 31, 2024
51ed234
Merge branch 'develop' into feature-batch
dangell7 Jul 31, 2024
676b9b6
[fold] add revert
dangell7 Jul 31, 2024
6c6180d
[fold] clang-format
dangell7 Jul 31, 2024
bd03ea3
[revert] remove rawRevert func
dangell7 Aug 1, 2024
c0e00b0
refactor with stacking views
dangell7 Aug 3, 2024
a3e15a1
clang-format
dangell7 Aug 3, 2024
14eef60
Merge branch 'develop' into feature-batch
dangell7 Aug 3, 2024
70e9931
[temp] invariant workaround
dangell7 Aug 3, 2024
c693b8f
update fields
dangell7 Aug 3, 2024
418836c
reject batch txn on submit
dangell7 Aug 3, 2024
fe09972
clang-format
dangell7 Aug 3, 2024
a72b070
add tests
dangell7 Aug 3, 2024
0a45c16
[fold] remove unused code
dangell7 Aug 5, 2024
2a0b9d4
include batch execution in tec failures
dangell7 Aug 5, 2024
3a9963a
atomic revert on non tec failures
dangell7 Aug 5, 2024
2c3c5c4
fix sequence & fee
dangell7 Aug 9, 2024
a54a570
Merge branch 'develop' into feature-batch
dangell7 Aug 9, 2024
3ab585b
clang-format
dangell7 Aug 9, 2024
26ee555
previousFields + nested views + signers
dangell7 Sep 5, 2024
0d5242e
clang-format
dangell7 Sep 5, 2024
51990ff
Merge branch 'develop' into feature-batch
dangell7 Sep 5, 2024
ff7fa26
add `sfBatchResult`
dangell7 Sep 5, 2024
ae5abf5
Merge branch 'develop' into feature-batch
dangell7 Sep 10, 2024
a78da6a
ticket sequence
dangell7 Sep 10, 2024
d3a2554
fix metadata
dangell7 Sep 10, 2024
e099e03
fix metadata
dangell7 Sep 10, 2024
84a69ef
fix metadata
dangell7 Sep 10, 2024
f9fe787
update tests
dangell7 Sep 10, 2024
0deea74
clang-format
dangell7 Sep 10, 2024
9266676
remove unused variable
dangell7 Sep 10, 2024
3fff4ca
rename func/field names
dangell7 Sep 10, 2024
ecfc64b
clang-format
dangell7 Sep 10, 2024
096f4bf
[fold] remove log
dangell7 Sep 10, 2024
122368f
Merge branch 'develop' into feature-batch
dangell7 Sep 12, 2024
274660b
add sfTxIDs and update signing
dangell7 Sep 18, 2024
04c5bde
clang-format
dangell7 Sep 18, 2024
e4a5c52
Merge branch 'develop' into feature-batch
dangell7 Sep 18, 2024
659e705
[fixup] rerun actions
dangell7 Sep 18, 2024
597e7fe
[fixup] remove comments
dangell7 Sep 18, 2024
639f8b7
fix no account
dangell7 Sep 22, 2024
75fd76b
clang-format
dangell7 Sep 22, 2024
2925a5d
Merge branch 'develop' into feature-batch
dangell7 Sep 24, 2024
1367e03
Merge branch 'develop' into feature-batch
dangell7 Oct 1, 2024
f185d38
[fold] remove comment
dangell7 Oct 30, 2024
767a88e
[fold] update headers
dangell7 Oct 30, 2024
ee03811
[fold] change error response text
dangell7 Oct 30, 2024
9d8368d
[fold] change flags bit
dangell7 Oct 30, 2024
b408b80
[fold] fix formatting
dangell7 Oct 30, 2024
27d4685
[fold] normal consequences
dangell7 Oct 30, 2024
419b14d
[fold] refactor single/multi sign
dangell7 Oct 30, 2024
6c87e70
[fold] review comments
dangell7 Oct 31, 2024
a75cf0e
[fold] clang-format
dangell7 Oct 31, 2024
e6021bf
[fold] tickets are not chronological
dangell7 Oct 31, 2024
fd0acb7
[fold] fix fee calculation
dangell7 Oct 31, 2024
8a6d6ce
Merge branch 'develop' into feature-batch
dangell7 Oct 31, 2024
dd77e03
[fold] fix merge issues
dangell7 Oct 31, 2024
6cb23e3
[fold] clang-format
dangell7 Oct 31, 2024
88c40e4
[fold] addressing review
dangell7 Nov 6, 2024
e4cb784
[fold] change sequence handling
dangell7 Nov 7, 2024
47120ac
[fixup] rename `prevFields` -> `batchPrevAcctRootFields`
dangell7 Nov 7, 2024
6ed4ac8
[fold] revert applyFlags change
dangell7 Nov 7, 2024
52f1ba9
[fold] use `unordered_set`
dangell7 Nov 7, 2024
1978fd3
Merge branch 'develop' into feature-batch
dangell7 Nov 7, 2024
6ffe349
[fold] clang-format
dangell7 Nov 7, 2024
04519e6
[fold] fix bad merge
dangell7 Nov 7, 2024
8029c30
[fold] address review
dangell7 Nov 11, 2024
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
37 changes: 37 additions & 0 deletions include/xrpl/protocol/Batch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2024 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================

#include <xrpl/protocol/HashPrefix.h>
#include <xrpl/protocol/STVector256.h>
#include <xrpl/protocol/Serializer.h>

namespace ripple {

inline void
serializeBatch(
Serializer& msg,
std::uint32_t const& flags,
STVector256 const& txids)
{
msg.add32(HashPrefix::batch);
msg.add32(flags);
msg.add32(txids.size());
for (auto const& txid : txids)
msg.addBitString(txid);
dangell7 marked this conversation as resolved.
Show resolved Hide resolved
}

} // namespace ripple
2 changes: 1 addition & 1 deletion include/xrpl/protocol/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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 = 80;
static constexpr std::size_t numFeatures = 81;

/** Amendments that this server supports and the default voting behavior.
Whether they are enabled depends on the Rules defined in the validated
Expand Down
3 changes: 3 additions & 0 deletions include/xrpl/protocol/HashPrefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ enum class HashPrefix : std::uint32_t {

/** Payment Channel Claim */
paymentChannelClaim = detail::make_hash_prefix('C', 'L', 'M'),

/** Batch */
batch = detail::make_hash_prefix('B', 'C', 'H'),
};

template <class Hasher>
Expand Down
17 changes: 17 additions & 0 deletions include/xrpl/protocol/STTx.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,16 @@ class STTx final : public STObject, public CountedObject<STTx>
@return `true` if valid signature. If invalid, the error message string.
*/
enum class RequireFullyCanonicalSig : bool { no, yes };

Expected<void, std::string>
checkSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const& rules)
const;

Expected<void, std::string>
checkBatchSign(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add these to STTx instead of having the code in Batch.cpp?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because they were so similar to the other functionality. I can move them. Is this preferred?

RequireFullyCanonicalSig requireCanonicalSig,
Rules const& rules) const;

// SQL Functions with metadata.
static std::string const&
getMetaSQLInsertReplaceHeader();
Expand All @@ -148,6 +154,17 @@ class STTx final : public STObject, public CountedObject<STTx>
RequireFullyCanonicalSig requireCanonicalSig,
Rules const& rules) const;

Expected<void, std::string>
checkBatchSingleSign(
STObject const& batchSigner,
RequireFullyCanonicalSig requireCanonicalSig) const;

Expected<void, std::string>
checkBatchMultiSign(
STObject const& batchSigner,
RequireFullyCanonicalSig requireCanonicalSig,
Rules const& rules) const;

STBase*
copy(std::size_t n, void* buf) const override;
STBase*
Expand Down
3 changes: 2 additions & 1 deletion include/xrpl/protocol/TER.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ enum TEMcodes : TERUnderlyingType {

temARRAY_EMPTY,
temARRAY_TOO_LARGE,

temBAD_TRANSFER_FEE,
temINVALID_BATCH,
};

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -343,6 +343,7 @@ enum TECcodes : TERUnderlyingType {
tecARRAY_EMPTY = 190,
tecARRAY_TOO_LARGE = 191,
tecLOCKED = 192,
tecBATCH_FAILURE = 193
};

//------------------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions include/xrpl/protocol/TxFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ constexpr std::uint32_t tfDepositMask = ~(tfUniversal | tfDepositSubTx);
// BridgeModify flags:
constexpr std::uint32_t tfClearAccountCreateAmount = 0x00010000;
constexpr std::uint32_t tfBridgeModifyMask = ~(tfUniversal | tfClearAccountCreateAmount);

// Batch Flags
dangell7 marked this conversation as resolved.
Show resolved Hide resolved
constexpr std::uint32_t tfAllOrNothing = 0x00010000;
constexpr std::uint32_t tfOnlyOne = 0x00020000;
constexpr std::uint32_t tfUntilFailure = 0x00040000;
constexpr std::uint32_t tfIndependent = 0x00080000;
constexpr std::uint32_t const tfBatchMask =
~(tfUniversal | tfAllOrNothing | tfOnlyOne | tfUntilFailure | tfIndependent);
constexpr std::uint32_t const tfBatchSubTx =
tfAllOrNothing | tfOnlyOne | tfUntilFailure | tfIndependent;

// clang-format on

} // namespace ripple
Expand Down
19 changes: 19 additions & 0 deletions include/xrpl/protocol/TxMeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,32 @@ class TxMeta
return static_cast<bool>(mDelivered);
}

STArray const&
getBatchExecutions() const
{
return *mBatchExecutions;
}

void
setBatchExecutions(STArray const& batchExecutions)
{
mBatchExecutions = batchExecutions;
}

bool
dangell7 marked this conversation as resolved.
Show resolved Hide resolved
hasBatchExecutions() const
{
return static_cast<bool>(mBatchExecutions);
}

private:
uint256 mTransactionID;
std::uint32_t mLedger;
std::uint32_t mIndex;
int mResult;

std::optional<STAmount> mDelivered;
std::optional<STArray> mBatchExecutions;

STArray mNodes;
};
Expand Down
1 change: 1 addition & 0 deletions include/xrpl/protocol/detail/features.macro
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

// InvariantsV1_1 will be changes to Supported::yes when all the
// invariants expected to be included under it are complete.
XRPL_FEATURE(Batch, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(MPTokensV1, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(InvariantsV1_1, Supported::no, VoteBehavior::DefaultNo)
XRPL_FIX (NFTokenPageLinks, Supported::yes, VoteBehavior::DefaultNo)
Expand Down
11 changes: 11 additions & 0 deletions include/xrpl/protocol/detail/sfields.macro
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ TYPED_SFIELD(sfTickSize, UINT8, 16)
TYPED_SFIELD(sfUNLModifyDisabling, UINT8, 17)
TYPED_SFIELD(sfHookResult, UINT8, 18)
TYPED_SFIELD(sfWasLockingChainSend, UINT8, 19)
TYPED_SFIELD(sfBatchIndex, UINT8, 20)

// 16-bit integers (common)
TYPED_SFIELD(sfLedgerEntryType, UINT16, 1, SField::sMD_Never)
Expand Down Expand Up @@ -258,6 +259,7 @@ TYPED_SFIELD(sfData, VL, 27)
TYPED_SFIELD(sfAssetClass, VL, 28)
TYPED_SFIELD(sfProvider, VL, 29)
TYPED_SFIELD(sfMPTokenMetadata, VL, 30)
TYPED_SFIELD(sfInnerResult, VL, 31)

// account (common)
TYPED_SFIELD(sfAccount, ACCOUNT, 1)
Expand All @@ -280,12 +282,14 @@ TYPED_SFIELD(sfAttestationSignerAccount, ACCOUNT, 20)
TYPED_SFIELD(sfAttestationRewardAccount, ACCOUNT, 21)
TYPED_SFIELD(sfLockingChainDoor, ACCOUNT, 22)
TYPED_SFIELD(sfIssuingChainDoor, ACCOUNT, 23)
TYPED_SFIELD(sfOuterAccount, ACCOUNT, 24)

// vector of 256-bit
TYPED_SFIELD(sfIndexes, VECTOR256, 1, SField::sMD_Never)
TYPED_SFIELD(sfHashes, VECTOR256, 2)
TYPED_SFIELD(sfAmendments, VECTOR256, 3)
TYPED_SFIELD(sfNFTokenOffers, VECTOR256, 4)
TYPED_SFIELD(sfTxIDs, VECTOR256, 5)

// path set
UNTYPED_SFIELD(sfPaths, PATHSET, 1)
Expand Down Expand Up @@ -337,6 +341,10 @@ UNTYPED_SFIELD(sfXChainCreateAccountProofSig, OBJECT, 29)
UNTYPED_SFIELD(sfXChainClaimAttestationCollectionElement, OBJECT, 30)
UNTYPED_SFIELD(sfXChainCreateAccountAttestationCollectionElement, OBJECT, 31)
UNTYPED_SFIELD(sfPriceData, OBJECT, 32)
UNTYPED_SFIELD(sfRawTransaction, OBJECT, 33)
UNTYPED_SFIELD(sfBatchExecution, OBJECT, 34)
UNTYPED_SFIELD(sfBatchTxn, OBJECT, 35)
UNTYPED_SFIELD(sfBatchSigner, OBJECT, 36)

// array of objects (common)
// ARRAY/1 is reserved for end of array
Expand Down Expand Up @@ -364,3 +372,6 @@ UNTYPED_SFIELD(sfXChainCreateAccountAttestations, ARRAY, 22)
// 23 unused
UNTYPED_SFIELD(sfPriceDataSeries, ARRAY, 24)
UNTYPED_SFIELD(sfAuthAccounts, ARRAY, 25)
UNTYPED_SFIELD(sfBatchExecutions, ARRAY, 26)
UNTYPED_SFIELD(sfRawTransactions, ARRAY, 27)
UNTYPED_SFIELD(sfBatchSigners, ARRAY, 28)
7 changes: 7 additions & 0 deletions include/xrpl/protocol/detail/transactions.macro
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,13 @@ TRANSACTION(ttMPTOKEN_AUTHORIZE, 57, MPTokenAuthorize, ({
{sfHolder, soeOPTIONAL},
}))

/** This transaction type wraps inner transactions for batch. */
TRANSACTION(ttBATCH, 58, Batch, ({
{sfRawTransactions, soeREQUIRED},
{sfTxIDs, soeREQUIRED},
{sfBatchSigners, soeOPTIONAL},
}))

/** This system-generated transaction type is used to update the status of the various amendments.

For details, see: https://xrpl.org/amendments.html
Expand Down
3 changes: 3 additions & 0 deletions include/xrpl/protocol/jss.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ JSS(Offer); // ledger type.
JSS(OfferSequence); // field.
JSS(Oracle); // ledger type.
JSS(OracleDocumentID); // field
JSS(OuterAccount); // field
JSS(Owner); // field
JSS(Paths); // in/out: TransactionSign
JSS(PayChannel); // ledger type.
Expand All @@ -98,6 +99,8 @@ JSS(PriceData); // field.
JSS(Provider); // field.
JSS(QuoteAsset); // in: Oracle.
JSS(RippleState); // ledger type.
JSS(RawTransaction); // in: Batch
JSS(RawTransactions); // in: Batch
JSS(SLE_hit_rate); // out: GetCounts.
JSS(Scale); // field.
JSS(SettleDelay); // in: TransactionSign
Expand Down
20 changes: 20 additions & 0 deletions src/libxrpl/protocol/InnerObjectFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,26 @@ InnerObjectFormats::InnerObjectFormats()
{sfAssetPrice, soeOPTIONAL},
{sfScale, soeDEFAULT},
});

add(sfBatchExecution.jsonName.c_str(),
sfBatchExecution.getCode(),
{{sfTransactionType, soeREQUIRED},
{sfInnerResult, soeREQUIRED},
{sfTransactionHash, soeOPTIONAL}});

add(sfBatchTxn.jsonName.c_str(),
sfBatchTxn.getCode(),
{{sfOuterAccount, soeREQUIRED},
{sfSequence, soeOPTIONAL},
{sfTicketSequence, soeOPTIONAL},
{sfBatchIndex, soeREQUIRED}});
dangell7 marked this conversation as resolved.
Show resolved Hide resolved

add(sfBatchSigner.jsonName.c_str(),
sfBatchSigner.getCode(),
{{sfAccount, soeREQUIRED},
{sfSigningPubKey, soeOPTIONAL},
{sfTxnSignature, soeOPTIONAL},
{sfSigners, soeOPTIONAL}});
}

InnerObjectFormats const&
Expand Down
Loading
Loading