Skip to content
Open
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
60 changes: 60 additions & 0 deletions .github/workflows/dependency-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: "Dependency Check"

on:
push:
branches: [ 'develop', 'master', 'release_**', 'feat/state_root_sync' ]
pull_request:
branches: [ 'develop', "release_**" , 'feat/state_root_sync' ]
schedule:
- cron: '25 6 * * *'
workflow_dispatch:

jobs:
dependency-check:
name: Dependency Check
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Cache ODC data
uses: actions/cache@v3
with:
path: ~/.dependency-check/data
key: ${{ runner.os }}-odc-data-${{ hashFiles('**/build.gradle') }}
restore-keys: |
${{ runner.os }}-odc-data-

- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'

- name: Gradlew build
run: ./gradlew --no-daemon -S -Dorg.gradle.dependency.verification=off -Dorg.gradle.warning.mode=none build -x test

- name: Dependency Check
uses: dependency-check/Dependency-Check_Action@1.1.0
env:
# actions/setup-java@v1 changes JAVA_HOME, so it needs to be reset to match the depcheck image
JAVA_HOME: /opt/jdk
with:
project: 'java-tron'
path: '.'
format: 'HTML'
out: 'reports'
args: >
--failOnCVSS 7
--enableRetired
- name: Generate timestamp
run: echo "BUILD_TIMESTAMP=$(date -u +"%Y%m%d-%H%M%S")" >> $GITHUB_ENV
- name: Get Repository Name
run: echo "REPO_NAME=$(echo '${{ github.repository }}' | cut -d'/' -f2)" >> $GITHUB_ENV
- name: Upload report
if: always()
uses: actions/upload-artifact@v4
with:
name: dependency-check-${{ env.REPO_NAME }}-${{ env.BUILD_TIMESTAMP }}
path: ${{github.workspace}}/reports
29 changes: 29 additions & 0 deletions .github/workflows/dependency-submission.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Dependency Submission

on:
push:
branches: [ 'develop', 'master', 'release_**', 'feat/state_root_sync' ]
pull_request:
branches: [ 'develop', "release_**" , 'feat/state_root_sync' ]

workflow_dispatch:

permissions:
contents: write

jobs:
dependency-submission:
runs-on: ubuntu-24.04-arm

steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@v4
4 changes: 2 additions & 2 deletions actuator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ test {

jacocoTestReport {
reports {
xml.enabled = true
html.enabled = true
xml.required.set(true)
html.required.set(true)
}
getExecutionData().setFrom(fileTree('../framework/build/jacoco').include("**.exec"))
afterEvaluate {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
package org.tron.core.utils;

import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import lombok.extern.slf4j.Slf4j;
import org.reflections.Reflections;
import org.tron.core.actuator.AbstractActuator;
import org.tron.core.exception.TronError;

@Slf4j(topic = "TransactionRegister")
public class TransactionRegister {

private static final AtomicBoolean REGISTERED = new AtomicBoolean(false);
private static final String PACKAGE_NAME = "org.tron.core.actuator";

public static void registerActuator() {
Reflections reflections = new Reflections("org.tron");
Set<Class<? extends AbstractActuator>> subTypes = reflections
.getSubTypesOf(AbstractActuator.class);
for (Class _class : subTypes) {
try {
_class.newInstance();
} catch (Exception e) {
logger.error("{} contract actuator register fail!", _class, e);
if (REGISTERED.get()) {
logger.info("Actuator already registered.");
return;
}

synchronized (TransactionRegister.class) {
if (REGISTERED.get()) {
logger.info("Actuator already registered.");
return;
}

logger.info("Register actuator start.");
Reflections reflections = new Reflections(PACKAGE_NAME);
Set<Class<? extends AbstractActuator>> subTypes = reflections
.getSubTypesOf(AbstractActuator.class);

for (Class<? extends AbstractActuator> clazz : subTypes) {
try {
logger.debug("Registering actuator: {} start", clazz.getName());
clazz.getDeclaredConstructor().newInstance();
logger.debug("Registering actuator: {} done", clazz.getName());
} catch (Exception e) {
throw new TronError(clazz.getName() + ": "
+ (e.getCause() == null ? e.getMessage() : e.getCause().getMessage()),
e, TronError.ErrCode.ACTUATOR_REGISTER);
}
}

REGISTERED.set(true);
logger.info("Register actuator done, total {}.", subTypes.size());
}
}

}
16 changes: 7 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,11 @@ ext.archInfo = [
VMOptions: isArm64 ? "${rootDir}/gradle/jdk17/java-tron.vmoptions" : "${rootDir}/gradle/java-tron.vmoptions"
]

if (!archInfo.java.is(archInfo.requires.JavaVersion)) {
throw new GradleException("Java ${archInfo.requires.JavaVersion} is required for ${archInfo.name}. Detected version ${archInfo.java}")
}

println "Building for architecture: ${archInfo.name}, Java version: ${archInfo.java}"


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

Expand Down Expand Up @@ -86,7 +83,7 @@ subprojects {
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.13'
implementation "com.google.code.findbugs:jsr305:3.0.0"
implementation group: 'org.springframework', name: 'spring-context', version: "${springVersion}"
implementation "org.apache.commons:commons-lang3:3.4"
implementation "org.apache.commons:commons-lang3:3.18.0"
implementation group: 'org.apache.commons', name: 'commons-math', version: '2.2'
implementation "org.apache.commons:commons-collections4:4.1"
implementation group: 'joda-time', name: 'joda-time', version: '2.3'
Expand All @@ -108,14 +105,15 @@ subprojects {
testImplementation "org.mockito:mockito-inline:4.11.0"
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
tasks.register('sourcesJar', Jar) {
dependsOn classes
archiveClassifier.set('sources')
from sourceSets.main.allSource
duplicatesStrategy = DuplicatesStrategy.INCLUDE // allow duplicates
}


tasks.withType(AbstractArchiveTask) {
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
duplicatesStrategy = DuplicatesStrategy.INCLUDE // allow duplicates
Expand Down Expand Up @@ -149,7 +147,7 @@ subprojects {
}
}

task copyToParent(type: Copy) {
tasks.register('copyToParent', Copy) {
into "$buildDir/libs"
subprojects {
from tasks.withType(Jar)
Expand Down
4 changes: 2 additions & 2 deletions chainbase/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ test {
jacocoTestReport {
dependsOn(processResources) // explicit_dependency
reports {
xml.enabled = true
html.enabled = true
xml.required.set(true)
html.required.set(true)
}
getExecutionData().setFrom(fileTree('../framework/build/jacoco').include("**.exec"))
afterEvaluate {
Expand Down
7 changes: 6 additions & 1 deletion chainbase/src/main/java/org/tron/core/ChainBaseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.tron.core.store.NullifierStore;
import org.tron.core.store.ProposalStore;
import org.tron.core.store.SectionBloomStore;
import org.tron.core.store.StateRootStore;
import org.tron.core.store.StorageRowStore;
import org.tron.core.store.TransactionHistoryStore;
import org.tron.core.store.TransactionRetStore;
Expand Down Expand Up @@ -233,6 +234,10 @@ public class ChainBaseManager {
@Getter
private SectionBloomStore sectionBloomStore;

@Autowired
@Getter
private StateRootStore stateRootStore;

@Autowired
private DbStatService dbStatService;

Expand Down Expand Up @@ -315,7 +320,7 @@ public boolean containBlockInMainChain(BlockId blockId) {
}
}

public BlockCapsule getKhaosDbHead(){
public BlockCapsule getKhaosDbHead() {
return this.khaosDb.getHead();
}

Expand Down
10 changes: 10 additions & 0 deletions chainbase/src/main/java/org/tron/core/capsule/BlockCapsule.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,16 @@ public String toString() {
return toStringBuff.toString();
}

public Sha256Hash getStateRoot() {
ByteString stateRoot = this.block.getBlockHeader().getStateRoot();
return stateRoot.isEmpty() ? Sha256Hash.ZERO_HASH : Sha256Hash.wrap(stateRoot);
}

public void clearStateRoot() {
BlockHeader blockHeader = this.block.getBlockHeader().toBuilder().clearStateRoot().build();
this.block = this.block.toBuilder().setBlockHeader(blockHeader).build();
}

public static class BlockId extends Sha256Hash {

private long num;
Expand Down
4 changes: 4 additions & 0 deletions chainbase/src/main/java/org/tron/core/db/TronDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public DbSourceInter<byte[]> getDbSource() {
}

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.tron.common.error.TronDBException;
import org.tron.common.es.ExecutorServiceManager;
Expand All @@ -49,7 +50,7 @@ public class SnapshotManager implements RevokingDatabase {

public static final int DEFAULT_MIN_FLUSH_COUNT = 1;
private static final int DEFAULT_STACK_MAX_SIZE = 256;
private static final long ONE_MINUTE_MILLS = 60*1000L;
private static final long ONE_MINUTE_MILLS = 60 * 1000L;
private static final String CHECKPOINT_V2_DIR = "checkpoint";
@Getter
private List<Chainbase> dbs = new ArrayList<>();
Expand Down Expand Up @@ -79,6 +80,9 @@ public class SnapshotManager implements RevokingDatabase {
@Getter
private CheckTmpStore checkTmpStore;

@Autowired
private ObjectFactory<CheckPointV2Store> checkPointV2Store;

@Setter
private volatile int maxFlushCount = DEFAULT_MIN_FLUSH_COUNT;

Expand Down Expand Up @@ -385,8 +389,7 @@ public void createCheckpoint() {
}
}
if (isV2Open()) {
String dbName = String.valueOf(System.currentTimeMillis());
checkPointStore = getCheckpointDB(dbName);
checkPointStore = checkPointV2Store.getObject();
} else {
checkPointStore = checkTmpStore;
}
Expand All @@ -405,7 +408,7 @@ public void createCheckpoint() {
}

private TronDatabase<byte[]> getCheckpointDB(String dbName) {
return new CheckPointV2Store(CHECKPOINT_V2_DIR+"/"+dbName);
return new CheckPointV2Store(CHECKPOINT_V2_DIR, dbName);
}

public List<String> getCheckpointList() {
Expand All @@ -431,7 +434,7 @@ private void deleteCheckpoint() {
for (Map.Entry<byte[], byte[]> e : checkTmpStore.getDbSource()) {
hmap.put(e.getKey(), null);
}
if (hmap.size() != 0) {
if (!hmap.isEmpty()) {
checkTmpStore.getDbSource().updateByBatch(hmap);
}
} catch (Exception e) {
Expand All @@ -450,10 +453,10 @@ private void pruneCheckpoint() {
if (cpList.size() < 3) {
return;
}
long latestTimestamp = Long.parseLong(cpList.get(cpList.size()-1));
for (String cp: cpList.subList(0, cpList.size()-3)) {
long latestTimestamp = Long.parseLong(cpList.get(cpList.size() - 1));
for (String cp: cpList.subList(0, cpList.size() - 3)) {
long timestamp = Long.parseLong(cp);
if (latestTimestamp - timestamp <= ONE_MINUTE_MILLS*2) {
if (latestTimestamp - timestamp <= ONE_MINUTE_MILLS * 2) {
break;
}
String checkpointPath = Paths.get(StorageUtils.getOutputDirectoryByDbName(CHECKPOINT_V2_DIR),
Expand Down
Loading
Loading