Genesis only created/applied when DB is empty + logging instead of printStackTrace()

This commit is contained in:
nicksavers 2014-07-05 21:41:00 +02:00
parent a660a1c294
commit 3953dc97c1
17 changed files with 79 additions and 66 deletions

View File

@ -2,7 +2,6 @@ package org.ethereum.core;
import org.ethereum.db.DatabaseImpl; import org.ethereum.db.DatabaseImpl;
import org.ethereum.manager.WorldManager; import org.ethereum.manager.WorldManager;
import org.ethereum.net.message.StaticMessages;
import org.ethereum.net.submit.WalletTransaction; import org.ethereum.net.submit.WalletTransaction;
import org.ethereum.util.ByteUtil; import org.ethereum.util.ByteUtil;
import org.iq80.leveldb.DBIterator; import org.iq80.leveldb.DBIterator;
@ -99,7 +98,7 @@ public class Blockchain {
// if it is the first block to add // if it is the first block to add
// check that the parent is the genesis // check that the parent is the genesis
if (index.isEmpty() if (index.isEmpty()
&& !Arrays.equals(StaticMessages.GENESIS_HASH, && !Arrays.equals(Genesis.getInstance().getHash(),
firstBlockToAdd.getParentHash())) { firstBlockToAdd.getParentHash())) {
return; return;
} }
@ -184,7 +183,7 @@ public class Blockchain {
public byte[] getLatestBlockHash() { public byte[] getLatestBlockHash() {
if (index.isEmpty()) if (index.isEmpty())
return StaticMessages.GENESIS_HASH; return Genesis.getInstance().getHash();
else else
return getLastBlock().getHash(); return getLastBlock().getHash();
} }

View File

@ -308,7 +308,7 @@ public class Repository {
} }
bw.close(); bw.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
} }

View File

@ -4,6 +4,8 @@ package org.ethereum.gui;
import javax.swing.text.Segment; import javax.swing.text.Segment;
import org.fife.ui.rsyntaxtextarea.*; import org.fife.ui.rsyntaxtextarea.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
@ -12,6 +14,8 @@ import org.fife.ui.rsyntaxtextarea.*;
* Created on: 24/04/14 11:52 * Created on: 24/04/14 11:52
*/ */
public class ConsoleTokenMaker extends AbstractTokenMaker { public class ConsoleTokenMaker extends AbstractTokenMaker {
private Logger logger = LoggerFactory.getLogger("gui");
protected final String operators = "+-*/%!=<>^&|?:"; protected final String operators = "+-*/%!=<>^&|?:";
@ -75,8 +79,7 @@ public class ConsoleTokenMaker extends AbstractTokenMaker {
break; break;
default: default:
new Exception("Unknown tokenType: '" + tokenType + "'"). logger.error("Unknown tokenType: '" + tokenType + "'");
printStackTrace();
tokenType = Token.IDENTIFIER; tokenType = Token.IDENTIFIER;
break; break;

View File

@ -3,6 +3,8 @@ package org.ethereum.gui;
import org.ethereum.serpent.SerpentCompiler; import org.ethereum.serpent.SerpentCompiler;
import org.fife.ui.rsyntaxtextarea.*; import org.fife.ui.rsyntaxtextarea.*;
import org.fife.ui.rtextarea.RTextScrollPane; import org.fife.ui.rtextarea.RTextScrollPane;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.swing.*; import javax.swing.*;
@ -23,6 +25,8 @@ import static org.ethereum.config.SystemProperties.CONFIG;
*/ */
public class SerpentEditor extends JFrame { public class SerpentEditor extends JFrame {
private Logger logger = LoggerFactory.getLogger("gui");
private String codeSample = "\n\n\n" + private String codeSample = "\n\n\n" +
"" + "" +
"if !contract.storage[msg.data[0]]:\n" + "if !contract.storage[msg.data[0]]:\n" +
@ -181,7 +185,7 @@ public class SerpentEditor extends JFrame {
asmResult = SerpentCompiler.compile(codeArea.getText()); asmResult = SerpentCompiler.compile(codeArea.getText());
} }
} catch (Throwable th) { } catch (Throwable th) {
th.printStackTrace(); logger.error(th.getMessage(), th);
splitPanel.setDividerLocation(0.8); splitPanel.setDividerLocation(0.8);
result.setVisible(true); result.setVisible(true);
@ -218,7 +222,7 @@ public class SerpentEditor extends JFrame {
machineCode = SerpentCompiler.encodeMachineCodeForVMRun(machineCode, null); machineCode = SerpentCompiler.encodeMachineCodeForVMRun(machineCode, null);
} }
} catch (Throwable th) { } catch (Throwable th) {
th.printStackTrace(); logger.error(th.getMessage(), th);
splitPanel.setDividerLocation(0.7); splitPanel.setDividerLocation(0.7);
result.setVisible(true); result.setVisible(true);
result.setText(th.getMessage()); result.setText(th.getMessage());
@ -266,7 +270,7 @@ public class SerpentEditor extends JFrame {
String content = new Scanner(file).useDelimiter("\\Z").next(); String content = new Scanner(file).useDelimiter("\\Z").next();
codeArea.setText(content); codeArea.setText(content);
} catch (FileNotFoundException e1) { } catch (FileNotFoundException e1) {
e1.printStackTrace(); logger.error(e1.getMessage(), e1);
} catch (java.util.NoSuchElementException e2) { } catch (java.util.NoSuchElementException e2) {
// don't worry it's just the file is empty // don't worry it's just the file is empty
codeArea.setText(""); codeArea.setText("");
@ -334,7 +338,7 @@ public class SerpentEditor extends JFrame {
out.write(codeArea.getText()); out.write(codeArea.getText());
out.close(); out.close();
} catch (IOException e1) { } catch (IOException e1) {
e1.printStackTrace(); logger.error(e1.getMessage(), e1);
} }
} }
}); });

View File

@ -226,9 +226,7 @@ public class ToolBar extends JFrame {
cp.add(chainToggle); cp.add(chainToggle);
cp.add(walletToggle); cp.add(walletToggle);
WorldManager.getInstance().getWallet();
WorldManager.getInstance().loadBlockChain(); WorldManager.getInstance().loadBlockChain();
MainData.instance.toString(); MainData.instance.toString();
} }

View File

@ -205,7 +205,7 @@ public class WorldManager {
.createProgramInvoke(tx, lastBlock, trackRepository); .createProgramInvoke(tx, lastBlock, trackRepository);
if (logger.isInfoEnabled()) if (logger.isInfoEnabled())
logger.info("running the init for contract: addres={}", logger.info("running the init for contract: address={}",
Hex.toHexString(tx.getContractAddress())); Hex.toHexString(tx.getContractAddress()));
VM vm = new VM(); VM vm = new VM();
@ -224,7 +224,7 @@ public class WorldManager {
Block lastBlock = blockchain.getLastBlock(); Block lastBlock = blockchain.getLastBlock();
if (logger.isInfoEnabled()) if (logger.isInfoEnabled())
logger.info("calling for existing contract: addres={}", logger.info("calling for existing contract: address={}",
Hex.toHexString(tx.getReceiveAddress())); Hex.toHexString(tx.getReceiveAddress()));
ProgramInvoke programInvoke = ProgramInvokeFactory ProgramInvoke programInvoke = ProgramInvokeFactory

View File

@ -314,7 +314,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
this.tearDown = true; this.tearDown = true;
logger.info("Lost connection to the server"); logger.info("Lost connection to the server");
cause.printStackTrace(); logger.error(cause.getMessage(), cause);
ctx.close().sync(); ctx.close().sync();
timer.cancel(); timer.cancel();
} }
@ -359,7 +359,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
private void sendGetChain(ChannelHandlerContext ctx) { private void sendGetChain(ChannelHandlerContext ctx) {
byte[] hash = WorldManager.getInstance().getBlockChain().getLatestBlockHash(); byte[] hash = WorldManager.getInstance().getBlockChain().getLastBlock().getHash();
GetChainMessage chainMessage = new GetChainMessage((byte)100, hash); GetChainMessage chainMessage = new GetChainMessage((byte)100, hash);
chainMessage.toString(); chainMessage.toString();

View File

@ -1,6 +1,5 @@
package org.ethereum.net.message; package org.ethereum.net.message;
import org.ethereum.core.Genesis;
import org.ethereum.crypto.HashUtil; import org.ethereum.crypto.HashUtil;
import org.spongycastle.util.encoders.Hex; import org.spongycastle.util.encoders.Hex;
@ -17,7 +16,6 @@ public class StaticMessages {
public static final byte[] GET_TRANSACTIONS = Hex.decode("2240089100000002C116"); public static final byte[] GET_TRANSACTIONS = Hex.decode("2240089100000002C116");
public static final byte[] DISCONNECT_08 = Hex.decode("2240089100000003C20108"); public static final byte[] DISCONNECT_08 = Hex.decode("2240089100000003C20108");
public static final byte[] GENESIS_HASH = Genesis.getInstance().getHash();
public static final byte[] MAGIC_PACKET = Hex.decode("22400891"); public static final byte[] MAGIC_PACKET = Hex.decode("22400891");

View File

@ -7,6 +7,8 @@ import org.ethereum.net.Command;
import org.ethereum.util.RLP; import org.ethereum.util.RLP;
import org.ethereum.util.RLPItem; import org.ethereum.util.RLPItem;
import org.ethereum.util.RLPList; import org.ethereum.util.RLPList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -19,6 +21,8 @@ import java.util.List;
* Created on: 06/04/14 14:56 * Created on: 06/04/14 14:56
*/ */
public class TransactionsMessage extends Message { public class TransactionsMessage extends Message {
private Logger logger = LoggerFactory.getLogger("wire");
private List<Transaction> transactions = new ArrayList<Transaction>(); private List<Transaction> transactions = new ArrayList<Transaction>();
@ -36,7 +40,7 @@ public class TransactionsMessage extends Message {
try { try {
baos.write(txPayload); baos.write(txPayload);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }

View File

@ -161,7 +161,7 @@ public class EthereumPeerTasterHandler extends ChannelInboundHandlerAdapter {
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
this.tearDown = true; this.tearDown = true;
logger.info("Lost connection to the server"); logger.info("Lost connection to the server");
cause.printStackTrace(); logger.error(cause.getMessage(), cause);
timer.cancel(); timer.cancel();
timer.purge(); timer.purge();
timer = null; timer = null;

View File

@ -56,7 +56,7 @@ public class PeerTaster {
try { try {
workerGroup.shutdownGracefully().sync(); workerGroup.shutdownGracefully().sync();
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
} }

View File

@ -21,7 +21,8 @@ import java.util.Stack;
public class Program { public class Program {
private Logger logger = LoggerFactory.getLogger("VM"); private Logger logger = LoggerFactory.getLogger("VM");
private Logger gasLogger = null; private Logger gasLogger = LoggerFactory.getLogger("gas");
private int invokeHash;
private ProgramListener listener; private ProgramListener listener;
Stack<DataWord> stack = new Stack<DataWord>(); Stack<DataWord> stack = new Stack<DataWord>();
@ -39,8 +40,7 @@ public class Program {
public Program(byte[] ops, ProgramInvoke invokeData) { public Program(byte[] ops, ProgramInvoke invokeData) {
gasLogger = LoggerFactory.getLogger("gas - " + invokeData.hashCode()); this.invokeHash = invokeData.hashCode();
result.setRepository(invokeData.getRepository()); result.setRepository(invokeData.getRepository());
if (ops == null) throw new RuntimeException("program can not run with ops: null"); if (ops == null) throw new RuntimeException("program can not run with ops: null");
@ -408,7 +408,7 @@ public class Program {
} }
public void spendGas(int gasValue, String cause) { public void spendGas(int gasValue, String cause) {
gasLogger.info("Spent for cause: [ {} ], gas: [ {} ]", cause, gasValue); gasLogger.info("[{}] Spent for cause: [ {} ], gas: [ {} ]", invokeHash, cause, gasValue);
long afterSpend = invokeData.getGas().longValue() - gasValue - result.getGasUsed(); long afterSpend = invokeData.getGas().longValue() - gasValue - result.getGasUsed();
if (afterSpend < 0) if (afterSpend < 0)
@ -417,7 +417,7 @@ public class Program {
} }
public void refundGas(int gasValue, String cause) { public void refundGas(int gasValue, String cause) {
gasLogger.info("Refund for cause: [ {} ], gas: [ {} ]", cause, gasValue); gasLogger.info("[{}] Refund for cause: [ {} ], gas: [ {} ]", invokeHash, cause, gasValue);
result.refundGas(gasValue); result.refundGas(gasValue);
} }

View File

@ -1,6 +1,7 @@
package org.ethereum.vm; package org.ethereum.vm;
import org.ethereum.crypto.HashUtil; import org.ethereum.crypto.HashUtil;
import org.ethereum.vm.Program.OutOfGasException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -556,8 +557,10 @@ public class VM {
program.fullTrace(); program.fullTrace();
} catch (RuntimeException e) { } catch (RuntimeException e) {
program.stop(); program.stop();
logger.info("VM halted: ", e); if(e instanceof OutOfGasException)
logger.warn("OutOfGasException occurred", e);
else
logger.error("VM halted", e);
throw e; throw e;
} }
} }

View File

@ -14,16 +14,18 @@ log4j.appender.file.RollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolic
log4j.appender.file.RollingPolicy.FileNamePattern=./logs/ethereum_%d{yyyy-MM-dd}_h%d{HH}.log log4j.appender.file.RollingPolicy.FileNamePattern=./logs/ethereum_%d{yyyy-MM-dd}_h%d{HH}.log
# filter noisy classes # filter noisy classes
log4j.logger.org.ethereum.net = INFO log4j.logger.org.ethereum.core = ERROR
log4j.logger.peerdiscovery = FATAL log4j.logger.org.ethereum.net = ERROR
log4j.logger.java.nio = WARN log4j.logger.org.ethereum.db = ERROR
log4j.logger.io.netty = FATAL log4j.logger.peerdiscovery = ERROR
log4j.logger.org.ethereum.core = FATAL log4j.logger.java.nio = ERROR
log4j.logger.wire = DEBUG log4j.logger.io.netty = ERROR
log4j.logger.VM = DEBUG log4j.logger.wire = ERROR
log4j.logger.VM = ERROR
log4j.logger.main = INFO log4j.logger.main = INFO
log4j.logger.state = DEBUG log4j.logger.state = ERROR
log4j.logger.repository = ERROR
log4j.logger.blockchain = DEBUG log4j.logger.blockchain = DEBUG
log4j.logger.ui = DEBUG log4j.logger.ui = ERROR
log4j.logger.gas = DEBUG log4j.logger.gas = ERROR

View File

@ -5,19 +5,19 @@ server.acceptConnections = false
# one default access point to start # one default access point to start
# discover the network e.g. ip: [54.201.28.117] port: [30303] # discover the network e.g. ip: [54.201.28.117] port: [30303]
# Peer Server Zero: peer discovery # Peer Server Zero: peer discovery
peer.discovery.ip = 54.72.69.180 #peer.discovery.ip = 54.72.69.180
peer.discovery.port = 30303 #peer.discovery.port = 30303
# Peer Server One: peer discovery # Peer Server One: peer discovery
#peer.discovery.ip = 54.204.10.41 peer.discovery.ip = 54.204.10.41
#peer.discovery.port = 30303 peer.discovery.port = 30303
# active peer ip and port # active peer ip and port
# that is the peer through # that is the peer through
# we get the chain: [54.201.28.117] port: [30303] # we get the chain: [54.201.28.117] port: [30303]
# ZeroGox # ZeroGox
#peer.active.ip = 54.204.10.41 peer.active.ip = 54.204.10.41
#peer.active.port = 30303 peer.active.port = 30303
# Some dude in Canada # Some dude in Canada
#peer.active.ip = 131.104.247.135 #peer.active.ip = 131.104.247.135
@ -28,8 +28,8 @@ peer.discovery.port = 30303
#peer.active.port = 30303 #peer.active.port = 30303
# PoC-5 testnet # PoC-5 testnet
peer.active.ip = 54.72.69.180 #peer.active.ip = 54.72.69.180
peer.active.port = 30303 #peer.active.port = 30303
#peer.active.ip = 151.64.223.120 #peer.active.ip = 151.64.223.120
#peer.active.port = 30304 #peer.active.port = 30304

View File

@ -8,16 +8,18 @@ log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern= %d{HH:mm:ss} [%c{1}] %m%n log4j.appender.stdout.layout.ConversionPattern= %d{HH:mm:ss} [%c{1}] %m%n
# filter noisy classes # filter noisy classes
log4j.logger.org.ethereum.net = FATAL log4j.logger.org.ethereum.core = ERROR
log4j.logger.peerdiscovery = FATAL log4j.logger.org.ethereum.net = ERROR
log4j.logger.java.nio = FATAL log4j.logger.org.ethereum.db = ERROR
log4j.logger.io.netty = FATAL log4j.logger.peerdiscovery = ERROR
log4j.logger.org.ethereum.core = FATAL log4j.logger.java.nio = ERROR
log4j.logger.wire = FATAL log4j.logger.io.netty = ERROR
log4j.logger.VM = DEBUG log4j.logger.wire = ERROR
log4j.logger.main = DEBUG log4j.logger.VM = OFF
log4j.logger.state = FATAL log4j.logger.main = INFO
log4j.logger.blockchain = FATAL log4j.logger.state = ERROR
log4j.logger.ui = FATAL log4j.logger.repository = ERROR
log4j.logger.gas = DEBUG log4j.logger.blockchain = DEBUG
log4j.logger.ui = ERROR
log4j.logger.gas = ERROR

View File

@ -5,23 +5,23 @@ server.acceptConnections = false
# one default access point to start # one default access point to start
# discover the network e.g. ip: [54.201.28.117] port: [30303] # discover the network e.g. ip: [54.201.28.117] port: [30303]
# Peer Server Zero: peer discovery # Peer Server Zero: peer discovery
peer.discovery.ip = 54.201.28.117 #peer.discovery.ip = 54.201.28.117
peer.discovery.port = 30303 #peer.discovery.port = 30303
# Peer Server One: peer discovery # Peer Server One: peer discovery
#peer.discovery.ip = 54.204.10.41 peer.discovery.ip = 54.204.10.41
#peer.discovery.port = 30303 peer.discovery.port = 30303
# active peer ip and port # active peer ip and port
# that is the peer through # that is the peer through
# we get the chain: [54.201.28.117] port: [30303] # we get the chain: [54.201.28.117] port: [30303]
# ZeroGox # ZeroGox
#peer.active.ip = 54.204.10.41 peer.active.ip = 54.204.10.41
#peer.active.port = 30303 peer.active.port = 30303
# RomanJ # RomanJ
peer.active.ip = 54.211.14.10 #peer.active.ip = 54.211.14.10
peer.active.port = 50505 #peer.active.port = 50505
# PoC-5 testnet # PoC-5 testnet
#peer.active.ip = 54.72.69.180 #peer.active.ip = 54.72.69.180