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

Fixes initialisation process on the web frontend #166

Merged
merged 11 commits into from
Sep 22, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ const useChangeAction = (

// TODO: can be modified such that if the majority of the node are
// initialized than the election status can still be set to initialized
const promises = Array.from(nodeProxyAddresses.values()).map((proxy) => {
if (proxy !== '') {
const promises = Array.from(nodeProxyAddresses).map(([node, proxy]) => {
if (proxy !== '' && DKGStatuses.get(node) === NodeStatus.NotInitialized) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is enough to prevent the initialization of nodes that were already initialized, because of this cough beautiful Promise.all (I'm sorry .....) line 221, which either set them all up to Initialized or none...

I think one way to do this would be to use the component DKGStatusRow, so that each node initializes itself and polls it own status. useChangeAction could then be notified of the changes via the states in DKGStatuses ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Luckily that works in this case, because "undefined" (and any other non-promise values) count as "resolved". 🙃

I think one way to do this would be to use the component DKGStatusRow, so that each node initializes itself and polls it own status. useChangeAction could then be notified of the changes via the states in DKGStatuses ?

Yes, that would be much better indeed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes but it will return undefined only if the proxy address of the node could not be found (i.e proxy===''). Otherwise in pollDKG:

// Add a timeout
if (attempts === maxAttempts) {
    throw new Error('Timeout');
}
...
catch (e) {
   return reject(e);
}

So if during the poll one of the node times out for some reason the Promise will be rejected thus the Promise.all will resolve to rejected for all of them. And the request to initialize will again be sent for all the nodes ...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh yes, that's true :/

Copy link
Contributor

Choose a reason for hiding this comment

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

I can try to solve this this coming week since it will be the start of term, but after that I probably won't have the time anymore 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the DKG logic to DKGStatusRow, as suggested. That wasn't straightforward as there are probably still too much states spread around between useChangeAction.tsx, Show.tsx, and DKGStatusRow.tsx. Having your input on that would help, if you are willing to :)

Copy link
Contributor

Choose a reason for hiding this comment

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

It's already so much better ! But yes there are way too many states to be passed around, it's a bit cumbersome ....

return initialize(proxy);
}
return undefined;
Expand Down