Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #5949 from Vurich/upgrade-elastic-array
Browse files Browse the repository at this point in the history
Upgrade elastic array
  • Loading branch information
rphmeier authored Jun 29, 2017
2 parents 826bf28 + 01ce28b commit a4195f2
Show file tree
Hide file tree
Showing 64 changed files with 159 additions and 158 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ethcore/light/src/cht.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub fn compute_root<I>(cht_num: u64, iterable: I) -> Option<H256>
let start_num = start_number(cht_num) as usize;

for (i, (h, td)) in iterable.into_iter().take(SIZE as usize).enumerate() {
v.push((key!(i + start_num).to_vec(), val!(h, td).to_vec()))
v.push((key!(i + start_num).into_vec(), val!(h, td).into_vec()))
}

if v.len() == SIZE as usize {
Expand Down
2 changes: 1 addition & 1 deletion ethcore/light/src/client/header_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl HeaderChain {
None => {
match self.db.get(self.col, &hash) {
Ok(db_value) => {
db_value.map(|x| x.to_vec()).map(encoded::Header::new)
db_value.map(|x| x.into_vec()).map(encoded::Header::new)
.and_then(|header| {
cache.insert_block_header(hash.clone(), header.clone());
Some(header)
Expand Down
2 changes: 1 addition & 1 deletion ethcore/light/src/net/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl Provider for TestProvider {

fn storage_proof(&self, req: request::CompleteStorageRequest) -> Option<request::StorageResponse> {
Some(StorageResponse {
proof: vec![::rlp::encode(&req.key_hash).to_vec()],
proof: vec![::rlp::encode(&req.key_hash).into_vec()],
value: req.key_hash | req.address_hash,
})
}
Expand Down
16 changes: 8 additions & 8 deletions ethcore/light/src/on_demand/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ impl BlockReceipts {
/// Check a response with receipts against the stored header.
pub fn check_response(&self, cache: &Mutex<::cache::Cache>, receipts: &[Receipt]) -> Result<Vec<Receipt>, Error> {
let receipts_root = self.0.as_ref()?.receipts_root();
let found_root = ::util::triehash::ordered_trie_root(receipts.iter().map(|r| ::rlp::encode(r).to_vec()));
let found_root = ::util::triehash::ordered_trie_root(receipts.iter().map(|r| ::rlp::encode(r).into_vec()));

match receipts_root == found_root {
true => {
Expand Down Expand Up @@ -902,7 +902,7 @@ mod tests {
header.set_number(10_000);
header.set_extra_data(b"test_header".to_vec());
let hash = header.hash();
let raw_header = encoded::Header::new(::rlp::encode(&header).to_vec());
let raw_header = encoded::Header::new(::rlp::encode(&header).into_vec());

let cache = Mutex::new(make_cache());
assert!(HeaderByHash(hash.into()).check_response(&cache, &hash.into(), &[raw_header]).is_ok())
Expand All @@ -916,10 +916,10 @@ mod tests {
let mut body_stream = RlpStream::new_list(2);
body_stream.begin_list(0).begin_list(0);

let req = Body(encoded::Header::new(::rlp::encode(&header).to_vec()).into());
let req = Body(encoded::Header::new(::rlp::encode(&header).into_vec()).into());

let cache = Mutex::new(make_cache());
let response = encoded::Body::new(body_stream.drain().to_vec());
let response = encoded::Body::new(body_stream.drain().into_vec());
assert!(req.check_response(&cache, &response).is_ok())
}

Expand All @@ -934,12 +934,12 @@ mod tests {

let mut header = Header::new();
let receipts_root = ::util::triehash::ordered_trie_root(
receipts.iter().map(|x| ::rlp::encode(x).to_vec())
receipts.iter().map(|x| ::rlp::encode(x).into_vec())
);

header.set_receipts_root(receipts_root);

let req = BlockReceipts(encoded::Header::new(::rlp::encode(&header).to_vec()).into());
let req = BlockReceipts(encoded::Header::new(::rlp::encode(&header).into_vec()).into());

let cache = Mutex::new(make_cache());
assert!(req.check_response(&cache, &receipts).is_ok())
Expand Down Expand Up @@ -987,7 +987,7 @@ mod tests {
header.set_state_root(root.clone());

let req = Account {
header: encoded::Header::new(::rlp::encode(&header).to_vec()).into(),
header: encoded::Header::new(::rlp::encode(&header).into_vec()).into(),
address: addr,
};

Expand All @@ -1001,7 +1001,7 @@ mod tests {
let code_hash = ::util::Hashable::sha3(&code);
let header = Header::new();
let req = Code {
header: encoded::Header::new(::rlp::encode(&header).to_vec()).into(),
header: encoded::Header::new(::rlp::encode(&header).into_vec()).into(),
code_hash: code_hash.into(),
};

Expand Down
2 changes: 1 addition & 1 deletion ethcore/light/src/types/request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,7 @@ mod tests {
let full_req = Request::Headers(req.clone());
let res = HeadersResponse {
headers: vec![
::ethcore::encoded::Header::new(::rlp::encode(&Header::default()).to_vec())
::ethcore::encoded::Header::new(::rlp::encode(&Header::default()).into_vec())
]
};
let full_res = Response::Headers(res.clone());
Expand Down
10 changes: 5 additions & 5 deletions ethcore/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,11 @@ impl<'x> OpenBlock<'x> {
if let Err(e) = s.block.state.commit() {
warn!("Encountered error on state commit: {}", e);
}
s.block.header.set_transactions_root(ordered_trie_root(s.block.transactions.iter().map(|e| e.rlp_bytes().to_vec())));
s.block.header.set_transactions_root(ordered_trie_root(s.block.transactions.iter().map(|e| e.rlp_bytes().into_vec())));
let uncle_bytes = s.block.uncles.iter().fold(RlpStream::new_list(s.block.uncles.len()), |mut s, u| {s.append_raw(&u.rlp(Seal::With), 1); s} ).out();
s.block.header.set_uncles_hash(uncle_bytes.sha3());
s.block.header.set_state_root(s.block.state.root().clone());
s.block.header.set_receipts_root(ordered_trie_root(s.block.receipts.iter().map(|r| r.rlp_bytes().to_vec())));
s.block.header.set_receipts_root(ordered_trie_root(s.block.receipts.iter().map(|r| r.rlp_bytes().into_vec())));
s.block.header.set_log_bloom(s.block.receipts.iter().fold(LogBloom::zero(), |mut b, r| {b = &b | &r.log_bloom; b})); //TODO: use |= operator
s.block.header.set_gas_used(s.block.receipts.last().map_or(U256::zero(), |r| r.gas_used));

Expand All @@ -410,14 +410,14 @@ impl<'x> OpenBlock<'x> {
warn!("Encountered error on state commit: {}", e);
}
if s.block.header.transactions_root().is_zero() || s.block.header.transactions_root() == &SHA3_NULL_RLP {
s.block.header.set_transactions_root(ordered_trie_root(s.block.transactions.iter().map(|e| e.rlp_bytes().to_vec())));
s.block.header.set_transactions_root(ordered_trie_root(s.block.transactions.iter().map(|e| e.rlp_bytes().into_vec())));
}
let uncle_bytes = s.block.uncles.iter().fold(RlpStream::new_list(s.block.uncles.len()), |mut s, u| {s.append_raw(&u.rlp(Seal::With), 1); s} ).out();
if s.block.header.uncles_hash().is_zero() {
s.block.header.set_uncles_hash(uncle_bytes.sha3());
}
if s.block.header.receipts_root().is_zero() || s.block.header.receipts_root() == &SHA3_NULL_RLP {
s.block.header.set_receipts_root(ordered_trie_root(s.block.receipts.iter().map(|r| r.rlp_bytes().to_vec())));
s.block.header.set_receipts_root(ordered_trie_root(s.block.receipts.iter().map(|r| r.rlp_bytes().into_vec())));
}

s.block.header.set_state_root(s.block.state.root().clone());
Expand Down Expand Up @@ -510,7 +510,7 @@ impl LockedBlock {
for receipt in &mut block.block.receipts {
receipt.state_root = None;
}
block.block.header.set_receipts_root(ordered_trie_root(block.block.receipts.iter().map(|r| r.rlp_bytes().to_vec())));
block.block.header.set_receipts_root(ordered_trie_root(block.block.receipts.iter().map(|r| r.rlp_bytes().into_vec())));
block
}
}
Expand Down
6 changes: 3 additions & 3 deletions ethcore/src/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl BlockProvider for BlockChain {

let result = match opt {
Some(b) => {
let bytes: Bytes = UntrustedRlp::new(&b).decompress(RlpType::Blocks).to_vec();
let bytes: Bytes = UntrustedRlp::new(&b).decompress(RlpType::Blocks).into_vec();
let mut write = self.block_headers.write();
write.insert(hash.clone(), bytes.clone());
Some(encoded::Header::new(bytes))
Expand Down Expand Up @@ -302,7 +302,7 @@ impl BlockProvider for BlockChain {

let result = match opt {
Some(b) => {
let bytes: Bytes = UntrustedRlp::new(&b).decompress(RlpType::Blocks).to_vec();
let bytes: Bytes = UntrustedRlp::new(&b).decompress(RlpType::Blocks).into_vec();
let mut write = self.block_bodies.write();
write.insert(hash.clone(), bytes.clone());
Some(encoded::Body::new(bytes))
Expand Down Expand Up @@ -536,7 +536,7 @@ impl BlockChain {
let best_block_rlp = bc.block(&best_block_hash).unwrap().into_inner();
let best_block_timestamp = BlockView::new(&best_block_rlp).header().timestamp();

let raw_first = bc.db.get(db::COL_EXTRA, b"first").unwrap().map(|v| v.to_vec());
let raw_first = bc.db.get(db::COL_EXTRA, b"first").unwrap().map(|v| v.into_vec());
let mut best_ancient = bc.db.get(db::COL_EXTRA, b"ancient").unwrap().map(|h| H256::from_slice(&h));
let best_ancient_number;
if best_ancient.is_none() && best_block_number > 1 && bc.block_hash(1).is_none() {
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/blockchain/generator/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ impl WithTransaction for Block {
impl CompleteBlock for Block {
fn complete(mut self, parent_hash: H256) -> Bytes {
self.header.set_parent_hash(parent_hash);
encode(&self).to_vec()
encode(&self).into_vec()
}
}
2 changes: 1 addition & 1 deletion ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ impl BlockChainClient for Client {
}

fn block_receipts(&self, hash: &H256) -> Option<Bytes> {
self.chain.read().block_receipts(hash).map(|receipts| ::rlp::encode(&receipts).to_vec())
self.chain.read().block_receipts(hash).map(|receipts| ::rlp::encode(&receipts).into_vec())
}

fn import_block(&self, bytes: Bytes) -> Result<H256, BlockImportError> {
Expand Down
26 changes: 13 additions & 13 deletions ethcore/src/engines/authority_round/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ impl Engine for AuthorityRound {

// only issue the seal if we were the first to reach the compare_and_swap.
if !self.proposed.compare_and_swap(false, true, AtomicOrdering::SeqCst) {
return Seal::Regular(vec![encode(&step).to_vec(), encode(&(&H520::from(signature) as &[u8])).to_vec()]);
return Seal::Regular(vec![encode(&step).into_vec(), encode(&(&H520::from(signature) as &[u8])).into_vec()]);
}
} else {
warn!(target: "engine", "generate_seal: FAIL: Accounts secret key unavailable.");
Expand Down Expand Up @@ -880,7 +880,7 @@ mod tests {
fn can_do_signature_verification_fail() {
let engine = Spec::new_test_round().engine;
let mut header: Header = Header::default();
header.set_seal(vec![encode(&H520::default()).to_vec()]);
header.set_seal(vec![encode(&H520::default()).into_vec()]);

let verify_result = engine.verify_block_external(&header, None);
assert!(verify_result.is_err());
Expand Down Expand Up @@ -923,7 +923,7 @@ mod tests {
let tap = AccountProvider::transient_provider();
let addr = tap.insert_account("0".sha3().into(), "0").unwrap();
let mut parent_header: Header = Header::default();
parent_header.set_seal(vec![encode(&0usize).to_vec()]);
parent_header.set_seal(vec![encode(&0usize).into_vec()]);
parent_header.set_gas_limit(U256::from_str("222222").unwrap());
let mut header: Header = Header::default();
header.set_number(1);
Expand All @@ -935,10 +935,10 @@ mod tests {
let signature = tap.sign(addr, Some("0".into()), header.bare_hash()).unwrap();
// Two validators.
// Spec starts with step 2.
header.set_seal(vec![encode(&2usize).to_vec(), encode(&(&*signature as &[u8])).to_vec()]);
header.set_seal(vec![encode(&2usize).into_vec(), encode(&(&*signature as &[u8])).into_vec()]);
assert!(engine.verify_block_family(&header, &parent_header, None).is_ok());
assert!(engine.verify_block_external(&header, None).is_err());
header.set_seal(vec![encode(&1usize).to_vec(), encode(&(&*signature as &[u8])).to_vec()]);
header.set_seal(vec![encode(&1usize).into_vec(), encode(&(&*signature as &[u8])).into_vec()]);
assert!(engine.verify_block_family(&header, &parent_header, None).is_ok());
assert!(engine.verify_block_external(&header, None).is_ok());
}
Expand All @@ -949,7 +949,7 @@ mod tests {
let addr = tap.insert_account("0".sha3().into(), "0").unwrap();

let mut parent_header: Header = Header::default();
parent_header.set_seal(vec![encode(&0usize).to_vec()]);
parent_header.set_seal(vec![encode(&0usize).into_vec()]);
parent_header.set_gas_limit(U256::from_str("222222").unwrap());
let mut header: Header = Header::default();
header.set_number(1);
Expand All @@ -961,10 +961,10 @@ mod tests {
let signature = tap.sign(addr, Some("0".into()), header.bare_hash()).unwrap();
// Two validators.
// Spec starts with step 2.
header.set_seal(vec![encode(&1usize).to_vec(), encode(&(&*signature as &[u8])).to_vec()]);
header.set_seal(vec![encode(&1usize).into_vec(), encode(&(&*signature as &[u8])).into_vec()]);
assert!(engine.verify_block_family(&header, &parent_header, None).is_ok());
assert!(engine.verify_block_external(&header, None).is_ok());
header.set_seal(vec![encode(&5usize).to_vec(), encode(&(&*signature as &[u8])).to_vec()]);
header.set_seal(vec![encode(&5usize).into_vec(), encode(&(&*signature as &[u8])).into_vec()]);
assert!(engine.verify_block_family(&header, &parent_header, None).is_ok());
assert!(engine.verify_block_external(&header, None).is_err());
}
Expand All @@ -975,7 +975,7 @@ mod tests {
let addr = tap.insert_account("0".sha3().into(), "0").unwrap();

let mut parent_header: Header = Header::default();
parent_header.set_seal(vec![encode(&4usize).to_vec()]);
parent_header.set_seal(vec![encode(&4usize).into_vec()]);
parent_header.set_gas_limit(U256::from_str("222222").unwrap());
let mut header: Header = Header::default();
header.set_number(1);
Expand All @@ -987,9 +987,9 @@ mod tests {
let signature = tap.sign(addr, Some("0".into()), header.bare_hash()).unwrap();
// Two validators.
// Spec starts with step 2.
header.set_seal(vec![encode(&5usize).to_vec(), encode(&(&*signature as &[u8])).to_vec()]);
header.set_seal(vec![encode(&5usize).into_vec(), encode(&(&*signature as &[u8])).into_vec()]);
assert!(engine.verify_block_family(&header, &parent_header, None).is_ok());
header.set_seal(vec![encode(&3usize).to_vec(), encode(&(&*signature as &[u8])).to_vec()]);
header.set_seal(vec![encode(&3usize).into_vec(), encode(&(&*signature as &[u8])).into_vec()]);
assert!(engine.verify_block_family(&header, &parent_header, None).is_err());
}

Expand All @@ -1011,12 +1011,12 @@ mod tests {
let aura = AuthorityRound::new(Default::default(), params, Default::default()).unwrap();

let mut parent_header: Header = Header::default();
parent_header.set_seal(vec![encode(&1usize).to_vec()]);
parent_header.set_seal(vec![encode(&1usize).into_vec()]);
parent_header.set_gas_limit(U256::from_str("222222").unwrap());
let mut header: Header = Header::default();
header.set_number(1);
header.set_gas_limit(U256::from_str("222222").unwrap());
header.set_seal(vec![encode(&3usize).to_vec()]);
header.set_seal(vec![encode(&3usize).into_vec()]);

assert!(aura.verify_block_family(&header, &parent_header, None).is_ok());
assert_eq!(last_benign.load(AtomicOrdering::SeqCst), 1);
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/engines/basic_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl Engine for BasicAuthority {
if self.validators.contains(header.parent_hash(), author) {
// account should be pernamently unlocked, otherwise sealing will fail
if let Ok(signature) = self.signer.sign(header.bare_hash()) {
return Seal::Regular(vec![::rlp::encode(&(&H520::from(signature) as &[u8])).to_vec()]);
return Seal::Regular(vec![::rlp::encode(&(&H520::from(signature) as &[u8])).into_vec()]);
} else {
trace!(target: "basicauthority", "generate_seal: FAIL: accounts secret key unavailable");
}
Expand Down Expand Up @@ -301,7 +301,7 @@ mod tests {
fn can_do_signature_verification_fail() {
let engine = new_test_authority().engine;
let mut header: Header = Header::default();
header.set_seal(vec![::rlp::encode(&H520::default()).to_vec()]);
header.set_seal(vec![::rlp::encode(&H520::default()).into_vec()]);

let verify_result = engine.verify_block_family(&header, &Default::default(), None);
assert!(verify_result.is_err());
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/engines/instant_seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ mod tests {

assert!(engine.verify_block_basic(&header, None).is_ok());

header.set_seal(vec![::rlp::encode(&H520::default()).to_vec()]);
header.set_seal(vec![::rlp::encode(&H520::default()).into_vec()]);

assert!(engine.verify_block_unordered(&header, None).is_ok());
}
Expand Down
6 changes: 3 additions & 3 deletions ethcore/src/engines/tendermint/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ mod tests {
},
block_hash: Some("1".sha3())
};
let raw_rlp = ::rlp::encode(&message).to_vec();
let raw_rlp = ::rlp::encode(&message).into_vec();
let rlp = Rlp::new(&raw_rlp);
assert_eq!(message, rlp.as_val());

Expand Down Expand Up @@ -265,8 +265,8 @@ mod tests {
fn proposal_message() {
let mut header = Header::default();
let seal = vec![
::rlp::encode(&0u8).to_vec(),
::rlp::encode(&H520::default()).to_vec(),
::rlp::encode(&0u8).into_vec(),
::rlp::encode(&H520::default()).into_vec(),
Vec::new()
];

Expand Down
Loading

0 comments on commit a4195f2

Please sign in to comment.