Skip to content

feat(tvm): optimize mcopy energy calculation #6194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
8 changes: 3 additions & 5 deletions actuator/src/main/java/org/tron/core/vm/EnergyCost.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.tron.core.vm;

import static org.tron.common.math.Maths.max;

import java.math.BigInteger;
import org.tron.common.runtime.vm.DataWord;
import org.tron.core.vm.config.VMConfig;
Expand Down Expand Up @@ -248,9 +246,9 @@ public static long getMCopyCost(Program program) {
Stack stack = program.getStack();
long oldMemSize = program.getMemSize();

int dstOffset = stack.peek().intValue();
int srcOffset = stack.get(stack.size() - 2).intValue();
DataWord maxOffset = new DataWord(max(dstOffset, srcOffset, VMConfig.allowStrictMath2()));
DataWord dstOffset = stack.peek();
DataWord srcOffset = stack.get(stack.size() - 2);
DataWord maxOffset = dstOffset.compareTo(srcOffset) > 0 ? dstOffset : srcOffset;
return VERY_LOW_TIER + calcMemEnergy(oldMemSize,
memNeeded(maxOffset, stack.get(stack.size() - 3)),
stack.get(stack.size() - 3).longValueSafe(), Op.MCOPY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public byte[] getTransientStorageValue(byte[] address, byte[] key) {
byte[] value;
if (parent != null) {
value = parent.getTransientStorageValue(address, key);
} else{
} else {
value = null;
}

Expand Down