From f169c8dbb05789abafb252c6fb71a6aad34c12f1 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Thu, 23 Feb 2017 19:17:05 +0100 Subject: [PATCH] fix remainder of build --- evmbin/src/ext.rs | 23 ++++++++-------- rpc/src/v1/helpers/errors.rs | 5 ++++ rpc/src/v1/impls/eth.rs | 32 ++++++++++++++++++++--- rpc/src/v1/tests/eth.rs | 1 - rpc/src/v1/tests/helpers/miner_service.rs | 29 ++++++++++++++------ 5 files changed, 66 insertions(+), 24 deletions(-) diff --git a/evmbin/src/ext.rs b/evmbin/src/ext.rs index 6492f4fdc..bcce9adc1 100644 --- a/evmbin/src/ext.rs +++ b/evmbin/src/ext.rs @@ -18,7 +18,7 @@ use std::sync::Arc; use std::collections::HashMap; -use util::{U256, H256, Address, Bytes, FixedHash}; +use util::{U256, H256, Address, Bytes, FixedHash, trie}; use ethcore::client::EnvInfo; use ethcore::evm::{self, Ext, ContractCreateResult, MessageCallResult, Schedule, CallType}; @@ -39,27 +39,28 @@ impl Default for FakeExt { } impl Ext for FakeExt { - fn storage_at(&self, key: &H256) -> H256 { - self.store.get(key).unwrap_or(&H256::new()).clone() + fn storage_at(&self, key: &H256) -> trie::Result { + Ok(self.store.get(key).unwrap_or(&H256::new()).clone()) } - fn set_storage(&mut self, key: H256, value: H256) { + fn set_storage(&mut self, key: H256, value: H256) -> trie::Result<()> { self.store.insert(key, value); + Ok(()) } - fn exists(&self, _address: &Address) -> bool { + fn exists(&self, _address: &Address) -> trie::Result { unimplemented!(); } - fn exists_and_not_null(&self, _address: &Address) -> bool { + fn exists_and_not_null(&self, _address: &Address) -> trie::Result { unimplemented!(); } - fn origin_balance(&self) -> U256 { + fn origin_balance(&self) -> trie::Result { unimplemented!(); } - fn balance(&self, _address: &Address) -> U256 { + fn balance(&self, _address: &Address) -> trie::Result { unimplemented!(); } @@ -83,11 +84,11 @@ impl Ext for FakeExt { unimplemented!(); } - fn extcode(&self, _address: &Address) -> Arc { + fn extcode(&self, _address: &Address) -> trie::Result> { unimplemented!(); } - fn extcodesize(&self, _address: &Address) -> usize { + fn extcodesize(&self, _address: &Address) -> trie::Result { unimplemented!(); } @@ -99,7 +100,7 @@ impl Ext for FakeExt { Ok(*gas) } - fn suicide(&mut self, _refund_address: &Address) { + fn suicide(&mut self, _refund_address: &Address) -> trie::Result<()> { unimplemented!(); } diff --git a/rpc/src/v1/helpers/errors.rs b/rpc/src/v1/helpers/errors.rs index 93d23b1aa..7b0891246 100644 --- a/rpc/src/v1/helpers/errors.rs +++ b/rpc/src/v1/helpers/errors.rs @@ -124,6 +124,10 @@ pub fn state_pruned() -> Error { } } +pub fn state_corrupt() -> Error { + internal("State corrupt", "") +} + pub fn exceptional() -> Error { Error { code: ErrorCode::ServerError(codes::EXCEPTION_ERROR), @@ -288,6 +292,7 @@ pub fn from_rlp_error(error: DecoderError) -> Error { pub fn from_call_error(error: CallError) -> Error { match error { CallError::StatePruned => state_pruned(), + CallError::StateCorrupt => state_corrupt(), CallError::Exceptional => exceptional(), CallError::Execution(e) => execution(e), CallError::TransactionNotFound => internal("{}, this should not be the case with eth_call, most likely a bug.", CallError::TransactionNotFound), diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 01627ba28..f47ab2055 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -349,7 +349,13 @@ impl Eth for EthClient where let address = address.into(); let res = match num.0.clone() { - BlockNumber::Pending => Ok(take_weakf!(self.miner).balance(&*take_weakf!(self.client), &address).into()), + BlockNumber::Pending => { + let client = take_weakf!(self.client); + match take_weakf!(self.miner).balance(&*client, &address) { + Some(balance) => Ok(balance.into()), + None => Err(errors::internal("Unable to load balance from database", "")) + } + } id => { let client = take_weakf!(self.client); @@ -369,7 +375,13 @@ impl Eth for EthClient where let position: U256 = RpcU256::into(pos); let res = match num.0.clone() { - BlockNumber::Pending => Ok(take_weakf!(self.miner).storage_at(&*take_weakf!(self.client), &address, &H256::from(position)).into()), + BlockNumber::Pending => { + let client = take_weakf!(self.client); + match take_weakf!(self.miner).storage_at(&*client, &address, &H256::from(position)) { + Some(s) => Ok(s.into()), + None => Err(errors::internal("Unable to load storage from database", "")) + } + } id => { let client = take_weakf!(self.client); @@ -387,7 +399,13 @@ impl Eth for EthClient where fn transaction_count(&self, address: RpcH160, num: Trailing) -> BoxFuture { let address: Address = RpcH160::into(address); let res = match num.0.clone() { - BlockNumber::Pending => Ok(take_weakf!(self.miner).nonce(&*take_weakf!(self.client), &address).into()), + BlockNumber::Pending => { + let client = take_weakf!(self.client); + match take_weakf!(self.miner).nonce(&*client, &address) { + Some(nonce) => Ok(nonce.into()), + None => Err(errors::internal("Unable to load nonce from database", "")) + } + } id => { let client = take_weakf!(self.client); @@ -437,7 +455,13 @@ impl Eth for EthClient where let address: Address = RpcH160::into(address); let res = match num.0.clone() { - BlockNumber::Pending => Ok(take_weakf!(self.miner).code(&*take_weakf!(self.client), &address).map_or_else(Bytes::default, Bytes::new)), + BlockNumber::Pending => { + let client = take_weakf!(self.client); + match take_weakf!(self.miner).code(&*client, &address) { + Some(code) => Ok(code.map_or_else(Bytes::default, Bytes::new)), + None => Err(errors::internal("Unable to load code from database", "")) + } + } id => { let client = take_weakf!(self.client); diff --git a/rpc/src/v1/tests/eth.rs b/rpc/src/v1/tests/eth.rs index 6b937d733..c505a2d5d 100644 --- a/rpc/src/v1/tests/eth.rs +++ b/rpc/src/v1/tests/eth.rs @@ -18,7 +18,6 @@ use std::sync::Arc; use std::time::Duration; -use devtools::RandomTempPath; use ethcore::client::{BlockChainClient, Client, ClientConfig}; use ethcore::ids::BlockId; use ethcore::spec::{Genesis, Spec}; diff --git a/rpc/src/v1/tests/helpers/miner_service.rs b/rpc/src/v1/tests/helpers/miner_service.rs index 75ca928b4..01dd9edc7 100644 --- a/rpc/src/v1/tests/helpers/miner_service.rs +++ b/rpc/src/v1/tests/helpers/miner_service.rs @@ -254,26 +254,39 @@ impl MinerService for TestMinerService { unimplemented!(); } - fn balance(&self, _chain: &MiningBlockChainClient, address: &Address) -> U256 { - self.latest_closed_block.lock().as_ref().map_or_else(U256::zero, |b| b.block().fields().state.balance(address).clone()) + fn balance(&self, _chain: &MiningBlockChainClient, address: &Address) -> Option { + self.latest_closed_block.lock() + .as_ref() + .map(|b| b.block().fields().state.balance(address)) + .map(|b| b.ok()) + .unwrap_or(Some(U256::default())) } fn call(&self, _chain: &MiningBlockChainClient, _t: &SignedTransaction, _analytics: CallAnalytics) -> Result { unimplemented!(); } - fn storage_at(&self, _chain: &MiningBlockChainClient, address: &Address, position: &H256) -> H256 { - self.latest_closed_block.lock().as_ref().map_or_else(H256::default, |b| b.block().fields().state.storage_at(address, position).clone()) + fn storage_at(&self, _chain: &MiningBlockChainClient, address: &Address, position: &H256) -> Option { + self.latest_closed_block.lock() + .as_ref() + .map(|b| b.block().fields().state.storage_at(address, position)) + .map(|s| s.ok()) + .unwrap_or(Some(H256::default())) } - fn nonce(&self, _chain: &MiningBlockChainClient, address: &Address) -> U256 { + fn nonce(&self, _chain: &MiningBlockChainClient, address: &Address) -> Option { // we assume all transactions are in a pending block, ignoring the // reality of gas limits. - self.last_nonce(address).unwrap_or(U256::zero()) + Some(self.last_nonce(address).unwrap_or(U256::zero())) } - fn code(&self, _chain: &MiningBlockChainClient, address: &Address) -> Option { - self.latest_closed_block.lock().as_ref().map_or(None, |b| b.block().fields().state.code(address).map(|c| (*c).clone())) + fn code(&self, _chain: &MiningBlockChainClient, address: &Address) -> Option> { + self.latest_closed_block.lock() + .as_ref() + .map(|b| b.block().fields().state.code(address)) + .map(|c| c.ok()) + .unwrap_or(None) + .map(|c| c.map(|c| (&*c).clone())) } fn sensible_gas_price(&self) -> U256 {