engine changes
This commit is contained in:
@@ -25,15 +25,12 @@ use std::sync::Weak;
|
||||
use util::{Address, H256};
|
||||
use ethjson::spec::ValidatorSet as ValidatorSpec;
|
||||
use client::Client;
|
||||
use receipt::Receipt;
|
||||
|
||||
use self::simple_list::SimpleList;
|
||||
use self::contract::ValidatorContract;
|
||||
use self::safe_contract::ValidatorSafeContract;
|
||||
use self::multi::Multi;
|
||||
|
||||
pub type Call = Fn(Address, Vec<u8>) -> Result<Vec<u8>, String>;
|
||||
|
||||
/// Creates a validator set from spec.
|
||||
pub fn new_validator_set(spec: ValidatorSpec) -> Box<ValidatorSet> {
|
||||
match spec {
|
||||
@@ -48,10 +45,6 @@ pub fn new_validator_set(spec: ValidatorSpec) -> Box<ValidatorSet> {
|
||||
|
||||
/// A validator set.
|
||||
pub trait ValidatorSet: Send + Sync {
|
||||
/// Get this validator set as a flexible validator set.
|
||||
/// Returning `None` indicates this is only usable for
|
||||
/// full nodes.
|
||||
fn as_memoized(&self) -> Option<&Memoized> { None }
|
||||
/// Checks if a given address is a validator.
|
||||
fn contains(&self, parent_block_hash: &H256, address: &Address) -> bool;
|
||||
/// Draws an validator nonce modulo number of validators.
|
||||
@@ -65,35 +58,3 @@ pub trait ValidatorSet: Send + Sync {
|
||||
/// Allows blockchain state access.
|
||||
fn register_contract(&self, _client: Weak<Client>) {}
|
||||
}
|
||||
|
||||
/// A flexible validator set can track its changes.
|
||||
pub trait FlexibleValidatorSet: Send + Sync {
|
||||
/// Whether a validator set may have changed at this header.
|
||||
fn has_possibly_changed(&self, header: &Header) -> bool;
|
||||
|
||||
/// Whether a validator set has changed at this header, given the block receipts.
|
||||
/// Called after `has_possibly_changed`.
|
||||
/// `Some` indicates the validator set has changed at this header and the new
|
||||
/// expected validator set.
|
||||
/// `None` indicates no change.
|
||||
fn has_changed(&self, header: &Header, receipts: &[Receipt]) -> Option<SimpleList>;
|
||||
|
||||
/// Fetch validators at a block synchronously.
|
||||
fn fetch_validators(&self, header: &Header, call: &Call) -> Result<SimpleList, String>;
|
||||
}
|
||||
|
||||
/// A memoized flexible validator set
|
||||
pub struct Memoized {
|
||||
inner: Box<FlexibleValidatorSet>,
|
||||
memo: Mutex<(SimpleList, (H256, u64))>,
|
||||
}
|
||||
|
||||
impl Memoized {
|
||||
/// Denote that the
|
||||
pub fn use_memo_at(&self, list: SimpleList)
|
||||
}
|
||||
|
||||
impl ValidatorSet for Memoized {
|
||||
fn as_memoized(&self) -> Option<&Memoized> { Some(self) }
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ impl Multi {
|
||||
) {
|
||||
Ok((block, set)) => {
|
||||
trace!(target: "engine", "Multi ValidatorSet retrieved for block {}.", block);
|
||||
Some(&*set)
|
||||
Some(&**set)
|
||||
},
|
||||
Err(e) => {
|
||||
debug!(target: "engine", "ValidatorSet could not be recovered: {}", e);
|
||||
@@ -66,21 +66,6 @@ impl Multi {
|
||||
}
|
||||
|
||||
impl ValidatorSet for Multi {
|
||||
fn has_possibly_changed(&self, header: &Header) -> bool {
|
||||
// if the sets are the same for each header, compare those.
|
||||
// otherwise, the sets have almost certainly changed.
|
||||
match (self.correct_set(&header.hash()), self.correct_set(header.parent_hash())) {
|
||||
(Some(a), Some(b)) if a as *const _ == b as *const _ => { a.has_possibly_changed(header) },
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn has_changed(&self, header: &Header, receipts: &[Receipt]) -> Option<Vec<Address>> {
|
||||
|
||||
}
|
||||
|
||||
fn fetch(&self) ->
|
||||
|
||||
fn contains(&self, bh: &H256, address: &Address) -> bool {
|
||||
self.correct_set(bh).map_or(false, |set| set.contains(bh, address))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user