Skip to content

Commit

Permalink
Merge branch 'master' into snap-v4-final
Browse files Browse the repository at this point in the history
  • Loading branch information
Vovchyk authored Mar 8, 2024
2 parents 40a23f6 + 71b5f5b commit 811f7ca
Show file tree
Hide file tree
Showing 162 changed files with 10,144 additions and 4,774 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ ENV RSKJ_SYS_PROPS="-Drpc.providers.web.http.bind_address=0.0.0.0 -Drpc.provider
ENV RSKJ_CLASS=co.rsk.Start
ENV RSKJ_OPTS=""

ENTRYPOINT ["/bin/sh", "-c", "java $DEFAULT_JVM_OPTS $RSKJ_SYS_PROPS -cp rsk.jar $RSKJ_CLASS $RSKJ_OPTS \"${@}\"", "--"]
ENTRYPOINT ["/bin/sh", "-c", "exec java $DEFAULT_JVM_OPTS $RSKJ_SYS_PROPS -cp rsk.jar $RSKJ_CLASS $RSKJ_OPTS \"${@}\"", "--"]

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
2 changes: 1 addition & 1 deletion rskj-core/src/jmh/java/co/rsk/jmh/web3/BenchmarkWeb3.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void traceFilterBetweenBlockRange(TracePlan plan) throws BenchmarkWeb3Exc
}

@Benchmark
@Timeout(time = 60)
@Timeout(time = 100)
public void traceFilterBetweenAddresses(TracePlan plan) throws BenchmarkWeb3Exception {
plan.getWeb3Connector().traceFilter(plan.getFromBlock(), plan.getToBlock(), plan.getFromAddresses(), plan.getToAddresses());
}
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.setGasLimit(configuration.getString("eth_call.gasLimit"));
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.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 @@ -69,6 +69,7 @@ trace.fromAddresses=0x0000000000000000000000000000000000000000
############################
# eth_call
############################
eth_call.gasLimit=0x4e252e0
eth_call.transaction.blockNumber=0x362193
eth_call.transaction.from=0x4a727d7943b563462c96d40689836600d20b983b
eth_call.transaction.to=0x19f64674d8a5b4e652319f5e239efd3bc969a1fe
Expand Down
14 changes: 10 additions & 4 deletions rskj-core/src/main/java/co/rsk/RskContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
import org.ethereum.facade.Ethereum;
import org.ethereum.facade.EthereumImpl;
import org.ethereum.listener.CompositeEthereumListener;
import org.ethereum.listener.GasPriceCalculator;
import org.ethereum.listener.GasPriceTracker;
import org.ethereum.net.EthereumChannelInitializerFactory;
import org.ethereum.net.NodeManager;
Expand Down Expand Up @@ -556,8 +557,11 @@ public synchronized Ethereum getRsk() {
public GasPriceTracker getGasPriceTracker() {
checkIfNotClosed();

double gasPriceMultiplier = getRskSystemProperties().gasPriceMultiplier();

if (this.gasPriceTracker == null) {
this.gasPriceTracker = GasPriceTracker.create(getBlockStore());
GasPriceCalculator.GasCalculatorType calculatorType = getRskSystemProperties().getGasCalculatorType();
this.gasPriceTracker = GasPriceTracker.create(getBlockStore(), gasPriceMultiplier, calculatorType);
}
return this.gasPriceTracker;
}
Expand Down Expand Up @@ -1593,17 +1597,19 @@ protected PeerExplorer getPeerExplorer() {
initialBootNodes.add(address.getHostName() + ":" + address.getPort());
}
}
int bucketSize = rskSystemProperties.discoveryBucketSize();
peerExplorer = new PeerExplorer(
initialBootNodes,
localNode,
new NodeDistanceTable(KademliaOptions.BINS, KademliaOptions.BUCKET_SIZE, localNode),
new NodeDistanceTable(KademliaOptions.BINS, bucketSize, localNode),
key,
rskSystemProperties.peerDiscoveryMessageTimeOut(),
rskSystemProperties.peerDiscoveryRefreshPeriod(),
rskSystemProperties.peerDiscoveryCleanPeriod(),
rskSystemProperties.networkId(),
getPeerScoringManager(),
rskSystemProperties.allowMultipleConnectionsPerHostPort()
rskSystemProperties.allowMultipleConnectionsPerHostPort(),
rskSystemProperties.peerDiscoveryMaxBootRetries()
);
}

Expand Down Expand Up @@ -1868,7 +1874,7 @@ private EthModuleWallet getEthModuleWallet() {
if (wallet == null) {
ethModuleWallet = new EthModuleWalletDisabled();
} else {
ethModuleWallet = new EthModuleWalletEnabled(wallet);
ethModuleWallet = new EthModuleWalletEnabled(wallet, getTransactionPool(), getReceivedTxSignatureCache());
}
}

Expand Down
2 changes: 1 addition & 1 deletion rskj-core/src/main/java/co/rsk/config/BridgeConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import co.rsk.bitcoinj.core.Coin;
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.peg.AddressBasedAuthorizer;
import co.rsk.peg.Federation;
import co.rsk.peg.federation.Federation;
import java.util.List;

import org.ethereum.config.blockchain.upgrades.ActivationConfig;
Expand Down
13 changes: 5 additions & 8 deletions rskj-core/src/main/java/co/rsk/config/BridgeDevNetConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import co.rsk.bitcoinj.core.Coin;
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.peg.AddressBasedAuthorizer;
import co.rsk.peg.FederationMember;
import co.rsk.peg.StandardMultisigFederation;
import co.rsk.peg.federation.FederationArgs;
import co.rsk.peg.federation.FederationMember;
import co.rsk.peg.federation.FederationFactory;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -57,12 +58,8 @@ public BridgeDevNetConstants(List<BtcECKey> federationPublicKeys) {

// Expected federation address is:
// 2NCEo1RdmGDj6MqiipD6DUSerSxKv79FNWX
genesisFederation = new StandardMultisigFederation(
federationMembers,
genesisFederationAddressCreatedAt,
1L,
getBtcParams()
);
FederationArgs federationArgs = new FederationArgs(federationMembers, genesisFederationAddressCreatedAt, 1L, getBtcParams());
genesisFederation = FederationFactory.buildStandardMultiSigFederation(federationArgs);

btc2RskMinimumAcceptableConfirmations = 1;
btc2RskMinimumAcceptableConfirmationsOnRsk = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import co.rsk.bitcoinj.core.Coin;
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.peg.AddressBasedAuthorizer;
import co.rsk.peg.FederationMember;
import co.rsk.peg.StandardMultisigFederation;
import co.rsk.peg.federation.FederationArgs;
import co.rsk.peg.federation.FederationMember;
import co.rsk.peg.federation.FederationFactory;
import com.google.common.collect.Lists;
import java.time.Instant;
import java.util.Arrays;
Expand Down Expand Up @@ -52,12 +53,8 @@ public class BridgeMainNetConstants extends BridgeConstants {
// Wednesday, January 3, 2018 12:00:00 AM GMT-03:00
Instant genesisFederationAddressCreatedAt = Instant.ofEpochMilli(1514948400L);

genesisFederation = new StandardMultisigFederation(
federationMembers,
genesisFederationAddressCreatedAt,
1L,
getBtcParams()
);
FederationArgs federationArgs = new FederationArgs(federationMembers, genesisFederationAddressCreatedAt, 1L, getBtcParams());
genesisFederation = FederationFactory.buildStandardMultiSigFederation(federationArgs);

btc2RskMinimumAcceptableConfirmations = 100;
btc2RskMinimumAcceptableConfirmationsOnRsk = 1000;
Expand Down Expand Up @@ -151,7 +148,7 @@ public class BridgeMainNetConstants extends BridgeConstants {

numberOfBlocksBetweenPegouts = 360; // 3 hours of RSK blocks (considering 1 block every 30 seconds)

btcHeightWhenPegoutTxIndexActivates = 100; // TODO: TBD and change current mock value. This is an estimation of the btc block number once RSKIP379 is activated.
btcHeightWhenPegoutTxIndexActivates = 837_589; // Estimated date Wed, 03 Apr 2024 15:00:00 GMT. 832,430 was the block number at time of calculation
pegoutTxIndexGracePeriodInBtcBlocks = 4_320; // 30 days in BTC blocks (considering 1 block every 10 minutes)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import co.rsk.bitcoinj.core.Coin;
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.peg.AddressBasedAuthorizer;
import co.rsk.peg.FederationMember;
import co.rsk.peg.StandardMultisigFederation;
import co.rsk.peg.federation.FederationArgs;
import co.rsk.peg.federation.FederationMember;
import co.rsk.peg.federation.FederationFactory;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.ZonedDateTime;
Expand Down Expand Up @@ -55,12 +56,8 @@ public BridgeRegTestConstants(List<BtcECKey> federationPublicKeys) {

Instant genesisFederationCreatedAt = ZonedDateTime.parse("2016-01-01T00:00:00Z").toInstant();

genesisFederation = new StandardMultisigFederation(
federationMembers,
genesisFederationCreatedAt,
1L,
getBtcParams()
);
FederationArgs federationArgs = new FederationArgs(federationMembers, genesisFederationCreatedAt, 1L, getBtcParams());
genesisFederation = FederationFactory.buildStandardMultiSigFederation(federationArgs);

btc2RskMinimumAcceptableConfirmations = 3;
btc2RskMinimumAcceptableConfirmationsOnRsk = 5;
Expand Down
17 changes: 7 additions & 10 deletions rskj-core/src/main/java/co/rsk/config/BridgeTestNetConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import co.rsk.bitcoinj.core.Coin;
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.peg.AddressBasedAuthorizer;
import co.rsk.peg.FederationMember;
import co.rsk.peg.StandardMultisigFederation;
import co.rsk.peg.federation.FederationArgs;
import co.rsk.peg.federation.FederationMember;
import co.rsk.peg.federation.FederationFactory;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -65,12 +66,8 @@ public class BridgeTestNetConstants extends BridgeConstants {
// Currently set to: Monday, October 8, 2018 12:00:00 AM GMT-03:00
Instant genesisFederationAddressCreatedAt = Instant.ofEpochMilli(1538967600l);

genesisFederation = new StandardMultisigFederation(
federationMembers,
genesisFederationAddressCreatedAt,
1L,
getBtcParams()
);
FederationArgs federationArgs = new FederationArgs(federationMembers, genesisFederationAddressCreatedAt, 1L, getBtcParams());
genesisFederation = FederationFactory.buildStandardMultiSigFederation(federationArgs);

btc2RskMinimumAcceptableConfirmations = 10;
btc2RskMinimumAcceptableConfirmationsOnRsk = 10;
Expand Down Expand Up @@ -169,8 +166,8 @@ public class BridgeTestNetConstants extends BridgeConstants {

numberOfBlocksBetweenPegouts = 360; // 3 hours of RSK blocks (considering 1 block every 30 seconds)

btcHeightWhenPegoutTxIndexActivates = 150; // TODO: TBD and change current mock value. This is an estimation of the btc block number once RSKIP379 is activated.
pegoutTxIndexGracePeriodInBtcBlocks = 4_320; // 30 days in BTC blocks (considering 1 block every 10 minutes)
btcHeightWhenPegoutTxIndexActivates = 2_589_553; // Estimated date Wed, 20 Mar 2024 15:00:00 GMT. 2,579,823 was the block number at time of calculation
pegoutTxIndexGracePeriodInBtcBlocks = 1_440; // 10 days in BTC blocks (considering 1 block every 10 minutes)
}

public static BridgeTestNetConstants getInstance() {
Expand Down
39 changes: 39 additions & 0 deletions rskj-core/src/main/java/co/rsk/config/RskSystemProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package co.rsk.config;

import co.rsk.core.RskAddress;
import co.rsk.net.discovery.table.KademliaOptions;
import co.rsk.rpc.ModuleDescription;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigObject;
Expand All @@ -29,6 +30,7 @@
import org.ethereum.core.Account;
import org.ethereum.crypto.ECKey;
import org.ethereum.crypto.HashUtil;
import org.ethereum.listener.GasPriceCalculator;

import javax.annotation.Nullable;
import java.nio.charset.StandardCharsets;
Expand All @@ -46,6 +48,9 @@ public class RskSystemProperties extends SystemProperties {
private static final int PD_DEFAULT_CLEAN_PERIOD = 15000; //miliseconds
private static final int PD_DEFAULT_TIMEOUT_MESSAGE = PD_DEFAULT_CLEAN_PERIOD - 1; //miliseconds
private static final int PD_DEFAULT_REFRESH_PERIOD = 60000; //miliseconds
private static final int PD_DEFAULT_MAX_BOOTSTRAP_RETRIES = -1;

private static final String PD_MAX_BOOTSTRAP_RETRIES_CONFIG = "peer.discovery.maxBootRetries";

private static final String REGTEST_BLOCKCHAIN_CONFIG = "regtest";

Expand All @@ -54,6 +59,10 @@ public class RskSystemProperties extends SystemProperties {
private static final String RPC_MODULES_PATH = "rpc.modules";
private static final String RPC_ETH_GET_LOGS_MAX_BLOCKS_TO_QUERY = "rpc.logs.maxBlocksToQuery";
private static final String RPC_ETH_GET_LOGS_MAX_LOGS_TO_RETURN = "rpc.logs.maxLogsToReturn";
public static final String TX_GAS_PRICE_CALCULATOR_TYPE = "transaction.gasPriceCalculatorType";

private static final String RPC_GAS_PRICE_MULTIPLIER_CONFIG = "rpc.gasPriceMultiplier";
private static final String DISCOVERY_BUCKET_SIZE = "peer.discovery.bucketSize";

private static final int CHUNK_SIZE = 192;

Expand Down Expand Up @@ -185,6 +194,16 @@ public boolean isWalletEnabled() {
return getBoolean("wallet.enabled", false);
}

public double gasPriceMultiplier() {
double gasPriceMultiplier = getDouble(RPC_GAS_PRICE_MULTIPLIER_CONFIG, 1.1);

if(gasPriceMultiplier >= 0) {
return gasPriceMultiplier;
} else {
throw new RskConfigurationException(RPC_GAS_PRICE_MULTIPLIER_CONFIG + " cannot be a negative number");
}
}

public List<WalletAccount> walletAccounts() {
if (!configFromFiles.hasPath("wallet.accounts")) {
return Collections.emptyList();
Expand Down Expand Up @@ -249,6 +268,14 @@ public boolean allowMultipleConnectionsPerHostPort() {
return getBoolean("peer.discovery.allowMultipleConnectionsPerHostPort", true);
}

public long peerDiscoveryMaxBootRetries() {
return getLong(PD_MAX_BOOTSTRAP_RETRIES_CONFIG, PD_DEFAULT_MAX_BOOTSTRAP_RETRIES);
}

public int discoveryBucketSize() {
return getInt(DISCOVERY_BUCKET_SIZE, KademliaOptions.BUCKET_SIZE);
}

public List<ModuleDescription> getRpcModules() {
if (this.moduleDescriptions != null) {
return this.moduleDescriptions;
Expand Down Expand Up @@ -494,6 +521,18 @@ public double getTopBest() {
return value;
}

public GasPriceCalculator.GasCalculatorType getGasCalculatorType() {
String value = configFromFiles.getString(TX_GAS_PRICE_CALCULATOR_TYPE);
if (value == null || value.isEmpty()) {
return GasPriceCalculator.GasCalculatorType.PLAIN_PERCENTILE;
}
GasPriceCalculator.GasCalculatorType gasCalculatorType = GasPriceCalculator.GasCalculatorType.fromString(value);
if(gasCalculatorType == null) {
throw new RskConfigurationException("Invalid gasPriceCalculatorType: " + value);
}
return gasCalculatorType;
}

private void fetchMethodTimeout(Config configElement, Map<String, Long> methodTimeoutMap) {
configElement.getObject("methods.timeout")
.unwrapped()
Expand Down
Loading

0 comments on commit 811f7ca

Please sign in to comment.