use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class ThreeAsyncNodeUsingSyncProcessorTest method synchronizeWithTwoPeers200AndOneFails.
@Test
public void synchronizeWithTwoPeers200AndOneFails() {
Blockchain b1 = BlockChainBuilder.ofSize(200, true);
Blockchain b2 = BlockChainBuilder.ofSize(0, true);
SimpleAsyncNode node1 = SimpleAsyncNode.createDefaultNode(b1);
SimpleAsyncNode node2 = SimpleAsyncNode.createDefaultNode(b1);
SyncConfiguration syncConfiguration = new SyncConfiguration(2, 1, 0, 1, 20, 192);
SimpleAsyncNode node3 = SimpleAsyncNode.createNode(b2, syncConfiguration);
Assert.assertEquals(200, node1.getBestBlock().getNumber());
Assert.assertEquals(200, node2.getBestBlock().getNumber());
Assert.assertEquals(0, node3.getBestBlock().getNumber());
node1.sendFullStatusTo(node3);
node2.sendFullStatusTo(node3);
// sync setup
int setupRequests = SyncUtils.syncSetupRequests(200, 0, SyncConfiguration.IMMEDIATE_FOR_TESTING);
node3.waitUntilNTasksWithTimeout(setupRequests);
node3.waitUntilNTasksWithTimeout(5);
// synchronize 200 (extra tasks are from old sync protocol messages)
BodyResponseMessage response = new BodyResponseMessage(new Random().nextLong(), null, null);
node3.getSyncProcessor().registerExpectedMessage(response);
node3.getSyncProcessor().processBodyResponse(node1.getMessageChannel(node3), response);
node3.waitExactlyNTasksWithTimeout(200 + setupRequests - 15);
Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertEquals(200, node3.getBestBlock().getNumber());
Assert.assertEquals(node1.getBestBlock().getHash(), node3.getBestBlock().getHash());
Assert.assertTrue(node1.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertTrue(node2.getSyncProcessor().getExpectedResponses().isEmpty());
Assert.assertTrue(node3.getSyncProcessor().getExpectedResponses().isEmpty());
node1.joinWithTimeout();
node2.joinWithTimeout();
node3.joinWithTimeout();
Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
Assert.assertFalse(node1.getSyncProcessor().isPeerSyncing(node3.getNodeID()));
Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node3.getNodeID()));
Assert.assertFalse(node3.getSyncProcessor().isPeerSyncing(node1.getNodeID()));
Assert.assertFalse(node2.getSyncProcessor().isPeerSyncing(node2.getNodeID()));
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class TwoAsyncNodeTest method createNodeWithUncles.
private static SimpleAsyncNode createNodeWithUncles(int size) {
final World world = new World();
final BlockStore store = new BlockStore();
final Blockchain blockchain = world.getBlockChain();
List<Block> blocks = new BlockGenerator().getBlockChain(blockchain.getBestBlock(), size, 0, true);
for (Block b : blocks) blockchain.tryToConnect(b);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
NodeMessageHandler handler = new NodeMessageHandler(config, processor, null, null, null, null, null, new DummyBlockValidationRule());
return new SimpleAsyncNode(handler);
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class TwoNodeTest method createNode.
private static SimpleNode createNode(int size) {
final World world = new World();
final BlockStore store = new BlockStore();
final Blockchain blockchain = world.getBlockChain();
List<Block> blocks = new BlockGenerator().getBlockChain(blockchain.getBestBlock(), size);
for (Block b : blocks) blockchain.tryToConnect(b);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
RskSystemProperties config = new RskSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
NodeMessageHandler handler = new NodeMessageHandler(new RskSystemProperties(), processor, null, null, null, null, null, new DummyBlockValidationRule());
return new SimpleNode(handler);
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class SimpleAsyncNode method createNodeWithWorldBlockChain.
public static SimpleAsyncNode createNodeWithWorldBlockChain(int size, boolean withUncles, boolean mining) {
final World world = new World();
final Blockchain blockchain = world.getBlockChain();
BlockChainBuilder.extend(blockchain, size, withUncles, mining);
return createNode(blockchain, SyncConfiguration.IMMEDIATE_FOR_TESTING);
}
use of org.ethereum.core.Blockchain in project rskj by rsksmart.
the class SelectionRuleTest method addBlockTest.
@Test
public void addBlockTest() {
Blockchain blockchain = createBlockchain();
BlockGenerator blockGenerator = new BlockGenerator();
Block lowDifficultyBlock = blockGenerator.createChildBlock(blockchain.getBestBlock(), 0, 1);
Block highDifficultyBlock = blockGenerator.createChildBlock(lowDifficultyBlock, 0, 5);
Block highDifficultyBlockWithMoreFees = blockGenerator.createChildBlock(lowDifficultyBlock, 10L, new ArrayList<>(), highDifficultyBlock.getDifficulty().getBytes());
// diff test
assertFalse(SelectionRule.shouldWeAddThisBlock(lowDifficultyBlock.getDifficulty(), highDifficultyBlock.getDifficulty(), lowDifficultyBlock, highDifficultyBlock));
assertTrue(SelectionRule.shouldWeAddThisBlock(highDifficultyBlock.getDifficulty(), lowDifficultyBlock.getDifficulty(), highDifficultyBlock, lowDifficultyBlock));
// At same difficulty, more fees
assertTrue(SelectionRule.shouldWeAddThisBlock(highDifficultyBlockWithMoreFees.getDifficulty(), highDifficultyBlock.getDifficulty(), highDifficultyBlockWithMoreFees, highDifficultyBlock));
// Low hash is proved in smallerBlockHashTest
}
Aggregations