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

Pub sub blocks #6139

Merged
merged 21 commits into from
Sep 1, 2017
Merged

Pub sub blocks #6139

merged 21 commits into from
Sep 1, 2017

Conversation

CraigglesO
Copy link
Contributor

@CraigglesO CraigglesO commented Jul 25, 2017

@kaikun213 -

  1. Not entirely sure I am using unsubscribe properly, would like you to verify,
  2. I changed localTransactions, if that causes any problems let me know, just needed more control.

@gavofyork gavofyork added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. M7-ui and removed M4-core ⛓ Core client code / Rust. labels Jul 25, 2017
@@ -79,7 +79,7 @@ impl<C, M, S: ?Sized, U> ParityClient<C, M, S, U> where
U: UpdateService,
{
/// Creates new `ParityClient`.
pub fn new(
pub fn new (
Copy link
Contributor

Choose a reason for hiding this comment

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

please revert this change

Copy link
Contributor

@kaikun213 kaikun213 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. You can also save the promise and then unsubscribe with resolving the promise. Otherwise it can happen that you unsubscribe before even having the subscriptionId, which would be invalid and have to be repeated.

I'm not sure where local transactions are all used but seems fine @jacogr .

Copy link
Collaborator

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

Couple grumbles.

Cargo.lock Outdated
@@ -418,6 +418,14 @@ dependencies = [
]

[[package]]
name = "error-chain"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like those changes are unnecessary.

}

stopPolling () {
Object.keys(this._timeoutIds).forEach((key) => clearTimeout(this._timeoutIds[key]));
if (this.subscriptionId) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should wait for subscriptionId, otherwise if you stopPolling before the promises in startPolling are resolved you may end up with dangling subscription.

@@ -49,8 +49,8 @@ export default class SignerStore {
}

@action unsubscribe () {
if (this._timeoutId) {
clearTimeout(this._timeoutId);
if (this.subscriptionId) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It should always wait for subscription id, otherwise you may end up with a dangling subscription.

@@ -88,20 +88,18 @@ export default class SignerStore {
}

fetchLocalTransactions = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The name suggests that the transactions will be fetched, but actually it sets up a subscription.
The name should be altered and it should be ensured that the method is never called more than once.

})
.then((subscriptionId) => {
this.subscriptionId = subscriptionId;
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be good to at least log errors here.

this.blockNumber = block.number;
this.blockTimestamp = block.timestamp;
this._pollMinerSettings();
return Promise
Copy link
Collaborator

Choose a reason for hiding this comment

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

return here is misleading, it looks a bit like then(subscriptionId) is chained to this promise, but it's not.

})
.then((subscriptionId) => {
this.subscriptionId = subscriptionId;
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be good to at least log errors.

@tomusdrw tomusdrw added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Aug 2, 2017
@CraigglesO
Copy link
Contributor Author

cleaned up and handles all errors/use cases. Lemme know what you think.

const self = this;

if (self.subscribed) {
if (!self.subscriptionId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can simplify the code by saving the promise itself as subscription and then resolving it in unsubscribe.
This works fine when the id does not need to get exposed.
E.g. like here in the bonds library

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I understand your design now and how nice that is. Sorry I didn't fully understand your first comment.

@CraigglesO CraigglesO added A0-pleasereview 🤓 Pull request needs code review. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Aug 7, 2017
@gavofyork
Copy link
Contributor

@tomusdrw could you take a look at this?

@tomusdrw tomusdrw added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Aug 30, 2017
});
return transactions;
});
: callback(null, transactions);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we get rid of the outTransaction here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch. Brought it back.

@tomusdrw
Copy link
Collaborator

@ngotchac Fixed, please have a look.

Copy link
Contributor

@ngotchac ngotchac left a comment

Choose a reason for hiding this comment

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

LGTM. I just think that the NodeStatus/store should be a singleton, instanciated once. But this was introduced in another PR so...

@tomusdrw tomusdrw merged commit 56f46ed into master Sep 1, 2017
@tomusdrw tomusdrw deleted the pub-sub-blocks branch September 1, 2017 10:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants