Refactor engine to make it clear that we're actually checking the seal.

This commit is contained in:
Gav Wood 2016-03-01 17:23:44 +01:00
parent f705f6957a
commit afc0605080
2 changed files with 10 additions and 8 deletions

View File

@ -309,15 +309,10 @@ impl ClosedBlock {
pub fn try_seal(self, engine: &Engine, seal: Vec<Bytes>) -> Result<SealedBlock, ClosedBlock> { pub fn try_seal(self, engine: &Engine, seal: Vec<Bytes>) -> Result<SealedBlock, ClosedBlock> {
let mut s = self; let mut s = self;
s.block.base.header.set_seal(seal); s.block.base.header.set_seal(seal);
if let Err(e) = engine.verify_block_basic(&s.block.base.header, None) { match engine.verify_block_seal(&s.block.base.header) {
debug!("Failed to try_seal: {:?}", e); Err(_) => Err(s),
return Err(s); _ => Ok(SealedBlock { block: s.block, uncle_bytes: s.uncle_bytes }),
} }
if let Err(e) = engine.verify_block_unordered(&s.block.base.header, None) {
debug!("Failed to try_seal: {:?}", e);
return Err(s);
}
Ok(SealedBlock { block: s.block, uncle_bytes: s.uncle_bytes })
} }
/// Drop this object and return the underlieing database. /// Drop this object and return the underlieing database.

View File

@ -74,6 +74,13 @@ pub trait Engine : Sync + Send {
/// Verify a particular transaction is valid. /// Verify a particular transaction is valid.
fn verify_transaction(&self, _t: &SignedTransaction, _header: &Header) -> Result<(), Error> { Ok(()) } fn verify_transaction(&self, _t: &SignedTransaction, _header: &Header) -> Result<(), Error> { Ok(()) }
/// Verify the seal of a block. This is an auxilliary method that actually just calls other `verify_` methods
/// to get the job done. By default it must pass `verify_basic` and `verify_block_unordered`. If more or fewer
/// methods are needed for an Engine, this may be overridden.
fn verify_block_seal(&self, header: &Header) -> Result<(), Error> {
self.verify_block_basic(header, None).and_then(|_| self.verify_block_unordered(header, None))
}
/// Don't forget to call Super::populateFromParent when subclassing & overriding. /// Don't forget to call Super::populateFromParent when subclassing & overriding.
// TODO: consider including State in the params. // TODO: consider including State in the params.
fn populate_from_parent(&self, _header: &mut Header, _parent: &Header) {} fn populate_from_parent(&self, _header: &mut Header, _parent: &Header) {}