-
Notifications
You must be signed in to change notification settings - Fork 1.7k
TransactionProposalCreate edge cases and tests #7958
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
Open
Kassaking7
wants to merge
6
commits into
XRPLF:ripple/cosign
Choose a base branch
from
Kassaking7:ProposalCreate-Tests
base: ripple/cosign
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+179
−91
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,10 +38,39 @@ TransactionProposalCreate::preflight(PreflightContext const& ctx) | |
|
|
||
| STObject const proposedTx = ctx.tx.getFieldObject(sfProposedTransaction); | ||
|
|
||
| if (!proposedTx.isFieldPresent(sfTransactionType) || !proposedTx.isFieldPresent(sfAccount)) | ||
| // The proposed transaction must pass its own static checks under the | ||
| // current rules, so no statically-dead proposal can be stored. This also | ||
| // guarantees every field common to all transactions (TransactionType, | ||
| // Account, Fee, Sequence, ...) is present, since applyTemplate throws | ||
| // otherwise; the checks below can therefore read those fields directly | ||
| // without re-checking presence. TapDryRun accepts the unsigned canonical | ||
| // form without a signature check; TapProposal additionally skips | ||
| // signature-presence checks (e.g. Batch signer matching), which are | ||
| // deferred to submission time (On-Chain Cosigner spec §5.3.1.2). A | ||
| // proposedTx that fails here is rejected with its own type's preflight | ||
| // code (or temMALFORMED if it isn't even a valid instance of that type), | ||
| // ahead of the Cosigner-specific structural checks below. | ||
| try | ||
| { | ||
| JLOG(ctx.j.debug()) << "TransactionProposalCreate: proposed txn " | ||
| "lacks TransactionType or Account."; | ||
| STTx const stx{STObject{proposedTx}}; | ||
| auto const inner = | ||
| xrpl::preflight(ctx.registry, ctx.rules, stx, TapDryRun | TapProposal, ctx.j); | ||
| if (!isTesSuccess(inner.ter)) | ||
| { | ||
| JLOG(ctx.j.debug()) << "TransactionProposalCreate: proposed txn " | ||
| "failed preflight: " | ||
| << transHuman(inner.ter); | ||
| // Surface the proposed transaction type's own preflight code | ||
| // rather than collapsing it to a generic error (On-Chain Cosigner | ||
| // spec §5.3.1). | ||
| return inner.ter; | ||
| } | ||
| } | ||
| catch (std::exception const& e) | ||
| { | ||
| JLOG(ctx.j.debug()) << "TransactionProposalCreate: proposed txn is " | ||
| "malformed: " | ||
| << e.what(); | ||
| return temMALFORMED; | ||
| } | ||
|
|
||
|
|
@@ -61,8 +90,7 @@ TransactionProposalCreate::preflight(PreflightContext const& ctx) | |
| return temINVALID; | ||
| } | ||
|
|
||
| if (proposedTx.isFieldPresent(sfFlags) && | ||
| ((proposedTx.getFieldU32(sfFlags) & tfInnerBatchTxn) != 0u)) | ||
| if (proposedTx.isFlag(tfInnerBatchTxn)) | ||
| { | ||
| JLOG(ctx.j.debug()) << "TransactionProposalCreate: proposed txn " | ||
| "carries tfInnerBatchTxn."; | ||
|
|
@@ -85,15 +113,6 @@ TransactionProposalCreate::preflight(PreflightContext const& ctx) | |
| return temBAD_SIGNER; | ||
| } | ||
|
|
||
| // The proposed transaction's fee is charged to the target account when | ||
| // the completed transaction is submitted, so it must be fixed now. | ||
| if (!proposedTx.isFieldPresent(sfFee) || !proposedTx.isFieldPresent(sfSequence)) | ||
| { | ||
| JLOG(ctx.j.debug()) << "TransactionProposalCreate: proposed txn " | ||
| "lacks Fee or Sequence."; | ||
| return temMALFORMED; | ||
| } | ||
|
|
||
| // The proposed transaction must be ticket-based: it must carry a | ||
| // TicketSequence and must not use a live Sequence. Sequence is a required | ||
| // common field, so "no Sequence" is expressed as a Sequence of 0 rather | ||
|
|
@@ -104,33 +123,17 @@ TransactionProposalCreate::preflight(PreflightContext const& ctx) | |
| if (!proposedTx.isFieldPresent(sfTicketSequence) || proposedTx.getFieldU32(sfSequence) != 0) | ||
| return temSEQ_AND_TICKET; | ||
|
Comment on lines
123
to
124
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. based on recent discussion, we need to reserve ticket, so we should check if the ticket exists |
||
|
|
||
| // The proposed transaction must pass its own static checks under the | ||
| // current rules, so no statically-dead proposal can be stored. TapDryRun | ||
| // accepts the unsigned canonical form without a signature check; | ||
| // TapProposal additionally skips signature-presence checks (e.g. Batch | ||
| // signer matching), which are deferred to submission time (On-Chain | ||
| // Cosigner spec §5.3.1.2). | ||
| try | ||
| { | ||
| STTx const stx{STObject{proposedTx}}; | ||
| auto const inner = | ||
| xrpl::preflight(ctx.registry, ctx.rules, stx, TapDryRun | TapProposal, ctx.j); | ||
| if (!isTesSuccess(inner.ter)) | ||
| { | ||
| JLOG(ctx.j.debug()) << "TransactionProposalCreate: proposed txn " | ||
| "failed preflight: " | ||
| << transHuman(inner.ter); | ||
| // Surface the proposed transaction type's own preflight code | ||
| // rather than collapsing it to a generic error (On-Chain Cosigner | ||
| // spec §5.3.1). | ||
| return inner.ter; | ||
| } | ||
| } | ||
| catch (std::exception const& e) | ||
| // If this transaction itself is paying with a Ticket, and the proposed | ||
| // transaction is targeting that same account and Ticket, then applying | ||
| // this transaction consumes the very Ticket the proposal depends on | ||
| // before the proposal is even stored: the proposal would be dead on | ||
| // arrival, and its only recourse would be TransactionProposalCancel. | ||
| if (ctx.tx.getSeqProxy().isTicket() && | ||
| proposedTx.getAccountID(sfAccount) == ctx.tx.getAccountID(sfAccount) && | ||
| proposedTx.getFieldU32(sfTicketSequence) == ctx.tx.getSeqProxy().value()) | ||
| { | ||
| JLOG(ctx.j.debug()) << "TransactionProposalCreate: proposed txn is " | ||
| "malformed: " | ||
| << e.what(); | ||
| JLOG(ctx.j.debug()) << "TransactionProposalCreate: proposed txn " | ||
| "reuses the Ticket this transaction itself consumes."; | ||
| return temMALFORMED; | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still need proposedTx.isFieldPresent(sfFlags) check, otherwise if the field doesn't exist it will throw. What if we move the STTx construction (line 128) to the start of preflight? would it avoid having need to check the existence of the fields