Search in sources :

Example 6 with RemascTransaction

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

the class BlockTest method testParseRemascTransaction.

@Test
public void testParseRemascTransaction() {
    List<Transaction> txs = new ArrayList<>();
    Transaction txNotToRemasc = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ONE.toByteArray(), BigInteger.valueOf(21000).toByteArray(), new ECKey().getAddress(), BigInteger.valueOf(1000).toByteArray(), null);
    txNotToRemasc.sign(new ECKey().getPrivKeyBytes());
    txs.add(txNotToRemasc);
    Transaction txToRemascThatIsNotTheLatestTx = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ONE.toByteArray(), BigInteger.valueOf(21000).toByteArray(), PrecompiledContracts.REMASC_ADDR.getBytes(), BigInteger.valueOf(1000).toByteArray(), null);
    txToRemascThatIsNotTheLatestTx.sign(new ECKey().getPrivKeyBytes());
    txs.add(txToRemascThatIsNotTheLatestTx);
    Transaction remascTx = new RemascTransaction(1);
    txs.add(remascTx);
    Block block = new Block(// parent hash
    PegTestUtils.createHash3().getBytes(), // uncle hash
    EMPTY_LIST_HASH, // coinbase
    TestUtils.randomAddress().getBytes(), // logs bloom
    new Bloom().getData(), // difficulty
    BigInteger.ONE.toByteArray(), 1, // gasLimit
    BigInteger.valueOf(4000000).toByteArray(), // gasUsed
    3000000, // timestamp
    100, // extraData
    new byte[0], // mixHash
    new byte[0], // provisory nonce
    new byte[] { 0 }, // receipts root
    HashUtil.EMPTY_TRIE_HASH, // transaction root
    BlockChainImpl.calcTxTrie(txs), // EMPTY_TRIE_HASH,   // state root
    HashUtil.EMPTY_TRIE_HASH, // transaction list
    txs, // uncle list
    null, BigInteger.TEN.toByteArray(), Coin.ZERO);
    Block parsedBlock = new Block(block.getEncoded());
    Assert.assertEquals(ImmutableTransaction.class, parsedBlock.getTransactionsList().get(0).getClass());
    Assert.assertEquals(ImmutableTransaction.class, parsedBlock.getTransactionsList().get(1).getClass());
    Assert.assertEquals(RemascTransaction.class, parsedBlock.getTransactionsList().get(2).getClass());
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) RemascTransaction(co.rsk.remasc.RemascTransaction) ArrayList(java.util.ArrayList) ECKey(org.ethereum.crypto.ECKey) Test(org.junit.Test)

Example 7 with RemascTransaction

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

the class BlockValidatorTest method remascTx.

@Test
public void remascTx() {
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    List<Transaction> txs = new ArrayList<>();
    Transaction tx = Transaction.create(config, "0000000000000000000000000000000000000006", BigInteger.ZERO, BigInteger.ZERO, BigInteger.valueOf(12L), BigInteger.TEN);
    tx.sign(new byte[] {});
    txs.add(tx);
    txs.add(new RemascTransaction(BigInteger.ONE.longValue()));
    Block block = new BlockBuilder().parent(genesis).transactions(txs).build();
    BlockValidatorImpl validator = new BlockValidatorBuilder().addRemascValidationRule().build();
    Assert.assertTrue(validator.isValid(block));
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) RemascTransaction(co.rsk.remasc.RemascTransaction) ArrayList(java.util.ArrayList) SimpleBlock(co.rsk.peg.simples.SimpleBlock) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 8 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.create(config, "0000000000000000000000000000000000000001", BigInteger.ZERO, BigInteger.ZERO, BigInteger.ONE, BigInteger.TEN));
    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 9 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 10 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)10 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Transaction (org.ethereum.core.Transaction)4 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)2 Coin (co.rsk.core.Coin)2 RskAddress (co.rsk.core.RskAddress)2 Keccak256 (co.rsk.crypto.Keccak256)2 SimpleBlock (co.rsk.peg.simples.SimpleBlock)2 BlockBuilder (co.rsk.test.builders.BlockBuilder)2 BigInteger (java.math.BigInteger)2 Block (org.ethereum.core.Block)2 BtcTransaction (co.rsk.bitcoinj.core.BtcTransaction)1 BlockUnclesValidationRule (co.rsk.validators.BlockUnclesValidationRule)1 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)1 IOException (java.io.IOException)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ECKey (org.ethereum.crypto.ECKey)1 EthereumImpl (org.ethereum.facade.EthereumImpl)1 RLPElement (org.ethereum.util.RLPElement)1