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
3ebd7f11
Commit
3ebd7f11
authored
May 25, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
State snapshotting
parent
81ef4001
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
8 deletions
+80
-8
state.go
ethchain/state.go
+15
-1
state_object.go
ethchain/state_object.go
+6
-1
state_test.go
ethchain/state_test.go
+31
-0
vm.go
ethchain/vm.go
+13
-4
trie_test.go
ethutil/trie_test.go
+15
-2
No files found.
ethchain/state.go
View file @
3ebd7f11
...
...
@@ -99,7 +99,21 @@ func (s *State) Cmp(other *State) bool {
}
func
(
s
*
State
)
Copy
()
*
State
{
return
NewState
(
s
.
trie
.
Copy
())
state
:=
NewState
(
s
.
trie
.
Copy
())
for
k
,
subState
:=
range
s
.
states
{
state
.
states
[
k
]
=
subState
.
Copy
()
}
return
state
}
func
(
s
*
State
)
Snapshot
()
*
State
{
return
s
.
Copy
()
}
func
(
s
*
State
)
Revert
(
snapshot
*
State
)
{
s
.
trie
=
snapshot
.
trie
s
.
states
=
snapshot
.
states
}
func
(
s
*
State
)
Put
(
key
,
object
[]
byte
)
{
...
...
ethchain/state_object.go
View file @
3ebd7f11
...
...
@@ -81,12 +81,17 @@ func (c *StateObject) SetStorage(num *big.Int, val *ethutil.Value) {
c
.
SetAddr
(
addr
,
val
)
}
func
(
c
*
StateObject
)
Get
Mem
(
num
*
big
.
Int
)
*
ethutil
.
Value
{
func
(
c
*
StateObject
)
Get
Storage
(
num
*
big
.
Int
)
*
ethutil
.
Value
{
nb
:=
ethutil
.
BigToBytes
(
num
,
256
)
return
c
.
Addr
(
nb
)
}
/* DEPRECATED */
func
(
c
*
StateObject
)
GetMem
(
num
*
big
.
Int
)
*
ethutil
.
Value
{
return
c
.
GetStorage
(
num
)
}
func
(
c
*
StateObject
)
GetInstr
(
pc
*
big
.
Int
)
*
ethutil
.
Value
{
if
int64
(
len
(
c
.
script
)
-
1
)
<
pc
.
Int64
()
{
return
ethutil
.
NewValue
(
0
)
...
...
ethchain/state_test.go
0 → 100644
View file @
3ebd7f11
package
ethchain
import
(
"fmt"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethutil"
"testing"
)
func
TestSnapshot
(
t
*
testing
.
T
)
{
ethutil
.
ReadConfig
(
""
,
ethutil
.
LogStd
,
""
)
db
,
_
:=
ethdb
.
NewMemDatabase
()
state
:=
NewState
(
ethutil
.
NewTrie
(
db
,
""
))
stateObject
:=
NewContract
([]
byte
(
"aa"
),
ethutil
.
Big1
,
ZeroHash256
)
state
.
UpdateStateObject
(
stateObject
)
stateObject
.
SetStorage
(
ethutil
.
Big
(
"0"
),
ethutil
.
NewValue
(
42
))
snapshot
:=
state
.
Snapshot
()
stateObject
=
state
.
GetStateObject
([]
byte
(
"aa"
))
stateObject
.
SetStorage
(
ethutil
.
Big
(
"0"
),
ethutil
.
NewValue
(
43
))
state
.
Revert
(
snapshot
)
stateObject
=
state
.
GetStateObject
([]
byte
(
"aa"
))
if
!
stateObject
.
GetStorage
(
ethutil
.
Big
(
"0"
))
.
Cmp
(
ethutil
.
NewValue
(
42
))
{
t
.
Error
(
"Expected storage 0 to be 42"
)
}
}
ethchain/vm.go
View file @
3ebd7f11
...
...
@@ -426,6 +426,10 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
value
:=
stack
.
Pop
()
size
,
offset
:=
stack
.
Popn
()
// Snapshot the current stack so we are able to
// revert back to it later.
snapshot
:=
vm
.
state
.
Snapshot
()
// Generate a new address
addr
:=
ethutil
.
CreateAddress
(
closure
.
callee
.
Address
(),
closure
.
callee
.
N
())
// Create a new contract
...
...
@@ -448,6 +452,9 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
closure
.
Script
,
err
=
closure
.
Call
(
vm
,
nil
,
hook
)
if
err
!=
nil
{
stack
.
Push
(
ethutil
.
BigFalse
)
// Revert the state as it was before.
vm
.
state
.
Revert
(
snapshot
)
}
else
{
stack
.
Push
(
ethutil
.
BigD
(
addr
))
...
...
@@ -473,6 +480,8 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
// Get the arguments from the memory
args
:=
mem
.
Get
(
inOffset
.
Int64
(),
inSize
.
Int64
())
snapshot
:=
vm
.
state
.
Snapshot
()
// Fetch the contract which will serve as the closure body
contract
:=
vm
.
state
.
GetStateObject
(
addr
.
Bytes
())
...
...
@@ -495,14 +504,14 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
if
err
!=
nil
{
stack
.
Push
(
ethutil
.
BigFalse
)
// Reset the changes applied this object
//contract.State().Reset(
)
vm
.
state
.
Revert
(
snapshot
)
}
else
{
stack
.
Push
(
ethutil
.
BigTrue
)
}
vm
.
state
.
UpdateStateObject
(
contract
)
vm
.
state
.
UpdateStateObject
(
contract
)
mem
.
Set
(
retOffset
.
Int64
(),
retSize
.
Int64
(),
ret
)
mem
.
Set
(
retOffset
.
Int64
(),
retSize
.
Int64
(),
ret
)
}
}
else
{
ethutil
.
Config
.
Log
.
Debugf
(
"Contract %x not found
\n
"
,
addr
.
Bytes
())
stack
.
Push
(
ethutil
.
BigFalse
)
...
...
ethutil/trie_test.go
View file @
3ebd7f11
package
ethutil
import
(
_
"fmt"
"fmt"
"reflect"
"testing"
)
...
...
@@ -26,7 +26,6 @@ func (db *MemDatabase) Delete(key []byte) error {
delete
(
db
.
db
,
string
(
key
))
return
nil
}
func
(
db
*
MemDatabase
)
GetKeys
()
[]
*
Key
{
return
nil
}
func
(
db
*
MemDatabase
)
Print
()
{}
func
(
db
*
MemDatabase
)
Close
()
{}
func
(
db
*
MemDatabase
)
LastKnownTD
()
[]
byte
{
return
nil
}
...
...
@@ -171,3 +170,17 @@ func TestTrieIterator(t *testing.T) {
t
.
Errorf
(
"Expected cached nodes to be deleted"
)
}
}
func
TestHashes
(
t
*
testing
.
T
)
{
_
,
trie
:=
New
()
trie
.
Update
(
"cat"
,
"dog"
)
trie
.
Update
(
"ca"
,
"dude"
)
trie
.
Update
(
"doge"
,
"1234567890abcdefghijklmnopqrstuvwxxzABCEFGHIJKLMNOPQRSTUVWXYZ"
)
trie
.
Update
(
"dog"
,
"test"
)
trie
.
Update
(
"test"
,
"1234567890abcdefghijklmnopqrstuvwxxzABCEFGHIJKLMNOPQRSTUVWXYZ"
)
fmt
.
Printf
(
"%x
\n
"
,
trie
.
Root
)
trie
.
Delete
(
"dog"
)
fmt
.
Printf
(
"%x
\n
"
,
trie
.
Root
)
trie
.
Delete
(
"test"
)
fmt
.
Printf
(
"%x
\n
"
,
trie
.
Root
)
}
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