Merge
This commit is contained in:
commit
81e339a77a
37
.travis.yml
37
.travis.yml
@ -4,11 +4,13 @@ language: rust
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- /^beta-.*$/
|
||||
- /^stable-.*$/
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- rust: nightly
|
||||
env: FEATURES="--features rpc"
|
||||
env: FEATURES="--features ethcore/json-tests" KCOV_FEATURES="" TARGETS="-p ethash -p ethcore-util -p ethcore -p ethsync -p ethcore-rpc -p parity" ARCHIVE_SUFFIX="-${TRAVIS_OS_NAME}-${TRAVIS_TAG}"
|
||||
cache:
|
||||
apt: true
|
||||
directories:
|
||||
@ -27,30 +29,24 @@ before_script: |
|
||||
sudo apt-get update &&
|
||||
sudo apt-get install -y --force-yes librocksdb
|
||||
script:
|
||||
- cargo build --release --verbose
|
||||
- cargo test --release -p ethash --verbose
|
||||
- cargo test --release -p ethcore-util --verbose
|
||||
- cargo test --release -p ethcore --verbose
|
||||
- cargo test --release -p ethcore-rpc --verbose ${FEATURES}
|
||||
- cargo test --release --verbose ${FEATURES}
|
||||
- cargo bench --no-run ${FEATURES}
|
||||
- cargo build --release --verbose ${FEATURES}
|
||||
- cargo test --release --verbose ${FEATURES} ${TARGETS}
|
||||
- cargo bench --no-run ${FEATURES} ${TARGETS}
|
||||
- tar cvzf parity${ARCHIVE_SUFFIX}.tar.gz -C target/release parity
|
||||
after_success: |
|
||||
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
|
||||
tar xzf master.tar.gz && mkdir kcov-master/build && cd kcov-master/build && cmake .. && make && make install DESTDIR=../tmp && cd ../.. &&
|
||||
cargo test --no-run -p ethcore-util &&
|
||||
cargo test --no-run ${KCOV_FEATURES} ${TARGETS} &&
|
||||
./kcov-master/tmp/usr/local/bin/kcov --exclude-pattern /.cargo,/root/.multirust target/kcov target/debug/deps/ethcore_util-* &&
|
||||
cargo test --no-run -p ethash &&
|
||||
./kcov-master/tmp/usr/local/bin/kcov --exclude-pattern /.cargo,/root/.multirust target/kcov target/debug/deps/ethash-* &&
|
||||
cargo test --no-run -p ethcore --no-default-features &&
|
||||
./kcov-master/tmp/usr/local/bin/kcov --exclude-pattern /.cargo,/root/.multirust target/kcov target/debug/deps/ethcore-* &&
|
||||
cargo test --no-run -p ethcore-rpc ${FEATURES} &&
|
||||
./kcov-master/tmp/usr/local/bin/kcov --exclude-pattern /.cargo,/root/.multirust target/kcov target/debug/deps/ethsync-* &&
|
||||
./kcov-master/tmp/usr/local/bin/kcov --exclude-pattern /.cargo,/root/.multirust target/kcov target/debug/deps/ethcore_rpc-* &&
|
||||
cargo test --no-run ${FEATURES} &&
|
||||
./kcov-master/tmp/usr/local/bin/kcov --coveralls-id=${COVERALLS_TOKEN} --exclude-pattern /.cargo,/root/.multirust target/kcov target/debug/parity-* &&
|
||||
[ $TRAVIS_BRANCH = master ] &&
|
||||
[ $TRAVIS_PULL_REQUEST = false ] &&
|
||||
[ $TRAVIS_RUST_VERSION = nightly ] &&
|
||||
cargo doc ${FEATURES} --no-deps --verbose -p ethcore -p ethcore-util -p ethcore-rpc -p parity -p ethash -p ethsync &&
|
||||
cargo doc --no-deps --verbose ${KCOV_FEATURES} ${TARGETS} &&
|
||||
echo '<meta http-equiv=refresh content=0;url=ethcore/index.html>' > target/doc/index.html &&
|
||||
pip install --user ghp-import &&
|
||||
/home/travis/.local/bin/ghp-import -n target/doc
|
||||
@ -58,5 +54,14 @@ after_success: |
|
||||
#git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
|
||||
env:
|
||||
global:
|
||||
secure: 3sUjNi9mhdL5h1GTm8LONnDN/SYvUHT+WSkMl93h3nYiLCQXk8eZaPS98AS7oOaTsfW4UvnwckVFCFl49ttInsv4cd/TkAxmrJHe6kPyS9/4NWUdmP8BjicbBvL/ioSdXMECMEYzPDLV+I3KhtC2LcB6ceDEl/XwMOJlzbGf7RbtcXGVQgMLqSYY1YKjQA4vbT5nFgIS/sZu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nb82zj9pVJhVXq0xF44WXJ8Za1jm0ByiTakgqpm8Juk822qjvtNulJ1XZW/fyZQZaN1dy3uq5Ud3W8wS9M7VIVl8CoXozzDpIsdPeUAtkAxeHBsZqL1vAH2yC1YJA7HPySMYzCjYqkJ2r62xYk0gXmNXphfU+F/X/rHzHsTMJPONJ54HQwu12m7zVlKIYBGHgEXg/HAM/g4ljUzl6WWR/nHH/tQM8ND/8FpHluJSZJWacq/1QNhVdTq2x6cqws2fs5A7nVpccR9+6RRgYgv6+YS2LxvFzByuZveGGoKif+uMECXN876j40araUqU528Yz9i8bHJlnM3coRBndaLNWByLcUyXCB9r9IUosUu41rr+L2mVzkSDm0GicuNCzqvzYQ9Q6QY4uQ=
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key:
|
||||
secure: ATorsRujvWN9y4bZlUdp2I0hvh3pKkpkrr/oyQyt8ZssE7ORx1+lYgTdYocHyx53uBrGFjRQbSCvdDsrs8c1v2Dh2872TmMQMWgLaeeS6bPiNw7WkJuH1hvvTNAiFCfuT9nnntFvMuKcUpBHQ1eeuEU
|
||||
skip_cleanup: true
|
||||
file: parity${ARCHIVE_SUFFIX}.tar.gz
|
||||
on:
|
||||
tags: true
|
||||
|
@ -19,6 +19,7 @@ ethsync = { path = "sync" }
|
||||
ethcore-rpc = { path = "rpc", optional = true }
|
||||
|
||||
[features]
|
||||
default = ["rpc"]
|
||||
rpc = ["ethcore-rpc"]
|
||||
|
||||
[[bin]]
|
||||
|
4
cov.sh
4
cov.sh
@ -15,7 +15,7 @@ if ! type kcov > /dev/null; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cargo test --no-run || exit $?
|
||||
cargo test -p ethcore --no-run || exit $?
|
||||
mkdir -p target/coverage
|
||||
kcov --exclude-pattern ~/.multirust,rocksdb,secp256k1 --include-pattern src --verify target/coverage target/debug/ethcore*
|
||||
kcov --exclude-pattern ~/.multirust,rocksdb,secp256k1 --include-pattern src --verify target/coverage target/debug/deps/ethcore*
|
||||
xdg-open target/coverage/index.html
|
||||
|
@ -3,7 +3,7 @@ description = "Ethcore library"
|
||||
homepage = "http://ethcore.io"
|
||||
license = "GPL-3.0"
|
||||
name = "ethcore"
|
||||
version = "0.1.0"
|
||||
version = "0.9.0"
|
||||
authors = ["Ethcore <admin@ethcore.io>"]
|
||||
|
||||
[dependencies]
|
||||
@ -25,7 +25,6 @@ crossbeam = "0.1.5"
|
||||
lazy_static = "0.1"
|
||||
|
||||
[features]
|
||||
default = ["json-tests"]
|
||||
jit = ["evmjit"]
|
||||
evm-debug = []
|
||||
json-tests = []
|
||||
|
@ -129,6 +129,9 @@ struct CacheManager {
|
||||
///
|
||||
/// **Does not do input data verification.**
|
||||
pub struct BlockChain {
|
||||
pref_cache_size: usize,
|
||||
max_cache_size: usize,
|
||||
|
||||
best_block: RwLock<BestBlock>,
|
||||
|
||||
// block cache
|
||||
@ -190,9 +193,7 @@ impl BlockProvider for BlockChain {
|
||||
}
|
||||
}
|
||||
|
||||
const COLLECTION_QUEUE_SIZE: usize = 2;
|
||||
const MIN_CACHE_SIZE: usize = 1;
|
||||
const MAX_CACHE_SIZE: usize = 1024 * 1024;
|
||||
const COLLECTION_QUEUE_SIZE: usize = 8;
|
||||
|
||||
impl BlockChain {
|
||||
/// Create new instance of blockchain from given Genesis
|
||||
@ -237,6 +238,8 @@ impl BlockChain {
|
||||
(0..COLLECTION_QUEUE_SIZE).foreach(|_| cache_man.cache_usage.push_back(HashSet::new()));
|
||||
|
||||
let bc = BlockChain {
|
||||
pref_cache_size: 1 << 14,
|
||||
max_cache_size: 1 << 20,
|
||||
best_block: RwLock::new(BestBlock::new()),
|
||||
blocks: RwLock::new(HashMap::new()),
|
||||
block_details: RwLock::new(HashMap::new()),
|
||||
@ -288,6 +291,12 @@ impl BlockChain {
|
||||
bc
|
||||
}
|
||||
|
||||
/// Set the cache configuration.
|
||||
pub fn configure_cache(&mut self, pref_cache_size: usize, max_cache_size: usize) {
|
||||
self.pref_cache_size = pref_cache_size;
|
||||
self.max_cache_size = max_cache_size;
|
||||
}
|
||||
|
||||
/// Returns a tree route between `from` and `to`, which is a tuple of:
|
||||
///
|
||||
/// - a vector of hashes of all blocks, ordered from `from` to `to`.
|
||||
@ -339,12 +348,12 @@ impl BlockChain {
|
||||
Some(h) => h,
|
||||
None => return None,
|
||||
};
|
||||
Some(self._tree_route((&from_details, &from), (&to_details, &to)))
|
||||
Some(self.tree_route_aux((&from_details, &from), (&to_details, &to)))
|
||||
}
|
||||
|
||||
/// Similar to `tree_route` function, but can be used to return a route
|
||||
/// between blocks which may not be in database yet.
|
||||
fn _tree_route(&self, from: (&BlockDetails, &H256), to: (&BlockDetails, &H256)) -> TreeRoute {
|
||||
fn tree_route_aux(&self, from: (&BlockDetails, &H256), to: (&BlockDetails, &H256)) -> TreeRoute {
|
||||
let mut from_branch = vec![];
|
||||
let mut to_branch = vec![];
|
||||
|
||||
@ -465,7 +474,7 @@ impl BlockChain {
|
||||
// find the route between old best block and the new one
|
||||
let best_hash = self.best_block_hash();
|
||||
let best_details = self.block_details(&best_hash).expect("best block hash is invalid!");
|
||||
let route = self._tree_route((&best_details, &best_hash), (&details, &hash));
|
||||
let route = self.tree_route_aux((&best_details, &best_hash), (&details, &hash));
|
||||
|
||||
match route.blocks.len() {
|
||||
// its our parent
|
||||
@ -581,13 +590,11 @@ impl BlockChain {
|
||||
}
|
||||
|
||||
/// Ticks our cache system and throws out any old data.
|
||||
pub fn collect_garbage(&self, force: bool) {
|
||||
// TODO: check time.
|
||||
let timeout = true;
|
||||
|
||||
let t = self.cache_size().total();
|
||||
if t < MIN_CACHE_SIZE || (!timeout && (!force || t < MAX_CACHE_SIZE)) { return; }
|
||||
pub fn collect_garbage(&self) {
|
||||
if self.cache_size().total() < self.pref_cache_size { return; }
|
||||
|
||||
for _ in 0..COLLECTION_QUEUE_SIZE {
|
||||
{
|
||||
let mut cache_man = self.cache_man.write().unwrap();
|
||||
let mut blocks = self.blocks.write().unwrap();
|
||||
let mut block_details = self.block_details.write().unwrap();
|
||||
@ -611,6 +618,9 @@ impl BlockChain {
|
||||
|
||||
// TODO: handle block_hashes properly.
|
||||
block_hashes.clear();
|
||||
}
|
||||
if self.cache_size().total() < self.max_cache_size { break; }
|
||||
}
|
||||
|
||||
// TODO: m_lastCollection = chrono::system_clock::now();
|
||||
}
|
||||
@ -786,7 +796,7 @@ mod tests {
|
||||
assert!(bc.cache_size().blocks > 1024 * 1024);
|
||||
|
||||
for _ in 0..2 {
|
||||
bc.collect_garbage(true);
|
||||
bc.collect_garbage();
|
||||
}
|
||||
assert!(bc.cache_size().blocks < 1024 * 1024);
|
||||
}
|
||||
|
@ -298,7 +298,12 @@ impl Client {
|
||||
|
||||
/// Tick the client.
|
||||
pub fn tick(&self) {
|
||||
self.chain.read().unwrap().collect_garbage(false);
|
||||
self.chain.read().unwrap().collect_garbage();
|
||||
}
|
||||
|
||||
/// Set up the cache behaviour.
|
||||
pub fn configure_cache(&self, pref_cache_size: usize, max_cache_size: usize) {
|
||||
self.chain.write().unwrap().configure_cache(pref_cache_size, max_cache_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,9 +35,15 @@ Usage:
|
||||
parity [options] <enode>...
|
||||
|
||||
Options:
|
||||
-l --logging LOGGING Specify the logging level
|
||||
-l --logging LOGGING Specify the logging level.
|
||||
-j --jsonrpc Enable the JSON-RPC API sever.
|
||||
--jsonrpc-url URL Specify URL for JSON-RPC API server (default: 127.0.0.1:8545).
|
||||
|
||||
--cache-pref-size BYTES Specify the prefered size of the blockchain cache in bytes (default: 16384).
|
||||
--cache-max-size BYTES Specify the maximum size of the blockchain cache in bytes (default: 262144).
|
||||
|
||||
-h --help Show this screen.
|
||||
");
|
||||
", flag_cache_pref_size: usize, flag_cache_max_size: usize);
|
||||
|
||||
fn setup_log(init: &str) {
|
||||
let mut builder = LogBuilder::new();
|
||||
@ -54,7 +60,7 @@ fn setup_log(init: &str) {
|
||||
|
||||
|
||||
#[cfg(feature = "rpc")]
|
||||
fn setup_rpc_server(client: Arc<Client>, sync: Arc<EthSync>) {
|
||||
fn setup_rpc_server(client: Arc<Client>, sync: Arc<EthSync>, url: &str) {
|
||||
use rpc::v1::*;
|
||||
|
||||
let mut server = rpc::HttpServer::new(1);
|
||||
@ -62,11 +68,11 @@ fn setup_rpc_server(client: Arc<Client>, sync: Arc<EthSync>) {
|
||||
server.add_delegate(EthClient::new(client.clone()).to_delegate());
|
||||
server.add_delegate(EthFilterClient::new(client).to_delegate());
|
||||
server.add_delegate(NetClient::new(sync).to_delegate());
|
||||
server.start_async("127.0.0.1:3030");
|
||||
server.start_async(url);
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "rpc"))]
|
||||
fn setup_rpc_server(_client: Arc<Client>, _sync: Arc<EthSync>) {
|
||||
fn setup_rpc_server(_client: Arc<Client>, _sync: Arc<EthSync>, _url: &str) {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@ -83,8 +89,11 @@ fn main() {
|
||||
net_settings.boot_nodes = init_nodes;
|
||||
let mut service = ClientService::start(spec, net_settings).unwrap();
|
||||
let client = service.client().clone();
|
||||
client.configure_cache(args.flag_cache_pref_size, args.flag_cache_max_size);
|
||||
let sync = EthSync::register(service.network(), client);
|
||||
setup_rpc_server(service.client(), sync.clone());
|
||||
if args.flag_jsonrpc {
|
||||
setup_rpc_server(service.client(), sync.clone(), &args.flag_jsonrpc_url);
|
||||
}
|
||||
let io_handler = Arc::new(ClientIoHandler { client: service.client(), info: Default::default(), sync: sync });
|
||||
service.io().register_handler(io_handler).expect("Error registering IO handler");
|
||||
|
||||
@ -169,3 +178,7 @@ impl IoHandler<NetSyncMessage> for ClientIoHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/// Parity needs at least 1 test to generate coverage reports correctly.
|
||||
#[test]
|
||||
fn if_works() {
|
||||
}
|
||||
|
@ -42,3 +42,8 @@ impl HttpServer {
|
||||
server.start_async(addr)
|
||||
}
|
||||
}
|
||||
|
||||
/// Lib needs at least 1 test to generate coverage reports correctly.
|
||||
#[test]
|
||||
fn if_works() {
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ description = "Ethcore utility library"
|
||||
homepage = "http://ethcore.io"
|
||||
license = "GPL-3.0"
|
||||
name = "ethcore-util"
|
||||
version = "0.1.0"
|
||||
version = "0.9.0"
|
||||
authors = ["Ethcore <admin@ethcore.io>"]
|
||||
|
||||
[dependencies]
|
||||
@ -28,3 +28,4 @@ sha3 = { path = "sha3" }
|
||||
serde = "0.6.7"
|
||||
clippy = "0.0.37"
|
||||
json-tests = { path = "json-tests" }
|
||||
target_info = "0.1.0"
|
||||
|
@ -63,9 +63,9 @@ fn bench_stream_nested_empty_lists(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
// [ [], [[]], [ [], [[]] ] ]
|
||||
let mut stream = RlpStream::new_list(3);
|
||||
stream.append_list(0);
|
||||
stream.append_list(1).append_list(0);
|
||||
stream.append_list(2).append_list(0).append_list(1).append_list(0);
|
||||
stream.begin_list(0);
|
||||
stream.begin_list(1).begin_list(0);
|
||||
stream.begin_list(2).begin_list(0).begin_list(1).begin_list(0);
|
||||
let _ = stream.out();
|
||||
});
|
||||
}
|
||||
@ -89,7 +89,7 @@ fn bench_stream_1000_empty_lists(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let mut stream = RlpStream::new_list(1000);
|
||||
for _ in 0..1000 {
|
||||
stream.append_list(0);
|
||||
stream.begin_list(0);
|
||||
}
|
||||
let _ = stream.out();
|
||||
});
|
||||
|
@ -42,6 +42,84 @@ fn random_value(seed: &mut H256) -> Bytes {
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn trie_insertions_32_mir_1k(b: &mut Bencher) {
|
||||
let st = StandardMap {
|
||||
alphabet: Alphabet::All,
|
||||
min_key: 32,
|
||||
journal_key: 0,
|
||||
value_mode: ValueMode::Mirror,
|
||||
count: 1000,
|
||||
};
|
||||
let d = st.make();
|
||||
let mut hash_count = 0usize;
|
||||
b.iter(&mut ||{
|
||||
let mut memdb = MemoryDB::new();
|
||||
let mut root = H256::new();
|
||||
let mut t = TrieDBMut::new(&mut memdb, &mut root);
|
||||
for i in d.iter() {
|
||||
t.insert(&i.0, &i.1);
|
||||
}
|
||||
hash_count = t.hash_count;
|
||||
});
|
||||
// println!("hash_count: {}", hash_count);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn triehash_insertions_32_mir_1k(b: &mut Bencher) {
|
||||
let st = StandardMap {
|
||||
alphabet: Alphabet::All,
|
||||
min_key: 32,
|
||||
journal_key: 0,
|
||||
value_mode: ValueMode::Mirror,
|
||||
count: 1000,
|
||||
};
|
||||
let d = st.make();
|
||||
b.iter(&mut ||{
|
||||
trie_root(d.clone()).clone();
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn trie_insertions_32_ran_1k(b: &mut Bencher) {
|
||||
let st = StandardMap {
|
||||
alphabet: Alphabet::All,
|
||||
min_key: 32,
|
||||
journal_key: 0,
|
||||
value_mode: ValueMode::Random,
|
||||
count: 1000,
|
||||
};
|
||||
let d = st.make();
|
||||
let mut hash_count = 0usize;
|
||||
let mut r = H256::new();
|
||||
b.iter(&mut ||{
|
||||
let mut memdb = MemoryDB::new();
|
||||
let mut root = H256::new();
|
||||
let mut t = TrieDBMut::new(&mut memdb, &mut root);
|
||||
for i in d.iter() {
|
||||
t.insert(&i.0, &i.1);
|
||||
}
|
||||
hash_count = t.hash_count;
|
||||
r = t.root().clone();
|
||||
});
|
||||
// println!("result: {}", hash_count);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn triehash_insertions_32_ran_1k(b: &mut Bencher) {
|
||||
let st = StandardMap {
|
||||
alphabet: Alphabet::All,
|
||||
min_key: 32,
|
||||
journal_key: 0,
|
||||
value_mode: ValueMode::Random,
|
||||
count: 1000,
|
||||
};
|
||||
let d = st.make();
|
||||
b.iter(&mut ||{
|
||||
trie_root(d.clone()).clone();
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn trie_insertions_six_high(b: &mut Bencher) {
|
||||
let mut d: Vec<(Bytes, Bytes)> = Vec::new();
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! Utils common types and macros global reexport.
|
||||
|
||||
pub use standard::*;
|
||||
pub use from_json::*;
|
||||
pub use error::*;
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! Ethcore crypto.
|
||||
|
||||
use hash::*;
|
||||
use bytes::*;
|
||||
use uint::*;
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! Coversion from json.
|
||||
|
||||
use standard::*;
|
||||
|
||||
#[macro_export]
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! Calculates heapsize of util types.
|
||||
|
||||
use uint::*;
|
||||
use hash::*;
|
||||
|
||||
|
@ -1,41 +1,41 @@
|
||||
/// General IO module.
|
||||
///
|
||||
/// Example usage for craeting a network service and adding an IO handler:
|
||||
///
|
||||
/// ```rust
|
||||
/// extern crate ethcore_util;
|
||||
/// use ethcore_util::*;
|
||||
///
|
||||
/// struct MyHandler;
|
||||
///
|
||||
/// #[derive(Clone)]
|
||||
/// struct MyMessage {
|
||||
/// data: u32
|
||||
/// }
|
||||
///
|
||||
/// impl IoHandler<MyMessage> for MyHandler {
|
||||
/// fn initialize(&self, io: &IoContext<MyMessage>) {
|
||||
/// io.register_timer(0, 1000).unwrap();
|
||||
/// }
|
||||
///
|
||||
/// fn timeout(&self, _io: &IoContext<MyMessage>, timer: TimerToken) {
|
||||
/// println!("Timeout {}", timer);
|
||||
/// }
|
||||
///
|
||||
/// fn message(&self, _io: &IoContext<MyMessage>, message: &MyMessage) {
|
||||
/// println!("Message {}", message.data);
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// fn main () {
|
||||
/// let mut service = IoService::<MyMessage>::start().expect("Error creating network service");
|
||||
/// service.register_handler(Arc::new(MyHandler)).unwrap();
|
||||
///
|
||||
/// // Wait for quit condition
|
||||
/// // ...
|
||||
/// // Drop the service
|
||||
/// }
|
||||
/// ```
|
||||
//! General IO module.
|
||||
//!
|
||||
//! Example usage for creating a network service and adding an IO handler:
|
||||
//!
|
||||
//! ```rust
|
||||
//! extern crate ethcore_util;
|
||||
//! use ethcore_util::*;
|
||||
//!
|
||||
//! struct MyHandler;
|
||||
//!
|
||||
//! #[derive(Clone)]
|
||||
//! struct MyMessage {
|
||||
//! data: u32
|
||||
//! }
|
||||
//!
|
||||
//! impl IoHandler<MyMessage> for MyHandler {
|
||||
//! fn initialize(&self, io: &IoContext<MyMessage>) {
|
||||
//! io.register_timer(0, 1000).unwrap();
|
||||
//! }
|
||||
//!
|
||||
//! fn timeout(&self, _io: &IoContext<MyMessage>, timer: TimerToken) {
|
||||
//! println!("Timeout {}", timer);
|
||||
//! }
|
||||
//!
|
||||
//! fn message(&self, _io: &IoContext<MyMessage>, message: &MyMessage) {
|
||||
//! println!("Message {}", message.data);
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! fn main () {
|
||||
//! let mut service = IoService::<MyMessage>::start().expect("Error creating network service");
|
||||
//! service.register_handler(Arc::new(MyHandler)).unwrap();
|
||||
//!
|
||||
//! // Wait for quit condition
|
||||
//! // ...
|
||||
//! // Drop the service
|
||||
//! }
|
||||
//! ```
|
||||
mod service;
|
||||
mod worker;
|
||||
|
||||
|
@ -8,32 +8,58 @@
|
||||
//! Ethcore-util library
|
||||
//!
|
||||
//! ### Rust version:
|
||||
//! - beta
|
||||
//! - nightly
|
||||
//!
|
||||
//! ### Supported platforms:
|
||||
//! - OSX
|
||||
//! - Linux
|
||||
//!
|
||||
//! ### Dependencies:
|
||||
//! - RocksDB 3.13
|
||||
//! ### Building:
|
||||
//!
|
||||
//! ### Dependencies Installation:
|
||||
//! - Ubuntu 14.04 and later:
|
||||
//!
|
||||
//! ```bash
|
||||
//! # install rocksdb
|
||||
//! add-apt-repository "deb http://ppa.launchpad.net/giskou/librocksdb/ubuntu trusty main"
|
||||
//! apt-get update
|
||||
//! apt-get install -y --force-yes librocksdb
|
||||
//!
|
||||
//! # install multirust
|
||||
//! curl -sf https://raw.githubusercontent.com/brson/multirust/master/blastoff.sh | sh -s -- --yes
|
||||
//!
|
||||
//! # install nightly and make it default
|
||||
//! multirust update nightly && multirust default nightly
|
||||
//!
|
||||
//! # export rust LIBRARY_PATH
|
||||
//! export LIBRARY_PATH=/usr/local/lib
|
||||
//!
|
||||
//! # download and build parity
|
||||
//! git clone https://github.com/ethcore/parity
|
||||
//! cd parity
|
||||
//! cargo build --release
|
||||
//! ```
|
||||
//!
|
||||
//! - OSX:
|
||||
//!
|
||||
//! ```bash
|
||||
//! # install rocksdb && multirust
|
||||
//! brew update
|
||||
//! brew install rocksdb
|
||||
//! ```
|
||||
//! brew install multirust
|
||||
//!
|
||||
//! - From source:
|
||||
//! # install nightly and make it default
|
||||
//! multirust update nightly && multirust default nightly
|
||||
//!
|
||||
//! ```bash
|
||||
//! wget https://github.com/facebook/rocksdb/archive/rocksdb-3.13.tar.gz
|
||||
//! tar xvf rocksdb-3.13.tar.gz && cd rocksdb-rocksdb-3.13 && make shared_lib
|
||||
//! sudo make install
|
||||
//! # export rust LIBRARY_PATH
|
||||
//! export LIBRARY_PATH=/usr/local/lib
|
||||
//!
|
||||
//! # download and build parity
|
||||
//! git clone https://github.com/ethcore/parity
|
||||
//! cd parity
|
||||
//! cargo build --release
|
||||
//! ```
|
||||
|
||||
extern crate target_info;
|
||||
extern crate slab;
|
||||
extern crate rustc_serialize;
|
||||
extern crate mio;
|
||||
@ -57,46 +83,34 @@ extern crate serde;
|
||||
#[macro_use]
|
||||
extern crate log as rlog;
|
||||
|
||||
/// TODO [Gav Wood] Please document me
|
||||
pub mod standard;
|
||||
#[macro_use]
|
||||
/// TODO [Gav Wood] Please document me
|
||||
pub mod from_json;
|
||||
#[macro_use]
|
||||
/// TODO [Gav Wood] Please document me
|
||||
pub mod common;
|
||||
pub mod error;
|
||||
pub mod hash;
|
||||
pub mod uint;
|
||||
pub mod bytes;
|
||||
pub mod rlp;
|
||||
/// TODO [Gav Wood] Please document me
|
||||
pub mod misc;
|
||||
/// TODO [Gav Wood] Please document me
|
||||
pub mod json_aid;
|
||||
mod json_aid;
|
||||
pub mod vector;
|
||||
pub mod sha3;
|
||||
pub mod hashdb;
|
||||
pub mod memorydb;
|
||||
pub mod overlaydb;
|
||||
pub mod journaldb;
|
||||
/// TODO [Gav Wood] Please document me
|
||||
pub mod math;
|
||||
mod math;
|
||||
pub mod chainfilter;
|
||||
/// TODO [Gav Wood] Please document me
|
||||
pub mod crypto;
|
||||
pub mod triehash;
|
||||
/// TODO [Gav Wood] Please document me
|
||||
pub mod trie;
|
||||
pub mod nibbleslice;
|
||||
/// TODO [Gav Wood] Please document me
|
||||
pub mod heapsizeof;
|
||||
mod heapsizeof;
|
||||
pub mod squeeze;
|
||||
/// TODO [Gav Wood] Please document me
|
||||
pub mod semantic_version;
|
||||
/// TODO [Gav Wood] Please document me
|
||||
pub mod io;
|
||||
/// TODO [Gav Wood] Please document me
|
||||
pub mod network;
|
||||
pub mod log;
|
||||
|
||||
@ -114,7 +128,6 @@ pub use crypto::*;
|
||||
pub use triehash::*;
|
||||
pub use trie::*;
|
||||
pub use nibbleslice::*;
|
||||
pub use heapsizeof::*;
|
||||
pub use squeeze::*;
|
||||
pub use semantic_version::*;
|
||||
pub use network::*;
|
||||
|
@ -1,4 +1,6 @@
|
||||
/// log2
|
||||
//! Common math functions.
|
||||
|
||||
/// Returns log2.
|
||||
pub fn log2(x: usize) -> u32 {
|
||||
if x <= 1 {
|
||||
return 0;
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! Diff misc.
|
||||
|
||||
use common::*;
|
||||
|
||||
#[derive(Debug,Clone,PartialEq,Eq)]
|
||||
|
@ -7,6 +7,7 @@ use std::ops::*;
|
||||
use mio::*;
|
||||
use mio::tcp::*;
|
||||
use mio::udp::*;
|
||||
use target_info::Target;
|
||||
use hash::*;
|
||||
use crypto::*;
|
||||
use sha3::Hashable;
|
||||
@ -294,7 +295,7 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
|
||||
config: config,
|
||||
nonce: H256::random(),
|
||||
protocol_version: 4,
|
||||
client_version: "parity".to_owned(),
|
||||
client_version: format!("Parity/{}/{}-{}-{}", env!("CARGO_PKG_VERSION"), Target::arch(), Target::env(), Target::os()),
|
||||
listen_port: 0,
|
||||
capabilities: Vec::new(),
|
||||
}),
|
||||
|
@ -1,52 +1,53 @@
|
||||
/// Network and general IO module.
|
||||
/// Example usage for craeting a network service and adding an IO handler:
|
||||
///
|
||||
/// ```rust
|
||||
/// extern crate ethcore_util as util;
|
||||
/// use util::*;
|
||||
///
|
||||
/// struct MyHandler;
|
||||
///
|
||||
/// #[derive(Clone)]
|
||||
/// struct MyMessage {
|
||||
/// data: u32
|
||||
/// }
|
||||
///
|
||||
/// impl NetworkProtocolHandler<MyMessage> for MyHandler {
|
||||
/// fn initialize(&self, io: &NetworkContext<MyMessage>) {
|
||||
/// io.register_timer(0, 1000);
|
||||
/// }
|
||||
///
|
||||
/// fn read(&self, io: &NetworkContext<MyMessage>, peer: &PeerId, packet_id: u8, data: &[u8]) {
|
||||
/// println!("Received {} ({} bytes) from {}", packet_id, data.len(), peer);
|
||||
/// }
|
||||
///
|
||||
/// fn connected(&self, io: &NetworkContext<MyMessage>, peer: &PeerId) {
|
||||
/// println!("Connected {}", peer);
|
||||
/// }
|
||||
///
|
||||
/// fn disconnected(&self, io: &NetworkContext<MyMessage>, peer: &PeerId) {
|
||||
/// println!("Disconnected {}", peer);
|
||||
/// }
|
||||
///
|
||||
/// fn timeout(&self, io: &NetworkContext<MyMessage>, timer: TimerToken) {
|
||||
/// println!("Timeout {}", timer);
|
||||
/// }
|
||||
///
|
||||
/// fn message(&self, io: &NetworkContext<MyMessage>, message: &MyMessage) {
|
||||
/// println!("Message {}", message.data);
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// fn main () {
|
||||
/// let mut service = NetworkService::<MyMessage>::start(NetworkConfiguration::new()).expect("Error creating network service");
|
||||
/// service.register_protocol(Arc::new(MyHandler), "myproto", &[1u8]);
|
||||
///
|
||||
/// // Wait for quit condition
|
||||
/// // ...
|
||||
/// // Drop the service
|
||||
/// }
|
||||
/// ```
|
||||
//! Network and general IO module.
|
||||
//!
|
||||
//! Example usage for craeting a network service and adding an IO handler:
|
||||
//!
|
||||
//! ```rust
|
||||
//! extern crate ethcore_util as util;
|
||||
//! use util::*;
|
||||
//!
|
||||
//! struct MyHandler;
|
||||
//!
|
||||
//! #[derive(Clone)]
|
||||
//! struct MyMessage {
|
||||
//! data: u32
|
||||
//! }
|
||||
//!
|
||||
//! impl NetworkProtocolHandler<MyMessage> for MyHandler {
|
||||
//! fn initialize(&self, io: &NetworkContext<MyMessage>) {
|
||||
//! io.register_timer(0, 1000);
|
||||
//! }
|
||||
//!
|
||||
//! fn read(&self, io: &NetworkContext<MyMessage>, peer: &PeerId, packet_id: u8, data: &[u8]) {
|
||||
//! println!("Received {} ({} bytes) from {}", packet_id, data.len(), peer);
|
||||
//! }
|
||||
//!
|
||||
//! fn connected(&self, io: &NetworkContext<MyMessage>, peer: &PeerId) {
|
||||
//! println!("Connected {}", peer);
|
||||
//! }
|
||||
//!
|
||||
//! fn disconnected(&self, io: &NetworkContext<MyMessage>, peer: &PeerId) {
|
||||
//! println!("Disconnected {}", peer);
|
||||
//! }
|
||||
//!
|
||||
//! fn timeout(&self, io: &NetworkContext<MyMessage>, timer: TimerToken) {
|
||||
//! println!("Timeout {}", timer);
|
||||
//! }
|
||||
//!
|
||||
//! fn message(&self, io: &NetworkContext<MyMessage>, message: &MyMessage) {
|
||||
//! println!("Message {}", message.data);
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! fn main () {
|
||||
//! let mut service = NetworkService::<MyMessage>::start(NetworkConfiguration::new()).expect("Error creating network service");
|
||||
//! service.register_protocol(Arc::new(MyHandler), "myproto", &[1u8]);
|
||||
//!
|
||||
//! // Wait for quit condition
|
||||
//! // ...
|
||||
//! // Drop the service
|
||||
//! }
|
||||
//! ```
|
||||
mod host;
|
||||
mod connection;
|
||||
mod handshake;
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! Semantic version formatting and comparing.
|
||||
|
||||
/// A version value with strict meaning. Use `to_u32` to convert to a simple integer.
|
||||
///
|
||||
/// # Example
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! Std lib global reexports.
|
||||
|
||||
pub use std::io;
|
||||
pub use std::fs;
|
||||
pub use std::str;
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! Trie interface and implementation.
|
||||
|
||||
/// TODO [Gav Wood] Please document me
|
||||
pub mod trietraits;
|
||||
pub mod standardmap;
|
||||
|
@ -17,12 +17,26 @@ pub enum Alphabet {
|
||||
Custom(Bytes),
|
||||
}
|
||||
|
||||
/// Means of determining the value.
|
||||
pub enum ValueMode {
|
||||
/// Same as the key.
|
||||
Mirror,
|
||||
/// Randomly (50:50) 1 or 32 byte randomly string.
|
||||
Random,
|
||||
}
|
||||
|
||||
/// Standard test map for profiling tries.
|
||||
pub struct StandardMap {
|
||||
alphabet: Alphabet,
|
||||
min_key: usize,
|
||||
journal_key: usize,
|
||||
count: usize,
|
||||
/// The alphabet to use for keys.
|
||||
pub alphabet: Alphabet,
|
||||
/// Minimum size of key.
|
||||
pub min_key: usize,
|
||||
/// Delta size of key.
|
||||
pub journal_key: usize,
|
||||
/// Mode of value generation.
|
||||
pub value_mode: ValueMode,
|
||||
/// Number of keys.
|
||||
pub count: usize,
|
||||
}
|
||||
|
||||
impl StandardMap {
|
||||
@ -71,7 +85,7 @@ impl StandardMap {
|
||||
Alphabet::Mid => Self::random_word(mid, self.min_key, self.journal_key, &mut seed),
|
||||
Alphabet::Custom(ref a) => Self::random_word(&a, self.min_key, self.journal_key, &mut seed),
|
||||
};
|
||||
let v = Self::random_value(&mut seed);
|
||||
let v = match self.value_mode { ValueMode::Mirror => k.clone(), ValueMode::Random => Self::random_value(&mut seed) };
|
||||
d.push((k, v))
|
||||
}
|
||||
d
|
||||
|
@ -1,40 +1,4 @@
|
||||
//! vector util functions
|
||||
|
||||
use std::ptr;
|
||||
|
||||
/// TODO [debris] Please document me
|
||||
pub trait InsertSlice<T> {
|
||||
/// TODO [debris] Please document me
|
||||
fn insert_slice(&mut self, index: usize, elements: &[T]);
|
||||
}
|
||||
|
||||
/// based on `insert` function implementation from standard library
|
||||
impl<T> InsertSlice<T> for Vec<T> {
|
||||
fn insert_slice(&mut self, index: usize, elements: &[T]) {
|
||||
let e_len = elements.len();
|
||||
if e_len == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
let len = self.len();
|
||||
assert!(index <= len);
|
||||
|
||||
// space for the new element
|
||||
self.reserve(e_len);
|
||||
|
||||
unsafe {
|
||||
{
|
||||
let p = self.as_mut_ptr().offset(index as isize);
|
||||
let ep = elements.as_ptr().offset(0);
|
||||
// shift everything by e_len, to make space
|
||||
ptr::copy(p, p.offset(e_len as isize), len - index);
|
||||
// write new element
|
||||
ptr::copy(ep, p, e_len);
|
||||
}
|
||||
self.set_len(len + e_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
//! Vector extensions.
|
||||
|
||||
/// Returns len of prefix shared with elem
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user