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));
}
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);
}
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;
}
Aggregations