Support running TendermintMachine when not a validator

This supports validators who leave the current set, without crashing 
their nodes, along with nodes trying to become validators (who will now 
seamlessly transition in).
This commit is contained in:
Luke Parker
2022-11-11 06:04:37 -05:00
parent dbcddb2fb0
commit 43b43bdbd9
4 changed files with 20 additions and 22 deletions

View File

@@ -123,17 +123,14 @@ impl<T: TendermintClient> Signer for TendermintSigner<T> {
type ValidatorId = u16;
type Signature = Signature;
async fn validator_id(&self) -> u16 {
async fn validator_id(&self) -> Option<u16> {
let key = self.get_public_key().await;
for (i, k) in (*self.1 .0).read().unwrap().lookup.iter().enumerate() {
if k == &key {
return u16::try_from(i).unwrap();
return Some(u16::try_from(i).unwrap());
}
}
// TODO: Enable switching between being a validator and not being one, likely be returning
// Option<u16> here. Non-validators should be able to simply not broadcast when they think
// they have messages.
panic!("not a validator");
None
}
async fn sign(&self, msg: &[u8]) -> Signature {