Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ethcore/light/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl<T: ChainDataFetcher> Client<T> {
The node may not be able to synchronize further.", e);
}

let epoch_proof = self.engine.is_epoch_end(
let epoch_proof = self.engine.is_epoch_end_light(
&verified_header,
&|h| self.chain.block_header(BlockId::Hash(h)).and_then(|hdr| hdr.decode().ok()),
&|h| self.chain.pending_transition(h),
Expand Down
23 changes: 16 additions & 7 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ impl Importer {
let number = header.number();
let parent = header.parent_hash();
let chain = client.chain.read();
let is_finalized = false;
let mut is_finalized = false;

// Commit results
let block = block.drain();
Expand Down Expand Up @@ -536,10 +536,18 @@ impl Importer {

state.journal_under(&mut batch, number, hash).expect("DB commit failed");

for ancestry_action in ancestry_actions {
let AncestryAction::MarkFinalized(ancestry) = ancestry_action;
chain.mark_finalized(&mut batch, ancestry).expect("Engine's ancestry action must be known blocks; qed");
}
let finalized: Vec<_> = ancestry_actions.into_iter().map(|ancestry_action| {
let AncestryAction::MarkFinalized(a) = ancestry_action;

if a != header.hash() {
chain.mark_finalized(&mut batch, a).expect("Engine's ancestry action must be known blocks; qed");
} else {
// we're finalizing the current block
is_finalized = true;
}

a
}).collect();

let route = chain.insert_block(&mut batch, block_data, receipts.clone(), ExtrasInsert {
fork_choice: fork_choice,
Expand All @@ -560,7 +568,7 @@ impl Importer {
client.db.read().key_value().write_buffered(batch);
chain.commit();

self.check_epoch_end(&header, &chain, client);
self.check_epoch_end(&header, &finalized, &chain, client);

client.update_last_hashes(&parent, hash);

Expand Down Expand Up @@ -667,9 +675,10 @@ impl Importer {
}

// check for ending of epoch and write transition if it occurs.
fn check_epoch_end<'a>(&self, header: &'a Header, chain: &BlockChain, client: &Client) {
fn check_epoch_end<'a>(&self, header: &'a Header, finalized: &'a [H256], chain: &BlockChain, client: &Client) {
let is_epoch_end = self.engine.is_epoch_end(
header,
finalized,
&(|hash| client.block_header_decoded(BlockId::Hash(hash))),
&(|hash| chain.get_pending_transition(hash)), // TODO: limit to current epoch.
);
Expand Down
17 changes: 5 additions & 12 deletions ethcore/src/engines/authority_round/finality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ impl RollingFinality {
}

/// Get an iterator over stored hashes in order.
pub fn unfinalized_hashes(&self) -> Iter { Iter(self.headers.iter()) }
#[cfg(test)]
pub fn unfinalized_hashes(&self) -> impl Iterator<Item=&H256> {
self.headers.iter().map(|(h, _)| h)
}

/// Get the validator set.
pub fn validators(&self) -> &SimpleList { &self.signers }
Expand Down Expand Up @@ -145,16 +148,6 @@ impl RollingFinality {
}
}

pub struct Iter<'a>(::std::collections::vec_deque::Iter<'a, (H256, Vec<Address>)>);

impl<'a> Iterator for Iter<'a> {
type Item = H256;

fn next(&mut self) -> Option<H256> {
self.0.next().map(|&(h, _)| h)
}
}

#[cfg(test)]
mod tests {
use ethereum_types::{H256, Address};
Expand Down Expand Up @@ -220,7 +213,7 @@ mod tests {

// only the last hash has < 51% of authorities' signatures
assert_eq!(finality.unfinalized_hashes().count(), 1);
assert_eq!(finality.unfinalized_hashes().next(), Some(hashes[11].0));
assert_eq!(finality.unfinalized_hashes().next(), Some(&hashes[11].0));
assert_eq!(finality.subchain_head(), Some(hashes[11].0));
}
}
Loading