Follow up merge

This commit is contained in:
romanman 2014-11-03 13:59:45 -05:00
parent 16a5094717
commit db1388a279
14 changed files with 59 additions and 58 deletions

View File

@ -1,9 +1,13 @@
package org.ethereum.core;
import static org.ethereum.crypto.HashUtil.EMTPY_TRIE_HASH;
import static org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY;
import static org.ethereum.crypto.HashUtil.EMPTY_DATA_HASH;
import org.ethereum.util.ByteUtil;
import org.ethereum.util.RLP;
import org.ethereum.util.RLPList;
import org.spongycastle.util.Arrays;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
@ -30,7 +34,7 @@ public class AccountState {
* I define a convenient equivalence TRIE (σ[a] s ) σ[a] s .
* It shall be understood that σ[a] s is not a physical member
* of the account and does not contribute to its later serialisation */
private byte[] stateRoot = EMPTY_DATA_HASH;
private byte[] stateRoot = EMTPY_TRIE_HASH;
/* The hash of the EVM code of this contractthis is the code
* that gets executed should this address receive a message call;
@ -53,10 +57,10 @@ public class AccountState {
this.rlpEncoded = rlpData;
RLPList items = (RLPList) RLP.decode2(rlpEncoded).get(0);
this.nonce = items.get(0).getRLPData() == null ? BigInteger.ZERO
: new BigInteger(1, items.get(0).getRLPData());
this.balance = items.get(1).getRLPData() == null ? BigInteger.ZERO
: new BigInteger(1, items.get(1).getRLPData());
this.nonce = new BigInteger(1, ((items.get(0).getRLPData()) == null ? new byte[]{0} :
items.get(0).getRLPData()));
this.balance = new BigInteger(1, ((items.get(1).getRLPData()) == null ? new byte[]{0} :
items.get(1).getRLPData()));
this.stateRoot = items.get(2).getRLPData();
this.codeHash = items.get(3).getRLPData();
}
@ -116,9 +120,13 @@ public class AccountState {
public String toString() {
String ret = "Nonce: " + this.getNonce().toString() + "\n" +
"Balance: " + Denomination.toFriendlyString(getBalance()) + "\n" +
"State Root: " + Hex.toHexString(this.getStateRoot()) + "\n" +
"Code Hash: " + Hex.toHexString(this.getCodeHash());
"Balance: " + Denomination.toFriendlyString(getBalance()) + "\n";
if(this.getStateRoot()!= null && !Arrays.areEqual(this.getStateRoot(), EMPTY_BYTE_ARRAY))
ret += "State Root: " + Hex.toHexString(this.getStateRoot()) + "\n";
if(this.getCodeHash() != null && !Arrays.areEqual(this.getCodeHash(), EMPTY_DATA_HASH))
ret += "Code Hash: " + Hex.toHexString(this.getCodeHash());
return ret;
}
}

View File

@ -2,14 +2,17 @@ package org.ethereum.core;
import java.math.BigInteger;
import static org.ethereum.crypto.HashUtil.EMPTY_DATA_HASH;
import static org.ethereum.crypto.HashUtil.EMTPY_TRIE_HASH;
import static org.ethereum.util.ByteUtil.*;
import static org.ethereum.crypto.HashUtil.*;
import org.ethereum.crypto.HashUtil;
import org.ethereum.crypto.SHA3Helper;
import org.ethereum.manager.WorldManager;
import org.ethereum.util.*;
import org.spongycastle.util.Arrays;
import org.spongycastle.util.BigIntegers;
import org.spongycastle.util.encoders.Hex;
/**
* Block header is a value object containing
@ -77,7 +80,7 @@ public class BlockHeader {
this.txTrieRoot = ((RLPItem) rlpHeader.get(4)).getRLPData();
if(this.txTrieRoot == null)
this.txTrieRoot = EMPTY_DATA_HASH;
this.txTrieRoot = EMTPY_TRIE_HASH;
this.recieptTrieRoot = ((RLPItem) rlpHeader.get(5)).getRLPData();
if(this.recieptTrieRoot == null)
@ -289,10 +292,10 @@ public class BlockHeader {
byte[] stateRoot = RLP.encodeElement(this.stateRoot);
if (txTrieRoot == null) this.txTrieRoot = EMPTY_DATA_HASH;
if (txTrieRoot == null) this.txTrieRoot = EMTPY_TRIE_HASH;
byte[] txTrieRoot = RLP.encodeElement(this.txTrieRoot);
if (recieptTrieRoot == null) this.recieptTrieRoot = EMPTY_DATA_HASH;
if (recieptTrieRoot == null) this.recieptTrieRoot = EMTPY_TRIE_HASH;
byte[] recieptTrieRoot = RLP.encodeElement(this.recieptTrieRoot);
byte[] logsBloom = RLP.encodeElement(this.logsBloom);
@ -354,23 +357,4 @@ public class BlockHeader {
return toStringBuff.toString();
}
public String toStylishString() {
toStringBuff.setLength(0);
toStringBuff.append(", <font color=\"${attribute_color}\"> parentHash</font>=" + toHexString(parentHash)).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> unclesHash</font>=" + toHexString(unclesHash)).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> coinbase</font>=" + toHexString(coinbase)).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> stateRoot</font>=" + toHexString(stateRoot)).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> txTrieHash</font>=" + toHexString(txTrieRoot)).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> difficulty</font>=" + toHexString(difficulty)).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> number</font>=" + number).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> minGasPrice</font>=" + minGasPrice).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> gasLimit</font>=" + gasLimit).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> gasUsed</font>=" + gasUsed).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> timestamp</font>=" + timestamp + " (" + Utils.longToDateTime(timestamp) + ")").append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> extraData</font>=" + toHexString(extraData)).append("<br/>");
toStringBuff.append(", <font color=\"${attribute_color}\"> nonce</font>=" + toHexString(nonce)).append("<br/>");
return toStringBuff.toString();
}
}

View File

@ -195,17 +195,11 @@ public class BlockchainImpl implements Blockchain {
int i = 0;
long totalGasUsed = 0;
for (TransactionReceipt txr : block.getTxReceiptList()) {
for (Transaction tx : block.getTransactionsList()) {
stateLogger.debug("apply block: [{}] tx: [{}] ", block.getNumber(), i);
totalGasUsed += applyTransaction(block, txr.getTransaction());
totalGasUsed += applyTransaction(block, tx);
if(block.getNumber() >= CONFIG.traceStartBlock())
repository.dumpState(block, totalGasUsed, i++, txr.getTransaction().getHash());
if(!Arrays.equals(this.repository.getWorldState().getRootHash(), txr.getPostTxState())) {
stateLogger.warn("TX: STATE CONFLICT {}..: {}", Hex.toHexString(txr.getTransaction().getHash()).substring(0, 8),
Hex.toHexString(this.repository.getWorldState().getRootHash()));
// repository.close();
// System.exit(-1); // Don't continue
}
repository.dumpState(block, totalGasUsed, i++, tx.getHash());
}
this.addReward(block);

View File

@ -1,14 +1,18 @@
package org.ethereum.core;
import static org.ethereum.crypto.HashUtil.sha3;
import static org.ethereum.crypto.HashUtil.EMPTY_LIST_HASH;
import org.ethereum.crypto.HashUtil;
import org.ethereum.crypto.SHA3Helper;
import org.ethereum.trie.Trie;
import org.ethereum.trie.TrieImpl;
import org.ethereum.util.ByteUtil;
import org.ethereum.util.RLP;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
import static org.ethereum.crypto.HashUtil.*;
import static org.ethereum.crypto.HashUtil.EMPTY_DATA_HASH;
/**
* The genesis block is the first block in the chain and has fixed values according to
* the protocol specification. The genesis block is 13 items, and is specified thus:
@ -46,7 +50,7 @@ public class Genesis extends Block {
private static byte[] zeroHash512 = new byte[64];
public static byte[] PARENT_HASH = zeroHash256;
public static byte[] UNCLES_HASH = EMPTY_LIST_HASH;
public static byte[] UNCLES_HASH = EMPTY_DATA_HASH;
public static byte[] COINBASE = zeroHash160;
public static byte[] LOG_BLOOM = zeroHash512;
public static byte[] DIFFICULTY = BigInteger.valueOf(2).pow(17).toByteArray();
@ -69,7 +73,8 @@ public class Genesis extends Block {
// The proof-of-concept series include a development pre-mine, making the state root hash
// some value stateRoot. The latest documentation should be consulted for the value of the state root.
for (String address : premine) {
AccountState acctState = new AccountState(BigInteger.ZERO, PREMINE_AMOUNT);
AccountState acctState = new AccountState();
acctState.addToBalance(PREMINE_AMOUNT);
state.update(Hex.decode(address), acctState.getEncoded());
}

View File

@ -7,6 +7,7 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.ethereum.db.ByteArrayWrapper;
import org.ethereum.util.ByteUtil;
import org.ethereum.util.RLP;
import org.ethereum.util.Utils;
import org.spongycastle.crypto.Digest;
@ -18,8 +19,8 @@ public class HashUtil {
private static final int MAX_ENTRIES = 100; // Should contain most commonly hashed values
private static LRUMap<ByteArrayWrapper, byte[]> sha3Cache = new LRUMap<>(0, MAX_ENTRIES);
public static final byte[] EMPTY_DATA_HASH = Hex.decode("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
public static final byte[] EMPTY_LIST_HASH = Hex.decode("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347");
public static final byte[] EMPTY_DATA_HASH = SHA3Helper.sha3("");
public static final byte[] EMTPY_TRIE_HASH = SHA3Helper.sha3(RLP.encodeElement(ByteUtil.EMPTY_BYTE_ARRAY));
private static final MessageDigest sha256digest;

View File

@ -1,6 +1,7 @@
package org.ethereum.trie;
import static java.util.Arrays.copyOfRange;
import static org.ethereum.crypto.HashUtil.EMTPY_TRIE_HASH;
import static org.ethereum.util.ByteUtil.matchingNibbleLength;
import static org.ethereum.util.CompactEncoder.binToNibbles;
import static org.ethereum.util.CompactEncoder.packNibbles;
@ -11,6 +12,7 @@ import java.util.*;
import org.ethereum.crypto.HashUtil;
import org.ethereum.db.ByteArrayWrapper;
import org.ethereum.util.ByteUtil;
import org.ethereum.util.Value;
import org.iq80.leveldb.DB;
import org.slf4j.Logger;
@ -154,7 +156,7 @@ public class TrieImpl implements Trie {
if (root == null
|| (root instanceof byte[] && ((byte[]) root).length == 0)
|| (root instanceof String && "".equals((String) root))) {
return HashUtil.EMPTY_DATA_HASH;
return EMTPY_TRIE_HASH;
} else if (root instanceof byte[]) {
return (byte[]) this.getRoot();
} else {

View File

@ -6,6 +6,8 @@ import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.Arrays;
import org.ethereum.crypto.SHA3Helper;
import org.ethereum.trie.TrieImpl;
import org.spongycastle.util.encoders.Hex;
public class ByteUtil {

View File

@ -30,8 +30,8 @@ public class BlockTest {
}
// https://ethereum.etherpad.mozilla.org/12
private String PoC7_GENESIS_HEX_RLP_ENCODED = "f8abf8a7a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0477fd4d3a3bae60913bbb0cbffbc1aae5c57a60f6351f9ed702d97378f851fc680830200008080830f4240808080a004994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829c0c0";
private String PoC7_GENESIS_HEX_HASH = "c4bcce917758c95695b8a368f920d166b4f9b3572c54ff40385ef84ea6850099";
private String PoC7_GENESIS_HEX_RLP_ENCODED = "f9012ff9012aa00000000000000000000000000000000000000000000000000000000000000000a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470940000000000000000000000000000000000000000a0c67c70f5d7d3049337d1dcc0503a249881120019a8e7322774dbfe57b463718ca056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200008080830f4240808080a004994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829c0c0";
private String PoC7_GENESIS_HEX_HASH = "19039f385f269fae48d497fba579d7079c761cec5643ec1096e98bdda4ffcf00";
String block_2 = "f8b5f8b1a0cf4b25b08b39350304fe12a16e4216c01a426f8f3dbf0d392b5b45"
+ "8ffb6a399da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a1"

View File

@ -14,7 +14,7 @@ import org.spongycastle.util.encoders.Hex;
public class StateTest {
private static final String GENESIS_STATE_ROOT = "477fd4d3a3bae60913bbb0cbffbc1aae5c57a60f6351f9ed702d97378f851fc6";
private static final String GENESIS_STATE_ROOT = "c67c70f5d7d3049337d1dcc0503a249881120019a8e7322774dbfe57b463718c";
@Test
public void testGenesisAccounts() {
@ -94,7 +94,7 @@ public class StateTest {
// 4) calc the root
Trie trie = generateGenesisState();
String expected = "e9d7cff80ac451f10a5212b0e8bb6070d0c2214b9d4943794269be78b13d1fb4";
String expected = "6ae5f47b0cc54ca33b4a46537f6cf6673f9138e876f3ac5a33dde173efe28236";
// Get and update sender in world state
byte[] cowAddress = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826");

View File

@ -4,12 +4,14 @@ import org.ethereum.core.AccountState;
import org.ethereum.crypto.HashUtil;
import org.ethereum.facade.Repository;
import org.ethereum.vm.DataWord;
import org.junit.*;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
import static org.ethereum.crypto.HashUtil.EMPTY_DATA_HASH;
import static org.junit.Assert.*;
/**
@ -183,7 +185,7 @@ public class RepositoryTest {
AccountState accountState = repository.getAccountState(addr);
assertTrue(code0 == null);
assertNull(code1);
assertArrayEquals(HashUtil.EMPTY_DATA_HASH, accountState.getCodeHash());
assertEquals(EMPTY_DATA_HASH, accountState.getCodeHash());
} finally {
repository.close();
}

View File

@ -1,5 +1,6 @@
package org.ethereum.trie;
import static org.ethereum.crypto.HashUtil.EMTPY_TRIE_HASH;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@ -18,6 +19,7 @@ import org.ethereum.core.AccountState;
import org.ethereum.crypto.HashUtil;
import org.ethereum.db.DatabaseImpl;
import org.ethereum.db.MockDB;
import org.ethereum.util.ByteUtil;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
@ -30,7 +32,7 @@ import org.spongycastle.util.encoders.Hex;
public class TrieTest {
private static String LONG_STRING = "1234567890abcdefghijklmnopqrstuvwxxzABCEFGHIJKLMNOPQRSTUVWXYZ";
private static String ROOT_HASH_EMPTY = Hex.toHexString(HashUtil.EMPTY_DATA_HASH);
private static String ROOT_HASH_EMPTY = Hex.toHexString(EMTPY_TRIE_HASH);
private static String c = "c";
private static String ca = "ca";

View File

@ -25,4 +25,5 @@ log4j.logger.blockchain = DEBUG
log4j.logger.txs = ERROR
log4j.logger.ui = ERROR
log4j.logger.gas = ERROR
log4j.logger.test = TRACE

View File

@ -71,7 +71,7 @@
<dependency>
<groupId>org.ethereum</groupId>
<artifactId>ethereumj</artifactId>
<version>0.7.8.20141103.1055</version>
<version>0.7.8.20141103.1355</version>
</dependency>

View File

@ -9,8 +9,8 @@ peer.discovery.ip.list = poc-7.ethdev.com:30303,\
185.43.109.23:30303
# Peer Server Zero (poc-7.ethdev.com)
peer.active.ip = 23.22.211.45
peer.active.port = 11111
peer.active.ip = 127.0.0.1
peer.active.port = 10101
# ZeroGox