Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 4430b41

Browse files
committed
Merge branch 'develop'
2 parents b17cb8a + c887e11 commit 4430b41

File tree

149 files changed

+2773
-775
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+2773
-775
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ dist: trusty
44
language: java
55
jdk: oraclejdk8
66

7+
before_script:
8+
- cd $HOME && mkdir tests && cd tests && git clone https://github.com/ethereum/tests.git . && cd $TRAVIS_BUILD_DIR
9+
710
# publish snapshots to https://oss.jfrog.org/libs-snapshot/org/ethereum/ethereumj-core
811
# publish releases to http://jcenter.bintray.com/org/ethereum/ethereumj-core
912
# publish coverage to https://coveralls.io/r/ethereum/ethereumj
1013
script:
11-
- ./gradlew clean build publish jacocoTestReport coveralls --stacktrace --info
14+
- ./gradlew clean build publish jacocoTestReport coveralls $TESTS_OPTS --stacktrace --info
1215

1316

1417
cache:
@@ -44,5 +47,6 @@ notifications:
4447
env:
4548
global:
4649
- JAVA_OPTS="-XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled"
50+
- TESTS_OPTS="-DGitHubTests.testPath=$HOME/tests"
4751
- secure: "OlSe9DlT1D/b/ru3uO1m8nwevaDhH9XGmAfJ/2U69eBwRtg/aLEF9ZpULrMNTDR8XbNT6uuZsvvRby5HOKPRRkOqnWIY8He2hRpw0IYDONfRfKXIcr4WuJM3N98mQ9RYoNcV9LbHoXFQtfc7oUIp5o7WsCx5Pd/Ygyz4ZVNBc5g="
4852
- secure: "Y5L4DJXonAavfoUAMgM+RUTVYfyT5YkB8yBp8oUTK6RMCUrSTXB2Kpa8fvP8gvPXIXpIQgxa+bn/85wSrFAm8I9e4zXYO/1h4TPsbXrE1KB3aIXlg96wr1WRg+YyWed1VOtrCDZhO0K9l2fEG4ktysv+vtSaDxRVjtnFX+0Xymk="

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ git clone https://github.com/ethereum/ethereumj
4242
cd ethereumj
4343
cp ethereumj-core/src/main/resources/ethereumj.conf ethereumj-core/src/main/resources/user.conf
4444
vim ethereumj-core/src/main/resources/user.conf # adjust user.conf to your needs
45-
./gradlew clean shadowJar
45+
./gradlew clean fatJar
4646
java -jar ethereumj-core/build/libs/ethereumj-core-*-all.jar
4747
```
4848

ethereumj-core/build.gradle

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ buildscript {
88
dependencies {
99
classpath 'io.spring.gradle:propdeps-plugin:0.0.9.RELEASE'
1010
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1'
11+
classpath 'com.typesafe:config:1.2.1'
1112
}
1213
}
1314

@@ -17,6 +18,7 @@ plugins {
1718
id 'jacoco'
1819
id 'com.github.kt3k.coveralls' version '2.6.3'
1920
id 'com.jfrog.bintray' version '1.0'
21+
id 'org.ajoberstar.grgit' version '2.2.0' apply false
2022
}
2123

2224
apply plugin: 'propdeps-maven'
@@ -78,15 +80,25 @@ task tckRun(type:JavaExec){
7880
classpath = sourceSets.test.runtimeClasspath
7981
}
8082

81-
82-
83+
/**
84+
* Runs all tests
85+
* EthereumJ also runs common Ethereum clients tests
86+
* See {@link #prepareGithubTests()} if you want to use local repo
87+
* instead of downloading tests during test execution
88+
*/
8389
test {
8490

8591
beforeTest { descriptor ->
8692
logger.lifecycle("Running test: ${descriptor}")
8793
}
8894

89-
jvmArgs '-Xss8m', '-Xmx3G'
95+
jvmArgs = ["-Xss8m", "-Xmx3G"]
96+
97+
prepareGithubTests()
98+
// If Github tests directory is provided, it's passed to test runner
99+
if (System.getProperty("GitHubTests.testPath") != null) {
100+
jvmArgs.add('-DGitHubTests.testPath' + '=' + System.getProperty("GitHubTests.testPath"))
101+
}
90102

91103
testLogging {
92104
events "failed"
@@ -165,6 +177,16 @@ javadoc {
165177
)
166178
}
167179

180+
//create a single Jar with all dependencies
181+
task fatJar(type: Jar) {
182+
classifier = 'all'
183+
manifest {
184+
attributes 'Main-Class' : mainClassName
185+
attributes 'Class-Path' : configurations.compile.collect { 'lib/' + it.getName() }.join(' ')
186+
}
187+
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
188+
with jar
189+
}
168190

169191
task sourcesJar(type: Jar, dependsOn: classes) {
170192
classifier = 'sources'
@@ -346,3 +368,73 @@ def gitCurBranch() {
346368
return process.text.trim()
347369
}
348370

371+
/**
372+
* This method is used to prepare local Ethereum Github tests for EthereumJ tests
373+
*
374+
* These tests are designed for all Ethereum clients and
375+
* maintained by Ethereum Foundation/Community.
376+
* EthereumJ executes all of them but by default downloads every
377+
* single file using internet connection.
378+
* Alternatively you could use local repo to run tests from it.
379+
*
380+
* Common usage:
381+
* 1) Local run:
382+
* a. Clone Ethereum tests repo (https://github.com/ethereum/tests)
383+
* to some local directory
384+
* b. Create `test-user.conf` file in test resources directory.
385+
* This file is under `.gitignore`, so it's your local file only.
386+
* You could override any EthereumJ configuration in it, but
387+
* for using local Ethereum tests repo you need following line:
388+
* GitHubTests.testPath=/some/path/with/Ethereum/tests/repo
389+
* c. Run `./gradlew test` task.
390+
* 2) CI run:
391+
* a. Clone Ethereum tests repo (https://github.com/ethereum/tests)
392+
* to some local directory
393+
* b. Run `test` task with following parameter:
394+
* -DGitHubTests.testPath=/some/path/with/Ethereum/tests/repo
395+
*
396+
* In both cases this method will get commit hash from
397+
* `src/test/resources/github-tests.prop` and checkout local repo
398+
* to specific commit. So, EthereumJ tests will run common
399+
* Ethereum client tests using local copy of repository.
400+
*
401+
* Repo with tests is changed often and EthereumJ is guaranteed
402+
* to pass only tests from specific commit.
403+
*/
404+
import org.ajoberstar.grgit.Grgit
405+
import com.typesafe.config.Config
406+
import com.typesafe.config.ConfigFactory
407+
def prepareGithubTests() {
408+
String testsPathKey = "GitHubTests.testPath"
409+
String testsCommitKey = "GitHubTests.commit"
410+
String testUserConf = "ethereumj-core/src/test/resources/test-user.conf"
411+
String githubTestsProp = "ethereumj-core/src/test/resources/github-tests.prop"
412+
def repoPath = System.getProperty(testsPathKey)
413+
if (repoPath == null) {
414+
try {
415+
Config userTest = ConfigFactory.parseFile(new File(testUserConf))
416+
repoPath = userTest.getString(testsPathKey)
417+
} catch (Exception ex) {}
418+
}
419+
if (repoPath == null) return
420+
def commit = System.getProperty(testsCommitKey)
421+
if (commit == null) {
422+
Properties testProp = new Properties();
423+
testProp.load(new File(githubTestsProp).newDataInputStream());
424+
commit = testProp.getProperty(testsCommitKey)
425+
}
426+
if (repoPath != null && commit != null) {
427+
println "Tests: Checking out Ethereum Tests repo at " + repoPath + " to commit #" + commit
428+
try {
429+
def testsRepo = Grgit.open(dir: repoPath)
430+
testsRepo.fetch()
431+
testsRepo.checkout(branch: commit)
432+
} catch (Exception ex) {
433+
println "Error occurs while trying to checkout local Ethereum tests repo to specific commit"
434+
println "Either remove " + testsPathKey + " property to use remote repo in tests or fix the issue"
435+
println "Error: "
436+
println ex
437+
throw ex
438+
}
439+
}
440+
}

ethereumj-core/src/main/java/org/ethereum/Start.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static void main(String args[]) throws IOException, URISyntaxException {
3737
CLIInterface.call(args);
3838

3939
final SystemProperties config = SystemProperties.getDefault();
40-
final boolean actionBlocksLoader = !config.blocksLoader().equals("");
40+
final boolean actionBlocksLoader = !config.blocksLoader().isEmpty();
4141
final boolean actionGenerateDag = !StringUtils.isEmpty(System.getProperty("ethash.blockNumber"));
4242

4343
if (actionBlocksLoader || actionGenerateDag) {

ethereumj-core/src/main/java/org/ethereum/cli/CLIInterface.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ private static void printHelp() {
171171
System.out.println("-listen <port> -- port to listen on for incoming connections ");
172172
System.out.println("-connect <enode://pubKey@host:port> -- address actively connect to ");
173173
System.out.println("-connectOnly <enode://pubKey@host:port> -- like 'connect', but will not attempt to connect to other peers ");
174-
System.out.println("");
174+
System.out.println();
175175
System.out.println("e.g: cli -reset no -db db-1 -listen 20202 -connect enode://[email protected]:30300 ");
176-
System.out.println("");
176+
System.out.println();
177177

178178
}
179179

ethereumj-core/src/main/java/org/ethereum/config/CommonConfig.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,14 @@ public AbstractCachedSource<byte[], byte[]> blockchainDbCache() {
154154
return ret;
155155
}
156156

157+
public DbSource<byte[]> keyValueDataSource(String name) {
158+
return keyValueDataSource(name, DbSettings.DEFAULT);
159+
}
160+
157161
@Bean
158162
@Scope("prototype")
159163
@Primary
160-
public DbSource<byte[]> keyValueDataSource(String name) {
164+
public DbSource<byte[]> keyValueDataSource(String name, DbSettings settings) {
161165
String dataSource = systemProperties().getKeyValueDataSource();
162166
try {
163167
DbSource<byte[]> dbSource;
@@ -170,7 +174,7 @@ public DbSource<byte[]> keyValueDataSource(String name) {
170174
dbSource = rocksDbDataSource();
171175
}
172176
dbSource.setName(name);
173-
dbSource.init();
177+
dbSource.init(settings);
174178
dbSources.add(dbSource);
175179
return dbSource;
176180
} finally {
@@ -193,7 +197,7 @@ protected RocksDbDataSource rocksDbDataSource() {
193197
public void fastSyncCleanUp() {
194198
byte[] fastsyncStageBytes = blockchainDB().get(FastSyncManager.FASTSYNC_DB_KEY_SYNC_STAGE);
195199
if (fastsyncStageBytes == null) return; // no uncompleted fast sync
196-
if (!systemProperties().blocksLoader().equals("")) return; // blocks loader enabled
200+
if (!systemProperties().blocksLoader().isEmpty()) return; // blocks loader enabled
197201

198202
EthereumListener.SyncState syncStage = EthereumListener.SyncState.values()[fastsyncStageBytes[0]];
199203

@@ -219,15 +223,26 @@ private void resetDataSource(Source source) {
219223

220224
@Bean
221225
@Lazy
222-
public DataSourceArray<BlockHeader> headerSource() {
223-
DbSource<byte[]> dataSource = keyValueDataSource("headers");
224-
BatchSourceWriter<byte[], byte[]> batchSourceWriter = new BatchSourceWriter<>(dataSource);
225-
WriteCache.BytesKey<byte[]> writeCache = new WriteCache.BytesKey<>(batchSourceWriter, WriteCache.CacheType.SIMPLE);
226-
writeCache.withSizeEstimators(MemSizeEstimator.ByteArrayEstimator, MemSizeEstimator.ByteArrayEstimator);
227-
writeCache.setFlushSource(true);
228-
ObjectDataSource<BlockHeader> objectDataSource = new ObjectDataSource<>(dataSource, Serializers.BlockHeaderSerializer, 0);
229-
DataSourceArray<BlockHeader> dataSourceArray = new DataSourceArray<>(objectDataSource);
230-
return dataSourceArray;
226+
public DbSource<byte[]> headerSource() {
227+
return keyValueDataSource("headers");
228+
}
229+
230+
@Bean
231+
@Lazy
232+
public HeaderStore headerStore() {
233+
DbSource<byte[]> dataSource = headerSource();
234+
235+
WriteCache.BytesKey<byte[]> cache = new WriteCache.BytesKey<>(
236+
new BatchSourceWriter<>(dataSource), WriteCache.CacheType.SIMPLE);
237+
cache.setFlushSource(true);
238+
dbFlushManager().addCache(cache);
239+
240+
HeaderStore headerStore = new HeaderStore();
241+
Source<byte[], byte[]> headers = new XorDataSource<>(cache, HashUtil.sha3("header".getBytes()));
242+
Source<byte[], byte[]> index = new XorDataSource<>(cache, HashUtil.sha3("index".getBytes()));
243+
headerStore.init(index, headers);
244+
245+
return headerStore;
231246
}
232247

233248
@Bean
@@ -256,7 +271,11 @@ public ProgramPrecompile deserialize(byte[] stream) {
256271

257272
@Bean
258273
public DbSource<byte[]> blockchainDB() {
259-
return keyValueDataSource("blockchain");
274+
DbSettings settings = DbSettings.newInstance()
275+
.withMaxOpenFiles(systemProperties().getConfig().getInt("database.maxOpenFiles"))
276+
.withMaxThreads(Math.max(1, Runtime.getRuntime().availableProcessors() / 2));
277+
278+
return keyValueDataSource("blockchain", settings);
260279
}
261280

262281
@Bean

ethereumj-core/src/main/java/org/ethereum/config/NodeFilter.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,19 @@ public Entry(byte[] nodeId, String hostIpPattern) {
6565
}
6666

6767
public boolean accept(InetAddress nodeAddr) {
68+
if (hostIpPattern == null) return true;
6869
String ip = nodeAddr.getHostAddress();
6970
return hostIpPattern != null && ip.startsWith(hostIpPattern);
7071
}
7172

7273
public boolean accept(Node node) {
7374
try {
74-
return (nodeId == null || Arrays.equals(node.getId(), nodeId))
75-
&& (hostIpPattern == null || accept(InetAddress.getByName(node.getHost())));
75+
boolean shouldAcceptNodeId = nodeId == null || Arrays.equals(node.getId(), nodeId);
76+
if (!shouldAcceptNodeId) {
77+
return false;
78+
}
79+
InetAddress nodeAddress = InetAddress.getByName(node.getHost());
80+
return (hostIpPattern == null || accept(nodeAddress));
7681
} catch (UnknownHostException e) {
7782
return false;
7883
}

ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.ethereum.net.rlpx.Node;
3535
import org.ethereum.util.BuildInfo;
3636
import org.ethereum.util.ByteUtil;
37+
import org.ethereum.util.Utils;
3738
import org.ethereum.validator.BlockCustomHashRule;
3839
import org.ethereum.validator.BlockHeaderValidator;
3940
import org.slf4j.Logger;
@@ -53,6 +54,7 @@
5354
import java.util.*;
5455

5556
import static org.ethereum.crypto.HashUtil.sha3;
57+
import static org.ethereum.util.ByteUtil.toHexString;
5658

5759
/**
5860
* Utility class to retrieve property values from the ethereumj.conf files
@@ -664,7 +666,7 @@ public String customSolcPath() {
664666
public String privateKey() {
665667
if (config.hasPath("peer.privateKey")) {
666668
String key = config.getString("peer.privateKey");
667-
if (key.length() != 64) {
669+
if (key.length() != 64 || !Utils.isHexEncoded(key)) {
668670
throw new RuntimeException("The peer.privateKey needs to be Hex encoded and 32 byte length");
669671
}
670672
return key;
@@ -810,7 +812,7 @@ public boolean isFastSyncEnabled() {
810812
public byte[] getFastSyncPivotBlockHash() {
811813
if (!config.hasPath("sync.fast.pivotBlockHash")) return null;
812814
byte[] ret = Hex.decode(config.getString("sync.fast.pivotBlockHash"));
813-
if (ret.length != 32) throw new RuntimeException("Invalid block hash length: " + Hex.toHexString(ret));
815+
if (ret.length != 32) throw new RuntimeException("Invalid block hash length: " + toHexString(ret));
814816
return ret;
815817
}
816818

@@ -824,6 +826,12 @@ public boolean fastSyncSkipHistory() {
824826
return config.getBoolean("sync.fast.skipHistory");
825827
}
826828

829+
@ValidateMe
830+
public int makeDoneByTimeout() {
831+
return config.getInt("sync.makeDoneByTimeout");
832+
}
833+
834+
827835
@ValidateMe
828836
public boolean isPublicHomeNode() { return config.getBoolean("peer.discovery.public.home.node");}
829837

ethereumj-core/src/main/java/org/ethereum/config/blockchain/ByzantiumConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.ethereum.core.Block;
2424
import org.ethereum.core.BlockHeader;
2525
import org.ethereum.core.Repository;
26-
import org.spongycastle.util.encoders.Hex;
2726

2827
import java.math.BigInteger;
2928

ethereumj-core/src/main/java/org/ethereum/core/AccountState.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525
import org.ethereum.util.RLP;
2626
import org.ethereum.util.RLPList;
2727

28-
import org.spongycastle.util.encoders.Hex;
29-
3028
import java.math.BigInteger;
3129

3230
import static org.ethereum.crypto.HashUtil.*;
3331
import static org.ethereum.util.FastByteComparisons.equal;
32+
import static org.ethereum.util.ByteUtil.toHexString;
3433

3534
public class AccountState {
3635

@@ -151,8 +150,8 @@ public boolean isEmpty() {
151150
public String toString() {
152151
String ret = " Nonce: " + this.getNonce().toString() + "\n" +
153152
" Balance: " + getBalance() + "\n" +
154-
" State Root: " + Hex.toHexString(this.getStateRoot()) + "\n" +
155-
" Code Hash: " + Hex.toHexString(this.getCodeHash());
153+
" State Root: " + toHexString(this.getStateRoot()) + "\n" +
154+
" Code Hash: " + toHexString(this.getCodeHash());
156155
return ret;
157156
}
158157
}

ethereumj-core/src/main/java/org/ethereum/core/Block.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import static org.ethereum.crypto.HashUtil.sha3;
3636
import static org.ethereum.datasource.MemSizeEstimator.ByteArrayEstimator;
37+
import static org.ethereum.util.ByteUtil.toHexString;
3738

3839
/**
3940
* The block in Ethereum is the collection of relevant pieces of information
@@ -69,7 +70,7 @@ private Block() {
6970
}
7071

7172
public Block(byte[] rawData) {
72-
logger.debug("new from [" + Hex.toHexString(rawData) + "]");
73+
logger.debug("new from [" + toHexString(rawData) + "]");
7374
this.rlpEncoded = rawData;
7475
}
7576

@@ -304,7 +305,7 @@ public String toString() {
304305
parseRLP();
305306

306307
toStringBuff.setLength(0);
307-
toStringBuff.append(Hex.toHexString(this.getEncoded())).append("\n");
308+
toStringBuff.append(toHexString(this.getEncoded())).append("\n");
308309
toStringBuff.append("BlockData [ ");
309310
toStringBuff.append(header.toString());
310311

0 commit comments

Comments
 (0)