Search in sources :

Example 1 with DifficultyCalculator

use of co.rsk.core.DifficultyCalculator in project rskj by rsksmart.

the class MinerManagerTest method getMinerServer.

private static MinerServerImpl getMinerServer(Blockchain blockchain) {
    SimpleEthereum ethereum = new SimpleEthereum();
    ethereum.repository = blockchain.getRepository();
    ethereum.blockchain = blockchain;
    DifficultyCalculator difficultyCalculator = new DifficultyCalculator(config);
    return new MinerServerImpl(config, ethereum, blockchain, null, difficultyCalculator, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new BlockToMineBuilder(ConfigUtils.getDefaultMiningConfig(), blockchain.getRepository(), blockchain.getBlockStore(), blockchain.getTransactionPool(), difficultyCalculator, new GasLimitCalculator(config), new BlockValidationRuleDummy(), config, null), ConfigUtils.getDefaultMiningConfig());
}
Also used : DifficultyCalculator(co.rsk.core.DifficultyCalculator) SimpleEthereum(org.ethereum.rpc.Simples.SimpleEthereum) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule)

Example 2 with DifficultyCalculator

use of co.rsk.core.DifficultyCalculator in project rskj by rsksmart.

the class LocalBasicTest method runDifficultyTest.

@Test
public void runDifficultyTest() throws IOException, ParseException {
    config.setGenesisInfo("frontier.json");
    config.setBlockchainConfig(new MainNetConfig());
    String json = getJSON("difficulty");
    DifficultyTestSuite testSuite = new DifficultyTestSuite(json);
    for (DifficultyTestCase testCase : testSuite.getTestCases()) {
        logger.info("Running {}\n", testCase.getName());
        BlockHeader current = testCase.getCurrent();
        BlockHeader parent = testCase.getParent();
        BlockDifficulty calc = new DifficultyCalculator(config).calcDifficulty(current, parent);
        int c = calc.compareTo(parent.getDifficulty());
        if (c > 0)
            logger.info(" Difficulty increase test\n");
        else if (c < 0)
            logger.info(" Difficulty decrease test\n");
        else
            logger.info(" Difficulty without change test\n");
        assertEquals(testCase.getExpectedDifficulty(), calc);
    }
}
Also used : DifficultyTestCase(org.ethereum.jsontestsuite.DifficultyTestCase) BlockDifficulty(co.rsk.core.BlockDifficulty) DifficultyCalculator(co.rsk.core.DifficultyCalculator) MainNetConfig(org.ethereum.config.net.MainNetConfig) BlockHeader(org.ethereum.core.BlockHeader) DifficultyTestSuite(org.ethereum.jsontestsuite.DifficultyTestSuite) Test(org.junit.Test)

Example 3 with DifficultyCalculator

use of co.rsk.core.DifficultyCalculator in project rskj by rsksmart.

the class SimpleAsyncNode method createNode.

public static SimpleAsyncNode createNode(Blockchain blockchain, SyncConfiguration syncConfiguration) {
    final BlockStore store = new BlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
    NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    DummyBlockValidationRule blockValidationRule = new DummyBlockValidationRule();
    PeerScoringManager peerScoringManager = RskMockFactory.getPeerScoringManager();
    SimpleChannelManager channelManager = new SimpleChannelManager();
    SyncProcessor syncProcessor = new SyncProcessor(config, blockchain, blockSyncService, peerScoringManager, channelManager, syncConfiguration, blockValidationRule, new DifficultyCalculator(config));
    NodeMessageHandler handler = new NodeMessageHandler(config, processor, syncProcessor, channelManager, null, null, peerScoringManager, blockValidationRule);
    return new SimpleAsyncNode(handler, syncProcessor, channelManager);
}
Also used : PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) DifficultyCalculator(co.rsk.core.DifficultyCalculator) DummyBlockValidationRule(co.rsk.validators.DummyBlockValidationRule)

Example 4 with DifficultyCalculator

use of co.rsk.core.DifficultyCalculator in project rskj by rsksmart.

the class CommonConfigTest method createParentHeaderValidator.

@Test
public void createParentHeaderValidator() {
    CommonConfig config = new CommonConfig();
    ParentBlockHeaderValidator result = config.parentHeaderValidator(this.config, new DifficultyCalculator(this.config));
    Assert.assertNotNull(result);
}
Also used : DifficultyCalculator(co.rsk.core.DifficultyCalculator) CommonConfig(org.ethereum.config.CommonConfig) ParentBlockHeaderValidator(org.ethereum.validator.ParentBlockHeaderValidator) Test(org.junit.Test)

Example 5 with DifficultyCalculator

use of co.rsk.core.DifficultyCalculator in project rskj by rsksmart.

the class MainNetMinerTest method blockToMineBuilder.

private BlockToMineBuilder blockToMineBuilder() {
    BlockUnclesValidationRule unclesValidationRule = Mockito.mock(BlockUnclesValidationRule.class);
    when(unclesValidationRule.isValid(Mockito.any())).thenReturn(true);
    MinerClock clock = new MinerClock(true, Clock.systemUTC());
    MiningConfig miningConfig = ConfigUtils.getDefaultMiningConfig();
    return new BlockToMineBuilder(config.getActivationConfig(), miningConfig, repositoryLocator, blockStore, transactionPool, new DifficultyCalculator(config.getActivationConfig(), config.getNetworkConstants()), new GasLimitCalculator(config.getNetworkConstants()), new ForkDetectionDataCalculator(), unclesValidationRule, clock, blockFactory, blockExecutor, new MinimumGasPriceCalculator(Coin.valueOf(miningConfig.getMinGasPriceTarget())), new MinerUtils());
}
Also used : MiningConfig(co.rsk.config.MiningConfig) DifficultyCalculator(co.rsk.core.DifficultyCalculator) BlockUnclesValidationRule(co.rsk.validators.BlockUnclesValidationRule)

Aggregations

DifficultyCalculator (co.rsk.core.DifficultyCalculator)13 MiningConfig (co.rsk.config.MiningConfig)4 BlockDifficulty (co.rsk.core.BlockDifficulty)4 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)4 BlockValidationRule (co.rsk.validators.BlockValidationRule)3 BlockFactory (org.ethereum.core.BlockFactory)3 BlockHeader (org.ethereum.core.BlockHeader)3 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)3 Test (org.junit.Test)3 ConsensusValidationMainchainView (co.rsk.core.bc.ConsensusValidationMainchainView)2 PeersInformation (co.rsk.net.sync.PeersInformation)2 PeerScoringManager (co.rsk.scoring.PeerScoringManager)2 Genesis (org.ethereum.core.Genesis)2 DifficultyTestCase (org.ethereum.jsontestsuite.DifficultyTestCase)2 DifficultyTestSuite (org.ethereum.jsontestsuite.DifficultyTestSuite)2 EthereumListener (org.ethereum.listener.EthereumListener)2 SimpleEthereum (org.ethereum.rpc.Simples.SimpleEthereum)2 BuildInfo (org.ethereum.util.BuildInfo)2 GasLimitConfig (co.rsk.config.GasLimitConfig)1 TestSystemProperties (co.rsk.config.TestSystemProperties)1