Search in sources :

Example 6 with DifficultyCalculator

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

the class MinerManagerTest method getMinerServer.

private MinerServerImpl getMinerServer() {
    SimpleEthereum ethereum = new SimpleEthereum();
    ethereum.blockchain = blockchain;
    DifficultyCalculator difficultyCalculator = new DifficultyCalculator(config.getActivationConfig(), config.getNetworkConstants());
    MinerClock clock = new MinerClock(true, Clock.systemUTC());
    MiningConfig miningConfig = ConfigUtils.getDefaultMiningConfig();
    return new MinerServerImpl(config, ethereum, miningMainchainView, null, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new BlockToMineBuilder(config.getActivationConfig(), miningConfig, repositoryLocator, blockStore, transactionPool, difficultyCalculator, new GasLimitCalculator(config.getNetworkConstants()), new ForkDetectionDataCalculator(), new BlockValidationRuleDummy(), clock, blockFactory, blockExecutor, new MinimumGasPriceCalculator(Coin.valueOf(miningConfig.getMinGasPriceTarget())), new MinerUtils()), clock, blockFactory, new BuildInfo("cb7f28e", "master"), miningConfig);
}
Also used : ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) DifficultyCalculator(co.rsk.core.DifficultyCalculator) MiningConfig(co.rsk.config.MiningConfig) BuildInfo(org.ethereum.util.BuildInfo) SimpleEthereum(org.ethereum.rpc.Simples.SimpleEthereum)

Example 7 with DifficultyCalculator

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

the class LocalBasicTest method runJsonTest.

private void runJsonTest(String jsonName, ActivationConfig activationConfig, Constants networkConstants) throws IOException {
    BlockFactory blockFactory = new BlockFactory(activationConfig);
    String json = getJSON(jsonName);
    DifficultyTestSuite testSuite = new DifficultyTestSuite(json);
    for (DifficultyTestCase testCase : testSuite.getTestCases()) {
        logger.info("Running {}\n", testCase.getName());
        BlockHeader current = testCase.getCurrent(blockFactory);
        BlockHeader parent = testCase.getParent(blockFactory);
        BlockDifficulty calc = new DifficultyCalculator(activationConfig, networkConstants).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) BlockFactory(org.ethereum.core.BlockFactory) BlockHeader(org.ethereum.core.BlockHeader) DifficultyTestSuite(org.ethereum.jsontestsuite.DifficultyTestSuite)

Example 8 with DifficultyCalculator

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

the class BlockToMineBuilderTest method setUp.

@Before
public void setUp() {
    validationRules = mock(BlockValidationRule.class);
    RepositoryLocator repositoryLocator = mock(RepositoryLocator.class);
    StateRootHandler stateRootHandler = mock(StateRootHandler.class);
    MiningConfig miningConfig = mock(MiningConfig.class);
    DifficultyCalculator difficultyCalculator = mock(DifficultyCalculator.class);
    MinimumGasPriceCalculator minimumGasPriceCalculator = mock(MinimumGasPriceCalculator.class);
    MinerUtils minerUtils = mock(MinerUtils.class);
    activationConfig = mock(ActivationConfig.class);
    blockExecutor = mock(BlockExecutor.class);
    blockBuilder = new BlockToMineBuilder(activationConfig, miningConfig, repositoryLocator, mock(BlockStore.class), mock(TransactionPool.class), difficultyCalculator, new GasLimitCalculator(Constants.mainnet()), new ForkDetectionDataCalculator(), validationRules, mock(MinerClock.class), new BlockFactory(activationConfig), blockExecutor, minimumGasPriceCalculator, minerUtils);
    BlockDifficulty blockDifficulty = mock(BlockDifficulty.class);
    Repository snapshot = mock(Repository.class);
    GasLimitConfig gasLimitConfig = new GasLimitConfig(0, 0, false);
    when(minerUtils.getAllTransactions(any())).thenReturn(new ArrayList<>());
    when(minerUtils.filterTransactions(any(), any(), any(), any(), any())).thenReturn(new ArrayList<>());
    when(repositoryLocator.snapshotAt(any())).thenReturn(snapshot);
    when(minimumGasPriceCalculator.calculate(any())).thenReturn(mock(Coin.class));
    when(stateRootHandler.translate(any())).thenReturn(TestUtils.randomHash());
    when(miningConfig.getGasLimit()).thenReturn(gasLimitConfig);
    when(miningConfig.getUncleListLimit()).thenReturn(10);
    when(miningConfig.getCoinbaseAddress()).thenReturn(TestUtils.randomAddress());
    when(difficultyCalculator.calcDifficulty(any(), any())).thenReturn(blockDifficulty);
}
Also used : BlockExecutor(co.rsk.core.bc.BlockExecutor) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) RepositoryLocator(co.rsk.db.RepositoryLocator) StateRootHandler(co.rsk.db.StateRootHandler) MiningConfig(co.rsk.config.MiningConfig) DifficultyCalculator(co.rsk.core.DifficultyCalculator) BlockDifficulty(co.rsk.core.BlockDifficulty) Coin(co.rsk.core.Coin) GasLimitConfig(co.rsk.config.GasLimitConfig) BlockValidationRule(co.rsk.validators.BlockValidationRule) Before(org.junit.Before)

Example 9 with DifficultyCalculator

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

the class Web3ImplSnapshotTest method getMinerServerForTest.

static MinerServer getMinerServerForTest(World world, SimpleEthereum ethereum) {
    BlockValidationRule rule = new MinerManagerTest.BlockValidationRuleDummy();
    DifficultyCalculator difficultyCalculator = new DifficultyCalculator(config);
    return new MinerServerImpl(config, ethereum, world.getBlockChain(), world.getBlockProcessor(), difficultyCalculator, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new BlockToMineBuilder(ConfigUtils.getDefaultMiningConfig(), world.getBlockChain().getRepository(), world.getBlockChain().getBlockStore(), world.getBlockChain().getTransactionPool(), difficultyCalculator, new GasLimitCalculator(config), rule, config, null), ConfigUtils.getDefaultMiningConfig());
}
Also used : DifficultyCalculator(co.rsk.core.DifficultyCalculator) BlockValidationRule(co.rsk.validators.BlockValidationRule) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule)

Example 10 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, org.ethereum.db.BlockStore indexedBlockStore) {
    NetBlockStore blockStore = new NetBlockStore();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    BlockSyncService blockSyncService = new BlockSyncService(config, blockStore, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    NodeBlockProcessor processor = new NodeBlockProcessor(blockStore, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    DummyBlockValidationRule blockValidationRule = new DummyBlockValidationRule();
    PeerScoringManager peerScoringManager = RskMockFactory.getPeerScoringManager();
    SimpleChannelManager channelManager = new SimpleChannelManager();
    BlockFactory blockFactory = new BlockFactory(config.getActivationConfig());
    SyncProcessor syncProcessor = new SyncProcessor(blockchain, indexedBlockStore, mock(ConsensusValidationMainchainView.class), blockSyncService, syncConfiguration, blockFactory, blockValidationRule, new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), new DifficultyCalculator(config.getActivationConfig(), config.getNetworkConstants()), new PeersInformation(channelManager, syncConfiguration, blockchain, peerScoringManager), mock(Genesis.class), mock(EthereumListener.class));
    NodeMessageHandler handler = new NodeMessageHandler(config, processor, syncProcessor, channelManager, null, peerScoringManager, mock(StatusResolver.class));
    return new SimpleAsyncNode(handler, blockchain, syncProcessor, channelManager);
}
Also used : EthereumListener(org.ethereum.listener.EthereumListener) BlockFactory(org.ethereum.core.BlockFactory) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) DifficultyCalculator(co.rsk.core.DifficultyCalculator) PeersInformation(co.rsk.net.sync.PeersInformation) Genesis(org.ethereum.core.Genesis)

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