Search in sources :

Example 1 with BlockMessage

use of co.rsk.net.messages.BlockMessage in project rskj by rsksmart.

the class OneAsyncNodeTest method buildBlockchainInReverse.

@Test
public void buildBlockchainInReverse() throws InterruptedException {
    SimpleAsyncNode node = createNode();
    List<Block> blocks = new BlockGenerator().getBlockChain(getGenesis(), 10);
    List<Block> reverse = new ArrayList<>();
    for (Block block : blocks) reverse.add(0, block);
    for (Block block : reverse) node.receiveMessageFrom(null, new BlockMessage(block));
    node.waitExactlyNTasksWithTimeout(10);
    node.joinWithTimeout();
    Assert.assertEquals(blocks.size(), node.getBestBlock().getNumber());
    Assert.assertEquals(blocks.get(blocks.size() - 1).getHash(), node.getBestBlock().getHash());
}
Also used : BlockMessage(co.rsk.net.messages.BlockMessage) SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 2 with BlockMessage

use of co.rsk.net.messages.BlockMessage in project rskj by rsksmart.

the class OneNodeTest method buildBlockchainInReverse.

@Test
public void buildBlockchainInReverse() {
    SimpleNode node = SimpleNode.createNode();
    List<Block> blocks = new BlockGenerator().getBlockChain(getGenesis(), 10);
    List<Block> reverse = new ArrayList<>();
    for (Block block : blocks) reverse.add(0, block);
    for (Block block : reverse) node.receiveMessageFrom(null, new BlockMessage(block));
    Assert.assertEquals(blocks.size(), node.getBestBlock().getNumber());
    Assert.assertEquals(blocks.get(blocks.size() - 1).getHash(), node.getBestBlock().getHash());
}
Also used : BlockMessage(co.rsk.net.messages.BlockMessage) ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimpleNode(co.rsk.net.simples.SimpleNode) Test(org.junit.Test)

Example 3 with BlockMessage

use of co.rsk.net.messages.BlockMessage in project rskj by rsksmart.

the class TwoNodeTest method buildBlockchainPartialAndSynchronize.

@Test
@Ignore
public void buildBlockchainPartialAndSynchronize() {
    SimpleNode node1 = createNode(0);
    SimpleNode node2 = createNode(0);
    List<Block> blocks = new BlockGenerator().getBlockChain(10);
    for (Block block : blocks) {
        BlockMessage message = new BlockMessage(block);
        node1.receiveMessageFrom(null, message);
        if (block.getNumber() <= 5)
            node2.receiveMessageFrom(null, message);
    }
    node1.sendStatusTo(node2);
    Assert.assertEquals(10, node1.getBestBlock().getNumber());
    Assert.assertEquals(10, node2.getBestBlock().getNumber());
    Assert.assertEquals(node1.getBestBlock().getHash(), node2.getBestBlock().getHash());
}
Also used : BlockMessage(co.rsk.net.messages.BlockMessage) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SimpleNode(co.rsk.net.simples.SimpleNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with BlockMessage

use of co.rsk.net.messages.BlockMessage in project rskj by rsksmart.

the class RskWireProtocol method channelRead0.

@Override
public void channelRead0(final ChannelHandlerContext ctx, EthMessage msg) throws InterruptedException {
    super.channelRead0(ctx, msg);
    if (this.messageRecorder != null) {
        this.messageRecorder.recordMessage(messageSender.getPeerNodeID(), msg);
    }
    if (!hasGoodReputation(ctx)) {
        ctx.disconnect();
        return;
    }
    Metrics.messageBytes(messageSender.getPeerNodeID(), msg.getEncoded().length);
    switch(msg.getCommand()) {
        case STATUS:
            processStatus((org.ethereum.net.eth.message.StatusMessage) msg, ctx);
            break;
        case RSK_MESSAGE:
            RskMessage rskmessage = (RskMessage) msg;
            Message message = rskmessage.getMessage();
            switch(message.getMessageType()) {
                case BLOCK_MESSAGE:
                    loggerNet.trace("RSK Block Message: Block {} {} from {}", ((BlockMessage) message).getBlock().getNumber(), ((BlockMessage) message).getBlock().getShortHash(), this.messageSender.getPeerNodeID());
                    syncStats.addBlocks(1);
                    break;
                case GET_BLOCK_MESSAGE:
                    loggerNet.trace("RSK Get Block Message: Block {} from {}", Hex.toHexString(((GetBlockMessage) message).getBlockHash()).substring(0, 10), this.messageSender.getPeerNodeID());
                    syncStats.getBlock();
                    break;
                case STATUS_MESSAGE:
                    loggerNet.trace("RSK Status Message: Block {} {} from {}", ((StatusMessage) message).getStatus().getBestBlockNumber(), Hex.toHexString(((StatusMessage) message).getStatus().getBestBlockHash()).substring(0, 10), this.messageSender.getPeerNodeID());
                    syncStats.addStatus();
                    break;
            }
            if (this.messageHandler != null) {
                this.messageHandler.postMessage(this.messageSender, rskmessage.getMessage());
            }
            break;
        default:
            break;
    }
}
Also used : BlockMessage(co.rsk.net.messages.BlockMessage) GetBlockMessage(co.rsk.net.messages.GetBlockMessage) StatusMessage(co.rsk.net.messages.StatusMessage) Message(co.rsk.net.messages.Message) BlockMessage(co.rsk.net.messages.BlockMessage) EthMessage(org.ethereum.net.eth.message.EthMessage) GetBlockMessage(co.rsk.net.messages.GetBlockMessage) TransactionsMessage(org.ethereum.net.eth.message.TransactionsMessage) co.rsk.net(co.rsk.net) StatusMessage(co.rsk.net.messages.StatusMessage)

Example 5 with BlockMessage

use of co.rsk.net.messages.BlockMessage in project rskj by rsksmart.

the class OneAsyncNodeTest method buildBlockchain.

@Test
public void buildBlockchain() throws InterruptedException {
    SimpleAsyncNode node = createNode();
    List<Block> blocks = new BlockGenerator().getBlockChain(getGenesis(), 10);
    for (Block block : blocks) node.receiveMessageFrom(null, new BlockMessage(block));
    node.waitExactlyNTasksWithTimeout(10);
    node.joinWithTimeout();
    Assert.assertEquals(blocks.size(), node.getBestBlock().getNumber());
    Assert.assertEquals(blocks.get(blocks.size() - 1).getHash(), node.getBestBlock().getHash());
}
Also used : BlockMessage(co.rsk.net.messages.BlockMessage) SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Aggregations

BlockMessage (co.rsk.net.messages.BlockMessage)8 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)7 Block (org.ethereum.core.Block)7 Test (org.junit.Test)7 SimpleAsyncNode (co.rsk.net.simples.SimpleAsyncNode)4 SimpleNode (co.rsk.net.simples.SimpleNode)3 ArrayList (java.util.ArrayList)2 Ignore (org.junit.Ignore)2 co.rsk.net (co.rsk.net)1 GetBlockMessage (co.rsk.net.messages.GetBlockMessage)1 Message (co.rsk.net.messages.Message)1 StatusMessage (co.rsk.net.messages.StatusMessage)1 EthMessage (org.ethereum.net.eth.message.EthMessage)1 TransactionsMessage (org.ethereum.net.eth.message.TransactionsMessage)1