From 4153052148b81fb8a07b3a8f8fb0d22b2e8336d5 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 5 Jun 2016 17:23:27 +0200 Subject: [PATCH] Fix fn call in miner.rs same as client.rs. --- ethcore/src/client/client.rs | 1 + ethcore/src/miner/miner.rs | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 6f0e5b874..97f8dd5a4 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -463,6 +463,7 @@ impl BlockChainClient for Client where V: Verifier { } let options = TransactOptions { tracing: false, vm_tracing: analytics.vm_tracing, check_nonce: false }; let mut ret = Executive::new(&mut state, &env_info, self.engine.deref().deref(), &self.vm_factory).transact(t, options); + // TODO gav move this into Executive. if analytics.state_diffing { if let Ok(ref mut x) = ret { diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 18a253ea9..5dc3864c3 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -255,6 +255,8 @@ impl MinerService for Miner { match sealing_work.peek_last_ref() { Some(work) => { let block = work.block(); + + // TODO: merge this code with client.rs's fn call somwhow. let header = block.header(); let last_hashes = chain.last_hashes(); let env_info = EnvInfo { @@ -273,12 +275,14 @@ impl MinerService for Miner { ExecutionError::TransactionMalformed(message) })); let balance = state.balance(&sender); - // give the sender max balance - state.sub_balance(&sender, &balance); - state.add_balance(&sender, &U256::max_value()); + let needed_balance = t.value + t.gas * t.gas_price; + if balance < needed_balance { + // give the sender a sufficient balance + state.add_balance(&sender, &(needed_balance - balance)); + } let options = TransactOptions { tracing: false, vm_tracing: analytics.vm_tracing, check_nonce: false }; - let mut ret = Executive::new(&mut state, &env_info, self.engine(), chain.vm_factory()).transact(t, options); + // TODO gav move this into Executive. if analytics.state_diffing { if let Ok(ref mut x) = ret {