Search in sources :

Example 31 with Blockchain

use of org.ethereum.core.Blockchain in project rskj by rsksmart.

the class RemascFederationProviderTest method getRemascFederationProvider.

private static RemascFederationProvider getRemascFederationProvider() throws IOException, BlockStoreException {
    Genesis genesisBlock = new BlockGenerator().getGenesisBlock();
    BlockChainBuilder builder = new BlockChainBuilder().setTesting(true).setGenesis(genesisBlock);
    Blockchain blockchain = builder.build();
    BridgeSupport bridgeSupport = new BridgeSupport(new RskSystemProperties(), blockchain.getRepository(), null, PrecompiledContracts.BRIDGE_ADDR, null);
    RemascFederationProvider provider = null;
    try {
        provider = new RemascFederationProvider(bridgeSupport);
    } catch (BlockStoreException | IOException e) {
        e.printStackTrace();
    }
    return provider;
}
Also used : BlockStoreException(co.rsk.bitcoinj.store.BlockStoreException) Blockchain(org.ethereum.core.Blockchain) Genesis(org.ethereum.core.Genesis) IOException(java.io.IOException) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) BridgeSupport(co.rsk.peg.BridgeSupport) RskSystemProperties(co.rsk.config.RskSystemProperties)

Example 32 with Blockchain

use of org.ethereum.core.Blockchain 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 33 with Blockchain

use of org.ethereum.core.Blockchain in project rskj by rsksmart.

the class ThreeAsyncNodeUsingSyncProcessorTest method synchronizeNewNodeWithThreePeers400Different.

@Test
public void synchronizeNewNodeWithThreePeers400Different() {
    Blockchain b1 = BlockChainBuilder.ofSize(0, true);
    Blockchain b2 = BlockChainBuilder.copyAndExtend(b1, 200);
    Blockchain b3 = BlockChainBuilder.copyAndExtend(b2, 200);
    SimpleAsyncNode node1 = SimpleAsyncNode.createDefaultNode(b2);
    SimpleAsyncNode node2 = SimpleAsyncNode.createDefaultNode(b2);
    SimpleAsyncNode node3 = SimpleAsyncNode.createDefaultNode(b3);
    SyncConfiguration syncConfiguration = new SyncConfiguration(3, 1, 10, 100, 20, 192);
    SimpleAsyncNode node4 = SimpleAsyncNode.createNode(b1, syncConfiguration);
    Assert.assertEquals(200, node1.getBestBlock().getNumber());
    Assert.assertEquals(200, node2.getBestBlock().getNumber());
    Assert.assertEquals(400, node3.getBestBlock().getNumber());
    Assert.assertEquals(0, node4.getBestBlock().getNumber());
    node1.sendFullStatusTo(node4);
    node2.sendFullStatusTo(node4);
    node3.sendFullStatusTo(node4);
    // sync setup
    int setupRequests = SyncUtils.syncSetupRequests(400, 0, syncConfiguration);
    node4.waitUntilNTasksWithTimeout(setupRequests);
    // synchronize 50 new blocks from node 1
    node4.waitExactlyNTasksWithTimeout(400 + setupRequests - 10);
    Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node4.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertEquals(400, node4.getBestBlock().getNumber());
    Assert.assertEquals(node4.getBestBlock().getHash(), node3.getBestBlock().getHash());
    Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
    Assert.assertTrue(node4.getSyncProcessor().getExpectedResponses().isEmpty());
    node1.joinWithTimeout();
    node2.joinWithTimeout();
    node3.joinWithTimeout();
    node4.joinWithTimeout();
    Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node4.getNodeID()));
    Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node4.getNodeID()));
    Assert.assertFalse(node3.getSyncProcessor().isPeerSyncing(node4.getNodeID()));
}
Also used : SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Blockchain(org.ethereum.core.Blockchain) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 34 with Blockchain

use of org.ethereum.core.Blockchain in project rskj by rsksmart.

the class TwoAsyncNodeTest method createNode.

private static SimpleAsyncNode createNode(int size) {
    final World world = new World();
    final BlockStore store = new BlockStore();
    final Blockchain blockchain = world.getBlockChain();
    List<Block> blocks = new BlockGenerator().getBlockChain(blockchain.getBestBlock(), size);
    for (Block b : blocks) blockchain.tryToConnect(b);
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
    NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    NodeMessageHandler handler = new NodeMessageHandler(config, processor, null, null, null, null, null, new DummyBlockValidationRule());
    return new SimpleAsyncNode(handler);
}
Also used : DummyBlockValidationRule(co.rsk.validators.DummyBlockValidationRule) Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Block(org.ethereum.core.Block) SyncConfiguration(co.rsk.net.sync.SyncConfiguration)

Example 35 with Blockchain

use of org.ethereum.core.Blockchain in project rskj by rsksmart.

the class TwoAsyncNodeUsingSyncProcessorTest method syncInMultipleStepsWithLongBlockchain.

@Test
public void syncInMultipleStepsWithLongBlockchain() {
    Blockchain b1 = BlockChainBuilder.ofSize(300, false);
    Blockchain b2 = BlockChainBuilder.copyAndExtend(b1, 4000, false);
    SimpleAsyncNode node1 = SimpleAsyncNode.createNode(b1, SyncConfiguration.IMMEDIATE_FOR_TESTING);
    SimpleAsyncNode node2 = SimpleAsyncNode.createNode(b2, SyncConfiguration.IMMEDIATE_FOR_TESTING);
    Assert.assertEquals(300, node1.getBestBlock().getNumber());
    Assert.assertEquals(4300, node2.getBestBlock().getNumber());
    for (int i = 0; i < 5; i++) {
        int skippedChunks = 300 / 192;
        int expectedBestBlockNumber = Math.min(4300, 192 * skippedChunks + 192 * 6 * (i + 1));
        long currentBestBlock = node1.getBestBlock().getNumber();
        // at the beginning and the end we might have different number of blocks to download
        int blocksToDownload = Math.toIntExact(expectedBestBlockNumber - currentBestBlock);
        node2.sendFullStatusTo(node1);
        node1.waitUntilNTasksWithTimeout(SyncUtils.syncSetupRequests(4300, currentBestBlock, SyncConfiguration.IMMEDIATE_FOR_TESTING));
        // request bodies
        node1.waitExactlyNTasksWithTimeout(blocksToDownload);
        Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
        Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
        Assert.assertEquals(expectedBestBlockNumber, node1.getBestBlock().getNumber());
        Assert.assertEquals(4300, node2.getBestBlock().getNumber());
        // this prevents node2's queue to get full
        node2.clearQueue();
    }
    node1.joinWithTimeout();
    node2.joinWithTimeout();
    Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
    Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
}
Also used : SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Blockchain(org.ethereum.core.Blockchain) Test(org.junit.Test)

Aggregations

Blockchain (org.ethereum.core.Blockchain)86 Test (org.junit.Test)75 Block (org.ethereum.core.Block)51 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)47 RskSystemProperties (co.rsk.config.RskSystemProperties)45 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)38 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)25 World (co.rsk.test.World)19 SimpleAsyncNode (co.rsk.net.simples.SimpleAsyncNode)14 Keccak256 (co.rsk.crypto.Keccak256)7 Ignore (org.junit.Ignore)7 DummyBlockValidationRule (co.rsk.validators.DummyBlockValidationRule)5 BlockIdentifier (org.ethereum.core.BlockIdentifier)3 BlockChainStatus (co.rsk.core.bc.BlockChainStatus)2 NewBlockHashMessage (co.rsk.net.messages.NewBlockHashMessage)2 PersonalModule (co.rsk.rpc.modules.personal.PersonalModule)2 Repository (org.ethereum.core.Repository)2 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)2 BlockStoreException (co.rsk.bitcoinj.store.BlockStoreException)1 BlockDifficulty (co.rsk.core.BlockDifficulty)1