Skip to content

Commit d4f44a7

Browse files
Merge pull request #6194 from raymondliu0711/feature/compare_dataword
feat(tvm): optimize mcopy energy calculation
2 parents e12adb2 + a464aa8 commit d4f44a7

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

actuator/src/main/java/org/tron/core/vm/EnergyCost.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.tron.core.vm;
22

3-
import static org.tron.common.math.Maths.max;
4-
53
import java.math.BigInteger;
64
import org.tron.common.runtime.vm.DataWord;
75
import org.tron.core.vm.config.VMConfig;
@@ -248,9 +246,9 @@ public static long getMCopyCost(Program program) {
248246
Stack stack = program.getStack();
249247
long oldMemSize = program.getMemSize();
250248

251-
int dstOffset = stack.peek().intValue();
252-
int srcOffset = stack.get(stack.size() - 2).intValue();
253-
DataWord maxOffset = new DataWord(max(dstOffset, srcOffset, VMConfig.allowStrictMath2()));
249+
DataWord dstOffset = stack.peek();
250+
DataWord srcOffset = stack.get(stack.size() - 2);
251+
DataWord maxOffset = dstOffset.compareTo(srcOffset) > 0 ? dstOffset : srcOffset;
254252
return VERY_LOW_TIER + calcMemEnergy(oldMemSize,
255253
memNeeded(maxOffset, stack.get(stack.size() - 3)),
256254
stack.get(stack.size() - 3).longValueSafe(), Op.MCOPY);

actuator/src/main/java/org/tron/core/vm/repository/RepositoryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ public byte[] getTransientStorageValue(byte[] address, byte[] key) {
456456
byte[] value;
457457
if (parent != null) {
458458
value = parent.getTransientStorageValue(address, key);
459-
} else{
459+
} else {
460460
value = null;
461461
}
462462

0 commit comments

Comments
 (0)