Skip to content

Commit

Permalink
Fixing EthCallPlan to add gasLimit to the request
Browse files Browse the repository at this point in the history
  • Loading branch information
fmacleal committed Feb 18, 2024
1 parent 7edbf4c commit 5e5ce38
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package co.rsk.jmh.web3;

import co.rsk.jmh.web3.plan.LocaWalletlPlan;
import co.rsk.jmh.web3.plan.LocalWalletPlan;
import co.rsk.jmh.web3.plan.TransactionPlan;
import org.openjdk.jmh.annotations.*;
import org.web3j.protocol.core.methods.request.Transaction;
Expand Down Expand Up @@ -57,7 +57,7 @@ public void ethSendTransaction_ContractCall(TransactionPlan plan) throws Benchma
}

@Benchmark
public void ethSign(LocaWalletlPlan plan) throws BenchmarkWeb3Exception {
public void ethSign(LocalWalletPlan plan) throws BenchmarkWeb3Exception {
String address = plan.getEthSignAddress();
String message = plan.getEthSignMessage();
plan.getWeb3Connector().ethSign(address, message);
Expand Down
30 changes: 7 additions & 23 deletions rskj-core/src/jmh/java/co/rsk/jmh/web3/plan/EthCallPlan.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@

package co.rsk.jmh.web3.plan;

import co.rsk.jmh.helpers.BenchmarkHelper;
import co.rsk.jmh.web3.BenchmarkWeb3Exception;
import co.rsk.jmh.web3.e2e.RskModuleWeb3j;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.infra.BenchmarkParams;
import org.web3j.protocol.core.methods.response.Transaction;

import java.math.BigInteger;

Expand All @@ -44,29 +41,16 @@ public void setUp(BenchmarkParams params) throws BenchmarkWeb3Exception {
ethCallArguments = buildEthCallArguments();
}

private Transaction setupTransaction() {
Transaction tx = new Transaction();

tx.setFrom(configuration.getString("eth_call.transaction.from"));
tx.setTo(configuration.getString("eth_call.transaction.to"));
tx.setGas(configuration.getString("eth_call.transaction.gas"));
tx.setGasPrice(configuration.getString("eth_call.transaction.gasPrice"));
tx.setValue(configuration.getString("eth_call.transaction.value"));
tx.setInput(configuration.getString("eth_call.transaction.input"));

return tx;
}

private RskModuleWeb3j.EthCallArguments buildEthCallArguments() {
RskModuleWeb3j.EthCallArguments args = new RskModuleWeb3j.EthCallArguments();
Transaction tx = setupTransaction();

args.setFrom(tx.getFrom());
args.setTo(tx.getTo());
args.setGas("0x" + tx.getGas().toString(16));
args.setGasPrice("0x" + tx.getGasPrice().toString(16));
args.setValue("0x" + tx.getValue().toString(16));
args.setData(tx.getInput());
args.setFrom(configuration.getString("eth_call.transaction.from"));
args.setTo(configuration.getString("eth_call.transaction.to"));
args.setGas(configuration.getString("eth_call.transaction.gas"));
args.setGasPrice(configuration.getString("eth_call.transaction.gasPrice"));
args.setGasLimit(configuration.getString("eth_call.transaction.gasLimit"));
args.setValue(configuration.getString("eth_call.transaction.value"));
args.setData(configuration.getString("eth_call.transaction.input"));

return args;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.openjdk.jmh.infra.BenchmarkParams;

@State(Scope.Benchmark)
public class LocaWalletlPlan extends BasePlan{
public class LocalWalletPlan extends BasePlan{

public static final String ETH_SIGN_ADDRESS = "ethSign.address";
public static final String ETH_SIGN_MESSAGE = "ethSign.message";
Expand Down
1 change: 1 addition & 0 deletions rskj-core/src/jmh/resources/conf/testnet-3_860_000.conf
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ eth_call.transaction.from=0x4a727d7943b563462c96d40689836600d20b983b
eth_call.transaction.to=0x19f64674d8a5b4e652319f5e239efd3bc969a1fe
eth_call.transaction.gas=0x13069
eth_call.transaction.gasPrice=0x3e252e0
eth_call.transaction.gasLimit=0x4e252e0
eth_call.transaction.value=0x0
eth_call.transaction.input=0xa9059cbb000000000000000000000000318bb57758207dc202bb78748e39eec8f269c6e10000000000000000000000000000000000000000000000056bc75e2d63100000

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
class DataSourceWithCacheProfilingMemoryTest {

private static final Logger logger = LoggerFactory.getLogger(DataSourceWithCacheProfilingMemoryTest.class);
private static final int TOTAL_CACHE_SIZE = 4000000;
private static final int MAX_TOTAL_SIZE_DATA_BYTES = 400;
private static final int TOTAL_CACHE_SIZE = 1000000;
private static final int SIZE_DATA = 32;
private static final int COUNTER_TO_PRINT_LOG = 1000000;
private HashMapDB baseDataSource = new HashMapDB();
private DataSourceWithCache dataSourceWithCache = new DataSourceWithCache(baseDataSource, TOTAL_CACHE_SIZE);
private final HashMapDB baseDataSource = new HashMapDB();
private final DataSourceWithCache dataSourceWithCache = new DataSourceWithCache(baseDataSource, TOTAL_CACHE_SIZE);

// @Test //Let's run only locally if we need to check
@Test //Let's run only locally if we need to check
void givenASpecificAmountOfEntries_weWillCreateEnoughRandomData_thenWeWillProfileTheHeapdump() {

logger.info("Starting the profile from DataSourceWithCache for a total cache of {}", TOTAL_CACHE_SIZE);

logger.info("Adding {} entries to the cache", TOTAL_CACHE_SIZE);

Map<ByteArrayWrapper, byte[]> currentEntries = generateRandomValuesToUpdate(TOTAL_CACHE_SIZE);
Map<ByteArrayWrapper, byte[]> currentEntries = generateRandomValuesToUpdate();
dataSourceWithCache.updateBatch(currentEntries, Collections.emptySet());

logger.info("The cache has now {} entries", dataSourceWithCache.keys().size());
Expand All @@ -44,7 +44,7 @@ void givenASpecificAmountOfEntries_weWillCreateEnoughRandomData_thenWeWillProfil
int counterToPrint = 0;
while(true) {
int selectedIndex = random.nextInt(datasourceKeySet.size());
int randomDataSize = random.nextInt(MAX_TOTAL_SIZE_DATA_BYTES);
int randomDataSize = random.nextInt(SIZE_DATA);

dataSourceWithCache.put(datasourceKeySet.get(selectedIndex), TestUtils.generateBytesFromRandom(random, randomDataSize));
if(counterToPrint == COUNTER_TO_PRINT_LOG){
Expand All @@ -56,11 +56,11 @@ void givenASpecificAmountOfEntries_weWillCreateEnoughRandomData_thenWeWillProfil
}
}

private Map<ByteArrayWrapper, byte[]> generateRandomValuesToUpdate(int maxValuesToCreate) {
private Map<ByteArrayWrapper, byte[]> generateRandomValuesToUpdate() {
Map<ByteArrayWrapper, byte[]> updatedValues = new HashMap<>();
Random random = new Random(DataSourceWithCacheProfilingMemoryTest.class.hashCode());
for (int i = 0; i < maxValuesToCreate; i++) {
Integer randomDataSize = random.nextInt(MAX_TOTAL_SIZE_DATA_BYTES);
for (int i = 0; i < TOTAL_CACHE_SIZE; i++) {
int randomDataSize = random.nextInt(SIZE_DATA);
updatedValues.put(ByteUtil.wrap(TestUtils.generateBytesFromRandom(random, HASH_LEN)), TestUtils.generateBytesFromRandom(random, randomDataSize));
}
return updatedValues;
Expand Down

0 comments on commit 5e5ce38

Please sign in to comment.