Search in sources :

Example 11 with DifficultyCalculator

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

the class Web3ImplSnapshotTest method getMinerServerForTest.

private MinerServer getMinerServerForTest(SimpleEthereum ethereum, MinerClock clock) {
    BlockValidationRule rule = new MinerManagerTest.BlockValidationRuleDummy();
    DifficultyCalculator difficultyCalculator = new DifficultyCalculator(config.getActivationConfig(), config.getNetworkConstants());
    MiningConfig miningConfig = ConfigUtils.getDefaultMiningConfig();
    return new MinerServerImpl(config, ethereum, mainchainView, factory.getNodeBlockProcessor(), new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new BlockToMineBuilder(config.getActivationConfig(), miningConfig, factory.getRepositoryLocator(), factory.getBlockStore(), factory.getTransactionPool(), difficultyCalculator, new GasLimitCalculator(config.getNetworkConstants()), new ForkDetectionDataCalculator(), rule, clock, blockFactory, factory.getBlockExecutor(), new MinimumGasPriceCalculator(Coin.valueOf(miningConfig.getMinGasPriceTarget())), new MinerUtils()), clock, blockFactory, new BuildInfo("cb7f28e", "master"), miningConfig);
}
Also used : DifficultyCalculator(co.rsk.core.DifficultyCalculator) MiningConfig(co.rsk.config.MiningConfig) BuildInfo(org.ethereum.util.BuildInfo) BlockValidationRule(co.rsk.validators.BlockValidationRule) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule)

Example 12 with DifficultyCalculator

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

the class OneAsyncNodeTest method createNode.

private static SimpleAsyncNode createNode() {
    final World world = new World();
    final NetBlockStore store = new NetBlockStore();
    final Blockchain blockchain = world.getBlockChain();
    TestSystemProperties config = new TestSystemProperties();
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
    NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
    SimpleChannelManager channelManager = new SimpleChannelManager();
    SyncProcessor syncProcessor = new SyncProcessor(blockchain, mock(org.ethereum.db.BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, syncConfiguration, new BlockFactory(config.getActivationConfig()), new DummyBlockValidationRule(), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), new DifficultyCalculator(config.getActivationConfig(), config.getNetworkConstants()), new PeersInformation(channelManager, syncConfiguration, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
    NodeMessageHandler handler = new NodeMessageHandler(config, processor, syncProcessor, channelManager, null, RskMockFactory.getPeerScoringManager(), mock(StatusResolver.class));
    return new SimpleAsyncNode(handler, blockchain, syncProcessor, channelManager);
}
Also used : EthereumListener(org.ethereum.listener.EthereumListener) BlockFactory(org.ethereum.core.BlockFactory) Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) SimpleAsyncNode(co.rsk.net.simples.SimpleAsyncNode) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) DifficultyCalculator(co.rsk.core.DifficultyCalculator) PeersInformation(co.rsk.net.sync.PeersInformation) Genesis(org.ethereum.core.Genesis) TestSystemProperties(co.rsk.config.TestSystemProperties)

Example 13 with DifficultyCalculator

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

the class BlockDifficultyValidationRuleTest method testDifficulty.

@Test
public void testDifficulty() {
    DifficultyCalculator difficultyCalculator = new DifficultyCalculator(activationConfig, networkConstants);
    BlockDifficultyRule validationRule = new BlockDifficultyRule(difficultyCalculator);
    Block block = Mockito.mock(Block.class);
    Block parent = Mockito.mock(Block.class);
    long parentTimestamp = 0;
    long blockTimeStamp = 10;
    BlockDifficulty parentDifficulty = new BlockDifficulty(new BigInteger("2048"));
    BlockDifficulty blockDifficulty = new BlockDifficulty(new BigInteger("2049"));
    // blockDifficulty = blockDifficulty.add(AbstractConfig.getConstants().getDifficultyBoundDivisor());
    Mockito.when(block.getDifficulty()).thenReturn(blockDifficulty);
    BlockHeader blockHeader = getEmptyHeader(blockDifficulty, blockTimeStamp, 1);
    BlockHeader parentHeader = Mockito.mock(BlockHeader.class);
    Mockito.when(parentHeader.getDifficulty()).thenReturn(parentDifficulty);
    Mockito.when(block.getHeader()).thenReturn(blockHeader);
    Mockito.when(parent.getHeader()).thenReturn(parentHeader);
    Mockito.when(parent.getDifficulty()).thenReturn(parentDifficulty);
    Mockito.when(parent.getTimestamp()).thenReturn(parentTimestamp);
    Assert.assertEquals(validationRule.isValid(block, parent), true);
}
Also used : DifficultyCalculator(co.rsk.core.DifficultyCalculator) BlockDifficulty(co.rsk.core.BlockDifficulty) Block(org.ethereum.core.Block) BigInteger(java.math.BigInteger) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

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