Skip to content

Commit

Permalink
Merge pull request #326 from LucasMLK/develop
Browse files Browse the repository at this point in the history
 Improve performance and update dependencies
  • Loading branch information
LucasMLK authored Dec 4, 2024
2 parents f6c773d + 1a2d009 commit 3924296
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 320 deletions.
20 changes: 12 additions & 8 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'

- name: Build with Maven
run: mvn clean package
155 changes: 57 additions & 98 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,41 @@
<dist.phase>package</dist.phase>
<dist.base>${project.basedir}/dist</dist.base>

<netty.version>4.1.111.Final</netty.version>
<xdagj-native-randomx.version>0.1.8</xdagj-native-randomx.version>
<netty.version>4.1.115.Final</netty.version>
<tuweni.version>2.4.2</tuweni.version>
<jackson.version>2.17.1</jackson.version>
<jackson.version>2.18.2</jackson.version>
<kryo.version>5.5.0</kryo.version>
<lombok.version>1.18.32</lombok.version>
<lombok.version>1.18.36</lombok.version>
<caffeine.version>3.1.8</caffeine.version>
<jline.version>3.26.2</jline.version>
<jline.version>3.26.3</jline.version>
<junit.version>4.13.2</junit.version>
<mockito.version>5.11.0</mockito.version>
<mockito.version>5.14.2</mockito.version>
<system-lambda.version>1.2.1</system-lambda.version>
<log4j.version>2.23.1</log4j.version>
<commons-lang3.version>3.14.0</commons-lang3.version>
<commons-rng.version>1.5</commons-rng.version>
<commons-collections4.version>4.5.0-M1</commons-collections4.version>
<commons-codec.version>1.17.0</commons-codec.version>
<commons-io.version>2.16.1</commons-io.version>
<commons-cli.version>1.8.0</commons-cli.version>
<guava.version>33.2.1-jre</guava.version>
<rocksdbjni.version>9.2.1</rocksdbjni.version>
<log4j.version>2.24.2</log4j.version>
<commons-lang3.version>3.17.0</commons-lang3.version>
<commons-rng.version>1.6</commons-rng.version>
<commons-collections4.version>4.5.0-M2</commons-collections4.version>
<commons-codec.version>1.17.1</commons-codec.version>
<commons-io.version>2.18.0</commons-io.version>
<commons-cli.version>1.9.0</commons-cli.version>
<guava.version>33.3.1-jre</guava.version>
<rocksdbjni.version>9.7.3</rocksdbjni.version>
<okhttp.version>4.12.0</okhttp.version>
<assertj-core.version>3.26.0</assertj-core.version>
<crypto.version>23.1.3</crypto.version>
<bcprov-jdk18on.version>1.78</bcprov-jdk18on.version>
<bcpkix-jdk18on.version>1.78</bcpkix-jdk18on.version>
<vertx-core.version>4.5.7</vertx-core.version>
<bcprov-jdk18on.version>1.79</bcprov-jdk18on.version>
<bcpkix-jdk18on.version>1.79</bcpkix-jdk18on.version>
<vertx-core.version>4.5.11</vertx-core.version>
<jsonrpc4j.version>1.6</jsonrpc4j.version>
<jaxws-ri.version>4.0.2</jaxws-ri.version>
<config.version>1.4.3</config.version>
<agrona.version>1.21.2</agrona.version>
<snappy-java.version>1.1.10.4</snappy-java.version>
<druid.version>1.2.23</druid.version>
<snappy-java.version>1.1.10.7</snappy-java.version>
<druid.version>1.2.24</druid.version>
<mysql-connector.version>8.4.0</mysql-connector.version>
<h2.version>2.2.224</h2.version>
<gson.version>2.10</gson.version>
<h2.version>2.3.232</h2.version>
<gson.version>2.11.0</gson.version>
<jws-api.version>2.1.0</jws-api.version>
<surefire.test.excludes>**/*RandomXSyncTest.java,**/*SyncTest.java,**/*SnapshotJTest.java</surefire.test.excludes>
</properties>
Expand Down Expand Up @@ -113,7 +114,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.13.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
Expand All @@ -128,7 +129,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<version>3.5.2</version>
<configuration>
<argLine>-Xmx2048m</argLine>
<excludes>
Expand All @@ -141,7 +142,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<version>3.4.2</version>
<configuration>
<archive>
<index>true</index>
Expand All @@ -154,11 +155,25 @@
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>

<!-- license header check -->
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>4.2</version>
<version>4.6</version>
<configuration>
<licenseSets>
<licenseSet>
Expand All @@ -182,7 +197,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -228,28 +243,24 @@
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
<transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
<resource>.SF</resource>
<resource>NOTICE</resource>
<resource>AL2.0</resource>
<resource>LGPL2.1</resource>
<resource>LICENSE.txt</resource>
<resource>NOTICE.txt</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>LICENSE</resource>
<resource>en-mnemonic-word-list.txt</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>io.xdag.Bootstrap</Main-Class>
<X-Compile-Source-JDK>${maven.compiler.source}
</X-Compile-Source-JDK>
<X-Compile-Target-JDK>${maven.compiler.target}
</X-Compile-Target-JDK>
<X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
<X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</transformer>
Expand Down Expand Up @@ -306,70 +317,18 @@
<phase>${dist.phase}</phase>
<configuration>
<target>
<!-- windows build -->
<copy file="${project.basedir}/target/xdagj-${project.version}-shaded.jar"
tofile="${dist.base}/windows/xdagj-${project.version}-shaded.jar"/>
<copy file="src/main/resources/log4j2.xml"
tofile="${dist.base}/windows/log4j2.xml"/>
<copy file="src/main/resources/xdag-mainnet.conf"
tofile="${dist.base}/windows/xdag-mainnet.conf"/>
<copy file="src/main/resources/xdag-testnet.conf"
tofile="${dist.base}/windows/xdag-testnet.conf"/>
<copy file="src/main/resources/xdag-devnet.conf"
tofile="${dist.base}/windows/xdag-devnet.conf"/>
<copy file="src/main/resources/rpc_modules.conf"
tofile="${dist.base}/windows/rpc_modules.conf"/>
<copy file="src/main/resources/druid.properties"
tofile="${dist.base}/windows/druid.properties"/>
<copy file="${dist.base}/xdag.bat"
tofile="${dist.base}/windows/xdag.bat"/>
<zip basedir="${dist.base}/windows/"
destfile="${dist.base}/xdagj-windows.zip"/>
<delete dir="${dist.base}/windows/" includeemptydirs="true"/>

<!-- linux build (executable jar) -->
<copy file="${project.basedir}/target/xdagj-${project.version}-shaded.jar"
tofile="${dist.base}/linux/xdagj-${project.version}-shaded.jar"/>
<copy file="src/main/resources/log4j2.xml"
tofile="${dist.base}/linux/log4j2.xml"/>
<copy file="src/main/resources/xdag-mainnet.conf"
tofile="${dist.base}/linux/xdag-mainnet.conf"/>
<copy file="src/main/resources/xdag-testnet.conf"
tofile="${dist.base}/linux/xdag-testnet.conf"/>
<copy file="src/main/resources/xdag-devnet.conf"
tofile="${dist.base}/linux/xdag-devnet.conf"/>
<copy file="src/main/resources/rpc_modules.conf"
tofile="${dist.base}/linux/rpc_modules.conf"/>
<copy file="src/main/resources/druid.properties"
tofile="${dist.base}/linux/druid.properties"/>
<copy file="${dist.base}/xdag.sh"
tofile="${dist.base}/linux/xdag.sh"/>
<copy file="${project.basedir}/target/xdagj-${project.version}-shaded.jar" tofile="${dist.base}/linux/xdagj-${project.version}-shaded.jar"/>
<copy file="src/main/resources/log4j2.xml" tofile="${dist.base}/linux/log4j2.xml"/>
<copy file="src/main/resources/xdag-mainnet.conf" tofile="${dist.base}/linux/xdag-mainnet.conf"/>
<copy file="src/main/resources/xdag-testnet.conf" tofile="${dist.base}/linux/xdag-testnet.conf"/>
<copy file="src/main/resources/xdag-devnet.conf" tofile="${dist.base}/linux/xdag-devnet.conf"/>
<copy file="src/main/resources/rpc_modules.conf" tofile="${dist.base}/linux/rpc_modules.conf"/>
<copy file="src/main/resources/druid.properties" tofile="${dist.base}/linux/druid.properties"/>
<copy file="${dist.base}/xdag.bat" tofile="${dist.base}/windows/xdag.bat"/>
<copy file="${dist.base}/xdag.sh" tofile="${dist.base}/linux/xdag.sh"/>
<chmod file="${dist.base}/linux/xdag.sh" perm="755"/>
<zip basedir="${dist.base}/linux/"
destfile="${dist.base}/xdagj-linux.zip"/>
<delete dir="${dist.base}/linux/" includeemptydirs="true"/>

<!-- macos build -->
<copy file="${project.basedir}/target/xdagj-${project.version}-shaded.jar"
tofile="${dist.base}/macos/xdagj-${project.version}-shaded.jar"/>
<copy file="src/main/resources/log4j2.xml"
tofile="${dist.base}/macos/log4j2.xml"/>
<copy file="src/main/resources/xdag-mainnet.conf"
tofile="${dist.base}/macos/xdag-mainnet.conf"/>
<copy file="src/main/resources/xdag-testnet.conf"
tofile="${dist.base}/macos/xdag-testnet.conf"/>
<copy file="src/main/resources/xdag-devnet.conf"
tofile="${dist.base}/macos/xdag-devnet.conf"/>
<copy file="src/main/resources/rpc_modules.conf"
tofile="${dist.base}/macos/rpc_modules.conf"/>
<copy file="src/main/resources/druid.properties"
tofile="${dist.base}/macos/druid.properties"/>
<copy file="${dist.base}/xdag.sh"
tofile="${dist.base}/macos/xdag.sh"/>
<chmod file="${dist.base}/macos/xdag.sh" perm="755"/>
<zip basedir="${dist.base}/macos/"
destfile="${dist.base}/xdagj-macos.zip"/>
<delete dir="${dist.base}/macos/" includeemptydirs="true"/>
<zip basedir="${dist.base}/" destfile="${dist.base}/xdagj.zip"/>
<delete dir="${dist.base}/" includeemptydirs="true"/>
</target>
</configuration>
<goals>
Expand Down Expand Up @@ -399,7 +358,7 @@
<dependency>
<groupId>io.xdag</groupId>
<artifactId>xdagj-native-randomx</artifactId>
<version>0.1.7</version>
<version>${xdagj-native-randomx.version}</version>
</dependency>

<!-- Logging framework -->
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/io/xdag/Kernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,6 @@ public synchronized void testStop() {
dbFactory.getDB(name).close();
}

// release
randomx.randomXPoolReleaseMem();
log.info("Release randomx");
webSocketServer.stop();
log.info("WebSocket server stop.");
poolAwardManager.stop();
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/io/xdag/cli/Shell.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.jline.reader.impl.DefaultParser;
import org.jline.terminal.Terminal;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -164,8 +165,10 @@ private void processOldBalance(CommandInput input) {
}

private void println(final String msg) {
reader.getTerminal().writer().println(msg);
reader.getTerminal().writer().flush();
try(PrintWriter writer = reader.getTerminal().writer()) {
writer.println(msg);
writer.flush();
}
}

private void processAccount(CommandInput input) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/xdag/consensus/XdagPow.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ protected void onNewShare(Bytes32 share) {
taskData.set(0, task.getTask()[0].getData());// preHash
taskData.set(32, share);// share
// Calculate hash
hash = Bytes32.wrap(kernel.getRandomx()
.randomXPoolCalcHash(taskData, taskData.size(), task.getTaskTime()).reverse());
hash = Bytes32.wrap(kernel.getRandomx().randomXPoolCalcHash(taskData, task.getTaskTime()).reverse());
} else {
XdagSha256Digest digest = new XdagSha256Digest(task.getDigest());
hash = Bytes32.wrap(digest.sha256Final(share.reverse()));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/xdag/core/BlockchainImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ public BigInteger getDiffByRandomXHash(Block block) {
Bytes32 rxHash = Hash.sha256(block.getXdagBlock().getData().slice(0, 512 - 32));
data.set(0, rxHash);
data.set(32, block.getXdagBlock().getField(15).getData());
byte[] blockHash = randomx.randomXBlockHash(data.toArray(), data.size(), epoch);
byte[] blockHash = randomx.randomXBlockHash(data.toArray(), epoch);
BigInteger diff;
if (blockHash != null) {
Bytes32 hash = Bytes32.wrap(Arrays.reverse(blockHash));
Expand Down
Loading

0 comments on commit 3924296

Please sign in to comment.