Search in sources :

Example 16 with RemascTransaction

use of co.rsk.remasc.RemascTransaction in project rskj by rsksmart.

the class RemascValidationRuleTest method remascTxIsNotTheLastOne.

@Test
public void remascTxIsNotTheLastOne() {
    Block b = Mockito.mock(Block.class);
    List<Transaction> tx = new ArrayList<>();
    tx.add(new RemascTransaction(1L));
    tx.add(Transaction.builder().nonce(BigInteger.ZERO).gasPrice(BigInteger.ONE).gasLimit(BigInteger.TEN).destination(Hex.decode("0000000000000000000000000000000000000001")).chainId(Constants.REGTEST_CHAIN_ID).value(BigInteger.ZERO).build());
    Mockito.when(b.getTransactionsList()).thenReturn(tx);
    RemascValidationRule rule = new RemascValidationRule();
    Assert.assertFalse(rule.isValid(b));
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) RemascTransaction(co.rsk.remasc.RemascTransaction) Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) Test(org.junit.Test)

Example 17 with RemascTransaction

use of co.rsk.remasc.RemascTransaction in project rskj by rsksmart.

the class BlockToMineBuilder method getTransactions.

private List<Transaction> getTransactions(List<Transaction> txsToRemove, Block parent, Coin minGasPrice) {
    logger.debug("getting transactions from pending state");
    List<Transaction> txs = minerUtils.getAllTransactions(transactionPool);
    logger.debug("{} transaction(s) collected from pending state", txs.size());
    Transaction remascTx = new RemascTransaction(parent.getNumber() + 1);
    txs.add(remascTx);
    Map<RskAddress, BigInteger> accountNonces = new HashMap<>();
    Repository originalRepo = repository.getSnapshotTo(parent.getStateRoot());
    return minerUtils.filterTransactions(txsToRemove, txs, accountNonces, originalRepo, minGasPrice);
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) RemascTransaction(co.rsk.remasc.RemascTransaction) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger)

Example 18 with RemascTransaction

use of co.rsk.remasc.RemascTransaction in project rskj by rsksmart.

the class MinerUtils method filterTransactions.

public List<org.ethereum.core.Transaction> filterTransactions(List<Transaction> txsToRemove, List<Transaction> txs, Map<RskAddress, BigInteger> accountNonces, Repository originalRepo, Coin minGasPrice) {
    List<org.ethereum.core.Transaction> txsResult = new ArrayList<>();
    for (org.ethereum.core.Transaction tx : txs) {
        try {
            Keccak256 hash = tx.getHash();
            Coin txValue = tx.getValue();
            BigInteger txNonce = new BigInteger(1, tx.getNonce());
            RskAddress txSender = tx.getSender();
            logger.debug("Examining tx={} sender: {} value: {} nonce: {}", hash, txSender, txValue, txNonce);
            BigInteger expectedNonce;
            if (accountNonces.containsKey(txSender)) {
                expectedNonce = accountNonces.get(txSender).add(BigInteger.ONE);
            } else {
                expectedNonce = originalRepo.getNonce(txSender);
            }
            if (!(tx instanceof RemascTransaction) && tx.getGasPrice().compareTo(minGasPrice) < 0) {
                logger.warn("Rejected tx={} because of low gas account {}, removing tx from pending state.", hash, txSender);
                txsToRemove.add(tx);
                continue;
            }
            if (!expectedNonce.equals(txNonce)) {
                logger.warn("Invalid nonce, expected {}, found {}, tx={}", expectedNonce, txNonce, hash);
                continue;
            }
            accountNonces.put(txSender, txNonce);
            logger.debug("Accepted tx={} sender: {} value: {} nonce: {}", hash, txSender, txValue, txNonce);
        } catch (Exception e) {
            // Txs that can't be selected by any reason should be removed from pending state
            logger.warn(String.format("Error when processing tx=%s", tx.getHash()), e);
            if (txsToRemove != null) {
                txsToRemove.add(tx);
            } else {
                logger.error("Can't remove invalid txs from pending state.");
            }
            continue;
        }
        txsResult.add(tx);
    }
    logger.debug("Ending getTransactions {}", txsResult.size());
    return txsResult;
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) Keccak256(co.rsk.crypto.Keccak256) IOException(java.io.IOException) Coin(co.rsk.core.Coin) RemascTransaction(co.rsk.remasc.RemascTransaction) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) Transaction(org.ethereum.core.Transaction) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) Transaction(org.ethereum.core.Transaction)

Aggregations

RemascTransaction (co.rsk.remasc.RemascTransaction)18 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 RskAddress (co.rsk.core.RskAddress)6 BigInteger (java.math.BigInteger)5 Transaction (org.ethereum.core.Transaction)5 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)3 Coin (co.rsk.core.Coin)3 Keccak256 (co.rsk.crypto.Keccak256)3 Block (org.ethereum.core.Block)3 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)2 BtcTransaction (co.rsk.bitcoinj.core.BtcTransaction)2 RepositorySnapshot (co.rsk.db.RepositorySnapshot)2 BlockBuilder (co.rsk.test.builders.BlockBuilder)2 IOException (java.io.IOException)2 RLPElement (org.ethereum.util.RLPElement)2 BlockUnclesValidationRule (co.rsk.validators.BlockUnclesValidationRule)1 Random (java.util.Random)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)1