use of org.ethereum.core.TransactionPool in project rskj by rsksmart.
the class MinerUtilsTest method getAllTransactionsTest.
@Test
public void getAllTransactionsTest() {
TransactionPool transactionPool = Mockito.mock(TransactionPool.class);
Transaction tx1 = Mockito.mock(Transaction.class);
Transaction tx2 = Mockito.mock(Transaction.class);
byte[] s1 = new byte[32];
byte[] s2 = new byte[32];
s1[0] = 0;
s2[0] = 1;
Mockito.when(tx1.getHash()).thenReturn(new Keccak256(s1));
Mockito.when(tx2.getHash()).thenReturn(new Keccak256(s2));
List<Transaction> txs = new LinkedList<>();
txs.add(tx1);
txs.add(tx2);
Mockito.when(transactionPool.getPendingTransactions()).thenReturn(txs);
List<Transaction> res = new MinerUtils().getAllTransactions(transactionPool);
Assert.assertEquals(2, res.size());
}
use of org.ethereum.core.TransactionPool in project rskj by rsksmart.
the class Web3ImplRpcTest method getRpcModules.
@Test
public void getRpcModules() {
Ethereum eth = Web3Mocks.getMockEthereum();
Blockchain blockchain = Web3Mocks.getMockBlockchain();
TransactionPool transactionPool = Web3Mocks.getMockTransactionPool();
PersonalModule pm = new PersonalModuleWalletDisabled();
Repository repository = Web3Mocks.getMockRepository();
Web3Impl web3 = new Web3RskImpl(eth, blockchain, transactionPool, new RskSystemProperties(), null, null, pm, null, null, null, repository, null, null, null, null, null, null, null, null);
Map<String, String> result = web3.rpc_modules();
Assert.assertNotNull(result);
Assert.assertFalse(result.isEmpty());
Assert.assertTrue(result.containsKey("eth"));
Assert.assertEquals("1.0", result.get("eth"));
}
use of org.ethereum.core.TransactionPool in project rskj by rsksmart.
the class SnapshotManager method revertToSnapshot.
public boolean revertToSnapshot(Blockchain blockchain, int snapshotId) {
if (snapshotId <= 0 || snapshotId > this.snapshots.size()) {
return false;
}
long newBestBlockNumber = this.snapshots.get(snapshotId - 1).longValue();
List<Long> newSnapshots = this.snapshots.stream().limit(snapshotId).collect(Collectors.toList());
this.snapshots = newSnapshots;
TransactionPool transactionPool = blockchain.getTransactionPool();
long currentBestBlockNumber = blockchain.getBestBlock().getNumber();
if (newBestBlockNumber >= currentBestBlockNumber) {
return true;
}
BlockStore store = blockchain.getBlockStore();
Block block = store.getChainBlockByNumber(newBestBlockNumber);
BlockDifficulty difficulty = blockchain.getBlockStore().getTotalDifficultyForHash(block.getHash().getBytes());
blockchain.setStatus(block, difficulty);
// To clean pending state, first process the fork
blockchain.getTransactionPool().processBest(block);
// then, clear any reverted transaction
transactionPool.removeTransactions(transactionPool.getPendingTransactions());
transactionPool.removeTransactions(transactionPool.getQueuedTransactions());
// Remove removed blocks from store
for (long nb = blockchain.getBestBlock().getNumber() + 1; nb <= currentBestBlockNumber; nb++) {
blockchain.removeBlocksByNumber(nb);
}
return true;
}
use of org.ethereum.core.TransactionPool in project rskj by rsksmart.
the class MainNetMinerTest method submitBitcoinBlockProofOfWorkNotGoodEnough.
/*
* This test is probabilistic, but it has a really high chance to pass. We will generate
* a random block that it is unlikely to pass the Long.MAX_VALUE difficulty, though
* it may happen once. Twice would be suspicious.
*/
@Test
public void submitBitcoinBlockProofOfWorkNotGoodEnough() {
/* We need a low target */
BlockChainImpl bc = new BlockChainBuilder().build();
Genesis gen = (Genesis) BlockChainImplTest.getGenesisBlock(bc);
gen.getHeader().setDifficulty(new BlockDifficulty(BigInteger.valueOf(Long.MAX_VALUE)));
bc.setStatus(gen, gen.getCumulativeDifficulty());
World world = new World(bc, gen);
TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), world.getBlockChain().getBlockStore(), null, null, null, 10, 100);
blockchain = world.getBlockChain();
EthereumImpl ethereumImpl = Mockito.mock(EthereumImpl.class);
MinerServer minerServer = new MinerServerImpl(config, ethereumImpl, blockchain, null, DIFFICULTY_CALCULATOR, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), blockToMineBuilder(), ConfigUtils.getDefaultMiningConfig());
try {
minerServer.start();
MinerWork work = minerServer.getWork();
co.rsk.bitcoinj.core.BtcBlock bitcoinMergedMiningBlock = getMergedMiningBlock(work);
bitcoinMergedMiningBlock.setNonce(2);
SubmitBlockResult result = minerServer.submitBitcoinBlock(work.getBlockHashForMergedMining(), bitcoinMergedMiningBlock);
Assert.assertEquals("ERROR", result.getStatus());
Assert.assertNull(result.getBlockInfo());
Mockito.verify(ethereumImpl, Mockito.times(0)).addNewMinedBlock(Mockito.any());
} finally {
minerServer.stop();
}
}
use of org.ethereum.core.TransactionPool in project rskj by rsksmart.
the class SnapshotManager method resetSnapshots.
public boolean resetSnapshots(Blockchain blockchain) {
this.snapshots = new ArrayList<>();
TransactionPool transactionPool = blockchain.getTransactionPool();
long bestNumber = blockchain.getBestBlock().getNumber();
BlockStore store = blockchain.getBlockStore();
Block block = store.getChainBlockByNumber(0);
BlockDifficulty difficulty = blockchain.getBlockStore().getTotalDifficultyForHash(block.getHash().getBytes());
blockchain.setStatus(block, difficulty);
// To clean pending state, first process the fork
blockchain.getTransactionPool().processBest(block);
// then, clear any reverted transaction
transactionPool.removeTransactions(transactionPool.getPendingTransactions());
transactionPool.removeTransactions(transactionPool.getQueuedTransactions());
// Remove removed blocks from store
for (long nb = blockchain.getBestBlock().getNumber() + 1; nb <= bestNumber; nb++) {
blockchain.removeBlocksByNumber(nb);
}
return true;
}
Aggregations