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:
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user