Naming consistency and make Updater improvements.
- ID -> Id (consistency with rust libs)
This commit is contained in:
@@ -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;
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ use log_entry::LocalizedLogEntry;
|
||||
use verification::queue::BlockQueue;
|
||||
use blockchain::{BlockChain, BlockProvider, TreeRoute, ImportRoute};
|
||||
use client::{
|
||||
BlockID, TransactionID, UncleID, TraceId, ClientConfig, BlockChainClient,
|
||||
BlockId, TransactionId, UncleId, TraceId, ClientConfig, BlockChainClient,
|
||||
MiningBlockChainClient, TraceFilter, CallAnalytics, BlockImportError, Mode,
|
||||
ChainNotify,
|
||||
};
|
||||
@@ -594,13 +594,13 @@ impl Client {
|
||||
|
||||
/// Attempt to get a copy of a specific block's final state.
|
||||
///
|
||||
/// This will not fail if given BlockID::Latest.
|
||||
/// This will not fail if given BlockId::Latest.
|
||||
/// Otherwise, this can fail (but may not) if the DB prunes state.
|
||||
pub fn state_at(&self, id: BlockID) -> Option<State> {
|
||||
pub fn state_at(&self, id: BlockId) -> Option<State> {
|
||||
// fast path for latest state.
|
||||
match id.clone() {
|
||||
BlockID::Pending => return self.miner.pending_state().or_else(|| Some(self.state())),
|
||||
BlockID::Latest => return Some(self.state()),
|
||||
BlockId::Pending => return self.miner.pending_state().or_else(|| Some(self.state())),
|
||||
BlockId::Latest => return Some(self.state()),
|
||||
_ => {},
|
||||
}
|
||||
|
||||
@@ -625,15 +625,15 @@ impl Client {
|
||||
|
||||
/// Attempt to get a copy of a specific block's beginning state.
|
||||
///
|
||||
/// This will not fail if given BlockID::Latest.
|
||||
/// This will not fail if given BlockId::Latest.
|
||||
/// Otherwise, this can fail (but may not) if the DB prunes state.
|
||||
pub fn state_at_beginning(&self, id: BlockID) -> Option<State> {
|
||||
pub fn state_at_beginning(&self, id: BlockId) -> Option<State> {
|
||||
// fast path for latest state.
|
||||
match id {
|
||||
BlockID::Pending => self.state_at(BlockID::Latest),
|
||||
BlockId::Pending => self.state_at(BlockId::Latest),
|
||||
id => match self.block_number(id) {
|
||||
None | Some(0) => None,
|
||||
Some(n) => self.state_at(BlockID::Number(n - 1)),
|
||||
Some(n) => self.state_at(BlockId::Number(n - 1)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -724,30 +724,31 @@ impl Client {
|
||||
data: data,
|
||||
}.fake_sign(from);
|
||||
|
||||
self.call(&transaction, BlockID::Latest, Default::default())
|
||||
self.call(&transaction, BlockId::Latest, Default::default())
|
||||
.map_err(|e| format!("{:?}", e))
|
||||
.map(|executed| {
|
||||
executed.output
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the updater object.
|
||||
pub fn updater(&self) -> MutexGuard<Option<Updater>> {
|
||||
self.updater.lock()
|
||||
}
|
||||
|
||||
/// Look up the block number for the given block ID.
|
||||
pub fn block_number(&self, id: BlockID) -> Option<BlockNumber> {
|
||||
/// Look up the block number for the given block Id.
|
||||
pub fn block_number(&self, id: BlockId) -> Option<BlockNumber> {
|
||||
match id {
|
||||
BlockID::Number(number) => Some(number),
|
||||
BlockID::Hash(ref hash) => self.chain.read().block_number(hash),
|
||||
BlockID::Earliest => Some(0),
|
||||
BlockID::Latest | BlockID::Pending => Some(self.chain.read().best_block_number()),
|
||||
BlockId::Number(number) => Some(number),
|
||||
BlockId::Hash(ref hash) => self.chain.read().block_number(hash),
|
||||
BlockId::Earliest => Some(0),
|
||||
BlockId::Latest | BlockId::Pending => Some(self.chain.read().best_block_number()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Take a snapshot at the given block.
|
||||
/// If the ID given is "latest", this will default to 1000 blocks behind.
|
||||
pub fn take_snapshot<W: snapshot_io::SnapshotWriter + Send>(&self, writer: W, at: BlockID, p: &snapshot::Progress) -> Result<(), EthcoreError> {
|
||||
/// If the Id given is "latest", this will default to 1000 blocks behind.
|
||||
pub fn take_snapshot<W: snapshot_io::SnapshotWriter + Send>(&self, writer: W, at: BlockId, p: &snapshot::Progress) -> Result<(), EthcoreError> {
|
||||
let db = self.state_db.lock().journal_db().boxed_clone();
|
||||
let best_block_number = self.chain_info().best_block_number;
|
||||
let block_number = try!(self.block_number(at).ok_or(snapshot::Error::InvalidStartingBlock(at)));
|
||||
@@ -759,13 +760,13 @@ impl Client {
|
||||
let history = ::std::cmp::min(self.history, 1000);
|
||||
|
||||
let start_hash = match at {
|
||||
BlockID::Latest => {
|
||||
BlockId::Latest => {
|
||||
let start_num = match db.earliest_era() {
|
||||
Some(era) => ::std::cmp::max(era, best_block_number - history),
|
||||
None => best_block_number - history,
|
||||
};
|
||||
|
||||
match self.block_hash(BlockID::Number(start_num)) {
|
||||
match self.block_hash(BlockId::Number(start_num)) {
|
||||
Some(h) => h,
|
||||
None => return Err(snapshot::Error::InvalidStartingBlock(at).into()),
|
||||
}
|
||||
@@ -786,19 +787,19 @@ impl Client {
|
||||
self.history
|
||||
}
|
||||
|
||||
fn block_hash(chain: &BlockChain, id: BlockID) -> Option<H256> {
|
||||
fn block_hash(chain: &BlockChain, id: BlockId) -> Option<H256> {
|
||||
match id {
|
||||
BlockID::Hash(hash) => Some(hash),
|
||||
BlockID::Number(number) => chain.block_hash(number),
|
||||
BlockID::Earliest => chain.block_hash(0),
|
||||
BlockID::Latest | BlockID::Pending => Some(chain.best_block_hash()),
|
||||
BlockId::Hash(hash) => Some(hash),
|
||||
BlockId::Number(number) => chain.block_hash(number),
|
||||
BlockId::Earliest => chain.block_hash(0),
|
||||
BlockId::Latest | BlockId::Pending => Some(chain.best_block_hash()),
|
||||
}
|
||||
}
|
||||
|
||||
fn transaction_address(&self, id: TransactionID) -> Option<TransactionAddress> {
|
||||
fn transaction_address(&self, id: TransactionId) -> Option<TransactionAddress> {
|
||||
match id {
|
||||
TransactionID::Hash(ref hash) => self.chain.read().transaction_address(hash),
|
||||
TransactionID::Location(id, index) => Self::block_hash(&self.chain.read(), id).map(|hash| TransactionAddress {
|
||||
TransactionId::Hash(ref hash) => self.chain.read().transaction_address(hash),
|
||||
TransactionId::Location(id, index) => Self::block_hash(&self.chain.read(), id).map(|hash| TransactionAddress {
|
||||
block_hash: hash,
|
||||
index: index,
|
||||
})
|
||||
@@ -852,7 +853,7 @@ impl snapshot::DatabaseRestore for Client {
|
||||
|
||||
|
||||
impl BlockChainClient for Client {
|
||||
fn call(&self, t: &SignedTransaction, block: BlockID, analytics: CallAnalytics) -> Result<Executed, CallError> {
|
||||
fn call(&self, t: &SignedTransaction, block: BlockId, analytics: CallAnalytics) -> Result<Executed, CallError> {
|
||||
let header = try!(self.block_header(block).ok_or(CallError::StatePruned));
|
||||
let view = HeaderView::new(&header);
|
||||
let last_hashes = self.build_last_hashes(view.parent_hash());
|
||||
@@ -888,11 +889,11 @@ impl BlockChainClient for Client {
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
fn replay(&self, id: TransactionID, analytics: CallAnalytics) -> Result<Executed, CallError> {
|
||||
fn replay(&self, id: TransactionId, analytics: CallAnalytics) -> Result<Executed, CallError> {
|
||||
let address = try!(self.transaction_address(id).ok_or(CallError::TransactionNotFound));
|
||||
let header_data = try!(self.block_header(BlockID::Hash(address.block_hash)).ok_or(CallError::StatePruned));
|
||||
let body_data = try!(self.block_body(BlockID::Hash(address.block_hash)).ok_or(CallError::StatePruned));
|
||||
let mut state = try!(self.state_at_beginning(BlockID::Hash(address.block_hash)).ok_or(CallError::StatePruned));
|
||||
let header_data = try!(self.block_header(BlockId::Hash(address.block_hash)).ok_or(CallError::StatePruned));
|
||||
let body_data = try!(self.block_body(BlockId::Hash(address.block_hash)).ok_or(CallError::StatePruned));
|
||||
let mut state = try!(self.state_at_beginning(BlockId::Hash(address.block_hash)).ok_or(CallError::StatePruned));
|
||||
let txs = BodyView::new(&body_data).transactions();
|
||||
|
||||
if address.index >= txs.len() {
|
||||
@@ -965,18 +966,18 @@ impl BlockChainClient for Client {
|
||||
self.chain.read().best_block_header()
|
||||
}
|
||||
|
||||
fn block_header(&self, id: BlockID) -> Option<Bytes> {
|
||||
fn block_header(&self, id: BlockId) -> Option<Bytes> {
|
||||
let chain = self.chain.read();
|
||||
Self::block_hash(&chain, id).and_then(|hash| chain.block_header_data(&hash))
|
||||
}
|
||||
|
||||
fn block_body(&self, id: BlockID) -> Option<Bytes> {
|
||||
fn block_body(&self, id: BlockId) -> Option<Bytes> {
|
||||
let chain = self.chain.read();
|
||||
Self::block_hash(&chain, id).and_then(|hash| chain.block_body(&hash))
|
||||
}
|
||||
|
||||
fn block(&self, id: BlockID) -> Option<Bytes> {
|
||||
if let BlockID::Pending = id {
|
||||
fn block(&self, id: BlockId) -> Option<Bytes> {
|
||||
if let BlockId::Pending = id {
|
||||
if let Some(block) = self.miner.pending_block() {
|
||||
return Some(block.rlp_bytes(Seal::Without));
|
||||
}
|
||||
@@ -987,7 +988,7 @@ impl BlockChainClient for Client {
|
||||
})
|
||||
}
|
||||
|
||||
fn block_status(&self, id: BlockID) -> BlockStatus {
|
||||
fn block_status(&self, id: BlockId) -> BlockStatus {
|
||||
let chain = self.chain.read();
|
||||
match Self::block_hash(&chain, id) {
|
||||
Some(ref hash) if chain.is_known(hash) => BlockStatus::InChain,
|
||||
@@ -996,38 +997,38 @@ impl BlockChainClient for Client {
|
||||
}
|
||||
}
|
||||
|
||||
fn block_total_difficulty(&self, id: BlockID) -> Option<U256> {
|
||||
if let BlockID::Pending = id {
|
||||
fn block_total_difficulty(&self, id: BlockId) -> Option<U256> {
|
||||
if let BlockId::Pending = id {
|
||||
if let Some(block) = self.miner.pending_block() {
|
||||
return Some(*block.header.difficulty() + self.block_total_difficulty(BlockID::Latest).expect("blocks in chain have details; qed"));
|
||||
return Some(*block.header.difficulty() + self.block_total_difficulty(BlockId::Latest).expect("blocks in chain have details; qed"));
|
||||
}
|
||||
}
|
||||
let chain = self.chain.read();
|
||||
Self::block_hash(&chain, id).and_then(|hash| chain.block_details(&hash)).map(|d| d.total_difficulty)
|
||||
}
|
||||
|
||||
fn nonce(&self, address: &Address, id: BlockID) -> Option<U256> {
|
||||
fn nonce(&self, address: &Address, id: BlockId) -> Option<U256> {
|
||||
self.state_at(id).map(|s| s.nonce(address))
|
||||
}
|
||||
|
||||
fn block_hash(&self, id: BlockID) -> Option<H256> {
|
||||
fn block_hash(&self, id: BlockId) -> Option<H256> {
|
||||
let chain = self.chain.read();
|
||||
Self::block_hash(&chain, id)
|
||||
}
|
||||
|
||||
fn code(&self, address: &Address, id: BlockID) -> Option<Option<Bytes>> {
|
||||
fn code(&self, address: &Address, id: BlockId) -> Option<Option<Bytes>> {
|
||||
self.state_at(id).map(|s| s.code(address).map(|c| (*c).clone()))
|
||||
}
|
||||
|
||||
fn balance(&self, address: &Address, id: BlockID) -> Option<U256> {
|
||||
fn balance(&self, address: &Address, id: BlockId) -> Option<U256> {
|
||||
self.state_at(id).map(|s| s.balance(address))
|
||||
}
|
||||
|
||||
fn storage_at(&self, address: &Address, position: &H256, id: BlockID) -> Option<H256> {
|
||||
fn storage_at(&self, address: &Address, position: &H256, id: BlockId) -> Option<H256> {
|
||||
self.state_at(id).map(|s| s.storage_at(address, position))
|
||||
}
|
||||
|
||||
fn list_accounts(&self, id: BlockID) -> Option<Vec<Address>> {
|
||||
fn list_accounts(&self, id: BlockId) -> Option<Vec<Address>> {
|
||||
if !self.factories.trie.is_fat() {
|
||||
trace!(target: "fatdb", "list_accounts: Not a fat DB");
|
||||
return None;
|
||||
@@ -1059,16 +1060,16 @@ impl BlockChainClient for Client {
|
||||
Some(accounts)
|
||||
}
|
||||
|
||||
fn transaction(&self, id: TransactionID) -> Option<LocalizedTransaction> {
|
||||
fn transaction(&self, id: TransactionId) -> Option<LocalizedTransaction> {
|
||||
self.transaction_address(id).and_then(|address| self.chain.read().transaction(&address))
|
||||
}
|
||||
|
||||
fn uncle(&self, id: UncleID) -> Option<Bytes> {
|
||||
fn uncle(&self, id: UncleId) -> Option<Bytes> {
|
||||
let index = id.position;
|
||||
self.block_body(id.block).and_then(|body| BodyView::new(&body).uncle_rlp_at(index))
|
||||
}
|
||||
|
||||
fn transaction_receipt(&self, id: TransactionID) -> Option<LocalizedReceipt> {
|
||||
fn transaction_receipt(&self, id: TransactionId) -> Option<LocalizedReceipt> {
|
||||
let chain = self.chain.read();
|
||||
self.transaction_address(id)
|
||||
.and_then(|address| chain.block_number(&address.block_hash).and_then(|block_number| {
|
||||
@@ -1152,7 +1153,7 @@ impl BlockChainClient for Client {
|
||||
if self.chain.read().is_known(&unverified.hash()) {
|
||||
return Err(BlockImportError::Import(ImportError::AlreadyInChain));
|
||||
}
|
||||
if self.block_status(BlockID::Hash(unverified.parent_hash())) == BlockStatus::Unknown {
|
||||
if self.block_status(BlockId::Hash(unverified.parent_hash())) == BlockStatus::Unknown {
|
||||
return Err(BlockImportError::Block(BlockError::UnknownParent(unverified.parent_hash())));
|
||||
}
|
||||
}
|
||||
@@ -1166,7 +1167,7 @@ impl BlockChainClient for Client {
|
||||
if self.chain.read().is_known(&header.hash()) {
|
||||
return Err(BlockImportError::Import(ImportError::AlreadyInChain));
|
||||
}
|
||||
if self.block_status(BlockID::Hash(header.parent_hash())) == BlockStatus::Unknown {
|
||||
if self.block_status(BlockId::Hash(header.parent_hash())) == BlockStatus::Unknown {
|
||||
return Err(BlockImportError::Block(BlockError::UnknownParent(header.parent_hash())));
|
||||
}
|
||||
}
|
||||
@@ -1189,7 +1190,7 @@ impl BlockChainClient for Client {
|
||||
self.engine.additional_params().into_iter().collect()
|
||||
}
|
||||
|
||||
fn blocks_with_bloom(&self, bloom: &H2048, from_block: BlockID, to_block: BlockID) -> Option<Vec<BlockNumber>> {
|
||||
fn blocks_with_bloom(&self, bloom: &H2048, from_block: BlockId, to_block: BlockId) -> Option<Vec<BlockNumber>> {
|
||||
match (self.block_number(from_block), self.block_number(to_block)) {
|
||||
(Some(from), Some(to)) => Some(self.chain.read().blocks_with_bloom(bloom, from, to)),
|
||||
_ => None
|
||||
@@ -1231,20 +1232,20 @@ impl BlockChainClient for Client {
|
||||
let trace_address = trace.address;
|
||||
self.transaction_address(trace.transaction)
|
||||
.and_then(|tx_address| {
|
||||
self.block_number(BlockID::Hash(tx_address.block_hash))
|
||||
self.block_number(BlockId::Hash(tx_address.block_hash))
|
||||
.and_then(|number| self.tracedb.read().trace(number, tx_address.index, trace_address))
|
||||
})
|
||||
}
|
||||
|
||||
fn transaction_traces(&self, transaction: TransactionID) -> Option<Vec<LocalizedTrace>> {
|
||||
fn transaction_traces(&self, transaction: TransactionId) -> Option<Vec<LocalizedTrace>> {
|
||||
self.transaction_address(transaction)
|
||||
.and_then(|tx_address| {
|
||||
self.block_number(BlockID::Hash(tx_address.block_hash))
|
||||
self.block_number(BlockId::Hash(tx_address.block_hash))
|
||||
.and_then(|number| self.tracedb.read().transaction_traces(number, tx_address.index))
|
||||
})
|
||||
}
|
||||
|
||||
fn block_traces(&self, block: BlockID) -> Option<Vec<LocalizedTrace>> {
|
||||
fn block_traces(&self, block: BlockId) -> Option<Vec<LocalizedTrace>> {
|
||||
self.block_number(block)
|
||||
.and_then(|number| self.tracedb.read().block_traces(number))
|
||||
}
|
||||
@@ -1279,13 +1280,13 @@ impl BlockChainClient for Client {
|
||||
self.engine.signing_network_id(&self.latest_env_info())
|
||||
}
|
||||
|
||||
fn block_extra_info(&self, id: BlockID) -> Option<BTreeMap<String, String>> {
|
||||
fn block_extra_info(&self, id: BlockId) -> Option<BTreeMap<String, String>> {
|
||||
self.block_header(id)
|
||||
.map(|block| decode(&block))
|
||||
.map(|header| self.engine.extra_info(&header))
|
||||
}
|
||||
|
||||
fn uncle_extra_info(&self, id: UncleID) -> Option<BTreeMap<String, String>> {
|
||||
fn uncle_extra_info(&self, id: UncleId) -> Option<BTreeMap<String, String>> {
|
||||
self.uncle(id)
|
||||
.map(|header| self.engine.extra_info(&decode(&header)))
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -24,8 +24,8 @@ use devtools::*;
|
||||
use transaction::{Transaction, LocalizedTransaction, SignedTransaction, Action};
|
||||
use blockchain::TreeRoute;
|
||||
use client::{
|
||||
BlockChainClient, MiningBlockChainClient, BlockChainInfo, BlockStatus, BlockID,
|
||||
TransactionID, UncleID, TraceId, TraceFilter, LastHashes, CallAnalytics, BlockImportError,
|
||||
BlockChainClient, MiningBlockChainClient, BlockChainInfo, BlockStatus, BlockId,
|
||||
TransactionId, UncleId, TraceId, TraceFilter, LastHashes, CallAnalytics, BlockImportError,
|
||||
};
|
||||
use db::{NUM_COLUMNS, COL_STATE};
|
||||
use header::{Header as BlockHeader, BlockNumber};
|
||||
@@ -72,7 +72,7 @@ pub struct TestBlockChainClient {
|
||||
/// Execution result.
|
||||
pub execution_result: RwLock<Option<Result<Executed, CallError>>>,
|
||||
/// Transaction receipts.
|
||||
pub receipts: RwLock<HashMap<TransactionID, LocalizedReceipt>>,
|
||||
pub receipts: RwLock<HashMap<TransactionId, LocalizedReceipt>>,
|
||||
/// Logs
|
||||
pub logs: RwLock<Vec<LocalizedLogEntry>>,
|
||||
/// Block queue size.
|
||||
@@ -157,7 +157,7 @@ impl TestBlockChainClient {
|
||||
}
|
||||
|
||||
/// Set the transaction receipt result
|
||||
pub fn set_transaction_receipt(&self, id: TransactionID, receipt: LocalizedReceipt) {
|
||||
pub fn set_transaction_receipt(&self, id: TransactionId, receipt: LocalizedReceipt) {
|
||||
self.receipts.write().insert(id, receipt);
|
||||
}
|
||||
|
||||
@@ -255,8 +255,8 @@ impl TestBlockChainClient {
|
||||
|
||||
/// Make a bad block by setting invalid extra data.
|
||||
pub fn corrupt_block(&mut self, n: BlockNumber) {
|
||||
let hash = self.block_hash(BlockID::Number(n)).unwrap();
|
||||
let mut header: BlockHeader = decode(&self.block_header(BlockID::Number(n)).unwrap());
|
||||
let hash = self.block_hash(BlockId::Number(n)).unwrap();
|
||||
let mut header: BlockHeader = decode(&self.block_header(BlockId::Number(n)).unwrap());
|
||||
header.set_extra_data(b"This extra data is way too long to be considered valid".to_vec());
|
||||
let mut rlp = RlpStream::new_list(3);
|
||||
rlp.append(&header);
|
||||
@@ -267,8 +267,8 @@ impl TestBlockChainClient {
|
||||
|
||||
/// Make a bad block by setting invalid parent hash.
|
||||
pub fn corrupt_block_parent(&mut self, n: BlockNumber) {
|
||||
let hash = self.block_hash(BlockID::Number(n)).unwrap();
|
||||
let mut header: BlockHeader = decode(&self.block_header(BlockID::Number(n)).unwrap());
|
||||
let hash = self.block_hash(BlockId::Number(n)).unwrap();
|
||||
let mut header: BlockHeader = decode(&self.block_header(BlockId::Number(n)).unwrap());
|
||||
header.set_parent_hash(H256::from(42));
|
||||
let mut rlp = RlpStream::new_list(3);
|
||||
rlp.append(&header);
|
||||
@@ -284,12 +284,12 @@ impl TestBlockChainClient {
|
||||
blocks_read[&index].clone()
|
||||
}
|
||||
|
||||
fn block_hash(&self, id: BlockID) -> Option<H256> {
|
||||
fn block_hash(&self, id: BlockId) -> Option<H256> {
|
||||
match id {
|
||||
BlockID::Hash(hash) => Some(hash),
|
||||
BlockID::Number(n) => self.numbers.read().get(&(n as usize)).cloned(),
|
||||
BlockID::Earliest => self.numbers.read().get(&0).cloned(),
|
||||
BlockID::Latest | BlockID::Pending => self.numbers.read().get(&(self.numbers.read().len() - 1)).cloned()
|
||||
BlockId::Hash(hash) => Some(hash),
|
||||
BlockId::Number(n) => self.numbers.read().get(&(n as usize)).cloned(),
|
||||
BlockId::Earliest => self.numbers.read().get(&0).cloned(),
|
||||
BlockId::Latest | BlockId::Pending => self.numbers.read().get(&(self.numbers.read().len() - 1)).cloned()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,42 +362,42 @@ impl MiningBlockChainClient for TestBlockChainClient {
|
||||
}
|
||||
|
||||
impl BlockChainClient for TestBlockChainClient {
|
||||
fn call(&self, _t: &SignedTransaction, _block: BlockID, _analytics: CallAnalytics) -> Result<Executed, CallError> {
|
||||
fn call(&self, _t: &SignedTransaction, _block: BlockId, _analytics: CallAnalytics) -> Result<Executed, CallError> {
|
||||
self.execution_result.read().clone().unwrap()
|
||||
}
|
||||
|
||||
fn replay(&self, _id: TransactionID, _analytics: CallAnalytics) -> Result<Executed, CallError> {
|
||||
fn replay(&self, _id: TransactionId, _analytics: CallAnalytics) -> Result<Executed, CallError> {
|
||||
self.execution_result.read().clone().unwrap()
|
||||
}
|
||||
|
||||
fn block_total_difficulty(&self, _id: BlockID) -> Option<U256> {
|
||||
fn block_total_difficulty(&self, _id: BlockId) -> Option<U256> {
|
||||
Some(U256::zero())
|
||||
}
|
||||
|
||||
fn block_hash(&self, id: BlockID) -> Option<H256> {
|
||||
fn block_hash(&self, id: BlockId) -> Option<H256> {
|
||||
Self::block_hash(self, id)
|
||||
}
|
||||
|
||||
fn nonce(&self, address: &Address, id: BlockID) -> Option<U256> {
|
||||
fn nonce(&self, address: &Address, id: BlockId) -> Option<U256> {
|
||||
match id {
|
||||
BlockID::Latest => Some(self.nonces.read().get(address).cloned().unwrap_or(self.spec.params.account_start_nonce)),
|
||||
BlockId::Latest => Some(self.nonces.read().get(address).cloned().unwrap_or(self.spec.params.account_start_nonce)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn latest_nonce(&self, address: &Address) -> U256 {
|
||||
self.nonce(address, BlockID::Latest).unwrap()
|
||||
self.nonce(address, BlockId::Latest).unwrap()
|
||||
}
|
||||
|
||||
fn code(&self, address: &Address, id: BlockID) -> Option<Option<Bytes>> {
|
||||
fn code(&self, address: &Address, id: BlockId) -> Option<Option<Bytes>> {
|
||||
match id {
|
||||
BlockID::Latest => Some(self.code.read().get(address).cloned()),
|
||||
BlockId::Latest => Some(self.code.read().get(address).cloned()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn balance(&self, address: &Address, id: BlockID) -> Option<U256> {
|
||||
if let BlockID::Latest = id {
|
||||
fn balance(&self, address: &Address, id: BlockId) -> Option<U256> {
|
||||
if let BlockId::Latest = id {
|
||||
Some(self.balances.read().get(address).cloned().unwrap_or_else(U256::zero))
|
||||
} else {
|
||||
None
|
||||
@@ -405,38 +405,38 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
}
|
||||
|
||||
fn latest_balance(&self, address: &Address) -> U256 {
|
||||
self.balance(address, BlockID::Latest).unwrap()
|
||||
self.balance(address, BlockId::Latest).unwrap()
|
||||
}
|
||||
|
||||
fn storage_at(&self, address: &Address, position: &H256, id: BlockID) -> Option<H256> {
|
||||
if let BlockID::Latest = id {
|
||||
fn storage_at(&self, address: &Address, position: &H256, id: BlockId) -> Option<H256> {
|
||||
if let BlockId::Latest = id {
|
||||
Some(self.storage.read().get(&(address.clone(), position.clone())).cloned().unwrap_or_else(H256::new))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn list_accounts(&self, _id: BlockID) -> Option<Vec<Address>> {
|
||||
fn list_accounts(&self, _id: BlockId) -> Option<Vec<Address>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn transaction(&self, _id: TransactionID) -> Option<LocalizedTransaction> {
|
||||
fn transaction(&self, _id: TransactionId) -> Option<LocalizedTransaction> {
|
||||
None // Simple default.
|
||||
}
|
||||
|
||||
fn uncle(&self, _id: UncleID) -> Option<Bytes> {
|
||||
fn uncle(&self, _id: UncleId) -> Option<Bytes> {
|
||||
None // Simple default.
|
||||
}
|
||||
|
||||
fn uncle_extra_info(&self, _id: UncleID) -> Option<BTreeMap<String, String>> {
|
||||
fn uncle_extra_info(&self, _id: UncleId) -> Option<BTreeMap<String, String>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn transaction_receipt(&self, id: TransactionID) -> Option<LocalizedReceipt> {
|
||||
fn transaction_receipt(&self, id: TransactionId) -> Option<LocalizedReceipt> {
|
||||
self.receipts.read().get(&id).cloned()
|
||||
}
|
||||
|
||||
fn blocks_with_bloom(&self, _bloom: &H2048, _from_block: BlockID, _to_block: BlockID) -> Option<Vec<BlockNumber>> {
|
||||
fn blocks_with_bloom(&self, _bloom: &H2048, _from_block: BlockId, _to_block: BlockId) -> Option<Vec<BlockNumber>> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
@@ -454,14 +454,14 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
}
|
||||
|
||||
fn best_block_header(&self) -> Bytes {
|
||||
self.block_header(BlockID::Hash(self.chain_info().best_block_hash)).expect("Best block always have header.")
|
||||
self.block_header(BlockId::Hash(self.chain_info().best_block_hash)).expect("Best block always have header.")
|
||||
}
|
||||
|
||||
fn block_header(&self, id: BlockID) -> Option<Bytes> {
|
||||
fn block_header(&self, id: BlockId) -> Option<Bytes> {
|
||||
self.block_hash(id).and_then(|hash| self.blocks.read().get(&hash).map(|r| Rlp::new(r).at(0).as_raw().to_vec()))
|
||||
}
|
||||
|
||||
fn block_body(&self, id: BlockID) -> Option<Bytes> {
|
||||
fn block_body(&self, id: BlockId) -> Option<Bytes> {
|
||||
self.block_hash(id).and_then(|hash| self.blocks.read().get(&hash).map(|r| {
|
||||
let mut stream = RlpStream::new_list(2);
|
||||
stream.append_raw(Rlp::new(r).at(1).as_raw(), 1);
|
||||
@@ -470,21 +470,21 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
}))
|
||||
}
|
||||
|
||||
fn block(&self, id: BlockID) -> Option<Bytes> {
|
||||
fn block(&self, id: BlockId) -> Option<Bytes> {
|
||||
self.block_hash(id).and_then(|hash| self.blocks.read().get(&hash).cloned())
|
||||
}
|
||||
|
||||
fn block_extra_info(&self, id: BlockID) -> Option<BTreeMap<String, String>> {
|
||||
fn block_extra_info(&self, id: BlockId) -> Option<BTreeMap<String, String>> {
|
||||
self.block(id)
|
||||
.map(|block| BlockView::new(&block).header())
|
||||
.map(|header| self.spec.engine.extra_info(&header))
|
||||
}
|
||||
|
||||
|
||||
fn block_status(&self, id: BlockID) -> BlockStatus {
|
||||
fn block_status(&self, id: BlockId) -> BlockStatus {
|
||||
match id {
|
||||
BlockID::Number(number) if (number as usize) < self.blocks.read().len() => BlockStatus::InChain,
|
||||
BlockID::Hash(ref hash) if self.blocks.read().get(hash).is_some() => BlockStatus::InChain,
|
||||
BlockId::Number(number) if (number as usize) < self.blocks.read().len() => BlockStatus::InChain,
|
||||
BlockId::Hash(ref hash) if self.blocks.read().get(hash).is_some() => BlockStatus::InChain,
|
||||
_ => BlockStatus::Unknown
|
||||
}
|
||||
}
|
||||
@@ -637,11 +637,11 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn transaction_traces(&self, _trace: TransactionID) -> Option<Vec<LocalizedTrace>> {
|
||||
fn transaction_traces(&self, _trace: TransactionId) -> Option<Vec<LocalizedTrace>> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn block_traces(&self, _trace: BlockID) -> Option<Vec<LocalizedTrace>> {
|
||||
fn block_traces(&self, _trace: BlockId) -> Option<Vec<LocalizedTrace>> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
|
||||
@@ -49,81 +49,81 @@ pub trait BlockChainClient : Sync + Send {
|
||||
fn keep_alive(&self) {}
|
||||
|
||||
/// Get raw block header data by block id.
|
||||
fn block_header(&self, id: BlockID) -> Option<Bytes>;
|
||||
fn block_header(&self, id: BlockId) -> Option<Bytes>;
|
||||
|
||||
/// Get raw block body data by block id.
|
||||
/// Block body is an RLP list of two items: uncles and transactions.
|
||||
fn block_body(&self, id: BlockID) -> Option<Bytes>;
|
||||
fn block_body(&self, id: BlockId) -> Option<Bytes>;
|
||||
|
||||
/// Get raw block data by block header hash.
|
||||
fn block(&self, id: BlockID) -> Option<Bytes>;
|
||||
fn block(&self, id: BlockId) -> Option<Bytes>;
|
||||
|
||||
/// Get block status by block header hash.
|
||||
fn block_status(&self, id: BlockID) -> BlockStatus;
|
||||
fn block_status(&self, id: BlockId) -> BlockStatus;
|
||||
|
||||
/// Get block total difficulty.
|
||||
fn block_total_difficulty(&self, id: BlockID) -> Option<U256>;
|
||||
fn block_total_difficulty(&self, id: BlockId) -> Option<U256>;
|
||||
|
||||
/// Attempt to get address nonce at given block.
|
||||
/// May not fail on BlockID::Latest.
|
||||
fn nonce(&self, address: &Address, id: BlockID) -> Option<U256>;
|
||||
/// May not fail on BlockId::Latest.
|
||||
fn nonce(&self, address: &Address, id: BlockId) -> Option<U256>;
|
||||
|
||||
/// Get address nonce at the latest block's state.
|
||||
fn latest_nonce(&self, address: &Address) -> U256 {
|
||||
self.nonce(address, BlockID::Latest)
|
||||
.expect("nonce will return Some when given BlockID::Latest. nonce was given BlockID::Latest. \
|
||||
self.nonce(address, BlockId::Latest)
|
||||
.expect("nonce will return Some when given BlockId::Latest. nonce was given BlockId::Latest. \
|
||||
Therefore nonce has returned Some; qed")
|
||||
}
|
||||
|
||||
/// Get block hash.
|
||||
fn block_hash(&self, id: BlockID) -> Option<H256>;
|
||||
fn block_hash(&self, id: BlockId) -> Option<H256>;
|
||||
|
||||
/// Get address code at given block's state.
|
||||
fn code(&self, address: &Address, id: BlockID) -> Option<Option<Bytes>>;
|
||||
fn code(&self, address: &Address, id: BlockId) -> Option<Option<Bytes>>;
|
||||
|
||||
/// Get address code at the latest block's state.
|
||||
fn latest_code(&self, address: &Address) -> Option<Bytes> {
|
||||
self.code(address, BlockID::Latest)
|
||||
.expect("code will return Some if given BlockID::Latest; qed")
|
||||
self.code(address, BlockId::Latest)
|
||||
.expect("code will return Some if given BlockId::Latest; qed")
|
||||
}
|
||||
|
||||
/// Get address balance at the given block's state.
|
||||
///
|
||||
/// May not return None if given BlockID::Latest.
|
||||
/// May not return None if given BlockId::Latest.
|
||||
/// Returns None if and only if the block's root hash has been pruned from the DB.
|
||||
fn balance(&self, address: &Address, id: BlockID) -> Option<U256>;
|
||||
fn balance(&self, address: &Address, id: BlockId) -> Option<U256>;
|
||||
|
||||
/// Get address balance at the latest block's state.
|
||||
fn latest_balance(&self, address: &Address) -> U256 {
|
||||
self.balance(address, BlockID::Latest)
|
||||
.expect("balance will return Some if given BlockID::Latest. balance was given BlockID::Latest \
|
||||
self.balance(address, BlockId::Latest)
|
||||
.expect("balance will return Some if given BlockId::Latest. balance was given BlockId::Latest \
|
||||
Therefore balance has returned Some; qed")
|
||||
}
|
||||
|
||||
/// Get value of the storage at given position at the given block's state.
|
||||
///
|
||||
/// May not return None if given BlockID::Latest.
|
||||
/// May not return None if given BlockId::Latest.
|
||||
/// Returns None if and only if the block's root hash has been pruned from the DB.
|
||||
fn storage_at(&self, address: &Address, position: &H256, id: BlockID) -> Option<H256>;
|
||||
fn storage_at(&self, address: &Address, position: &H256, id: BlockId) -> Option<H256>;
|
||||
|
||||
/// Get value of the storage at given position at the latest block's state.
|
||||
fn latest_storage_at(&self, address: &Address, position: &H256) -> H256 {
|
||||
self.storage_at(address, position, BlockID::Latest)
|
||||
.expect("storage_at will return Some if given BlockID::Latest. storage_at was given BlockID::Latest. \
|
||||
self.storage_at(address, position, BlockId::Latest)
|
||||
.expect("storage_at will return Some if given BlockId::Latest. storage_at was given BlockId::Latest. \
|
||||
Therefore storage_at has returned Some; qed")
|
||||
}
|
||||
|
||||
/// Get a list of all accounts in the block `id`, if fat DB is in operation, otherwise `None`.
|
||||
fn list_accounts(&self, id: BlockID) -> Option<Vec<Address>>;
|
||||
fn list_accounts(&self, id: BlockId) -> Option<Vec<Address>>;
|
||||
|
||||
/// Get transaction with given hash.
|
||||
fn transaction(&self, id: TransactionID) -> Option<LocalizedTransaction>;
|
||||
fn transaction(&self, id: TransactionId) -> Option<LocalizedTransaction>;
|
||||
|
||||
/// Get uncle with given id.
|
||||
fn uncle(&self, id: UncleID) -> Option<Bytes>;
|
||||
fn uncle(&self, id: UncleId) -> Option<Bytes>;
|
||||
|
||||
/// Get transaction receipt with given hash.
|
||||
fn transaction_receipt(&self, id: TransactionID) -> Option<LocalizedReceipt>;
|
||||
fn transaction_receipt(&self, id: TransactionId) -> Option<LocalizedReceipt>;
|
||||
|
||||
/// Get a tree route between `from` and `to`.
|
||||
/// See `BlockChain::tree_route`.
|
||||
@@ -160,16 +160,16 @@ pub trait BlockChainClient : Sync + Send {
|
||||
fn best_block_header(&self) -> Bytes;
|
||||
|
||||
/// Returns numbers of blocks containing given bloom.
|
||||
fn blocks_with_bloom(&self, bloom: &H2048, from_block: BlockID, to_block: BlockID) -> Option<Vec<BlockNumber>>;
|
||||
fn blocks_with_bloom(&self, bloom: &H2048, from_block: BlockId, to_block: BlockId) -> Option<Vec<BlockNumber>>;
|
||||
|
||||
/// Returns logs matching given filter.
|
||||
fn logs(&self, filter: Filter) -> Vec<LocalizedLogEntry>;
|
||||
|
||||
/// Makes a non-persistent transaction call.
|
||||
fn call(&self, t: &SignedTransaction, block: BlockID, analytics: CallAnalytics) -> Result<Executed, CallError>;
|
||||
fn call(&self, t: &SignedTransaction, block: BlockId, analytics: CallAnalytics) -> Result<Executed, CallError>;
|
||||
|
||||
/// Replays a given transaction for inspection.
|
||||
fn replay(&self, t: TransactionID, analytics: CallAnalytics) -> Result<Executed, CallError>;
|
||||
fn replay(&self, t: TransactionId, analytics: CallAnalytics) -> Result<Executed, CallError>;
|
||||
|
||||
/// Returns traces matching given filter.
|
||||
fn filter_traces(&self, filter: TraceFilter) -> Option<Vec<LocalizedTrace>>;
|
||||
@@ -178,10 +178,10 @@ pub trait BlockChainClient : Sync + Send {
|
||||
fn trace(&self, trace: TraceId) -> Option<LocalizedTrace>;
|
||||
|
||||
/// Returns traces created by transaction.
|
||||
fn transaction_traces(&self, trace: TransactionID) -> Option<Vec<LocalizedTrace>>;
|
||||
fn transaction_traces(&self, trace: TransactionId) -> Option<Vec<LocalizedTrace>>;
|
||||
|
||||
/// Returns traces created by transaction from block.
|
||||
fn block_traces(&self, trace: BlockID) -> Option<Vec<LocalizedTrace>>;
|
||||
fn block_traces(&self, trace: BlockId) -> Option<Vec<LocalizedTrace>>;
|
||||
|
||||
/// Get last hashes starting from best block.
|
||||
fn last_hashes(&self) -> LastHashes;
|
||||
@@ -198,7 +198,7 @@ pub trait BlockChainClient : Sync + Send {
|
||||
let mut corpus = Vec::new();
|
||||
while corpus.is_empty() {
|
||||
for _ in 0..sample_size {
|
||||
let block_bytes = self.block(BlockID::Hash(h)).expect("h is either the best_block_hash or an ancestor; qed");
|
||||
let block_bytes = self.block(BlockId::Hash(h)).expect("h is either the best_block_hash or an ancestor; qed");
|
||||
let block = BlockView::new(&block_bytes);
|
||||
let header = block.header_view();
|
||||
if header.number() == 0 {
|
||||
@@ -236,11 +236,11 @@ pub trait BlockChainClient : Sync + Send {
|
||||
/// Set the mode.
|
||||
fn set_mode(&self, mode: Mode);
|
||||
|
||||
/// Returns engine-related extra info for `BlockID`.
|
||||
fn block_extra_info(&self, id: BlockID) -> Option<BTreeMap<String, String>>;
|
||||
/// Returns engine-related extra info for `BlockId`.
|
||||
fn block_extra_info(&self, id: BlockId) -> Option<BTreeMap<String, String>>;
|
||||
|
||||
/// Returns engine-related extra info for `UncleID`.
|
||||
fn uncle_extra_info(&self, id: UncleID) -> Option<BTreeMap<String, String>>;
|
||||
/// Returns engine-related extra info for `UncleId`.
|
||||
fn uncle_extra_info(&self, id: UncleId) -> Option<BTreeMap<String, String>>;
|
||||
}
|
||||
|
||||
/// Extended client interface used for mining
|
||||
|
||||
@@ -15,45 +15,81 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::sync::Weak;
|
||||
use util::misc::code_hash;
|
||||
use util::{Address, H160};
|
||||
use util::misc::{VersionInfo, ReleaseTrack, platform};
|
||||
use util::{Address, H160, H256, FixedHash};
|
||||
use client::operations::Operations;
|
||||
use client::client::Client;
|
||||
use client::BlockId;
|
||||
|
||||
pub struct Updater {
|
||||
operations: Operations,
|
||||
pub struct ReleaseInfo {
|
||||
fork_supported: usize,
|
||||
latest_known_fork: usize,
|
||||
|
||||
latest: VersionInfo,
|
||||
latest_fork: usize,
|
||||
latest_binary: Option<H256>,
|
||||
}
|
||||
|
||||
fn platform() -> &'static str {
|
||||
"linux_x64"
|
||||
pub struct Updater {
|
||||
client: Weak<Client>,
|
||||
operations: Operations,
|
||||
|
||||
pub this: VersionInfo,
|
||||
pub release_info: Option<ReleaseInfo>,
|
||||
|
||||
}
|
||||
|
||||
impl Updater {
|
||||
pub fn new(client: Weak<Client>, operations: Address) -> Self {
|
||||
Updater {
|
||||
let mut u = Updater {
|
||||
client: client.clone(),
|
||||
operations: Operations::new(operations, move |a, d| client.upgrade().ok_or("No client!".into()).and_then(|c| c.call_contract(a, d))),
|
||||
this: VersionInfo::this(),
|
||||
release_info: None,
|
||||
};
|
||||
u.release_info = u.get_release_info().ok();
|
||||
if u.this.track == ReleaseTrack::Unknown {
|
||||
u.this.track = ReleaseTrack::Nightly;
|
||||
}
|
||||
u
|
||||
}
|
||||
|
||||
fn get_release_info(&mut self) -> Result<ReleaseInfo, String> {
|
||||
//601e0fb0fd7e9e1cec18f8872e8713117cab4e84
|
||||
if self.this.track == ReleaseTrack::Unknown {
|
||||
return Err(format!("Current executable ({}) is unreleased.", H160::from(self.this.hash)));
|
||||
}
|
||||
|
||||
let client_id = "parity";
|
||||
let latest_known_fork = self.operations.latest_fork()?;
|
||||
let our_fork = self.operations.release(client_id, &self.this.hash.into())?.0;
|
||||
let latest_release = self.operations.latest_in_track(client_id, self.this.track.into())?;
|
||||
let (fork, track, semver, _critical) = self.operations.release(client_id, &latest_release)?;
|
||||
let maybe_latest_binary = self.operations.checksum(client_id, &latest_release, &platform())?;
|
||||
Ok(ReleaseInfo {
|
||||
fork_supported: our_fork as usize,
|
||||
latest_known_fork: latest_known_fork as usize,
|
||||
latest: VersionInfo::from_raw(semver, track, latest_release.into()),
|
||||
latest_fork: fork as usize,
|
||||
latest_binary: if maybe_latest_binary.is_zero() { None } else { Some(maybe_latest_binary) },
|
||||
})
|
||||
}
|
||||
|
||||
pub fn tick(&mut self) {
|
||||
(|| -> Result<(), String> {
|
||||
let code_hash = H160::from("0x080ec8043f41e25ee8aa4ee6112906ac6d82ea74").into();//code_hash().into();
|
||||
let client = "parity";
|
||||
|
||||
let (fork, track, semver) = self.operations.find_release(client, &code_hash)?;
|
||||
let track_name = match track { 1 => "stable", 2 => "beta", 3 => "nightly", _ => "unknown" };
|
||||
info!(target: "updater", "Current release ({}) is {}.{}.{}-{} and latest fork it supports is at block #{}", H160::from(code_hash), semver >> 16, (semver >> 8) & 0xff, semver & 0xff, track_name, fork);
|
||||
|
||||
let latest_fork = self.operations.latest_fork()?;
|
||||
info!(target: "updater", "Latest fork is at block #{}", latest_fork);
|
||||
|
||||
let latest = self.operations.latest_in_track(client, track)?;
|
||||
let (fork, _, semver) = self.operations.find_release(client, &latest)?;
|
||||
info!(target: "updater", "Latest release in our track is {}.{}.{}-{} ({:?}); supports fork at block #{}", semver >> 16, (semver >> 8) & 0xff, semver & 0xff, track_name, H160::from(latest), fork);
|
||||
|
||||
let exe_hash = self.operations.find_checksum(client, &latest, platform())?;
|
||||
info!(target: "updater", "Latest release's binary on {} is {}", platform(), exe_hash);
|
||||
Ok(())
|
||||
})().unwrap_or_else(|e| warn!("{}", e));
|
||||
self.release_info = self.get_release_info().ok();
|
||||
let current_number = self.client.upgrade().map_or(0, |c| c.block_number(BlockId::Latest).unwrap_or(0));
|
||||
info!(target: "updater", "Current release is {}", self.this);
|
||||
if let Some(ref relinfo) = self.release_info {
|
||||
info!(target: "updater", "Latest release in our track is {} ({} binary is {})",
|
||||
relinfo.latest,
|
||||
platform(),
|
||||
if let Some(ref b) = relinfo.latest_binary {
|
||||
format!("{}", b)
|
||||
} else {
|
||||
"unreleased".into()
|
||||
}
|
||||
);
|
||||
info!(target: "updater", "Fork: this/current/latest/latest-known: #{}/#{}/#{}/#{}", relinfo.fork_supported, current_number, relinfo.latest_fork, relinfo.latest_known_fork);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ use account_provider::AccountProvider;
|
||||
use views::{BlockView, HeaderView};
|
||||
use header::Header;
|
||||
use state::{State, CleanupMode};
|
||||
use client::{MiningBlockChainClient, Executive, Executed, EnvInfo, TransactOptions, BlockID, CallAnalytics};
|
||||
use client::{MiningBlockChainClient, Executive, Executed, EnvInfo, TransactOptions, BlockId, CallAnalytics};
|
||||
use client::TransactionImportResult;
|
||||
use executive::contract_address;
|
||||
use block::{ClosedBlock, SealedBlock, IsBlock, Block};
|
||||
@@ -693,7 +693,7 @@ impl MinerService for Miner {
|
||||
Ok(ret)
|
||||
},
|
||||
None => {
|
||||
chain.call(t, BlockID::Latest, analytics)
|
||||
chain.call(t, BlockId::Latest, analytics)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1073,7 +1073,7 @@ impl MinerService for Miner {
|
||||
|
||||
fn fetch_transactions(chain: &MiningBlockChainClient, hash: &H256) -> Vec<SignedTransaction> {
|
||||
let block = chain
|
||||
.block(BlockID::Hash(*hash))
|
||||
.block(BlockId::Hash(*hash))
|
||||
// Client should send message after commit to db and inserting to chain.
|
||||
.expect("Expected in-chain blocks.");
|
||||
let block = BlockView::new(&block);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use ids::BlockID;
|
||||
use ids::BlockId;
|
||||
|
||||
use util::H256;
|
||||
use util::trie::TrieError;
|
||||
@@ -28,7 +28,7 @@ use rlp::DecoderError;
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
/// Invalid starting block for snapshot.
|
||||
InvalidStartingBlock(BlockID),
|
||||
InvalidStartingBlock(BlockId),
|
||||
/// Block not found.
|
||||
BlockNotFound(H256),
|
||||
/// Incomplete chain.
|
||||
|
||||
@@ -27,7 +27,7 @@ use account_db::{AccountDB, AccountDBMut};
|
||||
use blockchain::{BlockChain, BlockProvider};
|
||||
use engines::Engine;
|
||||
use header::Header;
|
||||
use ids::BlockID;
|
||||
use ids::BlockId;
|
||||
use views::BlockView;
|
||||
|
||||
use util::{Bytes, Hashable, HashDB, DBValue, snappy, U256, Uint};
|
||||
@@ -129,7 +129,7 @@ pub fn take_snapshot<W: SnapshotWriter + Send>(
|
||||
p: &Progress
|
||||
) -> Result<(), Error> {
|
||||
let start_header = try!(chain.block_header(&block_at)
|
||||
.ok_or(Error::InvalidStartingBlock(BlockID::Hash(block_at))));
|
||||
.ok_or(Error::InvalidStartingBlock(BlockId::Hash(block_at))));
|
||||
let state_root = start_header.state_root();
|
||||
let number = start_header.number();
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ use blockchain::BlockChain;
|
||||
use client::{BlockChainClient, Client};
|
||||
use engines::Engine;
|
||||
use error::Error;
|
||||
use ids::BlockID;
|
||||
use ids::BlockId;
|
||||
use service::ClientIoMessage;
|
||||
|
||||
use io::IoChannel;
|
||||
@@ -353,7 +353,7 @@ impl Service {
|
||||
let writer = try!(LooseWriter::new(temp_dir.clone()));
|
||||
|
||||
let guard = Guard::new(temp_dir.clone());
|
||||
let res = client.take_snapshot(writer, BlockID::Number(num), &self.progress);
|
||||
let res = client.take_snapshot(writer, BlockId::Number(num), &self.progress);
|
||||
|
||||
self.taking_snapshot.store(false, Ordering::SeqCst);
|
||||
if let Err(e) = res {
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use client::{BlockChainClient, Client};
|
||||
use ids::BlockID;
|
||||
use ids::BlockId;
|
||||
use snapshot::service::{Service, ServiceParams};
|
||||
use snapshot::{self, ManifestData, SnapshotService};
|
||||
use spec::Spec;
|
||||
@@ -96,8 +96,8 @@ fn restored_is_equivalent() {
|
||||
assert_eq!(service.status(), ::snapshot::RestorationStatus::Inactive);
|
||||
|
||||
for x in 0..NUM_BLOCKS {
|
||||
let block1 = client.block(BlockID::Number(x as u64)).unwrap();
|
||||
let block2 = client2.block(BlockID::Number(x as u64)).unwrap();
|
||||
let block1 = client.block(BlockId::Number(x as u64)).unwrap();
|
||||
let block2 = client2.block(BlockId::Number(x as u64)).unwrap();
|
||||
|
||||
assert_eq!(block1, block2);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
use util::Mutex;
|
||||
use client::{BlockChainClient, Client, ChainNotify};
|
||||
use ids::BlockID;
|
||||
use ids::BlockId;
|
||||
use service::ClientIoMessage;
|
||||
use views::HeaderView;
|
||||
|
||||
@@ -43,7 +43,7 @@ impl<F> Oracle for StandardOracle<F>
|
||||
where F: Send + Sync + Fn() -> bool
|
||||
{
|
||||
fn to_number(&self, hash: H256) -> Option<u64> {
|
||||
self.client.block_header(BlockID::Hash(hash)).map(|h| HeaderView::new(&h).number())
|
||||
self.client.block_header(BlockId::Hash(hash)).map(|h| HeaderView::new(&h).number())
|
||||
}
|
||||
|
||||
fn is_major_importing(&self) -> bool {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use io::IoChannel;
|
||||
use client::{BlockChainClient, MiningBlockChainClient, Client, ClientConfig, BlockID};
|
||||
use client::{BlockChainClient, MiningBlockChainClient, Client, ClientConfig, BlockId};
|
||||
use state::CleanupMode;
|
||||
use ethereum;
|
||||
use block::IsBlock;
|
||||
@@ -99,7 +99,7 @@ fn imports_good_block() {
|
||||
client.flush_queue();
|
||||
client.import_verified_blocks();
|
||||
|
||||
let block = client.block_header(BlockID::Number(1)).unwrap();
|
||||
let block = client.block_header(BlockId::Number(1)).unwrap();
|
||||
assert!(!block.is_empty());
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ fn query_none_block() {
|
||||
IoChannel::disconnected(),
|
||||
&db_config
|
||||
).unwrap();
|
||||
let non_existant = client.block_header(BlockID::Number(188));
|
||||
let non_existant = client.block_header(BlockId::Number(188));
|
||||
assert!(non_existant.is_none());
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ fn query_none_block() {
|
||||
fn query_bad_block() {
|
||||
let client_result = get_test_client_with_blocks(vec![get_bad_state_dummy_block()]);
|
||||
let client = client_result.reference();
|
||||
let bad_block:Option<Bytes> = client.block_header(BlockID::Number(1));
|
||||
let bad_block:Option<Bytes> = client.block_header(BlockId::Number(1));
|
||||
|
||||
assert!(bad_block.is_none());
|
||||
}
|
||||
@@ -146,8 +146,8 @@ fn returns_logs() {
|
||||
let client_result = get_test_client_with_blocks(vec![dummy_block.clone()]);
|
||||
let client = client_result.reference();
|
||||
let logs = client.logs(Filter {
|
||||
from_block: BlockID::Earliest,
|
||||
to_block: BlockID::Latest,
|
||||
from_block: BlockId::Earliest,
|
||||
to_block: BlockId::Latest,
|
||||
address: None,
|
||||
topics: vec![],
|
||||
limit: None,
|
||||
@@ -161,8 +161,8 @@ fn returns_logs_with_limit() {
|
||||
let client_result = get_test_client_with_blocks(vec![dummy_block.clone()]);
|
||||
let client = client_result.reference();
|
||||
let logs = client.logs(Filter {
|
||||
from_block: BlockID::Earliest,
|
||||
to_block: BlockID::Latest,
|
||||
from_block: BlockId::Earliest,
|
||||
to_block: BlockId::Latest,
|
||||
address: None,
|
||||
topics: vec![],
|
||||
limit: Some(2),
|
||||
@@ -176,7 +176,7 @@ fn returns_block_body() {
|
||||
let client_result = get_test_client_with_blocks(vec![dummy_block.clone()]);
|
||||
let client = client_result.reference();
|
||||
let block = BlockView::new(&dummy_block);
|
||||
let body = client.block_body(BlockID::Hash(block.header().hash())).unwrap();
|
||||
let body = client.block_body(BlockId::Hash(block.header().hash())).unwrap();
|
||||
let body = Rlp::new(&body);
|
||||
assert_eq!(body.item_count(), 2);
|
||||
assert_eq!(body.at(0).as_raw()[..], block.rlp().at(1).as_raw()[..]);
|
||||
@@ -187,7 +187,7 @@ fn returns_block_body() {
|
||||
fn imports_block_sequence() {
|
||||
let client_result = generate_dummy_client(6);
|
||||
let client = client_result.reference();
|
||||
let block = client.block_header(BlockID::Number(5)).unwrap();
|
||||
let block = client.block_header(BlockId::Number(5)).unwrap();
|
||||
|
||||
assert!(!block.is_empty());
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
use nanoipc;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{Ordering, AtomicBool};
|
||||
use client::{Client, BlockChainClient, ClientConfig, BlockID};
|
||||
use client::{Client, BlockChainClient, ClientConfig, BlockId};
|
||||
use client::remote::RemoteClient;
|
||||
use tests::helpers::*;
|
||||
use devtools::*;
|
||||
@@ -71,7 +71,7 @@ fn can_query_block() {
|
||||
run_test_worker(scope, stop_guard.share(), socket_path);
|
||||
let remote_client = nanoipc::generic_client::<RemoteClient<_>>(socket_path).unwrap();
|
||||
|
||||
let non_existant_block = remote_client.block_header(BlockID::Number(999));
|
||||
let non_existant_block = remote_client.block_header(BlockId::Number(999));
|
||||
|
||||
assert!(non_existant_block.is_none());
|
||||
})
|
||||
|
||||
@@ -18,17 +18,17 @@
|
||||
|
||||
use util::{Address, H256, Hashable, H2048};
|
||||
use util::bloom::Bloomable;
|
||||
use client::BlockID;
|
||||
use client::BlockId;
|
||||
use log_entry::LogEntry;
|
||||
|
||||
/// Blockchain Filter.
|
||||
#[derive(Binary, Debug, PartialEq)]
|
||||
pub struct Filter {
|
||||
/// Blockchain will be searched from this block.
|
||||
pub from_block: BlockID,
|
||||
pub from_block: BlockId,
|
||||
|
||||
/// Till this block.
|
||||
pub to_block: BlockID,
|
||||
pub to_block: BlockId,
|
||||
|
||||
/// Search addresses.
|
||||
///
|
||||
@@ -114,14 +114,14 @@ impl Filter {
|
||||
mod tests {
|
||||
use util::FixedHash;
|
||||
use filter::Filter;
|
||||
use client::BlockID;
|
||||
use client::BlockId;
|
||||
use log_entry::LogEntry;
|
||||
|
||||
#[test]
|
||||
fn test_bloom_possibilities_none() {
|
||||
let none_filter = Filter {
|
||||
from_block: BlockID::Earliest,
|
||||
to_block: BlockID::Latest,
|
||||
from_block: BlockId::Earliest,
|
||||
to_block: BlockId::Latest,
|
||||
address: None,
|
||||
topics: vec![None, None, None, None],
|
||||
limit: None,
|
||||
@@ -136,8 +136,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_bloom_possibilities_single_address_and_topic() {
|
||||
let filter = Filter {
|
||||
from_block: BlockID::Earliest,
|
||||
to_block: BlockID::Latest,
|
||||
from_block: BlockId::Earliest,
|
||||
to_block: BlockId::Latest,
|
||||
address: Some(vec!["b372018f3be9e171df0581136b59d2faf73a7d5d".into()]),
|
||||
topics: vec![
|
||||
Some(vec!["ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into()]),
|
||||
@@ -155,8 +155,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_bloom_possibilities_single_address_and_many_topics() {
|
||||
let filter = Filter {
|
||||
from_block: BlockID::Earliest,
|
||||
to_block: BlockID::Latest,
|
||||
from_block: BlockId::Earliest,
|
||||
to_block: BlockId::Latest,
|
||||
address: Some(vec!["b372018f3be9e171df0581136b59d2faf73a7d5d".into()]),
|
||||
topics: vec![
|
||||
Some(vec!["ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into()]),
|
||||
@@ -174,8 +174,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_bloom_possibilites_multiple_addresses_and_topics() {
|
||||
let filter = Filter {
|
||||
from_block: BlockID::Earliest,
|
||||
to_block: BlockID::Latest,
|
||||
from_block: BlockId::Earliest,
|
||||
to_block: BlockId::Latest,
|
||||
address: Some(vec![
|
||||
"b372018f3be9e171df0581136b59d2faf73a7d5d".into(),
|
||||
"b372018f3be9e171df0581136b59d2faf73a7d5d".into(),
|
||||
@@ -204,8 +204,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_filter_matches() {
|
||||
let filter = Filter {
|
||||
from_block: BlockID::Earliest,
|
||||
to_block: BlockID::Latest,
|
||||
from_block: BlockId::Earliest,
|
||||
to_block: BlockId::Latest,
|
||||
address: Some(vec!["b372018f3be9e171df0581136b59d2faf73a7d5d".into()]),
|
||||
topics: vec![
|
||||
Some(vec!["ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into()]),
|
||||
|
||||
@@ -21,7 +21,7 @@ use header::BlockNumber;
|
||||
|
||||
/// Uniquely identifies block.
|
||||
#[derive(Debug, PartialEq, Copy, Clone, Hash, Eq, Binary)]
|
||||
pub enum BlockID {
|
||||
pub enum BlockId {
|
||||
/// Block's sha3.
|
||||
/// Querying by hash is always faster.
|
||||
Hash(H256),
|
||||
@@ -37,28 +37,28 @@ pub enum BlockID {
|
||||
|
||||
/// Uniquely identifies transaction.
|
||||
#[derive(Debug, PartialEq, Clone, Hash, Eq, Binary)]
|
||||
pub enum TransactionID {
|
||||
pub enum TransactionId {
|
||||
/// Transaction's sha3.
|
||||
Hash(H256),
|
||||
/// Block id and transaction index within this block.
|
||||
/// Querying by block position is always faster.
|
||||
Location(BlockID, usize)
|
||||
Location(BlockId, usize)
|
||||
}
|
||||
|
||||
/// Uniquely identifies Trace.
|
||||
#[derive(Binary)]
|
||||
pub struct TraceId {
|
||||
/// Transaction
|
||||
pub transaction: TransactionID,
|
||||
pub transaction: TransactionId,
|
||||
/// Trace address within transaction.
|
||||
pub address: Vec<usize>,
|
||||
}
|
||||
|
||||
/// Uniquely identifies Uncle.
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone, Binary)]
|
||||
pub struct UncleID {
|
||||
pub struct UncleId {
|
||||
/// Block id.
|
||||
pub block: BlockID,
|
||||
pub block: BlockId,
|
||||
/// Position in block.
|
||||
pub position: usize
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
|
||||
use std::ops::Range;
|
||||
use util::{Address};
|
||||
use types::ids::BlockID;
|
||||
use types::ids::BlockId;
|
||||
|
||||
/// Easy to use trace filter.
|
||||
#[derive(Binary)]
|
||||
pub struct Filter {
|
||||
/// Range of filtering.
|
||||
pub range: Range<BlockID>,
|
||||
pub range: Range<BlockId>,
|
||||
/// From address.
|
||||
pub from_address: Vec<Address>,
|
||||
/// To address.
|
||||
|
||||
Reference in New Issue
Block a user