for Builtin {
@@ -108,14 +109,13 @@ struct Sha256;
struct Ripemd160;
impl Impl for Identity {
- fn execute(&self, input: &[u8], output: &mut [u8]) {
- let len = min(input.len(), output.len());
- output[..len].copy_from_slice(&input[..len]);
+ fn execute(&self, input: &[u8], output: &mut BytesRef) {
+ output.write(0, input);
}
}
impl Impl for EcRecover {
- fn execute(&self, i: &[u8], output: &mut [u8]) {
+ fn execute(&self, i: &[u8], output: &mut BytesRef) {
let len = min(i.len(), 128);
let mut input = [0; 128];
@@ -135,58 +135,34 @@ impl Impl for EcRecover {
if s.is_valid() {
if let Ok(p) = ec_recover(&s, &hash) {
let r = p.sha3();
-
- let out_len = min(output.len(), 32);
-
- for x in &mut output[0.. min(12, out_len)] {
- *x = 0;
- }
-
- if out_len > 12 {
- output[12..out_len].copy_from_slice(&r[12..out_len]);
- }
+ output.write(0, &[0; 12]);
+ output.write(12, &r[12..r.len()]);
}
}
}
}
impl Impl for Sha256 {
- fn execute(&self, input: &[u8], output: &mut [u8]) {
- let out_len = min(output.len(), 32);
-
+ fn execute(&self, input: &[u8], output: &mut BytesRef) {
let mut sha = Sha256Digest::new();
sha.input(input);
- if out_len == 32 {
- sha.result(&mut output[0..32]);
- } else {
- let mut out = [0; 32];
- sha.result(&mut out);
+ let mut out = [0; 32];
+ sha.result(&mut out);
- output.copy_from_slice(&out[..out_len])
- }
+ output.write(0, &out);
}
}
impl Impl for Ripemd160 {
- fn execute(&self, input: &[u8], output: &mut [u8]) {
- let out_len = min(output.len(), 32);
-
+ fn execute(&self, input: &[u8], output: &mut BytesRef) {
let mut sha = Ripemd160Digest::new();
sha.input(input);
- for x in &mut output[0.. min(12, out_len)] {
- *x = 0;
- }
+ let mut out = [0; 32];
+ sha.result(&mut out[12..32]);
- if out_len >= 32 {
- sha.result(&mut output[12..32]);
- } else if out_len > 12 {
- let mut out = [0; 20];
- sha.result(&mut out);
-
- output.copy_from_slice(&out[12..out_len])
- }
+ output.write(0, &out);
}
}
@@ -194,7 +170,7 @@ impl Impl for Ripemd160 {
mod tests {
use super::{Builtin, Linear, ethereum_builtin, Pricer};
use ethjson;
- use util::U256;
+ use util::{U256, BytesRef};
#[test]
fn identity() {
@@ -203,15 +179,15 @@ mod tests {
let i = [0u8, 1, 2, 3];
let mut o2 = [255u8; 2];
- f.execute(&i[..], &mut o2[..]);
+ f.execute(&i[..], &mut BytesRef::Fixed(&mut o2[..]));
assert_eq!(i[0..2], o2);
let mut o4 = [255u8; 4];
- f.execute(&i[..], &mut o4[..]);
+ f.execute(&i[..], &mut BytesRef::Fixed(&mut o4[..]));
assert_eq!(i, o4);
let mut o8 = [255u8; 8];
- f.execute(&i[..], &mut o8[..]);
+ f.execute(&i[..], &mut BytesRef::Fixed(&mut o8[..]));
assert_eq!(i, o8[..4]);
assert_eq!([255u8; 4], o8[4..]);
}
@@ -224,16 +200,20 @@ mod tests {
let i = [0u8; 0];
let mut o = [255u8; 32];
- f.execute(&i[..], &mut o[..]);
+ f.execute(&i[..], &mut BytesRef::Fixed(&mut o[..]));
assert_eq!(&o[..], &(FromHex::from_hex("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855").unwrap())[..]);
let mut o8 = [255u8; 8];
- f.execute(&i[..], &mut o8[..]);
+ f.execute(&i[..], &mut BytesRef::Fixed(&mut o8[..]));
assert_eq!(&o8[..], &(FromHex::from_hex("e3b0c44298fc1c14").unwrap())[..]);
let mut o34 = [255u8; 34];
- f.execute(&i[..], &mut o34[..]);
+ f.execute(&i[..], &mut BytesRef::Fixed(&mut o34[..]));
assert_eq!(&o34[..], &(FromHex::from_hex("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855ffff").unwrap())[..]);
+
+ let mut ov = vec![];
+ f.execute(&i[..], &mut BytesRef::Flexible(&mut ov));
+ assert_eq!(&ov[..], &(FromHex::from_hex("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855").unwrap())[..]);
}
#[test]
@@ -244,15 +224,15 @@ mod tests {
let i = [0u8; 0];
let mut o = [255u8; 32];
- f.execute(&i[..], &mut o[..]);
+ f.execute(&i[..], &mut BytesRef::Fixed(&mut o[..]));
assert_eq!(&o[..], &(FromHex::from_hex("0000000000000000000000009c1185a5c5e9fc54612808977ee8f548b2258d31").unwrap())[..]);
let mut o8 = [255u8; 8];
- f.execute(&i[..], &mut o8[..]);
+ f.execute(&i[..], &mut BytesRef::Fixed(&mut o8[..]));
assert_eq!(&o8[..], &(FromHex::from_hex("0000000000000000").unwrap())[..]);
let mut o34 = [255u8; 34];
- f.execute(&i[..], &mut o34[..]);
+ f.execute(&i[..], &mut BytesRef::Fixed(&mut o34[..]));
assert_eq!(&o34[..], &(FromHex::from_hex("0000000000000000000000009c1185a5c5e9fc54612808977ee8f548b2258d31ffff").unwrap())[..]);
}
@@ -272,46 +252,46 @@ mod tests {
let i = FromHex::from_hex("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad000000000000000000000000000000000000000000000000000000000000001b650acf9d3f5f0a2c799776a1254355d5f4061762a237396a99a0e0e3fc2bcd6729514a0dacb2e623ac4abd157cb18163ff942280db4d5caad66ddf941ba12e03").unwrap();
let mut o = [255u8; 32];
- f.execute(&i[..], &mut o[..]);
+ f.execute(&i[..], &mut BytesRef::Fixed(&mut o[..]));
assert_eq!(&o[..], &(FromHex::from_hex("000000000000000000000000c08b5542d177ac6686946920409741463a15dddb").unwrap())[..]);
let mut o8 = [255u8; 8];
- f.execute(&i[..], &mut o8[..]);
+ f.execute(&i[..], &mut BytesRef::Fixed(&mut o8[..]));
assert_eq!(&o8[..], &(FromHex::from_hex("0000000000000000").unwrap())[..]);
let mut o34 = [255u8; 34];
- f.execute(&i[..], &mut o34[..]);
+ f.execute(&i[..], &mut BytesRef::Fixed(&mut o34[..]));
assert_eq!(&o34[..], &(FromHex::from_hex("000000000000000000000000c08b5542d177ac6686946920409741463a15dddbffff").unwrap())[..]);
let i_bad = FromHex::from_hex("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad000000000000000000000000000000000000000000000000000000000000001a650acf9d3f5f0a2c799776a1254355d5f4061762a237396a99a0e0e3fc2bcd6729514a0dacb2e623ac4abd157cb18163ff942280db4d5caad66ddf941ba12e03").unwrap();
let mut o = [255u8; 32];
- f.execute(&i_bad[..], &mut o[..]);
+ f.execute(&i_bad[..], &mut BytesRef::Fixed(&mut o[..]));
assert_eq!(&o[..], &(FromHex::from_hex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap())[..]);
let i_bad = FromHex::from_hex("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad000000000000000000000000000000000000000000000000000000000000001b000000000000000000000000000000000000000000000000000000000000001b0000000000000000000000000000000000000000000000000000000000000000").unwrap();
let mut o = [255u8; 32];
- f.execute(&i_bad[..], &mut o[..]);
+ f.execute(&i_bad[..], &mut BytesRef::Fixed(&mut o[..]));
assert_eq!(&o[..], &(FromHex::from_hex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap())[..]);
let i_bad = FromHex::from_hex("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad000000000000000000000000000000000000000000000000000000000000001b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001b").unwrap();
let mut o = [255u8; 32];
- f.execute(&i_bad[..], &mut o[..]);
+ f.execute(&i_bad[..], &mut BytesRef::Fixed(&mut o[..]));
assert_eq!(&o[..], &(FromHex::from_hex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap())[..]);
let i_bad = FromHex::from_hex("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad000000000000000000000000000000000000000000000000000000000000001bffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000000001b").unwrap();
let mut o = [255u8; 32];
- f.execute(&i_bad[..], &mut o[..]);
+ f.execute(&i_bad[..], &mut BytesRef::Fixed(&mut o[..]));
assert_eq!(&o[..], &(FromHex::from_hex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap())[..]);
let i_bad = FromHex::from_hex("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad000000000000000000000000000000000000000000000000000000000000001b000000000000000000000000000000000000000000000000000000000000001bffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap();
let mut o = [255u8; 32];
- f.execute(&i_bad[..], &mut o[..]);
+ f.execute(&i_bad[..], &mut BytesRef::Fixed(&mut o[..]));
assert_eq!(&o[..], &(FromHex::from_hex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap())[..]);
// TODO: Should this (corrupted version of the above) fail rather than returning some address?
/* let i_bad = FromHex::from_hex("48173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad000000000000000000000000000000000000000000000000000000000000001b650acf9d3f5f0a2c799776a1254355d5f4061762a237396a99a0e0e3fc2bcd6729514a0dacb2e623ac4abd157cb18163ff942280db4d5caad66ddf941ba12e03").unwrap();
let mut o = [255u8; 32];
- f.execute(&i_bad[..], &mut o[..]);
+ f.execute(&i_bad[..], &mut BytesRef::Fixed(&mut o[..]));
assert_eq!(&o[..], &(FromHex::from_hex("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap())[..]);*/
}
@@ -336,7 +316,7 @@ mod tests {
let i = [0u8, 1, 2, 3];
let mut o = [255u8; 4];
- b.execute(&i[..], &mut o[..]);
+ b.execute(&i[..], &mut BytesRef::Fixed(&mut o[..]));
assert_eq!(i, o);
}
@@ -357,7 +337,7 @@ mod tests {
let i = [0u8, 1, 2, 3];
let mut o = [255u8; 4];
- b.execute(&i[..], &mut o[..]);
+ b.execute(&i[..], &mut BytesRef::Fixed(&mut o[..]));
assert_eq!(i, o);
}
-}
\ No newline at end of file
+}
diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs
index 863130699..445ec37f7 100644
--- a/ethcore/src/client/client.rs
+++ b/ethcore/src/client/client.rs
@@ -144,7 +144,9 @@ pub struct Client {
factories: Factories,
}
-const HISTORY: u64 = 1200;
+/// The pruning constant -- how old blocks must be before we
+/// assume finality of a given candidate.
+pub const HISTORY: u64 = 1200;
/// Append a path element to the given path and return the string.
pub fn append_path(path: P, item: &str) -> String where P: AsRef {
@@ -168,7 +170,7 @@ impl Client {
let db = Arc::new(try!(Database::open(&db_config, &path.to_str().unwrap()).map_err(ClientError::Database)));
let chain = Arc::new(BlockChain::new(config.blockchain.clone(), &gb, db.clone()));
- let tracedb = RwLock::new(try!(TraceDB::new(config.tracing.clone(), db.clone(), chain.clone())));
+ let tracedb = RwLock::new(TraceDB::new(config.tracing.clone(), db.clone(), chain.clone()));
let mut state_db = journaldb::new(db.clone(), config.pruning, ::db::COL_STATE);
if state_db.is_empty() && try!(spec.ensure_db_good(state_db.as_hashdb_mut())) {
@@ -685,7 +687,7 @@ impl snapshot::DatabaseRestore for Client {
*state_db = journaldb::new(db.clone(), self.pruning, ::db::COL_STATE);
*chain = Arc::new(BlockChain::new(self.config.blockchain.clone(), &[], db.clone()));
- *tracedb = try!(TraceDB::new(self.config.tracing.clone(), db.clone(), chain.clone()).map_err(ClientError::from));
+ *tracedb = TraceDB::new(self.config.tracing.clone(), db.clone(), chain.clone());
Ok(())
}
}
@@ -957,7 +959,7 @@ impl BlockChainClient for Client {
}
}
- fn logs(&self, filter: Filter, limit: Option) -> Vec {
+ fn logs(&self, filter: Filter) -> Vec {
let blocks = filter.bloom_possibilities().iter()
.filter_map(|bloom| self.blocks_with_bloom(bloom, filter.from_block.clone(), filter.to_block.clone()))
.flat_map(|m| m)
@@ -966,7 +968,7 @@ impl BlockChainClient for Client {
.into_iter()
.collect::>();
- self.chain.read().logs(blocks, |entry| filter.matches(entry), limit)
+ self.chain.read().logs(blocks, |entry| filter.matches(entry), filter.limit)
}
fn filter_traces(&self, filter: TraceFilter) -> Option> {
diff --git a/ethcore/src/client/config.rs b/ethcore/src/client/config.rs
index bb70de6cd..0146293df 100644
--- a/ethcore/src/client/config.rs
+++ b/ethcore/src/client/config.rs
@@ -18,7 +18,7 @@ use std::str::FromStr;
pub use std::time::Duration;
pub use block_queue::BlockQueueConfig;
pub use blockchain::Config as BlockChainConfig;
-pub use trace::{Config as TraceConfig, Switch};
+pub use trace::Config as TraceConfig;
pub use evm::VMType;
pub use verification::VerifierType;
use util::{journaldb, CompactionProfile};
@@ -102,7 +102,7 @@ pub struct ClientConfig {
/// State db compaction profile
pub db_compaction: DatabaseCompactionProfile,
/// Should db have WAL enabled?
- pub db_wal: bool,
+ pub db_wal: bool,
/// Operating mode
pub mode: Mode,
/// Type of block verifier used by client.
diff --git a/ethcore/src/client/mod.rs b/ethcore/src/client/mod.rs
index 32582ddf2..a5ff89c47 100644
--- a/ethcore/src/client/mod.rs
+++ b/ethcore/src/client/mod.rs
@@ -23,7 +23,7 @@ mod trace;
mod client;
pub use self::client::*;
-pub use self::config::{Mode, ClientConfig, DatabaseCompactionProfile, BlockQueueConfig, BlockChainConfig, Switch, VMType};
+pub use self::config::{Mode, ClientConfig, DatabaseCompactionProfile, BlockQueueConfig, BlockChainConfig, VMType};
pub use self::error::Error;
pub use types::ids::*;
pub use self::test_client::{TestBlockChainClient, EachBlockWith};
diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs
index 0c0a443d6..c0d7e35ba 100644
--- a/ethcore/src/client/test_client.rs
+++ b/ethcore/src/client/test_client.rs
@@ -67,6 +67,8 @@ pub struct TestBlockChainClient {
pub execution_result: RwLock