Skip to content

Commit

Permalink
Merge branch 'main' into feature/fallback-for-para-evm
Browse files Browse the repository at this point in the history
  • Loading branch information
matkt authored Jan 10, 2025
2 parents 5c54f82 + 8cddcfd commit 5ffe473
Show file tree
Hide file tree
Showing 63 changed files with 2,189 additions and 1,079 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Breaking Changes
- `--host-whitelist` has been deprecated since 2020 and this option is removed. Use the equivalent `--host-allowlist` instead.
- Changed tracer API to include the mining beneficiary in BlockAwareOperationTracer::traceStartBlock [#8096](https://github.com/hyperledger/besu/pull/8096)

### Upcoming Breaking Changes
- `MetricSystem::createLabelledGauge` is deprecated and will be removed in a future release, replace it with `MetricSystem::createLabelledSuppliedGauge`
Expand All @@ -19,7 +20,7 @@
- Retrieve all transaction receipts for a block in one request [#6646](https://github.com/hyperledger/besu/pull/6646)
- Implement EIP-7840: Add blob schedule to config files [#8042](https://github.com/hyperledger/besu/pull/8042)
- Allow gasPrice (legacy) and 1559 gasPrice params to be specified simultaneously for `eth_call`, `eth_createAccessList`, and `eth_estimateGas` [#8059](https://github.com/hyperledger/besu/pull/8059)

- Add support for EIP-7702 transaction in the txpool [#8018](https://github.com/hyperledger/besu/pull/8018) [#7984](https://github.com/hyperledger/besu/pull/7984)

### Bug fixes
- Fix serialization of state overrides when `movePrecompileToAddress` is present [#8204](https://github.com/hyperledger/besu/pull/8024)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static org.hyperledger.besu.ethereum.mainnet.feemarket.ExcessBlobGasCalculator.calculateExcessBlobGasForParent;

import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.BlobGas;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
Expand Down Expand Up @@ -152,16 +153,13 @@ public void trace(
.toList();
Tracer.processTracing(
blockchainQueries,
blocks.get(0).getHash(),
blocks.getFirst().getHash(),
traceableState -> {
final WorldUpdater worldStateUpdater = traceableState.updater();
final ChainUpdater chainUpdater = new ChainUpdater(traceableState, worldStateUpdater);
beforeTracing.accept(worldStateUpdater);
final List<TransactionProcessingResult> results = new ArrayList<>();
blocks.forEach(
block -> {
results.addAll(trace(blockchain, block, chainUpdater, tracer));
});
blocks.forEach(block -> results.addAll(trace(blockchain, block, chainUpdater, tracer)));
afterTracing.accept(chainUpdater.getNextUpdater());
return Optional.of(results);
});
Expand Down Expand Up @@ -191,7 +189,9 @@ private List<TransactionProcessingResult> trace(
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockHeader(block.getHeader());
final MainnetTransactionProcessor transactionProcessor = protocolSpec.getTransactionProcessor();
final BlockHeader header = block.getHeader();
tracer.traceStartBlock(block.getHeader(), block.getBody());
final Address miningBeneficiary =
protocolSpec.getMiningBeneficiaryCalculator().calculateBeneficiary(block.getHeader());
tracer.traceStartBlock(block.getHeader(), block.getBody(), miningBeneficiary);

block
.getBody()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ void shouldRetrieveStateUpdatePostTracingForOneBlock() {

final Block tracedBlock = blockchain.getBlockByNumber(blockNumber).get();

verify(opTracer).traceStartBlock(tracedBlock.getHeader(), tracedBlock.getBody());
verify(opTracer)
.traceStartBlock(
tracedBlock.getHeader(), tracedBlock.getBody(), tracedBlock.getHeader().getCoinbase());

tracedBlock
.getBody()
Expand Down Expand Up @@ -163,7 +165,11 @@ void shouldRetrieveStateUpdatePostTracingForAllBlocks() {
.map(Optional::get)
.forEach(
tracedBlock -> {
verify(opTracer).traceStartBlock(tracedBlock.getHeader(), tracedBlock.getBody());
verify(opTracer)
.traceStartBlock(
tracedBlock.getHeader(),
tracedBlock.getBody(),
tracedBlock.getHeader().getCoinbase());
tracedBlock
.getBody()
.getTransactions()
Expand Down Expand Up @@ -312,7 +318,8 @@ public void traceEndTransaction(
}

@Override
public void traceStartBlock(final BlockHeader blockHeader, final BlockBody blockBody) {
public void traceStartBlock(
final BlockHeader blockHeader, final BlockBody blockBody, final Address miningBeneficiary) {
if (!traceStartBlockCalled.add(blockHeader.getBlockHash())) {
fail("traceStartBlock already called for block " + blockHeader);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void readGenesisFromObjectNode() {
final var configNode = mapper.createObjectNode();
configNode.put("londonBlock", 1);
final var allocNode = mapper.createObjectNode();
allocNode.put(Address.BLS12_G2MUL.toUnprefixedHexString(), generateAllocation(Wei.ONE));
allocNode.put(Address.BLS12_G2MULTIEXP.toUnprefixedHexString(), generateAllocation(Wei.ONE));
final var rootNode = mapper.createObjectNode();
rootNode.put("chainId", 12);
rootNode.put(CONFIG_FIELD, configNode);
Expand All @@ -52,15 +52,16 @@ public void readGenesisFromObjectNode() {
assertThat(genesisReader.getRoot().has(ALLOCATION_FIELD)).isFalse();
assertThat(genesisReader.getConfig().get("londonblock").asInt()).isEqualTo(1);
assertThat(genesisReader.streamAllocations())
.containsExactly(new GenesisAccount(Address.BLS12_G2MUL, 0, Wei.ONE, null, Map.of(), null));
.containsExactly(
new GenesisAccount(Address.BLS12_G2MULTIEXP, 0, Wei.ONE, null, Map.of(), null));
}

@Test
public void readGenesisFromObjectDoesNotModifyObjectNodeArg() {
final var configNode = mapper.createObjectNode();
configNode.put("londonBlock", 1);
final var allocNode = mapper.createObjectNode();
allocNode.put(Address.BLS12_G2MUL.toUnprefixedHexString(), generateAllocation(Wei.ONE));
allocNode.put(Address.BLS12_G2MULTIEXP.toUnprefixedHexString(), generateAllocation(Wei.ONE));
final var rootNode = mapper.createObjectNode();
rootNode.put("chainId", 12);
rootNode.put(CONFIG_FIELD, configNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,23 @@ public class Address extends DelegatingBytes {
/** The constant BLS12_G1ADD. */
public static final Address BLS12_G1ADD = Address.precompiled(0xB);

/** The constant BLS12_G1MUL. */
public static final Address BLS12_G1MUL = Address.precompiled(0xC);

/** The constant BLS12_G1MULTIEXP. */
public static final Address BLS12_G1MULTIEXP = Address.precompiled(0xD);
public static final Address BLS12_G1MULTIEXP = Address.precompiled(0xC);

/** The constant BLS12_G2ADD. */
public static final Address BLS12_G2ADD = Address.precompiled(0xE);

/** The constant BLS12_G2MUL. */
public static final Address BLS12_G2MUL = Address.precompiled(0xF);
public static final Address BLS12_G2ADD = Address.precompiled(0xD);

/** The constant BLS12_G2MULTIEXP. */
public static final Address BLS12_G2MULTIEXP = Address.precompiled(0x10);
public static final Address BLS12_G2MULTIEXP = Address.precompiled(0xE);

/** The constant BLS12_PAIRING. */
public static final Address BLS12_PAIRING = Address.precompiled(0x11);
public static final Address BLS12_PAIRING = Address.precompiled(0xF);

/** The constant BLS12_MAP_FP_TO_G1. */
public static final Address BLS12_MAP_FP_TO_G1 = Address.precompiled(0x12);
public static final Address BLS12_MAP_FP_TO_G1 = Address.precompiled(0x10);

/** The constant BLS12_MAP_FP2_TO_G2. */
public static final Address BLS12_MAP_FP2_TO_G2 = Address.precompiled(0x13);
public static final Address BLS12_MAP_FP2_TO_G2 = Address.precompiled(0x11);

/** The constant ZERO. */
public static final Address ZERO = Address.fromHexString("0x0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ protected BlockCreationResult createBlock(
final BlockAwareOperationTracer operationTracer =
pluginTransactionSelector.getOperationTracer();

operationTracer.traceStartBlock(processableBlockHeader);
operationTracer.traceStartBlock(processableBlockHeader, miningBeneficiary);
timings.register("preTxsSelection");
final TransactionSelectionResults transactionResults =
selectTransactions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ public InterruptibleOperationTracer(final BlockAwareOperationTracer delegate) {
}

@Override
public void traceStartBlock(final BlockHeader blockHeader, final BlockBody blockBody) {
delegate.traceStartBlock(blockHeader, blockBody);
public void traceStartBlock(
final BlockHeader blockHeader, final BlockBody blockBody, final Address miningBeneficiary) {
delegate.traceStartBlock(blockHeader, blockBody, miningBeneficiary);
}

@Override
Expand All @@ -51,8 +52,9 @@ public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBo
}

@Override
public void traceStartBlock(final ProcessableBlockHeader processableBlockHeader) {
delegate.traceStartBlock(processableBlockHeader);
public void traceStartBlock(
final ProcessableBlockHeader processableBlockHeader, final Address miningBeneficiary) {
delegate.traceStartBlock(processableBlockHeader, miningBeneficiary);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,14 +1300,14 @@ public Builder versionedHashes(final List<VersionedHash> versionedHashes) {
}

public Builder guessType() {
if (versionedHashes != null && !versionedHashes.isEmpty()) {
if (codeDelegationAuthorizations.isPresent()) {
transactionType = TransactionType.DELEGATE_CODE;
} else if (versionedHashes != null && !versionedHashes.isEmpty()) {
transactionType = TransactionType.BLOB;
} else if (maxPriorityFeePerGas != null || maxFeePerGas != null) {
transactionType = TransactionType.EIP1559;
} else if (accessList.isPresent()) {
transactionType = TransactionType.ACCESS_LIST;
} else if (codeDelegationAuthorizations.isPresent()) {
transactionType = TransactionType.DELEGATE_CODE;
} else {
transactionType = TransactionType.FRONTIER;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,35 @@
*/
package org.hyperledger.besu.ethereum.core;

import org.hyperledger.besu.crypto.CodeDelegationSignature;
import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SECPSignature;
import org.hyperledger.besu.crypto.SignatureAlgorithm;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.datatypes.AccessListEntry;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.BlobsWithCommitments;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.TransactionType;
import org.hyperledger.besu.datatypes.VersionedHash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.encoding.CodeDelegationTransactionEncoder;
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;

import java.math.BigInteger;
import java.util.List;
import java.util.Optional;

import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import org.apache.tuweni.bytes.Bytes;

public class TransactionTestFixture {
private final SECPSignature signature =
new SECPSignature(BigInteger.ONE, BigInteger.ONE, (byte) 0);
private static final Supplier<SignatureAlgorithm> SIGNATURE_ALGORITHM =
Suppliers.memoize(SignatureAlgorithmFactory::getInstance);
private static final KeyPair KEY_PAIR = SIGNATURE_ALGORITHM.get().generateKeyPair();
private static final org.hyperledger.besu.datatypes.CodeDelegation CODE_DELEGATION =
createSignedCodeDelegation(BigInteger.ZERO, Address.ZERO, 0, KEY_PAIR);

private TransactionType transactionType = TransactionType.FRONTIER;

private long nonce = 0;
Expand Down Expand Up @@ -100,9 +111,7 @@ public Transaction createTransaction(final KeyPair keys) {
builder.maxPriorityFeePerGas(maxPriorityFeePerGas.orElse(Wei.of(500)));
builder.maxFeePerGas(maxFeePerGas.orElse(Wei.of(5000)));
builder.accessList(accessListEntries.orElse(List.of()));
builder.codeDelegations(
codeDelegations.orElse(
List.of(new CodeDelegation(chainId.get(), sender, 0, signature))));
builder.codeDelegations(codeDelegations.orElse(List.of(CODE_DELEGATION)));
break;
}

Expand Down Expand Up @@ -196,7 +205,28 @@ public TransactionTestFixture blobsWithCommitments(final Optional<BlobsWithCommi

public TransactionTestFixture codeDelegations(
final List<org.hyperledger.besu.datatypes.CodeDelegation> codeDelegations) {
this.codeDelegations = Optional.of(codeDelegations);
this.codeDelegations = Optional.ofNullable(codeDelegations);
return this;
}

public static CodeDelegation createSignedCodeDelegation(
final BigInteger chainId, final Address address, final long nonce, final KeyPair keys) {
BytesValueRLPOutput rlpOutput = new BytesValueRLPOutput();
CodeDelegationTransactionEncoder.encodeSingleCodeDelegationWithoutSignature(
new org.hyperledger.besu.ethereum.core.CodeDelegation(chainId, address, nonce, null),
rlpOutput);

final Hash hash =
Hash.hash(
Bytes.concatenate(
org.hyperledger.besu.ethereum.core.CodeDelegation.MAGIC, rlpOutput.encoded()));

final var signature = SIGNATURE_ALGORITHM.get().sign(hash, keys);

return new org.hyperledger.besu.ethereum.core.CodeDelegation(
chainId,
address,
nonce,
CodeDelegationSignature.create(signature.getR(), signature.getS(), signature.getRecId()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@
*/
package org.hyperledger.besu.ethereum.core;

import static java.util.stream.Collectors.toUnmodifiableSet;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.datatypes.VersionedHash.DEFAULT_VERSIONED_HASH;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SECPSignature;
import org.hyperledger.besu.crypto.SignatureAlgorithm;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.datatypes.AccessListEntry;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.TransactionType;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;

import java.math.BigInteger;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Stream;

Expand All @@ -45,20 +46,51 @@ class TransactionBuilderTest {
@Test
void guessTypeCanGuessAllTypes() {
final BlockDataGenerator gen = new BlockDataGenerator();
final List<AccessListEntry> accessList =
List.of(new AccessListEntry(gen.address(), List.of(gen.bytes32())));

final Transaction.Builder frontierBuilder = Transaction.builder();
final Transaction.Builder eip1559Builder = Transaction.builder().maxFeePerGas(Wei.of(5));
final Transaction.Builder accessListBuilder =
final Transaction.Builder accessListBuilder = Transaction.builder().accessList(accessList);

final Transaction.Builder eip1559Builder =
Transaction.builder().accessList(accessList).maxFeePerGas(Wei.of(5));

final Transaction.Builder blobBuilder =
Transaction.builder()
.accessList(accessList)
.maxFeePerGas(Wei.of(5))
.versionedHashes(List.of(DEFAULT_VERSIONED_HASH));

final CodeDelegation codeDelegation =
new CodeDelegation(
BigInteger.ZERO,
Address.ZERO,
0,
new SECPSignature(BigInteger.ZERO, BigInteger.ZERO, (byte) 0));

final Transaction.Builder delegateCodeBuilder =
Transaction.builder()
.accessList(List.of(new AccessListEntry(gen.address(), List.of(gen.bytes32()))));
.accessList(accessList)
.maxFeePerGas(Wei.of(5))
.codeDelegations(List.of(codeDelegation));

final Set<TransactionType> guessedTypes =
Stream.of(frontierBuilder, eip1559Builder, accessListBuilder)
final List<TransactionType> guessedTypes =
Stream.of(
frontierBuilder,
accessListBuilder,
eip1559Builder,
blobBuilder,
delegateCodeBuilder)
.map(transactionBuilder -> transactionBuilder.guessType().getTransactionType())
.collect(toUnmodifiableSet());
.toList();

assertThat(guessedTypes)
.containsExactlyInAnyOrder(
TransactionType.FRONTIER, TransactionType.ACCESS_LIST, TransactionType.EIP1559);
.containsExactly(
TransactionType.FRONTIER,
TransactionType.ACCESS_LIST,
TransactionType.EIP1559,
TransactionType.BLOB,
TransactionType.DELEGATE_CODE);
}

@Test
Expand Down
Loading

0 comments on commit 5ffe473

Please sign in to comment.