Search in sources :

Example 1 with TransactionPool

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());
}
Also used : TransactionPool(org.ethereum.core.TransactionPool) Transaction(org.ethereum.core.Transaction) Keccak256(co.rsk.crypto.Keccak256) Test(org.junit.Test)

Example 2 with TransactionPool

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"));
}
Also used : TransactionPool(org.ethereum.core.TransactionPool) Repository(org.ethereum.core.Repository) Ethereum(org.ethereum.facade.Ethereum) Blockchain(org.ethereum.core.Blockchain) PersonalModule(co.rsk.rpc.modules.personal.PersonalModule) Web3Impl(org.ethereum.rpc.Web3Impl) PersonalModuleWalletDisabled(co.rsk.rpc.modules.personal.PersonalModuleWalletDisabled) RskSystemProperties(co.rsk.config.RskSystemProperties) Test(org.junit.Test)

Example 3 with TransactionPool

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;
}
Also used : TransactionPool(org.ethereum.core.TransactionPool) BlockStore(org.ethereum.db.BlockStore) Block(org.ethereum.core.Block)

Example 4 with TransactionPool

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();
    }
}
Also used : TransactionPool(org.ethereum.core.TransactionPool) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) EthereumImpl(org.ethereum.facade.EthereumImpl) World(co.rsk.test.World) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) BlockDifficulty(co.rsk.core.BlockDifficulty) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) Genesis(org.ethereum.core.Genesis) Test(org.junit.Test) BlockChainImplTest(co.rsk.core.bc.BlockChainImplTest)

Example 5 with TransactionPool

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;
}
Also used : TransactionPool(org.ethereum.core.TransactionPool) BlockStore(org.ethereum.db.BlockStore) Block(org.ethereum.core.Block)

Aggregations

TransactionPool (org.ethereum.core.TransactionPool)5 Test (org.junit.Test)3 Block (org.ethereum.core.Block)2 BlockStore (org.ethereum.db.BlockStore)2 RskSystemProperties (co.rsk.config.RskSystemProperties)1 BlockDifficulty (co.rsk.core.BlockDifficulty)1 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)1 BlockChainImplTest (co.rsk.core.bc.BlockChainImplTest)1 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)1 Keccak256 (co.rsk.crypto.Keccak256)1 PersonalModule (co.rsk.rpc.modules.personal.PersonalModule)1 PersonalModuleWalletDisabled (co.rsk.rpc.modules.personal.PersonalModuleWalletDisabled)1 World (co.rsk.test.World)1 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)1 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)1 Blockchain (org.ethereum.core.Blockchain)1 Genesis (org.ethereum.core.Genesis)1 Repository (org.ethereum.core.Repository)1 Transaction (org.ethereum.core.Transaction)1 Ethereum (org.ethereum.facade.Ethereum)1