Search in sources :

Example 51 with SimplePeer

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

the class NodeMessageHandlerTest method skipAdvancedBlock.

@Test
public void skipAdvancedBlock() throws UnknownHostException {
    SimplePeer sender = new SimplePeer();
    PeerScoringManager scoring = createPeerScoringManager();
    SimpleBlockProcessor sbp = new SimpleBlockProcessor();
    sbp.setBlockGap(100000);
    NodeMessageHandler processor = new NodeMessageHandler(config, sbp, null, null, null, scoring, mock(StatusResolver.class));
    Block block = new BlockGenerator().createBlock(200000, 0);
    Message message = new BlockMessage(block);
    processor.processMessage(sender, message);
    Assert.assertNotNull(sbp.getBlocks());
    Assert.assertEquals(0, sbp.getBlocks().size());
    Assert.assertTrue(scoring.isEmpty());
    PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
    Assert.assertNotNull(pscoring);
    Assert.assertTrue(pscoring.isEmpty());
}
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 52 with SimplePeer

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

the class NodeMessageHandlerTest method postBlockMessageFromBannedMiner.

@Test
public void postBlockMessageFromBannedMiner() {
    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 bannedMiner = block.getCoinbase();
    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(0, 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 53 with SimplePeer

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

the class DecidingSyncStateTest method doesntStartSyncingIfAllPeersHaveLowerDifficulty.

@Test
public void doesntStartSyncingIfAllPeersHaveLowerDifficulty() {
    SyncConfiguration syncConfiguration = SyncConfiguration.DEFAULT;
    SimpleSyncEventsHandler syncEventsHandler = new SimpleSyncEventsHandler();
    PeerScoringManager peerScoringManager = RskMockFactory.getPeerScoringManager();
    Blockchain blockchain = mock(Blockchain.class);
    PeersInformation knownPeers = new PeersInformation(RskMockFactory.getChannelManager(), syncConfiguration, blockchain, peerScoringManager);
    SyncState syncState = new DecidingSyncState(syncConfiguration, syncEventsHandler, knownPeers, mock(BlockStore.class));
    Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
    knownPeers.registerPeer(new SimplePeer(new NodeID(HashUtil.randomPeerId())));
    syncState.newPeerStatus();
    syncState.tick(Duration.ofMinutes(2));
    Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) BlockStore(org.ethereum.db.BlockStore) Blockchain(org.ethereum.core.Blockchain) NodeID(co.rsk.net.NodeID) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

Example 54 with SimplePeer

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

the class DecidingSyncStateTest method doesntStartSyncingIfAllPeersHaveBadReputation.

@Test
public void doesntStartSyncingIfAllPeersHaveBadReputation() {
    SyncConfiguration syncConfiguration = SyncConfiguration.DEFAULT;
    SimpleSyncEventsHandler syncEventsHandler = new SimpleSyncEventsHandler();
    PeerScoringManager peerScoringManager = RskMockFactory.getPeerScoringManager();
    Blockchain blockchain = mock(Blockchain.class);
    PeersInformation knownPeers = new PeersInformation(RskMockFactory.getChannelManager(), syncConfiguration, blockchain, peerScoringManager);
    SyncState syncState = new DecidingSyncState(syncConfiguration, syncEventsHandler, knownPeers, mock(BlockStore.class));
    Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
    knownPeers.registerPeer(new SimplePeer(new NodeID(HashUtil.randomPeerId())));
    syncState.newPeerStatus();
    syncState.tick(Duration.ofMinutes(2));
    Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) BlockStore(org.ethereum.db.BlockStore) Blockchain(org.ethereum.core.Blockchain) NodeID(co.rsk.net.NodeID) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

Example 55 with SimplePeer

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

the class DecidingSyncStateTest method doesntStartSyncingWith1PeerBeforeTimeout.

@Test
public void doesntStartSyncingWith1PeerBeforeTimeout() {
    SyncConfiguration syncConfiguration = SyncConfiguration.DEFAULT;
    SimpleSyncEventsHandler syncEventsHandler = new SimpleSyncEventsHandler();
    PeerScoringManager peerScoringManager = RskMockFactory.getPeerScoringManager();
    Blockchain blockchain = mock(Blockchain.class);
    PeersInformation knownPeers = new PeersInformation(RskMockFactory.getChannelManager(), syncConfiguration, blockchain, peerScoringManager);
    SyncState syncState = new DecidingSyncState(syncConfiguration, syncEventsHandler, knownPeers, mock(BlockStore.class));
    Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
    knownPeers.registerPeer(new SimplePeer(new NodeID(HashUtil.randomPeerId())));
    syncState.newPeerStatus();
    syncState.tick(syncConfiguration.getTimeoutWaitingPeers().minusSeconds(1L));
    Assert.assertFalse(syncEventsHandler.startSyncingWasCalled());
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) BlockStore(org.ethereum.db.BlockStore) Blockchain(org.ethereum.core.Blockchain) NodeID(co.rsk.net.NodeID) SimplePeer(co.rsk.net.simples.SimplePeer) Test(org.junit.Test)

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