epoch generation proof fixes

This commit is contained in:
Robert Habermeier 2017-04-22 18:56:01 +02:00
parent 023c45f302
commit 7ab92f0807
2 changed files with 15 additions and 13 deletions

View File

@ -256,10 +256,8 @@ impl Client {
// ensure genesis epoch proof in the DB.
{
let mut batch = DBTransaction::new();
let chain = client.chain.read();
client.generate_epoch_proof(&mut batch, &spec.genesis_header(), 0, &*chain);
client.db.read().write_buffered(batch);
client.generate_epoch_proof(&spec.genesis_header(), 0, &*chain);
}
if let Some(reg_addr) = client.additional_params().get("registrar").and_then(|s| Address::from_str(s).ok()) {
@ -611,10 +609,6 @@ impl Client {
state.journal_under(&mut batch, number, hash).expect("DB commit failed");
let route = chain.insert_block(&mut batch, block_data, receipts);
if let Some((header, epoch)) = entering_new_epoch {
self.generate_epoch_proof(&mut batch, &header, epoch, &chain);
}
self.tracedb.read().import(&mut batch, TraceImportRequest {
traces: traces.into(),
block_hash: hash.clone(),
@ -634,14 +628,19 @@ impl Client {
warn!("Failed to prune ancient state data: {}", e);
}
if let Some((header, epoch)) = entering_new_epoch {
self.generate_epoch_proof(&header, epoch, &chain);
}
route
}
// generate an epoch transition proof at the given block, and write it into the given blockchain.
fn generate_epoch_proof(&self, batch: &mut DBTransaction, header: &Header, epoch_number: u64, chain: &BlockChain) {
fn generate_epoch_proof(&self, header: &Header, epoch_number: u64, chain: &BlockChain) {
use std::cell::RefCell;
use std::collections::BTreeSet;
let mut batch = DBTransaction::new();
let hash = header.hash();
debug!(target: "client", "Generating validation proof for block {}", hash);
@ -664,13 +663,16 @@ impl Client {
// insert into database, using the generated proof.
match proof {
Ok(proof) =>
chain.insert_epoch_transition(batch, epoch_number, EpochTransition {
Ok(proof) => {
chain.insert_epoch_transition(&mut batch, epoch_number, EpochTransition {
block_hash: hash.clone(),
block_number: header.number(),
proof: proof,
state_proof: read_values.into_inner().into_iter().collect(),
}),
});
self.db.read().write_buffered(batch);
}
Err(e) => {
warn!(target: "client", "Error generating epoch change proof for block {}: {}", hash, e);
warn!(target: "client", "Snapshots generated by this node will be incomplete.");

View File

@ -170,8 +170,8 @@ impl ValidatorSet for ValidatorSafeContract {
Some(matched_event) => {
// decode log manually until the native contract generator is
// good enough to do it for us.
let &(_, _, ref nonce_token) = &matched_event.params[2];
let &(_, _, ref validators_token) = &matched_event.params[3];
let &(_, _, ref nonce_token) = &matched_event.params[1];
let &(_, _, ref validators_token) = &matched_event.params[2];
let nonce: Option<U256> = nonce_token.clone().to_uint()
.map(H256).map(Into::into);