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);
}
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);
}
}
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);
}
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());
}
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);
}
Aggregations