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

feat: ✨ MSP stop storing buckets for insolvent user task #366

Open
wants to merge 8 commits into
base: feat/stop-storing-bucket-insolvent-user
Choose a base branch
from

Conversation

TDemeco
Copy link
Contributor

@TDemeco TDemeco commented Feb 12, 2025

This PR adds the MspStopStoringInsolventUserTask, which is the task in charge of deleting the currently stored buckets that belong to a user that has become insolvent. This task:

  • Reacts initially to the UserWithoutFunds event from the runtime. When it receives it, checks if any of the MSP's stored buckets belongs to the now-insolvent user, and if it has at least one it queues up a StopStoringForInsolventUserRequest.
  • Reacts to the MspStopStoringBucketInsolventUser event from the runtime. When it receives it it executes the same logic as when reacting to the UserWithoutFunds. This is so after successfully deleting a bucket of the insolvent user, the MSP continues deleting if it has more buckets left.
  • Reacts to the ProcessStopStoringForInsolventUserRequest event from the blockchain service. This event is emitted when the task can acquire a forest write tx lock to process the previously emitted StopStoringForInsolventUserRequest.
    • It checks if the MSP is crrently storing any bucket from the insolvent user and, if it is, gets the bucket ID of one of them. To do this and avoid processing the same bucket multiple times, the process is as follows:
      • Gets the indexer database, and from it all the buckets that are marked as stored by this MSP and that belong to the insolvent user.
      • Then, from that list of buckets, gets the first bucket ID that both is currently still stored in the MSP's forest and that it's not marked as already processed.
        • This task keeps a HashSet of buckets that have been procesed (are not currently stored by the MSP according to the runtime) but have not yet been deleted, since bucket deletion waits for finality in case the msp_stop_storing_bucket_for_insolvent_user call gets reverted.
      • Finally, builds the msp_stop_storing_bucket_for_insolvent_user extrinsic and sends it.
      • Once the extrinsic is successful and gets included in a block, add this bucket to the HashSet of processed buckets that have not yet been deleted.
  • Reacts to the FinalisedMspStopStoringBucketInsolventUser (which is emitted when a block that contained a MspStopStoringBucketInsolventUser event gets finalised). When it receives it, it deletes the bucket from the forest storage and all that bucket's files from the file storage.

Pending TODOs:

  • Develop an integration test that comprehensively tests this flow. DONE

@TDemeco TDemeco requested review from ffarall and links234 February 12, 2025 02:32
@TDemeco TDemeco marked this pull request as ready for review February 12, 2025 21:00
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.

1 participant