Merge with master

This commit is contained in:
Anton Gavrilov
2017-08-02 17:24:34 +02:00
158 changed files with 14603 additions and 959 deletions

View File

@@ -17,8 +17,10 @@
//! A blockchain engine that supports a non-instant BFT proof-of-authority.
use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering};
use std::sync::Weak;
use std::sync::{Weak, Arc};
use std::time::{UNIX_EPOCH, Duration};
use std::collections::{BTreeMap, HashSet, HashMap};
use std::cmp;
use account_provider::AccountProvider;
use block::*;
@@ -446,9 +448,9 @@ impl Engine for AuthorityRound {
let gas_limit = parent.gas_limit().clone();
let bound_divisor = self.params().gas_limit_bound_divisor;
if gas_limit < gas_floor_target {
min(gas_floor_target, gas_limit + gas_limit / bound_divisor - 1.into())
cmp::min(gas_floor_target, gas_limit + gas_limit / bound_divisor - 1.into())
} else {
max(gas_floor_target, gas_limit - gas_limit / bound_divisor + 1.into())
cmp::max(gas_floor_target, gas_limit - gas_limit / bound_divisor + 1.into())
}
});
}
@@ -515,7 +517,7 @@ impl Engine for AuthorityRound {
fn on_new_block(
&self,
block: &mut ExecutedBlock,
last_hashes: Arc<::evm::env_info::LastHashes>,
last_hashes: Arc<::vm::LastHashes>,
epoch_begin: bool,
) -> Result<(), Error> {
let parent_hash = block.fields().header.parent_hash().clone();
@@ -813,7 +815,7 @@ impl Engine for AuthorityRound {
}
}
fn verify_transaction_basic(&self, t: &UnverifiedTransaction, header: &Header) -> result::Result<(), Error> {
fn verify_transaction_basic(&self, t: &UnverifiedTransaction, header: &Header) -> Result<(), Error> {
t.check_low_s()?;
if let Some(n) = t.network_id() {
@@ -849,6 +851,7 @@ impl Engine for AuthorityRound {
#[cfg(test)]
mod tests {
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
use util::*;
use header::Header;
@@ -939,10 +942,10 @@ mod tests {
let addr = tap.insert_account("0".sha3().into(), "0").unwrap();
let mut parent_header: Header = Header::default();
parent_header.set_seal(vec![encode(&0usize).into_vec()]);
parent_header.set_gas_limit(U256::from_str("222222").unwrap());
parent_header.set_gas_limit("222222".parse::<U256>().unwrap());
let mut header: Header = Header::default();
header.set_number(1);
header.set_gas_limit(U256::from_str("222222").unwrap());
header.set_gas_limit("222222".parse::<U256>().unwrap());
header.set_author(addr);
let engine = Spec::new_test_round().engine;
@@ -965,10 +968,10 @@ mod tests {
let mut parent_header: Header = Header::default();
parent_header.set_seal(vec![encode(&0usize).into_vec()]);
parent_header.set_gas_limit(U256::from_str("222222").unwrap());
parent_header.set_gas_limit("222222".parse::<U256>().unwrap());
let mut header: Header = Header::default();
header.set_number(1);
header.set_gas_limit(U256::from_str("222222").unwrap());
header.set_gas_limit("222222".parse::<U256>().unwrap());
header.set_author(addr);
let engine = Spec::new_test_round().engine;
@@ -991,10 +994,10 @@ mod tests {
let mut parent_header: Header = Header::default();
parent_header.set_seal(vec![encode(&4usize).into_vec()]);
parent_header.set_gas_limit(U256::from_str("222222").unwrap());
parent_header.set_gas_limit("222222".parse::<U256>().unwrap());
let mut header: Header = Header::default();
header.set_number(1);
header.set_gas_limit(U256::from_str("222222").unwrap());
header.set_gas_limit("222222".parse::<U256>().unwrap());
header.set_author(addr);
let engine = Spec::new_test_round().engine;
@@ -1028,10 +1031,10 @@ mod tests {
let mut parent_header: Header = Header::default();
parent_header.set_seal(vec![encode(&1usize).into_vec()]);
parent_header.set_gas_limit(U256::from_str("222222").unwrap());
parent_header.set_gas_limit("222222".parse::<U256>().unwrap());
let mut header: Header = Header::default();
header.set_number(1);
header.set_gas_limit(U256::from_str("222222").unwrap());
header.set_gas_limit("222222".parse::<U256>().unwrap());
header.set_seal(vec![encode(&3usize).into_vec()]);
// Do not report when signer not present.

View File

@@ -16,7 +16,9 @@
//! A blockchain engine that supports a basic, non-BFT proof-of-authority.
use std::sync::Weak;
use std::sync::{Weak, Arc};
use std::collections::BTreeMap;
use std::cmp;
use util::*;
use ethkey::{recover, public_to_address, Signature};
use account_provider::AccountProvider;
@@ -116,9 +118,9 @@ impl Engine for BasicAuthority {
let gas_limit = parent.gas_limit().clone();
let bound_divisor = self.params().gas_limit_bound_divisor;
if gas_limit < gas_floor_target {
min(gas_floor_target, gas_limit + gas_limit / bound_divisor - 1.into())
cmp::min(gas_floor_target, gas_limit + gas_limit / bound_divisor - 1.into())
} else {
max(gas_floor_target, gas_limit - gas_limit / bound_divisor + 1.into())
cmp::max(gas_floor_target, gas_limit - gas_limit / bound_divisor + 1.into())
}
});
}
@@ -142,7 +144,7 @@ impl Engine for BasicAuthority {
Seal::None
}
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
// check the seal fields.
// TODO: pull this out into common code.
if header.seal().len() != self.seal_fields() {
@@ -153,11 +155,11 @@ impl Engine for BasicAuthority {
Ok(())
}
fn verify_block_unordered(&self, _header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
fn verify_block_unordered(&self, _header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
Ok(())
}
fn verify_block_family(&self, header: &Header, parent: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> {
fn verify_block_family(&self, header: &Header, parent: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
// Do not calculate difficulty for genesis blocks.
if header.number() == 0 {
return Err(From::from(BlockError::RidiculousNumber(OutOfBounds { min: Some(1), max: None, found: header.number() })));
@@ -249,6 +251,7 @@ impl Engine for BasicAuthority {
#[cfg(test)]
mod tests {
use std::sync::Arc;
use util::*;
use block::*;
use error::{BlockError, Error};

View File

@@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::collections::BTreeMap;
use util::{Address, HashMap};
use std::collections::{BTreeMap, HashMap};
use util::Address;
use builtin::Builtin;
use engines::{Engine, Seal};
use spec::CommonParams;
@@ -63,6 +63,7 @@ impl Engine for InstantSeal {
#[cfg(test)]
mod tests {
use std::sync::Arc;
use util::*;
use tests::helpers::*;
use spec::Spec;

View File

@@ -35,7 +35,9 @@ pub use self::instant_seal::InstantSeal;
pub use self::null_engine::NullEngine;
pub use self::tendermint::Tendermint;
use std::sync::Weak;
use std::sync::{Weak, Arc};
use std::collections::{BTreeMap, HashMap};
use std::fmt;
use self::epoch::PendingTransition;
@@ -43,16 +45,14 @@ use account_provider::AccountProvider;
use block::ExecutedBlock;
use builtin::Builtin;
use client::Client;
use evm::env_info::{EnvInfo, LastHashes};
use vm::{EnvInfo, LastHashes, Schedule, CreateContractAddress};
use error::Error;
use evm::Schedule;
use header::{Header, BlockNumber};
use receipt::Receipt;
use trace::FlatTrace;
use snapshot::SnapshotComponents;
use spec::CommonParams;
use transaction::{UnverifiedTransaction, SignedTransaction};
use evm::CreateContractAddress;
use ethkey::Signature;
use util::*;
@@ -401,13 +401,12 @@ pub trait Engine : Sync + Send {
/// Common engine utilities
pub mod common {
use std::sync::Arc;
use block::ExecutedBlock;
use evm::env_info::{EnvInfo, LastHashes};
use error::Error;
use transaction::SYSTEM_ADDRESS;
use executive::Executive;
use evm::CallType;
use evm::action_params::{ActionParams, ActionValue};
use vm::{CallType, ActionParams, ActionValue, EnvInfo, LastHashes};
use trace::{NoopTracer, NoopVMTracer};
use state::Substate;

View File

@@ -16,7 +16,8 @@
//! A signer used by Engines which need to sign messages.
use util::{Arc, H256, Address};
use std::sync::Arc;
use util::{H256, Address};
use ethkey::Signature;
use account_provider::{self, AccountProvider};

View File

@@ -16,6 +16,7 @@
//! Tendermint message handling.
use std::cmp;
use util::*;
use super::{Height, View, BlockHash, Step};
use error::Error;
@@ -110,13 +111,13 @@ impl Default for VoteStep {
}
impl PartialOrd for VoteStep {
fn partial_cmp(&self, m: &VoteStep) -> Option<Ordering> {
fn partial_cmp(&self, m: &VoteStep) -> Option<cmp::Ordering> {
Some(self.cmp(m))
}
}
impl Ord for VoteStep {
fn cmp(&self, m: &VoteStep) -> Ordering {
fn cmp(&self, m: &VoteStep) -> cmp::Ordering {
if self.height != m.height {
self.height.cmp(&m.height)
} else if self.view != m.view {
@@ -198,6 +199,7 @@ pub fn message_hash(vote_step: VoteStep, block_hash: H256) -> H256 {
#[cfg(test)]
mod tests {
use std::sync::Arc;
use util::*;
use rlp::*;
use account_provider::AccountProvider;

View File

@@ -25,8 +25,10 @@
mod message;
mod params;
use std::sync::Weak;
use std::sync::{Weak, Arc};
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
use std::collections::{HashSet, BTreeMap, HashMap};
use std::cmp;
use util::*;
use client::{Client, EngineClient};
use error::{Error, BlockError};
@@ -470,9 +472,9 @@ impl Engine for Tendermint {
let gas_limit = parent.gas_limit().clone();
let bound_divisor = self.params().gas_limit_bound_divisor;
if gas_limit < gas_floor_target {
min(gas_floor_target, gas_limit + gas_limit / bound_divisor - 1.into())
cmp::min(gas_floor_target, gas_limit + gas_limit / bound_divisor - 1.into())
} else {
max(gas_floor_target, gas_limit - gas_limit / bound_divisor + 1.into())
cmp::max(gas_floor_target, gas_limit - gas_limit / bound_divisor + 1.into())
}
});
}
@@ -783,6 +785,7 @@ impl Engine for Tendermint {
#[cfg(test)]
mod tests {
use std::str::FromStr;
use rustc_hex::FromHex;
use util::*;
use block::*;

View File

@@ -126,6 +126,7 @@ impl ValidatorSet for ValidatorContract {
#[cfg(test)]
mod tests {
use std::sync::Arc;
use rustc_hex::FromHex;
use util::*;
use rlp::encode;
@@ -142,11 +143,11 @@ mod tests {
#[test]
fn fetches_validators() {
let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_contract, None);
let vc = Arc::new(ValidatorContract::new(Address::from_str("0000000000000000000000000000000000000005").unwrap()));
let vc = Arc::new(ValidatorContract::new("0000000000000000000000000000000000000005".parse::<Address>().unwrap()));
vc.register_contract(Arc::downgrade(&client));
let last_hash = client.best_block_header().hash();
assert!(vc.contains(&last_hash, &Address::from_str("7d577a597b2742b498cb5cf0c26cdcd726d39e6e").unwrap()));
assert!(vc.contains(&last_hash, &Address::from_str("82a978b3f5962a5b0957d9ee9eef472ee55b42f1").unwrap()));
assert!(vc.contains(&last_hash, &"7d577a597b2742b498cb5cf0c26cdcd726d39e6e".parse::<Address>().unwrap()));
assert!(vc.contains(&last_hash, &"82a978b3f5962a5b0957d9ee9eef472ee55b42f1".parse::<Address>().unwrap()));
}
#[test]
@@ -155,7 +156,7 @@ mod tests {
let v1 = tap.insert_account("1".sha3().into(), "").unwrap();
let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_contract, Some(tap.clone()));
client.engine().register_client(Arc::downgrade(&client));
let validator_contract = Address::from_str("0000000000000000000000000000000000000005").unwrap();
let validator_contract = "0000000000000000000000000000000000000005".parse::<Address>().unwrap();
// Make sure reporting can be done.
client.miner().set_gas_floor_target(1_000_000.into());

View File

@@ -142,6 +142,8 @@ impl ValidatorSet for Multi {
#[cfg(test)]
mod tests {
use std::sync::Arc;
use std::collections::BTreeMap;
use account_provider::AccountProvider;
use client::{BlockChainClient, EngineClient};
use engines::EpochChange;

View File

@@ -16,7 +16,7 @@
/// Validator set maintained in a contract, updated using `getValidators` method.
use std::sync::Weak;
use std::sync::{Weak, Arc};
use futures::Future;
use native_contracts::ValidatorSet as Provider;
@@ -299,7 +299,7 @@ impl ValidatorSet for ValidatorSafeContract {
let (old_header, state_items) = decode_first_proof(&rlp)?;
let old_hash = old_header.hash();
let env_info = ::evm::env_info::EnvInfo {
let env_info = ::vm::EnvInfo {
number: old_header.number(),
author: *old_header.author(),
difficulty: *old_header.difficulty(),
@@ -422,6 +422,7 @@ impl ValidatorSet for ValidatorSafeContract {
#[cfg(test)]
mod tests {
use std::sync::Arc;
use rustc_hex::FromHex;
use util::*;
use types::ids::BlockId;
@@ -438,11 +439,11 @@ mod tests {
#[test]
fn fetches_validators() {
let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_safe_contract, None);
let vc = Arc::new(ValidatorSafeContract::new(Address::from_str("0000000000000000000000000000000000000005").unwrap()));
let vc = Arc::new(ValidatorSafeContract::new("0000000000000000000000000000000000000005".parse::<Address>().unwrap()));
vc.register_contract(Arc::downgrade(&client));
let last_hash = client.best_block_header().hash();
assert!(vc.contains(&last_hash, &Address::from_str("7d577a597b2742b498cb5cf0c26cdcd726d39e6e").unwrap()));
assert!(vc.contains(&last_hash, &Address::from_str("82a978b3f5962a5b0957d9ee9eef472ee55b42f1").unwrap()));
assert!(vc.contains(&last_hash, &"7d577a597b2742b498cb5cf0c26cdcd726d39e6e".parse::<Address>().unwrap()));
assert!(vc.contains(&last_hash, &"82a978b3f5962a5b0957d9ee9eef472ee55b42f1".parse::<Address>().unwrap()));
}
#[test]
@@ -454,7 +455,7 @@ mod tests {
let network_id = Spec::new_validator_safe_contract().network_id();
let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_safe_contract, Some(tap));
client.engine().register_client(Arc::downgrade(&client));
let validator_contract = Address::from_str("0000000000000000000000000000000000000005").unwrap();
let validator_contract = "0000000000000000000000000000000000000005".parse::<Address>().unwrap();
client.miner().set_engine_signer(v1, "".into()).unwrap();
// Remove "1" validator.
@@ -520,7 +521,7 @@ mod tests {
let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_safe_contract, None);
let engine = client.engine().clone();
let validator_contract = Address::from_str("0000000000000000000000000000000000000005").unwrap();
let validator_contract = "0000000000000000000000000000000000000005".parse::<Address>().unwrap();
let last_hash = client.best_block_header().hash();
let mut new_header = Header::default();

View File

@@ -17,8 +17,9 @@
/// Used for Engine testing.
use std::str::FromStr;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
use util::{Arc, Bytes, H256, Address, HeapSizeOf};
use util::{Bytes, H256, Address, HeapSizeOf};
use engines::{Call, Engine};
use header::{Header, BlockNumber};

View File

@@ -17,6 +17,8 @@
//! Collects votes on hashes at each Message::Round.
use std::fmt::Debug;
use std::collections::{BTreeMap, HashSet, HashMap};
use std::hash::Hash;
use util::*;
use rlp::{Encodable, RlpStream};