From f59e2408f94f01cf1fb9d6cf05e8d40c6304fc0c Mon Sep 17 00:00:00 2001 From: nicksavers Date: Sat, 7 Jun 2014 17:27:38 +0200 Subject: [PATCH] Remove call to Blockchain DB from Genesis and fix default calc values --- .../main/java/org/ethereum/core/Block.java | 6 +++--- .../main/java/org/ethereum/core/Genesis.java | 21 +++++++++++++++++-- .../java/org/ethereum/core/BlockTest.java | 6 ++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Block.java b/ethereumj-core/src/main/java/org/ethereum/core/Block.java index f6b452a0..fff0fe6a 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Block.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Block.java @@ -226,7 +226,7 @@ public class Block { toStringBuff.setLength(0); toStringBuff.append("BlockData ["); - toStringBuff.append(" hash=" + ByteUtil.toHexString(hash)).append(""); + toStringBuff.append(" hash=" + ByteUtil.toHexString(this.getHash())).append(""); toStringBuff.append(header.toFlatString()); for (Transaction tx : getTransactionsList()){ @@ -313,8 +313,8 @@ public class Block { * @return */ public long calcGasLimit() { - if (this.header.getParentHash() == null) - return 1000000L; + if (Arrays.equals(this.header.getParentHash(), Genesis.PARENT_HASH)) + return Genesis.GAS_LIMIT; else { Block parent = this.getParent(); return Math.max(MIN_GAS_LIMIT, (parent.header.getGasLimit() * (1024 - 1) + (parent.header.getGasUsed() * 6 / 5)) / 1024); diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Genesis.java b/ethereumj-core/src/main/java/org/ethereum/core/Genesis.java index 5058384e..e54e39fc 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Genesis.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Genesis.java @@ -9,10 +9,29 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spongycastle.util.encoders.Hex; +/** + * 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: + * + * ( zerohash_256 , SHA3 RLP () , zerohash_160 , stateRoot, 0, 2^22 , 0, 0, 1000000, 0, 0, 0, SHA3 (42) , (), () ) + * + * - Where zerohash_256 refers to the parent hash, a 256-bit hash which is all zeroes; + * - zerohash_160 refers to the coinbase address, a 160-bit hash which is all zeroes; + * - 2^22 refers to the difficulty; + * - 0 refers to the timestamp (the Unix epoch); + * - the transaction trie root and extradata are both 0, being equivalent to the empty byte array. + * - The sequences of both uncles and transactions are empty and represented by (). + * - SHA3 (42) refers to the SHA3 hash of a byte array of length one whose first and only byte is of value 42. + * - SHA3 RLP () value refers to the hash of the uncle lists in RLP, both empty lists. + * + * See Yellow Paper: http://www.gavwood.com/Paper.pdf (Appendix I. Genesis Block) + */ public class Genesis extends Block { Logger logger = LoggerFactory.getLogger(this.getClass()); + // The proof-of-concept series include a development premine, making the state root hash + // some value stateRoot. The latest documentation should be consulted for the value of the state root. private AccountState acct = new AccountState(BigInteger.ZERO, BigInteger.valueOf(2).pow(200)); private String[] premine = new String[] { "2ef47100e0787b915105fd5e3f4ff6752079d5cb", // # (M) @@ -53,8 +72,6 @@ public class Genesis extends Block { } logger.info("Genesis-hash: " + Hex.toHexString(this.getHash())); logger.info("Genesis-stateRoot: " + Hex.toHexString(this.getStateRoot())); - - Config.CHAIN_DB.put(getParentHash(), getEncoded()); } public static Block getInstance() { diff --git a/ethereumj-core/src/test/java/org/ethereum/core/BlockTest.java b/ethereumj-core/src/test/java/org/ethereum/core/BlockTest.java index f0914fd7..a6edcbc3 100644 --- a/ethereumj-core/src/test/java/org/ethereum/core/BlockTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/core/BlockTest.java @@ -94,13 +94,15 @@ public class BlockTest { Block genesis = Genesis.getInstance(); byte[] diffBytes = genesis.calcDifficulty(); BigInteger difficulty = new BigInteger(1, diffBytes); - System.out.println(difficulty.toString()); + System.out.println("Genesis difficulty = " + difficulty.toString()); fail("Yet to be implemented."); } @Test public void testCalcGasLimit() { - // Block.calcGasLimit() + Block genesis = Genesis.getInstance(); + long gasLimit = genesis.calcGasLimit(); + System.out.println("Genesis gasLimit = " + gasLimit); fail("Yet to be implemented."); } } \ No newline at end of file