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

Make *ID names consistent with std Rust (Id) #3781

Merged
merged 4 commits into from
Dec 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ethcore/light/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use std::sync::Arc;

use ethcore::engines::Engine;
use ethcore::ids::BlockID;
use ethcore::ids::BlockId;
use ethcore::service::ClientIoMessage;
use ethcore::block_import_error::BlockImportError;
use ethcore::block_status::BlockStatus;
Expand Down Expand Up @@ -51,7 +51,7 @@ impl Client {
}

/// Whether the block is already known (but not necessarily part of the canonical chain)
pub fn is_known(&self, _id: BlockID) -> bool {
pub fn is_known(&self, _id: BlockId) -> bool {
false
}

Expand All @@ -61,7 +61,7 @@ impl Client {
}

/// Inquire about the status of a given block.
pub fn status(&self, _id: BlockID) -> BlockStatus {
pub fn status(&self, _id: BlockId) -> BlockStatus {
BlockStatus::Unknown
}

Expand Down
18 changes: 9 additions & 9 deletions ethcore/light/src/net/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use ethcore::blockchain_info::BlockChainInfo;
use ethcore::client::{BlockChainClient, EachBlockWith, TestBlockChainClient};
use ethcore::ids::BlockID;
use ethcore::ids::BlockId;
use ethcore::transaction::SignedTransaction;
use network::PeerId;

Expand Down Expand Up @@ -94,7 +94,7 @@ impl Provider for TestProvider {
let best_num = self.0.client.chain_info().best_block_number;
let start_num = req.block_num;

match self.0.client.block_hash(BlockID::Number(req.block_num)) {
match self.0.client.block_hash(BlockId::Number(req.block_num)) {
Some(hash) if hash == req.block_hash => {}
_=> {
trace!(target: "les_provider", "unknown/non-canonical start block in header request: {:?}", (req.block_num, req.block_hash));
Expand All @@ -106,15 +106,15 @@ impl Provider for TestProvider {
.map(|x: u64| x.saturating_mul(req.skip + 1))
.take_while(|x| if req.reverse { x < &start_num } else { best_num - start_num >= *x })
.map(|x| if req.reverse { start_num - x } else { start_num + x })
.map(|x| self.0.client.block_header(BlockID::Number(x)))
.map(|x| self.0.client.block_header(BlockId::Number(x)))
.take_while(|x| x.is_some())
.flat_map(|x| x)
.collect()
}

fn block_bodies(&self, req: request::Bodies) -> Vec<Bytes> {
req.block_hashes.into_iter()
.map(|hash| self.0.client.block_body(BlockID::Hash(hash)))
.map(|hash| self.0.client.block_body(BlockId::Hash(hash)))
.map(|body| body.unwrap_or_else(|| ::rlp::EMPTY_LIST_RLP.to_vec()))
.collect()
}
Expand Down Expand Up @@ -285,7 +285,7 @@ fn get_block_headers() {

let request = Headers {
block_num: 1,
block_hash: provider.client.block_hash(BlockID::Number(1)).unwrap(),
block_hash: provider.client.block_hash(BlockId::Number(1)).unwrap(),
max: 10,
skip: 0,
reverse: false,
Expand All @@ -294,7 +294,7 @@ fn get_block_headers() {

let request_body = encode_request(&Request::Headers(request.clone()), req_id);
let response = {
let headers: Vec<_> = (0..10).map(|i| provider.client.block_header(BlockID::Number(i + 1)).unwrap()).collect();
let headers: Vec<_> = (0..10).map(|i| provider.client.block_header(BlockId::Number(i + 1)).unwrap()).collect();
assert_eq!(headers.len(), 10);

let new_buf = *flow_params.limit() - flow_params.compute_cost(request::Kind::Headers, 10);
Expand Down Expand Up @@ -334,14 +334,14 @@ fn get_block_bodies() {
}

let request = request::Bodies {
block_hashes: (0..10).map(|i| provider.client.block_hash(BlockID::Number(i)).unwrap()).collect(),
block_hashes: (0..10).map(|i| provider.client.block_hash(BlockId::Number(i)).unwrap()).collect(),
};

let req_id = 111;

let request_body = encode_request(&Request::Bodies(request.clone()), req_id);
let response = {
let bodies: Vec<_> = (0..10).map(|i| provider.client.block_body(BlockID::Number(i + 1)).unwrap()).collect();
let bodies: Vec<_> = (0..10).map(|i| provider.client.block_body(BlockId::Number(i + 1)).unwrap()).collect();
assert_eq!(bodies.len(), 10);

let new_buf = *flow_params.limit() - flow_params.compute_cost(request::Kind::Bodies, 10);
Expand Down Expand Up @@ -382,7 +382,7 @@ fn get_block_receipts() {

// find the first 10 block hashes starting with `f` because receipts are only provided
// by the test client in that case.
let block_hashes: Vec<_> = (0..1000).map(|i| provider.client.block_hash(BlockID::Number(i)).unwrap())
let block_hashes: Vec<_> = (0..1000).map(|i| provider.client.block_hash(BlockId::Number(i)).unwrap())
.filter(|hash| format!("{}", hash).starts_with("f")).take(10).collect();

let request = request::Receipts {
Expand Down
14 changes: 7 additions & 7 deletions ethcore/light/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use ethcore::blockchain_info::BlockChainInfo;
use ethcore::client::{BlockChainClient, ProvingBlockChainClient};
use ethcore::transaction::SignedTransaction;
use ethcore::ids::BlockID;
use ethcore::ids::BlockId;

use util::{Bytes, H256};

Expand Down Expand Up @@ -100,7 +100,7 @@ impl<T: ProvingBlockChainClient + ?Sized> Provider for T {
let best_num = self.chain_info().best_block_number;
let start_num = req.block_num;

match self.block_hash(BlockID::Number(req.block_num)) {
match self.block_hash(BlockId::Number(req.block_num)) {
Some(hash) if hash == req.block_hash => {}
_=> {
trace!(target: "les_provider", "unknown/non-canonical start block in header request: {:?}", (req.block_num, req.block_hash));
Expand All @@ -112,15 +112,15 @@ impl<T: ProvingBlockChainClient + ?Sized> Provider for T {
.map(|x: u64| x.saturating_mul(req.skip + 1))
.take_while(|x| if req.reverse { x < &start_num } else { best_num - start_num >= *x })
.map(|x| if req.reverse { start_num - x } else { start_num + x })
.map(|x| self.block_header(BlockID::Number(x)))
.map(|x| self.block_header(BlockId::Number(x)))
.take_while(|x| x.is_some())
.flat_map(|x| x)
.collect()
}

fn block_bodies(&self, req: request::Bodies) -> Vec<Bytes> {
req.block_hashes.into_iter()
.map(|hash| self.block_body(BlockID::Hash(hash)))
.map(|hash| self.block_body(BlockId::Hash(hash)))
.map(|body| body.unwrap_or_else(|| ::rlp::EMPTY_LIST_RLP.to_vec()))
.collect()
}
Expand All @@ -139,8 +139,8 @@ impl<T: ProvingBlockChainClient + ?Sized> Provider for T {

for request in req.requests {
let proof = match request.key2 {
Some(key2) => self.prove_storage(request.key1, key2, request.from_level, BlockID::Hash(request.block)),
None => self.prove_account(request.key1, request.from_level, BlockID::Hash(request.block)),
Some(key2) => self.prove_storage(request.key1, key2, request.from_level, BlockId::Hash(request.block)),
None => self.prove_account(request.key1, request.from_level, BlockId::Hash(request.block)),
};

let mut stream = RlpStream::new_list(proof.len());
Expand All @@ -157,7 +157,7 @@ impl<T: ProvingBlockChainClient + ?Sized> Provider for T {
fn contract_code(&self, req: request::ContractCodes) -> Vec<Bytes> {
req.code_requests.into_iter()
.map(|req| {
self.code_by_hash(req.account_key, BlockID::Hash(req.block_hash))
self.code_by_hash(req.account_key, BlockId::Hash(req.block_hash))
})
.collect()
}
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/account_provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl AccountProvider {
Ok(AccountMeta {
name: try!(self.sstore.name(&account)),
meta: try!(self.sstore.meta(&account)),
uuid: self.sstore.uuid(&account).ok().map(Into::into), // allowed to not have a UUID
uuid: self.sstore.uuid(&account).ok().map(Into::into), // allowed to not have a Uuid
})
}

Expand Down
40 changes: 20 additions & 20 deletions ethcore/src/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub trait BlockProvider {
}

#[derive(Debug, Hash, Eq, PartialEq, Clone)]
enum CacheID {
enum CacheId {
BlockHeader(H256),
BlockBody(H256),
BlockDetails(H256),
Expand All @@ -160,7 +160,7 @@ impl bc::group::BloomGroupDatabase for BlockChain {
fn blooms_at(&self, position: &bc::group::GroupPosition) -> Option<bc::group::BloomGroup> {
let position = LogGroupPosition::from(position.clone());
let result = self.db.read_with_cache(db::COL_EXTRA, &self.blocks_blooms, &position).map(Into::into);
self.cache_man.lock().note_used(CacheID::BlocksBlooms(position));
self.cache_man.lock().note_used(CacheId::BlocksBlooms(position));
result
}
}
Expand Down Expand Up @@ -193,7 +193,7 @@ pub struct BlockChain {

db: Arc<Database>,

cache_man: Mutex<CacheManager<CacheID>>,
cache_man: Mutex<CacheManager<CacheId>>,

pending_best_block: RwLock<Option<BestBlock>>,
pending_block_hashes: RwLock<HashMap<BlockNumber, H256>>,
Expand Down Expand Up @@ -270,7 +270,7 @@ impl BlockProvider for BlockChain {
None => None
};

self.cache_man.lock().note_used(CacheID::BlockHeader(hash.clone()));
self.cache_man.lock().note_used(CacheId::BlockHeader(hash.clone()));
result
}

Expand Down Expand Up @@ -306,36 +306,36 @@ impl BlockProvider for BlockChain {
None => None
};

self.cache_man.lock().note_used(CacheID::BlockBody(hash.clone()));
self.cache_man.lock().note_used(CacheId::BlockBody(hash.clone()));

result
}

/// Get the familial details concerning a block.
fn block_details(&self, hash: &H256) -> Option<BlockDetails> {
let result = self.db.read_with_cache(db::COL_EXTRA, &self.block_details, hash);
self.cache_man.lock().note_used(CacheID::BlockDetails(hash.clone()));
self.cache_man.lock().note_used(CacheId::BlockDetails(hash.clone()));
result
}

/// Get the hash of given block's number.
fn block_hash(&self, index: BlockNumber) -> Option<H256> {
let result = self.db.read_with_cache(db::COL_EXTRA, &self.block_hashes, &index);
self.cache_man.lock().note_used(CacheID::BlockHashes(index));
self.cache_man.lock().note_used(CacheId::BlockHashes(index));
result
}

/// Get the address of transaction with given hash.
fn transaction_address(&self, hash: &H256) -> Option<TransactionAddress> {
let result = self.db.read_with_cache(db::COL_EXTRA, &self.transaction_addresses, hash);
self.cache_man.lock().note_used(CacheID::TransactionAddresses(hash.clone()));
self.cache_man.lock().note_used(CacheId::TransactionAddresses(hash.clone()));
result
}

/// Get receipts of block with given hash.
fn block_receipts(&self, hash: &H256) -> Option<BlockReceipts> {
let result = self.db.read_with_cache(db::COL_EXTRA, &self.block_receipts, hash);
self.cache_man.lock().note_used(CacheID::BlockReceipts(hash.clone()));
self.cache_man.lock().note_used(CacheId::BlockReceipts(hash.clone()));
result
}

Expand Down Expand Up @@ -809,7 +809,7 @@ impl BlockChain {
let mut write_details = self.block_details.write();
batch.extend_with_cache(db::COL_EXTRA, &mut *write_details, update, CacheUpdatePolicy::Overwrite);

self.cache_man.lock().note_used(CacheID::BlockDetails(block_hash));
self.cache_man.lock().note_used(CacheId::BlockDetails(block_hash));
}

#[cfg_attr(feature="dev", allow(similar_names))]
Expand Down Expand Up @@ -968,15 +968,15 @@ impl BlockChain {

let mut cache_man = self.cache_man.lock();
for n in pending_hashes_keys {
cache_man.note_used(CacheID::BlockHashes(n));
cache_man.note_used(CacheId::BlockHashes(n));
}

for hash in enacted_txs_keys {
cache_man.note_used(CacheID::TransactionAddresses(hash));
cache_man.note_used(CacheId::TransactionAddresses(hash));
}

for hash in pending_block_hashes {
cache_man.note_used(CacheID::BlockDetails(hash));
cache_man.note_used(CacheId::BlockDetails(hash));
}
}

Expand Down Expand Up @@ -1244,13 +1244,13 @@ impl BlockChain {
cache_man.collect_garbage(current_size, | ids | {
for id in &ids {
match *id {
CacheID::BlockHeader(ref h) => { block_headers.remove(h); },
CacheID::BlockBody(ref h) => { block_bodies.remove(h); },
CacheID::BlockDetails(ref h) => { block_details.remove(h); }
CacheID::BlockHashes(ref h) => { block_hashes.remove(h); }
CacheID::TransactionAddresses(ref h) => { transaction_addresses.remove(h); }
CacheID::BlocksBlooms(ref h) => { blocks_blooms.remove(h); }
CacheID::BlockReceipts(ref h) => { block_receipts.remove(h); }
CacheId::BlockHeader(ref h) => { block_headers.remove(h); },
CacheId::BlockBody(ref h) => { block_bodies.remove(h); },
CacheId::BlockDetails(ref h) => { block_details.remove(h); }
CacheId::BlockHashes(ref h) => { block_hashes.remove(h); }
CacheId::TransactionAddresses(ref h) => { transaction_addresses.remove(h); }
CacheId::BlocksBlooms(ref h) => { blocks_blooms.remove(h); }
CacheId::BlockReceipts(ref h) => { block_receipts.remove(h); }
}
}

Expand Down
Loading