Merge remote-tracking branch 'origin/master' into targetgaslimit

This commit is contained in:
Gav Wood 2016-03-14 10:54:38 +01:00
commit 7320ad077f
10 changed files with 185 additions and 83 deletions

View File

@ -33,10 +33,6 @@ addons:
- libcurl4-openssl-dev - libcurl4-openssl-dev
- libelf-dev - libelf-dev
- libdw-dev - libdw-dev
before_script: |
sudo add-apt-repository "deb http://ppa.launchpad.net/giskou/librocksdb/ubuntu trusty main" &&
sudo apt-get update &&
sudo apt-get install -y --force-yes librocksdb
script: script:
- cargo build --release --verbose ${FEATURES} - cargo build --release --verbose ${FEATURES}
- cargo test --release --verbose ${FEATURES} ${TARGETS} - cargo test --release --verbose ${FEATURES} ${TARGETS}

View File

@ -78,73 +78,88 @@ Usage:
parity [options] parity [options]
Protocol Options: Protocol Options:
--chain CHAIN Specify the blockchain type. CHAIN may be either a JSON chain specification file --chain CHAIN Specify the blockchain type. CHAIN may be either a
or olympic, frontier, homestead, mainnet, morden, or testnet [default: homestead]. JSON chain specification file or olympic, frontier,
--testnet Equivalent to --chain testnet (geth-compatible). homestead, mainnet, morden, or testnet
--networkid INDEX Override the network identifier from the chain we are on. [default: homestead].
--pruning METHOD Configure pruning of the state/storage trie. METHOD may be one of: archive, -d --db-path PATH Specify the database & configuration directory path
basic (experimental), fast (experimental) [default: archive]. [default: $HOME/.parity].
-d --datadir PATH Specify the database & configuration directory path [default: $HOME/.parity] --keys-path PATH Specify the path for JSON key files to be found
--db-path PATH Specify the database & configuration directory path [default: $HOME/.parity] [default: $HOME/.web3/keys].
--keys-path PATH Specify the path for JSON key files to be found [default: $HOME/.web3/keys]
--identity NAME Specify your node's name. --identity NAME Specify your node's name.
Networking Options: Networking Options:
--port PORT Override the port on which the node should listen [default: 30303]. --port PORT Override the port on which the node should listen
[default: 30303].
--peers NUM Try to maintain that many peers [default: 25]. --peers NUM Try to maintain that many peers [default: 25].
--nat METHOD Specify method to use for determining public address. Must be one of: any, none, --nat METHOD Specify method to use for determining public
upnp, extip:(IP) [default: any]. address. Must be one of: any, none, upnp,
--bootnodes NODES Specify additional comma-separated bootnodes. extip:<IP> [default: any].
--no-bootstrap Don't bother trying to connect to standard bootnodes. --network-id INDEX Override the network identifier from the chain we
are on.
--bootnodes NODES Override the bootnodes from our chain. NODES should
be comma-delimited enodes.
--no-discovery Disable new peer discovery. --no-discovery Disable new peer discovery.
--node-key KEY Specify node secret key, either as 64-character hex string or input to SHA3 operation. --node-key KEY Specify node secret key, either as 64-character hex
string or input to SHA3 operation.
API and Console Options: API and Console Options:
-j --jsonrpc Enable the JSON-RPC API sever. -j --jsonrpc Enable the JSON-RPC API sever.
--jsonrpc-addr HOST Specify the hostname portion of the JSONRPC API server [default: 127.0.0.1]. --jsonrpc-addr HOST Specify the hostname portion of the JSONRPC API
--jsonrpc-port PORT Specify the port portion of the JSONRPC API server [default: 8545]. server [default: 127.0.0.1].
--jsonrpc-cors URL Specify CORS header for JSON-RPC API responses [default: null]. --jsonrpc-port PORT Specify the port portion of the JSONRPC API server
--jsonrpc-apis APIS Specify the APIs available through the JSONRPC interface. APIS is a comma-delimited [default: 8545].
list of API name. Possible name are web3, eth and net. [default: web3,eth,net,personal]. --jsonrpc-cors URL Specify CORS header for JSON-RPC API responses
[default: null].
--rpc Equivalent to --jsonrpc (geth-compatible). --jsonrpc-apis APIS Specify the APIs available through the JSONRPC
--rpcaddr HOST Equivalent to --jsonrpc-addr HOST (geth-compatible). interface. APIS is a comma-delimited list of API
--rpcport PORT Equivalent to --jsonrpc-port PORT (geth-compatible). name. Possible name are web3, eth and net.
--rpcapi APIS Equivalent to --jsonrpc-apis APIS (geth-compatible). [default: web3,eth,net,personal].
--rpccorsdomain URL Equivalent to --jsonrpc-cors URL (geth-compatible).
Sealing/Mining Options: Sealing/Mining Options:
--gas-price WEI Minimum amount of Wei to be paid for a transaction to be accepted for mining [default: 20000000000]. --gas-price WEI Minimum amount of Wei to be paid for a transaction
--gas-floor-target GAS Amount of gas per block to target when sealing a new block [default: 4712388]. to be accepted for mining [default: 20000000000].
--author ADDRESS Specify the block author (aka "coinbase") address for sending block rewards --gas-floor-target GAS Amount of gas per block to target when sealing a new
from sealed blocks [default: 0037a6b811ffeb6e072da21179d11b1406371c63]. block [default: 4712388].
--extra-data STRING Specify a custom extra-data for authored blocks, no more than 32 characters. --author ADDRESS Specify the block author (aka "coinbase") address
for sending block rewards from sealed blocks
[default: 0037a6b811ffeb6e072da21179d11b1406371c63].
--extra-data STRING Specify a custom extra-data for authored blocks, no
more than 32 characters.
Memory Footprint Options: Footprint Options:
--cache-pref-size BYTES Specify the prefered size of the blockchain cache in bytes [default: 16384]. --pruning METHOD Configure pruning of the state/storage trie. METHOD
--cache-max-size BYTES Specify the maximum size of the blockchain cache in bytes [default: 262144]. may be one of: archive, basic (experimental), fast
--queue-max-size BYTES Specify the maximum size of memory to use for block queue [default: 52428800]. (experimental) [default: archive].
--cache MEGABYTES Set total amount of cache to use for the entire system, mutually exclusive with --cache-pref-size BYTES Specify the prefered size of the blockchain cache in
other cache options (geth-compatible). bytes [default: 16384].
--cache-max-size BYTES Specify the maximum size of the blockchain cache in
bytes [default: 262144].
--queue-max-size BYTES Specify the maximum size of memory to use for block
queue [default: 52428800].
--cache MEGABYTES Set total amount of discretionary memory to use for
the entire system, overrides other cache and queue
options.
Geth-Compatibility Options Geth-compatibility Options:
--datadir PATH Equivalent to --db-path PATH. --datadir PATH Equivalent to --db-path PATH.
--testnet Equivalent to --chain testnet. --testnet Equivalent to --chain testnet.
--networkid INDEX Override the network identifier from the chain we are on. --networkid INDEX Equivalent to --network-id INDEX.
--maxpeers COUNT Equivalent to --peers COUNT.
--nodekey KEY Equivalent to --node-key KEY.
--nodiscover Equivalent to --no-discovery.
--rpc Equivalent to --jsonrpc. --rpc Equivalent to --jsonrpc.
--rpcaddr HOST Equivalent to --jsonrpc-addr HOST. --rpcaddr HOST Equivalent to --jsonrpc-addr HOST.
--rpcport PORT Equivalent to --jsonrpc-port PORT. --rpcport PORT Equivalent to --jsonrpc-port PORT.
--rpcapi APIS Equivalent to --jsonrpc-apis APIS. --rpcapi APIS Equivalent to --jsonrpc-apis APIS.
--rpccorsdomain URL Equivalent to --jsonrpc-cors URL. --rpccorsdomain URL Equivalent to --jsonrpc-cors URL.
--maxpeers COUNT Equivalent to --peers COUNT.
--nodekey KEY Equivalent to --node-key KEY.
--nodiscover Equivalent to --no-discovery.
--gasprice WEI Equivalent to --gas-price WEI. --gasprice WEI Equivalent to --gas-price WEI.
--etherbase ADDRESS Equivalent to --author ADDRESS. --etherbase ADDRESS Equivalent to --author ADDRESS.
--extradata STRING Equivalent to --extra-data STRING. --extradata STRING Equivalent to --extra-data STRING.
Miscellaneous Options: Miscellaneous Options:
-l --logging LOGGING Specify the logging level. Must conform to the same format as RUST_LOG. -l --logging LOGGING Specify the logging level. Must conform to the same
format as RUST_LOG.
-v --version Show information about version. -v --version Show information about version.
-h --help Show this screen. -h --help Show this screen.
"#; "#;
@ -162,8 +177,8 @@ struct Args {
flag_cache: Option<usize>, flag_cache: Option<usize>,
flag_keys_path: String, flag_keys_path: String,
flag_bootnodes: Option<String>, flag_bootnodes: Option<String>,
flag_network_id: Option<String>,
flag_pruning: String, flag_pruning: String,
flag_no_bootstrap: bool,
flag_port: u16, flag_port: u16,
flag_peers: usize, flag_peers: usize,
flag_no_discovery: bool, flag_no_discovery: bool,
@ -354,15 +369,15 @@ impl Configuration {
} }
fn init_nodes(&self, spec: &Spec) -> Vec<String> { fn init_nodes(&self, spec: &Spec) -> Vec<String> {
let mut r = if self.args.flag_no_bootstrap { Vec::new() } else { spec.nodes().clone() }; match self.args.flag_bootnodes {
if let Some(ref x) = self.args.flag_bootnodes { Some(ref x) if x.len() > 0 => x.split(',').map(|s| {
r.extend(x.split(',').map(|s| {
Self::normalize_enode(s).unwrap_or_else(|| { Self::normalize_enode(s).unwrap_or_else(|| {
die!("{}: Invalid node address format given for a boot node.", s) die!("{}: Invalid node address format given for a boot node.", s)
}) })
})); }).collect(),
Some(_) => Vec::new(),
None => spec.nodes().clone(),
} }
r
} }
#[cfg_attr(feature="dev", allow(useless_format))] #[cfg_attr(feature="dev", allow(useless_format))]
@ -399,7 +414,7 @@ impl Configuration {
match self.args.flag_cache { match self.args.flag_cache {
Some(mb) => { Some(mb) => {
client_config.blockchain.max_cache_size = mb * 1024 * 1024; client_config.blockchain.max_cache_size = mb * 1024 * 1024;
client_config.blockchain.pref_cache_size = client_config.blockchain.max_cache_size / 2; client_config.blockchain.pref_cache_size = client_config.blockchain.max_cache_size * 3 / 4;
} }
None => { None => {
client_config.blockchain.pref_cache_size = self.args.flag_cache_pref_size; client_config.blockchain.pref_cache_size = self.args.flag_cache_pref_size;
@ -420,8 +435,8 @@ impl Configuration {
fn sync_config(&self, spec: &Spec) -> SyncConfig { fn sync_config(&self, spec: &Spec) -> SyncConfig {
let mut sync_config = SyncConfig::default(); let mut sync_config = SyncConfig::default();
sync_config.network_id = self.args.flag_networkid.as_ref().map_or(spec.network_id(), |id| { sync_config.network_id = self.args.flag_network_id.as_ref().or(self.args.flag_networkid.as_ref()).map_or(spec.network_id(), |id| {
U256::from_str(id).unwrap_or_else(|_| die!("{}: Invalid index given with --networkid", id)) U256::from_str(id).unwrap_or_else(|_| die!("{}: Invalid index given with --network-id/--networkid", id))
}); });
sync_config sync_config
} }

View File

@ -49,7 +49,7 @@ impl<A> Personal for PersonalClient<A> where A: AccountProvider + 'static {
|(pass, )| { |(pass, )| {
let store = take_weak!(self.accounts); let store = take_weak!(self.accounts);
match store.new_account(&pass) { match store.new_account(&pass) {
Ok(address) => Ok(Value::String(format!("{:?}", address))), Ok(address) => Ok(Value::String(format!("0x{:?}", address))),
Err(_) => Err(Error::internal_error()) Err(_) => Err(Error::internal_error())
} }
} }

View File

@ -42,6 +42,7 @@ impl TestAccount {
/// Test account provider. /// Test account provider.
pub struct TestAccountProvider { pub struct TestAccountProvider {
accounts: RwLock<HashMap<Address, TestAccount>>, accounts: RwLock<HashMap<Address, TestAccount>>,
pub adds: RwLock<Vec<String>>,
} }
impl TestAccountProvider { impl TestAccountProvider {
@ -49,6 +50,7 @@ impl TestAccountProvider {
pub fn new(accounts: HashMap<Address, TestAccount>) -> Self { pub fn new(accounts: HashMap<Address, TestAccount>) -> Self {
TestAccountProvider { TestAccountProvider {
accounts: RwLock::new(accounts), accounts: RwLock::new(accounts),
adds: RwLock::new(vec![]),
} }
} }
} }
@ -69,9 +71,13 @@ impl AccountProvider for TestAccountProvider {
} }
} }
fn new_account(&self, _pass: &str) -> Result<Address, io::Error> { fn new_account(&self, pass: &str) -> Result<Address, io::Error> {
unimplemented!() let mut adds = self.adds.write().unwrap();
let address = Address::from(adds.len() as u64 + 2);
adds.push(pass.to_owned());
Ok(address)
} }
fn account_secret(&self, _account: &Address) -> Result<Secret, SigningError> { fn account_secret(&self, _account: &Address) -> Result<Secret, SigningError> {
unimplemented!() unimplemented!()
} }

View File

@ -20,3 +20,4 @@ mod eth;
mod net; mod net;
mod web3; mod web3;
mod helpers; mod helpers;
mod personal;

View File

@ -0,0 +1,59 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 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::sync::Arc;
use jsonrpc_core::IoHandler;
use v1::tests::helpers::{TestAccount, TestAccountProvider};
use v1::{PersonalClient, Personal};
use util::numbers::*;
use std::collections::*;
fn accounts_provider() -> Arc<TestAccountProvider> {
let mut accounts = HashMap::new();
accounts.insert(Address::from(1), TestAccount::new("test"));
let ap = TestAccountProvider::new(accounts);
Arc::new(ap)
}
fn setup() -> (Arc<TestAccountProvider>, IoHandler) {
let test_provider = accounts_provider();
let personal = PersonalClient::new(&test_provider);
let io = IoHandler::new();
io.add_delegate(personal.to_delegate());
(test_provider, io)
}
#[test]
fn accounts() {
let (_test_provider, io) = setup();
let request = r#"{"jsonrpc": "2.0", "method": "personal_listAccounts", "params": [], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":["0x0000000000000000000000000000000000000001"],"id":1}"#;
assert_eq!(io.handle_request(request), Some(response.to_owned()));
}
#[test]
fn new_account() {
let (_test_provider, io) = setup();
let request = r#"{"jsonrpc": "2.0", "method": "personal_newAccount", "params": ["pass"], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"0x0000000000000000000000000000000000000002","id":1}"#;
assert_eq!(io.handle_request(request), Some(response.to_owned()));
}

View File

@ -1,5 +1,4 @@
#!/bin/sh #!/bin/sh
# Running Parity Full Test Sute # Running Parity Full Test Sute
cargo test --features ethcore/json-tests $1 -p ethash -p ethcore-util -p ethcore -p ethsync -p ethcore-rpc -p parity -p cargo test --features ethcore/json-tests $1 -p ethash -p ethcore-util -p ethcore -p ethsync -p ethcore-rpc -p parity -p ethminer
ethminer

View File

@ -171,7 +171,7 @@ impl EarlyMergeDB {
trace!(target: "jdb.fine", "replay_keys: (end) refs={:?}", refs); trace!(target: "jdb.fine", "replay_keys: (end) refs={:?}", refs);
} }
fn kill_keys(deletes: &Vec<H256>, refs: &mut HashMap<H256, RefInfo>, batch: &DBTransaction, from: RemoveFrom, trace: bool) { fn kill_keys(deletes: &[H256], refs: &mut HashMap<H256, RefInfo>, batch: &DBTransaction, from: RemoveFrom, trace: bool) {
// with a kill on {queue_refs: 1, in_archive: true}, we have two options: // with a kill on {queue_refs: 1, in_archive: true}, we have two options:
// - convert to {queue_refs: 1, in_archive: false} (i.e. remove it from the conceptual archive) // - convert to {queue_refs: 1, in_archive: false} (i.e. remove it from the conceptual archive)
// - convert to {queue_refs: 0, in_archive: true} (i.e. remove it from the conceptual queue) // - convert to {queue_refs: 0, in_archive: true} (i.e. remove it from the conceptual queue)
@ -340,6 +340,8 @@ impl JournalDB for EarlyMergeDB {
} }
} }
#[cfg_attr(feature="dev", allow(cyclomatic_complexity))]
fn commit(&mut self, now: u64, id: &H256, end: Option<(u64, H256)>) -> Result<u32, UtilError> { fn commit(&mut self, now: u64, id: &H256, end: Option<(u64, H256)>) -> Result<u32, UtilError> {
// journal format: // journal format:
// [era, 0] => [ id, [insert_0, ...], [remove_0, ...] ] // [era, 0] => [ id, [insert_0, ...], [remove_0, ...] ]
@ -473,7 +475,7 @@ impl JournalDB for EarlyMergeDB {
if trace { if trace {
trace!(target: "jdb.ops", " Finalising: {:?}", inserts); trace!(target: "jdb.ops", " Finalising: {:?}", inserts);
} }
for k in inserts.iter() { for k in &inserts {
match refs.get(k).cloned() { match refs.get(k).cloned() {
None => { None => {
// [in archive] -> SHIFT remove -> SHIFT insert None->Some{queue_refs: 1, in_archive: true} -> TAKE remove Some{queue_refs: 1, in_archive: true}->None -> TAKE insert // [in archive] -> SHIFT remove -> SHIFT insert None->Some{queue_refs: 1, in_archive: true} -> TAKE remove Some{queue_refs: 1, in_archive: true}->None -> TAKE insert
@ -489,7 +491,7 @@ impl JournalDB for EarlyMergeDB {
Self::set_already_in(&batch, k); Self::set_already_in(&batch, k);
refs.insert(k.clone(), RefInfo{ queue_refs: x - 1, in_archive: true }); refs.insert(k.clone(), RefInfo{ queue_refs: x - 1, in_archive: true });
} }
Some( RefInfo{queue_refs: _, in_archive: true} ) => { Some( RefInfo{in_archive: true, ..} ) => {
// Invalid! Reinserted the same key twice. // Invalid! Reinserted the same key twice.
warn!("Key {} inserted twice into same fork.", k); warn!("Key {} inserted twice into same fork.", k);
} }

View File

@ -18,7 +18,6 @@ use bytes::Bytes;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::collections::{HashSet, HashMap, BTreeMap, VecDeque}; use std::collections::{HashSet, HashMap, BTreeMap, VecDeque};
use std::mem; use std::mem;
use std::cmp;
use std::default::Default; use std::default::Default;
use mio::*; use mio::*;
use mio::udp::*; use mio::udp::*;
@ -407,27 +406,34 @@ impl Discovery {
let target: NodeId = try!(rlp.val_at(0)); let target: NodeId = try!(rlp.val_at(0));
let timestamp: u64 = try!(rlp.val_at(1)); let timestamp: u64 = try!(rlp.val_at(1));
try!(self.check_timestamp(timestamp)); try!(self.check_timestamp(timestamp));
let limit = (MAX_DATAGRAM_SIZE - 109) / 90;
let nearest = Discovery::nearest_node_entries(&target, &self.node_buckets); let nearest = Discovery::nearest_node_entries(&target, &self.node_buckets);
if nearest.is_empty() { if nearest.is_empty() {
return Ok(None); return Ok(None);
} }
let mut rlp = RlpStream::new_list(1); let mut packets = Discovery::prepare_neighbours_packets(&nearest);
rlp.begin_list(cmp::min(limit, nearest.len())); for p in packets.drain(..) {
for n in 0 .. nearest.len() { self.send_packet(PACKET_NEIGHBOURS, &from, &p);
rlp.begin_list(4);
nearest[n].endpoint.to_rlp(&mut rlp);
rlp.append(&nearest[n].id);
if (n + 1) % limit == 0 || n == nearest.len() - 1 {
self.send_packet(PACKET_NEIGHBOURS, &from, &rlp.drain());
trace!(target: "discovery", "Sent {} Neighbours to {:?}", n, &from);
rlp = RlpStream::new_list(1);
rlp.begin_list(cmp::min(limit, nearest.len() - n));
}
} }
trace!(target: "discovery", "Sent {} Neighbours to {:?}", nearest.len(), &from);
Ok(None) Ok(None)
} }
fn prepare_neighbours_packets(nearest: &[NodeEntry]) -> Vec<Bytes> {
let limit = (MAX_DATAGRAM_SIZE - 109) / 90;
let chunks = nearest.chunks(limit);
let packets = chunks.map(|c| {
let mut rlp = RlpStream::new_list(1);
rlp.begin_list(c.len());
for n in 0 .. c.len() {
rlp.begin_list(4);
c[n].endpoint.to_rlp(&mut rlp);
rlp.append(&c[n].id);
}
rlp.out()
});
packets.collect()
}
fn on_neighbours(&mut self, rlp: &UntrustedRlp, _node: &NodeId, from: &SocketAddr) -> Result<Option<TableUpdates>, NetworkError> { fn on_neighbours(&mut self, rlp: &UntrustedRlp, _node: &NodeId, from: &SocketAddr) -> Result<Option<TableUpdates>, NetworkError> {
// TODO: validate packet // TODO: validate packet
let mut added = HashMap::new(); let mut added = HashMap::new();
@ -506,6 +512,24 @@ mod tests {
use crypto::KeyPair; use crypto::KeyPair;
use std::str::FromStr; use std::str::FromStr;
use rustc_serialize::hex::FromHex; use rustc_serialize::hex::FromHex;
use rlp::*;
#[test]
fn find_node() {
let mut nearest = Vec::new();
let node = Node::from_str("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@127.0.0.1:7770").unwrap();
for _ in 0..1000 {
nearest.push( NodeEntry { id: node.id.clone(), endpoint: node.endpoint.clone() });
}
let packets = Discovery::prepare_neighbours_packets(&nearest);
assert_eq!(packets.len(), 77);
for p in &packets[0..76] {
assert!(p.len() > 1280/2);
assert!(p.len() <= 1280);
}
assert!(packets.last().unwrap().len() > 0);
}
#[test] #[test]
fn discovery() { fn discovery() {

View File

@ -40,7 +40,7 @@ impl<Row, Col, Val> Default for Table<Row, Col, Val>
} }
// There is default but clippy does not detect it? // There is default but clippy does not detect it?
#[allow(new_without_default)] #[cfg_attr(feature="dev", allow(new_without_default))]
impl<Row, Col, Val> Table<Row, Col, Val> impl<Row, Col, Val> Table<Row, Col, Val>
where Row: Eq + Hash + Clone, where Row: Eq + Hash + Clone,
Col: Eq + Hash { Col: Eq + Hash {