aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain
diff options
context:
space:
mode:
Diffstat (limited to 'ethchain')
-rw-r--r--ethchain/block.go81
-rw-r--r--ethchain/block_chain.go16
-rw-r--r--ethchain/genesis.go18
3 files changed, 98 insertions, 17 deletions
diff --git a/ethchain/block.go b/ethchain/block.go
index ca84dc19c..c6c2c1226 100644
--- a/ethchain/block.go
+++ b/ethchain/block.go
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/ethereum/eth-go/ethutil"
"math/big"
+ "strconv"
"time"
)
@@ -40,6 +41,14 @@ type Block struct {
Difficulty *big.Int
// Creation time
Time int64
+ // The block number
+ Number *big.Int
+ // Minimum Gas Price
+ MinGasPrice *big.Int
+ // Gas limit
+ GasLimit *big.Int
+ // Gas used
+ GasUsed *big.Int
// Extra data
Extra string
// Block Nonce for verification
@@ -206,7 +215,12 @@ func (block *Block) SetUncles(uncles []*Block) {
func (block *Block) SetTransactions(txs []*Transaction) {
block.transactions = txs
- block.TxSha = ethutil.Sha3Bin(ethutil.Encode(block.rlpTxs()))
+ trie := ethutil.NewTrie(ethutil.Config.Db, "")
+ for i, tx := range txs {
+ trie.Update(strconv.Itoa(i), string(tx.RlpEncode()))
+ }
+
+ block.TxSha = trie.Root.([]byte)
}
func (block *Block) Value() *ethutil.Value {
@@ -233,9 +247,13 @@ func (block *Block) RlpValueDecode(decoder *ethutil.Value) {
block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, header.Get(3).Val))
block.TxSha = header.Get(4).Bytes()
block.Difficulty = header.Get(5).BigInt()
- block.Time = int64(header.Get(6).BigInt().Uint64())
- block.Extra = header.Get(7).Str()
- block.Nonce = header.Get(8).Bytes()
+ block.Number = header.Get(6).BigInt()
+ block.MinGasPrice = header.Get(7).BigInt()
+ block.GasLimit = header.Get(8).BigInt()
+ block.GasUsed = header.Get(9).BigInt()
+ block.Time = int64(header.Get(10).BigInt().Uint64())
+ block.Extra = header.Get(11).Str()
+ block.Nonce = header.Get(12).Bytes()
block.contractStates = make(map[string]*ethutil.Trie)
// Tx list might be empty if this is an uncle. Uncles only have their
@@ -270,21 +288,21 @@ func NewUncleBlockFromValue(header *ethutil.Value) *Block {
block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, header.Get(3).Val))
block.TxSha = header.Get(4).Bytes()
block.Difficulty = header.Get(5).BigInt()
- block.Time = int64(header.Get(6).BigInt().Uint64())
- block.Extra = header.Get(7).Str()
- block.Nonce = header.Get(8).Bytes()
+ block.Number = header.Get(6).BigInt()
+ block.MinGasPrice = header.Get(7).BigInt()
+ block.GasLimit = header.Get(8).BigInt()
+ block.GasUsed = header.Get(9).BigInt()
+ block.Time = int64(header.Get(10).BigInt().Uint64())
+ block.Extra = header.Get(11).Str()
+ block.Nonce = header.Get(12).Bytes()
return block
}
-func (block *Block) String() string {
- return fmt.Sprintf("Block(%x):\nPrevHash:%x\nUncleSha:%x\nCoinbase:%x\nRoot:%x\nTxSha:%x\nDiff:%v\nTime:%d\nNonce:%x\nTxs:%d\n", block.Hash(), block.PrevHash, block.UncleSha, block.Coinbase, block.state.trie.Root, block.TxSha, block.Difficulty, block.Time, block.Nonce, len(block.transactions))
-}
func (block *Block) GetRoot() interface{} {
return block.state.trie.Root
}
-//////////// UNEXPORTED /////////////////
func (block *Block) header() []interface{} {
return []interface{}{
// Sha of the previous block
@@ -299,6 +317,14 @@ func (block *Block) header() []interface{} {
block.TxSha,
// Current block Difficulty
block.Difficulty,
+ // The block number
+ block.Number,
+ // Block minimum gas price
+ block.MinGasPrice,
+ // Block upper gas bound
+ block.GasLimit,
+ // Block gas used
+ block.GasUsed,
// Time the block was found?
block.Time,
// Extra data
@@ -307,3 +333,36 @@ func (block *Block) header() []interface{} {
block.Nonce,
}
}
+
+func (block *Block) String() string {
+ return fmt.Sprintf(`
+ BLOCK(%x):
+ PrevHash: %x
+ UncleSha: %x
+ Coinbase: %x
+ Root: %x
+ TxSha: %x
+ Difficulty: %v
+ Number: %v
+ MinGas: %v
+ MaxLimit: %v
+ GasUsed: %v
+ Time: %v
+ Extra: %v
+ Nonce: %x
+`,
+ block.Hash(),
+ block.PrevHash,
+ block.UncleSha,
+ block.Coinbase,
+ block.state.trie.Root,
+ block.TxSha,
+ block.Difficulty,
+ block.Number,
+ block.MinGasPrice,
+ block.GasLimit,
+ block.GasUsed,
+ block.Time,
+ block.Extra,
+ block.Nonce)
+}
diff --git a/ethchain/block_chain.go b/ethchain/block_chain.go
index eb25bd3f4..2865336fb 100644
--- a/ethchain/block_chain.go
+++ b/ethchain/block_chain.go
@@ -70,6 +70,22 @@ func (bc *BlockChain) NewBlock(coinbase []byte, txs []*Transaction) *Block {
diff.Mul(diff, mul)
diff.Add(diff, bc.CurrentBlock.Difficulty)
block.Difficulty = diff
+
+ block.Number = new(big.Int).Add(bc.CurrentBlock.Number, ethutil.Big1)
+
+ // max(10000, (parent gas limit * (1024 - 1) + (parent gas used * 6 / 5)) / 1024)
+ base := new(big.Int)
+ base2 := new(big.Int)
+ parentGL := bc.CurrentBlock.GasLimit
+ parentUsed := bc.CurrentBlock.GasUsed
+
+ base.Mul(parentGL, big.NewInt(1024-1))
+ base2.Mul(parentUsed, big.NewInt(6))
+ base2.Div(base2, big.NewInt(5))
+ base.Add(base, base2)
+ base.Div(base, big.NewInt(1024))
+
+ block.GasLimit = ethutil.BigMax(big.NewInt(10000), base)
}
return block
diff --git a/ethchain/genesis.go b/ethchain/genesis.go
index 935978a69..b8f9f865a 100644
--- a/ethchain/genesis.go
+++ b/ethchain/genesis.go
@@ -15,7 +15,6 @@ var EmptyShaList = ethutil.Sha3Bin(ethutil.Encode([]interface{}{}))
var GenesisHeader = []interface{}{
// Previous hash (none)
- //"",
ZeroHash256,
// Sha of uncles
ethutil.Sha3Bin(ethutil.Encode([]interface{}{})),
@@ -23,15 +22,22 @@ var GenesisHeader = []interface{}{
ZeroHash160,
// Root state
"",
- // Sha of transactions
- //EmptyShaList,
- ethutil.Sha3Bin(ethutil.Encode([]interface{}{})),
+ // tx sha
+ ZeroHash256,
// Difficulty
ethutil.BigPow(2, 22),
+ // Number
+ ethutil.Big0,
+ // Block minimum gas price
+ ethutil.Big0,
+ // Block upper gas bound
+ big.NewInt(1000000),
+ // Block gas used
+ ethutil.Big0,
// Time
- int64(0),
+ ethutil.Big0,
// Extra
- "",
+ nil,
// Nonce
ethutil.Sha3Bin(big.NewInt(42).Bytes()),
}