Search in sources :

Example 16 with BlockIdentifier

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

the class AsyncNodeBlockProcessorTest method processSkeletonRequestNotIncludingGenesis.

@Test
public void processSkeletonRequestNotIncludingGenesis() {
    final int skeletonStep = 192;
    final Blockchain blockchain = new BlockChainBuilder().ofSize(400);
    final NetBlockStore store = new NetBlockStore();
    final BlockNodeInformation nodeInformation = new BlockNodeInformation();
    final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    final TestSystemProperties config = new TestSystemProperties();
    final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final SimplePeer sender = new SimplePeer();
    processor.processSkeletonRequest(sender, 100, skeletonStep + 5);
    Assert.assertFalse(sender.getMessages().isEmpty());
    Assert.assertEquals(1, sender.getMessages().size());
    final Message message = sender.getMessages().get(0);
    Assert.assertEquals(MessageType.SKELETON_RESPONSE_MESSAGE, message.getMessageType());
    final SkeletonResponseMessage bMessage = (SkeletonResponseMessage) message;
    Assert.assertEquals(100, bMessage.getId());
    final Block b1 = blockchain.getBlockByNumber(skeletonStep);
    final Block b2 = blockchain.getBlockByNumber(2 * skeletonStep);
    final Block b3 = blockchain.getBestBlock();
    final BlockIdentifier[] expected = { new BlockIdentifier(b1.getHash().getBytes(), b1.getNumber()), new BlockIdentifier(b2.getHash().getBytes(), b2.getNumber()), new BlockIdentifier(b3.getHash().getBytes(), b3.getNumber()) };
    assertBlockIdentifiers(expected, bMessage.getBlockIdentifiers());
}
Also used : BlockIdentifier(org.ethereum.core.BlockIdentifier) Blockchain(org.ethereum.core.Blockchain) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) Block(org.ethereum.core.Block) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 17 with BlockIdentifier

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

the class AsyncNodeBlockProcessorTest method processSkeletonRequestWithGenesisPlusBestBlockInSkeleton.

@Test
public void processSkeletonRequestWithGenesisPlusBestBlockInSkeleton() {
    int skeletonStep = 192;
    final Blockchain blockchain = new BlockChainBuilder().ofSize(skeletonStep / 2);
    final NetBlockStore store = new NetBlockStore();
    final BlockNodeInformation nodeInformation = new BlockNodeInformation();
    final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    final TestSystemProperties config = new TestSystemProperties();
    final BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final AsyncNodeBlockProcessor processor = new AsyncNodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final SimplePeer sender = new SimplePeer();
    processor.processSkeletonRequest(sender, 100, 5);
    Assert.assertFalse(sender.getMessages().isEmpty());
    Assert.assertEquals(1, sender.getMessages().size());
    final Message message = sender.getMessages().get(0);
    Assert.assertEquals(MessageType.SKELETON_RESPONSE_MESSAGE, message.getMessageType());
    final SkeletonResponseMessage bMessage = (SkeletonResponseMessage) message;
    Assert.assertEquals(100, bMessage.getId());
    Block genesis = blockchain.getBlockByNumber(0);
    Block bestBlock = blockchain.getBestBlock();
    BlockIdentifier[] expected = { new BlockIdentifier(genesis.getHash().getBytes(), genesis.getNumber()), new BlockIdentifier(bestBlock.getHash().getBytes(), bestBlock.getNumber()) };
    assertBlockIdentifiers(expected, bMessage.getBlockIdentifiers());
}
Also used : BlockIdentifier(org.ethereum.core.BlockIdentifier) Blockchain(org.ethereum.core.Blockchain) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) Block(org.ethereum.core.Block) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 18 with BlockIdentifier

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

the class NodeBlockProcessorTest method processSkeletonRequestWithGenesisPlusBestBlockInSkeleton.

@Test
public void processSkeletonRequestWithGenesisPlusBestBlockInSkeleton() throws UnknownHostException {
    int skeletonStep = 192;
    final Blockchain blockchain = new BlockChainBuilder().ofSize(skeletonStep / 2);
    final Block blockStart = blockchain.getBlockByNumber(5);
    final Block blockEnd = blockchain.getBlockByNumber(skeletonStep / 2);
    final NetBlockStore store = new NetBlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    TestSystemProperties config = new TestSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    final SimplePeer sender = new SimplePeer();
    processor.processSkeletonRequest(sender, 100, 5);
    Assert.assertFalse(sender.getMessages().isEmpty());
    Assert.assertEquals(1, sender.getMessages().size());
    final Message message = sender.getMessages().get(0);
    Assert.assertEquals(MessageType.SKELETON_RESPONSE_MESSAGE, message.getMessageType());
    final SkeletonResponseMessage bMessage = (SkeletonResponseMessage) message;
    Assert.assertEquals(100, bMessage.getId());
    Block genesis = blockchain.getBlockByNumber(0);
    Block bestBlock = blockchain.getBestBlock();
    BlockIdentifier[] expected = { new BlockIdentifier(genesis.getHash().getBytes(), genesis.getNumber()), new BlockIdentifier(bestBlock.getHash().getBytes(), bestBlock.getNumber()) };
    assertBlockIdentifiers(expected, bMessage.getBlockIdentifiers());
}
Also used : BlockIdentifier(org.ethereum.core.BlockIdentifier) Blockchain(org.ethereum.core.Blockchain) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) Block(org.ethereum.core.Block) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 19 with BlockIdentifier

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

the class NodeBlockProcessorTest method processSkeletonRequestWithThreeResults.

@Test
public void processSkeletonRequestWithThreeResults() throws UnknownHostException {
    int skeletonStep = 192;
    final Blockchain blockchain = new BlockChainBuilder().ofSize(300);
    final NetBlockStore store = new NetBlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    TestSystemProperties config = new TestSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    final SimplePeer sender = new SimplePeer();
    processor.processSkeletonRequest(sender, 100, 5);
    Assert.assertFalse(sender.getMessages().isEmpty());
    Assert.assertEquals(1, sender.getMessages().size());
    final Message message = sender.getMessages().get(0);
    Assert.assertEquals(MessageType.SKELETON_RESPONSE_MESSAGE, message.getMessageType());
    final SkeletonResponseMessage bMessage = (SkeletonResponseMessage) message;
    Assert.assertEquals(100, bMessage.getId());
    Block b1 = blockchain.getBlockByNumber(0);
    Block b2 = blockchain.getBlockByNumber(skeletonStep);
    Block b3 = blockchain.getBestBlock();
    BlockIdentifier[] expected = { new BlockIdentifier(b1.getHash().getBytes(), b1.getNumber()), new BlockIdentifier(b2.getHash().getBytes(), b2.getNumber()), new BlockIdentifier(b3.getHash().getBytes(), b3.getNumber()) };
    assertBlockIdentifiers(expected, bMessage.getBlockIdentifiers());
}
Also used : BlockIdentifier(org.ethereum.core.BlockIdentifier) Blockchain(org.ethereum.core.Blockchain) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) Block(org.ethereum.core.Block) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 20 with BlockIdentifier

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

the class NodeBlockProcessorTest method processSkeletonRequestNotIncludingGenesis.

@Test
public void processSkeletonRequestNotIncludingGenesis() throws UnknownHostException {
    int skeletonStep = 192;
    final Blockchain blockchain = new BlockChainBuilder().ofSize(400);
    final NetBlockStore store = new NetBlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    TestSystemProperties config = new TestSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    final SimplePeer sender = new SimplePeer();
    processor.processSkeletonRequest(sender, 100, skeletonStep + 5);
    Assert.assertFalse(sender.getMessages().isEmpty());
    Assert.assertEquals(1, sender.getMessages().size());
    final Message message = sender.getMessages().get(0);
    Assert.assertEquals(MessageType.SKELETON_RESPONSE_MESSAGE, message.getMessageType());
    final SkeletonResponseMessage bMessage = (SkeletonResponseMessage) message;
    Assert.assertEquals(100, bMessage.getId());
    Block b1 = blockchain.getBlockByNumber(skeletonStep);
    Block b2 = blockchain.getBlockByNumber(2 * skeletonStep);
    Block b3 = blockchain.getBestBlock();
    BlockIdentifier[] expected = { new BlockIdentifier(b1.getHash().getBytes(), b1.getNumber()), new BlockIdentifier(b2.getHash().getBytes(), b2.getNumber()), new BlockIdentifier(b3.getHash().getBytes(), b3.getNumber()) };
    assertBlockIdentifiers(expected, bMessage.getBlockIdentifiers());
}
Also used : BlockIdentifier(org.ethereum.core.BlockIdentifier) Blockchain(org.ethereum.core.Blockchain) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) Block(org.ethereum.core.Block) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Aggregations

BlockIdentifier (org.ethereum.core.BlockIdentifier)21 Block (org.ethereum.core.Block)14 Test (org.junit.Test)10 TestSystemProperties (co.rsk.config.TestSystemProperties)6 SimplePeer (co.rsk.net.simples.SimplePeer)5 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)5 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)5 Blockchain (org.ethereum.core.Blockchain)5 RskSystemProperties (co.rsk.config.RskSystemProperties)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 Nonnull (javax.annotation.Nonnull)4 Transaction (org.ethereum.core.Transaction)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 NodeID (co.rsk.net.NodeID)3 co.rsk.net.messages (co.rsk.net.messages)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 TimeUnit (java.util.concurrent.TimeUnit)3 Nullable (javax.annotation.Nullable)3