-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement BaseFee, blobBaseFee, CallValue, GasPrice, Balance and SelfBalance for EVM v2 #10229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
d63e96e
Migrate wei operations to EVM v2 (first commit)
ahamlat ff6d03e
Update SelfBalance benchmarks
ahamlat de6a840
spotless
ahamlat 436c308
Address comments.
ahamlat b7d8cab
Merge branch 'main' into wei-opcodes-on-evm-v2
ahamlat edcc531
Add Javadoc
ahamlat f969516
Add unit tests
ahamlat 648b921
Merge branch 'main' into wei-opcodes-on-evm-v2
ahamlat 3ecd7d3
spotless
ahamlat 8009532
Update datatypes/src/main/java/org/hyperledger/besu/datatypes/Wei.java
ahamlat 3cdf3af
Update evm/src/main/java/org/hyperledger/besu/evm/frame/MessageFrame.…
ahamlat 310ffbf
Update evm/src/main/java/org/hyperledger/besu/evm/frame/MessageFrame.…
ahamlat e38f455
Update datatypes/src/main/java/org/hyperledger/besu/datatypes/Wei.java
ahamlat 6a30d3f
Merge branch 'main' into wei-opcodes-on-evm-v2
ahamlat c406646
Apply refactoring changes
ahamlat 0820192
remove basefee field
ahamlat bb8e572
Merge branch 'main' into wei-opcodes-on-evm-v2
ahamlat 8ed8bfb
Fix merge issue
ahamlat 5c79af7
Address more comments
ahamlat 5acec25
Remove not used field
ahamlat 1826010
spotless
ahamlat 98b66d1
Undo Balance operation change and add more unit tests
ahamlat 89ab0d2
Merge branch 'main' into wei-opcodes-on-evm-v2
ahamlat aec17bc
Update AddOperationV2 after merge with main
ahamlat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
.../java/org/hyperledger/besu/ethereum/vm/operations/v2/SelfBalanceOperationBenchmarkV2.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * Copyright contributors to Besu. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations under the License. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package org.hyperledger.besu.ethereum.vm.operations.v2; | ||
|
|
||
| import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createBonsaiInMemoryWorldStateArchive; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| import org.hyperledger.besu.datatypes.Address; | ||
| import org.hyperledger.besu.datatypes.Hash; | ||
| import org.hyperledger.besu.datatypes.Wei; | ||
| import org.hyperledger.besu.ethereum.chain.Blockchain; | ||
| import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; | ||
| import org.hyperledger.besu.evm.Code; | ||
| import org.hyperledger.besu.evm.frame.BlockValues; | ||
| import org.hyperledger.besu.evm.frame.MessageFrame; | ||
| import org.hyperledger.besu.evm.gascalculator.GasCalculator; | ||
| import org.hyperledger.besu.evm.v2.operation.SelfBalanceOperationV2; | ||
| import org.hyperledger.besu.evm.worldstate.WorldUpdater; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import org.apache.tuweni.bytes.Bytes32; | ||
| import org.openjdk.jmh.annotations.Benchmark; | ||
| import org.openjdk.jmh.annotations.BenchmarkMode; | ||
| import org.openjdk.jmh.annotations.Measurement; | ||
| import org.openjdk.jmh.annotations.Mode; | ||
| import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
| import org.openjdk.jmh.annotations.Scope; | ||
| import org.openjdk.jmh.annotations.Setup; | ||
| import org.openjdk.jmh.annotations.State; | ||
| import org.openjdk.jmh.annotations.Warmup; | ||
| import org.openjdk.jmh.infra.Blackhole; | ||
|
|
||
| @State(Scope.Thread) | ||
| @Warmup(iterations = 2, time = 3, timeUnit = TimeUnit.SECONDS) | ||
| @OutputTimeUnit(value = TimeUnit.NANOSECONDS) | ||
| @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) | ||
| @BenchmarkMode(Mode.AverageTime) | ||
| public class SelfBalanceOperationBenchmarkV2 { | ||
|
|
||
| private SelfBalanceOperationV2 operation; | ||
| private MessageFrame frame; | ||
|
|
||
| @Setup | ||
| public void setup() throws Exception { | ||
| operation = new SelfBalanceOperationV2(mock(GasCalculator.class)); | ||
| final Blockchain blockchain = mock(Blockchain.class); | ||
| final Address address = Address.fromHexString("0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); | ||
|
|
||
| final WorldUpdater worldUpdater; | ||
| try (WorldStateArchive archive = createBonsaiInMemoryWorldStateArchive(blockchain)) { | ||
| worldUpdater = archive.getWorldState().updater(); | ||
| } | ||
| worldUpdater.getOrCreate(address).setBalance(Wei.of(1)); | ||
| worldUpdater.commit(); | ||
|
|
||
| frame = | ||
| MessageFrame.builder() | ||
| .enableEvmV2(true) | ||
| .worldUpdater(worldUpdater) | ||
| .originator(Address.ZERO) | ||
| .gasPrice(Wei.ONE) | ||
| .blobGasPrice(Wei.ONE) | ||
| .blockValues(mock(BlockValues.class)) | ||
| .miningBeneficiary(Address.ZERO) | ||
| .blockHashLookup((__, ___) -> Hash.ZERO) | ||
| .type(MessageFrame.Type.MESSAGE_CALL) | ||
| .initialGas(Long.MAX_VALUE) | ||
| .address(address) | ||
| .contract(address) | ||
| .inputData(Bytes32.ZERO) | ||
| .sender(Address.ZERO) | ||
| .value(Wei.ZERO) | ||
| .apparentValue(Wei.ZERO) | ||
| .code(Code.EMPTY_CODE) | ||
| .completer(__ -> {}) | ||
| .build(); | ||
|
|
||
| // Pre-warm: force trie path into memory | ||
|
ahamlat marked this conversation as resolved.
|
||
| worldUpdater.get(address); | ||
| } | ||
|
|
||
| @Benchmark | ||
| public void executeOperation(final Blackhole blackhole) { | ||
| blackhole.consume(operation.execute(frame, null)); | ||
| frame.setTopV2(frame.stackTopV2() - 1); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.