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 SyncState #3297

Merged
merged 2 commits into from
Apr 20, 2020
Merged

Conversation

hashmap
Copy link
Contributor

@hashmap hashmap commented Apr 16, 2020

Method sync_error() return type was simplified.
update_txhashset_download() was made type safe, which eliminates a runtime enum variant's check. As a bonus matching code is shorter and simpler when we do a partial destructuing, which happens quite often.

Method sync_error() retrun type was simplified.
update_txhashset_download() was  made type safe, which eliminates a runtime enum variant's  check
Copy link
Member

@antiochp antiochp left a comment

Choose a reason for hiding this comment

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

Makes sense to me.
Question about the RwLockReadGuard. This feels like a leaky abstraction to me.
The must be a way around this somehow. Maybe we need to reconstruct the actual error somehow from its low level contents.

chain/src/types.rs Outdated Show resolved Hide resolved
Copy link
Member

@antiochp antiochp left a comment

Choose a reason for hiding this comment

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

👍

@@ -114,37 +144,54 @@ impl SyncState {
}

/// Update the syncing status
pub fn update(&self, new_status: SyncStatus) {
if self.status() == new_status {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check is not great, we take a read lock, compare and then release the lock, so when we obtain a write lock the state may be different already.

/// Update the syncing status if predicate f is satisfied
pub fn update_if<F>(&self, new_status: SyncStatus, f: F) -> bool
where
F: Fn(SyncStatus) -> bool,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's a bit awkward to have predicate here, but some variants of SyncStatus have state attached which makes matching painful

/// Communicate sync error
pub fn set_sync_error(&self, error: Error) {
*self.sync_error.write() = Some(error);
}

/// Get sync error
pub fn sync_error(&self) -> Arc<RwLock<Option<Error>>> {
Arc::clone(&self.sync_error)
pub fn sync_error(&self) -> Option<String> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need Error per se, just the fact of its existence and description, returning String makes life much easier

Copy link
Member

Choose a reason for hiding this comment

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

👍 yeah that makes sense.

@hashmap hashmap merged commit d8c6eef into mimblewimble:master Apr 20, 2020
@hashmap hashmap deleted the refactor-sync-status branch April 20, 2020 10:30
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