From f6d1bfe45bf3709d7bad40bf563b5c09228622e3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 14 Feb 2014 23:56:09 +0100 Subject: The great merge --- ethchain/block.go | 363 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 363 insertions(+) create mode 100644 ethchain/block.go (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go new file mode 100644 index 000000000..a7a1f787b --- /dev/null +++ b/ethchain/block.go @@ -0,0 +1,363 @@ +package ethchain + +import ( + "fmt" + "github.com/ethereum/eth-go/ethutil" + "math/big" + "time" +) + +type BlockInfo struct { + Number uint64 + Hash []byte + Parent []byte +} + +func (bi *BlockInfo) RlpDecode(data []byte) { + decoder := ethutil.NewValueFromBytes(data) + + bi.Number = decoder.Get(0).Uint() + bi.Hash = decoder.Get(1).Bytes() + bi.Parent = decoder.Get(2).Bytes() +} + +func (bi *BlockInfo) RlpEncode() []byte { + return ethutil.Encode([]interface{}{bi.Number, bi.Hash, bi.Parent}) +} + +type Block struct { + // Hash to the previous block + PrevHash []byte + // Uncles of this block + Uncles []*Block + UncleSha []byte + // The coin base address + Coinbase []byte + // Block Trie state + state *ethutil.Trie + // Difficulty for the current block + Difficulty *big.Int + // Creation time + Time int64 + // Extra data + Extra string + // Block Nonce for verification + Nonce []byte + // List of transactions and/or contracts + transactions []*Transaction + TxSha []byte +} + +// New block takes a raw encoded string +// XXX DEPRICATED +func NewBlockFromData(raw []byte) *Block { + return NewBlockFromBytes(raw) +} + +func NewBlockFromBytes(raw []byte) *Block { + block := &Block{} + block.RlpDecode(raw) + + return block +} + +// New block takes a raw encoded string +func NewBlockFromRlpValue(rlpValue *ethutil.Value) *Block { + block := &Block{} + block.RlpValueDecode(rlpValue) + + return block +} + +func CreateBlock(root interface{}, + prevHash []byte, + base []byte, + Difficulty *big.Int, + Nonce []byte, + extra string, + txes []*Transaction) *Block { + + block := &Block{ + // Slice of transactions to include in this block + transactions: txes, + PrevHash: prevHash, + Coinbase: base, + Difficulty: Difficulty, + Nonce: Nonce, + Time: time.Now().Unix(), + Extra: extra, + UncleSha: EmptyShaList, + } + block.SetTransactions(txes) + block.SetUncles([]*Block{}) + + block.state = ethutil.NewTrie(ethutil.Config.Db, root) + + for _, tx := range txes { + block.MakeContract(tx) + } + + return block +} + +// Returns a hash of the block +func (block *Block) Hash() []byte { + return ethutil.Sha3Bin(block.RlpValue().Encode()) +} + +func (block *Block) HashNoNonce() []byte { + return ethutil.Sha3Bin(ethutil.Encode([]interface{}{block.PrevHash, block.UncleSha, block.Coinbase, block.state.Root, block.TxSha, block.Difficulty, block.Time, block.Extra})) +} + +func (block *Block) PrintHash() { + fmt.Println(block) + fmt.Println(ethutil.NewValue(ethutil.Encode([]interface{}{block.PrevHash, block.UncleSha, block.Coinbase, block.state.Root, block.TxSha, block.Difficulty, block.Time, block.Extra, block.Nonce}))) +} + +func (block *Block) State() *ethutil.Trie { + return block.state +} + +func (block *Block) Transactions() []*Transaction { + return block.transactions +} + +func (block *Block) GetContract(addr []byte) *Contract { + data := block.state.Get(string(addr)) + if data == "" { + return nil + } + + contract := &Contract{} + contract.RlpDecode([]byte(data)) + + return contract +} +func (block *Block) UpdateContract(addr []byte, contract *Contract) { + // Make sure the state is synced + contract.State().Sync() + + block.state.Update(string(addr), string(contract.RlpEncode())) +} + +func (block *Block) GetAddr(addr []byte) *Address { + var address *Address + + data := block.State().Get(string(addr)) + if data == "" { + address = NewAddress(big.NewInt(0)) + } else { + address = NewAddressFromData([]byte(data)) + } + + return address +} +func (block *Block) UpdateAddr(addr []byte, address *Address) { + block.state.Update(string(addr), string(address.RlpEncode())) +} + +func (block *Block) PayFee(addr []byte, fee *big.Int) bool { + contract := block.GetContract(addr) + // If we can't pay the fee return + if contract == nil || contract.Amount.Cmp(fee) < 0 /* amount < fee */ { + fmt.Println("Contract has insufficient funds", contract.Amount, fee) + + return false + } + + base := new(big.Int) + contract.Amount = base.Sub(contract.Amount, fee) + block.state.Update(string(addr), string(contract.RlpEncode())) + + data := block.state.Get(string(block.Coinbase)) + + // Get the ether (Coinbase) and add the fee (gief fee to miner) + ether := NewAddressFromData([]byte(data)) + + base = new(big.Int) + ether.Amount = base.Add(ether.Amount, fee) + + block.state.Update(string(block.Coinbase), string(ether.RlpEncode())) + + return true +} + +func (block *Block) BlockInfo() BlockInfo { + bi := BlockInfo{} + data, _ := ethutil.Config.Db.Get(append(block.Hash(), []byte("Info")...)) + bi.RlpDecode(data) + + return bi +} + +func (block *Block) MakeContract(tx *Transaction) { + // Create contract if there's no recipient + if tx.IsContract() { + addr := tx.Hash() + + value := tx.Value + contract := NewContract(value, []byte("")) + block.state.Update(string(addr), string(contract.RlpEncode())) + for i, val := range tx.Data { + contract.state.Update(string(ethutil.NumberToBytes(uint64(i), 32)), val) + } + block.UpdateContract(addr, contract) + } +} + +/////// Block Encoding +func (block *Block) encodedUncles() interface{} { + uncles := make([]interface{}, len(block.Uncles)) + for i, uncle := range block.Uncles { + uncles[i] = uncle.RlpEncode() + } + + return uncles +} + +func (block *Block) encodedTxs() interface{} { + // Marshal the transactions of this block + encTx := make([]interface{}, len(block.transactions)) + for i, tx := range block.transactions { + // Cast it to a string (safe) + encTx[i] = tx.RlpData() + } + + return encTx +} + +func (block *Block) rlpTxs() interface{} { + // Marshal the transactions of this block + encTx := make([]interface{}, len(block.transactions)) + for i, tx := range block.transactions { + // Cast it to a string (safe) + encTx[i] = tx.RlpData() + } + + return encTx +} + +func (block *Block) rlpUncles() interface{} { + // Marshal the transactions of this block + uncles := make([]interface{}, len(block.Uncles)) + for i, uncle := range block.Uncles { + // Cast it to a string (safe) + uncles[i] = uncle.header() + } + + return uncles +} + +func (block *Block) SetUncles(uncles []*Block) { + block.Uncles = uncles + + // Sha of the concatenated uncles + block.UncleSha = ethutil.Sha3Bin(ethutil.Encode(block.rlpUncles())) +} + +func (block *Block) SetTransactions(txs []*Transaction) { + block.transactions = txs + + block.TxSha = ethutil.Sha3Bin(ethutil.Encode(block.rlpTxs())) +} + +func (block *Block) RlpValue() *ethutil.RlpValue { + return ethutil.NewRlpValue([]interface{}{block.header(), block.rlpTxs(), block.rlpUncles()}) +} + +func (block *Block) RlpEncode() []byte { + // Encode a slice interface which contains the header and the list of + // transactions. + return block.RlpValue().Encode() +} + +func (block *Block) RlpDecode(data []byte) { + rlpValue := ethutil.NewValueFromBytes(data) + block.RlpValueDecode(rlpValue) +} + +func (block *Block) RlpValueDecode(decoder *ethutil.Value) { + header := decoder.Get(0) + + block.PrevHash = header.Get(0).Bytes() + block.UncleSha = header.Get(1).Bytes() + block.Coinbase = header.Get(2).Bytes() + block.state = 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() + + // Tx list might be empty if this is an uncle. Uncles only have their + // header set. + if decoder.Get(1).IsNil() == false { // Yes explicitness + txes := decoder.Get(1) + block.transactions = make([]*Transaction, txes.Len()) + for i := 0; i < txes.Len(); i++ { + tx := NewTransactionFromValue(txes.Get(i)) + + block.transactions[i] = tx + + /* + if ethutil.Config.Debug { + ethutil.Config.Db.Put(tx.Hash(), ethutil.Encode(tx)) + } + */ + } + + } + + if decoder.Get(2).IsNil() == false { // Yes explicitness + uncles := decoder.Get(2) + block.Uncles = make([]*Block, uncles.Len()) + for i := 0; i < uncles.Len(); i++ { + block.Uncles[i] = NewUncleBlockFromValue(uncles.Get(i)) + } + } + +} + +func NewUncleBlockFromValue(header *ethutil.Value) *Block { + block := &Block{} + + block.PrevHash = header.Get(0).Bytes() + block.UncleSha = header.Get(1).Bytes() + block.Coinbase = header.Get(2).Bytes() + block.state = 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() + + 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", block.Hash(), block.PrevHash, block.UncleSha, block.Coinbase, block.state.Root, block.TxSha, block.Difficulty, block.Time, block.Nonce) +} + +//////////// UNEXPORTED ///////////////// +func (block *Block) header() []interface{} { + return []interface{}{ + // Sha of the previous block + block.PrevHash, + // Sha of uncles + block.UncleSha, + // Coinbase address + block.Coinbase, + // root state + block.state.Root, + // Sha of tx + block.TxSha, + // Current block Difficulty + block.Difficulty, + // Time the block was found? + block.Time, + // Extra data + block.Extra, + // Block's Nonce for validation + block.Nonce, + } +} -- cgit From 73fd358d940418b15dec850f50407bd2e504d88c Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 15 Feb 2014 01:34:18 +0100 Subject: Removed RlpValue in favour of Value --- ethchain/block.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index a7a1f787b..0678f64e2 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -102,7 +102,7 @@ func CreateBlock(root interface{}, // Returns a hash of the block func (block *Block) Hash() []byte { - return ethutil.Sha3Bin(block.RlpValue().Encode()) + return ethutil.Sha3Bin(block.Value().Encode()) } func (block *Block) HashNoNonce() []byte { @@ -261,14 +261,14 @@ func (block *Block) SetTransactions(txs []*Transaction) { block.TxSha = ethutil.Sha3Bin(ethutil.Encode(block.rlpTxs())) } -func (block *Block) RlpValue() *ethutil.RlpValue { - return ethutil.NewRlpValue([]interface{}{block.header(), block.rlpTxs(), block.rlpUncles()}) +func (block *Block) Value() *ethutil.Value { + return ethutil.NewValue([]interface{}{block.header(), block.rlpTxs(), block.rlpUncles()}) } func (block *Block) RlpEncode() []byte { // Encode a slice interface which contains the header and the list of // transactions. - return block.RlpValue().Encode() + return block.Value().Encode() } func (block *Block) RlpDecode(data []byte) { -- cgit From 8629d9a4187c2027e565a50d763f949993ab169c Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 18 Feb 2014 01:33:15 +0100 Subject: String changed and removed some debugging code --- ethchain/block.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 0678f64e2..34ddf9fec 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -135,7 +135,7 @@ func (block *Block) GetContract(addr []byte) *Contract { } func (block *Block) UpdateContract(addr []byte, contract *Contract) { // Make sure the state is synced - contract.State().Sync() + //contract.State().Sync() block.state.Update(string(addr), string(contract.RlpEncode())) } @@ -298,12 +298,6 @@ func (block *Block) RlpValueDecode(decoder *ethutil.Value) { tx := NewTransactionFromValue(txes.Get(i)) block.transactions[i] = tx - - /* - if ethutil.Config.Debug { - ethutil.Config.Db.Put(tx.Hash(), ethutil.Encode(tx)) - } - */ } } @@ -335,7 +329,7 @@ func NewUncleBlockFromValue(header *ethutil.Value) *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", block.Hash(), block.PrevHash, block.UncleSha, block.Coinbase, block.state.Root, block.TxSha, block.Difficulty, block.Time, block.Nonce) + 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.Root, block.TxSha, block.Difficulty, block.Time, block.Nonce, len(block.transactions)) } //////////// UNEXPORTED ///////////////// -- cgit From 24f2b2afc3a848190822c382e6aa31c8ab120f07 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 19 Feb 2014 11:35:17 +0100 Subject: Running contracts fixed --- ethchain/block.go | 53 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 9 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 34ddf9fec..ae654b7d8 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -46,6 +46,8 @@ type Block struct { // List of transactions and/or contracts transactions []*Transaction TxSha []byte + + contractStates map[string]*ethutil.Trie } // New block takes a raw encoded string @@ -79,14 +81,15 @@ func CreateBlock(root interface{}, block := &Block{ // Slice of transactions to include in this block - transactions: txes, - PrevHash: prevHash, - Coinbase: base, - Difficulty: Difficulty, - Nonce: Nonce, - Time: time.Now().Unix(), - Extra: extra, - UncleSha: EmptyShaList, + transactions: txes, + PrevHash: prevHash, + Coinbase: base, + Difficulty: Difficulty, + Nonce: Nonce, + Time: time.Now().Unix(), + Extra: extra, + UncleSha: EmptyShaList, + contractStates: make(map[string]*ethutil.Trie), } block.SetTransactions(txes) block.SetUncles([]*Block{}) @@ -131,6 +134,13 @@ func (block *Block) GetContract(addr []byte) *Contract { contract := &Contract{} contract.RlpDecode([]byte(data)) + cachedState := block.contractStates[string(addr)] + if cachedState != nil { + contract.state = cachedState + } else { + block.contractStates[string(addr)] = contract.state + } + return contract } func (block *Block) UpdateContract(addr []byte, contract *Contract) { @@ -190,6 +200,25 @@ func (block *Block) BlockInfo() BlockInfo { return bi } +// Sync the block's state and contract respectively +func (block *Block) Sync() { + // Sync all contracts currently in cache + for _, val := range block.contractStates { + val.Sync() + } + // Sync the block state itself + block.state.Sync() +} + +func (block *Block) Undo() { + // Sync all contracts currently in cache + for _, val := range block.contractStates { + val.Undo() + } + // Sync the block state itself + block.state.Undo() +} + func (block *Block) MakeContract(tx *Transaction) { // Create contract if there's no recipient if tx.IsContract() { @@ -199,9 +228,14 @@ func (block *Block) MakeContract(tx *Transaction) { contract := NewContract(value, []byte("")) block.state.Update(string(addr), string(contract.RlpEncode())) for i, val := range tx.Data { - contract.state.Update(string(ethutil.NumberToBytes(uint64(i), 32)), val) + if len(val) > 0 { + bytNum := ethutil.BigToBytes(big.NewInt(int64(i)), 256) + contract.state.Update(string(bytNum), val) + } } block.UpdateContract(addr, contract) + + block.contractStates[string(addr)] = contract.state } } @@ -288,6 +322,7 @@ func (block *Block) RlpValueDecode(decoder *ethutil.Value) { block.Time = int64(header.Get(6).BigInt().Uint64()) block.Extra = header.Get(7).Str() block.Nonce = header.Get(8).Bytes() + block.contractStates = make(map[string]*ethutil.Trie) // Tx list might be empty if this is an uncle. Uncles only have their // header set. -- cgit From b3da104e569e15c710e6b95ac00c9c2fc80bc9ae Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 19 Feb 2014 16:26:35 +0100 Subject: Corrected contract addresses --- ethchain/block.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index ae654b7d8..0b4f93e8c 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -222,7 +222,7 @@ func (block *Block) Undo() { func (block *Block) MakeContract(tx *Transaction) { // Create contract if there's no recipient if tx.IsContract() { - addr := tx.Hash() + addr := tx.Hash()[12:] value := tx.Value contract := NewContract(value, []byte("")) -- cgit From 95a8ebc2495476c5dbe6c35f30629ca11f660b86 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 24 Feb 2014 12:45:21 +0100 Subject: Changed MakeContract on block MakeContract in Block is now using the MakeContract defined in contract.go --- ethchain/block.go | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 0b4f93e8c..7ad9984be 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -220,23 +220,9 @@ func (block *Block) Undo() { } func (block *Block) MakeContract(tx *Transaction) { - // Create contract if there's no recipient - if tx.IsContract() { - addr := tx.Hash()[12:] - - value := tx.Value - contract := NewContract(value, []byte("")) - block.state.Update(string(addr), string(contract.RlpEncode())) - for i, val := range tx.Data { - if len(val) > 0 { - bytNum := ethutil.BigToBytes(big.NewInt(int64(i)), 256) - contract.state.Update(string(bytNum), val) - } - } - block.UpdateContract(addr, contract) + contract := MakeContract(tx, NewState(block.state)) - block.contractStates[string(addr)] = contract.state - } + block.contractStates[string(tx.Hash()[12:])] = contract.state } /////// Block Encoding -- cgit From 6c7255cde2afdff7710af23c9830835398e6b43d Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 24 Feb 2014 13:15:34 +0100 Subject: Fixed a minor issue on crashed contracts --- ethchain/block.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 7ad9984be..472ae134a 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -221,8 +221,9 @@ func (block *Block) Undo() { func (block *Block) MakeContract(tx *Transaction) { contract := MakeContract(tx, NewState(block.state)) - - block.contractStates[string(tx.Hash()[12:])] = contract.state + if contract != nil { + block.contractStates[string(tx.Hash()[12:])] = contract.state + } } /////// Block Encoding -- cgit From 507fc7b9d1e227de91b25e18891c4cd44452b222 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 25 Feb 2014 11:21:35 +0100 Subject: Length checking when fetching contract. Contract always have 3 fields --- ethchain/block.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 472ae134a..7ca44a47d 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -131,6 +131,11 @@ func (block *Block) GetContract(addr []byte) *Contract { return nil } + value := ethutil.NewValueFromBytes([]byte(data)) + if value.Len() == 2 { + return nil + } + contract := &Contract{} contract.RlpDecode([]byte(data)) -- cgit From d65b4cd0dd49975410374801fae3ece7d7e087b3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 2 Mar 2014 20:42:05 +0100 Subject: Updated block to use state instead of trie directly --- ethchain/block.go | 61 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 27 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 7ca44a47d..8de57cced 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -34,7 +34,8 @@ type Block struct { // The coin base address Coinbase []byte // Block Trie state - state *ethutil.Trie + //state *ethutil.Trie + state *State // Difficulty for the current block Difficulty *big.Int // Creation time @@ -94,7 +95,7 @@ func CreateBlock(root interface{}, block.SetTransactions(txes) block.SetUncles([]*Block{}) - block.state = ethutil.NewTrie(ethutil.Config.Db, root) + block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, root)) for _, tx := range txes { block.MakeContract(tx) @@ -109,15 +110,15 @@ func (block *Block) Hash() []byte { } func (block *Block) HashNoNonce() []byte { - return ethutil.Sha3Bin(ethutil.Encode([]interface{}{block.PrevHash, block.UncleSha, block.Coinbase, block.state.Root, block.TxSha, block.Difficulty, block.Time, block.Extra})) + return ethutil.Sha3Bin(ethutil.Encode([]interface{}{block.PrevHash, block.UncleSha, block.Coinbase, block.state.trie.Root, block.TxSha, block.Difficulty, block.Time, block.Extra})) } func (block *Block) PrintHash() { fmt.Println(block) - fmt.Println(ethutil.NewValue(ethutil.Encode([]interface{}{block.PrevHash, block.UncleSha, block.Coinbase, block.state.Root, block.TxSha, block.Difficulty, block.Time, block.Extra, block.Nonce}))) + fmt.Println(ethutil.NewValue(ethutil.Encode([]interface{}{block.PrevHash, block.UncleSha, block.Coinbase, block.state.trie.Root, block.TxSha, block.Difficulty, block.Time, block.Extra, block.Nonce}))) } -func (block *Block) State() *ethutil.Trie { +func (block *Block) State() *State { return block.state } @@ -125,6 +126,7 @@ func (block *Block) Transactions() []*Transaction { return block.transactions } +/* func (block *Block) GetContract(addr []byte) *Contract { data := block.state.Get(string(addr)) if data == "" { @@ -152,13 +154,13 @@ func (block *Block) UpdateContract(addr []byte, contract *Contract) { // Make sure the state is synced //contract.State().Sync() - block.state.Update(string(addr), string(contract.RlpEncode())) + block.state.trie.Update(string(addr), string(contract.RlpEncode())) } func (block *Block) GetAddr(addr []byte) *Address { var address *Address - data := block.State().Get(string(addr)) + data := block.state.trie.Get(string(addr)) if data == "" { address = NewAddress(big.NewInt(0)) } else { @@ -168,11 +170,12 @@ func (block *Block) GetAddr(addr []byte) *Address { return address } func (block *Block) UpdateAddr(addr []byte, address *Address) { - block.state.Update(string(addr), string(address.RlpEncode())) + block.state.trie.Update(string(addr), string(address.RlpEncode())) } +*/ func (block *Block) PayFee(addr []byte, fee *big.Int) bool { - contract := block.GetContract(addr) + contract := block.state.GetContract(addr) // If we can't pay the fee return if contract == nil || contract.Amount.Cmp(fee) < 0 /* amount < fee */ { fmt.Println("Contract has insufficient funds", contract.Amount, fee) @@ -182,9 +185,9 @@ func (block *Block) PayFee(addr []byte, fee *big.Int) bool { base := new(big.Int) contract.Amount = base.Sub(contract.Amount, fee) - block.state.Update(string(addr), string(contract.RlpEncode())) + block.state.trie.Update(string(addr), string(contract.RlpEncode())) - data := block.state.Get(string(block.Coinbase)) + data := block.state.trie.Get(string(block.Coinbase)) // Get the ether (Coinbase) and add the fee (gief fee to miner) ether := NewAddressFromData([]byte(data)) @@ -192,7 +195,7 @@ func (block *Block) PayFee(addr []byte, fee *big.Int) bool { base = new(big.Int) ether.Amount = base.Add(ether.Amount, fee) - block.state.Update(string(block.Coinbase), string(ether.RlpEncode())) + block.state.trie.Update(string(block.Coinbase), string(ether.RlpEncode())) return true } @@ -207,25 +210,29 @@ func (block *Block) BlockInfo() BlockInfo { // Sync the block's state and contract respectively func (block *Block) Sync() { - // Sync all contracts currently in cache - for _, val := range block.contractStates { - val.Sync() - } + /* + // Sync all contracts currently in cache + for _, val := range block.contractStates { + val.Sync() + } + */ // Sync the block state itself - block.state.Sync() + block.state.trie.Sync() } func (block *Block) Undo() { - // Sync all contracts currently in cache - for _, val := range block.contractStates { - val.Undo() - } + /* + // Sync all contracts currently in cache + for _, val := range block.contractStates { + val.Undo() + } + */ // Sync the block state itself - block.state.Undo() + block.state.Reset() } func (block *Block) MakeContract(tx *Transaction) { - contract := MakeContract(tx, NewState(block.state)) + contract := MakeContract(tx, block.state) if contract != nil { block.contractStates[string(tx.Hash()[12:])] = contract.state } @@ -308,7 +315,7 @@ func (block *Block) RlpValueDecode(decoder *ethutil.Value) { block.PrevHash = header.Get(0).Bytes() block.UncleSha = header.Get(1).Bytes() block.Coinbase = header.Get(2).Bytes() - block.state = ethutil.NewTrie(ethutil.Config.Db, header.Get(3).Val) + 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()) @@ -345,7 +352,7 @@ func NewUncleBlockFromValue(header *ethutil.Value) *Block { block.PrevHash = header.Get(0).Bytes() block.UncleSha = header.Get(1).Bytes() block.Coinbase = header.Get(2).Bytes() - block.state = ethutil.NewTrie(ethutil.Config.Db, header.Get(3).Val) + 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()) @@ -356,7 +363,7 @@ func NewUncleBlockFromValue(header *ethutil.Value) *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.Root, block.TxSha, block.Difficulty, block.Time, block.Nonce, len(block.transactions)) + 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)) } //////////// UNEXPORTED ///////////////// @@ -369,7 +376,7 @@ func (block *Block) header() []interface{} { // Coinbase address block.Coinbase, // root state - block.state.Root, + block.state.trie.Root, // Sha of tx block.TxSha, // Current block Difficulty -- cgit From bfed1c7cac98e135ba176c03bd7b4fe51c0dc932 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 3 Mar 2014 11:03:16 +0100 Subject: Trie's are no longer referenced directly but through State instead --- ethchain/block.go | 65 ++----------------------------------------------------- 1 file changed, 2 insertions(+), 63 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 8de57cced..b5739102c 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -126,54 +126,6 @@ func (block *Block) Transactions() []*Transaction { return block.transactions } -/* -func (block *Block) GetContract(addr []byte) *Contract { - data := block.state.Get(string(addr)) - if data == "" { - return nil - } - - value := ethutil.NewValueFromBytes([]byte(data)) - if value.Len() == 2 { - return nil - } - - contract := &Contract{} - contract.RlpDecode([]byte(data)) - - cachedState := block.contractStates[string(addr)] - if cachedState != nil { - contract.state = cachedState - } else { - block.contractStates[string(addr)] = contract.state - } - - return contract -} -func (block *Block) UpdateContract(addr []byte, contract *Contract) { - // Make sure the state is synced - //contract.State().Sync() - - block.state.trie.Update(string(addr), string(contract.RlpEncode())) -} - -func (block *Block) GetAddr(addr []byte) *Address { - var address *Address - - data := block.state.trie.Get(string(addr)) - if data == "" { - address = NewAddress(big.NewInt(0)) - } else { - address = NewAddressFromData([]byte(data)) - } - - return address -} -func (block *Block) UpdateAddr(addr []byte, address *Address) { - block.state.trie.Update(string(addr), string(address.RlpEncode())) -} -*/ - func (block *Block) PayFee(addr []byte, fee *big.Int) bool { contract := block.state.GetContract(addr) // If we can't pay the fee return @@ -210,23 +162,10 @@ func (block *Block) BlockInfo() BlockInfo { // Sync the block's state and contract respectively func (block *Block) Sync() { - /* - // Sync all contracts currently in cache - for _, val := range block.contractStates { - val.Sync() - } - */ - // Sync the block state itself - block.state.trie.Sync() + block.state.Sync() } func (block *Block) Undo() { - /* - // Sync all contracts currently in cache - for _, val := range block.contractStates { - val.Undo() - } - */ // Sync the block state itself block.state.Reset() } @@ -234,7 +173,7 @@ func (block *Block) Undo() { func (block *Block) MakeContract(tx *Transaction) { contract := MakeContract(tx, block.state) if contract != nil { - block.contractStates[string(tx.Hash()[12:])] = contract.state + block.state.states[string(tx.Hash()[12:])] = contract.state } } -- cgit From 9d492b0509d3614072e0f9ed9fd1dc560ba29fc9 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 3 Mar 2014 11:05:12 +0100 Subject: Renamed Address to Account --- ethchain/block.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index b5739102c..20af73ba2 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -142,7 +142,7 @@ func (block *Block) PayFee(addr []byte, fee *big.Int) bool { data := block.state.trie.Get(string(block.Coinbase)) // Get the ether (Coinbase) and add the fee (gief fee to miner) - ether := NewAddressFromData([]byte(data)) + ether := NewAccountFromData([]byte(data)) base = new(big.Int) ether.Amount = base.Add(ether.Amount, fee) -- cgit From ae837c4719855384921fcaadb1a575942dc9833d Mon Sep 17 00:00:00 2001 From: Maran Date: Thu, 20 Mar 2014 11:20:29 +0100 Subject: More mining rework --- ethchain/block.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 20af73ba2..d42aa7d83 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -304,6 +304,9 @@ func NewUncleBlockFromValue(header *ethutil.Value) *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{} { -- cgit From 7705b23f248156878d00c301fbbadafedaf7e3d2 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 20 Mar 2014 23:17:53 +0100 Subject: Removed caller from tx and added "callership" to account. Transactions can no longer serve as callers. Accounts are now the initial callee of closures. Transactions now serve as transport to call closures. --- ethchain/block.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 20af73ba2..1f63c2c9e 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -142,7 +142,7 @@ func (block *Block) PayFee(addr []byte, fee *big.Int) bool { data := block.state.trie.Get(string(block.Coinbase)) // Get the ether (Coinbase) and add the fee (gief fee to miner) - ether := NewAccountFromData([]byte(data)) + ether := NewAccountFromData(block.Coinbase, []byte(data)) base = new(big.Int) ether.Amount = base.Add(ether.Amount, fee) -- cgit From 9c6aca78933c14ca107da30c4690808950718368 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 16 Apr 2014 04:06:51 +0200 Subject: Merged accounts and contracts in to StateObject * Account removed * Contract removed * Address state changed to CachedStateObject * Added StateObject --- ethchain/block.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 732739c1b..8c93947fb 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -142,12 +142,13 @@ func (block *Block) PayFee(addr []byte, fee *big.Int) bool { data := block.state.trie.Get(string(block.Coinbase)) // Get the ether (Coinbase) and add the fee (gief fee to miner) - ether := NewAccountFromData(block.Coinbase, []byte(data)) + account := NewStateObjectFromBytes(block.Coinbase, []byte(data)) base = new(big.Int) - ether.Amount = base.Add(ether.Amount, fee) + account.Amount = base.Add(account.Amount, fee) - block.state.trie.Update(string(block.Coinbase), string(ether.RlpEncode())) + //block.state.trie.Update(string(block.Coinbase), string(ether.RlpEncode())) + block.state.UpdateStateObject(account) return true } -- cgit From f7d4e3cd6b276e4d66abe89b4f1b2dfa2faf90df Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 23 Apr 2014 15:52:50 +0200 Subject: Copy over bytes from previous root Copy over instead of directly using the previous root. This is order to avoid resetting problems --- ethchain/block.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 8c93947fb..c9197c69a 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -80,6 +80,9 @@ func CreateBlock(root interface{}, extra string, txes []*Transaction) *Block { + // Copy over the bytes + copiedRoot := ethutil.NewValue(root).Bytes() + block := &Block{ // Slice of transactions to include in this block transactions: txes, @@ -95,7 +98,7 @@ func CreateBlock(root interface{}, block.SetTransactions(txes) block.SetUncles([]*Block{}) - block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, root)) + block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, copiedRoot)) for _, tx := range txes { block.MakeContract(tx) -- cgit From f3818478e2601df1d9cfc9cc36b021366f870856 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 24 Apr 2014 13:48:33 +0200 Subject: Removed debug & unused functions --- ethchain/block.go | 25 ------------------------- 1 file changed, 25 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index c9197c69a..d95ebf4b5 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -116,11 +116,6 @@ func (block *Block) HashNoNonce() []byte { return ethutil.Sha3Bin(ethutil.Encode([]interface{}{block.PrevHash, block.UncleSha, block.Coinbase, block.state.trie.Root, block.TxSha, block.Difficulty, block.Time, block.Extra})) } -func (block *Block) PrintHash() { - fmt.Println(block) - fmt.Println(ethutil.NewValue(ethutil.Encode([]interface{}{block.PrevHash, block.UncleSha, block.Coinbase, block.state.trie.Root, block.TxSha, block.Difficulty, block.Time, block.Extra, block.Nonce}))) -} - func (block *Block) State() *State { return block.state } @@ -182,26 +177,6 @@ func (block *Block) MakeContract(tx *Transaction) { } /////// Block Encoding -func (block *Block) encodedUncles() interface{} { - uncles := make([]interface{}, len(block.Uncles)) - for i, uncle := range block.Uncles { - uncles[i] = uncle.RlpEncode() - } - - return uncles -} - -func (block *Block) encodedTxs() interface{} { - // Marshal the transactions of this block - encTx := make([]interface{}, len(block.transactions)) - for i, tx := range block.transactions { - // Cast it to a string (safe) - encTx[i] = tx.RlpData() - } - - return encTx -} - func (block *Block) rlpTxs() interface{} { // Marshal the transactions of this block encTx := make([]interface{}, len(block.transactions)) -- cgit From 38d6b67b5cfbfb63620a244ea01b5b534917128f Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 29 Apr 2014 12:36:27 +0200 Subject: Fixed state problem --- ethchain/block.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index d95ebf4b5..aac50ccb1 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -80,9 +80,6 @@ func CreateBlock(root interface{}, extra string, txes []*Transaction) *Block { - // Copy over the bytes - copiedRoot := ethutil.NewValue(root).Bytes() - block := &Block{ // Slice of transactions to include in this block transactions: txes, @@ -98,7 +95,7 @@ func CreateBlock(root interface{}, block.SetTransactions(txes) block.SetUncles([]*Block{}) - block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, copiedRoot)) + block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, root)) for _, tx := range txes { block.MakeContract(tx) -- cgit From fd19142c0db3d2b6651989f5389944f3e211d84f Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 20 May 2014 11:19:07 +0200 Subject: No longer store script directly in the state tree --- ethchain/block.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index aac50ccb1..ca84dc19c 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -122,7 +122,7 @@ func (block *Block) Transactions() []*Transaction { } func (block *Block) PayFee(addr []byte, fee *big.Int) bool { - contract := block.state.GetContract(addr) + contract := block.state.GetStateObject(addr) // If we can't pay the fee return if contract == nil || contract.Amount.Cmp(fee) < 0 /* amount < fee */ { fmt.Println("Contract has insufficient funds", contract.Amount, fee) -- cgit From 7d3e99a2abcef6011714a7e6e515aa8e2bc738cc Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 20 May 2014 14:29:52 +0200 Subject: Fixed genesis and block data --- ethchain/block.go | 69 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 7 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index ca84dc19c..beb2bc14c 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -40,6 +40,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 @@ -233,9 +241,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,16 +282,51 @@ 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)) + //return fmt.Sprintf("Block(%x):\nPrevHash:%x\nUncleSha:%x\nCoinbase:%x\nRoot:%x\nTxSha:%x\nDiff:%v\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)) + 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) } + func (block *Block) GetRoot() interface{} { return block.state.trie.Root } @@ -299,6 +346,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 -- cgit From 2bd377a3de54652923558b63cc8756531269e36e Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 20 May 2014 15:02:46 +0200 Subject: Changed transaction hash for poc 5 --- ethchain/block.go | 76 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 36 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index beb2bc14c..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" ) @@ -214,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 { @@ -293,45 +299,10 @@ func NewUncleBlockFromValue(header *ethutil.Value) *Block { return block } -func (block *Block) String() string { - //return fmt.Sprintf("Block(%x):\nPrevHash:%x\nUncleSha:%x\nCoinbase:%x\nRoot:%x\nTxSha:%x\nDiff:%v\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)) - 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) -} - func (block *Block) GetRoot() interface{} { return block.state.trie.Root } -//////////// UNEXPORTED ///////////////// func (block *Block) header() []interface{} { return []interface{}{ // Sha of the previous block @@ -362,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) +} -- cgit From ad51c85e5d67ca2e64e95786e79d062c4467b4c1 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 20 May 2014 19:19:53 +0200 Subject: Fixed crash --- ethchain/block.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index c6c2c1226..bdb243286 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -99,6 +99,9 @@ func CreateBlock(root interface{}, Time: time.Now().Unix(), Extra: extra, UncleSha: EmptyShaList, + GasUsed: new(big.Int), + MinGasPrice: new(big.Int), + GasLimit: new(big.Int), contractStates: make(map[string]*ethutil.Trie), } block.SetTransactions(txes) @@ -220,7 +223,7 @@ func (block *Block) SetTransactions(txs []*Transaction) { trie.Update(strconv.Itoa(i), string(tx.RlpEncode())) } - block.TxSha = trie.Root.([]byte) + block.TxSha = []byte(trie.Root.(string)) } func (block *Block) Value() *ethutil.Value { -- cgit From 3b38df085ebebd68f1bf76c11c8b87ae75f29fe2 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 20 May 2014 22:04:47 +0200 Subject: Fixed casting issue --- ethchain/block.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index bdb243286..24ff5a32f 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -223,7 +223,15 @@ func (block *Block) SetTransactions(txs []*Transaction) { trie.Update(strconv.Itoa(i), string(tx.RlpEncode())) } - block.TxSha = []byte(trie.Root.(string)) + switch trie.Root.(type) { + case string: + block.TxSha = []byte(trie.Root.(string)) + case []byte: + block.TxSha = trie.Root.([]byte) + default: + panic(fmt.Sprintf("invalid root type %T", trie.Root)) + } + } func (block *Block) Value() *ethutil.Value { -- cgit From f8f84ef0953534f44c3ce7c9630c569b1059e4bd Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 22 May 2014 00:25:02 +0200 Subject: Removed old contract creation code --- ethchain/block.go | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 24ff5a32f..3401632b1 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -56,8 +56,6 @@ type Block struct { // List of transactions and/or contracts transactions []*Transaction TxSha []byte - - contractStates map[string]*ethutil.Trie } // New block takes a raw encoded string @@ -91,28 +89,23 @@ func CreateBlock(root interface{}, block := &Block{ // Slice of transactions to include in this block - transactions: txes, - PrevHash: prevHash, - Coinbase: base, - Difficulty: Difficulty, - Nonce: Nonce, - Time: time.Now().Unix(), - Extra: extra, - UncleSha: EmptyShaList, - GasUsed: new(big.Int), - MinGasPrice: new(big.Int), - GasLimit: new(big.Int), - contractStates: make(map[string]*ethutil.Trie), + transactions: txes, + PrevHash: prevHash, + Coinbase: base, + Difficulty: Difficulty, + Nonce: Nonce, + Time: time.Now().Unix(), + Extra: extra, + UncleSha: EmptyShaList, + GasUsed: new(big.Int), + MinGasPrice: new(big.Int), + GasLimit: new(big.Int), } block.SetTransactions(txes) block.SetUncles([]*Block{}) block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, root)) - for _, tx := range txes { - block.MakeContract(tx) - } - return block } @@ -178,13 +171,6 @@ func (block *Block) Undo() { block.state.Reset() } -func (block *Block) MakeContract(tx *Transaction) { - contract := MakeContract(tx, block.state) - if contract != nil { - block.state.states[string(tx.Hash()[12:])] = contract.state - } -} - /////// Block Encoding func (block *Block) rlpTxs() interface{} { // Marshal the transactions of this block @@ -265,7 +251,6 @@ func (block *Block) RlpValueDecode(decoder *ethutil.Value) { 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 // header set. -- cgit From 230aafbf66ba747fb3796810adf3b1680f368e73 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 22 May 2014 17:35:26 +0200 Subject: Working on interop * Receipts after each transaction * Fee structure * Applying fees to miners --- ethchain/block.go | 74 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 30 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 3401632b1..c846516f4 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -55,6 +55,7 @@ type Block struct { Nonce []byte // List of transactions and/or contracts transactions []*Transaction + receipts []*Receipt TxSha []byte } @@ -84,24 +85,20 @@ func CreateBlock(root interface{}, base []byte, Difficulty *big.Int, Nonce []byte, - extra string, - txes []*Transaction) *Block { + extra string) *Block { block := &Block{ - // Slice of transactions to include in this block - transactions: txes, - PrevHash: prevHash, - Coinbase: base, - Difficulty: Difficulty, - Nonce: Nonce, - Time: time.Now().Unix(), - Extra: extra, - UncleSha: EmptyShaList, - GasUsed: new(big.Int), - MinGasPrice: new(big.Int), - GasLimit: new(big.Int), + PrevHash: prevHash, + Coinbase: base, + Difficulty: Difficulty, + Nonce: Nonce, + Time: time.Now().Unix(), + Extra: extra, + UncleSha: EmptyShaList, + GasUsed: new(big.Int), + MinGasPrice: new(big.Int), + GasLimit: new(big.Int), } - block.SetTransactions(txes) block.SetUncles([]*Block{}) block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, root)) @@ -115,7 +112,10 @@ func (block *Block) Hash() []byte { } func (block *Block) HashNoNonce() []byte { - return ethutil.Sha3Bin(ethutil.Encode([]interface{}{block.PrevHash, block.UncleSha, block.Coinbase, block.state.trie.Root, block.TxSha, block.Difficulty, block.Time, block.Extra})) + return ethutil.Sha3Bin(ethutil.Encode([]interface{}{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})) } func (block *Block) State() *State { @@ -172,15 +172,15 @@ func (block *Block) Undo() { } /////// Block Encoding -func (block *Block) rlpTxs() interface{} { +func (block *Block) rlpReceipts() interface{} { // Marshal the transactions of this block - encTx := make([]interface{}, len(block.transactions)) - for i, tx := range block.transactions { + encR := make([]interface{}, len(block.receipts)) + for i, r := range block.receipts { // Cast it to a string (safe) - encTx[i] = tx.RlpData() + encR[i] = r.RlpData() } - return encTx + return encR } func (block *Block) rlpUncles() interface{} { @@ -201,7 +201,12 @@ func (block *Block) SetUncles(uncles []*Block) { block.UncleSha = ethutil.Sha3Bin(ethutil.Encode(block.rlpUncles())) } -func (block *Block) SetTransactions(txs []*Transaction) { +func (self *Block) SetReceipts(receipts []*Receipt, txs []*Transaction) { + self.receipts = receipts + self.setTransactions(txs) +} + +func (block *Block) setTransactions(txs []*Transaction) { block.transactions = txs trie := ethutil.NewTrie(ethutil.Config.Db, "") @@ -221,7 +226,7 @@ func (block *Block) SetTransactions(txs []*Transaction) { } func (block *Block) Value() *ethutil.Value { - return ethutil.NewValue([]interface{}{block.header(), block.rlpTxs(), block.rlpUncles()}) + return ethutil.NewValue([]interface{}{block.header(), block.rlpReceipts(), block.rlpUncles()}) } func (block *Block) RlpEncode() []byte { @@ -245,6 +250,7 @@ func (block *Block) RlpValueDecode(decoder *ethutil.Value) { block.TxSha = header.Get(4).Bytes() block.Difficulty = header.Get(5).BigInt() block.Number = header.Get(6).BigInt() + //fmt.Printf("#%v : %x\n", block.Number, block.Coinbase) block.MinGasPrice = header.Get(7).BigInt() block.GasLimit = header.Get(8).BigInt() block.GasUsed = header.Get(9).BigInt() @@ -255,12 +261,13 @@ func (block *Block) RlpValueDecode(decoder *ethutil.Value) { // Tx list might be empty if this is an uncle. Uncles only have their // header set. if decoder.Get(1).IsNil() == false { // Yes explicitness - txes := decoder.Get(1) - block.transactions = make([]*Transaction, txes.Len()) - for i := 0; i < txes.Len(); i++ { - tx := NewTransactionFromValue(txes.Get(i)) - - block.transactions[i] = tx + receipts := decoder.Get(1) + block.transactions = make([]*Transaction, receipts.Len()) + block.receipts = make([]*Receipt, receipts.Len()) + for i := 0; i < receipts.Len(); i++ { + receipt := NewRecieptFromValue(receipts.Get(i)) + block.transactions[i] = receipt.Tx + block.receipts[i] = receipt } } @@ -299,6 +306,10 @@ func (block *Block) GetRoot() interface{} { return block.state.trie.Root } +func (self *Block) Receipts() []*Receipt { + return self.receipts +} + func (block *Block) header() []interface{} { return []interface{}{ // Sha of the previous block @@ -346,6 +357,7 @@ func (block *Block) String() string { Time: %v Extra: %v Nonce: %x + NumTx: %v `, block.Hash(), block.PrevHash, @@ -360,5 +372,7 @@ func (block *Block) String() string { block.GasUsed, block.Time, block.Extra, - block.Nonce) + block.Nonce, + len(block.transactions), + ) } -- cgit From cc8464ce805279735f637ac710b25e2fb264f9aa Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 22 May 2014 17:56:33 +0200 Subject: Transaction querying --- ethchain/block.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index c846516f4..73e29f878 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -1,6 +1,7 @@ package ethchain import ( + "bytes" "fmt" "github.com/ethereum/eth-go/ethutil" "math/big" @@ -161,6 +162,16 @@ func (block *Block) BlockInfo() BlockInfo { return bi } +func (self *Block) GetTransaction(hash []byte) *Transaction { + for _, receipt := range self.receipts { + if bytes.Compare(receipt.Tx.Hash(), hash) == 0 { + return receipt.Tx + } + } + + return nil +} + // Sync the block's state and contract respectively func (block *Block) Sync() { block.state.Sync() -- cgit From 753f749423df7d5fba55a4080383d215db8e0fc7 Mon Sep 17 00:00:00 2001 From: Maran Date: Tue, 10 Jun 2014 17:22:06 +0200 Subject: Implement CalcGasPrice for ethereum/go-ethereum#77 --- ethchain/block.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 73e29f878..780c60869 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -154,6 +154,35 @@ func (block *Block) PayFee(addr []byte, fee *big.Int) bool { return true } +func (block *Block) CalcGasLimit(parent *Block) *big.Int { + if block.Number == big.NewInt(0) { + return ethutil.BigPow(10, 6) + } + previous := new(big.Int).Mul(big.NewInt(1023), parent.GasLimit) + current := new(big.Rat).Mul(new(big.Rat).SetInt(block.GasUsed), big.NewRat(6, 5)) + curInt := new(big.Int).Div(current.Num(), current.Denom()) + + result := new(big.Int).Add(previous, curInt) + result.Div(result, big.NewInt(1024)) + + min := ethutil.BigPow(10, 4) + + return ethutil.BigMax(min, result) + /* + 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)) + */ + +} + func (block *Block) BlockInfo() BlockInfo { bi := BlockInfo{} data, _ := ethutil.Config.Db.Get(append(block.Hash(), []byte("Info")...)) -- cgit From 1938bfcddfd2722880a692c59cad344b611711c8 Mon Sep 17 00:00:00 2001 From: Maran Date: Wed, 11 Jun 2014 16:16:57 +0200 Subject: Fix compare --- ethchain/block.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 780c60869..fee4a2d59 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -155,9 +155,10 @@ func (block *Block) PayFee(addr []byte, fee *big.Int) bool { } func (block *Block) CalcGasLimit(parent *Block) *big.Int { - if block.Number == big.NewInt(0) { + if block.Number.Cmp(big.NewInt(0)) == 0 { return ethutil.BigPow(10, 6) } + previous := new(big.Int).Mul(big.NewInt(1023), parent.GasLimit) current := new(big.Rat).Mul(new(big.Rat).SetInt(block.GasUsed), big.NewRat(6, 5)) curInt := new(big.Int).Div(current.Num(), current.Denom()) -- cgit From dabaa4cce01586fd8b1b9314073a1d26f35355c8 Mon Sep 17 00:00:00 2001 From: zelig Date: Sun, 29 Jun 2014 18:30:05 +0100 Subject: change all modified calls to ethtrie, ethutil and ethcrypto functions --- ethchain/block.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index fee4a2d59..ed5b754f8 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -3,6 +3,8 @@ package ethchain import ( "bytes" "fmt" + "github.com/ethereum/eth-go/ethcrypto" + "github.com/ethereum/eth-go/ethtrie" "github.com/ethereum/eth-go/ethutil" "math/big" "strconv" @@ -102,18 +104,18 @@ func CreateBlock(root interface{}, } block.SetUncles([]*Block{}) - block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, root)) + block.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, root)) return block } // Returns a hash of the block func (block *Block) Hash() []byte { - return ethutil.Sha3Bin(block.Value().Encode()) + return ethcrypto.Sha3Bin(block.Value().Encode()) } func (block *Block) HashNoNonce() []byte { - return ethutil.Sha3Bin(ethutil.Encode([]interface{}{block.PrevHash, + return ethcrypto.Sha3Bin(ethutil.Encode([]interface{}{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})) @@ -239,7 +241,7 @@ func (block *Block) SetUncles(uncles []*Block) { block.Uncles = uncles // Sha of the concatenated uncles - block.UncleSha = ethutil.Sha3Bin(ethutil.Encode(block.rlpUncles())) + block.UncleSha = ethcrypto.Sha3Bin(ethutil.Encode(block.rlpUncles())) } func (self *Block) SetReceipts(receipts []*Receipt, txs []*Transaction) { @@ -250,7 +252,7 @@ func (self *Block) SetReceipts(receipts []*Receipt, txs []*Transaction) { func (block *Block) setTransactions(txs []*Transaction) { block.transactions = txs - trie := ethutil.NewTrie(ethutil.Config.Db, "") + trie := ethtrie.NewTrie(ethutil.Config.Db, "") for i, tx := range txs { trie.Update(strconv.Itoa(i), string(tx.RlpEncode())) } @@ -287,7 +289,7 @@ func (block *Block) RlpValueDecode(decoder *ethutil.Value) { block.PrevHash = header.Get(0).Bytes() block.UncleSha = header.Get(1).Bytes() block.Coinbase = header.Get(2).Bytes() - block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, header.Get(3).Val)) + block.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, header.Get(3).Val)) block.TxSha = header.Get(4).Bytes() block.Difficulty = header.Get(5).BigInt() block.Number = header.Get(6).BigInt() @@ -329,7 +331,7 @@ func NewUncleBlockFromValue(header *ethutil.Value) *Block { block.PrevHash = header.Get(0).Bytes() block.UncleSha = header.Get(1).Bytes() block.Coinbase = header.Get(2).Bytes() - block.state = NewState(ethutil.NewTrie(ethutil.Config.Db, header.Get(3).Val)) + block.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, header.Get(3).Val)) block.TxSha = header.Get(4).Bytes() block.Difficulty = header.Get(5).BigInt() block.Number = header.Get(6).BigInt() -- cgit From e798294a4b2049dc59df6ad4a3bc67c00916cb9f Mon Sep 17 00:00:00 2001 From: Maran Date: Tue, 1 Jul 2014 15:25:57 +0200 Subject: Update min GasLimit --- ethchain/block.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index fee4a2d59..1be8282fa 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -166,7 +166,7 @@ func (block *Block) CalcGasLimit(parent *Block) *big.Int { result := new(big.Int).Add(previous, curInt) result.Div(result, big.NewInt(1024)) - min := ethutil.BigPow(10, 4) + min := big.NewInt(125000) return ethutil.BigMax(min, result) /* -- cgit From 5d2669dbd35b9449cbbb249dcec89e2a64c90f30 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 21 Jul 2014 12:21:34 +0200 Subject: Fixed tx sha creation --- ethchain/block.go | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index a0f9ecd86..447d55f99 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -7,7 +7,7 @@ import ( "github.com/ethereum/eth-go/ethtrie" "github.com/ethereum/eth-go/ethutil" "math/big" - "strconv" + _ "strconv" "time" ) @@ -252,20 +252,43 @@ func (self *Block) SetReceipts(receipts []*Receipt, txs []*Transaction) { func (block *Block) setTransactions(txs []*Transaction) { block.transactions = txs + /* + trie := ethtrie.NewTrie(ethutil.Config.Db, "") + for i, tx := range txs { + trie.Update(strconv.Itoa(i), string(tx.RlpEncode())) + } + + switch trie.Root.(type) { + case string: + block.TxSha = []byte(trie.Root.(string)) + case []byte: + block.TxSha = trie.Root.([]byte) + default: + panic(fmt.Sprintf("invalid root type %T", trie.Root)) + } + */ +} + +func CreateTxSha(receipts Receipts) (sha []byte) { trie := ethtrie.NewTrie(ethutil.Config.Db, "") - for i, tx := range txs { - trie.Update(strconv.Itoa(i), string(tx.RlpEncode())) + for i, receipt := range receipts { + trie.Update(string(ethutil.NewValue(i).Encode()), string(ethutil.NewValue(receipt.RlpData()).Encode())) } switch trie.Root.(type) { case string: - block.TxSha = []byte(trie.Root.(string)) + sha = []byte(trie.Root.(string)) case []byte: - block.TxSha = trie.Root.([]byte) + sha = trie.Root.([]byte) default: panic(fmt.Sprintf("invalid root type %T", trie.Root)) } + return sha +} + +func (self *Block) SetTxHash(receipts Receipts) { + self.TxSha = CreateTxSha(receipts) } func (block *Block) Value() *ethutil.Value { -- cgit From 32d125131f602d63f66ee7eb09439074f0b94a91 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 24 Jul 2014 12:04:15 +0200 Subject: Refactored to new state and vm --- ethchain/block.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 447d55f99..437525e35 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "github.com/ethereum/eth-go/ethcrypto" + "github.com/ethereum/eth-go/ethstate" "github.com/ethereum/eth-go/ethtrie" "github.com/ethereum/eth-go/ethutil" "math/big" @@ -39,7 +40,7 @@ type Block struct { Coinbase []byte // Block Trie state //state *ethutil.Trie - state *State + state *ethstate.State // Difficulty for the current block Difficulty *big.Int // Creation time @@ -104,7 +105,7 @@ func CreateBlock(root interface{}, } block.SetUncles([]*Block{}) - block.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, root)) + block.state = ethstate.NewState(ethtrie.NewTrie(ethutil.Config.Db, root)) return block } @@ -116,12 +117,12 @@ func (block *Block) Hash() []byte { func (block *Block) HashNoNonce() []byte { return ethcrypto.Sha3Bin(ethutil.Encode([]interface{}{block.PrevHash, - block.UncleSha, block.Coinbase, block.state.trie.Root, + block.UncleSha, block.Coinbase, block.state.Trie.Root, block.TxSha, block.Difficulty, block.Number, block.MinGasPrice, block.GasLimit, block.GasUsed, block.Time, block.Extra})) } -func (block *Block) State() *State { +func (block *Block) State() *ethstate.State { return block.state } @@ -140,17 +141,17 @@ func (block *Block) PayFee(addr []byte, fee *big.Int) bool { base := new(big.Int) contract.Amount = base.Sub(contract.Amount, fee) - block.state.trie.Update(string(addr), string(contract.RlpEncode())) + block.state.Trie.Update(string(addr), string(contract.RlpEncode())) - data := block.state.trie.Get(string(block.Coinbase)) + data := block.state.Trie.Get(string(block.Coinbase)) // Get the ether (Coinbase) and add the fee (gief fee to miner) - account := NewStateObjectFromBytes(block.Coinbase, []byte(data)) + account := ethstate.NewStateObjectFromBytes(block.Coinbase, []byte(data)) base = new(big.Int) account.Amount = base.Add(account.Amount, fee) - //block.state.trie.Update(string(block.Coinbase), string(ether.RlpEncode())) + //block.state.Trie.Update(string(block.Coinbase), string(ether.RlpEncode())) block.state.UpdateStateObject(account) return true @@ -312,7 +313,7 @@ func (block *Block) RlpValueDecode(decoder *ethutil.Value) { block.PrevHash = header.Get(0).Bytes() block.UncleSha = header.Get(1).Bytes() block.Coinbase = header.Get(2).Bytes() - block.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, header.Get(3).Val)) + block.state = ethstate.NewState(ethtrie.NewTrie(ethutil.Config.Db, header.Get(3).Val)) block.TxSha = header.Get(4).Bytes() block.Difficulty = header.Get(5).BigInt() block.Number = header.Get(6).BigInt() @@ -354,7 +355,7 @@ func NewUncleBlockFromValue(header *ethutil.Value) *Block { block.PrevHash = header.Get(0).Bytes() block.UncleSha = header.Get(1).Bytes() block.Coinbase = header.Get(2).Bytes() - block.state = NewState(ethtrie.NewTrie(ethutil.Config.Db, header.Get(3).Val)) + block.state = ethstate.NewState(ethtrie.NewTrie(ethutil.Config.Db, header.Get(3).Val)) block.TxSha = header.Get(4).Bytes() block.Difficulty = header.Get(5).BigInt() block.Number = header.Get(6).BigInt() @@ -369,7 +370,7 @@ func NewUncleBlockFromValue(header *ethutil.Value) *Block { } func (block *Block) GetRoot() interface{} { - return block.state.trie.Root + return block.state.Trie.Root } func (self *Block) Receipts() []*Receipt { @@ -385,7 +386,7 @@ func (block *Block) header() []interface{} { // Coinbase address block.Coinbase, // root state - block.state.trie.Root, + block.state.Trie.Root, // Sha of tx block.TxSha, // Current block Difficulty @@ -429,7 +430,7 @@ func (block *Block) String() string { block.PrevHash, block.UncleSha, block.Coinbase, - block.state.trie.Root, + block.state.Trie.Root, block.TxSha, block.Difficulty, block.Number, -- cgit From 41bd38147c2e5968283facf641b2444c09f53d14 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 26 Jul 2014 11:24:44 +0200 Subject: Clean up and util methods --- ethchain/block.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 437525e35..e00bcb24f 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -3,13 +3,14 @@ package ethchain import ( "bytes" "fmt" + "math/big" + _ "strconv" + "time" + "github.com/ethereum/eth-go/ethcrypto" "github.com/ethereum/eth-go/ethstate" "github.com/ethereum/eth-go/ethtrie" "github.com/ethereum/eth-go/ethutil" - "math/big" - _ "strconv" - "time" ) type BlockInfo struct { @@ -63,12 +64,6 @@ type Block struct { TxSha []byte } -// New block takes a raw encoded string -// XXX DEPRICATED -func NewBlockFromData(raw []byte) *Block { - return NewBlockFromBytes(raw) -} - func NewBlockFromBytes(raw []byte) *Block { block := &Block{} block.RlpDecode(raw) -- cgit From 1f9894c0845a5259adbfd30fe3a86631e6403b8d Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 30 Jul 2014 00:31:15 +0200 Subject: Old code removed and renamed amount to balance --- ethchain/block.go | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index e00bcb24f..ac56f58c3 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -125,33 +125,6 @@ func (block *Block) Transactions() []*Transaction { return block.transactions } -func (block *Block) PayFee(addr []byte, fee *big.Int) bool { - contract := block.state.GetStateObject(addr) - // If we can't pay the fee return - if contract == nil || contract.Amount.Cmp(fee) < 0 /* amount < fee */ { - fmt.Println("Contract has insufficient funds", contract.Amount, fee) - - return false - } - - base := new(big.Int) - contract.Amount = base.Sub(contract.Amount, fee) - block.state.Trie.Update(string(addr), string(contract.RlpEncode())) - - data := block.state.Trie.Get(string(block.Coinbase)) - - // Get the ether (Coinbase) and add the fee (gief fee to miner) - account := ethstate.NewStateObjectFromBytes(block.Coinbase, []byte(data)) - - base = new(big.Int) - account.Amount = base.Add(account.Amount, fee) - - //block.state.Trie.Update(string(block.Coinbase), string(ether.RlpEncode())) - block.state.UpdateStateObject(account) - - return true -} - func (block *Block) CalcGasLimit(parent *Block) *big.Int { if block.Number.Cmp(big.NewInt(0)) == 0 { return ethutil.BigPow(10, 6) -- cgit From 3debeb7236d2c8474fa9049cc91dc26bf1040b3f Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 4 Aug 2014 10:38:18 +0200 Subject: ethtrie.NewTrie => ethtrie.New --- ethchain/block.go | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index ac56f58c3..e4486f8e4 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -100,7 +100,7 @@ func CreateBlock(root interface{}, } block.SetUncles([]*Block{}) - block.state = ethstate.NewState(ethtrie.NewTrie(ethutil.Config.Db, root)) + block.state = ethstate.NewState(ethtrie.New(ethutil.Config.Db, root)) return block } @@ -220,26 +220,10 @@ func (self *Block) SetReceipts(receipts []*Receipt, txs []*Transaction) { func (block *Block) setTransactions(txs []*Transaction) { block.transactions = txs - - /* - trie := ethtrie.NewTrie(ethutil.Config.Db, "") - for i, tx := range txs { - trie.Update(strconv.Itoa(i), string(tx.RlpEncode())) - } - - switch trie.Root.(type) { - case string: - block.TxSha = []byte(trie.Root.(string)) - case []byte: - block.TxSha = trie.Root.([]byte) - default: - panic(fmt.Sprintf("invalid root type %T", trie.Root)) - } - */ } func CreateTxSha(receipts Receipts) (sha []byte) { - trie := ethtrie.NewTrie(ethutil.Config.Db, "") + trie := ethtrie.New(ethutil.Config.Db, "") for i, receipt := range receipts { trie.Update(string(ethutil.NewValue(i).Encode()), string(ethutil.NewValue(receipt.RlpData()).Encode())) } @@ -281,7 +265,7 @@ func (block *Block) RlpValueDecode(decoder *ethutil.Value) { block.PrevHash = header.Get(0).Bytes() block.UncleSha = header.Get(1).Bytes() block.Coinbase = header.Get(2).Bytes() - block.state = ethstate.NewState(ethtrie.NewTrie(ethutil.Config.Db, header.Get(3).Val)) + block.state = ethstate.NewState(ethtrie.New(ethutil.Config.Db, header.Get(3).Val)) block.TxSha = header.Get(4).Bytes() block.Difficulty = header.Get(5).BigInt() block.Number = header.Get(6).BigInt() @@ -323,7 +307,7 @@ func NewUncleBlockFromValue(header *ethutil.Value) *Block { block.PrevHash = header.Get(0).Bytes() block.UncleSha = header.Get(1).Bytes() block.Coinbase = header.Get(2).Bytes() - block.state = ethstate.NewState(ethtrie.NewTrie(ethutil.Config.Db, header.Get(3).Val)) + block.state = ethstate.NewState(ethtrie.New(ethutil.Config.Db, header.Get(3).Val)) block.TxSha = header.Get(4).Bytes() block.Difficulty = header.Get(5).BigInt() block.Number = header.Get(6).BigInt() -- cgit From 03ce15df4c7ef51d4373233ab5c3766282b31771 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 4 Aug 2014 10:42:40 +0200 Subject: ethstate.NewState => ethstate.New --- ethchain/block.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index e4486f8e4..321af6183 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -100,7 +100,7 @@ func CreateBlock(root interface{}, } block.SetUncles([]*Block{}) - block.state = ethstate.NewState(ethtrie.New(ethutil.Config.Db, root)) + block.state = ethstate.New(ethtrie.New(ethutil.Config.Db, root)) return block } @@ -265,7 +265,7 @@ func (block *Block) RlpValueDecode(decoder *ethutil.Value) { block.PrevHash = header.Get(0).Bytes() block.UncleSha = header.Get(1).Bytes() block.Coinbase = header.Get(2).Bytes() - block.state = ethstate.NewState(ethtrie.New(ethutil.Config.Db, header.Get(3).Val)) + block.state = ethstate.New(ethtrie.New(ethutil.Config.Db, header.Get(3).Val)) block.TxSha = header.Get(4).Bytes() block.Difficulty = header.Get(5).BigInt() block.Number = header.Get(6).BigInt() @@ -307,7 +307,7 @@ func NewUncleBlockFromValue(header *ethutil.Value) *Block { block.PrevHash = header.Get(0).Bytes() block.UncleSha = header.Get(1).Bytes() block.Coinbase = header.Get(2).Bytes() - block.state = ethstate.NewState(ethtrie.New(ethutil.Config.Db, header.Get(3).Val)) + block.state = ethstate.New(ethtrie.New(ethutil.Config.Db, header.Get(3).Val)) block.TxSha = header.Get(4).Bytes() block.Difficulty = header.Get(5).BigInt() block.Number = header.Get(6).BigInt() -- cgit From 27290e12772f4a354cfdc6383222597f66cefa21 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 9 Aug 2014 18:06:16 +0100 Subject: Fixed gas limit calculation --- ethchain/block.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 321af6183..5b06fd58d 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -130,8 +130,10 @@ func (block *Block) CalcGasLimit(parent *Block) *big.Int { return ethutil.BigPow(10, 6) } - previous := new(big.Int).Mul(big.NewInt(1023), parent.GasLimit) - current := new(big.Rat).Mul(new(big.Rat).SetInt(block.GasUsed), big.NewRat(6, 5)) + // ((1024-1) * parent.gasLimit + (gasUsed * 6 / 5)) / 1024 + + previous := new(big.Int).Mul(big.NewInt(1024-1), parent.GasLimit) + current := new(big.Rat).Mul(new(big.Rat).SetInt(parent.GasUsed), big.NewRat(6, 5)) curInt := new(big.Int).Div(current.Num(), current.Denom()) result := new(big.Int).Add(previous, curInt) -- cgit From a760ce05b948e89bc564af20599dcf95698ac0eb Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 11 Aug 2014 16:23:38 +0200 Subject: Updated chain for filtering --- ethchain/block.go | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 5b06fd58d..5765abd51 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -142,19 +142,6 @@ func (block *Block) CalcGasLimit(parent *Block) *big.Int { min := big.NewInt(125000) return ethutil.BigMax(min, result) - /* - 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)) - */ - } func (block *Block) BlockInfo() BlockInfo { -- cgit From 6afc16399f9624663579ad72950b4ea3b887db57 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 25 Aug 2014 12:53:06 +0200 Subject: Block size --- ethchain/block.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 5765abd51..d2d012e55 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -351,7 +351,7 @@ func (block *Block) header() []interface{} { func (block *Block) String() string { return fmt.Sprintf(` - BLOCK(%x): + BLOCK(%x): Size: %v PrevHash: %x UncleSha: %x Coinbase: %x @@ -368,6 +368,7 @@ func (block *Block) String() string { NumTx: %v `, block.Hash(), + block.Size(), block.PrevHash, block.UncleSha, block.Coinbase, @@ -384,3 +385,7 @@ func (block *Block) String() string { len(block.transactions), ) } + +func (self *Block) Size() ethutil.StorageSize { + return ethutil.StorageSize(len(self.RlpEncode())) +} -- cgit From 2f614900e82036e3e8f6f6a714efc43e09aca830 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 15 Sep 2014 01:11:01 +0200 Subject: Updated GHOST --- ethchain/block.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index d2d012e55..fde6ff04a 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -31,11 +31,22 @@ func (bi *BlockInfo) RlpEncode() []byte { return ethutil.Encode([]interface{}{bi.Number, bi.Hash, bi.Parent}) } +type Blocks []*Block + +func (self Blocks) AsSet() ethutil.UniqueSet { + set := make(ethutil.UniqueSet) + for _, block := range self { + set.Insert(block.Hash()) + } + + return set +} + type Block struct { // Hash to the previous block PrevHash []byte // Uncles of this block - Uncles []*Block + Uncles Blocks UncleSha []byte // The coin base address Coinbase []byte -- cgit From 33a0dec8a157b9687ca6038f4deb011f3f1f7bdc Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 15 Sep 2014 15:42:12 +0200 Subject: Improved catching up and refactored --- ethchain/block.go | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index fde6ff04a..157be2a52 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "math/big" + "sort" _ "strconv" "time" @@ -42,9 +43,32 @@ func (self Blocks) AsSet() ethutil.UniqueSet { return set } +type BlockBy func(b1, b2 *Block) bool + +func (self BlockBy) Sort(blocks Blocks) { + bs := blockSorter{ + blocks: blocks, + by: self, + } + sort.Sort(bs) +} + +type blockSorter struct { + blocks Blocks + by func(b1, b2 *Block) bool +} + +func (self blockSorter) Len() int { return len(self.blocks) } +func (self blockSorter) Swap(i, j int) { + self.blocks[i], self.blocks[j] = self.blocks[j], self.blocks[i] +} +func (self blockSorter) Less(i, j int) bool { return self.by(self.blocks[i], self.blocks[j]) } + +func Number(b1, b2 *Block) bool { return b1.Number.Cmp(b2.Number) < 0 } + type Block struct { // Hash to the previous block - PrevHash []byte + PrevHash ethutil.Bytes // Uncles of this block Uncles Blocks UncleSha []byte @@ -68,7 +92,7 @@ type Block struct { // Extra data Extra string // Block Nonce for verification - Nonce []byte + Nonce ethutil.Bytes // List of transactions and/or contracts transactions []*Transaction receipts []*Receipt @@ -117,8 +141,9 @@ func CreateBlock(root interface{}, } // Returns a hash of the block -func (block *Block) Hash() []byte { - return ethcrypto.Sha3Bin(block.Value().Encode()) +func (block *Block) Hash() ethutil.Bytes { + return ethcrypto.Sha3Bin(ethutil.NewValue(block.header()).Encode()) + //return ethcrypto.Sha3Bin(block.Value().Encode()) } func (block *Block) HashNoNonce() []byte { -- cgit From 57dc435f9b928f5de2a49736a2c71a7bf611289a Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 24 Sep 2014 11:39:17 +0200 Subject: Added TD for each block --- ethchain/block.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 157be2a52..5e8aca33a 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -18,6 +18,7 @@ type BlockInfo struct { Number uint64 Hash []byte Parent []byte + TD *big.Int } func (bi *BlockInfo) RlpDecode(data []byte) { @@ -26,10 +27,11 @@ func (bi *BlockInfo) RlpDecode(data []byte) { bi.Number = decoder.Get(0).Uint() bi.Hash = decoder.Get(1).Bytes() bi.Parent = decoder.Get(2).Bytes() + bi.TD = decoder.Get(3).BigInt() } func (bi *BlockInfo) RlpEncode() []byte { - return ethutil.Encode([]interface{}{bi.Number, bi.Hash, bi.Parent}) + return ethutil.Encode([]interface{}{bi.Number, bi.Hash, bi.Parent, bi.TD}) } type Blocks []*Block -- cgit From 9d86a49a7327199c01977f3372c8adf748252c32 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 8 Oct 2014 12:06:39 +0200 Subject: Renamed Sha3Bin to Sha3 --- ethchain/block.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 5e8aca33a..d6ff5ef7e 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -144,12 +144,12 @@ func CreateBlock(root interface{}, // Returns a hash of the block func (block *Block) Hash() ethutil.Bytes { - return ethcrypto.Sha3Bin(ethutil.NewValue(block.header()).Encode()) - //return ethcrypto.Sha3Bin(block.Value().Encode()) + return ethcrypto.Sha3(ethutil.NewValue(block.header()).Encode()) + //return ethcrypto.Sha3(block.Value().Encode()) } func (block *Block) HashNoNonce() []byte { - return ethcrypto.Sha3Bin(ethutil.Encode([]interface{}{block.PrevHash, + return ethcrypto.Sha3(ethutil.Encode([]interface{}{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})) @@ -237,7 +237,7 @@ func (block *Block) SetUncles(uncles []*Block) { block.Uncles = uncles // Sha of the concatenated uncles - block.UncleSha = ethcrypto.Sha3Bin(ethutil.Encode(block.rlpUncles())) + block.UncleSha = ethcrypto.Sha3(ethutil.Encode(block.rlpUncles())) } func (self *Block) SetReceipts(receipts []*Receipt, txs []*Transaction) { -- cgit From 56843ca0fca1886213be4ee1e25995a537afda57 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 10 Oct 2014 22:42:37 +0200 Subject: Added some methods to comply to the PoW block interface --- ethchain/block.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index d6ff5ef7e..72dc5b55a 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -348,10 +348,18 @@ func NewUncleBlockFromValue(header *ethutil.Value) *Block { return block } +func (block *Block) Trie() *ethrie.Trie { + return block.state.Trie +} + func (block *Block) GetRoot() interface{} { return block.state.Trie.Root } +func (block *Block) Diff() *big.Int { + return block.Difficulty +} + func (self *Block) Receipts() []*Receipt { return self.receipts } -- cgit From 2e894b668a2bde3eb83418cfd9128f3a571e0026 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 11 Oct 2014 00:41:37 +0200 Subject: Max callstack --- ethchain/block.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 72dc5b55a..0fb01ea5b 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -348,7 +348,7 @@ func NewUncleBlockFromValue(header *ethutil.Value) *Block { return block } -func (block *Block) Trie() *ethrie.Trie { +func (block *Block) Trie() *ethtrie.Trie { return block.state.Trie } -- cgit From 520fdfe346ab51708f4f1fdfd0b2e42cc919e613 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 21 Oct 2014 13:25:31 +0200 Subject: PoC7 Net --- ethchain/block.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index 0fb01ea5b..fc7c6b13f 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -130,7 +130,7 @@ func CreateBlock(root interface{}, Nonce: Nonce, Time: time.Now().Unix(), Extra: extra, - UncleSha: EmptyShaList, + UncleSha: EmptyShaList, //nil, GasUsed: new(big.Int), MinGasPrice: new(big.Int), GasLimit: new(big.Int), @@ -237,7 +237,9 @@ func (block *Block) SetUncles(uncles []*Block) { block.Uncles = uncles // Sha of the concatenated uncles - block.UncleSha = ethcrypto.Sha3(ethutil.Encode(block.rlpUncles())) + //if len(uncles) > 0 { + // block.UncleSha = ethcrypto.Sha3(ethutil.Encode(block.rlpUncles())) + //} } func (self *Block) SetReceipts(receipts []*Receipt, txs []*Transaction) { -- cgit From 6b92d541dabc289043529f65e586e40c4613e7f8 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 21 Oct 2014 13:30:23 +0200 Subject: Empty string for uncle --- ethchain/block.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'ethchain/block.go') diff --git a/ethchain/block.go b/ethchain/block.go index fc7c6b13f..951bd8de3 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -130,7 +130,7 @@ func CreateBlock(root interface{}, Nonce: Nonce, Time: time.Now().Unix(), Extra: extra, - UncleSha: EmptyShaList, //nil, + UncleSha: nil, GasUsed: new(big.Int), MinGasPrice: new(big.Int), GasLimit: new(big.Int), @@ -237,9 +237,9 @@ func (block *Block) SetUncles(uncles []*Block) { block.Uncles = uncles // Sha of the concatenated uncles - //if len(uncles) > 0 { - // block.UncleSha = ethcrypto.Sha3(ethutil.Encode(block.rlpUncles())) - //} + if len(uncles) > 0 { + block.UncleSha = ethcrypto.Sha3(ethutil.Encode(block.rlpUncles())) + } } func (self *Block) SetReceipts(receipts []*Receipt, txs []*Transaction) { -- cgit