Refactored to new state and vm
This commit is contained in:
@@ -17,7 +17,7 @@ var statelogger = ethlog.NewLogger("STATE")
|
||||
// * Accounts
|
||||
type State struct {
|
||||
// The trie for this structure
|
||||
trie *ethtrie.Trie
|
||||
Trie *ethtrie.Trie
|
||||
|
||||
stateObjects map[string]*StateObject
|
||||
|
||||
@@ -26,7 +26,7 @@ type State struct {
|
||||
|
||||
// Create a new state from a given trie
|
||||
func NewState(trie *ethtrie.Trie) *State {
|
||||
return &State{trie: trie, stateObjects: make(map[string]*StateObject), manifest: NewManifest()}
|
||||
return &State{Trie: trie, stateObjects: make(map[string]*StateObject), manifest: NewManifest()}
|
||||
}
|
||||
|
||||
// Retrieve the balance from the given address or 0 if object not found
|
||||
@@ -58,14 +58,14 @@ func (self *State) UpdateStateObject(stateObject *StateObject) {
|
||||
|
||||
ethutil.Config.Db.Put(ethcrypto.Sha3Bin(stateObject.Code), stateObject.Code)
|
||||
|
||||
self.trie.Update(string(addr), string(stateObject.RlpEncode()))
|
||||
self.Trie.Update(string(addr), string(stateObject.RlpEncode()))
|
||||
|
||||
self.manifest.AddObjectChange(stateObject)
|
||||
}
|
||||
|
||||
// Delete the given state object and delete it from the state trie
|
||||
func (self *State) DeleteStateObject(stateObject *StateObject) {
|
||||
self.trie.Delete(string(stateObject.Address()))
|
||||
self.Trie.Delete(string(stateObject.Address()))
|
||||
|
||||
delete(self.stateObjects, string(stateObject.Address()))
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func (self *State) GetStateObject(addr []byte) *StateObject {
|
||||
return stateObject
|
||||
}
|
||||
|
||||
data := self.trie.Get(string(addr))
|
||||
data := self.Trie.Get(string(addr))
|
||||
if len(data) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -122,12 +122,12 @@ func (self *State) GetAccount(addr []byte) *StateObject {
|
||||
//
|
||||
|
||||
func (s *State) Cmp(other *State) bool {
|
||||
return s.trie.Cmp(other.trie)
|
||||
return s.Trie.Cmp(other.Trie)
|
||||
}
|
||||
|
||||
func (self *State) Copy() *State {
|
||||
if self.trie != nil {
|
||||
state := NewState(self.trie.Copy())
|
||||
if self.Trie != nil {
|
||||
state := NewState(self.Trie.Copy())
|
||||
for k, stateObject := range self.stateObjects {
|
||||
state.stateObjects[k] = stateObject.Copy()
|
||||
}
|
||||
@@ -143,21 +143,21 @@ func (self *State) Set(state *State) {
|
||||
panic("Tried setting 'state' to nil through 'Set'")
|
||||
}
|
||||
|
||||
self.trie = state.trie
|
||||
self.Trie = state.Trie
|
||||
self.stateObjects = state.stateObjects
|
||||
}
|
||||
|
||||
func (s *State) Root() interface{} {
|
||||
return s.trie.Root
|
||||
return s.Trie.Root
|
||||
}
|
||||
|
||||
// Resets the trie and all siblings
|
||||
func (s *State) Reset() {
|
||||
s.trie.Undo()
|
||||
s.Trie.Undo()
|
||||
|
||||
// Reset all nested states
|
||||
for _, stateObject := range s.stateObjects {
|
||||
if stateObject.state == nil {
|
||||
if stateObject.State == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -174,14 +174,14 @@ func (s *State) Sync() {
|
||||
for _, stateObject := range s.stateObjects {
|
||||
//s.UpdateStateObject(stateObject)
|
||||
|
||||
if stateObject.state == nil {
|
||||
if stateObject.State == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
stateObject.state.Sync()
|
||||
stateObject.State.Sync()
|
||||
}
|
||||
|
||||
s.trie.Sync()
|
||||
s.Trie.Sync()
|
||||
|
||||
s.Empty()
|
||||
}
|
||||
@@ -202,11 +202,11 @@ func (self *State) Update() {
|
||||
}
|
||||
|
||||
// FIXME trie delete is broken
|
||||
valid, t2 := ethtrie.ParanoiaCheck(self.trie)
|
||||
valid, t2 := ethtrie.ParanoiaCheck(self.Trie)
|
||||
if !valid {
|
||||
statelogger.Infof("Warn: PARANOIA: Different state root during copy %x vs %x\n", self.trie.Root, t2.Root)
|
||||
statelogger.Infof("Warn: PARANOIA: Different state root during copy %x vs %x\n", self.Trie.Root, t2.Root)
|
||||
|
||||
self.trie = t2
|
||||
self.Trie = t2
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,8 +230,8 @@ type Manifest struct {
|
||||
objectAddresses map[string]bool
|
||||
storageAddresses map[string]map[string]bool
|
||||
|
||||
objectChanges map[string]*StateObject
|
||||
storageChanges map[string]map[string]*big.Int
|
||||
ObjectChanges map[string]*StateObject
|
||||
StorageChanges map[string]map[string]*big.Int
|
||||
}
|
||||
|
||||
func NewManifest() *Manifest {
|
||||
@@ -242,18 +242,18 @@ func NewManifest() *Manifest {
|
||||
}
|
||||
|
||||
func (m *Manifest) Reset() {
|
||||
m.objectChanges = make(map[string]*StateObject)
|
||||
m.storageChanges = make(map[string]map[string]*big.Int)
|
||||
m.ObjectChanges = make(map[string]*StateObject)
|
||||
m.StorageChanges = make(map[string]map[string]*big.Int)
|
||||
}
|
||||
|
||||
func (m *Manifest) AddObjectChange(stateObject *StateObject) {
|
||||
m.objectChanges[string(stateObject.Address())] = stateObject
|
||||
m.ObjectChanges[string(stateObject.Address())] = stateObject
|
||||
}
|
||||
|
||||
func (m *Manifest) AddStorageChange(stateObject *StateObject, storageAddr []byte, storage *big.Int) {
|
||||
if m.storageChanges[string(stateObject.Address())] == nil {
|
||||
m.storageChanges[string(stateObject.Address())] = make(map[string]*big.Int)
|
||||
if m.StorageChanges[string(stateObject.Address())] == nil {
|
||||
m.StorageChanges[string(stateObject.Address())] = make(map[string]*big.Int)
|
||||
}
|
||||
|
||||
m.storageChanges[string(stateObject.Address())][string(storageAddr)] = storage
|
||||
m.StorageChanges[string(stateObject.Address())][string(storageAddr)] = storage
|
||||
}
|
||||
|
Reference in New Issue
Block a user