diff --git a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/JSONReader.java b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/JSONReader.java index 49cb98c9..f31abdfd 100644 --- a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/JSONReader.java +++ b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/JSONReader.java @@ -1,55 +1,55 @@ -package org.ethereum.jsontestsuite; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Files; - -public class JSONReader { - - public static String loadJSON(String filename) { -// return getFromLocal(filename); - String json = getFromUrl("https://raw.githubusercontent.com/ethereum/tests/develop/" + filename); - return json == "" ? json = getFromLocal(filename) : json; - } - - public static String getFromLocal(String filename) { - System.out.println("Loading local file: " + filename); - try { - URL vmtest = ClassLoader.getSystemResource("jsontestsuite/" + filename); - File vmTestFile = new File(vmtest.toURI()); - return new String(Files.readAllBytes(vmTestFile.toPath())); - } catch (URISyntaxException | IOException e) { - e.printStackTrace(); - } - return ""; - } - - public static String getFromUrl(String urlToRead) { - URL url; - HttpURLConnection conn; - BufferedReader rd; - String line; - String result = ""; - try { - url = new URL(urlToRead); - conn = (HttpURLConnection) url.openConnection(); - conn.setRequestMethod("GET"); - conn.setConnectTimeout(3000); - rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); - while ((line = rd.readLine()) != null) { - result += line; - } - rd.close(); - } catch (IOException e) { - e.printStackTrace(); - } catch (Throwable e) { - e.printStackTrace(); - } - return result; - } -} +package org.ethereum.jsontestsuite; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Files; + +public class JSONReader { + + public static String loadJSON(String filename) { +// return getFromLocal(filename); + String json = getFromUrl("https://raw.githubusercontent.com/ethereum/tests/develop/" + filename); + return json == "" ? json = getFromLocal(filename) : json; + } + + public static String getFromLocal(String filename) { + System.out.println("Loading local file: " + filename); + try { + URL vmtest = ClassLoader.getSystemResource("jsontestsuite/" + filename); + File vmTestFile = new File(vmtest.toURI()); + return new String(Files.readAllBytes(vmTestFile.toPath())); + } catch (URISyntaxException | IOException e) { + e.printStackTrace(); + } + return ""; + } + + public static String getFromUrl(String urlToRead) { + URL url; + HttpURLConnection conn; + BufferedReader rd; + String line; + String result = ""; + try { + url = new URL(urlToRead); + conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + conn.setConnectTimeout(3000); + rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); + while ((line = rd.readLine()) != null) { + result += line; + } + rd.close(); + } catch (IOException e) { + e.printStackTrace(); + } catch (Throwable e) { + e.printStackTrace(); + } + return result; + } +} \ No newline at end of file diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/EthMessageCodes.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/EthMessageCodes.java index 6ce7a95b..534847ac 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/EthMessageCodes.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/EthMessageCodes.java @@ -8,8 +8,8 @@ import java.util.Map; *
* The codes for these commands are the first byte in every packet. * - * @see - * https://github.com/ethereum/wiki/wiki/Wire-Protocol + * @see + * https://github.com/ethereum/wiki/wiki/Ethereum-Wire-Protocol */ public enum EthMessageCodes { @@ -20,8 +20,6 @@ public enum EthMessageCodes { * send after the initial handshake and prior to any ethereum related messages. */ STATUS(0x00), - /* Ethereum */ - /** [+0x01] Request the peer to send all transactions * currently in the queue. */ GET_TRANSACTIONS(0x01), @@ -88,11 +86,7 @@ public enum EthMessageCodes { } public static boolean inRange(byte code){ - - if (code >= STATUS.asByte() && code <= PACKET_COUNT.asByte()) - return true; - else - return false; + return code >= STATUS.asByte() && code <= PACKET_COUNT.asByte(); } public static void setOffset(byte offset){ diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/MessageFactory.java b/ethereumj-core/src/main/java/org/ethereum/net/message/MessageFactory.java index 5d66b41b..63178802 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/message/MessageFactory.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/MessageFactory.java @@ -63,7 +63,7 @@ public class MessageFactory { switch (receivedCommand) { case STATUS: break; - case MESSAGE: + case MESSAGES: break; case ADD_FILTER: break; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/p2p/P2pMessageCodes.java b/ethereumj-core/src/main/java/org/ethereum/net/p2p/P2pMessageCodes.java index 11414fb7..9b4e8b2d 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/p2p/P2pMessageCodes.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/p2p/P2pMessageCodes.java @@ -7,13 +7,13 @@ import java.util.Map; * A list of commands for the Ethereum network protocol. *
* The codes for these commands are the first byte in every packet. - * - * @see - * https://github.com/ethereum/wiki/wiki/Wire-Protocol + * ÐΞV + * @see + * https://github.com/ethereum/wiki/wiki/ÐΞVp2p-Wire-Protocol */ public enum P2pMessageCodes { - /* P2P */ + /* P2P protocol */ /** [0x00, P2P_VERSION, CLIEND_ID, CAPS, LISTEN_PORT, CLIENT_ID]
* First packet sent over the connection, and sent once by both sides. diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/ProgramInvokeFactory.java b/ethereumj-core/src/main/java/org/ethereum/vm/ProgramInvokeFactory.java index 2cc552ab..38274af1 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/ProgramInvokeFactory.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/ProgramInvokeFactory.java @@ -22,12 +22,12 @@ public class ProgramInvokeFactory { private static final Logger logger = LoggerFactory.getLogger("VM"); /** - * This attribute defines the number of resursive calls allowed in the EVM + * This attribute defines the number of recursive calls allowed in the EVM * Note: For the JVM to reach this level without a StackOverflow exception, * ethereumj may need to be started with a JVM argument to increase * the stack size. For example: -Xss10m */ - private static final int MAX_CREATE_CALL_DEPTH = 1024; + private static final int MAX_DEPTH = 1024; // Invocation by the wire tx public static ProgramInvoke createProgramInvoke(Transaction tx, Block block, Repository repository) { @@ -180,12 +180,11 @@ public class ProgramInvokeFactory { gasLimit.longValue()); } - int newCallDepth = program.invokeData.getCallDeep() + 1; - if (newCallDepth > MAX_CREATE_CALL_DEPTH) + if (program.invokeData.getCallDeep() >= MAX_DEPTH) throw program.new OutOfGasException(); return new ProgramInvokeImpl(address, origin, caller, balance, gasPrice, gas, callValue, data, lastHash, coinbase, timestamp, number, difficulty, gasLimit, - repository, newCallDepth); + repository, program.invokeData.getCallDeep()+1); } } diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/VM.java b/ethereumj-core/src/main/java/org/ethereum/vm/VM.java index f58df050..d6660d9d 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/VM.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/VM.java @@ -166,9 +166,8 @@ public class VM { program.spendGas(gasCost, op.name()); // Avoid overflows - if(newMemSize.compareTo(MAX_GAS) == 1) { + if(newMemSize.compareTo(MAX_GAS) == 1) throw program.new OutOfGasException(); - } // memory gas calc long memoryUsage = (newMemSize.longValue() + 31) / 32 * 32; @@ -869,7 +868,7 @@ public class VM { program.getGas().value(), program.invokeData.getCallDeep(), hint); } - + MessageCall msg = new MessageCall( op.equals(CALL) ? MsgType.CALL : MsgType.STATELESS, gas, codeAddress, value, inDataOffs, inDataSize,