Search in sources :

Example 6 with SimpleBlockProcessor

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

the class NodeMessageHandlerTest method processBlockHeadersRequestMessageUsingProcessor.

@Test
public void processBlockHeadersRequestMessageUsingProcessor() throws UnknownHostException {
    byte[] hash = HashUtil.randomHash();
    SimpleBlockProcessor sbp = new SimpleBlockProcessor();
    NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, null, null, new ProofOfWorkRule(config).setFallbackMiningEnabled(false));
    Message message = new BlockHeadersRequestMessage(100, hash, 50);
    processor.processMessage(new SimpleMessageChannel(), message);
    Assert.assertEquals(100, sbp.getRequestId());
    Assert.assertArrayEquals(hash, sbp.getHash());
}
Also used : SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Test(org.junit.Test)

Example 7 with SimpleBlockProcessor

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

the class NodeMessageHandlerTest method processMissingPoWBlockMessageUsingProcessor.

@Test
public void processMissingPoWBlockMessageUsingProcessor() throws UnknownHostException {
    SimpleMessageChannel sender = new SimpleMessageChannel();
    PeerScoringManager scoring = createPeerScoringManager();
    SimpleBlockProcessor sbp = new SimpleBlockProcessor();
    NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, null, scoring, new DummyBlockValidationRule());
    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) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) DummyBlockValidationRule(co.rsk.validators.DummyBlockValidationRule) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 8 with SimpleBlockProcessor

use of co.rsk.net.simples.SimpleBlockProcessor 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 {
    SimpleMessageChannel sender = new SimpleMessageChannel();
    PeerScoringManager scoring = createPeerScoringManager();
    SimpleBlockProcessor sbp = new SimpleBlockProcessor();
    NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, null, scoring, new ProofOfWorkRule(config).setFallbackMiningEnabled(false));
    Block block = 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) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Ignore(org.junit.Ignore)

Example 9 with SimpleBlockProcessor

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

the class NodeMessageHandlerTest method processFutureBlockMessageUsingProcessor.

@Test
public void processFutureBlockMessageUsingProcessor() throws UnknownHostException {
    SimpleBlockProcessor sbp = new SimpleBlockProcessor();
    NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, null, null, new ProofOfWorkRule(config).setFallbackMiningEnabled(false));
    Block block = new BlockGenerator().getGenesisBlock();
    Message message = new BlockMessage(block);
    SimpleMessageChannel sender = new SimpleMessageChannel();
    processor.processMessage(sender, message);
    Assert.assertNotNull(sbp.getBlocks());
    Assert.assertEquals(0, sbp.getBlocks().size());
}
Also used : SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Test(org.junit.Test)

Example 10 with SimpleBlockProcessor

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

the class NodeMessageHandlerTest method processBlockMessageUsingProcessor.

@Test
public void processBlockMessageUsingProcessor() throws UnknownHostException {
    SimpleMessageChannel sender = new SimpleMessageChannel();
    PeerScoringManager scoring = createPeerScoringManager();
    SimpleBlockProcessor sbp = new SimpleBlockProcessor();
    NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, null, scoring, new ProofOfWorkRule(config).setFallbackMiningEnabled(false));
    Block block = BlockChainBuilder.ofSize(1, true).getBestBlock();
    Message message = new BlockMessage(block);
    processor.processMessage(sender, message);
    Assert.assertNotNull(sbp.getBlocks());
    Assert.assertEquals(1, sbp.getBlocks().size());
    Assert.assertSame(block, sbp.getBlocks().get(0));
    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));
    pscoring = scoring.getPeerScoring(sender.getAddress());
    Assert.assertNotNull(pscoring);
    Assert.assertFalse(pscoring.isEmpty());
    Assert.assertEquals(1, pscoring.getTotalEventCounter());
    Assert.assertEquals(1, pscoring.getEventCounter(EventType.VALID_BLOCK));
}
Also used : PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Test(org.junit.Test)

Aggregations

SimpleBlockProcessor (co.rsk.net.simples.SimpleBlockProcessor)12 Test (org.junit.Test)11 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)10 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)7 PeerScoring (co.rsk.scoring.PeerScoring)6 PeerScoringManager (co.rsk.scoring.PeerScoringManager)6 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)4 DummyBlockValidationRule (co.rsk.validators.DummyBlockValidationRule)3 World (co.rsk.test.World)2 Ignore (org.junit.Ignore)1