use of org.hyperledger.besu.ethereum.mainnet.PoWSolver in project besu by hyperledger.
the class PoWBlockCreatorTest method createMainnetBlock1_fixedDifficulty1.
@Test
public void createMainnetBlock1_fixedDifficulty1() {
final GenesisConfigOptions genesisConfigOptions = GenesisConfigFile.fromConfig("{\"config\": {\"ethash\": {\"fixeddifficulty\":1}}}").getConfigOptions();
final ExecutionContextTestFixture executionContextTestFixture = ExecutionContextTestFixture.builder().protocolSchedule(new ProtocolScheduleBuilder(genesisConfigOptions, BigInteger.valueOf(42), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, genesisConfigOptions.isQuorum(), EvmConfiguration.DEFAULT).createProtocolSchedule()).build();
final PoWSolver solver = new PoWSolver(Lists.newArrayList(BLOCK_1_NONCE), PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator(), 1000, 8);
final BaseFeePendingTransactionsSorter pendingTransactions = new BaseFeePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem, executionContextTestFixture.getProtocolContext().getBlockchain()::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);
final PoWBlockCreator blockCreator = new PoWBlockCreator(BLOCK_1_COINBASE, () -> Optional.empty(), parent -> BLOCK_1_EXTRA_DATA, pendingTransactions, executionContextTestFixture.getProtocolContext(), executionContextTestFixture.getProtocolSchedule(), solver, Wei.ZERO, 0.8, executionContextTestFixture.getBlockchain().getChainHeadHeader());
blockCreator.createBlock(BLOCK_1_TIMESTAMP);
// If we weren't setting difficulty to 2^256-1 a difficulty of 1 would have caused a
// IllegalArgumentException at the previous line, as 2^256 is 33 bytes.
}
use of org.hyperledger.besu.ethereum.mainnet.PoWSolver in project besu by hyperledger.
the class PoWBlockCreatorTest method rewardBeneficiary_zeroReward_skipZeroRewardsTrue.
@Test
public void rewardBeneficiary_zeroReward_skipZeroRewardsTrue() {
final GenesisConfigOptions genesisConfigOptions = GenesisConfigFile.fromConfig("{\"config\": {\"ethash\": {\"fixeddifficulty\":1}}}").getConfigOptions();
final ExecutionContextTestFixture executionContextTestFixture = ExecutionContextTestFixture.builder().protocolSchedule(new ProtocolScheduleBuilder(genesisConfigOptions, BigInteger.valueOf(42), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, genesisConfigOptions.isQuorum(), EvmConfiguration.DEFAULT).createProtocolSchedule()).build();
final PoWSolver solver = new PoWSolver(Lists.newArrayList(BLOCK_1_NONCE), PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator(), 1000, 8);
final BaseFeePendingTransactionsSorter pendingTransactions = new BaseFeePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem, executionContextTestFixture.getProtocolContext().getBlockchain()::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);
final PoWBlockCreator blockCreator = new PoWBlockCreator(BLOCK_1_COINBASE, () -> Optional.of(10_000_000L), parent -> BLOCK_1_EXTRA_DATA, pendingTransactions, executionContextTestFixture.getProtocolContext(), executionContextTestFixture.getProtocolSchedule(), solver, Wei.ZERO, 0.8, executionContextTestFixture.getBlockchain().getChainHeadHeader());
final MutableWorldState mutableWorldState = executionContextTestFixture.getStateArchive().getMutable();
assertThat(mutableWorldState.get(BLOCK_1_COINBASE)).isNull();
final ProcessableBlockHeader header = BlockHeaderBuilder.create().parentHash(Hash.ZERO).coinbase(BLOCK_1_COINBASE).difficulty(Difficulty.ONE).number(1).gasLimit(1).timestamp(1).buildProcessableBlockHeader();
blockCreator.rewardBeneficiary(mutableWorldState, header, Collections.emptyList(), BLOCK_1_COINBASE, Wei.ZERO, true);
assertThat(mutableWorldState.get(BLOCK_1_COINBASE)).isNull();
}
use of org.hyperledger.besu.ethereum.mainnet.PoWSolver in project besu by hyperledger.
the class PoWBlockCreatorTest method rewardBeneficiary_zeroReward_skipZeroRewardsFalse.
@Test
public void rewardBeneficiary_zeroReward_skipZeroRewardsFalse() {
final GenesisConfigOptions genesisConfigOptions = GenesisConfigFile.fromConfig("{\"config\": {\"ethash\": {\"fixeddifficulty\":1}}}").getConfigOptions();
final ExecutionContextTestFixture executionContextTestFixture = ExecutionContextTestFixture.builder().protocolSchedule(new ProtocolScheduleBuilder(genesisConfigOptions, BigInteger.valueOf(42), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, genesisConfigOptions.isQuorum(), EvmConfiguration.DEFAULT).createProtocolSchedule()).build();
final PoWSolver solver = new PoWSolver(Lists.newArrayList(BLOCK_1_NONCE), PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator(), 1000, 8);
final BaseFeePendingTransactionsSorter pendingTransactions = new BaseFeePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem, executionContextTestFixture.getProtocolContext().getBlockchain()::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);
final PoWBlockCreator blockCreator = new PoWBlockCreator(BLOCK_1_COINBASE, () -> Optional.of(10_000_000L), parent -> BLOCK_1_EXTRA_DATA, pendingTransactions, executionContextTestFixture.getProtocolContext(), executionContextTestFixture.getProtocolSchedule(), solver, Wei.ZERO, 0.8, executionContextTestFixture.getBlockchain().getChainHeadHeader());
final MutableWorldState mutableWorldState = executionContextTestFixture.getStateArchive().getMutable();
assertThat(mutableWorldState.get(BLOCK_1_COINBASE)).isNull();
final ProcessableBlockHeader header = BlockHeaderBuilder.create().parentHash(Hash.ZERO).coinbase(BLOCK_1_COINBASE).difficulty(Difficulty.ONE).number(1).gasLimit(1).timestamp(1).buildProcessableBlockHeader();
blockCreator.rewardBeneficiary(mutableWorldState, header, Collections.emptyList(), BLOCK_1_COINBASE, Wei.ZERO, false);
assertThat(mutableWorldState.get(BLOCK_1_COINBASE)).isNotNull();
assertThat(mutableWorldState.get(BLOCK_1_COINBASE).getBalance()).isEqualTo(Wei.ZERO);
}
use of org.hyperledger.besu.ethereum.mainnet.PoWSolver in project besu by hyperledger.
the class RetestethContext method buildContext.
private boolean buildContext(final String genesisConfigString, final String sealEngine, final Optional<Long> clockTime) {
final ObjectNode genesisConfig = normalizeKeys(JsonUtil.objectNodeFromString(genesisConfigString));
retestethClock = new RetestethClock();
clockTime.ifPresent(retestethClock::resetTime);
final MetricsSystem metricsSystem = new NoOpMetricsSystem();
final JsonGenesisConfigOptions jsonGenesisConfigOptions = JsonGenesisConfigOptions.fromJsonObject(JsonUtil.getObjectNode(genesisConfig, "config").get());
protocolSchedule = MainnetProtocolSchedule.fromConfig(jsonGenesisConfigOptions, EvmConfiguration.DEFAULT);
if ("NoReward".equalsIgnoreCase(sealEngine)) {
protocolSchedule = new NoRewardProtocolScheduleWrapper(protocolSchedule);
}
blockHeaderFunctions = ScheduleBasedBlockHeaderFunctions.create(protocolSchedule);
final GenesisState genesisState = GenesisState.fromJson(genesisConfigString, protocolSchedule);
coinbase = genesisState.getBlock().getHeader().getCoinbase();
extraData = genesisState.getBlock().getHeader().getExtraData();
final WorldStateArchive worldStateArchive = new DefaultWorldStateArchive(new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()), new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage()));
final MutableWorldState worldState = worldStateArchive.getMutable();
genesisState.writeStateTo(worldState);
blockchain = createInMemoryBlockchain(genesisState.getBlock());
protocolContext = new ProtocolContext(blockchain, worldStateArchive, null);
blockchainQueries = new BlockchainQueries(blockchain, worldStateArchive, ethScheduler);
final String sealengine = JsonUtil.getString(genesisConfig, "sealengine", "");
headerValidationMode = "NoProof".equals(sealengine) || "NoReward".equals(sealEngine) ? HeaderValidationMode.LIGHT : HeaderValidationMode.FULL;
final Iterable<Long> nonceGenerator = new IncrementingNonceGenerator(0);
poWSolver = ("NoProof".equals(sealengine) || "NoReward".equals(sealEngine)) ? new PoWSolver(nonceGenerator, NO_WORK_HASHER, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator(), 1000, 8) : new PoWSolver(nonceGenerator, PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator(), 1000, 8);
blockReplay = new BlockReplay(protocolSchedule, blockchainQueries.getBlockchain(), blockchainQueries.getWorldStateArchive());
// mining support
final EthPeers ethPeers = new EthPeers("reteseth", retestethClock, metricsSystem, 0);
final SyncState syncState = new SyncState(blockchain, ethPeers);
ethScheduler = new EthScheduler(1, 1, 1, 1, metricsSystem);
final EthContext ethContext = new EthContext(ethPeers, new EthMessages(), ethScheduler);
final TransactionPoolConfiguration transactionPoolConfiguration = ImmutableTransactionPoolConfiguration.builder().build();
transactionPool = TransactionPoolFactory.createTransactionPool(protocolSchedule, protocolContext, ethContext, retestethClock, metricsSystem, syncState, new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).build(), transactionPoolConfiguration);
if (LOG.isTraceEnabled()) {
LOG.trace("Genesis Block {} ", genesisState.getBlock());
}
return true;
}
use of org.hyperledger.besu.ethereum.mainnet.PoWSolver in project besu by hyperledger.
the class PoWBlockCreatorTest method createMainnetBlock1.
@Test
public void createMainnetBlock1() throws IOException {
final GenesisConfigOptions genesisConfigOptions = GenesisConfigFile.DEFAULT.getConfigOptions();
final ExecutionContextTestFixture executionContextTestFixture = ExecutionContextTestFixture.builder().protocolSchedule(new ProtocolScheduleBuilder(genesisConfigOptions, BigInteger.valueOf(42), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, genesisConfigOptions.isQuorum(), EvmConfiguration.DEFAULT).createProtocolSchedule()).build();
final PoWSolver solver = new PoWSolver(Lists.newArrayList(BLOCK_1_NONCE), PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator(), 1000, 8);
final BaseFeePendingTransactionsSorter pendingTransactions = new BaseFeePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem, executionContextTestFixture.getProtocolContext().getBlockchain()::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);
final PoWBlockCreator blockCreator = new PoWBlockCreator(BLOCK_1_COINBASE, () -> Optional.empty(), parent -> BLOCK_1_EXTRA_DATA, pendingTransactions, executionContextTestFixture.getProtocolContext(), executionContextTestFixture.getProtocolSchedule(), solver, Wei.ZERO, 0.8, executionContextTestFixture.getBlockchain().getChainHeadHeader());
// A Hashrate should not exist in the block creator prior to creating a block
assertThat(blockCreator.getHashesPerSecond().isPresent()).isFalse();
final Block actualBlock = blockCreator.createBlock(BLOCK_1_TIMESTAMP);
final Block expectedBlock = ValidationTestUtils.readBlock(1);
assertThat(actualBlock).isEqualTo(expectedBlock);
assertThat(blockCreator.getHashesPerSecond().isPresent()).isTrue();
}
Aggregations