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

Fixed shared cache race on import #4194

Merged
merged 3 commits into from
Nov 25, 2019
Merged

Fixed shared cache race on import #4194

merged 3 commits into from
Nov 25, 2019

Conversation

arkpar
Copy link
Member

@arkpar arkpar commented Nov 25, 2019

  • Make sure cache is updated under impror lock so that the best block info is always consistent.
  • is_best functor was checked under cache lock, which was supposed to guarantee consistency. But in reality it does not, because cache is also updated when validating transactions outside of import lock. So this is removed.
  • Changed import lock to be Rwlock instead of Mutex for extra performance.

@arkpar arkpar added the A0-please_review Pull request needs code review. label Nov 25, 2019
Copy link
Contributor

@marcio-diaz marcio-diaz left a comment

Choose a reason for hiding this comment

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

looks good to me

Copy link
Contributor

@svyatonik svyatonik left a comment

Choose a reason for hiding this comment

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

LGTM. Probably this comment must be updated as well, because Backend actually acquires the lock itself starting from this PR. Also maybe worth mentioning that no states should be destroyed when import lock is held (this seems a bit fragile)?

@arkpar arkpar added A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Nov 25, 2019
@arkpar
Copy link
Member Author

arkpar commented Nov 25, 2019

LGTM. Probably this comment must be updated as well, because Backend actually acquires the lock itself starting from this PR. Also maybe worth mentioning that no states should be destroyed when import lock is held (this seems a bit fragile)?

Good point. It would be better to lock it outside.

@arkpar arkpar added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Nov 25, 2019
@@ -96,7 +96,10 @@ where
None,
)
.map(|(result, _, _)| result)?;
self.backend.destroy_state(state)?;
{
let _ = self.backend.get_import_lock().read();
Copy link
Member

Choose a reason for hiding this comment

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

That is not correct. It drops immediately the lock!

It is also not required to create a sub context here, as the functions end after it anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

That is not correct. It drops immediately the lock!

How so? The RwLockReadGuard returned by read lives till the end of the block.

It is also not required to create a sub context here, as the functions end after it anyway.

Here it actually makes sense because we don't want to hold the lock for the duration of into_encoded

Copy link
Member

Choose a reason for hiding this comment

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

@arkpar arkpar requested a review from bkchr November 25, 2019 11:06
@gavofyork gavofyork merged commit 6681ee1 into master Nov 25, 2019
@gavofyork gavofyork deleted the a-fix-cache-import-race branch November 25, 2019 12:38
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants