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

@@ -424,7 +424,7 @@ impl<V> Client<V> where V: Verifier {
}
impl<V> BlockChainClient for Client<V> where V: Verifier {
fn call(&self, t: &SignedTransaction) -> Result<Executed, Error> {
fn call(&self, t: &SignedTransaction) -> Result<Executed, ExecutionError> {
let header = self.block_header(BlockId::Latest).unwrap();
let view = HeaderView::new(&header);
let last_hashes = self.build_last_hashes(view.hash());
@@ -439,7 +439,10 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
};
// that's just a copy of the state.
let mut state = self.state();
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);

View File

@@ -42,7 +42,7 @@ use header::{BlockNumber, Header};
use transaction::{LocalizedTransaction, SignedTransaction};
use log_entry::LocalizedLogEntry;
use filter::Filter;
use error::{ImportResult, Error};
use error::{ImportResult, ExecutionError};
use receipt::LocalizedReceipt;
use engine::{Engine};
use trace::LocalizedTrace;
@@ -133,7 +133,7 @@ pub trait BlockChainClient : Sync + Send {
fn try_seal(&self, block: LockedBlock, seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock>;
/// Makes a non-persistent transaction call.
fn call(&self, t: &SignedTransaction) -> Result<Executed, Error>;
fn call(&self, t: &SignedTransaction) -> Result<Executed, ExecutionError>;
/// Attempt to seal the block internally. See `Engine`.
fn generate_seal(&self, block: &ExecutedBlock, accounts: Option<&AccountProvider>) -> Option<Vec<Bytes>> { self.engine().generate_seal(block, accounts) }

View File

@@ -31,7 +31,7 @@ use error::{ImportResult};
use block_queue::BlockQueueInfo;
use block::{SealedBlock, ClosedBlock, LockedBlock};
use executive::Executed;
use error::Error;
use error::{ExecutionError};
use engine::Engine;
use trace::LocalizedTrace;
@@ -221,7 +221,7 @@ impl TestBlockChainClient {
}
impl BlockChainClient for TestBlockChainClient {
fn call(&self, _t: &SignedTransaction) -> Result<Executed, Error> {
fn call(&self, _t: &SignedTransaction) -> Result<Executed, ExecutionError> {
Ok(self.execution_result.read().unwrap().clone().unwrap())
}