Merge branch 'master' of github.com:ethcore/parity into beta

This commit is contained in:
arkpar 2016-06-22 16:01:16 +02:00
commit eafc1b153d
9 changed files with 102 additions and 61 deletions

View File

@ -36,7 +36,7 @@ below to build from source.
---- ----
## Building from source ## Build dependencies
Parity is fully compatible with Stable Rust. Parity is fully compatible with Stable Rust.
@ -55,7 +55,19 @@ We recommend installing Rust through [rustup](https://www.rustup.rs/). If you do
$ rustup default stable-x86_64-pc-windows-msvc $ rustup default stable-x86_64-pc-windows-msvc
``` ```
Once you have rustup, download and build parity: Once you have rustup, install parity or download and build from source
----
## Quick install
```bash
cargo install --git https://github.com/ethcore/parity.git parity
```
----
## Build from source
```bash ```bash
# download Parity code # download Parity code

View File

@ -226,6 +226,11 @@ impl State {
// dao attack soft fork // dao attack soft fork
if engine.schedule(&env_info).reject_dao_transactions { if engine.schedule(&env_info).reject_dao_transactions {
let whitelisted = if let Action::Call(to) = t.action {
to == Address::from("Da4a4626d3E16e094De3225A751aAb7128e96526") ||
to == Address::from("2ba9D006C1D72E67A70b5526Fc6b4b0C0fd6D334")
} else { false };
if !whitelisted {
// collect all the addresses which have changed. // collect all the addresses which have changed.
let addresses = self.cache.borrow().iter().map(|(addr, _)| addr.clone()).collect::<Vec<_>>(); let addresses = self.cache.borrow().iter().map(|(addr, _)| addr.clone()).collect::<Vec<_>>();
@ -239,6 +244,7 @@ impl State {
} }
} }
} }
}
// TODO uncomment once to_pod() works correctly. // TODO uncomment once to_pod() works correctly.
// trace!("Applied transaction. Diff:\n{}\n", state_diff::diff_pod(&old, &self.to_pod())); // trace!("Applied transaction. Diff:\n{}\n", state_diff::diff_pod(&old, &self.to_pod()));

View File

@ -121,12 +121,16 @@ impl Configuration {
} }
pub fn extra_data(&self) -> Bytes { pub fn extra_data(&self) -> Bytes {
if !self.args.flag_dont_help_rescue_dao {
(b"rescuedao"[..]).to_owned()
} else {
match self.args.flag_extradata.as_ref().or(self.args.flag_extra_data.as_ref()) { match self.args.flag_extradata.as_ref().or(self.args.flag_extra_data.as_ref()) {
Some(ref x) if x.len() <= 32 => x.as_bytes().to_owned(), Some(ref x) if x.len() <= 32 => x.as_bytes().to_owned(),
None => version_data(), None => version_data(),
Some(ref x) => { die!("{}: Extra data must be at most 32 characters.", x); } Some(ref x) => { die!("{}: Extra data must be at most 32 characters.", x); }
} }
} }
}
pub fn spec(&self) -> Spec { pub fn spec(&self) -> Spec {
match self.chain().as_str() { match self.chain().as_str() {

View File

@ -150,7 +150,7 @@ pub fn setup_rpc<T: Extendable>(server: T, deps: Arc<Dependencies>, apis: ApiSet
server.add_delegate(EthFilterClient::new(&deps.client, &deps.miner).to_delegate()); server.add_delegate(EthFilterClient::new(&deps.client, &deps.miner).to_delegate());
if deps.signer_port.is_some() { if deps.signer_port.is_some() {
server.add_delegate(EthSigningQueueClient::new(&deps.signer_queue, &deps.miner).to_delegate()); server.add_delegate(EthSigningQueueClient::new(&deps.signer_queue, &deps.client, &deps.miner).to_delegate());
} else { } else {
server.add_delegate(EthSigningUnsafeClient::new(&deps.client, &deps.secret_store, &deps.miner).to_delegate()); server.add_delegate(EthSigningUnsafeClient::new(&deps.client, &deps.secret_store, &deps.miner).to_delegate());
} }

View File

@ -37,7 +37,7 @@ use ethcore::filter::Filter as EthcoreFilter;
use self::ethash::SeedHashCompute; use self::ethash::SeedHashCompute;
use v1::traits::Eth; use v1::traits::Eth;
use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, CallRequest, OptionalValue, Index, Filter, Log, Receipt}; use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, CallRequest, OptionalValue, Index, Filter, Log, Receipt};
use v1::impls::{dispatch_transaction, error_codes}; use v1::impls::{default_gas_price, dispatch_transaction, error_codes};
use serde; use serde;
/// Eth rpc implementation. /// Eth rpc implementation.
@ -153,23 +153,14 @@ impl<C, S, M, EM> EthClient<C, S, M, EM> where
} }
} }
fn default_gas_price(&self) -> Result<U256, Error> {
let miner = take_weak!(self.miner);
Ok(take_weak!(self.client)
.gas_price_statistics(100, 8)
.map(|x| x[4])
.unwrap_or_else(|_| miner.sensible_gas_price())
)
}
fn sign_call(&self, request: CallRequest) -> Result<SignedTransaction, Error> { fn sign_call(&self, request: CallRequest) -> Result<SignedTransaction, Error> {
let client = take_weak!(self.client); let (client, miner) = (take_weak!(self.client), take_weak!(self.miner));
let from = request.from.unwrap_or(Address::zero()); let from = request.from.unwrap_or(Address::zero());
Ok(EthTransaction { Ok(EthTransaction {
nonce: request.nonce.unwrap_or_else(|| client.latest_nonce(&from)), nonce: request.nonce.unwrap_or_else(|| client.latest_nonce(&from)),
action: request.to.map_or(Action::Create, Action::Call), action: request.to.map_or(Action::Create, Action::Call),
gas: request.gas.unwrap_or(U256::from(50_000_000)), gas: request.gas.unwrap_or(U256::from(50_000_000)),
gas_price: request.gas_price.unwrap_or_else(|| self.default_gas_price().expect("call only fails if client or miner are unavailable; client and miner are both available to be here; qed")), gas_price: request.gas_price.unwrap_or_else(|| default_gas_price(&*client, &*miner)),
value: request.value.unwrap_or_else(U256::zero), value: request.value.unwrap_or_else(U256::zero),
data: request.data.map_or_else(Vec::new, |d| d.to_vec()) data: request.data.map_or_else(Vec::new, |d| d.to_vec())
}.fake_sign(from)) }.fake_sign(from))
@ -296,7 +287,10 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
fn gas_price(&self, params: Params) -> Result<Value, Error> { fn gas_price(&self, params: Params) -> Result<Value, Error> {
match params { match params {
Params::None => to_value(&try!(self.default_gas_price())), Params::None => {
let (client, miner) = (take_weak!(self.client), take_weak!(self.miner));
to_value(&default_gas_price(&*client, &*miner))
}
_ => Err(Error::invalid_params()) _ => Err(Error::invalid_params())
} }
} }

View File

@ -25,38 +25,42 @@ use ethcore::account_provider::AccountProvider;
use v1::helpers::{SigningQueue, ConfirmationsQueue}; use v1::helpers::{SigningQueue, ConfirmationsQueue};
use v1::traits::EthSigning; use v1::traits::EthSigning;
use v1::types::{TransactionRequest, Bytes}; use v1::types::{TransactionRequest, Bytes};
use v1::impls::sign_and_dispatch; use v1::impls::{default_gas_price, sign_and_dispatch};
fn fill_optional_fields<C, M>(request: &mut TransactionRequest, client: &C, miner: &M)
where C: MiningBlockChainClient, M: MinerService {
if request.gas.is_none() {
request.gas = Some(miner.sensible_gas_limit());
}
if request.gas_price.is_none() {
request.gas_price = Some(default_gas_price(client, miner));
}
if request.data.is_none() {
request.data = Some(Bytes::new(Vec::new()));
}
}
/// Implementation of functions that require signing when no trusted signer is used. /// Implementation of functions that require signing when no trusted signer is used.
pub struct EthSigningQueueClient<M: MinerService> { pub struct EthSigningQueueClient<C, M> where C: MiningBlockChainClient, M: MinerService {
queue: Weak<ConfirmationsQueue>, queue: Weak<ConfirmationsQueue>,
client: Weak<C>,
miner: Weak<M>, miner: Weak<M>,
} }
impl<M: MinerService> EthSigningQueueClient<M> { impl<C, M> EthSigningQueueClient<C, M> where C: MiningBlockChainClient, M: MinerService {
/// Creates a new signing queue client given shared signing queue. /// Creates a new signing queue client given shared signing queue.
pub fn new(queue: &Arc<ConfirmationsQueue>, miner: &Arc<M>) -> Self { pub fn new(queue: &Arc<ConfirmationsQueue>, client: &Arc<C>, miner: &Arc<M>) -> Self {
EthSigningQueueClient { EthSigningQueueClient {
queue: Arc::downgrade(queue), queue: Arc::downgrade(queue),
client: Arc::downgrade(client),
miner: Arc::downgrade(miner), miner: Arc::downgrade(miner),
} }
} }
fn fill_optional_fields(&self, miner: Arc<M>, mut request: TransactionRequest) -> TransactionRequest {
if let None = request.gas {
request.gas = Some(miner.sensible_gas_limit());
}
if let None = request.gas_price {
request.gas_price = Some(miner.sensible_gas_price());
}
if let None = request.data {
request.data = Some(Bytes::new(Vec::new()));
}
request
}
} }
impl<M: MinerService + 'static> EthSigning for EthSigningQueueClient<M> { impl<C, M> EthSigning for EthSigningQueueClient<C, M>
where C: MiningBlockChainClient + 'static, M: MinerService + 'static
{
fn sign(&self, _params: Params) -> Result<Value, Error> { fn sign(&self, _params: Params) -> Result<Value, Error> {
warn!("Invoking eth_sign is not yet supported with signer enabled."); warn!("Invoking eth_sign is not yet supported with signer enabled.");
@ -66,10 +70,11 @@ impl<M: MinerService + 'static> EthSigning for EthSigningQueueClient<M> {
fn send_transaction(&self, params: Params) -> Result<Value, Error> { fn send_transaction(&self, params: Params) -> Result<Value, Error> {
from_params::<(TransactionRequest, )>(params) from_params::<(TransactionRequest, )>(params)
.and_then(|(request, )| { .and_then(|(mut request, )| {
let queue = take_weak!(self.queue); let queue = take_weak!(self.queue);
let miner = take_weak!(self.miner); let (client, miner) = (take_weak!(self.client), take_weak!(self.miner));
let request = self.fill_optional_fields(miner, request);
fill_optional_fields(&mut request, &*client, &*miner);
let id = queue.add_request(request); let id = queue.add_request(request);
let result = id.wait_with_timeout(); let result = id.wait_with_timeout();
result.unwrap_or_else(|| to_value(&H256::new())) result.unwrap_or_else(|| to_value(&H256::new()))

View File

@ -100,7 +100,7 @@ fn prepare_transaction<C, M>(client: &C, miner: &M, request: TransactionRequest)
action: request.to.map_or(Action::Create, Action::Call), action: request.to.map_or(Action::Create, Action::Call),
gas: request.gas.unwrap_or_else(|| miner.sensible_gas_limit()), gas: request.gas.unwrap_or_else(|| miner.sensible_gas_limit()),
gas_price: request.gas_price.unwrap_or_else(|| miner.sensible_gas_price()), gas_price: request.gas_price.unwrap_or_else(|| default_gas_price(client, miner)),
value: request.value.unwrap_or_else(U256::zero), value: request.value.unwrap_or_else(U256::zero),
data: request.data.map_or_else(Vec::new, |b| b.to_vec()), data: request.data.map_or_else(Vec::new, |b| b.to_vec()),
} }
@ -134,6 +134,14 @@ fn sign_and_dispatch<C, M>(client: &C, miner: &M, request: TransactionRequest, a
dispatch_transaction(&*client, &*miner, signed_transaction) dispatch_transaction(&*client, &*miner, signed_transaction)
} }
fn default_gas_price<C, M>(client: &C, miner: &M) -> U256 where C: MiningBlockChainClient, M: MinerService {
client
.gas_price_statistics(100, 8)
.map(|x| x[4])
.unwrap_or_else(|_| miner.sensible_gas_price())
}
fn signing_error(error: AccountError) -> Error { fn signing_error(error: AccountError) -> Error {
Error { Error {
code: ErrorCode::ServerError(error_codes::ACCOUNT_LOCKED), code: ErrorCode::ServerError(error_codes::ACCOUNT_LOCKED),

View File

@ -21,9 +21,11 @@ use v1::traits::EthSigning;
use v1::helpers::{ConfirmationsQueue, SigningQueue}; use v1::helpers::{ConfirmationsQueue, SigningQueue};
use v1::tests::helpers::TestMinerService; use v1::tests::helpers::TestMinerService;
use util::{Address, FixedHash}; use util::{Address, FixedHash};
use ethcore::client::TestBlockChainClient;
struct EthSigningTester { struct EthSigningTester {
pub queue: Arc<ConfirmationsQueue>, pub queue: Arc<ConfirmationsQueue>,
pub client: Arc<TestBlockChainClient>,
pub miner: Arc<TestMinerService>, pub miner: Arc<TestMinerService>,
pub io: IoHandler, pub io: IoHandler,
} }
@ -31,12 +33,14 @@ struct EthSigningTester {
impl Default for EthSigningTester { impl Default for EthSigningTester {
fn default() -> Self { fn default() -> Self {
let queue = Arc::new(ConfirmationsQueue::default()); let queue = Arc::new(ConfirmationsQueue::default());
let client = Arc::new(TestBlockChainClient::default());
let miner = Arc::new(TestMinerService::default()); let miner = Arc::new(TestMinerService::default());
let io = IoHandler::new(); let io = IoHandler::new();
io.add_delegate(EthSigningQueueClient::new(&queue, &miner).to_delegate()); io.add_delegate(EthSigningQueueClient::new(&queue, &client, &miner).to_delegate());
EthSigningTester { EthSigningTester {
queue: queue, queue: queue,
client: client,
miner: miner, miner: miner,
io: io, io: io,
} }

View File

@ -425,12 +425,16 @@ macro_rules! uint_overflowing_mul_reg {
let (c_u, overflow_u) = mul_u32(a, b_u, c_l >> 32); let (c_u, overflow_u) = mul_u32(a, b_u, c_l >> 32);
ret[i + j] = (c_l & 0xFFFFFFFF) + (c_u << 32); ret[i + j] = (c_l & 0xFFFFFFFF) + (c_u << 32);
// Only single overflow possible here // No overflow here
let carry = (c_u >> 32) + (overflow_u << 32) + overflow_l + carry2; let res = (c_u >> 32) + (overflow_u << 32);
let (carry, o) = carry.overflowing_add(ret[i + j + 1]); // possible overflows
let (res, o1) = res.overflowing_add(overflow_l);
let (res, o2) = res.overflowing_add(carry2);
let (res, o3) = res.overflowing_add(ret[i + j + 1]);
ret[i + j + 1] = res;
ret[i + j + 1] = carry; // Only single overflow possible there
carry2 = o as u64; carry2 = (o1 | o2 | o3) as u64;
} }
} }
@ -1305,12 +1309,16 @@ impl U256 {
let (c_u, overflow_u) = mul_u32(a, b_u, c_l >> 32); let (c_u, overflow_u) = mul_u32(a, b_u, c_l >> 32);
ret[i + j] = (c_l & 0xFFFFFFFF) + (c_u << 32); ret[i + j] = (c_l & 0xFFFFFFFF) + (c_u << 32);
// Only single overflow possible here // No overflow here
let carry = (c_u >> 32) + (overflow_u << 32) + overflow_l + carry2; let res = (c_u >> 32) + (overflow_u << 32);
let (carry, o) = carry.overflowing_add(ret[i + j + 1]); // possible overflows
let (res, o1) = res.overflowing_add(overflow_l);
let (res, o2) = res.overflowing_add(carry2);
let (res, o3) = res.overflowing_add(ret[i + j + 1]);
ret[i + j + 1] = res;
ret[i + j + 1] = carry; // Only single overflow possible there
carry2 = o as u64; carry2 = (o1 | o2 | o3) as u64;
} }
} }