ethereumj-core cleaning (bring it closer to develop branch for merging).

This commit is contained in:
Adrian Tiberius 2015-06-03 18:24:25 +02:00
parent 99fed23489
commit c695ce4772
22 changed files with 88 additions and 434 deletions

View File

@ -44,7 +44,7 @@ dependencies {
exclude group: "org.hibernate", module: "hibernate-core"
exclude group: "org.hibernate", module: "hibernate-entitymanager"
exclude group: "redis.clients", module: "jedis"
exclude group: "org.antlr", module: "antlr4-runtime"
}
//compile "com.google.dagger:dagger:2.1-SNAPSHOT"

View File

@ -1,11 +1,10 @@
buildscript {
repositories {
jcenter()
maven {
name 'JFrog OSS snapshot repo'
url 'https://oss.jfrog.org/oss-snapshot-local/'
}
jcenter()
}
dependencies {
classpath 'me.champeau.gradle:antlr4-gradle-plugin:0.1'
@ -16,7 +15,7 @@ buildscript {
plugins {
id 'java'
// id "com.ewerk.gradle.plugins.dagger" version "1.0.0"
// id "com.ewerk.gradle.plugins.dagger" version "1.0.0"
id 'application'
id 'jacoco'
id 'com.github.johnrengelman.shadow' version '1.2.1'
@ -25,25 +24,28 @@ plugins {
id 'com.jfrog.bintray' version '1.0'
}
sourceCompatibility = 1.7
mainClassName = 'org.ethereum.Start'
configurations {
compile.extendsFrom antlr4
provided
}
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
mavenCentral()
flatDir {
dirs "libs"
}
jcenter()
}
sourceCompatibility = 1.7
mainClassName = 'org.ethereum.Start'
applicationDefaultJvmArgs = ["-server", "-Xms2g"]
ext.generatedSrcDir = file('src/gen/java')
sourceSets {
main {
java {
exclude '**/CommonConfig.java'
exclude '**/DefaultConfig.java'
exclude '**/RemoteConfig.java'
srcDirs += generatedSrcDir
}
}
}
antlr4 {
extraArgs = ['-package', 'org.ethereum.serpent']
@ -57,7 +59,6 @@ if (isJavaProject(project)) {
} else {
throw new GradleException('unknown plugin type')
}
public static boolean isJavaProject(Project project) {
project.plugins.findPlugin('java')
}
@ -65,7 +66,53 @@ public static boolean isAndroidProject(Project project) {
project.plugins.findPlugin('com.android.application') || project.plugins.findPlugin('com.android.library')
}
tasks.withType(JavaCompile){
options.warnings = false
}
/**
* This is TCK test command line option,
* to run the test:
* gradle tckRun -PfilePath=[ file path]
* e.g: gradle tckRun -PfilePath=E:\temp\test-case.json
*/
task tckRun(type:JavaExec){
if (project.hasProperty("filePath")) {
args = ["filerun", "$filePath"]
jvmArgs = ["-Xss32M"]
}
if (project.hasProperty("content")) {
args = ["content", "$content"]
jvmArgs = ["-Xss32M"]
}
main = "org.ethereum.tck.RunTck"
classpath = sourceSets.main.runtimeClasspath
}
test {
beforeTest { descriptor ->
logger.lifecycle("Running test: ${descriptor}")
}
jvmArgs '-Xss32m'
testLogging {
events "failed"
exceptionFormat "short"
}
systemProperty "file.encoding", "UTF-8"
}
configurations {
compile.extendsFrom antlr4
}
ext {
slf4jVersion = '1.7.7'
@ -76,20 +123,6 @@ ext {
junitVersion = '4.11'
}
sourceSets {
main {
java {
exclude '**/BlockStoreImpl.java'
exclude '**/CommonConfig.java'
exclude '**/DefaultConfig.java'
exclude '**/RemoteConfig.java'
exclude '**/EthereumFactory.java'
exclude '**/Start.java'
srcDirs += generatedSrcDir
}
}
}
dependencies {
compile 'com.google.dagger:dagger:2.1-SNAPSHOT'
compile 'com.google.dagger:dagger-compiler:2.0'
@ -110,7 +143,7 @@ dependencies {
exclude group: 'commons-logging', module: 'commons-logging'
} // for deep equals
//compile 'org.antlr:antlr4-runtime:4.5' // for serpent compilation
compile 'org.antlr:antlr4-runtime:4.5' // for serpent compilation
compile 'com.yuvalshavit:antlr-denter:1.1'
@ -120,6 +153,7 @@ dependencies {
compile 'com.google.code.findbugs:jsr305:3.0.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.2.0'
compile 'org.apache.commons:commons-collections4:4.0'
compile 'commons-io:commons-io:2.4'
compile "commons-codec:commons-codec:1.10"
compile 'org.hsqldb:hsqldb:1.8.0.10' // best performance - do not upgrade!
compile "org.hibernate:hibernate-core:${hibernateVersion}"

View File

@ -1,28 +0,0 @@
package org.ethereum;
import org.ethereum.config.SystemProperties;
import org.ethereum.di.components.DaggerEthereumComponent;
import org.ethereum.di.components.EthereumComponent;
import org.ethereum.di.modules.EthereumModule;
import org.ethereum.facade.Ethereum;
//import org.robospring.RoboSpring;
//import org.springframework.context.ApplicationContext;
public class EthereumFactory {
// public static ApplicationContext context = null;
public static EthereumComponent ethereumComponent = null;
public static Ethereum getEthereum(android.content.Context androidContext) {
// RoboSpring.autowire(androidContext);
// context = RoboSpring.getContext();
// Ethereum ethereum = context.getBean(org.ethereum.facade.Ethereum.class);
// ethereum.setContext(context);
ethereumComponent = DaggerEthereumComponent.builder()
.ethereumModule(new EthereumModule(androidContext))
.build();
return ethereumComponent.ethereum();
}
}

View File

@ -2,7 +2,6 @@ package org.ethereum.cli;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Component;
import java.net.URI;
@ -12,7 +11,6 @@ import static org.ethereum.config.SystemProperties.CONFIG;
* @author Roman Mandeleil
* @since 13.11.2014
*/
//@Component
public class CLIInterface {
private static final Logger logger = LoggerFactory.getLogger("cli");

View File

@ -30,7 +30,6 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

View File

@ -1,105 +0,0 @@
package org.ethereum.datasource;
import org.ethereum.config.SystemProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import static org.iq80.leveldb.impl.Iq80DBFactory.factory;
/**
* @author Roman Mandeleil
* @since 18.01.2015
*/
public class InMemoryDbDataSource implements KeyValueDataSource {
private static final Logger logger = LoggerFactory.getLogger("db");
String name;
HashMap<ByteBuffer, byte[]> db;
public InMemoryDbDataSource() {
}
public InMemoryDbDataSource(String name) {
this.name = name;
}
@Override
public void init() {
db = new HashMap<ByteBuffer, byte[]>();
}
public void destroyDB(File fileLocation) {
logger.debug("Destroying existing database");
db = new HashMap<ByteBuffer, byte[]>();
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public byte[] get(byte[] key) {
return db.get(key);
}
@Override
public byte[] put(byte[] key, byte[] value) {
ByteBuffer wrapped = ByteBuffer.wrap(key);
db.put(wrapped, value);
return value;
}
@Override
public void delete(byte[] key) {
db.remove(key);
}
@Override
public Set<byte[]> keys() {
Set<byte[]> keys = new HashSet<>();
Set bufferKeys = db.keySet();
for (Iterator i = bufferKeys.iterator(); i.hasNext();)
{
ByteBuffer key = (ByteBuffer) i.next();
keys.add(key.array());
}
return keys;
}
@Override
public void updateBatch(Map<byte[], byte[]> rows) {
for (Map.Entry<byte[], byte[]> row : rows.entrySet()) {
ByteBuffer wrapped = ByteBuffer.wrap(row.getKey());
db.put(wrapped, row.getValue());
}
}
@Override
public void close() {
try {
logger.info("Close db: {}", name);
init();
} catch (Exception e) {
logger.error("Failed to find the db file on the close: {} ", name);
}
}
}

View File

@ -55,6 +55,7 @@ public class RedisConnectionImpl implements RedisConnection {
Protocol.DEFAULT_TIMEOUT,
userInfo.split(":", 2)[1]);
}
return new JedisPool(new JedisPoolConfig(),
redisUri.getHost(),
redisUri.getPort(),

View File

@ -6,12 +6,6 @@ import org.ethereum.util.ByteUtil;
import org.hibernate.SessionFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.ApplicationContext;
//import org.springframework.stereotype.Repository;
//import org.springframework.transaction.annotation.Propagation;
//import org.springframework.transaction.annotation.Transactional;
import java.math.BigInteger;
import java.util.ArrayList;
@ -21,7 +15,6 @@ import java.util.List;
* @author Roman Mandeleil
* @since 12.11.2014
*/
public class BlockStoreImpl implements BlockStore {
private SessionFactory sessionFactory;

View File

@ -198,12 +198,10 @@ public class RepositoryImpl implements Repository {
if (block.getNumber() == 0 && txNumber == 0)
if (CONFIG.dumpCleanOnRestart()) {
try{
FileUtils.forceDelete(new File(CONFIG.dumpDir()));
FileUtils.forceDelete(new File(CONFIG.dumpDir()));
}catch(IOException e){
e.printStackTrace();
logger.error(e.getMessage(), e);
}
//FileSystemUtils.deleteRecursively(new File(CONFIG.dumpDir()));
}
String dir = CONFIG.dumpDir() + "/";

View File

@ -1,5 +1,8 @@
package org.ethereum.facade;
import org.ethereum.di.components.EthereumComponent;
import org.ethereum.di.modules.EthereumModule;
import org.ethereum.di.components.DaggerEthereumComponent;
import org.ethereum.net.eth.EthHandler;
import org.ethereum.net.shh.ShhHandler;
@ -15,16 +18,17 @@ public class EthereumFactory {
private static final Logger logger = LoggerFactory.getLogger("general");
public static Ethereum createEthereum() {
return createEthereum(DefaultConfig.class);
}
private static EthereumComponent ethereumComponent;
public static Ethereum createEthereum(Class clazz) {
public static Ethereum createEthereum() {
logger.info("capability eth version: [{}]", EthHandler.VERSION);
logger.info("capability shh version: [{}]", ShhHandler.VERSION);
return null;
ethereumComponent = DaggerEthereumComponent.builder()
.ethereumModule(new EthereumModule())
.build();
return ethereumComponent.ethereum();
}
}

View File

@ -15,7 +15,6 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
//import java.nio.file.Files;
import org.apache.commons.io.FileUtils;
import java.util.ArrayList;
import java.util.Iterator;
@ -52,7 +51,6 @@ public class JSONReader {
System.out.println(" Error: no file: " +filename);
System.exit(1);
}
//return new String(Files.readAllBytes(vmTestFile.toPath()));
return new String(FileUtils.readFileToByteArray(vmTestFile));
} catch (IOException e) {
e.printStackTrace();

View File

@ -21,12 +21,12 @@ import java.math.BigInteger;
import java.util.ArrayList;
import static org.ethereum.config.SystemProperties.CONFIG;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Singleton;
import static org.ethereum.config.SystemProperties.CONFIG;
/**
* WorldManager is a singleton containing references to different parts of the system.
*

View File

@ -45,8 +45,7 @@ public class WorkerThread implements Runnable {
try {
// TODO: check if this works
DiscoveryChannel discoveryChannel = discoveryChannelProvider.get();//ctx.getBean(DiscoveryChannel.class);
DiscoveryChannel discoveryChannel = discoveryChannelProvider.get();
discoveryChannel.connect(peerInfo.getAddress().getHostAddress(), peerInfo.getPort());
peerInfo.setOnline(true);

View File

@ -55,26 +55,6 @@ public class MessageCodec extends ByteToMessageCodec<Message> {
public void channelActive(ChannelHandlerContext ctx) throws Exception {
initiate(ctx);
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
super.channelRead(ctx, msg);
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
super.channelReadComplete(ctx);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
super.exceptionCaught(ctx, cause);
}
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
super.userEventTriggered(ctx, evt);
}
}
EthereumListener listener;
@ -112,7 +92,7 @@ public class MessageCodec extends ByteToMessageCodec<Message> {
if (loggerNet.isInfoEnabled())
loggerNet.info("From: \t{} \tRecv: \t{}", ctx.channel().remoteAddress(), msg);
//listener.onRecvMessage(msg);
listener.onRecvMessage(msg);
out.add(msg);
}
@ -121,7 +101,7 @@ public class MessageCodec extends ByteToMessageCodec<Message> {
protected void encode(ChannelHandlerContext ctx, Message msg, ByteBuf out) throws Exception {
String output = String.format("To: \t%s \tSend: \t%s", ctx.channel().remoteAddress(), msg);
//listener.trace(output);
listener.trace(output);
if (loggerNet.isInfoEnabled())
loggerNet.info("To: \t{} \tSend: \t{}", ctx.channel().remoteAddress(), msg);

View File

@ -1,6 +1,6 @@
package org.ethereum.util;
//import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.PropertyConfigurator;
import java.net.URL;
@ -16,7 +16,7 @@ public class AdvancedDeviceUtils {
// here we can turn on the detail tracing in the middle of the chain
if (blockNum >= CONFIG.traceStartBlock() && CONFIG.traceStartBlock() != -1) {
URL configFile = ClassLoader.getSystemResource("log4j-detailed.properties");
//PropertyConfigurator.configure(configFile);
PropertyConfigurator.configure(configFile);
}
}
}

View File

@ -1,209 +0,0 @@
package org.ethereum.vm;
import org.ethereum.util.ByteUtil;
import java.util.LinkedList;
import static java.lang.String.format;
public class MemoryBuffer {
int CHUNK_SIZE = 1024;
LinkedList<byte[]> chunks = new LinkedList<byte[]>();
int memorySoftSize = 0;
public MemoryBuffer() {
}
public void memorySave(int address, byte[] data) {
ensureAvailable(address, data.length);
int chunkIndex = address / CHUNK_SIZE;
int chunkOffset = address % CHUNK_SIZE;
int toCapture = data.length;
int start = 0;
while(toCapture > 0){
int captured = captureMax(chunkIndex, chunkOffset, toCapture, data, start);
// capture next chunk
++chunkIndex;
chunkOffset = 0;
// mark remind
toCapture -= captured;
start += captured;
}
memorySoftSize = Math.max(memorySoftSize, (int) Math.ceil((double) (address + data.length) / 32) * 32);
}
public void memorySave(int address, int allocSize, byte[] value){
memoryExpand(address, allocSize);
memorySave(address, value);
}
public DataWord memoryLoad(int address){
ensureAvailable(address, 32);
byte[] retData = new byte[32];
int chunkIndex = address / CHUNK_SIZE;
int chunkOffset = address % CHUNK_SIZE;
int toGrab = retData.length;
int start = 0;
while(toGrab > 0){
int copied = grabMax(chunkIndex, chunkOffset, toGrab, retData, start);
// read next chunk from the start
++chunkIndex;
chunkOffset = 0;
// mark remind
toGrab -= copied;
start += copied;
}
memorySoftSize = Math.max(memorySoftSize, (int) Math.ceil((double) (address + retData.length) / 32) * 32);
return new DataWord(retData);
}
public void memoryExpand(int offset, int size){
ensureAvailable(offset, size);
memorySoftSize = Math.max(memorySoftSize,offset + size);
}
public byte[] memoryChunk(int offset, int size) {
byte[] data = new byte[size];
ensureAvailable(offset, size);
int chunkIndex = offset / CHUNK_SIZE;
int chunkOffset = offset % CHUNK_SIZE;
int toGrab = data.length;
int start = 0;
while (toGrab > 0) {
int copied = grabMax(chunkIndex, chunkOffset, toGrab, data, start);
// read next chunk from the start
++chunkIndex;
chunkOffset = 0;
// mark remind
toGrab -= copied;
start += copied;
}
memorySoftSize = Math.max(memorySoftSize, (int) Math.ceil((double) (offset + data.length) / 32) * 32);
return data;
}
public String memoryToString() {
StringBuilder memoryData = new StringBuilder();
StringBuilder firstLine = new StringBuilder();
StringBuilder secondLine = new StringBuilder();
for (int i = 0; i < memorySoftSize; ++i){
byte value = getByte(i);
// Check if value is ASCII
String character = ((byte) 0x20 <= value && value <= (byte) 0x7e) ? new String(new byte[]{value}) : "?";
firstLine.append(character).append("");
secondLine.append(ByteUtil.oneByteToHexString(value)).append(" ");
if ((i + 1) % 8 == 0) {
String tmp = format("%4s", Integer.toString(i - 7, 16)).replace(" ", "0");
memoryData.append("").append(tmp).append(" ");
memoryData.append(firstLine).append(" ");
memoryData.append(secondLine);
if (i + 1 < memorySoftSize) memoryData.append("\n");
firstLine.setLength(0);
secondLine.setLength(0);
}
}
return memoryData.toString();
}
public int getSize(){
return memorySoftSize;
}
/*****************************/
/*****************************/
/*****************************/
// just access expecting all data valid
byte getByte(int address){
int chunkIndex = address / CHUNK_SIZE;
int chunkOffset = address % CHUNK_SIZE;
byte[] chunk = chunks.get(chunkIndex);
return chunk[chunkOffset];
}
void ensureAvailable(int address, int offset){
int memHardSize = getMemoryHardSize();
int endNewMem = Math.max(memHardSize, address + offset);
// there is enough mem allocated
if (endNewMem <= memHardSize) return;
int toAllocate = endNewMem - memHardSize ;
int chunks = (toAllocate % (CHUNK_SIZE) == 0) ?
toAllocate / (CHUNK_SIZE) :
(toAllocate / (CHUNK_SIZE)) + 1;
addChunks(chunks);
}
int getMemoryHardSize(){
return chunks.size() * CHUNK_SIZE;
}
int getMemorySoftSize() {
return memorySoftSize;
}
int captureMax(int chunkIndex, int chunkOffset, int size, byte[] src, int srcPos){
byte[] chunk = chunks.get(chunkIndex);
int toCapture = Math.min(size, chunk.length - chunkOffset);
System.arraycopy(src, srcPos, chunk, chunkOffset, toCapture);
return toCapture;
}
int grabMax(int chunkIndex, int chunkOffset, int size, byte[] dest, int destPos) {
byte[] chunk = chunks.get(chunkIndex);
int toGrab = Math.min(size, chunk.length - chunkOffset);
System.arraycopy(chunk, chunkOffset, dest, destPos, toGrab);
return toGrab;
}
void addChunks(int num){
for (int i = 0; i < num; ++i)
addChunk();
}
void addChunk(){
chunks.add(new byte[CHUNK_SIZE]);
}
}

View File

@ -14,16 +14,12 @@ import javax.inject.Inject;
import org.spongycastle.util.encoders.Hex;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
import java.math.BigInteger;
/**
* @author Roman Mandeleil
* @since 08.06.2014
*/
//@Component("ProgramInvokeFactory")
public class ProgramInvokeFactoryImpl implements ProgramInvokeFactory {
private static final Logger logger = LoggerFactory.getLogger("VM");

View File

@ -12,9 +12,6 @@ import java.util.zip.InflaterOutputStream;
import static java.lang.String.format;
import static java.lang.System.getProperty;
//import static java.util.Base64.getDecoder;
//import static java.util.Base64.getEncoder;
//import static org.springframework.util.StringUtils.isEmpty;
import static org.apache.commons.codec.binary.Base64.decodeBase64;
import static org.apache.commons.codec.binary.Base64.encodeBase64String;

View File

@ -59,8 +59,9 @@ public class ImportTest {
TestEthereumComponent component = DaggerTestEthereumComponent.builder()
.testEthereumModule(new TestEthereumModule())
.build();
//Ethereum ethereum = component.ethereum();
worldManager = component.worldManager();
// TODO: load blockchain, otherwise bestblock error occurs (why error does not occur in develop branch without this ??)
// TODO: load blockchain, otherwise bestblock error occurs ??
worldManager.loadBlockchain();
}

View File

@ -10,8 +10,6 @@ import org.spongycastle.util.encoders.Hex;
*/
public class RedisDataSourceTest extends AbstractRedisTest {
@Test
public void testSet1() {
if (!isConnected()) return;