Genesis only created/applied when DB is empty + logging instead of printStackTrace()
This commit is contained in:
parent
a660a1c294
commit
3953dc97c1
|
@ -2,7 +2,6 @@ package org.ethereum.core;
|
|||
|
||||
import org.ethereum.db.DatabaseImpl;
|
||||
import org.ethereum.manager.WorldManager;
|
||||
import org.ethereum.net.message.StaticMessages;
|
||||
import org.ethereum.net.submit.WalletTransaction;
|
||||
import org.ethereum.util.ByteUtil;
|
||||
import org.iq80.leveldb.DBIterator;
|
||||
|
@ -99,7 +98,7 @@ public class Blockchain {
|
|||
// if it is the first block to add
|
||||
// check that the parent is the genesis
|
||||
if (index.isEmpty()
|
||||
&& !Arrays.equals(StaticMessages.GENESIS_HASH,
|
||||
&& !Arrays.equals(Genesis.getInstance().getHash(),
|
||||
firstBlockToAdd.getParentHash())) {
|
||||
return;
|
||||
}
|
||||
|
@ -184,7 +183,7 @@ public class Blockchain {
|
|||
|
||||
public byte[] getLatestBlockHash() {
|
||||
if (index.isEmpty())
|
||||
return StaticMessages.GENESIS_HASH;
|
||||
return Genesis.getInstance().getHash();
|
||||
else
|
||||
return getLastBlock().getHash();
|
||||
}
|
||||
|
|
|
@ -308,7 +308,7 @@ public class Repository {
|
|||
}
|
||||
bw.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ package org.ethereum.gui;
|
|||
import javax.swing.text.Segment;
|
||||
|
||||
import org.fife.ui.rsyntaxtextarea.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -13,6 +15,8 @@ import org.fife.ui.rsyntaxtextarea.*;
|
|||
*/
|
||||
public class ConsoleTokenMaker extends AbstractTokenMaker {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger("gui");
|
||||
|
||||
protected final String operators = "+-*/%!=<>^&|?:";
|
||||
|
||||
protected final String separators = "()[]{}";
|
||||
|
@ -75,8 +79,7 @@ public class ConsoleTokenMaker extends AbstractTokenMaker {
|
|||
break;
|
||||
|
||||
default:
|
||||
new Exception("Unknown tokenType: '" + tokenType + "'").
|
||||
printStackTrace();
|
||||
logger.error("Unknown tokenType: '" + tokenType + "'");
|
||||
tokenType = Token.IDENTIFIER;
|
||||
break;
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ package org.ethereum.gui;
|
|||
import org.ethereum.serpent.SerpentCompiler;
|
||||
import org.fife.ui.rsyntaxtextarea.*;
|
||||
import org.fife.ui.rtextarea.RTextScrollPane;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
|
@ -23,6 +25,8 @@ import static org.ethereum.config.SystemProperties.CONFIG;
|
|||
*/
|
||||
public class SerpentEditor extends JFrame {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger("gui");
|
||||
|
||||
private String codeSample = "\n\n\n" +
|
||||
"" +
|
||||
"if !contract.storage[msg.data[0]]:\n" +
|
||||
|
@ -181,7 +185,7 @@ public class SerpentEditor extends JFrame {
|
|||
asmResult = SerpentCompiler.compile(codeArea.getText());
|
||||
}
|
||||
} catch (Throwable th) {
|
||||
th.printStackTrace();
|
||||
logger.error(th.getMessage(), th);
|
||||
|
||||
splitPanel.setDividerLocation(0.8);
|
||||
result.setVisible(true);
|
||||
|
@ -218,7 +222,7 @@ public class SerpentEditor extends JFrame {
|
|||
machineCode = SerpentCompiler.encodeMachineCodeForVMRun(machineCode, null);
|
||||
}
|
||||
} catch (Throwable th) {
|
||||
th.printStackTrace();
|
||||
logger.error(th.getMessage(), th);
|
||||
splitPanel.setDividerLocation(0.7);
|
||||
result.setVisible(true);
|
||||
result.setText(th.getMessage());
|
||||
|
@ -266,7 +270,7 @@ public class SerpentEditor extends JFrame {
|
|||
String content = new Scanner(file).useDelimiter("\\Z").next();
|
||||
codeArea.setText(content);
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
logger.error(e1.getMessage(), e1);
|
||||
} catch (java.util.NoSuchElementException e2) {
|
||||
// don't worry it's just the file is empty
|
||||
codeArea.setText("");
|
||||
|
@ -334,7 +338,7 @@ public class SerpentEditor extends JFrame {
|
|||
out.write(codeArea.getText());
|
||||
out.close();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
logger.error(e1.getMessage(), e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -226,9 +226,7 @@ public class ToolBar extends JFrame {
|
|||
cp.add(chainToggle);
|
||||
cp.add(walletToggle);
|
||||
|
||||
WorldManager.getInstance().getWallet();
|
||||
WorldManager.getInstance().loadBlockChain();
|
||||
|
||||
MainData.instance.toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -205,7 +205,7 @@ public class WorldManager {
|
|||
.createProgramInvoke(tx, lastBlock, trackRepository);
|
||||
|
||||
if (logger.isInfoEnabled())
|
||||
logger.info("running the init for contract: addres={}",
|
||||
logger.info("running the init for contract: address={}",
|
||||
Hex.toHexString(tx.getContractAddress()));
|
||||
|
||||
VM vm = new VM();
|
||||
|
@ -224,7 +224,7 @@ public class WorldManager {
|
|||
Block lastBlock = blockchain.getLastBlock();
|
||||
|
||||
if (logger.isInfoEnabled())
|
||||
logger.info("calling for existing contract: addres={}",
|
||||
logger.info("calling for existing contract: address={}",
|
||||
Hex.toHexString(tx.getReceiveAddress()));
|
||||
|
||||
ProgramInvoke programInvoke = ProgramInvokeFactory
|
||||
|
|
|
@ -314,7 +314,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
this.tearDown = true;
|
||||
logger.info("Lost connection to the server");
|
||||
cause.printStackTrace();
|
||||
logger.error(cause.getMessage(), cause);
|
||||
ctx.close().sync();
|
||||
timer.cancel();
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
|
||||
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);
|
||||
chainMessage.toString();
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.ethereum.net.message;
|
||||
|
||||
import org.ethereum.core.Genesis;
|
||||
import org.ethereum.crypto.HashUtil;
|
||||
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[] DISCONNECT_08 = Hex.decode("2240089100000003C20108");
|
||||
public static final byte[] GENESIS_HASH = Genesis.getInstance().getHash();
|
||||
|
||||
public static final byte[] MAGIC_PACKET = Hex.decode("22400891");
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ import org.ethereum.net.Command;
|
|||
import org.ethereum.util.RLP;
|
||||
import org.ethereum.util.RLPItem;
|
||||
import org.ethereum.util.RLPList;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -20,6 +22,8 @@ import java.util.List;
|
|||
*/
|
||||
public class TransactionsMessage extends Message {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger("wire");
|
||||
|
||||
private List<Transaction> transactions = new ArrayList<Transaction>();
|
||||
|
||||
public TransactionsMessage() {
|
||||
|
@ -36,7 +40,7 @@ public class TransactionsMessage extends Message {
|
|||
try {
|
||||
baos.write(txPayload);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ public class EthereumPeerTasterHandler extends ChannelInboundHandlerAdapter {
|
|||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
this.tearDown = true;
|
||||
logger.info("Lost connection to the server");
|
||||
cause.printStackTrace();
|
||||
logger.error(cause.getMessage(), cause);
|
||||
timer.cancel();
|
||||
timer.purge();
|
||||
timer = null;
|
||||
|
|
|
@ -56,7 +56,7 @@ public class PeerTaster {
|
|||
try {
|
||||
workerGroup.shutdownGracefully().sync();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,8 @@ import java.util.Stack;
|
|||
public class Program {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger("VM");
|
||||
private Logger gasLogger = null;
|
||||
private Logger gasLogger = LoggerFactory.getLogger("gas");
|
||||
private int invokeHash;
|
||||
private ProgramListener listener;
|
||||
|
||||
Stack<DataWord> stack = new Stack<DataWord>();
|
||||
|
@ -39,8 +40,7 @@ public class Program {
|
|||
|
||||
public Program(byte[] ops, ProgramInvoke invokeData) {
|
||||
|
||||
gasLogger = LoggerFactory.getLogger("gas - " + invokeData.hashCode());
|
||||
|
||||
this.invokeHash = invokeData.hashCode();
|
||||
result.setRepository(invokeData.getRepository());
|
||||
|
||||
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) {
|
||||
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();
|
||||
if (afterSpend < 0)
|
||||
|
@ -417,7 +417,7 @@ public class Program {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.ethereum.vm;
|
||||
|
||||
import org.ethereum.crypto.HashUtil;
|
||||
import org.ethereum.vm.Program.OutOfGasException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -556,8 +557,10 @@ public class VM {
|
|||
program.fullTrace();
|
||||
} catch (RuntimeException e) {
|
||||
program.stop();
|
||||
logger.info("VM halted: ", e);
|
||||
|
||||
if(e instanceof OutOfGasException)
|
||||
logger.warn("OutOfGasException occurred", e);
|
||||
else
|
||||
logger.error("VM halted", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
# filter noisy classes
|
||||
log4j.logger.org.ethereum.net = INFO
|
||||
log4j.logger.peerdiscovery = FATAL
|
||||
log4j.logger.java.nio = WARN
|
||||
log4j.logger.io.netty = FATAL
|
||||
log4j.logger.org.ethereum.core = FATAL
|
||||
log4j.logger.wire = DEBUG
|
||||
log4j.logger.VM = DEBUG
|
||||
log4j.logger.org.ethereum.core = ERROR
|
||||
log4j.logger.org.ethereum.net = ERROR
|
||||
log4j.logger.org.ethereum.db = ERROR
|
||||
log4j.logger.peerdiscovery = ERROR
|
||||
log4j.logger.java.nio = ERROR
|
||||
log4j.logger.io.netty = ERROR
|
||||
log4j.logger.wire = ERROR
|
||||
log4j.logger.VM = ERROR
|
||||
log4j.logger.main = INFO
|
||||
log4j.logger.state = DEBUG
|
||||
log4j.logger.state = ERROR
|
||||
log4j.logger.repository = ERROR
|
||||
log4j.logger.blockchain = DEBUG
|
||||
log4j.logger.ui = DEBUG
|
||||
log4j.logger.gas = DEBUG
|
||||
log4j.logger.ui = ERROR
|
||||
log4j.logger.gas = ERROR
|
||||
|
||||
|
|
|
@ -5,19 +5,19 @@ server.acceptConnections = false
|
|||
# one default access point to start
|
||||
# discover the network e.g. ip: [54.201.28.117] port: [30303]
|
||||
# Peer Server Zero: peer discovery
|
||||
peer.discovery.ip = 54.72.69.180
|
||||
peer.discovery.port = 30303
|
||||
#peer.discovery.ip = 54.72.69.180
|
||||
#peer.discovery.port = 30303
|
||||
|
||||
# Peer Server One: peer discovery
|
||||
#peer.discovery.ip = 54.204.10.41
|
||||
#peer.discovery.port = 30303
|
||||
peer.discovery.ip = 54.204.10.41
|
||||
peer.discovery.port = 30303
|
||||
|
||||
# active peer ip and port
|
||||
# that is the peer through
|
||||
# we get the chain: [54.201.28.117] port: [30303]
|
||||
# ZeroGox
|
||||
#peer.active.ip = 54.204.10.41
|
||||
#peer.active.port = 30303
|
||||
peer.active.ip = 54.204.10.41
|
||||
peer.active.port = 30303
|
||||
|
||||
# Some dude in Canada
|
||||
#peer.active.ip = 131.104.247.135
|
||||
|
@ -28,8 +28,8 @@ peer.discovery.port = 30303
|
|||
#peer.active.port = 30303
|
||||
|
||||
# PoC-5 testnet
|
||||
peer.active.ip = 54.72.69.180
|
||||
peer.active.port = 30303
|
||||
#peer.active.ip = 54.72.69.180
|
||||
#peer.active.port = 30303
|
||||
|
||||
#peer.active.ip = 151.64.223.120
|
||||
#peer.active.port = 30304
|
||||
|
|
|
@ -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
|
||||
|
||||
# filter noisy classes
|
||||
log4j.logger.org.ethereum.net = FATAL
|
||||
log4j.logger.peerdiscovery = FATAL
|
||||
log4j.logger.java.nio = FATAL
|
||||
log4j.logger.io.netty = FATAL
|
||||
log4j.logger.org.ethereum.core = FATAL
|
||||
log4j.logger.wire = FATAL
|
||||
log4j.logger.VM = DEBUG
|
||||
log4j.logger.main = DEBUG
|
||||
log4j.logger.state = FATAL
|
||||
log4j.logger.blockchain = FATAL
|
||||
log4j.logger.ui = FATAL
|
||||
log4j.logger.gas = DEBUG
|
||||
log4j.logger.org.ethereum.core = ERROR
|
||||
log4j.logger.org.ethereum.net = ERROR
|
||||
log4j.logger.org.ethereum.db = ERROR
|
||||
log4j.logger.peerdiscovery = ERROR
|
||||
log4j.logger.java.nio = ERROR
|
||||
log4j.logger.io.netty = ERROR
|
||||
log4j.logger.wire = ERROR
|
||||
log4j.logger.VM = OFF
|
||||
log4j.logger.main = INFO
|
||||
log4j.logger.state = ERROR
|
||||
log4j.logger.repository = ERROR
|
||||
log4j.logger.blockchain = DEBUG
|
||||
log4j.logger.ui = ERROR
|
||||
log4j.logger.gas = ERROR
|
||||
|
||||
|
|
|
@ -5,23 +5,23 @@ server.acceptConnections = false
|
|||
# one default access point to start
|
||||
# discover the network e.g. ip: [54.201.28.117] port: [30303]
|
||||
# Peer Server Zero: peer discovery
|
||||
peer.discovery.ip = 54.201.28.117
|
||||
peer.discovery.port = 30303
|
||||
#peer.discovery.ip = 54.201.28.117
|
||||
#peer.discovery.port = 30303
|
||||
|
||||
# Peer Server One: peer discovery
|
||||
#peer.discovery.ip = 54.204.10.41
|
||||
#peer.discovery.port = 30303
|
||||
peer.discovery.ip = 54.204.10.41
|
||||
peer.discovery.port = 30303
|
||||
|
||||
# active peer ip and port
|
||||
# that is the peer through
|
||||
# we get the chain: [54.201.28.117] port: [30303]
|
||||
# ZeroGox
|
||||
#peer.active.ip = 54.204.10.41
|
||||
#peer.active.port = 30303
|
||||
peer.active.ip = 54.204.10.41
|
||||
peer.active.port = 30303
|
||||
|
||||
# RomanJ
|
||||
peer.active.ip = 54.211.14.10
|
||||
peer.active.port = 50505
|
||||
#peer.active.ip = 54.211.14.10
|
||||
#peer.active.port = 50505
|
||||
|
||||
# PoC-5 testnet
|
||||
#peer.active.ip = 54.72.69.180
|
||||
|
|
Loading…
Reference in New Issue