store epoch transition proofs in DB
This commit is contained in:
@@ -76,7 +76,7 @@ impl ValidatorSet for ValidatorContract {
|
||||
self.validators.epoch_proof(header, caller)
|
||||
}
|
||||
|
||||
fn epoch_set(&self, header: &Header, proof: &[u8]) -> Result<(U256, super::SimpleList), ::error::Error> {
|
||||
fn epoch_set(&self, header: &Header, proof: &[u8]) -> Result<(u64, super::SimpleList), ::error::Error> {
|
||||
self.validators.epoch_set(header, proof)
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ mod multi;
|
||||
|
||||
use std::sync::Weak;
|
||||
use ids::BlockId;
|
||||
use util::{Address, H256, U256};
|
||||
use util::{Address, H256};
|
||||
use ethjson::spec::ValidatorSet as ValidatorSpec;
|
||||
use client::Client;
|
||||
use header::Header;
|
||||
@@ -97,7 +97,7 @@ pub trait ValidatorSet: Send + Sync {
|
||||
/// the proof is invalid.
|
||||
///
|
||||
/// Returns the epoch number and proof.
|
||||
fn epoch_set(&self, header: &Header, proof: &[u8]) -> Result<(U256, SimpleList), ::error::Error>;
|
||||
fn epoch_set(&self, header: &Header, proof: &[u8]) -> Result<(u64, SimpleList), ::error::Error>;
|
||||
|
||||
/// Checks if a given address is a validator, with the given function
|
||||
/// for executing synchronous calls to contracts.
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::Weak;
|
||||
use engines::{Call, EpochChange};
|
||||
use util::{H256, Address, RwLock, U256};
|
||||
use util::{H256, Address, RwLock};
|
||||
use ids::BlockId;
|
||||
use header::{BlockNumber, Header};
|
||||
use client::{Client, BlockChainClient};
|
||||
@@ -75,19 +75,24 @@ impl ValidatorSet for Multi {
|
||||
fn is_epoch_end(&self, header: &Header, block: Option<&[u8]>, receipts: Option<&[::receipt::Receipt]>)
|
||||
-> EpochChange
|
||||
{
|
||||
self.correct_set_by_number(header.number()).1.is_epoch_end(header, block, receipts)
|
||||
let (set_block, set) = self.correct_set_by_number(header.number());
|
||||
|
||||
match set.is_epoch_end(header, block, receipts) {
|
||||
EpochChange::Yes(num, proof) => EpochChange::Yes(set_block + num, proof),
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
|
||||
fn epoch_proof(&self, header: &Header, caller: &Call) -> Result<Vec<u8>, String> {
|
||||
self.correct_set_by_number(header.number()).1.epoch_proof(header, caller)
|
||||
}
|
||||
|
||||
fn epoch_set(&self, header: &Header, proof: &[u8]) -> Result<(U256, super::SimpleList), ::error::Error> {
|
||||
fn epoch_set(&self, header: &Header, proof: &[u8]) -> Result<(u64, super::SimpleList), ::error::Error> {
|
||||
// "multi" epoch is the inner set's epoch plus the transition block to that set.
|
||||
// ensures epoch increases monotonically.
|
||||
let (set_block, set) = self.correct_set_by_number(header.number());
|
||||
let (inner_epoch, list) = set.epoch_set(header, proof)?;
|
||||
Ok((U256::from(set_block) + inner_epoch, list))
|
||||
Ok((set_block + inner_epoch, list))
|
||||
}
|
||||
|
||||
fn contains_with_caller(&self, bh: &H256, address: &Address, caller: &Call) -> bool {
|
||||
|
||||
@@ -165,8 +165,6 @@ impl ValidatorSet for ValidatorSafeContract {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// TODO: are multiple transitions per block possible?
|
||||
match decoded_events.next() {
|
||||
None => ::engines::EpochChange::No,
|
||||
Some(matched_event) => {
|
||||
@@ -184,8 +182,11 @@ impl ValidatorSet for ValidatorSafeContract {
|
||||
);
|
||||
|
||||
match (nonce, validators) {
|
||||
(Some(nonce), Some(validators)) =>
|
||||
::engines::EpochChange::Yes(encode_proof(nonce, &validators)),
|
||||
(Some(nonce), Some(validators)) => {
|
||||
let proof = encode_proof(nonce, &validators);
|
||||
let new_epoch = nonce.low_u64();
|
||||
::engines::EpochChange::Yes(new_epoch, proof)
|
||||
}
|
||||
_ => {
|
||||
debug!(target: "engine", "Successfully decoded log turned out to be bad.");
|
||||
::engines::EpochChange::No
|
||||
@@ -206,11 +207,11 @@ impl ValidatorSet for ValidatorSafeContract {
|
||||
}
|
||||
}
|
||||
|
||||
fn epoch_set(&self, _header: &Header, proof: &[u8]) -> Result<(U256, SimpleList), ::error::Error> {
|
||||
fn epoch_set(&self, _header: &Header, proof: &[u8]) -> Result<(u64, SimpleList), ::error::Error> {
|
||||
use rlp::UntrustedRlp;
|
||||
|
||||
let rlp = UntrustedRlp::new(proof);
|
||||
let nonce: U256 = rlp.val_at(0)?;
|
||||
let nonce: u64 = rlp.val_at(0)?;
|
||||
let validators: Vec<Address> = rlp.list_at(1)?;
|
||||
|
||||
Ok((nonce, SimpleList::new(validators)))
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
/// Preconfigured validator list.
|
||||
|
||||
use util::{H256, Address, HeapSizeOf, U256};
|
||||
use util::{H256, Address, HeapSizeOf};
|
||||
|
||||
use engines::Call;
|
||||
use header::Header;
|
||||
@@ -63,8 +63,8 @@ impl ValidatorSet for SimpleList {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
fn epoch_set(&self, _header: &Header, _: &[u8]) -> Result<(U256, SimpleList), ::error::Error> {
|
||||
Ok((0.into(), self.clone()))
|
||||
fn epoch_set(&self, _header: &Header, _: &[u8]) -> Result<(u64, SimpleList), ::error::Error> {
|
||||
Ok((0, self.clone()))
|
||||
}
|
||||
|
||||
fn contains_with_caller(&self, _bh: &H256, address: &Address, _: &Call) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user