Commit 26559b6a authored by George Hotz's avatar George Hotz

more storage

parent ef668f73
D1޴h4K S/$GҠ,$Y㇨ngUn c
\ No newline at end of file
D+Syǐ3
'ǃEX'?BҰ,znnFg
\ No newline at end of file
D+Aq:y6Ų\[ߴ*1͕ ͂ݿQ΍T)ng @VVoψdEF
\ No newline at end of file
D Sp[@39g6&j:<` <Ȩ)j-jڍru
\ No newline at end of file
D閵uOO0llO9e\tkx/֎+Tp
\ No newline at end of file
DLg^CzDo>4-p"7A9JI9dI'$XZ
Tq
\ No newline at end of file
DVUEn[Hlb/c!f\fόX[`bP# 1
\ No newline at end of file
DYZ:}"vn$Oꉃ!Q`q9龠^1_y}myR'C6VWm'\2
\ No newline at end of file
DElDZfj35[7s).1ͭ쎢[9JI9dI'$XZ
Tq
\ No newline at end of file
DvWw,p(}K0ـ yz3A uT|g_SMW"
\ No newline at end of file
DV%IMlOMb}Z8Ovzp/d?"Ά^/ )
\ No newline at end of file
DL `>.<p9+{a+cƮ3@HϵY`ֆ/pLºː
\ No newline at end of file
DGS!&c~g^F jc#o0Y##U\
9Tji[I\r~
\ No newline at end of file
Deq GBpp~d{IU9JI9dI'$XZ
Tq
\ No newline at end of file
DVUEn[Hlb/c!uR ȳq~Jun'
ɺVa
\ No newline at end of file
DH$@ *Pcd"
턝V
StC(r)&܆17,zuz6$
\ No newline at end of file
D[,S{[ 8}[}߮14XiXL 9(/AF>
\ No newline at end of file
D
o<<ʶ}#//EQqPʠ[k.c(Ұf*Xa
\ No newline at end of file
Dډ=:yvlsbtt^>`fhm20`Y//
\ No newline at end of file
Dj;(4U&㟮xFr\xtm"FW)v
\ No newline at end of file
Dd"WSD2Yg2"
oRLBhz!.௠H΂f
\ No newline at end of file
Dwz˅dZ^6f~f9iuo!蠩ltz=~ _i`R=Z hĀ
\ No newline at end of file
D5p
ø*f tkx/֎+Tp
\ No newline at end of file
D>OFPFAȜE?]`Ԝ0#@Bn;kWaʐ4KVZua
\ No newline at end of file
DK,Eo$9bJh~MG1>Jà4BRlZV+]$~-?k
\ No newline at end of file
Dxץ¢ڴ`T? sfE{tuzoRLBhz!.௠H΂f
\ No newline at end of file
DdAl_)z+s;]zlRGj'kC{R Gߛ 9@.
\ No newline at end of file
D'y\nj64JgVsL B`M HL@
\ No newline at end of file
DVUEn[Hlb/c!d
ԙ\V}R"Q`)n
\ No newline at end of file
De>`
3)&#NŸ1gd 7KyȮ{9>S&^2
Le8A=p
\ No newline at end of file
DE#
,3 n?l8vLmշijbtkx/֎+Tp
\ No newline at end of file
汰"ツ1mv 署ロキ$ゞ/a,K:fq"ケd箱Br躪#うヨスbqサケ モョ9PN」ィ0
\ No newline at end of file
D`;g?Pį)U!Y^QO8`ʠ ٶVG(wLTXg'-
\ No newline at end of file
D|FI퇞IGe=v,T:17ѠDQ!Œ& 8G=Ph:F
\ No newline at end of file
DVUEn[Hlb/c!! h1uإ%M 
\ No newline at end of file
......@@ -21,5 +21,5 @@ type Account struct {
// TODO: oracle for
// GetProvedAccountBytes(blockNumber, stateRoot, addr) -> rlpAccount
// GetProvedCodeBytes(blockNumber, addr, codehash) -> []byte
// GetProvedStorage(blockNumber, addr, root, key) -> uint256
// GetProvedStorage(blockNumber, addr, root, key) -> common.Hash
// These functions access the backend oracle, and will assert if the proof is bad
......@@ -328,3 +328,41 @@ func (s *stateObject) GetCommittedState(db Database, key common.Hash) common.Has
s.originStorage[key] = value
return value
}
// SetState updates a value in account storage.
func (s *stateObject) SetState(db Database, key, value common.Hash) {
// If the fake storage is set, put the temporary state update here.
if s.fakeStorage != nil {
s.fakeStorage[key] = value
return
}
// If the new value is the same as old, don't set
prev := s.GetState(db, key)
if prev == value {
return
}
// New value is different, update and journal the change
s.setState(key, value)
}
// SetStorage replaces the entire state storage with the given one.
//
// After this function is called, all original state will be ignored and state
// lookup only happens in the fake state storage.
//
// Note this function should only be used for debugging purpose.
func (s *stateObject) SetStorage(storage map[common.Hash]common.Hash) {
// Allocate fake storage if it's nil.
if s.fakeStorage == nil {
s.fakeStorage = make(Storage)
}
for key, value := range storage {
s.fakeStorage[key] = value
}
// Don't bother journal since this function should only be used for
// debugging and the `fake` storage won't be committed to database.
}
func (s *stateObject) setState(key, value common.Hash) {
s.dirtyStorage[key] = value
}
......@@ -6,6 +6,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/oracle"
"github.com/ethereum/go-ethereum/rlp"
......@@ -144,14 +145,77 @@ func (s *StateDB) GetState(addr common.Address, hash common.Hash) common.Hash {
func (s *StateDB) AddAddressToAccessList(addr common.Address) {
}
/*
* SETTERS
*/
// AddBalance adds amount to the account associated with addr.
func (s *StateDB) AddBalance(addr common.Address, amount *big.Int) {
fmt.Println("AddBalance", addr, amount)
stateObject := s.GetOrNewStateObject(addr)
if stateObject != nil {
stateObject.AddBalance(amount)
}
}
// SubBalance subtracts amount from the account associated with addr.
func (s *StateDB) SubBalance(addr common.Address, amount *big.Int) {
fmt.Println("SubBalance", addr, amount)
stateObject := s.GetOrNewStateObject(addr)
if stateObject != nil {
stateObject.SubBalance(amount)
}
}
func (s *StateDB) SetBalance(addr common.Address, amount *big.Int) {
stateObject := s.GetOrNewStateObject(addr)
if stateObject != nil {
stateObject.SetBalance(amount)
}
}
func (s *StateDB) SetNonce(addr common.Address, nonce uint64) {
stateObject := s.GetOrNewStateObject(addr)
if stateObject != nil {
stateObject.SetNonce(nonce)
}
}
func (s *StateDB) SetCode(addr common.Address, code []byte) {
stateObject := s.GetOrNewStateObject(addr)
if stateObject != nil {
stateObject.SetCode(crypto.Keccak256Hash(code), code)
}
}
func (s *StateDB) SetState(addr common.Address, key, value common.Hash) {
stateObject := s.GetOrNewStateObject(addr)
if stateObject != nil {
stateObject.SetState(s.db, key, value)
}
}
// SetStorage replaces the entire storage for the specified account with given
// storage. This function should only be used for debugging.
func (s *StateDB) SetStorage(addr common.Address, storage map[common.Hash]common.Hash) {
stateObject := s.GetOrNewStateObject(addr)
if stateObject != nil {
stateObject.SetStorage(storage)
}
}
// Suicide marks the given account as suicided.
// This clears the account balance.
//
// The account's state object is still available until the state is committed,
// getStateObject will return a non-nil account after Suicide.
func (s *StateDB) Suicide(addr common.Address) bool {
stateObject := s.getStateObject(addr)
if stateObject == nil {
return false
}
stateObject.markSuicided()
stateObject.data.Balance = new(big.Int)
return true
}
// IntermediateRoot computes the current root hash of the state trie.
......@@ -204,7 +268,11 @@ func (db *StateDB) ForEachStorage(addr common.Address, cb func(key, value common
// GetCommittedState retrieves a value from the given account's committed storage trie.
func (s *StateDB) GetCommittedState(addr common.Address, hash common.Hash) common.Hash {
fmt.Println("GetCommittedState", addr, hash)
// TODO: this is wrong
stateObject := s.getStateObject(addr)
if stateObject != nil {
return stateObject.GetState(s.db, hash)
}
return common.Hash{}
}
......@@ -214,11 +282,6 @@ func (s *StateDB) GetRefund() uint64 {
return 0
}
func (s *StateDB) Suicide(addr common.Address) bool {
fmt.Println("Suicide", addr)
return true
}
func (s *StateDB) HasSuicided(addr common.Address) bool {
fmt.Println("HasSuicided", addr)
return false
......@@ -231,22 +294,6 @@ func (s *StateDB) PrepareAccessList(sender common.Address, dst *common.Address,
func (s *StateDB) RevertToSnapshot(revid int) {
}
func (s *StateDB) SetCode(addr common.Address, code []byte) {
fmt.Println("SetCode", addr, code)
}
func (s *StateDB) SetNonce(addr common.Address, nonce uint64) {
fmt.Println("SetNonce", addr, nonce)
stateObject := s.GetOrNewStateObject(addr)
if stateObject != nil {
stateObject.SetNonce(nonce)
}
}
func (s *StateDB) SetState(addr common.Address, key, value common.Hash) {
fmt.Println("SetState", addr, key)
}
// SlotInAccessList returns true if the given (address, slot)-tuple is in the access list.
func (s *StateDB) SlotInAccessList(addr common.Address, slot common.Hash) (addressPresent bool, slotPresent bool) {
return true, true
......@@ -287,7 +334,7 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject {
return obj
}
fmt.Println("getDeletedStateObject:", addr)
//fmt.Println("getDeletedStateObject:", addr)
// If snapshot unavailable or reading from it failed, load from the database
/*enc, err := s.trie.TryGet(addr.Bytes())
if err != nil {
......
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