Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Touched accounts moved to ProgramResult
Browse files Browse the repository at this point in the history
  • Loading branch information
zilm13 committed Dec 12, 2016
1 parent ea856dd commit 0861487
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public void go() {
throw result.getException();
}

touchedAccounts.addAll(program.getTouchedAccounts());
touchedAccounts.addAll(result.getTouchedAccounts());
}

cacheTrack.commit();
Expand Down
4 changes: 2 additions & 2 deletions ethereumj-core/src/main/java/org/ethereum/vm/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ else if (oldValue != null && newValue.isZero()) {
PrecompiledContracts.getContractForAddress(codeAddress);

if (op.equals(CALL)) {
program.touchAccount(codeAddress.getLast20Bytes());
program.getResult().addTouchAccount(codeAddress.getLast20Bytes());
}

if (contract != null) {
Expand Down Expand Up @@ -1192,7 +1192,7 @@ else if (oldValue != null && newValue.isZero()) {
case SUICIDE: {
DataWord address = program.stackPop();
program.suicide(address);
program.touchAccount(address.getLast20Bytes());
program.getResult().addTouchAccount(address.getLast20Bytes());

if (logger.isInfoEnabled())
hint = "address: " + Hex.toHexString(program.getOwnerAddress().getLast20Bytes());
Expand Down
12 changes: 2 additions & 10 deletions ethereumj-core/src/main/java/org/ethereum/vm/program/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@ this, new DataWord(newAddress), getOwnerAddress(), value, gasLimit,
Program program = commonConfig.program(programCode, programInvoke, internalTx);
vm.play(program);
result = program.getResult();
touchedAccounts.addAll(program.getTouchedAccounts());

getResult().merge(result);
}
Expand Down Expand Up @@ -466,6 +465,7 @@ this, new DataWord(newAddress), getOwnerAddress(), value, gasLimit,
if (!byTestingSuite())
track.commit();
getResult().addDeleteAccounts(result.getDeleteAccounts());
getResult().addTouchAccounts(result.getTouchedAccounts());

// IN SUCCESS PUSH THE ADDRESS INTO THE STACK
stackPush(new DataWord(newAddress));
Expand Down Expand Up @@ -554,7 +554,6 @@ this, new DataWord(contextAddress),

getTrace().merge(program.getTrace());
getResult().merge(result);
touchedAccounts.addAll(program.getTouchedAccounts());

if (result.getException() != null) {
logger.debug("contract run halted by Exception: contract: [{}], exception: [{}]",
Expand All @@ -572,6 +571,7 @@ this, new DataWord(contextAddress),
} else if (Arrays.equals(transaction.getReceiveAddress(), internalTx.getReceiveAddress())) {
storageDiffListener.merge(program.getStorageDiff());
}
getResult().addTouchAccounts(result.getTouchedAccounts());
}

// 3. APPLY RESULTS: result.getHReturn() into out_memory allocated
Expand Down Expand Up @@ -870,14 +870,6 @@ public void precompile() {
}
}

public void touchAccount(byte[] addr) {
touchedAccounts.add(addr);
}

public Set<byte[]> getTouchedAccounts() {
return touchedAccounts;
}

static String formatBinData(byte[] binData, int startPC) {
StringBuilder ret = new StringBuilder();
for (int i = 0; i < binData.length; i += 16) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ethereum.vm.program;

import org.ethereum.util.ByteArraySet;
import org.ethereum.vm.CallCreate;
import org.ethereum.vm.DataWord;
import org.ethereum.vm.LogInfo;
Expand All @@ -24,6 +25,7 @@ public class ProgramResult {
private RuntimeException exception;

private Set<DataWord> deleteAccounts;
private ByteArraySet touchedAccounts = new ByteArraySet();
private List<InternalTransaction> internalTransactions;
private List<LogInfo> logInfoList;
private long futureRefund = 0;
Expand Down Expand Up @@ -81,6 +83,20 @@ public void addDeleteAccounts(Set<DataWord> accounts) {
}
}

public void addTouchAccount(byte[] addr) {
touchedAccounts.add(addr);
}

public Set<byte[]> getTouchedAccounts() {
return touchedAccounts;
}

public void addTouchAccounts(Set<byte[]> accounts) {
if (!isEmpty(accounts)) {
getTouchedAccounts().addAll(accounts);
}
}

public List<LogInfo> getLogInfoList() {
if (logInfoList == null) {
logInfoList = new ArrayList<>();
Expand Down

0 comments on commit 0861487

Please sign in to comment.