Search in sources :

Example 71 with SimplePeer

use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.

the class NodeBlockProcessorTest method processGetBlockMessageUsingEmptyStore.

@Test
public void processGetBlockMessageUsingEmptyStore() throws UnknownHostException {
    final Block block = new BlockGenerator().getBlock(3);
    final NetBlockStore store = new NetBlockStore();
    final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
    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();
    Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).isEmpty());
    processor.processGetBlock(sender, block.getHash().getBytes());
    Assert.assertTrue(nodeInformation.getNodesByBlock(block.getHash()).isEmpty());
    Assert.assertTrue(sender.getMessages().isEmpty());
}
Also used : Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

Example 72 with SimplePeer

use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.

the class NodeBlockProcessorTest method processStatusRetrievingBestBlockUsingSender.

@Test
@Ignore("Ignored when Process status deleted on block processor")
public void processStatusRetrievingBestBlockUsingSender() throws UnknownHostException {
    final NetBlockStore store = new NetBlockStore();
    final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
    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();
    BlockGenerator blockGenerator = new BlockGenerator();
    final Block genesis = blockGenerator.getGenesisBlock();
    final Block block = blockGenerator.createChildBlock(genesis);
    // final Status status = new Status(block.getNumber(), block.getHash());
    // processor.processStatus(sender, status);
    Assert.assertTrue(processor.getNodeInformation().getNodesByBlock(block.getHash().getBytes()).size() == 1);
    Assert.assertEquals(1, sender.getGetBlockMessages().size());
    final Message message = sender.getGetBlockMessages().get(0);
    Assert.assertNotNull(message);
    Assert.assertEquals(MessageType.GET_BLOCK_MESSAGE, message.getMessageType());
    final GetBlockMessage gbMessage = (GetBlockMessage) message;
    Assert.assertArrayEquals(block.getHash().getBytes(), gbMessage.getBlockHash());
    Assert.assertEquals(0, store.size());
}
Also used : Blockchain(org.ethereum.core.Blockchain) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimplePeer(co.rsk.net.simples.SimplePeer) Block(org.ethereum.core.Block) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 73 with SimplePeer

use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.

the class NodeMessageHandlerTest method processMissingPoWBlockMessageUsingProcessor.

@Test
public void processMissingPoWBlockMessageUsingProcessor() throws UnknownHostException {
    SimplePeer sender = new SimplePeer();
    PeerScoringManager scoring = createPeerScoringManager();
    SimpleBlockProcessor sbp = new SimpleBlockProcessor();
    NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, scoring, mock(StatusResolver.class));
    BlockGenerator blockGenerator = new BlockGenerator();
    Block block = blockGenerator.getGenesisBlock();
    for (int i = 0; i < 50; i++) {
        block = blockGenerator.createChildBlock(block);
    }
    Message message = new BlockMessage(block);
    processor.processMessage(sender, message);
    Assert.assertNotNull(sbp.getBlocks());
    Assert.assertEquals(1, sbp.getBlocks().size());
    Assert.assertFalse(scoring.isEmpty());
    PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
    Assert.assertNotNull(pscoring);
    Assert.assertFalse(pscoring.isEmpty());
    Assert.assertEquals(1, pscoring.getTotalEventCounter());
    Assert.assertEquals(1, pscoring.getEventCounter(EventType.VALID_BLOCK));
    Assert.assertEquals(0, pscoring.getEventCounter(EventType.INVALID_BLOCK));
}
Also used : PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

Example 74 with SimplePeer

use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.

the class NodeMessageHandlerTest method postBlockMessageFromNonBannedMiner.

@Test
public void postBlockMessageFromNonBannedMiner() {
    RskSystemProperties config = spy(this.config);
    Peer sender = new SimplePeer();
    PeerScoringManager scoring = createPeerScoringManager();
    SimpleBlockProcessor sbp = new SimpleBlockProcessor();
    Block block = new BlockChainBuilder().ofSize(1, true).getBestBlock();
    Message message = new BlockMessage(block);
    RskAddress coinbase = block.getCoinbase();
    RskAddress bannedMiner = new RskAddress("0000000000000000000000000000000000000023");
    Assert.assertNotEquals(coinbase, bannedMiner);
    doReturn(Collections.singletonList(bannedMiner.toHexString())).when(config).bannedMinerList();
    NodeMessageHandler nodeMessageHandler = new NodeMessageHandler(config, sbp, null, null, null, scoring, mock(StatusResolver.class));
    nodeMessageHandler.postMessage(sender, message);
    Assert.assertEquals(1, nodeMessageHandler.getMessageQueueSize());
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) SimplePeer(co.rsk.net.simples.SimplePeer) RskAddress(co.rsk.core.RskAddress) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) RskSystemProperties(co.rsk.config.RskSystemProperties) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

Example 75 with SimplePeer

use of co.rsk.net.simples.SimplePeer in project rskj by rsksmart.

the class NodeMessageHandlerTest method processInvalidPoWMessageUsingProcessor.

// TODO: Difficulty in RegTest is so small that this test will sometimes pass and other times fail
// This should be executed in a special mode where difficulty is high.
@Ignore
public void processInvalidPoWMessageUsingProcessor() throws UnknownHostException {
    SimplePeer sender = new SimplePeer();
    PeerScoringManager scoring = createPeerScoringManager();
    SimpleBlockProcessor sbp = new SimpleBlockProcessor();
    NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, scoring, mock(StatusResolver.class));
    Block block = new BlockChainBuilder().ofSize(1, true).getBestBlock();
    byte[] mergedMiningHeader = block.getBitcoinMergedMiningHeader();
    // change merged mining nonce.
    mergedMiningHeader[76] += 3;
    Message message = new BlockMessage(block);
    processor.processMessage(sender, message);
    Assert.assertNotNull(sbp.getBlocks());
    Assert.assertEquals(0, sbp.getBlocks().size());
    Assert.assertFalse(scoring.isEmpty());
    PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
    Assert.assertNotNull(pscoring);
    Assert.assertFalse(pscoring.isEmpty());
    Assert.assertEquals(1, pscoring.getTotalEventCounter());
    Assert.assertEquals(1, pscoring.getEventCounter(EventType.INVALID_BLOCK));
}
Also used : PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) Ignore(org.junit.Ignore)

Aggregations

SimplePeer (co.rsk.net.simples.SimplePeer)109 Test (org.junit.Test)108 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)81 TestSystemProperties (co.rsk.config.TestSystemProperties)68 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)54 Blockchain (org.ethereum.core.Blockchain)49 Block (org.ethereum.core.Block)46 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)41 BlockStore (org.ethereum.db.BlockStore)28 ConsensusValidationMainchainView (co.rsk.core.bc.ConsensusValidationMainchainView)26 EthereumListener (org.ethereum.listener.EthereumListener)26 SimpleBlockProcessor (co.rsk.net.simples.SimpleBlockProcessor)19 PeerScoringManager (co.rsk.scoring.PeerScoringManager)16 Keccak256 (co.rsk.crypto.Keccak256)13 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)13 ChannelManager (org.ethereum.net.server.ChannelManager)11 PeerScoring (co.rsk.scoring.PeerScoring)10 World (co.rsk.test.World)8 Ignore (org.junit.Ignore)7 BlockBuilder (co.rsk.test.builders.BlockBuilder)6