Merge branch 'master' into path-man
Conflicts: parity/configuration.rs
This commit is contained in:
commit
93aa6c613a
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -301,7 +301,7 @@ dependencies = [
|
||||
"ethsync 1.2.0",
|
||||
"json-ipc-server 0.1.0 (git+https://github.com/ethcore/json-ipc-server.git)",
|
||||
"jsonrpc-core 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jsonrpc-http-server 5.1.0 (git+https://github.com/ethcore/jsonrpc-http-server.git)",
|
||||
"jsonrpc-http-server 5.1.0 (git+https://github.com/ethcore/jsonrpc-http-server.git?branch=multiple_cors_domains)",
|
||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -577,6 +577,16 @@ dependencies = [
|
||||
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jsonrpc-http-server"
|
||||
version = "5.1.0"
|
||||
source = "git+https://github.com/ethcore/jsonrpc-http-server.git?branch=multiple_cors_domains#9c026feeb6573c82c99c8005c5d8244de68a2e30"
|
||||
dependencies = [
|
||||
"hyper 0.9.3 (git+https://github.com/ethcore/hyper)",
|
||||
"jsonrpc-core 2.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kernel32-sys"
|
||||
version = "0.2.2"
|
||||
|
@ -59,7 +59,7 @@ impl RandomTempPath {
|
||||
impl Drop for RandomTempPath {
|
||||
fn drop(&mut self) {
|
||||
if let Err(e) = fs::remove_dir_all(self.as_path()) {
|
||||
panic!("failed to remove temp directory, probably something failed to destroyed ({})", e);
|
||||
panic!("Failed to remove temp directory. Here's what prevented this from happening: ({})", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -424,7 +424,7 @@ impl<V> Client<V> where V: Verifier {
|
||||
}
|
||||
|
||||
impl<V> BlockChainClient for Client<V> where V: Verifier {
|
||||
fn call(&self, t: &SignedTransaction) -> Result<Executed, Error> {
|
||||
fn call(&self, t: &SignedTransaction) -> Result<Executed, ExecutionError> {
|
||||
let header = self.block_header(BlockId::Latest).unwrap();
|
||||
let view = HeaderView::new(&header);
|
||||
let last_hashes = self.build_last_hashes(view.hash());
|
||||
@ -439,7 +439,10 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
|
||||
};
|
||||
// that's just a copy of the state.
|
||||
let mut state = self.state();
|
||||
let sender = try!(t.sender());
|
||||
let sender = try!(t.sender().map_err(|e| {
|
||||
let message = format!("Transaction malformed: {:?}", e);
|
||||
ExecutionError::TransactionMalformed(message)
|
||||
}));
|
||||
let balance = state.balance(&sender);
|
||||
// give the sender max balance
|
||||
state.sub_balance(&sender, &balance);
|
||||
|
@ -42,7 +42,7 @@ use header::{BlockNumber, Header};
|
||||
use transaction::{LocalizedTransaction, SignedTransaction};
|
||||
use log_entry::LocalizedLogEntry;
|
||||
use filter::Filter;
|
||||
use error::{ImportResult, Error};
|
||||
use error::{ImportResult, ExecutionError};
|
||||
use receipt::LocalizedReceipt;
|
||||
use engine::{Engine};
|
||||
use trace::LocalizedTrace;
|
||||
@ -133,7 +133,7 @@ pub trait BlockChainClient : Sync + Send {
|
||||
fn try_seal(&self, block: LockedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock>;
|
||||
|
||||
/// Makes a non-persistent transaction call.
|
||||
fn call(&self, t: &SignedTransaction) -> Result<Executed, Error>;
|
||||
fn call(&self, t: &SignedTransaction) -> Result<Executed, ExecutionError>;
|
||||
|
||||
/// Attempt to seal the block internally. See `Engine`.
|
||||
fn generate_seal(&self, block: &ExecutedBlock, accounts: Option<&AccountProvider>) -> Option<Vec<Bytes>> { self.engine().generate_seal(block, accounts) }
|
||||
|
@ -31,7 +31,7 @@ use error::{ImportResult};
|
||||
use block_queue::BlockQueueInfo;
|
||||
use block::{SealedBlock, ClosedBlock, LockedBlock};
|
||||
use executive::Executed;
|
||||
use error::Error;
|
||||
use error::{ExecutionError};
|
||||
use engine::Engine;
|
||||
use trace::LocalizedTrace;
|
||||
|
||||
@ -221,7 +221,7 @@ impl TestBlockChainClient {
|
||||
}
|
||||
|
||||
impl BlockChainClient for TestBlockChainClient {
|
||||
fn call(&self, _t: &SignedTransaction) -> Result<Executed, Error> {
|
||||
fn call(&self, _t: &SignedTransaction) -> Result<Executed, ExecutionError> {
|
||||
Ok(self.execution_result.read().unwrap().clone().unwrap())
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,9 @@ pub enum ExecutionError {
|
||||
got: U512
|
||||
},
|
||||
/// Returned when internal evm error occurs.
|
||||
Internal
|
||||
Internal,
|
||||
/// Returned when generic transaction occurs
|
||||
TransactionMalformed(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
|
@ -119,7 +119,7 @@ impl<'a> Executive<'a> {
|
||||
}
|
||||
|
||||
/// This function should be used to execute transaction.
|
||||
pub fn transact(&'a mut self, t: &SignedTransaction, options: TransactOptions) -> Result<Executed, Error> {
|
||||
pub fn transact(&'a mut self, t: &SignedTransaction, options: TransactOptions) -> Result<Executed, ExecutionError> {
|
||||
let check = options.check_nonce;
|
||||
match options.tracing {
|
||||
true => self.transact_with_tracer(t, check, ExecutiveTracer::default()),
|
||||
@ -128,8 +128,11 @@ impl<'a> Executive<'a> {
|
||||
}
|
||||
|
||||
/// Execute transaction/call with tracing enabled
|
||||
pub fn transact_with_tracer<T>(&'a mut self, t: &SignedTransaction, check_nonce: bool, mut tracer: T) -> Result<Executed, Error> where T: Tracer {
|
||||
let sender = try!(t.sender());
|
||||
pub fn transact_with_tracer<T>(&'a mut self, t: &SignedTransaction, check_nonce: bool, mut tracer: T) -> Result<Executed, ExecutionError> where T: Tracer {
|
||||
let sender = try!(t.sender().map_err(|e| {
|
||||
let message = format!("Transaction malformed: {:?}", e);
|
||||
ExecutionError::TransactionMalformed(message)
|
||||
}));
|
||||
let nonce = self.state.nonce(&sender);
|
||||
|
||||
let schedule = self.engine.schedule(self.info);
|
||||
@ -983,8 +986,8 @@ mod tests {
|
||||
};
|
||||
|
||||
match res {
|
||||
Err(Error::Util(UtilError::Crypto(CryptoError::InvalidSignature))) => (),
|
||||
_ => assert!(false, "Expected invalid signature error.")
|
||||
Err(ExecutionError::TransactionMalformed(_)) => (),
|
||||
_ => assert!(false, "Expected an invalid transaction error.")
|
||||
}
|
||||
}
|
||||
|
||||
@ -1015,7 +1018,7 @@ mod tests {
|
||||
};
|
||||
|
||||
match res {
|
||||
Err(Error::Execution(ExecutionError::InvalidNonce { expected, got }))
|
||||
Err(ExecutionError::InvalidNonce { expected, got })
|
||||
if expected == U256::zero() && got == U256::one() => (),
|
||||
_ => assert!(false, "Expected invalid nonce error.")
|
||||
}
|
||||
@ -1049,7 +1052,7 @@ mod tests {
|
||||
};
|
||||
|
||||
match res {
|
||||
Err(Error::Execution(ExecutionError::BlockGasLimitReached { gas_limit, gas_used, gas }))
|
||||
Err(ExecutionError::BlockGasLimitReached { gas_limit, gas_used, gas })
|
||||
if gas_limit == U256::from(100_000) && gas_used == U256::from(20_000) && gas == U256::from(80_001) => (),
|
||||
_ => assert!(false, "Expected block gas limit error.")
|
||||
}
|
||||
@ -1083,7 +1086,7 @@ mod tests {
|
||||
};
|
||||
|
||||
match res {
|
||||
Err(Error::Execution(ExecutionError::NotEnoughCash { required , got }))
|
||||
Err(ExecutionError::NotEnoughCash { required , got })
|
||||
if required == U512::from(100_018) && got == U512::from(100_017) => (),
|
||||
_ => assert!(false, "Expected not enough cash error. {:?}", res)
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ pub use external::{ExternalMiner, ExternalMinerService};
|
||||
use util::{H256, U256, Address, Bytes};
|
||||
use ethcore::client::{BlockChainClient, Executed};
|
||||
use ethcore::block::{ClosedBlock};
|
||||
use ethcore::error::{Error};
|
||||
use ethcore::error::{Error, ExecutionError};
|
||||
use ethcore::transaction::SignedTransaction;
|
||||
|
||||
/// Miner client API
|
||||
@ -150,7 +150,7 @@ pub trait MinerService : Send + Sync {
|
||||
fn balance(&self, chain: &BlockChainClient, address: &Address) -> U256;
|
||||
|
||||
/// Call into contract code using pending state.
|
||||
fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, Error>;
|
||||
fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, ExecutionError>;
|
||||
|
||||
/// Get storage value in pending state.
|
||||
fn storage_at(&self, chain: &BlockChainClient, address: &Address, position: &H256) -> H256;
|
||||
|
@ -240,7 +240,7 @@ impl MinerService for Miner {
|
||||
}
|
||||
}
|
||||
|
||||
fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, Error> {
|
||||
fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, ExecutionError> {
|
||||
let sealing_work = self.sealing_work.lock().unwrap();
|
||||
match sealing_work.peek_last_ref() {
|
||||
Some(work) => {
|
||||
@ -258,7 +258,10 @@ impl MinerService for Miner {
|
||||
};
|
||||
// that's just a copy of the state.
|
||||
let mut state = block.state().clone();
|
||||
let sender = try!(t.sender());
|
||||
let sender = try!(t.sender().map_err(|e| {
|
||||
let message = format!("Transaction malformed: {:?}", e);
|
||||
ExecutionError::TransactionMalformed(message)
|
||||
}));
|
||||
let balance = state.balance(&sender);
|
||||
// give the sender max balance
|
||||
state.sub_balance(&sender, &balance);
|
||||
|
@ -42,6 +42,9 @@ Account Options:
|
||||
ACCOUNTS is a comma-delimited list of addresses.
|
||||
--password FILE Provide a file containing a password for unlocking
|
||||
an account.
|
||||
--keys-iterations NUM Specify the number of iterations to use when deriving key
|
||||
from the password (bigger is more secure)
|
||||
[default: 10240].
|
||||
|
||||
Networking Options:
|
||||
--port PORT Override the port on which the node should listen
|
||||
@ -182,6 +185,7 @@ pub struct Args {
|
||||
pub flag_password: Vec<String>,
|
||||
pub flag_cache: Option<usize>,
|
||||
pub flag_keys_path: String,
|
||||
pub flag_keys_iterations: u32,
|
||||
pub flag_bootnodes: Option<String>,
|
||||
pub flag_network_id: Option<String>,
|
||||
pub flag_pruning: String,
|
||||
|
@ -241,7 +241,7 @@ impl Configuration {
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
}).collect::<Vec<_>>();
|
||||
let account_service = AccountService::new_in(Path::new(&self.keys_path()));
|
||||
let account_service = AccountService::with_security(Path::new(&self.keys_path()), self.keys_iterations());
|
||||
if let Some(ref unlocks) = self.args.flag_unlock {
|
||||
for d in unlocks.split(',') {
|
||||
let a = Address::from_str(clean_0x(&d)).unwrap_or_else(|_| {
|
||||
@ -259,8 +259,9 @@ impl Configuration {
|
||||
self.args.flag_rpcapi.clone().unwrap_or(self.args.flag_jsonrpc_apis.clone())
|
||||
}
|
||||
|
||||
pub fn rpc_cors(&self) -> Option<String> {
|
||||
self.args.flag_jsonrpc_cors.clone().or(self.args.flag_rpccorsdomain.clone())
|
||||
pub fn rpc_cors(&self) -> Vec<String> {
|
||||
let cors = self.args.flag_jsonrpc_cors.clone().or(self.args.flag_rpccorsdomain.clone());
|
||||
cors.map_or_else(Vec::new, |c| c.split(',').map(|s| s.to_owned()).collect())
|
||||
}
|
||||
|
||||
fn geth_ipc_path() -> String {
|
||||
@ -360,7 +361,7 @@ mod tests {
|
||||
assert_eq!(net.rpc_enabled, true);
|
||||
assert_eq!(net.rpc_interface, "all".to_owned());
|
||||
assert_eq!(net.rpc_port, 8000);
|
||||
assert_eq!(conf.rpc_cors(), Some("*".to_owned()));
|
||||
assert_eq!(conf.rpc_cors(), vec!["*".to_owned()]);
|
||||
assert_eq!(conf.rpc_apis(), "web3,eth".to_owned());
|
||||
}
|
||||
|
||||
|
@ -219,7 +219,7 @@ fn flush_stdout() {
|
||||
fn execute_account_cli(conf: Configuration) {
|
||||
use util::keys::store::SecretStore;
|
||||
use rpassword::read_password;
|
||||
let mut secret_store = SecretStore::new_in(Path::new(&conf.keys_path()));
|
||||
let mut secret_store = SecretStore::with_security(Path::new(&conf.keys_path()), conf.keys_iterations());
|
||||
if conf.args.cmd_new {
|
||||
println!("Please note that password is NOT RECOVERABLE.");
|
||||
print!("Type password: ");
|
||||
|
@ -41,7 +41,7 @@ pub struct HttpConfiguration {
|
||||
pub interface: String,
|
||||
pub port: u16,
|
||||
pub apis: String,
|
||||
pub cors: Option<String>,
|
||||
pub cors: Vec<String>,
|
||||
}
|
||||
|
||||
pub struct IpcConfiguration {
|
||||
@ -139,11 +139,11 @@ pub fn setup_http_rpc_server(
|
||||
pub fn setup_http_rpc_server(
|
||||
dependencies: &Arc<Dependencies>,
|
||||
url: &SocketAddr,
|
||||
cors_domain: Option<String>,
|
||||
cors_domains: Vec<String>,
|
||||
apis: Vec<&str>,
|
||||
) -> RpcServer {
|
||||
let server = setup_rpc_server(apis, dependencies);
|
||||
let start_result = server.start_http(url, cors_domain);
|
||||
let start_result = server.start_http(url, cors_domains);
|
||||
let deps = dependencies.clone();
|
||||
match start_result {
|
||||
Err(RpcServerError::IoError(err)) => die_with_io_error("RPC", err),
|
||||
|
@ -13,7 +13,7 @@ log = "0.3"
|
||||
serde = "0.7.0"
|
||||
serde_json = "0.7.0"
|
||||
jsonrpc-core = "2.0"
|
||||
jsonrpc-http-server = { git = "https://github.com/ethcore/jsonrpc-http-server.git" }
|
||||
jsonrpc-http-server = { git = "https://github.com/ethcore/jsonrpc-http-server.git", branch = "multiple_cors_domains" }
|
||||
ethcore-util = { path = "../util" }
|
||||
ethcore = { path = "../ethcore" }
|
||||
ethash = { path = "../ethash" }
|
||||
|
@ -59,9 +59,11 @@ impl RpcServer {
|
||||
}
|
||||
|
||||
/// Start http server asynchronously and returns result with `Server` handle on success or an error.
|
||||
pub fn start_http(&self, addr: &SocketAddr, cors_domain: Option<String>) -> Result<Server, RpcServerError> {
|
||||
let cors_domain = cors_domain.to_owned();
|
||||
Server::start(addr, self.handler.clone(), cors_domain.map(jsonrpc_http_server::AccessControlAllowOrigin::Value))
|
||||
pub fn start_http(&self, addr: &SocketAddr, cors_domains: Vec<String>) -> Result<Server, RpcServerError> {
|
||||
let cors_domains = cors_domains.into_iter()
|
||||
.map(jsonrpc_http_server::AccessControlAllowOrigin::Value)
|
||||
.collect();
|
||||
Server::start(addr, self.handler.clone(), cors_domains)
|
||||
}
|
||||
|
||||
/// Start ipc server asynchronously and returns result with `Server` handle on success or an error.
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
use util::{Address, H256, Bytes, U256, FixedHash, Uint};
|
||||
use util::standard::*;
|
||||
use ethcore::error::Error;
|
||||
use ethcore::error::{Error, ExecutionError};
|
||||
use ethcore::client::{BlockChainClient, Executed};
|
||||
use ethcore::block::{ClosedBlock, IsBlock};
|
||||
use ethcore::transaction::SignedTransaction;
|
||||
@ -179,7 +179,7 @@ impl MinerService for TestMinerService {
|
||||
self.latest_closed_block.lock().unwrap().as_ref().map_or_else(U256::zero, |b| b.block().fields().state.balance(address).clone())
|
||||
}
|
||||
|
||||
fn call(&self, _chain: &BlockChainClient, _t: &SignedTransaction) -> Result<Executed, Error> {
|
||||
fn call(&self, _chain: &BlockChainClient, _t: &SignedTransaction) -> Result<Executed, ExecutionError> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
|
@ -1193,7 +1193,7 @@ impl ChainSync {
|
||||
let mut rlp_stream = RlpStream::new_list(route.blocks.len());
|
||||
for block_hash in route.blocks {
|
||||
let mut hash_rlp = RlpStream::new_list(2);
|
||||
let difficulty = chain.block_total_difficulty(BlockId::Hash(block_hash.clone())).expect("Mallformed block without a difficulty on the chain!");
|
||||
let difficulty = chain.block_total_difficulty(BlockId::Hash(block_hash.clone())).expect("Malformed block without a difficulty on the chain!");
|
||||
hash_rlp.append(&block_hash);
|
||||
hash_rlp.append(&difficulty);
|
||||
rlp_stream.append_raw(&hash_rlp.out(), 1);
|
||||
@ -1570,7 +1570,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn handles_peer_new_block_mallformed() {
|
||||
fn handles_peer_new_block_malformed() {
|
||||
let mut client = TestBlockChainClient::new();
|
||||
client.add_blocks(10, EachBlockWith::Uncle);
|
||||
|
||||
|
@ -381,7 +381,7 @@ impl KeyFileContent {
|
||||
}
|
||||
}
|
||||
|
||||
/// Loads key from valid json, returns error and records warning if key is mallformed
|
||||
/// Loads key from valid json, returns error and records warning if key is malformed
|
||||
pub fn load(json: &Json) -> Result<KeyFileContent, ()> {
|
||||
match Self::from_json(json) {
|
||||
Ok(key_file) => Ok(key_file),
|
||||
|
@ -73,6 +73,7 @@ pub enum SigningError {
|
||||
pub struct SecretStore {
|
||||
directory: KeyDirectory,
|
||||
unlocks: RwLock<HashMap<Address, AccountUnlock>>,
|
||||
key_iterations: u32,
|
||||
}
|
||||
|
||||
struct AccountUnlock {
|
||||
@ -128,10 +129,15 @@ impl AccountProvider for AccountService {
|
||||
impl AccountService {
|
||||
/// New account service with the keys store in specific location
|
||||
pub fn new_in(path: &Path) -> Self {
|
||||
let secret_store = RwLock::new(SecretStore::new_in(path));
|
||||
AccountService::with_security(path, KEY_ITERATIONS)
|
||||
}
|
||||
|
||||
/// New account service with the keys store in specific location and configured security parameters
|
||||
pub fn with_security(path: &Path, key_iterations: u32) -> Self {
|
||||
let secret_store = RwLock::new(SecretStore::with_security(path, key_iterations));
|
||||
secret_store.write().unwrap().try_import_existing();
|
||||
AccountService {
|
||||
secret_store: secret_store
|
||||
secret_store: secret_store,
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,10 +163,16 @@ impl AccountService {
|
||||
impl SecretStore {
|
||||
/// new instance of Secret Store in specific directory
|
||||
pub fn new_in(path: &Path) -> Self {
|
||||
SecretStore::with_security(path, KEY_ITERATIONS)
|
||||
}
|
||||
|
||||
/// new instance of Secret Store in specific directory and configured security parameters
|
||||
pub fn with_security(path: &Path, key_iterations: u32) -> Self {
|
||||
::std::fs::create_dir_all(&path).expect("Cannot access requested key directory - critical");
|
||||
SecretStore {
|
||||
directory: KeyDirectory::new(path),
|
||||
unlocks: RwLock::new(HashMap::new()),
|
||||
key_iterations: key_iterations,
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,6 +218,7 @@ impl SecretStore {
|
||||
SecretStore {
|
||||
directory: KeyDirectory::new(path.as_path()),
|
||||
unlocks: RwLock::new(HashMap::new()),
|
||||
key_iterations: KEY_ITERATIONS,
|
||||
}
|
||||
}
|
||||
|
||||
@ -289,8 +302,8 @@ fn derive_key_iterations(password: &str, salt: &H256, c: u32) -> (Bytes, Bytes)
|
||||
(derived_right_bits.to_vec(), derived_left_bits.to_vec())
|
||||
}
|
||||
|
||||
fn derive_key(password: &str, salt: &H256) -> (Bytes, Bytes) {
|
||||
derive_key_iterations(password, salt, KEY_ITERATIONS)
|
||||
fn derive_key(password: &str, salt: &H256, iterations: u32) -> (Bytes, Bytes) {
|
||||
derive_key_iterations(password, salt, iterations)
|
||||
}
|
||||
|
||||
fn derive_key_scrypt(password: &str, salt: &H256, n: u32, p: u32, r: u32) -> (Bytes, Bytes) {
|
||||
@ -346,7 +359,7 @@ impl EncryptedHashMap<H128> for SecretStore {
|
||||
|
||||
// two parts of derived key
|
||||
// DK = [ DK[0..15] DK[16..31] ] = [derived_left_bits, derived_right_bits]
|
||||
let (derived_left_bits, derived_right_bits) = derive_key(password, &salt);
|
||||
let (derived_left_bits, derived_right_bits) = derive_key(password, &salt, self.key_iterations);
|
||||
|
||||
let mut cipher_text = vec![0u8; value.as_slice().len()];
|
||||
// aes-128-ctr with initial vector of iv
|
||||
@ -361,7 +374,7 @@ impl EncryptedHashMap<H128> for SecretStore {
|
||||
iv,
|
||||
salt,
|
||||
mac,
|
||||
KEY_ITERATIONS,
|
||||
self.key_iterations,
|
||||
KEY_LENGTH));
|
||||
key_file.id = key;
|
||||
if let Err(io_error) = self.directory.save(key_file) {
|
||||
|
Loading…
Reference in New Issue
Block a user