2 Bugs:
+ VM CODECOPY wrong param + Apply tx run results - different when init code and body code
This commit is contained in:
parent
feebfdbe72
commit
287684aa62
|
@ -173,7 +173,6 @@ public class WorldManager {
|
||||||
if (tx.getValue() != null) {
|
if (tx.getValue() != null) {
|
||||||
|
|
||||||
BigInteger senderBalance = repository.getBalance(senderAddress);
|
BigInteger senderBalance = repository.getBalance(senderAddress);
|
||||||
BigInteger contractBalance = repository.getBalance(contractAddress);
|
|
||||||
|
|
||||||
if (senderBalance.compareTo(new BigInteger(1, tx.getValue())) >= 0) {
|
if (senderBalance.compareTo(new BigInteger(1, tx.getValue())) >= 0) {
|
||||||
|
|
||||||
|
@ -210,7 +209,7 @@ public class WorldManager {
|
||||||
vm.play(program);
|
vm.play(program);
|
||||||
ProgramResult result = program.getResult();
|
ProgramResult result = program.getResult();
|
||||||
applyProgramResult(result, gasDebit, trackRepository,
|
applyProgramResult(result, gasDebit, trackRepository,
|
||||||
senderAddress, tx.getContractAddress(), coinbase);
|
senderAddress, tx.getContractAddress(), coinbase, true);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -231,7 +230,7 @@ public class WorldManager {
|
||||||
vm.play(program);
|
vm.play(program);
|
||||||
ProgramResult result = program.getResult();
|
ProgramResult result = program.getResult();
|
||||||
applyProgramResult(result, gasDebit, trackRepository,
|
applyProgramResult(result, gasDebit, trackRepository,
|
||||||
senderAddress, tx.getReceiveAddress(), coinbase);
|
senderAddress, tx.getReceiveAddress(), coinbase,false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
@ -253,7 +252,7 @@ public class WorldManager {
|
||||||
*/
|
*/
|
||||||
private void applyProgramResult(ProgramResult result, BigInteger gasDebit,
|
private void applyProgramResult(ProgramResult result, BigInteger gasDebit,
|
||||||
Repository repository, byte[] senderAddress,
|
Repository repository, byte[] senderAddress,
|
||||||
byte[] contractAddress, byte[] coinbase) {
|
byte[] contractAddress, byte[] coinbase, boolean initResults) {
|
||||||
|
|
||||||
if (result.getException() != null
|
if (result.getException() != null
|
||||||
&& result.getException() instanceof Program.OutOfGasException) {
|
&& result.getException() instanceof Program.OutOfGasException) {
|
||||||
|
@ -263,11 +262,6 @@ public class WorldManager {
|
||||||
throw result.getException();
|
throw result.getException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the code created by init
|
|
||||||
byte[] bodyCode = null;
|
|
||||||
if (result.getHReturn() != null) {
|
|
||||||
bodyCode = result.getHReturn().array();
|
|
||||||
}
|
|
||||||
|
|
||||||
BigInteger gasPrice = BigInteger.valueOf(blockchain.getGasPrice());
|
BigInteger gasPrice = BigInteger.valueOf(blockchain.getGasPrice());
|
||||||
BigInteger refund = gasDebit.subtract(BigInteger.valueOf(
|
BigInteger refund = gasDebit.subtract(BigInteger.valueOf(
|
||||||
|
@ -285,6 +279,15 @@ public class WorldManager {
|
||||||
repository.addBalance(coinbase, refund.negate());
|
repository.addBalance(coinbase, refund.negate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (initResults){
|
||||||
|
|
||||||
|
// Save the code created by init
|
||||||
|
byte[] bodyCode = null;
|
||||||
|
if (result.getHReturn() != null) {
|
||||||
|
bodyCode = result.getHReturn().array();
|
||||||
|
}
|
||||||
|
|
||||||
if (bodyCode != null) {
|
if (bodyCode != null) {
|
||||||
repository.saveCode(contractAddress, bodyCode);
|
repository.saveCode(contractAddress, bodyCode);
|
||||||
if (stateLogger.isInfoEnabled())
|
if (stateLogger.isInfoEnabled())
|
||||||
|
@ -294,6 +297,7 @@ public class WorldManager {
|
||||||
Hex.toHexString(bodyCode));
|
Hex.toHexString(bodyCode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void applyBlock(Block block) {
|
public void applyBlock(Block block) {
|
||||||
|
|
||||||
|
|
|
@ -349,7 +349,6 @@ public class VM {
|
||||||
|
|
||||||
int length = lengthData.value().intValue();
|
int length = lengthData.value().intValue();
|
||||||
int codeOffset = codeOffsetData.value().intValue();
|
int codeOffset = codeOffsetData.value().intValue();
|
||||||
int memOffset = memOffsetData.value().intValue();
|
|
||||||
|
|
||||||
if (program.ops.length < length + codeOffset) {
|
if (program.ops.length < length + codeOffset) {
|
||||||
program.stop();
|
program.stop();
|
||||||
|
@ -357,7 +356,7 @@ public class VM {
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] code = new byte[length];
|
byte[] code = new byte[length];
|
||||||
System.arraycopy(program.ops, codeOffset, code, memOffset, length);
|
System.arraycopy(program.ops, codeOffset, code, 0, length);
|
||||||
|
|
||||||
program.memorySave(memOffsetData.getData(), code);
|
program.memorySave(memOffsetData.getData(), code);
|
||||||
program.step();
|
program.step();
|
||||||
|
|
Loading…
Reference in New Issue