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

add(scan): Implement DeleteKeys ScanService request #8217

Merged
merged 18 commits into from
Jan 31, 2024
Merged

Conversation

arya2
Copy link
Contributor

@arya2 arya2 commented Jan 31, 2024

Motivation

This PR implements the DeleteKeys request for ScanService to:

  • drop keys from the scanner task
  • delete keys and their results from the database

Closes #8204.

PR Author Checklist

Check before marking the PR as ready for review:

  • Will the PR name make sense to users?
  • Does the PR have a priority label?
  • Have you added or updated tests?
  • Is the documentation up to date?
For significant changes:
  • Is there a summary in the CHANGELOG?
  • Can these changes be split into multiple PRs?

If a checkbox isn't relevant to the PR, mark it as done.

Solution

  • Updates request/response variant types
  • Adds a new argument to scan::start() for the scan task channel receiver
  • Adds ScanTask::remove_keys() method for sending a RemoveKeys message
  • Adds ScanTask::process_msgs() and calls it from the loop in scan::start()
  • Adds a delete_sapling_keys() method to Storage
  • Calls remove_keys() and delete_sapling_keys() from the ScanService match arm for Request::DeleteKeys

Testing

  • Tests that the new Storage::delete_sapling_results() method deletes all results for a provided key
  • Tests that the ScanService sends a message to the ScanTask to remove the keys and that it deletes the results before responding

Review

Anyone can review.

Reviewer Checklist

Check before approving the PR:

  • Does the PR scope match the ticket?
  • Are there enough tests to make sure it works? Do the tests cover the PR motivation?
  • Are all the PR blockers dealt with?
    PR blockers can be dealt with in new tickets or PRs.

And check the PR Author checklist is complete.

Follow Up Work

  • Add a test for ScanTask::process_msgs()

@arya2 arya2 added C-feature Category: New features A-blockchain-scanner Area: Blockchain scanner of shielded transactions P-Medium ⚡ labels Jan 31, 2024
@arya2 arya2 self-assigned this Jan 31, 2024
@arya2 arya2 requested review from a team as code owners January 31, 2024 03:08
@arya2 arya2 requested review from oxarbitrage and removed request for a team January 31, 2024 03:08
@arya2 arya2 added the A-concurrency Area: Async code, needs extra work to make it work properly. label Jan 31, 2024
@arya2 arya2 requested a review from upbqdn January 31, 2024 13:42
oxarbitrage
oxarbitrage previously approved these changes Jan 31, 2024
Copy link
Contributor

@oxarbitrage oxarbitrage left a comment

Choose a reason for hiding this comment

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

I think this looks really good. I left some of comments and questions but i don't think any of those are blockers.

zebra-scan/src/init.rs Outdated Show resolved Hide resolved
zebra-scan/src/init.rs Show resolved Hide resolved
zebra-scan/src/init.rs Show resolved Hide resolved
zebra-scan/src/scan.rs Show resolved Hide resolved
zebra-scan/src/service/tests.rs Show resolved Hide resolved
zebra-scan/src/service/tests.rs Show resolved Hide resolved
@arya2 arya2 requested a review from oxarbitrage January 31, 2024 17:34
Copy link
Contributor

@oxarbitrage oxarbitrage left a comment

Choose a reason for hiding this comment

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

thanks for the changes.

@mergify mergify bot merged commit 80827f5 into main Jan 31, 2024
133 checks passed
@mergify mergify bot deleted the scan-svc-del-keys branch January 31, 2024 19:34
Comment on lines +44 to +59
let response_fut = scan_service
.ready()
.await
.map_err(|err| eyre!(err))?
.call(Request::DeleteKeys(vec![zec_pages_sapling_efvk.clone()]));

let expected_keys = vec![zec_pages_sapling_efvk.clone()];
let cmd_handler_fut = tokio::task::spawn_blocking(move || {
let Ok(ScanTaskCommand::RemoveKeys { done_tx, keys }) = cmd_receiver.recv() else {
panic!("should successfully receive RemoveKeys message");
};

assert_eq!(keys, expected_keys, "keys should match the request keys");

done_tx.send(()).expect("send should succeed");
});
Copy link
Member

Choose a reason for hiding this comment

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

Optional Suggestion

This looks great. I wonder if we could use mocked services from zebra-test, for example: https://github.com/ZcashFoundation/zebra/blob/main/zebra-test/src/mock_service.rs and https://github.com/ZcashFoundation/zebra/blob/main/zebra-test/src/transcript.rs. I haven't used them yet, but I'll look into it.

) -> JoinHandle<Result<(), Report>> {
scan::spawn_init(config, network, state, chain_tip_change)
/// Sends a message to the scan task to remove the provided viewing keys.
pub fn remove_keys(
Copy link
Member

Choose a reason for hiding this comment

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

Optional Suggestion

I think it would be good to place this function into a different file since the filename is init.rs, but let's do that in a different PR?

// TODO: Replace with Arc::unwrap_or_clone() when it stabilises:
// https://github.com/rust-lang/rust/issues/93610
let mut updated_parsed_keys =
Arc::try_unwrap(parsed_keys).unwrap_or_else(|arc| (*arc).clone());
Copy link
Member

Choose a reason for hiding this comment

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

Optional Suggestion

Arc::get_mut might also have been an option here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-blockchain-scanner Area: Blockchain scanner of shielded transactions A-concurrency Area: Async code, needs extra work to make it work properly. C-feature Category: New features P-Medium ⚡
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement DeleteKeys scan service request to delete registered keys and any cached results for those keys
3 participants