mirror of
https://github.com/status-im/ethereumj-personal.git
synced 2025-01-27 12:15:55 +00:00
Remove call to Blockchain DB from Genesis and fix default calc values
This commit is contained in:
parent
eb46749f53
commit
f59e2408f9
@ -226,7 +226,7 @@ public class Block {
|
|||||||
|
|
||||||
toStringBuff.setLength(0);
|
toStringBuff.setLength(0);
|
||||||
toStringBuff.append("BlockData [");
|
toStringBuff.append("BlockData [");
|
||||||
toStringBuff.append(" hash=" + ByteUtil.toHexString(hash)).append("");
|
toStringBuff.append(" hash=" + ByteUtil.toHexString(this.getHash())).append("");
|
||||||
toStringBuff.append(header.toFlatString());
|
toStringBuff.append(header.toFlatString());
|
||||||
|
|
||||||
for (Transaction tx : getTransactionsList()){
|
for (Transaction tx : getTransactionsList()){
|
||||||
@ -313,8 +313,8 @@ public class Block {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public long calcGasLimit() {
|
public long calcGasLimit() {
|
||||||
if (this.header.getParentHash() == null)
|
if (Arrays.equals(this.header.getParentHash(), Genesis.PARENT_HASH))
|
||||||
return 1000000L;
|
return Genesis.GAS_LIMIT;
|
||||||
else {
|
else {
|
||||||
Block parent = this.getParent();
|
Block parent = this.getParent();
|
||||||
return Math.max(MIN_GAS_LIMIT, (parent.header.getGasLimit() * (1024 - 1) + (parent.header.getGasUsed() * 6 / 5)) / 1024);
|
return Math.max(MIN_GAS_LIMIT, (parent.header.getGasLimit() * (1024 - 1) + (parent.header.getGasUsed() * 6 / 5)) / 1024);
|
||||||
|
@ -9,10 +9,29 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.spongycastle.util.encoders.Hex;
|
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 {
|
public class Genesis extends Block {
|
||||||
|
|
||||||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
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 AccountState acct = new AccountState(BigInteger.ZERO, BigInteger.valueOf(2).pow(200));
|
||||||
private String[] premine = new String[] {
|
private String[] premine = new String[] {
|
||||||
"2ef47100e0787b915105fd5e3f4ff6752079d5cb", // # (M)
|
"2ef47100e0787b915105fd5e3f4ff6752079d5cb", // # (M)
|
||||||
@ -53,8 +72,6 @@ public class Genesis extends Block {
|
|||||||
}
|
}
|
||||||
logger.info("Genesis-hash: " + Hex.toHexString(this.getHash()));
|
logger.info("Genesis-hash: " + Hex.toHexString(this.getHash()));
|
||||||
logger.info("Genesis-stateRoot: " + Hex.toHexString(this.getStateRoot()));
|
logger.info("Genesis-stateRoot: " + Hex.toHexString(this.getStateRoot()));
|
||||||
|
|
||||||
Config.CHAIN_DB.put(getParentHash(), getEncoded());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Block getInstance() {
|
public static Block getInstance() {
|
||||||
|
@ -94,13 +94,15 @@ public class BlockTest {
|
|||||||
Block genesis = Genesis.getInstance();
|
Block genesis = Genesis.getInstance();
|
||||||
byte[] diffBytes = genesis.calcDifficulty();
|
byte[] diffBytes = genesis.calcDifficulty();
|
||||||
BigInteger difficulty = new BigInteger(1, diffBytes);
|
BigInteger difficulty = new BigInteger(1, diffBytes);
|
||||||
System.out.println(difficulty.toString());
|
System.out.println("Genesis difficulty = " + difficulty.toString());
|
||||||
fail("Yet to be implemented.");
|
fail("Yet to be implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCalcGasLimit() {
|
public void testCalcGasLimit() {
|
||||||
// Block.calcGasLimit()
|
Block genesis = Genesis.getInstance();
|
||||||
|
long gasLimit = genesis.calcGasLimit();
|
||||||
|
System.out.println("Genesis gasLimit = " + gasLimit);
|
||||||
fail("Yet to be implemented.");
|
fail("Yet to be implemented.");
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user