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

wallet: keep batch action order when sorting with same covenant types #839

Open
rithvikvibhu opened this issue Aug 8, 2023 · 0 comments

Comments

@rithvikvibhu
Copy link
Member

The code in makeBatch sorts actions to put the linked covenants first:

hsd/lib/wallet/wallet.js

Lines 3741 to 3765 in 500d638

// Sort actions so covenants that require linked inputs
// are pushed first into the mtx input/output arrays.
// This is a required step otherwise an unlinked
// covenant like NONE, OPEN, or BID could shift the
// output array out of sync with their corresponding inputs.
actions.sort((a, b) => {
assert(Array.isArray(a));
assert(Array.isArray(b));
assert(a.length);
assert(b.length);
switch (b[0]) {
case 'REVEAL':
case 'REDEEM':
case 'UPDATE':
case 'RENEW':
case 'TRANSFER':
case 'FINALIZE':
case 'CANCEL':
case 'REVOKE':
return 1;
default:
return -1;
}
});

This doesn't retain the order of actions provided. To do so, returning 0 for same covenants before the switch should work (but need to be sure it doesn't break other things):

actions.sort((a, b) => {
      assert(Array.isArray(a));
      assert(Array.isArray(b));
      assert(a.length);
      assert(b.length);

      if (a[0] === b[0]) // <--
          return 0;

      switch (b[0]) {
@rithvikvibhu rithvikvibhu changed the title wallet: keep action order when sorting with same covenant types wallet: keep batch action order when sorting with same covenant types Aug 8, 2023
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

No branches or pull requests

1 participant