Search in sources :

Example 1 with ExecutionContextTestFixture

use of org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture in project besu by hyperledger.

the class TraceTransactionIntegrationTest method setUp.

@BeforeEach
public void setUp() {
    final ExecutionContextTestFixture contextTestFixture = ExecutionContextTestFixture.create();
    genesisBlock = contextTestFixture.getGenesis();
    blockchain = contextTestFixture.getBlockchain();
    worldStateArchive = contextTestFixture.getStateArchive();
    final ProtocolSchedule protocolSchedule = contextTestFixture.getProtocolSchedule();
    transactionProcessor = protocolSchedule.getByBlockNumber(0).getTransactionProcessor();
    blockHashLookup = new BlockHashLookup(genesisBlock.getHeader(), blockchain);
}
Also used : ExecutionContextTestFixture(org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with ExecutionContextTestFixture

use of org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture in project besu by hyperledger.

the class OperationBenchmarkHelper method create.

public static OperationBenchmarkHelper create() throws IOException {
    final Path storageDirectory = Files.createTempDirectory("benchmark");
    final KeyValueStorage keyValueStorage = new RocksDBKeyValueStorage(new RocksDBConfigurationBuilder().databaseDir(storageDirectory).build(), new NoOpMetricsSystem(), RocksDBMetricsFactory.PUBLIC_ROCKS_DB_METRICS);
    final ExecutionContextTestFixture executionContext = ExecutionContextTestFixture.builder().keyValueStorage(keyValueStorage).build();
    final MutableBlockchain blockchain = executionContext.getBlockchain();
    for (int i = 1; i < 256; i++) {
        blockchain.appendBlock(new Block(new BlockHeaderTestFixture().parentHash(blockchain.getChainHeadHash()).number(i).difficulty(Difficulty.ONE).buildHeader(), new BlockBody(emptyList(), emptyList())), emptyList());
    }
    final MessageFrame messageFrame = new MessageFrameTestFixture().executionContextTestFixture(executionContext).blockHeader(new BlockHeaderTestFixture().parentHash(blockchain.getChainHeadHash()).number(blockchain.getChainHeadBlockNumber() + 1).difficulty(Difficulty.ONE).buildHeader()).build();
    return new OperationBenchmarkHelper(storageDirectory, keyValueStorage, messageFrame, blockchain);
}
Also used : Path(java.nio.file.Path) BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) RocksDBKeyValueStorage(org.hyperledger.besu.plugin.services.storage.rocksdb.unsegmented.RocksDBKeyValueStorage) KeyValueStorage(org.hyperledger.besu.plugin.services.storage.KeyValueStorage) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) MessageFrameTestFixture(org.hyperledger.besu.ethereum.core.MessageFrameTestFixture) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) RocksDBKeyValueStorage(org.hyperledger.besu.plugin.services.storage.rocksdb.unsegmented.RocksDBKeyValueStorage) RocksDBConfigurationBuilder(org.hyperledger.besu.plugin.services.storage.rocksdb.configuration.RocksDBConfigurationBuilder) ExecutionContextTestFixture(org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture) Block(org.hyperledger.besu.ethereum.core.Block) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain)

Example 3 with ExecutionContextTestFixture

use of org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture 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.
}
Also used : EpochCalculator(org.hyperledger.besu.ethereum.mainnet.EpochCalculator) BaseFeePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter) ExecutionContextTestFixture(org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) ProtocolScheduleBuilder(org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder) PoWSolver(org.hyperledger.besu.ethereum.mainnet.PoWSolver) Test(org.junit.Test)

Example 4 with ExecutionContextTestFixture

use of org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture 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();
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) EpochCalculator(org.hyperledger.besu.ethereum.mainnet.EpochCalculator) BaseFeePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter) ProcessableBlockHeader(org.hyperledger.besu.ethereum.core.ProcessableBlockHeader) ExecutionContextTestFixture(org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) ProtocolScheduleBuilder(org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder) PoWSolver(org.hyperledger.besu.ethereum.mainnet.PoWSolver) Test(org.junit.Test)

Example 5 with ExecutionContextTestFixture

use of org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture 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);
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) EpochCalculator(org.hyperledger.besu.ethereum.mainnet.EpochCalculator) BaseFeePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter) ProcessableBlockHeader(org.hyperledger.besu.ethereum.core.ProcessableBlockHeader) ExecutionContextTestFixture(org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) ProtocolScheduleBuilder(org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder) PoWSolver(org.hyperledger.besu.ethereum.mainnet.PoWSolver) Test(org.junit.Test)

Aggregations

ExecutionContextTestFixture (org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture)8 BaseFeePendingTransactionsSorter (org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter)5 GenesisConfigOptions (org.hyperledger.besu.config.GenesisConfigOptions)4 EpochCalculator (org.hyperledger.besu.ethereum.mainnet.EpochCalculator)4 PoWSolver (org.hyperledger.besu.ethereum.mainnet.PoWSolver)4 ProtocolScheduleBuilder (org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder)4 Test (org.junit.Test)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)2 FilterManagerBuilder (org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManagerBuilder)2 EthGetFilterChanges (org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetFilterChanges)2 BlockchainQueries (org.hyperledger.besu.ethereum.api.query.BlockchainQueries)2 Block (org.hyperledger.besu.ethereum.core.Block)2 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)2 ProcessableBlockHeader (org.hyperledger.besu.ethereum.core.ProcessableBlockHeader)2 EthContext (org.hyperledger.besu.ethereum.eth.manager.EthContext)2 EthPeers (org.hyperledger.besu.ethereum.eth.manager.EthPeers)2 TransactionPool (org.hyperledger.besu.ethereum.eth.transactions.TransactionPool)2 Path (java.nio.file.Path)1 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)1