Limiting result of the execution to execution-specific errors (#1071)

* execution error/result limiting

* missing trailing comma

* fix executive tests

* adding original error as string to the generic transaction error

* 'mallformed'-s all around
This commit is contained in:
Nikolay Volf
2016-05-14 15:28:44 +03:00
committed by Gav Wood
parent 2b78e511c9
commit 354ac7d6e5
10 changed files with 35 additions and 24 deletions

View File

@@ -63,7 +63,7 @@ pub use external::{ExternalMiner, ExternalMinerService};
use util::{H256, U256, Address, Bytes};
use ethcore::client::{BlockChainClient, Executed};
use ethcore::block::{ClosedBlock};
use ethcore::error::{Error};
use ethcore::error::{Error, ExecutionError};
use ethcore::transaction::SignedTransaction;
/// Miner client API
@@ -150,7 +150,7 @@ pub trait MinerService : Send + Sync {
fn balance(&self, chain: &BlockChainClient, address: &Address) -> U256;
/// Call into contract code using pending state.
fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, Error>;
fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, ExecutionError>;
/// Get storage value in pending state.
fn storage_at(&self, chain: &BlockChainClient, address: &Address, position: &H256) -> H256;

View File

@@ -240,7 +240,7 @@ impl MinerService for Miner {
}
}
fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, Error> {
fn call(&self, chain: &BlockChainClient, t: &SignedTransaction) -> Result<Executed, ExecutionError> {
let sealing_work = self.sealing_work.lock().unwrap();
match sealing_work.peek_last_ref() {
Some(work) => {
@@ -258,7 +258,10 @@ impl MinerService for Miner {
};
// that's just a copy of the state.
let mut state = block.state().clone();
let sender = try!(t.sender());
let sender = try!(t.sender().map_err(|e| {
let message = format!("Transaction malformed: {:?}", e);
ExecutionError::TransactionMalformed(message)
}));
let balance = state.balance(&sender);
// give the sender max balance
state.sub_balance(&sender, &balance);