Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

pow: add Version for quick-check of metadata state and refactor lock handling #9698

Merged
6 commits merged into from
Oct 12, 2021

Conversation

sorpaas
Copy link
Member

@sorpaas sorpaas commented Sep 5, 2021

This PR adds a Version field into the mining worker, an atomic value that is incremented every time the metadata is changed. It acts as a quick check for mining threads to determine if they need to fetch the metadata again.

The code is also refactored that now it handles all locking internally -- the MiningHandle interface is mostly same as the previous MiningWorker, but it handles locks itself instead of exposing an Mutex.

We keep using an Mutex for build (instead of a RwLock). While this is a one writer, multiple reader case, write priority is much more important than read, because we have to immediately notify miners of a metadata change, otherwise any work done is invalid anyway.

@sorpaas sorpaas added A0-please_review Pull request needs code review. B3-apinoteworthy C1-low PR touches the given topic and has a low impact on builders. labels Sep 5, 2021
@Wizdave97
Copy link
Contributor

@sorpaas anyway to get this merged quickly, It works and I kinda need it urgently

Copy link
Contributor

@andresilva andresilva left a comment

Choose a reason for hiding this comment

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

Didn't understand where the version will be used though.

@sorpaas
Copy link
Member Author

sorpaas commented Oct 12, 2021

Didn't understand where the version will be used though.

I added an example here kulupu/kulupu#168. Properly using it can avoid unnecessary data fetch in the mining lifecycle (checking if metadata is updated, computing the pre-mining information, etc) because we know for sure nothing has changed.

@sorpaas
Copy link
Member Author

sorpaas commented Oct 12, 2021

bot merge

@ghost
Copy link

ghost commented Oct 12, 2021

Trying merge.

@ghost ghost merged commit e308d0f into master Oct 12, 2021
@ghost ghost deleted the sp-pow-metadata-version branch October 12, 2021 03:50
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants