Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion actuator/src/main/java/org/tron/core/actuator/VMActuator.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.tron.core.vm.program.ProgramPrecompile;
import org.tron.core.vm.program.invoke.ProgramInvoke;
import org.tron.core.vm.program.invoke.ProgramInvokeFactory;
import org.tron.core.vm.program.listener.SimulationTracer;
import org.tron.core.vm.repository.Repository;
import org.tron.core.vm.repository.RepositoryImpl;
import org.tron.core.vm.utils.MUtil;
Expand Down Expand Up @@ -95,6 +96,12 @@ public class VMActuator implements Actuator2 {
@Setter
private boolean enableEventListener;

@Setter
private Repository injectedRootRepository;

@Setter
private SimulationTracer simulationTracer;

private LogInfoTriggerParser logInfoTriggerParser;

public VMActuator(boolean isConstantCall) {
Expand Down Expand Up @@ -138,7 +145,9 @@ public void validate(Object object) throws ContractValidateException {
//Route Type
ContractType contractType = this.trx.getRawData().getContract(0).getType();
//Prepare Repository
rootRepository = RepositoryImpl.createRoot(context.getStoreFactory());
rootRepository = injectedRootRepository != null
? injectedRootRepository
: RepositoryImpl.createRoot(context.getStoreFactory());

enableEventListener = context.isEventPluginLoaded();

Expand Down Expand Up @@ -414,6 +423,7 @@ private void create()
if (VMConfig.allowTvmCompatibleEvm()) {
this.program.setContractVersion(1);
}
this.program.setSimulationTracer(simulationTracer);
byte[] txId = TransactionUtil.getTransactionId(trx).getBytes();
this.program.setRootTransactionId(txId);
if (enableEventListener && isCheckTransaction()) {
Expand All @@ -437,10 +447,18 @@ private void create()
// transfer from callerAddress to contractAddress according to callValue
if (callValue > 0) {
MUtil.transfer(rootRepository, callerAddress, contractAddress, callValue);
if (simulationTracer != null) {
simulationTracer.onTransfer(stripTronPrefix(callerAddress),
stripTronPrefix(contractAddress), callValue);
}
}
if (VMConfig.allowTvmTransferTrc10() && tokenValue > 0) {
MUtil.transferToken(rootRepository, callerAddress, contractAddress, String.valueOf(tokenId),
tokenValue);
if (simulationTracer != null) {
simulationTracer.onTokenTransfer(stripTronPrefix(callerAddress),
stripTronPrefix(contractAddress), tokenId, tokenValue);
}
}

}
Expand Down Expand Up @@ -529,6 +547,7 @@ private void call()
if (VMConfig.allowTvmCompatibleEvm()) {
this.program.setContractVersion(deployedContract.getContractVersion());
}
this.program.setSimulationTracer(simulationTracer);
byte[] txId = TransactionUtil.getTransactionId(trx).getBytes();
this.program.setRootTransactionId(txId);

Expand All @@ -543,14 +562,31 @@ private void call()

if (callValue > 0) {
MUtil.transfer(rootRepository, callerAddress, contractAddress, callValue);
if (simulationTracer != null) {
simulationTracer.onTransfer(stripTronPrefix(callerAddress),
stripTronPrefix(contractAddress), callValue);
}
}
if (VMConfig.allowTvmTransferTrc10() && tokenValue > 0) {
MUtil.transferToken(rootRepository, callerAddress, contractAddress, String.valueOf(tokenId),
tokenValue);
if (simulationTracer != null) {
simulationTracer.onTokenTransfer(stripTronPrefix(callerAddress),
stripTronPrefix(contractAddress), tokenId, tokenValue);
}
}

}

private static byte[] stripTronPrefix(byte[] tronAddress) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[SHOULD] stripTronPrefix duplicated in VMActuator and Program

The 7-line private static byte[] stripTronPrefix(byte[]) here at VMActuator.java:581 is bit-for-bit identical to the one in Program.java around line 525. Two private statics that drift independently are a maintenance hazard; if Tron ever adds an alternate address encoding (e.g. multichain prefix), both copies need to be hunted down. Address-prefix handling is core protocol behavior — it should live in one place.

Suggestion: Move to MUtil (or a small new AddressUtil) and call from both sites.

if (tronAddress == null || tronAddress.length != 21) {
return tronAddress;
}
byte[] evm = new byte[20];
System.arraycopy(tronAddress, 1, evm, 0, 20);
return evm;
}

public long getAccountEnergyLimitWithFixRatio(AccountCapsule account, long feeLimit,
long callValue) {

Expand Down
3 changes: 3 additions & 0 deletions actuator/src/main/java/org/tron/core/vm/OperationActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,9 @@ public static void logAction(Program program) {
new LogInfo(address.getLast20Bytes(), topics, data);

program.getResult().addLogInfo(logInfo);
if (program.getSimulationTracer() != null) {
program.getSimulationTracer().onLog(logInfo);
}
program.step();
}

Expand Down
Loading
Loading