Skip to content

Commit

Permalink
Test fixes and add placeholder hardfork
Browse files Browse the repository at this point in the history
  • Loading branch information
rmoreliovlabs committed May 22, 2024
1 parent ef3f0d4 commit f0f6fbc
Show file tree
Hide file tree
Showing 29 changed files with 88 additions and 42 deletions.
14 changes: 8 additions & 6 deletions rskj-core/src/main/java/co/rsk/core/bc/BlockExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,14 @@ private BlockResult executeInternal(
for (Transaction tx : block.getTransactionsList()) {
logger.trace("apply block: [{}] tx: [{}] ", block.getNumber(), i);

if (claimTransactionValidator.isClaimTx(tx)
&& !claimTransactionValidator.hasLockedFunds(tx, track)) {
logger.warn("block: [{}] discarded claim tx: [{}], because the funds it tries to claim no longer exist in contract",
block.getNumber(),
tx.getHash());
continue;
if (claimTransactionValidator.isFeatureActive(activationConfig.forBlock(block.getNumber()))) {
if(claimTransactionValidator.isClaimTx(tx)
&& !claimTransactionValidator.hasLockedFunds(tx, track)) {
logger.warn("block: [{}] discarded claim tx: [{}], because the funds it tries to claim no longer exist in contract",
block.getNumber(),
tx.getHash());
continue;
}
}

TransactionExecutor txExecutor = transactionExecutorFactory.newInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import co.rsk.db.RepositorySnapshot;
import co.rsk.util.HexUtils;
import org.ethereum.config.Constants;
import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.config.blockchain.upgrades.ConsensusRule;
import org.ethereum.core.CallTransaction;
import org.ethereum.core.SignatureCache;
import org.ethereum.core.Transaction;
Expand All @@ -24,17 +26,16 @@ public class ClaimTransactionValidator {
private static final String SWAPS_MAP_POSITION = "0000000000000000000000000000000000000000000000000000000000000000";
private static final String CLAIM_METHOD_ABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"preimage\",\"type\":\"bytes32\"}, {\"name\":\"amount\",\"type\":\"uint256\"}, {\"name\":\"address\",\"type\":\"address\"}, {\"name\":\"timelock\",\"type\":\"uint256\"}],\"name\":\"claim\",\"outputs\":[],\"payable\":false,\"type\":\"function\"}]";

@Nonnull
private final SignatureCache signatureCache;

@Nonnull
private final Constants constants;

private final CallTransaction.Contract contract = new CallTransaction.Contract(CLAIM_METHOD_ABI);;

public ClaimTransactionValidator(@Nonnull SignatureCache signatureCache,
public ClaimTransactionValidator(SignatureCache signatureCache,
@Nonnull Constants constants) {
this.signatureCache = Objects.requireNonNull(signatureCache);
this.signatureCache = signatureCache;
this.constants = Objects.requireNonNull(constants);
}

Expand Down Expand Up @@ -125,7 +126,14 @@ public boolean hasLockedFunds(Transaction tx, RepositorySnapshot repositorySnaps
return swapRecord != null;
}

public boolean isClaimTxAndValid(Transaction tx, RepositorySnapshot repositorySnapshot) {
public boolean isFeatureActive (ActivationConfig.ForBlock activationConfig) {
return activationConfig.isActive(ConsensusRule.RSKIP00);
}

public boolean isClaimTxAndValid(Transaction tx, RepositorySnapshot repositorySnapshot, ActivationConfig.ForBlock activationConfig) {
if(!isFeatureActive(activationConfig)) {
return false;
}

if(!isClaimTx(tx)) {
return false;
Expand Down Expand Up @@ -181,7 +189,6 @@ public boolean canPayPendingAndNewClaimTx(Transaction newTx, RepositorySnapshot
return balanceAfterPendingTx.add(totalLockedAmount).compareTo(totalClaimTxCost) >= 0;
}

@Nonnull
public SignatureCache getSignatureCache() {
return signatureCache;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,13 @@ private boolean senderCanPayPendingTransactionsAndNewTx(Transaction newTx, Repos

Coin costWithNewTx = accumTxCost.add(getTxBaseCost(newTx));

return costWithNewTx.compareTo(currentRepository.getBalance(newTx.getSender(signatureCache))) <= 0
|| claimTxValidator.canPayPendingAndNewClaimTx(newTx, currentRepository, transactions);
if(costWithNewTx.compareTo(currentRepository.getBalance(newTx.getSender(signatureCache))) <= 0) {
return true;
} if(claimTxValidator.isFeatureActive(config.getActivationConfig().forBlock(bestBlock.getNumber()))) {
return claimTxValidator.canPayPendingAndNewClaimTx(newTx, currentRepository, transactions);
}

return false;
}

private Coin getTxBaseCost(Transaction tx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public TransactionValidationResult isValid(Transaction tx, Block executionBlock,
}

for (TxValidatorStep step : validatorSteps) {
TransactionValidationResult validationResult = step.validate(tx, state, blockGasLimit, minimumGasPrice, bestBlockNumber, basicTxCost == 0, repositorySnapshot);
TransactionValidationResult validationResult = step.validate(tx, state, blockGasLimit, minimumGasPrice, bestBlockNumber, basicTxCost == 0, repositorySnapshot, activationConfig.forBlock(bestBlockNumber));
if (!validationResult.transactionIsValid()) {
logger.info("[tx={}] validation failed with error: {}", tx.getHash(), validationResult.getErrorMessage());
return validationResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import co.rsk.core.Coin;
import co.rsk.db.RepositorySnapshot;
import co.rsk.net.TransactionValidationResult;
import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.core.AccountState;
import org.ethereum.core.Transaction;

Expand All @@ -35,7 +36,7 @@
public class TxNotNullValidator implements TxValidatorStep {

@Override
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot) {
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot, ActivationConfig.ForBlock activationConfig) {
return this.validate(tx, state, gasLimit, minimumGasPrice, bestBlockNumber, isFreeTx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import co.rsk.db.RepositorySnapshot;
import co.rsk.net.TransactionValidationResult;
import org.ethereum.config.Constants;
import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.core.AccountState;
import org.ethereum.core.SignatureCache;
import org.ethereum.core.Transaction;
Expand All @@ -35,7 +36,7 @@
*/
public class TxValidatorAccountBalanceValidator implements TxValidatorStep {

private ClaimTransactionValidator claimTransactionValidator;
private final ClaimTransactionValidator claimTransactionValidator;

public TxValidatorAccountBalanceValidator(
Constants constants,
Expand All @@ -44,7 +45,7 @@ public TxValidatorAccountBalanceValidator(
}

@Override
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot) {
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot, ActivationConfig.ForBlock activationConfig) {
if (isFreeTx) {
return TransactionValidationResult.ok();
}
Expand All @@ -56,7 +57,7 @@ public TransactionValidationResult validate(Transaction tx, @Nullable AccountSta
BigInteger txGasLimit = tx.getGasLimitAsInteger();
Coin maximumPrice = tx.getGasPrice().multiply(txGasLimit);
if (state.getBalance().compareTo(maximumPrice) >= 0
|| claimTransactionValidator.isClaimTxAndValid(tx, repositorySnapshot)) {
|| claimTransactionValidator.isClaimTxAndValid(tx, repositorySnapshot, activationConfig)) {
return TransactionValidationResult.ok();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import co.rsk.core.Coin;
import co.rsk.db.RepositorySnapshot;
import co.rsk.net.TransactionValidationResult;
import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.core.AccountState;
import org.ethereum.core.Transaction;

Expand All @@ -33,7 +34,7 @@
public class TxValidatorAccountStateValidator implements TxValidatorStep {

@Override
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot) {
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot, ActivationConfig.ForBlock activationConfig) {
return validate(tx, state, gasLimit, minimumGasPrice, bestBlockNumber, isFreeTx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import co.rsk.db.RepositorySnapshot;
import co.rsk.net.TransactionValidationResult;
import org.ethereum.config.Constants;
import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.core.AccountState;
import org.ethereum.core.Transaction;

Expand All @@ -35,7 +36,7 @@
*/
public class TxValidatorGasLimitValidator implements TxValidatorStep {
@Override
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot) {
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot, ActivationConfig.ForBlock activationConfig) {
return validate(tx, state, gasLimit, minimumGasPrice, bestBlockNumber, isFreeTx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public TxValidatorIntrinsicGasLimitValidator(
}

@Override
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot) {
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot, ActivationConfig.ForBlock activationConfig) {
return validate(tx, state, gasLimit, minimumGasPrice, bestBlockNumber, isFreeTx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public TxValidatorMaximumGasPriceValidator(ActivationConfig activationConfig) {
}

@Override
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot) {
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot, ActivationConfig.ForBlock activationConfig) {
return validate(tx, state, gasLimit, minimumGasPrice, bestBlockNumber, isFreeTx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import co.rsk.core.Coin;
import co.rsk.db.RepositorySnapshot;
import co.rsk.net.TransactionValidationResult;
import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.core.AccountState;
import org.ethereum.core.Transaction;

Expand All @@ -32,7 +33,7 @@
*/
public class TxValidatorMinimuGasPriceValidator implements TxValidatorStep {
@Override
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot) {
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot, ActivationConfig.ForBlock activationConfig) {
return validate(tx, state, gasLimit, minimumGasPrice, bestBlockNumber, isFreeTx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import co.rsk.core.Coin;
import co.rsk.db.RepositorySnapshot;
import co.rsk.net.TransactionValidationResult;
import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.core.AccountState;
import org.ethereum.core.Transaction;

Expand All @@ -43,7 +44,7 @@ public TxValidatorNonceRangeValidator(int accountSlots) {
}

@Override
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot) {
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot, ActivationConfig.ForBlock activationConfig) {
return validate(tx, state, gasLimit, minimumGasPrice, bestBlockNumber, isFreeTx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import co.rsk.db.RepositorySnapshot;
import co.rsk.net.TransactionValidationResult;
import co.rsk.remasc.RemascTransaction;
import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.core.AccountState;
import org.ethereum.core.Transaction;

Expand All @@ -35,7 +36,7 @@
*/
public class TxValidatorNotRemascTxValidator implements TxValidatorStep {
@Override
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot) {
public TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot, ActivationConfig.ForBlock activationConfig) {
return validate(tx, state, gasLimit, minimumGasPrice, bestBlockNumber, isFreeTx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import co.rsk.core.Coin;
import co.rsk.db.RepositorySnapshot;
import co.rsk.net.TransactionValidationResult;
import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.core.AccountState;
import org.ethereum.core.Transaction;

Expand All @@ -33,7 +34,7 @@
*/
public interface TxValidatorStep {

TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot);
TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx, RepositorySnapshot repositorySnapshot, ActivationConfig.ForBlock activationConfig);

TransactionValidationResult validate(Transaction tx, @Nullable AccountState state, BigInteger gasLimit, Coin minimumGasPrice, long bestBlockNumber, boolean isFreeTx);
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public enum ConsensusRule {
RSKIP412("rskip412"), // From EIP-3198 BASEFEE opcode
RSKIP415("rskip415"),
RSKIP417("rskip417"),
RSKIP00("rskip00"), // Placeholder for EthSwap feature
;

private String configKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public enum NetworkUpgrade {
HOP401("hop401"),
FINGERROOT500("fingerroot500"),
ARROWHEAD600("arrowhead600"),
LOVELL700("lovell700");
LOVELL700("lovell700"),
TBD000("tbd000");

private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private boolean init() {

Coin senderBalance = track.getBalance(tx.getSender(signatureCache));

if (!isCovers(senderBalance, totalCost) && !claimTransactionValidator.isClaimTxAndValid(tx, track)) {
if (!isCovers(senderBalance, totalCost) && !claimTransactionValidator.isClaimTxAndValid(tx, track, activations)) {

logger.warn("Not enough cash: Require: {}, Sender cash: {}, tx {}", totalCost, senderBalance, tx.getHash());
logger.warn("Transaction Data: {}", tx);
Expand Down
3 changes: 2 additions & 1 deletion rskj-core/src/main/resources/config/devnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ blockchain.config {
hop401 = 0,
fingerroot500 = 0,
arrowhead600 = 0,
lovell700 = 0
lovell700 = 0,
tbd000 = 0,
},
consensusRules = {
rskip97 = -1 # disable orchid difficulty drop
Expand Down
3 changes: 2 additions & 1 deletion rskj-core/src/main/resources/config/main.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ blockchain.config {
hop401 = 4976300,
fingerroot500 = 5468000,
arrowhead600 = 6223700,
lovell700 = -1
lovell700 = -1,
tbd000 = -1,
}
}

Expand Down
3 changes: 2 additions & 1 deletion rskj-core/src/main/resources/config/regtest.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ blockchain.config {
hop401 = 0,
fingerroot500 = 0,
arrowhead600 = 0,
lovell700 = 0
lovell700 = 0,
tbd000 = 0,
},
consensusRules = {
rskip97 = -1 # disable orchid difficulty drop
Expand Down
1 change: 1 addition & 0 deletions rskj-core/src/main/resources/config/testnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ blockchain.config {
fingerroot500 = 4015800,
arrowhead600 = 4927100,
lovell700 = -1
tbd000 = -1,
},
consensusRules = {
rskip97 = -1, # disable orchid difficulty drop
Expand Down
2 changes: 2 additions & 0 deletions rskj-core/src/main/resources/expected.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ blockchain = {
fingerroot500 = <height>
arrowhead600 = <height>
lovell700 = <height>
tbd000 = <height>
}
consensusRules = {
areBridgeTxsPaid = <hardforkName>
Expand Down Expand Up @@ -93,6 +94,7 @@ blockchain = {
rskip412 = <hardforkName>
rskip415 = <hardforkName>
rskip417 = <hardforkName>
rskip00 = <hardforkName>
}
}
gc = {
Expand Down
1 change: 1 addition & 0 deletions rskj-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ blockchain = {
rskip412 = arrowhead600
rskip415 = arrowhead600
rskip417 = arrowhead600
rskip00 = tbd000
}
}
gc = {
Expand Down
3 changes: 2 additions & 1 deletion rskj-core/src/test/java/co/rsk/mine/MainNetMinerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import co.rsk.validators.ProofOfWorkRule;
import org.ethereum.config.Constants;
import org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest;
import org.ethereum.config.blockchain.upgrades.ConsensusRule;
import org.ethereum.core.*;
import org.ethereum.core.genesis.GenesisLoader;
import org.ethereum.db.BlockStore;
Expand Down Expand Up @@ -76,7 +77,7 @@ class MainNetMinerTest {
void setup() {
config = spy(new TestSystemProperties());
when(config.getNetworkConstants()).thenReturn(Constants.mainnet());
when(config.getActivationConfig()).thenReturn(ActivationConfigsForTest.all());
when(config.getActivationConfig()).thenReturn(ActivationConfigsForTest.allBut(ConsensusRule.RSKIP00));
RskTestFactory factory = new RskTestFactory(tempDir, config) {
@Override
public GenesisLoader buildGenesisLoader() {
Expand Down
Loading

0 comments on commit f0f6fbc

Please sign in to comment.