From 3e71d0d122f82b969a753c25160de69508e5d2d4 Mon Sep 17 00:00:00 2001 From: nicksavers Date: Mon, 4 Aug 2014 22:00:48 +0200 Subject: [PATCH] Use long instead of hex for timestamp and difficulty --- .../java/org/ethereum/core/Blockchain.java | 3 +++ .../org/ethereum/db/ByteArrayWrapper.java | 2 +- .../java/org/ethereum/db/TrackDatabase.java | 19 +++++++++++---- .../ethereum/net/message/StaticMessages.java | 2 +- .../java/org/ethereum/trie/TrackTrie.java | 7 ++++++ .../java/org/ethereum/trie/TrieFacade.java | 2 ++ .../org/ethereum/vm/ProgramInvokeFactory.java | 23 +++++++++---------- .../main/resources/log4j-detailed.properties | 2 +- .../src/main/resources/system.properties | 2 +- 9 files changed, 41 insertions(+), 21 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Blockchain.java b/ethereumj-core/src/main/java/org/ethereum/core/Blockchain.java index 34a532e0..86dd579c 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Blockchain.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Blockchain.java @@ -188,6 +188,9 @@ public class Blockchain { public void applyBlock(Block block) { + if(block.getNumber() == 1157) + logger.debug("block 1157"); + int i = 0; for (Transaction tx : block.getTransactionsList()) { stateLogger.debug("apply block: [ {} ] tx: [ {} ] ", block.getNumber(), i); diff --git a/ethereumj-core/src/main/java/org/ethereum/db/ByteArrayWrapper.java b/ethereumj-core/src/main/java/org/ethereum/db/ByteArrayWrapper.java index cda96800..d58b32c7 100644 --- a/ethereumj-core/src/main/java/org/ethereum/db/ByteArrayWrapper.java +++ b/ethereumj-core/src/main/java/org/ethereum/db/ByteArrayWrapper.java @@ -16,7 +16,7 @@ public class ByteArrayWrapper implements Comparable { public ByteArrayWrapper(byte[] data) { if (data == null) { - throw new NullPointerException(); + throw new NullPointerException("Can't create a wrapper around null"); } this.data = data; } diff --git a/ethereumj-core/src/main/java/org/ethereum/db/TrackDatabase.java b/ethereumj-core/src/main/java/org/ethereum/db/TrackDatabase.java index 9b1b8d2a..a6370c82 100644 --- a/ethereumj-core/src/main/java/org/ethereum/db/TrackDatabase.java +++ b/ethereumj-core/src/main/java/org/ethereum/db/TrackDatabase.java @@ -3,6 +3,8 @@ package org.ethereum.db; import java.util.HashMap; import java.util.Map; +import org.ethereum.util.LRUMap; + /** * www.ethereumJ.com * @@ -11,6 +13,9 @@ import java.util.Map; */ public class TrackDatabase implements Database { +// private static final int MAX_ENTRIES = 1000; // Should contain most commonly hashed values +// private static LRUMap valueCache = new LRUMap<>(0, MAX_ENTRIES); + private Database db; private boolean trackingChanges; @@ -43,21 +48,25 @@ public class TrackDatabase implements Database { } public void put(byte[] key, byte[] value) { +// valueCache.put(wKey, value); if (trackingChanges) { - changes.put(new ByteArrayWrapper(key), value); + ByteArrayWrapper wKey = new ByteArrayWrapper(key); + changes.put(wKey, value); } else { db.put(key, value); } } public byte[] get(byte[] key) { - if(trackingChanges) { - ByteArrayWrapper wKey = new ByteArrayWrapper(key); + if(trackingChanges) { + ByteArrayWrapper wKey = new ByteArrayWrapper(key); if (deletes.get(wKey) != null) return null; if (changes.get(wKey) != null) return changes.get(wKey); - return db.get(key); } - return db.get(key); +// byte[] result = valueCache.get(wKey); +// if(result != null) +// return result; + return db.get(key); } /** Delete object (key) from db **/ diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/StaticMessages.java b/ethereumj-core/src/main/java/org/ethereum/net/message/StaticMessages.java index 24a0aa63..7eb10e56 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/message/StaticMessages.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/StaticMessages.java @@ -34,7 +34,7 @@ public class StaticMessages { byte[] peerIdBytes = HashUtil.randomPeerId(); return new HelloMessage((byte) 0x17, (byte) 0x00, - "EthereumJ [v0.5.1] by RomanJ", Byte.parseByte("00000111", 2), + "EthereumJ/v0.5.1/Nick", Byte.parseByte("00000111", 2), (short) 30303, peerIdBytes); } } diff --git a/ethereumj-core/src/main/java/org/ethereum/trie/TrackTrie.java b/ethereumj-core/src/main/java/org/ethereum/trie/TrackTrie.java index 098dd5a6..765bb74a 100644 --- a/ethereumj-core/src/main/java/org/ethereum/trie/TrackTrie.java +++ b/ethereumj-core/src/main/java/org/ethereum/trie/TrackTrie.java @@ -33,6 +33,7 @@ public class TrackTrie implements TrieFacade { for (ByteArrayWrapper key : changes.keySet()) { trie.update(key.getData(), changes.get(key)); } +// trie.sync(); changes = null; trackingChanges = false; } @@ -75,4 +76,10 @@ public class TrackTrie implements TrieFacade { trie.delete(key); } } + + @Override + public void sync() { + // TODO Auto-generated method stub + + } } diff --git a/ethereumj-core/src/main/java/org/ethereum/trie/TrieFacade.java b/ethereumj-core/src/main/java/org/ethereum/trie/TrieFacade.java index ef6b51eb..4f4cc6dd 100644 --- a/ethereumj-core/src/main/java/org/ethereum/trie/TrieFacade.java +++ b/ethereumj-core/src/main/java/org/ethereum/trie/TrieFacade.java @@ -11,4 +11,6 @@ public interface TrieFacade { public void update(byte[] key, byte[] value); public byte[] get(byte[] key); public void delete(byte[] key); + + public void sync(); } 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 8a1f1ce3..37772475 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/ProgramInvokeFactory.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/ProgramInvokeFactory.java @@ -89,8 +89,7 @@ public class ProgramInvokeFactory { "timestamp={}\n" + "blockNumber={}\n" + "difficulty={}\n" + - "gaslimit={}\n" - , + "gaslimit={}\n", Hex.toHexString(address), Hex.toHexString(origin), @@ -145,7 +144,7 @@ public class ProgramInvokeFactory { if (logger.isInfoEnabled()) { - logger.info("Program invocation: \n" + + logger.info("Internal call: \n" + "address={}\n" + "origin={}\n" + "caller={}\n" + @@ -163,17 +162,17 @@ public class ProgramInvokeFactory { Hex.toHexString(address.getLast20Bytes()), Hex.toHexString(origin.getLast20Bytes()), Hex.toHexString(caller.getLast20Bytes()), - new BigInteger(balance.getData()).longValue(), - new BigInteger(gasPrice.getData()).longValue(), - new BigInteger(gas.getData()).longValue(), - Hex.toHexString(callValue.getData()), + balance.longValue(), + gasPrice.longValue(), + gas.longValue(), + callValue.longValue(), data == null ? "null": Hex.toHexString(data), Hex.toHexString(lastHash.getData()), - Hex.toHexString(coinbase.getData()), - Hex.toHexString(timestamp.getData()), - new BigInteger(number.getData()).longValue(), - Hex.toHexString(difficulty.getData()), - new BigInteger(gasLimit.getData()).longValue()); + Hex.toHexString(coinbase.getLast20Bytes()), + timestamp.longValue(), + number.longValue(), + difficulty.longValue(), + gasLimit.longValue()); } return new ProgramInvokeImpl(address, origin, caller, balance, gasPrice, gas, callValue, diff --git a/ethereumj-core/src/main/resources/log4j-detailed.properties b/ethereumj-core/src/main/resources/log4j-detailed.properties index 15d8b9b4..46818872 100644 --- a/ethereumj-core/src/main/resources/log4j-detailed.properties +++ b/ethereumj-core/src/main/resources/log4j-detailed.properties @@ -24,7 +24,7 @@ log4j.logger.wire = ERROR log4j.logger.VM = DEBUG log4j.logger.main = INFO log4j.logger.state = DEBUG -log4j.logger.repository = DEBUG +log4j.logger.repository = INFO log4j.logger.blockchain = INFO log4j.logger.ui = ERROR log4j.logger.gas = ERROR diff --git a/ethereumj-core/src/main/resources/system.properties b/ethereumj-core/src/main/resources/system.properties index 89a74fcd..7e944dc6 100644 --- a/ethereumj-core/src/main/resources/system.properties +++ b/ethereumj-core/src/main/resources/system.properties @@ -84,7 +84,7 @@ samples.dir = samples # the existing database will be # destroyed and all the data will be # downloaded from peers again -database.reset = true +database.reset = false # place to save physical storage files database.dir = database