seals_internally (#4613)

This commit is contained in:
keorn
2017-02-20 15:35:53 +00:00
committed by Gav Wood
parent 44769fcd4a
commit ac6180a6fe
6 changed files with 33 additions and 32 deletions

View File

@@ -220,8 +220,8 @@ impl Engine for AuthorityRound {
});
}
fn is_sealer(&self, author: &Address) -> Option<bool> {
Some(self.validators.contains(author))
fn seals_internally(&self) -> Option<bool> {
Some(self.validators.contains(&self.signer.address()))
}
/// Attempt to seal the block internally.

View File

@@ -103,8 +103,8 @@ impl Engine for BasicAuthority {
});
}
fn is_sealer(&self, author: &Address) -> Option<bool> {
Some(self.validators.contains(author))
fn seals_internally(&self) -> Option<bool> {
Some(self.validators.contains(&self.signer.address()))
}
/// Attempt to seal the block internally.
@@ -268,7 +268,8 @@ mod tests {
let authority = tap.insert_account(Secret::from_slice(&"".sha3()).unwrap(), "").unwrap();
let engine = new_test_authority().engine;
assert!(!engine.is_sealer(&Address::default()).unwrap());
assert!(engine.is_sealer(&authority).unwrap());
assert!(!engine.seals_internally().unwrap());
engine.set_signer(Arc::new(tap), authority, "".into());
assert!(engine.seals_internally().unwrap());
}
}

View File

@@ -56,7 +56,7 @@ impl Engine for InstantSeal {
Schedule::new_post_eip150(usize::max_value(), true, true, true)
}
fn is_sealer(&self, _author: &Address) -> Option<bool> { Some(true) }
fn seals_internally(&self) -> Option<bool> { Some(true) }
fn generate_seal(&self, _block: &ExecutedBlock) -> Seal {
Seal::Regular(Vec::new())

View File

@@ -128,11 +128,10 @@ pub trait Engine : Sync + Send {
/// Block transformation functions, after the transactions.
fn on_close_block(&self, _block: &mut ExecutedBlock) {}
/// If Some(true) this author is able to generate seals, generate_seal has to be implemented.
/// None indicates that this Engine never seals internally regardless of author (e.g. PoW).
fn is_sealer(&self, _author: &Address) -> Option<bool> { None }
/// Checks if default address is able to seal.
fn is_default_sealer(&self) -> Option<bool> { self.is_sealer(&Default::default()) }
/// None means that it requires external input (e.g. PoW) to seal a block.
/// Some(true) means the engine is currently prime for seal generation (i.e. node is the current validator).
/// Some(false) means that the node might seal internally but is not qualified now.
fn seals_internally(&self) -> Option<bool> { None }
/// Attempt to seal the block internally.
///
/// If `Some` is returned, then you get a valid seal.

View File

@@ -410,8 +410,8 @@ impl Engine for Tendermint {
}
/// Should this node participate.
fn is_sealer(&self, address: &Address) -> Option<bool> {
Some(self.is_authority(address))
fn seals_internally(&self) -> Option<bool> {
Some(self.is_authority(&self.signer.address()))
}
/// Attempt to seal generate a proposal seal.