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

Make tx set frame order matter only during encoding/decoding. #3496

Merged
merged 1 commit into from
Aug 25, 2022

Conversation

dmkozh
Copy link
Contributor

@dmkozh dmkozh commented Aug 4, 2022

Description

Resolves #3495

Make tx set frame order matter only during encoding/decoding.

There is no reason to maintain the order in memory and then implicitly assume it's preserved during encoding. Instead, we store transactions in arbitrary order in memory and sort only during encoding to XDR. This hopefully should reduce the risk of outputting a malformed tx set.

Checklist

  • Reviewed the contributing document
  • Rebased on top of master (no merge commits)
  • Ran clang-format v8.0.0 (via make format or the Visual Studio extension)
  • Compiles
  • Ran all tests
  • If change impacts performance, include supporting evidence per the performance document

Copy link
Contributor

@MonsieurNicolas MonsieurNicolas left a comment

Choose a reason for hiding this comment

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

Thank you

src/herder/TxSetFrame.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@MonsieurNicolas MonsieurNicolas left a comment

Choose a reason for hiding this comment

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

looks good, minor test issue. you can squash commits and we'll merge

@@ -2377,12 +2377,12 @@ TEST_CASE_VERSIONS("txenvelope", "[tx][envelope]")

auto r = closeLedgerOn(*app, 1, 2, 2016, {tx1, tx2});

REQUIRE(tx1->getResultCode() == txSUCCESS);
REQUIRE(tx2->getResultCode() == txFAILED);
checkTx(0, r, txSUCCESS);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you need to pass true to the last arg of closeLedgerOn, otherwise you don't know if tx1 < tx2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so: results are in the apply order (I've double-checked with the debugger). The last arg of closeLedgerOn makes the txs to be applied in the same order as we have passed to the method (which already happens due to seq nums) and it has nothing to do with the result order.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah didn't see that tx1 and tx2 were from the same account!

There is no reason to maintain the order in memory and then implicitly assume it's preserved during encoding. Instead, we store transactions in arbitrary order in memory and sort only during encoding to XDR. This hopefully should reduce the risk of outputting a malformed tx set.

For additional safety, we do the XDR roundtrip during the in-memory tx set construction, so we guarantee that we never nominate malformed tx set XDR (at least from the standpoint of the particular core version).
@MonsieurNicolas
Copy link
Contributor

r+ 1f5d4bc

@latobarita latobarita merged commit 552d60c into stellar:master Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleanup validation code in txset
3 participants