Fix block detail updating (#11015)

* Add finality parameter to `null engine`

* Add testcase for finalization marking in `ethcore` client

* Add double cache read for db

* Prevent lost update of block details

* Read with pending update for block details in batch
This commit is contained in:
Atkins
2019-09-06 01:27:05 +08:00
committed by David
parent 44c00b1f74
commit a89bbfe366
7 changed files with 117 additions and 8 deletions

View File

@@ -27,19 +27,26 @@ use machine::{
ExecutedBlock,
Machine,
};
use common_types::snapshot::Snapshotting;
use common_types::{
ancestry_action::AncestryAction,
header::ExtendedHeader,
snapshot::Snapshotting
};
/// Params for a null engine.
#[derive(Clone, Default)]
pub struct NullEngineParams {
/// base reward for a block.
pub block_reward: U256,
/// Immediate finalization.
pub immediate_finalization: bool
}
impl From<ethjson::spec::NullEngineParams> for NullEngineParams {
fn from(p: ethjson::spec::NullEngineParams) -> Self {
NullEngineParams {
block_reward: p.block_reward.map_or_else(Default::default, Into::into),
immediate_finalization: p.immediate_finalization.unwrap_or(false)
}
}
}
@@ -108,4 +115,13 @@ impl Engine for NullEngine {
fn params(&self) -> &CommonParams {
self.machine.params()
}
fn ancestry_actions(&self, _header: &Header, ancestry: &mut dyn Iterator<Item=ExtendedHeader>) -> Vec<AncestryAction> {
if self.params.immediate_finalization {
// always mark parent finalized
ancestry.take(1).map(|e| AncestryAction::MarkFinalized(e.header.hash())).collect()
} else {
Vec::new()
}
}
}