Gas checks must be made earlier than other checks

This commit is contained in:
Faiz Khan 2015-01-27 16:33:07 -06:00
parent 277ca6af7a
commit 7c4f749835
2 changed files with 19 additions and 22 deletions

View File

@ -100,6 +100,25 @@ public class TransactionExecutor {
return;
}
// GET TOTAL ETHER VALUE AVAILABLE FOR TX FEE
BigInteger gasPrice = new BigInteger(1, tx.getGasPrice());
BigInteger gasDebit = new BigInteger(1, tx.getGasLimit()).multiply(gasPrice);
logger.info("Gas price limited to [{} wei]", gasDebit.toString());
// Debit the actual total gas value from the sender
// the purchased gas will be available for
// the contract in the execution state,
// it can be retrieved using GAS op
BigInteger txValue = new BigInteger(1, tx.getValue());
if (track.getBalance(senderAddress).compareTo(gasDebit.add(txValue)) == -1) {
logger.debug("No gas to start the execution: sender={}",
Hex.toHexString(senderAddress));
receipt.setCumulativeGas(0);
this.receipt = receipt;
return;
}
// FIND OUT THE TRANSACTION TYPE
final byte[] receiverAddress;
final byte[] code;
@ -122,27 +141,6 @@ public class TransactionExecutor {
}
}
// GET TOTAL ETHER VALUE AVAILABLE FOR TX FEE
BigInteger gasPrice = new BigInteger(1, tx.getGasPrice());
BigInteger gasDebit = new BigInteger(1, tx.getGasLimit()).multiply(gasPrice);
logger.info("Gas price limited to [{} wei]", gasDebit.toString());
// Debit the actual total gas value from the sender
// the purchased gas will be available for
// the contract in the execution state,
// it can be retrieved using GAS op
BigInteger txValue = new BigInteger(1, tx.getValue());
if (track.getBalance(senderAddress).compareTo(gasDebit.add(txValue)) == -1) {
logger.debug("No gas to start the execution: sender={}",
Hex.toHexString(senderAddress));
receipt.setCumulativeGas(0);
this.receipt = receipt;
return;
}
// THE SIMPLE VALUE/BALANCE CHANGE
if (track.getBalance(senderAddress).compareTo(txValue) >= 0) {

View File

@ -44,7 +44,6 @@ public class GitHubStateTest {
public void stInitCodeTest() throws ParseException { // [V]
Set<String> excluded = new HashSet<>();
excluded.add("NotEnoughCashContractCreation");
excluded.add("CallContractToCreateContractOOG");
excluded.add("CallContractToCreateContractNoCash");
excluded.add("CallContractToCreateContractWhichWouldCreateContractInInitCode");