Skip to content

Commit

Permalink
Merge pull request #324 from XDagger/develop
Browse files Browse the repository at this point in the history
merge to master
  • Loading branch information
LucasMLK authored Jul 1, 2024
2 parents 406caef + f6c773d commit 3c2e28f
Show file tree
Hide file tree
Showing 63 changed files with 382 additions and 874 deletions.
102 changes: 56 additions & 46 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,52 @@

<groupId>io.xdag</groupId>
<artifactId>xdagj</artifactId>
<version>0.7.1</version>
<version>0.7.2</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<kotlin.version>1.7.22</kotlin.version>
<kotlin.version>1.8.21</kotlin.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<dist.phase>package</dist.phase>
<dist.base>${project.basedir}/dist</dist.base>

<netty.version>4.1.107.Final</netty.version>
<tuweni.version>2.3.1</tuweni.version>
<json.version>2.14.2</json.version>
<kryo.version>5.4.0</kryo.version>
<lombok.version>1.18.26</lombok.version>
<caffeine.version>3.1.5</caffeine.version>
<jline.version>3.25.0</jline.version>
<netty.version>4.1.111.Final</netty.version>
<tuweni.version>2.4.2</tuweni.version>
<jackson.version>2.17.1</jackson.version>
<kryo.version>5.5.0</kryo.version>
<lombok.version>1.18.32</lombok.version>
<caffeine.version>3.1.8</caffeine.version>
<jline.version>3.26.2</jline.version>
<junit.version>4.13.2</junit.version>
<mockito.version>5.2.0</mockito.version>
<mockito.version>5.11.0</mockito.version>
<system-lambda.version>1.2.1</system-lambda.version>
<log4j.version>2.20.0</log4j.version>
<commons-lang3.version>3.13.0</commons-lang3.version>
<commons-collections4.version>4.4</commons-collections4.version>
<commons-codec.version>1.16.0</commons-codec.version>
<commons-io.version>2.13.0</commons-io.version>
<commons-cli.version>1.5.0</commons-cli.version>
<guava.version>32.1.2-jre</guava.version>
<rocksdbjni.version>8.0.0</rocksdbjni.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>
<okhttp.version>4.12.0</okhttp.version>
<assertj-core.version>3.24.2</assertj-core.version>
<assertj-core.version>3.26.0</assertj-core.version>
<crypto.version>23.1.3</crypto.version>
<bcprov-jdk18on.version>1.76</bcprov-jdk18on.version>
<bcpkix-jdk18on.version>1.76</bcpkix-jdk18on.version>
<vertx-core.version>4.4.0</vertx-core.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>
<jsonrpc4j.version>1.6</jsonrpc4j.version>
<jaxws-ri.version>4.0.1</jaxws-ri.version>
<config.version>1.4.2</config.version>
<agrona.version>1.17.1</agrona.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.18</druid.version>
<mysql-connector.version>8.0.33</mysql-connector.version>
<h2.version>2.2.220</h2.version>
<druid.version>1.2.23</druid.version>
<mysql-connector.version>8.4.0</mysql-connector.version>
<h2.version>2.2.224</h2.version>
<gson.version>2.10</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 @@ -90,6 +93,11 @@
<id>hyperledger.jfrog.io</id>
<url>https://hyperledger.jfrog.io/artifactory/besu-maven/</url>
</repository>
<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>

<pluginRepositories>
Expand Down Expand Up @@ -388,7 +396,6 @@
</build>

<dependencies>
<!-- https://mvnrepository.com/artifact/io.xdag/xdagj-native-randomx -->
<dependency>
<groupId>io.xdag</groupId>
<artifactId>xdagj-native-randomx</artifactId>
Expand Down Expand Up @@ -432,6 +439,12 @@
<version>${commons-collections4.version}</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-rng-simple</artifactId>
<version>${commons-rng.version}</version>
</dependency>

<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
Expand Down Expand Up @@ -619,7 +632,7 @@
</dependency>

<dependency>
<groupId>org.apache.tuweni</groupId>
<groupId>io.tmio</groupId>
<artifactId>tuweni-bytes</artifactId>
<version>${tuweni.version}</version>
<exclusions>
Expand All @@ -635,7 +648,7 @@
</dependency>

<dependency>
<groupId>org.apache.tuweni</groupId>
<groupId>io.tmio</groupId>
<artifactId>tuweni-units</artifactId>
<version>${tuweni.version}</version>
<exclusions>
Expand All @@ -647,7 +660,7 @@
</dependency>

<dependency>
<groupId>org.apache.tuweni</groupId>
<groupId>io.tmio</groupId>
<artifactId>tuweni-io</artifactId>
<version>${tuweni.version}</version>
<exclusions>
Expand Down Expand Up @@ -793,22 +806,21 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${json.version}</version>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${json.version}</version>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${json.version}</version>
<version>${jackson.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.github.briandilley.jsonrpc4j/jsonrpc4j -->
<dependency>
<groupId>com.github.briandilley.jsonrpc4j</groupId>
<artifactId>jsonrpc4j</artifactId>
Expand Down Expand Up @@ -862,22 +874,25 @@
</exclusions>
</dependency>

<dependency>
<groupId>jakarta.jws</groupId>
<artifactId>jakarta.jws-api</artifactId>
<version>${jws-api.version}</version>
</dependency>

<!--config-->
<!-- https://mvnrepository.com/artifact/com.typesafe/config -->
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>${config.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.agrona/agrona -->
<dependency>
<groupId>org.agrona</groupId>
<artifactId>agrona</artifactId>
<version>${agrona.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.xerial.snappy/snappy-java -->
<dependency>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
Expand All @@ -901,16 +916,11 @@
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
<version>${gson.version}</version>
<scope>compile</scope>
</dependency>

Expand Down
50 changes: 9 additions & 41 deletions src/main/java/io/xdag/Kernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
import io.xdag.rpc.cors.CorsConfiguration;
import io.xdag.rpc.modules.xdag.*;
import io.xdag.rpc.netty.*;
import io.xdag.rpc.serialize.JacksonBasedRpcSerializer;
import io.xdag.rpc.serialize.JsonRpcSerializer;
import io.xdag.utils.XdagTime;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -112,10 +110,8 @@ public class Kernel {
// rpc
private JsonRpcWeb3ServerHandler jsonRpcWeb3ServerHandler;
private Web3 web3;
private Web3WebSocketServer web3WebSocketServer;
private Web3HttpServer web3HttpServer;
private JsonRpcWeb3FilterHandler jsonRpcWeb3FilterHandler;
private JacksonBasedRpcSerializer jacksonBasedRpcSerializer;

public Kernel(Config config, Wallet wallet) {
this.config = config;
Expand Down Expand Up @@ -300,7 +296,6 @@ public synchronized void testStart() throws Exception {
// ====================================
if (config.getRPCSpec().isRPCEnabled()) {
getWeb3HttpServer().start();
getWeb3WebSocketServer().start();
}

// ====================================
Expand Down Expand Up @@ -335,36 +330,13 @@ private JsonRpcWeb3ServerHandler getJsonRpcWeb3ServerHandler() {
config.getRPCSpec().getRpcModules()
);
} catch (Exception e) {
log.error("catch an error " + e.getMessage());
log.error("catch an error {}", e.getMessage());
}
}

return jsonRpcWeb3ServerHandler;
}

public WebSocketServer getWsServer() {
if (webSocketServer == null) {
webSocketServer = new WebSocketServer(this, config.getPoolWhiteIPList(),
config.getWebsocketServerPort());
}
return webSocketServer;
}

private Web3WebSocketServer getWeb3WebSocketServer() throws UnknownHostException {
if (web3WebSocketServer == null) {
JsonRpcSerializer jsonRpcSerializer = getJsonRpcSerializer();
XdagJsonRpcHandler jsonRpcHandler = new XdagJsonRpcHandler(jsonRpcSerializer);
web3WebSocketServer = new Web3WebSocketServer(
InetAddress.getByName(config.getRPCSpec().getRPCHost()),
config.getRPCSpec().getRPCPortByWebSocket(),
jsonRpcHandler,
getJsonRpcWeb3ServerHandler()
);
}

return web3WebSocketServer;
}

private Web3HttpServer getWeb3HttpServer() throws UnknownHostException {
if (web3HttpServer == null) {
web3HttpServer = new Web3HttpServer(
Expand All @@ -381,6 +353,14 @@ private Web3HttpServer getWeb3HttpServer() throws UnknownHostException {
return web3HttpServer;
}

public WebSocketServer getWsServer() {
if (webSocketServer == null) {
webSocketServer = new WebSocketServer(this, config.getPoolWhiteIPList(),
config.getWebsocketServerPort());
}
return webSocketServer;
}

private JsonRpcWeb3FilterHandler getJsonRpcWeb3FilterHandler() throws UnknownHostException {
if (jsonRpcWeb3FilterHandler == null) {
jsonRpcWeb3FilterHandler = new JsonRpcWeb3FilterHandler(
Expand All @@ -393,14 +373,6 @@ private JsonRpcWeb3FilterHandler getJsonRpcWeb3FilterHandler() throws UnknownHos
return jsonRpcWeb3FilterHandler;
}

private JsonRpcSerializer getJsonRpcSerializer() {
if (jacksonBasedRpcSerializer == null) {
jacksonBasedRpcSerializer = new JacksonBasedRpcSerializer();
}

return jacksonBasedRpcSerializer;
}

/**
* Stops the kernel.
*/
Expand All @@ -416,9 +388,6 @@ public synchronized void testStop() {
if (web3HttpServer != null) {
web3HttpServer.stop();
}
if (web3WebSocketServer != null) {
web3WebSocketServer.stop();
}

// 1. 工作层关闭
// stop consensus
Expand Down Expand Up @@ -465,7 +434,6 @@ public synchronized void testStop() {
log.info("Pool award manager stop.");
}


public enum Status {
STOPPED, SYNCING, BLOCK_PRODUCTION_ON, SYNCDONE
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/xdag/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ protected void addOption(Option option) {

/**
* Parses options from the given arguments.
*
* Priority: arguments => system property => console input
*/
protected CommandLine parseOptions(String[] args) throws ParseException {
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/io/xdag/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public class Wallet {
private static final int SALT_LENGTH = 16;
private static final int BCRYPT_COST = 12;
private static final String MNEMONIC_PASS_PHRASE = "";
/**
* -- GETTER --
* Returns the file where the wallet is persisted.
*/
@Getter
private final File file;
private final Config config;

Expand Down Expand Up @@ -123,13 +128,6 @@ public void delete() throws IOException {
Files.delete(file.toPath());
}

/**
* Returns the file where the wallet is persisted.
*/
public File getFile() {
return file;
}

/**
* Locks the wallet.
*/
Expand Down Expand Up @@ -502,7 +500,7 @@ public List<BlockWrapper> createTransactionBlock(Map<Address, KeyPair> ourKeys,
int base = 1 + 1 + 2 + hasRemark;
XAmount amount = XAmount.ZERO;

while (stack.size() > 0) {
while (!stack.isEmpty()) {
Map.Entry<Address, KeyPair> key = stack.peek();
base += 1;
int originSize = keysPerBlock.size();
Expand All @@ -527,7 +525,7 @@ public List<BlockWrapper> createTransactionBlock(Map<Address, KeyPair> ourKeys,
amount = XAmount.ZERO;
}
}
if (keys.size() != 0) {
if (!keys.isEmpty()) {
res.add(createTransaction(to, amount, keys, remark));
}

Expand Down Expand Up @@ -571,12 +569,12 @@ private Block createNewBlock(Map<Address, KeyPair> pairs, List<Address> to,
int defKeyIndex = -1;

// if no input, return null
if (pairs == null || pairs.size() == 0) {
if (pairs == null || pairs.isEmpty()) {
return null;
}

// if no output, return null
if (to == null || to.size() == 0) {
if (to == null || to.isEmpty()) {
return null;
}

Expand Down
Loading

0 comments on commit 3c2e28f

Please sign in to comment.