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

refactor(core): collect runs batched checks #180

Merged
merged 4 commits into from
Oct 30, 2023

Conversation

aasseman
Copy link
Contributor

@aasseman aasseman commented Oct 3, 2023

The checks are specifically made to check the receipts that are to be aggregated only in their own context. Helps for uniqueness checks for example, where we avoid calling the storage backend and only check that the collected receipts are unique.

In terms of the public API, this should be a cleaner solution than #179 . The implementation itself is not super clean though. A deeper refactor of tap_core may help make this a bit less hacky.

@aasseman aasseman self-assigned this Oct 3, 2023
@github-actions

This comment has been minimized.

@github-actions
Copy link

github-actions bot commented Oct 3, 2023

Pull Request Test Coverage Report for Build 6673349985

  • 125 of 128 (97.66%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+2.1%) to 82.176%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tap_core/src/tap_receipt/receipt_auditor.rs 102 105 97.14%
Totals Coverage Status
Change from base Build 6500762705: 2.1%
Covered Lines: 1231
Relevant Lines: 1498

💛 - Coveralls

The checks are specifically made to check the receipts that are to be
aggregated only in their own context. Helps for uniqueness checks for
example, where we avoid calling the storage backend and only check that
the collected receipts are unique.

Signed-off-by: Alexis Asseman <[email protected]>
@aasseman aasseman force-pushed the aasseman/rav_bulk_receipt_checks branch from 26242a2 to e608b44 Compare October 18, 2023 02:32
@github-actions

This comment has been minimized.

@aasseman aasseman marked this pull request as ready for review October 26, 2023 19:16
@aasseman aasseman requested a review from ColePBryan as a code owner October 26, 2023 19:16
@ColePBryan
Copy link
Contributor

ColePBryan commented Oct 27, 2023

What do you think about proxying the batch call through received receipts class? That way, we can ensure the state remains owned by received receipt. I am worried that we will get difficult bugs popping up as soon as we start requiring the state to be managed outside the state owner.
I think the code would look something like this:

impl ReceivedReceipt {
...
    pub async fn perform_batch_checks<CA: EscrowAdapter, RCA: ReceiptChecksAdapter>(
        batch: &mut [Self],
        check: &ReceiptCheck,
        receipt_auditor: &ReceiptAuditor<CA, RCA>,
    ) -> crate::Result<()> {
        receipt_auditor
            .check_batch(check, batch)
            .await?;
        for receipt in batch {
            receipt.update_state();
        }
        Ok(())
    }
...
}

Additionally, we could return the list of results and have ReceivedReceipt do the updating as well, mainly to keep the approach consistent.

    pub async fn perform_batch_checks<CA: EscrowAdapter, RCA: ReceiptChecksAdapter>(
        batch: &mut [Self],
        check: &ReceiptCheck,
        receipt_auditor: &ReceiptAuditor<CA, RCA>,
    ) -> crate::Result<()> {
        results = receipt_auditor
            .check_batch(check, batch)
            .await?;
        for (receipt,result) in batch.iter_mut().zip(results) {
            receipt.update_check(check, result);
            receipt.update_state();
        }
        ok(())
    }

Assuming the returned list of results are in the same order as the receipts provided. (edited)

@aasseman aasseman force-pushed the aasseman/rav_bulk_receipt_checks branch from 9bf9064 to 1ed4355 Compare October 27, 2023 23:58
@aasseman
Copy link
Contributor Author

I reverted a commit that shouldn't be in this PR, and applied your suggestion.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions
Copy link

🤖 Cargo Audit Report 🤖

(Empty means OK! 👍)

Copy link
Contributor

@ColePBryan ColePBryan left a comment

Choose a reason for hiding this comment

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

:shipit:

@aasseman aasseman merged commit d3359c1 into main Oct 30, 2023
8 checks passed
@aasseman aasseman deleted the aasseman/rav_bulk_receipt_checks branch October 30, 2023 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants