fix: non-deterministic writeable account order (#21724)

This commit is contained in:
Noah Prince
2022-01-07 23:38:58 -06:00
committed by GitHub
parent 6d76db1de5
commit 81a10e649f
2 changed files with 87 additions and 2 deletions

View File

@@ -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());
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 ? pubkeySorting : x.isWritable ? -1 : 1;
return checkSigner || checkWritable;
});