Search in sources :

Example 11 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 = BlockChainBuilder.ofSize(300);
    final BlockStore store = new BlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    RskSystemProperties config = new RskSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
    final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    final SimpleMessageChannel sender = new SimpleMessageChannel();
    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) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) RskSystemProperties(co.rsk.config.RskSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 12 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 = BlockChainBuilder.ofSize(skeletonStep / 2);
    final Block blockStart = blockchain.getBlockByNumber(5);
    final Block blockEnd = blockchain.getBlockByNumber(skeletonStep / 2);
    final BlockStore store = new BlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    RskSystemProperties config = new RskSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
    final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    final SimpleMessageChannel sender = new SimpleMessageChannel();
    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) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) RskSystemProperties(co.rsk.config.RskSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 13 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 = BlockChainBuilder.ofSize(400);
    final BlockStore store = new BlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    RskSystemProperties config = new RskSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
    final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    final SimpleMessageChannel sender = new SimpleMessageChannel();
    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) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) RskSystemProperties(co.rsk.config.RskSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 14 with BlockIdentifier

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

the class NewBlockHashesMessage method encode.

private void encode() {
    List<byte[]> encodedElements = new ArrayList<>();
    for (BlockIdentifier identifier : blockIdentifiers) {
        encodedElements.add(identifier.getEncoded());
    }
    byte[][] encodedElementArray = encodedElements.toArray(new byte[encodedElements.size()][]);
    this.encoded = RLP.encodeList(encodedElementArray);
}
Also used : BlockIdentifier(org.ethereum.core.BlockIdentifier) ArrayList(java.util.ArrayList)

Example 15 with BlockIdentifier

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

the class NewBlockHashesTest method getMessageType.

@Test
public void getMessageType() {
    Block block = new BlockGenerator().getBlock(1);
    List<BlockIdentifier> blockIdentifierList = new LinkedList<>();
    blockIdentifierList.add(new BlockIdentifier(block.getHash().getBytes(), block.getNumber()));
    NewBlockHashesMessage message = new NewBlockHashesMessage(blockIdentifierList);
    Assert.assertEquals(MessageType.NEW_BLOCK_HASHES, message.getMessageType());
}
Also used : BlockIdentifier(org.ethereum.core.BlockIdentifier) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

BlockIdentifier (org.ethereum.core.BlockIdentifier)15 Block (org.ethereum.core.Block)9 Test (org.junit.Test)7 RskSystemProperties (co.rsk.config.RskSystemProperties)6 co.rsk.net.messages (co.rsk.net.messages)3 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)3 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 java.util (java.util)3 TimeUnit (java.util.concurrent.TimeUnit)3 Collectors (java.util.stream.Collectors)3 Nonnull (javax.annotation.Nonnull)3 Nullable (javax.annotation.Nullable)3 Blockchain (org.ethereum.core.Blockchain)3 Transaction (org.ethereum.core.Transaction)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Component (org.springframework.stereotype.Component)3 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)2