Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/arm64-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: arm64-Platform Matrix

on:
push:
branches: [ 'develop', 'master', 'release_**' ]
pull_request:
branches: [ 'develop', 'master', 'release_**' ]

jobs:
build:

name: ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.runner }}

strategy:
fail-fast: false
matrix:
include:
# Apple Silicon runners (using latest available)
# see https://github.com/actions/runner-images?tab=readme-ov-file#available-images
- os: macOS
arch: arm64
runner: macos-latest
# Linux arm runners
- os: Linux
arch: arm64
runner: ubuntu-24.04-arm

permissions:
contents: read

steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Build with Gradle Wrapper
run: ./gradlew clean build --no-daemon
54 changes: 54 additions & 0 deletions .github/workflows/x86_64-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: X86_64-Platform Matrix

on:
push:
branches: [ 'develop', 'master', 'release_**' ]
pull_request:
branches: [ 'develop', 'master', 'release_**' ]

jobs:
build:

name: ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.runner }}

strategy:
fail-fast: false
matrix:
include:
# Macos Intel runners
# see https://github.com/actions/runner-images?tab=readme-ov-file#available-images
- os: macOS
arch: x86_64
runner: macos-13
# Linux x86_64 runners
- os: Linux
arch: x86_64
runner: ubuntu-latest

permissions:
contents: read

steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'zulu'

# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Build with Gradle Wrapper
run: ./gradlew clean build --no-daemon
5 changes: 4 additions & 1 deletion actuator/src/main/java/org/tron/core/vm/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ public static void play(Program program, JumpTable jumpTable) {
} catch (JVMStackOverFlowException | OutOfTimeException e) {
throw e;
} catch (RuntimeException e) {
if (StringUtils.isEmpty(e.getMessage())) {
// https://openjdk.org/jeps/358
// https://bugs.openjdk.org/browse/JDK-8220715
// since jdk 14, the NullPointerExceptions message is not empty
if (e instanceof NullPointerException || StringUtils.isEmpty(e.getMessage())) {
logger.warn("Unknown Exception occurred, tx id: {}",
Hex.toHexString(program.getRootTransactionId()), e);
program.setRuntimeFailure(new RuntimeException("Unknown Exception"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return new Integer(Boolean.valueOf(byTestingSuite).hashCode()
return Integer.valueOf(Boolean.valueOf(byTestingSuite).hashCode()
+ Boolean.valueOf(byTransaction).hashCode()
+ address.hashCode()
+ balance.hashCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public boolean equals(Object obj) {

@Override
public int hashCode() {
return new Integer(type).hashCode();
return Integer.valueOf(type).hashCode();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public boolean equals(Object obj) {

@Override
public int hashCode() {
return new Integer(type.hashCode() + Objects.hashCode(value)).hashCode();
return Integer.valueOf(type.hashCode() + Objects.hashCode(value)).hashCode();
}
}
37 changes: 32 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
import org.gradle.nativeplatform.platform.internal.Architectures
allprojects {
version = "1.0.0"
apply plugin: "java-library"
}

static def isX86() {
def arch = System.getProperty("os.arch").toLowerCase()
return Architectures.X86_64.isAlias(arch) || Architectures.X86.isAlias(arch)
}

static def isArm64() {
def arch = System.getProperty("os.arch").toLowerCase()
return new Architectures.KnownArchitecture("arm64", "aarch64").isAlias(arch)
}

if (isArm64() && !JavaVersion.current().is(JavaVersion.VERSION_17)) {
throw new GradleException("Java 17 is required to build Java-Tron for arm64.\n" +
" Detected version ${JavaVersion.current()}")
}

if (isX86() && !JavaVersion.current().isJava8()) {
throw new GradleException("Java 8 is required to build Java-Tron for x86.\n" +
" Detected version ${JavaVersion.current()}")
}

subprojects {
apply plugin: "jacoco"
apply plugin: "maven-publish"

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.current()

[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
jacoco {
Expand Down Expand Up @@ -49,10 +70,16 @@ subprojects {
implementation group: 'joda-time', name: 'joda-time', version: '2.3'
implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.69'

compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
testCompileOnly 'org.projectlombok:lombok:1.18.12'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
compileOnly 'org.projectlombok:lombok:1.18.34'
annotationProcessor 'org.projectlombok:lombok:1.18.34'
testCompileOnly 'org.projectlombok:lombok:1.18.34'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.34'

// https://www.oracle.com/java/technologies/javase/11-relnote-issues.html#JDK-8190378
implementation group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
// for json-rpc, see https://github.com/briandilley/jsonrpc4j/issues/278
implementation group: 'javax.jws', name: 'javax.jws-api', version: '1.1'
annotationProcessor group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'

testImplementation group: 'junit', name: 'junit', version: '4.13.2'
testImplementation "org.mockito:mockito-core:4.11.0"
Expand Down
15 changes: 15 additions & 0 deletions chainbase/src/main/java/org/tron/common/storage/OptionsPicker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.tron.common.storage;

import org.tron.common.setting.RocksDbSettings;
import org.tron.common.utils.StorageUtils;

public class OptionsPicker {

protected org.iq80.leveldb.Options getOptionsByDbNameForLevelDB(String dbName) {
return StorageUtils.getOptionsByDbName(dbName);
}

protected org.rocksdb.Options getOptionsByDbNameForRocksDB(String dbName) {
return RocksDbSettings.getOptionsByDbName(dbName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.fusesource.leveldbjni.JniDBFactory.factory;

import com.google.common.collect.Sets;
import com.google.common.primitives.Bytes;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -30,18 +31,14 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import com.google.common.primitives.Bytes;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.iq80.leveldb.CompressionType;
import org.iq80.leveldb.DB;
import org.iq80.leveldb.DBIterator;
import org.iq80.leveldb.Logger;
Expand All @@ -54,6 +51,7 @@
import org.tron.common.storage.WriteOptionsWrapper;
import org.tron.common.storage.metric.DbStat;
import org.tron.common.utils.FileUtil;
import org.tron.common.utils.PropUtil;
import org.tron.common.utils.StorageUtils;
import org.tron.core.db.common.DbSourceInter;
import org.tron.core.db.common.iterator.StoreIterator;
Expand All @@ -75,6 +73,7 @@ public class LevelDbDataSourceImpl extends DbStat implements DbSourceInter<byte[
private ReadWriteLock resetDbLock = new ReentrantReadWriteLock();
private static final String LEVELDB = "LEVELDB";
private static final org.slf4j.Logger innerLogger = LoggerFactory.getLogger(LEVELDB);
private static final String KEY_ENGINE = "ENGINE";
private Logger leveldbLogger = new Logger() {
@Override
public void log(String message) {
Expand Down Expand Up @@ -110,6 +109,10 @@ public LevelDbDataSourceImpl(String parentPath, String dataBaseName) {

@Override
public void initDB() {
if (!checkOrInitEngine()) {
throw new RuntimeException(
String.format("failed to check database: %s, engine do not match", dataBaseName));
}
resetDbLock.writeLock().lock();
try {
logger.debug("Init DB: {}.", dataBaseName);
Expand All @@ -135,6 +138,28 @@ public void initDB() {
}
}

private boolean checkOrInitEngine() {
String dir = getDbPath().toString();
String enginePath = dir + File.separator + "engine.properties";

if (FileUtil.createDirIfNotExists(dir)) {
if (!FileUtil.createFileIfNotExists(enginePath)) {
return false;
}
} else {
return false;
}

// for the first init engine
String engine = PropUtil.readProperty(enginePath, KEY_ENGINE);
if (engine.isEmpty() && !PropUtil.writeProperty(enginePath, KEY_ENGINE, LEVELDB)) {
return false;
}
engine = PropUtil.readProperty(enginePath, KEY_ENGINE);

return LEVELDB.equals(engine);
}

private void openDatabase(Options dbOptions) throws IOException {
final Path dbPath = getDbPath();
if (dbPath == null || dbPath.getParent() == null) {
Expand Down Expand Up @@ -362,6 +387,7 @@ public Map<WrappedByteArray, byte[]> prefixQuery(byte[] key) {
}
}

@Deprecated
@Override
public long getTotal() throws RuntimeException {
resetDbLock.readLock().lock();
Expand All @@ -378,13 +404,6 @@ public long getTotal() throws RuntimeException {
}
}

private void updateByBatchInner(Map<byte[], byte[]> rows) throws Exception {
try (WriteBatch batch = database.createWriteBatch()) {
innerBatchUpdate(rows,batch);
database.write(batch, writeOptions);
}
}

private void updateByBatchInner(Map<byte[], byte[]> rows, WriteOptions options) throws Exception {
try (WriteBatch batch = database.createWriteBatch()) {
innerBatchUpdate(rows,batch);
Expand All @@ -404,30 +423,23 @@ private void innerBatchUpdate(Map<byte[], byte[]> rows, WriteBatch batch) {

@Override
public void updateByBatch(Map<byte[], byte[]> rows, WriteOptionsWrapper options) {
resetDbLock.readLock().lock();
try {
updateByBatchInner(rows, options.level);
} catch (Exception e) {
try {
updateByBatchInner(rows, options.level);
} catch (Exception e1) {
throw new RuntimeException(e);
}
} finally {
resetDbLock.readLock().unlock();
}
this.updateByBatch(rows, options.level);
}

@Override
public void updateByBatch(Map<byte[], byte[]> rows) {
this.updateByBatch(rows, writeOptions);
}

private void updateByBatch(Map<byte[], byte[]> rows, WriteOptions options) {
resetDbLock.readLock().lock();
try {
updateByBatchInner(rows);
updateByBatchInner(rows, options);
} catch (Exception e) {
try {
updateByBatchInner(rows);
updateByBatchInner(rows, options);
} catch (Exception e1) {
throw new RuntimeException(e);
throw new RuntimeException(e1);
}
} finally {
resetDbLock.readLock().unlock();
Expand Down
Loading
Loading