Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
5a0bae1d
Commit
5a0bae1d
authored
May 08, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auto update state changes notifications
parent
e8fb965c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
51 deletions
+18
-51
closure.go
ethchain/closure.go
+3
-3
state.go
ethchain/state.go
+4
-31
state_manager.go
ethchain/state_manager.go
+7
-8
state_object.go
ethchain/state_object.go
+1
-1
vm.go
ethchain/vm.go
+3
-8
No files found.
ethchain/closure.go
View file @
5a0bae1d
...
...
@@ -11,7 +11,7 @@ type ClosureRef interface {
ReturnGas
(
*
big
.
Int
,
*
big
.
Int
,
*
State
)
Address
()
[]
byte
GetMem
(
*
big
.
Int
)
*
ethutil
.
Value
Set
Mem
(
*
big
.
Int
,
*
ethutil
.
Value
)
Set
Store
(
*
big
.
Int
,
*
ethutil
.
Value
)
N
()
*
big
.
Int
}
...
...
@@ -64,8 +64,8 @@ func (c *Closure) Gets(x, y *big.Int) *ethutil.Value {
return
ethutil
.
NewValue
(
partial
)
}
func
(
c
*
Closure
)
Set
Mem
(
x
*
big
.
Int
,
val
*
ethutil
.
Value
)
{
c
.
object
.
Set
Mem
(
x
,
val
)
func
(
c
*
Closure
)
Set
Storage
(
x
*
big
.
Int
,
val
*
ethutil
.
Value
)
{
c
.
object
.
Set
Storage
(
x
,
val
)
}
func
(
c
*
Closure
)
Address
()
[]
byte
{
...
...
ethchain/state.go
View file @
5a0bae1d
...
...
@@ -15,11 +15,13 @@ type State struct {
trie
*
ethutil
.
Trie
// Nested states
states
map
[
string
]
*
State
manifest
*
Manifest
}
// Create a new state from a given trie
func
NewState
(
trie
*
ethutil
.
Trie
)
*
State
{
return
&
State
{
trie
:
trie
,
states
:
make
(
map
[
string
]
*
State
)}
return
&
State
{
trie
:
trie
,
states
:
make
(
map
[
string
]
*
State
)
,
manifest
:
NewManifest
()
}
}
// Resets the trie and all siblings
...
...
@@ -124,36 +126,6 @@ const (
UnknownTy
)
/*
// Returns the object stored at key and the type stored at key
// Returns nil if nothing is stored
func (s *State) GetStateObject(key []byte) (*ethutil.Value, ObjType) {
// Fetch data from the trie
data := s.trie.Get(string(key))
// Returns the nil type, indicating nothing could be retrieved.
// Anything using this function should check for this ret val
if data == "" {
return nil, NilTy
}
var typ ObjType
val := ethutil.NewValueFromBytes([]byte(data))
// Check the length of the retrieved value.
// Len 2 = Account
// Len 3 = Contract
// Other = invalid for now. If other types emerge, add them here
if val.Len() == 2 {
typ = AccountTy
} else if val.Len() == 3 {
typ = ContractTy
} else {
typ = UnknownTy
}
return val, typ
}
*/
// Updates any given state object
func
(
s
*
State
)
UpdateStateObject
(
object
*
StateObject
)
{
addr
:=
object
.
Address
()
...
...
@@ -163,6 +135,7 @@ func (s *State) UpdateStateObject(object *StateObject) {
}
s
.
trie
.
Update
(
string
(
addr
),
string
(
object
.
RlpEncode
()))
s
.
manifest
.
AddObjectChange
(
object
)
}
func
(
s
*
State
)
Put
(
key
,
object
[]
byte
)
{
...
...
ethchain/state_manager.go
View file @
5a0bae1d
...
...
@@ -47,7 +47,9 @@ type StateManager struct {
// the main states.
transState
*
State
// Manifest for keeping changes regarding state objects. See `notify`
manifest
*
Manifest
// XXX Should we move the manifest to the State object. Benefit:
// * All states can keep their own local changes
//manifest *Manifest
}
func
NewStateManager
(
ethereum
EthManager
)
*
StateManager
{
...
...
@@ -57,7 +59,7 @@ func NewStateManager(ethereum EthManager) *StateManager {
Pow
:
&
EasyPow
{},
Ethereum
:
ethereum
,
bc
:
ethereum
.
BlockChain
(),
manifest
:
NewManifest
(),
//
manifest: NewManifest(),
}
sm
.
procState
=
ethereum
.
BlockChain
()
.
CurrentBlock
.
State
()
sm
.
transState
=
sm
.
procState
.
Copy
()
...
...
@@ -190,7 +192,7 @@ func (sm *StateManager) ProcessBlock(block *Block, dontReact bool) error {
sm
.
notifyChanges
()
sm
.
manifest
.
Reset
()
sm
.
procState
.
manifest
.
Reset
()
}
}
else
{
fmt
.
Println
(
"total diff failed"
)
...
...
@@ -315,18 +317,15 @@ func (sm *StateManager) EvalScript(script []byte, object *StateObject, tx *Trans
// Update the account (refunds)
sm
.
procState
.
UpdateStateObject
(
account
)
sm
.
manifest
.
AddObjectChange
(
account
)
sm
.
procState
.
UpdateStateObject
(
object
)
sm
.
manifest
.
AddObjectChange
(
object
)
}
func
(
sm
*
StateManager
)
notifyChanges
()
{
for
addr
,
stateObject
:=
range
sm
.
manifest
.
objectChanges
{
for
addr
,
stateObject
:=
range
sm
.
procState
.
manifest
.
objectChanges
{
sm
.
Ethereum
.
Reactor
()
.
Post
(
"object:"
+
addr
,
stateObject
)
}
for
stateObjectAddr
,
mappedObjects
:=
range
sm
.
manifest
.
storageChanges
{
for
stateObjectAddr
,
mappedObjects
:=
range
sm
.
procState
.
manifest
.
storageChanges
{
for
addr
,
value
:=
range
mappedObjects
{
sm
.
Ethereum
.
Reactor
()
.
Post
(
"storage:"
+
stateObjectAddr
+
":"
+
addr
,
&
StorageState
{[]
byte
(
stateObjectAddr
),
[]
byte
(
addr
),
value
})
}
...
...
ethchain/state_object.go
View file @
5a0bae1d
...
...
@@ -77,7 +77,7 @@ func (c *StateObject) SetAddr(addr []byte, value interface{}) {
c
.
state
.
trie
.
Update
(
string
(
addr
),
string
(
ethutil
.
NewValue
(
value
)
.
Encode
()))
}
func
(
c
*
StateObject
)
Set
Mem
(
num
*
big
.
Int
,
val
*
ethutil
.
Value
)
{
func
(
c
*
StateObject
)
Set
Storage
(
num
*
big
.
Int
,
val
*
ethutil
.
Value
)
{
addr
:=
ethutil
.
BigToBytes
(
num
,
256
)
c
.
SetAddr
(
addr
,
val
)
}
...
...
ethchain/vm.go
View file @
5a0bae1d
...
...
@@ -395,10 +395,10 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
case
oSSTORE
:
require
(
2
)
val
,
loc
:=
stack
.
Popn
()
closure
.
Set
Mem
(
loc
,
ethutil
.
NewValue
(
val
))
closure
.
Set
Storage
(
loc
,
ethutil
.
NewValue
(
val
))
// Add the change to manifest
vm
.
state
Manager
.
manifest
.
AddStorageChange
(
closure
.
Object
(),
loc
.
Bytes
(),
val
)
vm
.
state
.
manifest
.
AddStorageChange
(
closure
.
Object
(),
loc
.
Bytes
(),
val
)
case
oJUMP
:
require
(
1
)
pc
=
stack
.
Pop
()
...
...
@@ -473,7 +473,6 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
// Fetch the contract which will serve as the closure body
contract
:=
vm
.
state
.
GetContract
(
addr
.
Bytes
())
fmt
.
Println
(
"before"
,
contract
.
Amount
)
if
contract
!=
nil
{
// Prepay for the gas
...
...
@@ -497,12 +496,9 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
//contract.State().Reset()
}
else
{
stack
.
Push
(
ethutil
.
BigTrue
)
// Notify of the changes
vm
.
stateManager
.
manifest
.
AddObjectChange
(
contract
)
}
vm
.
state
.
SetStateObject
(
contract
)
fmt
.
Println
(
"after"
,
contract
.
Amount
)
mem
.
Set
(
retOffset
.
Int64
(),
retSize
.
Int64
(),
ret
)
}
else
{
...
...
@@ -520,8 +516,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
receiver
:=
vm
.
state
.
GetAccount
(
stack
.
Pop
()
.
Bytes
())
receiver
.
AddAmount
(
closure
.
object
.
Amount
)
vm
.
stateManager
.
manifest
.
AddObjectChange
(
receiver
)
vm
.
state
.
SetStateObject
(
receiver
)
closure
.
object
.
state
.
Purge
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment