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

fix: use deterministic writeable account order #21724

Merged
merged 1 commit into from
Jan 8, 2022

Conversation

ChewingGlass
Copy link
Contributor

Problem

See #21722

Summary of Changes

See #21722

Fixes #

Fixes ordering of writeable accounts to always be deterministic.

@mergify mergify bot added the community Community contribution label Dec 9, 2021
@mergify mergify bot requested a review from a team December 9, 2021 04:59
@@ -261,7 +261,7 @@ export class Transaction {
accountMetas.sort(function (x, y) {
const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
const checkWritable =
x.isWritable === y.isWritable ? 0 : x.isWritable ? -1 : 1;
x.isWritable === y.isWritable ? x.pubkey.toBuffer().compare(y.pubkey.toBuffer()) : x.isWritable ? -1 : 1;
Copy link
Member

Choose a reason for hiding this comment

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

We also need this ordering for checkSigner right?

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. Just spent a bit trying it out.

The checkSigner || checkWritable means that it falls back to the writable ordering. So writable signers go earlier. If both signers aren't writable, then it uses the fallback buffer sorting.

Copy link
Member

Choose a reason for hiding this comment

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

Ah yeah, that's right. Thanks!

@jstarry
Copy link
Member

jstarry commented Dec 10, 2021

Looks good, do you mind fixing the lint issues?

@ChewingGlass
Copy link
Contributor Author

Looks good, do you mind fixing the lint issues?

Should be good

@ChewingGlass
Copy link
Contributor Author

@jstarry it says first-time contributors need a maintainer to approve running workflows. Lmk if there's anything else I can do on this one

@jstarry
Copy link
Member

jstarry commented Dec 14, 2021

@jstarry it says first-time contributors need a maintainer to approve running workflows. Lmk if there's anything else I can do on this one

thanks for the ping, just kicked off the job.

@jstarry jstarry changed the title [#21722] Fix non-deterministic writeable account order feat: use deterministic writeable account order Dec 14, 2021
@ChewingGlass
Copy link
Contributor Author

@jstarry it says first-time contributors need a maintainer to approve running workflows. Lmk if there's anything else I can do on this one

thanks for the ping, just kicked off the job.

Needs another workflow run, fixed the issue I think.

@codecov
Copy link

codecov bot commented Jan 8, 2022

Codecov Report

Merging #21724 (7ab2ed6) into master (0224a8b) will decrease coverage by 11.5%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##           master   #21724       +/-   ##
===========================================
- Coverage    81.6%    70.1%    -11.6%     
===========================================
  Files         511       35      -476     
  Lines      143320     2084   -141236     
  Branches        0      299      +299     
===========================================
- Hits       116976     1461   -115515     
+ Misses      26344      521    -25823     
- Partials        0      102      +102     

@jstarry jstarry merged commit 81a10e6 into solana-labs:master Jan 8, 2022
@jstarry
Copy link
Member

jstarry commented Jan 8, 2022

thx for your patience!

@jstarry jstarry changed the title feat: use deterministic writeable account order fix: use deterministic writeable account order Jan 8, 2022
@@ -259,9 +259,12 @@ export class Transaction {

// Sort. Prioritizing first by signer, then by writable
accountMetas.sort(function (x, y) {
const pubkeySorting = x.pubkey
.toBase58()
.localeCompare(y.pubkey.toBase58());
Copy link

@mvayngrib mvayngrib Aug 4, 2022

Choose a reason for hiding this comment

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

can i ask why localeCompare? These are public keys, not sure what internationalization has to do with it 🤔

Copy link
Member

Choose a reason for hiding this comment

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

I didn't notice this in review but agreed that it's overkill here, direct comparison should be fine here. It's fine as is though, imo

Copy link

@mvayngrib mvayngrib Aug 5, 2022

Choose a reason for hiding this comment

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

it breaks in react native depending on which JS engine u use, that's how we noticed it. Might be worth refactoring

Copy link
Member

Choose a reason for hiding this comment

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

Oh ok, let's refactor then. Do you have the bandwidth to PR the change?

Choose a reason for hiding this comment

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

@jstarry i'll ask someone on my team to upstream the fix 👍

Copy link
Member

Choose a reason for hiding this comment

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

Excellent, thanks!

Choose a reason for hiding this comment

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

@jstarry @mvayngrib apologizes for the delay, but I just created a PR to upstream the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Community contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants