Skip to content

Commit

Permalink
Merge branch 'main' into feature/fix-trielog
Browse files Browse the repository at this point in the history
  • Loading branch information
garyschulte authored Dec 30, 2023
2 parents d9de070 + 2cf61d6 commit e21d440
Show file tree
Hide file tree
Showing 22 changed files with 2,121 additions and 719 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: adopt
distribution: 'temurin'
java-version: 17
cache: gradle
- name: spotless
Expand All @@ -27,9 +27,9 @@ jobs:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Set up Java 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: adopt
distribution: 'temurin'
java-version: 17
cache: gradle
- name: javadoc (JDK 17)
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ jobs:
uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: adopt
distribution: 'temurin'
java-version: 17
cache: gradle

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ jobs:
runs-on: [besu-research-ubuntu-16]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
cache: gradle
- name: Login to DockerHub
run: echo '${{ secrets.DOCKER_PASSWORD_RW }}' | docker login -u '${{ secrets.DOCKER_USER_RW }}' --password-stdin
- name: Setup Gradle
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,17 @@ jobs:
- name: checkout
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: gradle
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- New `Sequenced` transaction pool. The pool is an evolution of the `legacy` pool and is likely to be more suitable to enterprise or permissioned chains than the `layered` transaction pool. Select to use this pool with `--tx-pool=sequenced`. Supports the same options as the `legacy` pool [#6211](https://github.com/hyperledger/besu/issues/6211)
- Set Ethereum Classic mainnet activation block for Spiral network upgrade [#6267](https://github.com/hyperledger/besu/pull/6267)
- Add custom genesis file name to config overview if specified [#6297](https://github.com/hyperledger/besu/pull/6297)
- Update Gradle plugins and replace unmaintained License Gradle Plugin with the actively maintained Gradle License Report [#6275](https://github.com/hyperledger/besu/pull/6275)

### Bug fixes

Expand Down
51 changes: 36 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/


import com.github.jk1.license.filter.LicenseBundleNormalizer
import groovy.transform.CompileStatic
import groovy.transform.Memoized
import net.ltgt.gradle.errorprone.CheckSeverity
Expand All @@ -22,15 +23,15 @@ import java.text.SimpleDateFormat
import java.util.regex.Pattern

plugins {
id 'com.diffplug.spotless' version '6.12.0'
id 'com.github.ben-manes.versions' version '0.42.0'
id 'com.github.hierynomus.license' version '0.16.1-fix'
id 'com.jfrog.artifactory' version '4.28.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'me.champeau.jmh' version '0.7.0' apply false
id 'net.ltgt.errorprone' version '2.0.2'
id 'com.diffplug.spotless' version '6.23.3'
id 'com.github.ben-manes.versions' version '0.50.0'
id 'com.github.jk1.dependency-license-report' version '2.5'
id 'com.jfrog.artifactory' version '5.1.11'
id 'io.spring.dependency-management' version '1.1.4'
id 'me.champeau.jmh' version '0.7.2' apply false
id 'net.ltgt.errorprone' version '3.0.1'
id 'maven-publish'
id 'org.sonarqube' version '3.4.0.2513'
id 'org.sonarqube' version '4.4.1.3373'
}

sonarqube {
Expand Down Expand Up @@ -87,13 +88,35 @@ def _strListCmdArg(name) {
return _strListCmdArg(name, null)
}

licenseReport {
// This is for the allowed-licenses-file in checkLicense Task
// Accepts File, URL or String path to local or remote file
allowedLicensesFile = new File("$rootDir/gradle/allowed-licenses.json")

excludes = [
// only used for static analysis, not actually shipped
'com.google.errorprone:javac',
'org.checkerframework:dataflow-shaded',
'org.checkerframework:dataflow-errorprone',
// exclude Kotlin multiplatform dependencies container, they have the same license of what they contain
'com.squareup.okio:okio',
'org.jetbrains.kotlinx:kotlinx-coroutines-core'
]

// If set to true, then all boms will be excluded from the report
excludeBoms = true

filters = [
new LicenseBundleNormalizer(bundlePath: "$rootDir/gradle/license-normalizer-bundle.json")
]
}

allprojects {
apply plugin: 'java-library'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'jacoco'
apply plugin: 'net.ltgt.errorprone'
apply from: "${rootDir}/gradle/versions.gradle"
apply from: "${rootDir}/gradle/check-licenses.gradle"

version = rootProject.version

Expand Down Expand Up @@ -177,7 +200,7 @@ allprojects {
}
groovyGradle {
target '*.gradle'
greclipse('4.21.0').configFile(rootProject.file('gradle/formatter.properties'))
greclipse('4.21').configFile(rootProject.file('gradle/formatter.properties'))
endWithNewline()
}
// Below this line are currently only license header tasks
Expand Down Expand Up @@ -323,7 +346,6 @@ allprojects {
options.addStringOption('Xwerror', '-html5')
options.encoding = 'UTF-8'
}

}

task deploy() {}
Expand Down Expand Up @@ -624,10 +646,10 @@ task autocomplete(type: JavaExec) {
}
}

installDist { dependsOn checkLicenses, untunedStartScripts, evmToolStartScripts }
installDist { dependsOn checkLicense, untunedStartScripts, evmToolStartScripts }

distTar {
dependsOn checkLicenses, autocomplete, untunedStartScripts, evmToolStartScripts
dependsOn checkLicense, autocomplete, untunedStartScripts, evmToolStartScripts
doFirst {
delete fileTree(dir: 'build/distributions', include: '*.tar.gz')
}
Expand All @@ -636,7 +658,7 @@ distTar {
}

distZip {
dependsOn checkLicenses, autocomplete, untunedStartScripts, evmToolStartScripts
dependsOn checkLicense, autocomplete, untunedStartScripts, evmToolStartScripts
doFirst {
delete fileTree(dir: 'build/distributions', include: '*.zip')
}
Expand Down Expand Up @@ -958,7 +980,6 @@ task checkSpdxHeader(type: CheckSpdxHeader) {
"(.*${sep}build${sep}.*)",
"(.*${sep}src${sep}[^${sep}]+${sep}generated${sep}.*)"
].join("|")

}

task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,15 @@ public TransactionProcessingResult processTransaction(
gasUsedByTransaction, refundedGas, validationResult, initialFrame.getRevertReason());
}
} catch (final MerkleTrieException re) {
operationTracer.traceEndTransaction(
worldState.updater(), transaction, false, Bytes.EMPTY, List.of(), 0, 0L);

// need to throw to trigger the heal
throw re;
} catch (final RuntimeException re) {
operationTracer.traceEndTransaction(
worldState.updater(), transaction, false, Bytes.EMPTY, List.of(), 0, 0L);

LOG.error("Critical Exception Processing Transaction", re);
return TransactionProcessingResult.invalid(
ValidationResult.invalid(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,29 @@
import org.hyperledger.besu.ethereum.core.feemarket.CoinbaseFeePriceCalculator;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason;
import org.hyperledger.besu.ethereum.trie.MerkleTrieException;
import org.hyperledger.besu.ethereum.vm.BlockHashLookup;
import org.hyperledger.besu.evm.account.MutableAccount;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.hyperledger.besu.evm.gascalculator.GasCalculator;
import org.hyperledger.besu.evm.gascalculator.LondonGasCalculator;
import org.hyperledger.besu.evm.log.Log;
import org.hyperledger.besu.evm.processor.AbstractMessageProcessor;
import org.hyperledger.besu.evm.tracing.OperationTracer;
import org.hyperledger.besu.evm.worldstate.WorldUpdater;
import org.hyperledger.besu.evm.worldstate.WorldView;

import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Stream;

import org.apache.tuweni.bytes.Bytes;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
Expand All @@ -67,6 +76,7 @@ class MainnetTransactionProcessorTest {
@Mock private BlockHashLookup blockHashLookup;

@Mock private MutableAccount senderAccount;
@Mock private MutableAccount receiverAccount;

MainnetTransactionProcessor createTransactionProcessor(final boolean warmCoinbase) {
return new MainnetTransactionProcessor(
Expand All @@ -83,9 +93,9 @@ MainnetTransactionProcessor createTransactionProcessor(final boolean warmCoinbas

@Test
void shouldWarmCoinbaseIfRequested() {
Optional<Address> toAddresss =
Optional<Address> toAddress =
Optional.of(Address.fromHexString("0x2222222222222222222222222222222222222222"));
when(transaction.getTo()).thenReturn(toAddresss);
when(transaction.getTo()).thenReturn(toAddress);
Address senderAddress = Address.fromHexString("0x5555555555555555555555555555555555555555");
Address coinbaseAddress = Address.fromHexString("0x4242424242424242424242424242424242424242");

Expand Down Expand Up @@ -141,6 +151,81 @@ void shouldWarmCoinbaseIfRequested() {
assertThat(coinbaseWarmed).isFalse();
}

@ParameterizedTest
@MethodSource("provideExceptionsForTransactionProcessing")
/*
This test is to ensure that the OperationTracer.traceEndTxCalled is called even if the transaction processing fails.
@param exception will either be of class RuntimeException or MerkleTrieException
*/
void shouldTraceEndTxOnFailingTransaction(final Exception exception) {
Optional<Address> toAddress =
Optional.of(Address.fromHexString("0x2222222222222222222222222222222222222222"));
Address senderAddress = Address.fromHexString("0x5555555555555555555555555555555555555555");
Address coinbaseAddress = Address.fromHexString("0x4242424242424242424242424242424242424242");

when(transaction.getTo()).thenReturn(toAddress);
when(transaction.getHash()).thenReturn(Hash.EMPTY);
when(transaction.getPayload()).thenReturn(Bytes.EMPTY);
when(transaction.getSender()).thenReturn(senderAddress);
when(transaction.getValue()).thenReturn(Wei.ZERO);
when(transactionValidatorFactory.get().validate(any(), any(), any()))
.thenReturn(ValidationResult.valid());
when(transactionValidatorFactory.get().validateForSender(any(), any(), any()))
.thenReturn(ValidationResult.valid());
when(worldState.getOrCreateSenderAccount(senderAddress)).thenReturn(senderAccount);
when(worldState.get(toAddress.get())).thenReturn(receiverAccount);
when(worldState.updater()).thenReturn(worldState);
// throw exception when processing the transaction
doAnswer(
invocation -> {
throw exception;
})
.when(messageCallProcessor)
.process(any(), any());

final TraceEndTxTracer tracer = new TraceEndTxTracer();
var transactionProcessor = createTransactionProcessor(true);
try {
transactionProcessor.processTransaction(
blockchain,
worldState,
blockHeader,
transaction,
coinbaseAddress,
blockHashLookup,
false,
ImmutableTransactionValidationParams.builder().build(),
tracer,
Wei.ZERO);
} catch (final MerkleTrieException e) {
// the MerkleTrieException is thrown again in MainnetTransactionProcessor, we ignore it here
}

assertThat(tracer.traceEndTxCalled).isTrue();
}

// those two exceptions can be thrown while processing a transaction
private static Stream<Arguments> provideExceptionsForTransactionProcessing() {
return Stream.of(
Arguments.of(new MerkleTrieException("")), Arguments.of(new RuntimeException()));
}

static class TraceEndTxTracer implements OperationTracer {
boolean traceEndTxCalled = false;

@Override
public void traceEndTransaction(
final WorldView worldView,
final org.hyperledger.besu.datatypes.Transaction tx,
final boolean status,
final Bytes output,
final List<Log> logs,
final long gasUsed,
final long timeNs) {
this.traceEndTxCalled = true;
}
}

@Test
void shouldCallTransactionValidatorWithExpectedTransactionValidationParams() {
final ArgumentCaptor<TransactionValidationParams> txValidationParamCaptor =
Expand Down
Loading

0 comments on commit e21d440

Please sign in to comment.