Commit c331571a authored by George Hotz's avatar George Hotz

state transition

parent 3ecdafb0
package state package state
import ( import (
"fmt"
"math/big" "math/big"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
...@@ -81,18 +82,22 @@ type SimpleTrie struct { ...@@ -81,18 +82,22 @@ type SimpleTrie struct {
} }
func (trie SimpleTrie) Commit(onleaf LeafCallback) (common.Hash, error) { func (trie SimpleTrie) Commit(onleaf LeafCallback) (common.Hash, error) {
fmt.Println("trie.Commit")
return trie.Root, nil return trie.Root, nil
} }
func (trie SimpleTrie) Hash() common.Hash { func (trie SimpleTrie) Hash() common.Hash {
fmt.Println("trie.Hash")
return trie.Root return trie.Root
} }
func (trie SimpleTrie) TryUpdate(key, value []byte) error { func (trie SimpleTrie) TryUpdate(key, value []byte) error {
fmt.Println("trie.TryUpdate")
return nil return nil
} }
func (trie SimpleTrie) TryDelete(key []byte) error { func (trie SimpleTrie) TryDelete(key []byte) error {
fmt.Println("trie.TryDelete")
return nil return nil
} }
......
...@@ -859,14 +859,14 @@ func (s *StateDB) clearJournalAndRefund() { ...@@ -859,14 +859,14 @@ func (s *StateDB) clearJournalAndRefund() {
// Commit writes the state to the underlying in-memory trie database. // Commit writes the state to the underlying in-memory trie database.
func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) { func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) {
/*if s.dbErr != nil { if s.dbErr != nil {
return common.Hash{}, fmt.Errorf("commit aborted due to earlier error: %v", s.dbErr) return common.Hash{}, fmt.Errorf("commit aborted due to earlier error: %v", s.dbErr)
} }
// Finalize any pending changes and merge everything into the tries // Finalize any pending changes and merge everything into the tries
s.IntermediateRoot(deleteEmptyObjects) s.IntermediateRoot(deleteEmptyObjects)
// Commit objects to the trie, measuring the elapsed time // Commit objects to the trie, measuring the elapsed time
codeWriter := s.db.TrieDB().DiskDB().NewBatch() /*codeWriter := s.db.TrieDB().DiskDB().NewBatch()
for addr := range s.stateObjectsDirty { for addr := range s.stateObjectsDirty {
if obj := s.stateObjects[addr]; !obj.deleted { if obj := s.stateObjects[addr]; !obj.deleted {
// Write any contract code associated with the state object // Write any contract code associated with the state object
...@@ -887,7 +887,8 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) { ...@@ -887,7 +887,8 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) {
if err := codeWriter.Write(); err != nil { if err := codeWriter.Write(); err != nil {
log.Crit("Failed to commit dirty codes", "error", err) log.Crit("Failed to commit dirty codes", "error", err)
} }
} }*/
// Write the account trie changes, measuing the amount of wasted time // Write the account trie changes, measuing the amount of wasted time
var start time.Time var start time.Time
if metrics.EnabledExpensive { if metrics.EnabledExpensive {
...@@ -900,16 +901,16 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) { ...@@ -900,16 +901,16 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) {
if err := rlp.DecodeBytes(leaf, &account); err != nil { if err := rlp.DecodeBytes(leaf, &account); err != nil {
return nil return nil
} }
if account.Root != emptyRoot { /*if account.Root != emptyRoot {
s.db.TrieDB().Reference(account.Root, parent) s.db.TrieDB().Reference(account.Root, parent)
} }*/
return nil return nil
}) })
if metrics.EnabledExpensive { if metrics.EnabledExpensive {
s.AccountCommits += time.Since(start) s.AccountCommits += time.Since(start)
} }
// If snapshotting is enabled, update the snapshot tree with this new version // If snapshotting is enabled, update the snapshot tree with this new version
if s.snap != nil { /*if s.snap != nil {
if metrics.EnabledExpensive { if metrics.EnabledExpensive {
defer func(start time.Time) { s.SnapshotCommits += time.Since(start) }(time.Now()) defer func(start time.Time) { s.SnapshotCommits += time.Since(start) }(time.Now())
} }
...@@ -927,10 +928,9 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) { ...@@ -927,10 +928,9 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) {
} }
} }
s.snap, s.snapDestructs, s.snapAccounts, s.snapStorage = nil, nil, nil, nil s.snap, s.snapDestructs, s.snapAccounts, s.snapStorage = nil, nil, nil, nil
} }*/
return root, err*/
fmt.Println("Commit doesn't work!!!") fmt.Println("Commit doesn't work!!!")
return common.Hash{}, nil return root, err
} }
// PrepareAccessList handles the preparatory steps for executing a state transition with // PrepareAccessList handles the preparatory steps for executing a state transition with
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment