poanetwork / hydrabadger

A simple, experimental, peer-to-peer network node using the hbbft consensus algorithm which can be run as a standalone client or used as a library
GNU General Public License v3.0
22 stars 9 forks source link

Mechanism for adding / removing validators #27

Open KORuL opened 5 years ago

KORuL commented 5 years ago

Hi! We use this repo for creating crypto-based messenger app. The are some issues and improvements suggestoins we want to introduce. It would be cool if you add the following capablities we need:

afck commented 5 years ago

Isn't that already implemented? If you call Hydrabadger::vote_for in a majority of the current validators, the change should automatically be carried out within a few epochs—it doesn't work instantly because distributed key generation (DKG) has to complete before the changed validator set can take over consensus.

When we were experimenting with integrating this with Parity—which is something we still intend to do, but is paused for now—, we came to the conclusion that in our case it was better to handle validator set changes (including DKG) on a higher level, and were even considering removing this functionality from hydrabadger again! (Happy to discuss that in more detail, if you're interested.) For a messenger app, I can imagine that it's more convenient this way, though, so let's keep DKG in hydrabadger and make sure it works. Let us know if you find bugs in it!

KORuL commented 5 years ago

And you can provide the simplest example for sample?

c0gent commented 5 years ago

@KORuL, The details of precisely what happens when the validator set changes (e.g. nodes connect/disconnect) has been in a state of flux for some time, partly due to the fact that we had decided to perform DKG using the blockchain itself (though that work is incomplete).

As @afck mentioned, doing something like the following (on all [or most] validator nodes):

use hydrabadger::Change;
...
let new_validator_public_keys: BTreeMap<NodeId, PublicKey> = ...;
hydrabadger.vote_for(Change::NodeChange(new_validator_public_keys)?

will eventually update the list of validators but will not 'disconnect' them cleanly (within hydrabadger). I had intended to use the WireMessageKind::Goodbye enum variant, broadcast to each node, for this purpose.

I'll have a closer look at this when I get around to it or please feel free to submit a pull request with the appropriate changes.