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

Assign default value for confirmationsRequired #1809

Merged
merged 3 commits into from
Aug 7, 2024

Conversation

iamacook
Copy link
Member

@iamacook iamacook commented Aug 6, 2024

Summary

We are occasionally seeing confirmationsRequired of multisig transactions returned as null by the Transaction Service. As we expect it to be an integer, this therefore fails validation.

As this causes transactions not to be returned, this implements fallback values should the value be null:

  • Safe threshold for queued transactions
  • Confirmations required (if present) or Safe threshold for historical transactions

Note: the above is a known bug that should eventually be tackled on the Transaction Service, after which we intend to revert the above.

Changes

  • Fallback to the default values when fetching singular/a list of multisig transactions, or all transactions
  • Add appropriate test coverage

@iamacook iamacook self-assigned this Aug 6, 2024
@iamacook iamacook requested a review from a team as a code owner August 6, 2024 08:34
@coveralls
Copy link

coveralls commented Aug 6, 2024

Pull Request Test Coverage Report for Build 10270570133

Details

  • 2 of 19 (10.53%) changed or added relevant lines in 1 file are covered.
  • 14 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.1%) to 47.957%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/datasources/transaction-api/transaction-api.service.ts 2 19 10.53%
Files with Coverage Reduction New Missed Lines %
src/routes/safes/safes.service.ts 14 14.44%
Totals Coverage Status
Change from base Build 10262920550: -0.1%
Covered Lines: 4426
Relevant Lines: 7441

💛 - Coveralls

},
],
});
// Doesn't need to fetch the Safe for it's threshold
Copy link
Member

Choose a reason for hiding this comment

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

Nit: It does need to fetch the Safe for 2 of the 3 transactions, I'd adjust the comment to make it clearer, wdyt?

Comment on lines 658 to 669
const hasConfirmationsRequired = data.results.every((tx) => {
return tx.confirmationsRequired !== null;
});
if (hasConfirmationsRequired) {
return data;
}

const results = await Promise.all(
data.results.map(async (tx) => {
return await this._setConfirmationsRequired(tx);
}),
);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: this iterates data.results twice when there is an item with confirmationsRequired === null, and also executes _setConfirmationsRequired(tx) for all the transactions in the page.

No strong requirement, but maybe we can optimize it a bit by:

        .then(
          async (data): Promise<Page<MultisigTransaction>> => ({
            ...data,
            results: await Promise.all(
              data.results.map(async (tx) =>
                tx.confirmationsRequired !== null
                  ? tx
                  : await this._setConfirmationsRequired(tx),
              ),
            ),
          }),
        );

This would also simplify the _setConfirmationRequired implementation because the initial check can be removed (and the input type) as the function would only receive transactions affected by the bug:

And a final adjustment could be also done in the other _setConfirmationRequired call in line 705:

        .then(async (tx) =>
          transaction.confirmationsRequired !== null
            ? tx
            : await this._setConfirmationsRequired(tx),
        );

Again, this is just a nit, feel free to keep the current implementation if you think is clearer!

Copy link
Member Author

Choose a reason for hiding this comment

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

I adjusted it in all three instances in 09995bb.

@iamacook iamacook merged commit e042b7b into main Aug 7, 2024
16 checks passed
@iamacook iamacook deleted the default-confirmations-required branch August 7, 2024 06:54
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.

3 participants