Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
ed276cd7
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ed276cd7
编写于
6月 30, 2014
作者:
O
obscuren
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added Paranoia check for VM execution
上级
82272ee0
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
58 addition
and
115 deletion
+58
-115
ethchain/state.go
ethchain/state.go
+0
-81
ethchain/state_manager.go
ethchain/state_manager.go
+6
-2
ethchain/state_test.go
ethchain/state_test.go
+2
-2
ethchain/state_transition.go
ethchain/state_transition.go
+15
-18
ethchain/vm_test.go
ethchain/vm_test.go
+3
-5
ethutil/trie.go
ethutil/trie.go
+12
-6
ethutil/trie_test.go
ethutil/trie_test.go
+20
-1
未找到文件。
ethchain/state.go
浏览文件 @
ed276cd7
...
...
@@ -204,84 +204,3 @@ func (m *Manifest) AddStorageChange(stateObject *StateObject, storageAddr []byte
m
.
storageChanges
[
string
(
stateObject
.
Address
())][
string
(
storageAddr
)]
=
storage
}
/*
// Resets the trie and all siblings
func (s *State) Reset() {
s.trie.Undo()
// Reset all nested states
for _, state := range s.states {
state.Reset()
}
}
// Syncs the trie and all siblings
func (s *State) Sync() {
// Sync all nested states
for _, state := range s.states {
state.Sync()
}
s.trie.Sync()
}
func (s *State) GetStateObject(addr []byte) *StateObject {
data := s.trie.Get(string(addr))
if data == "" {
return nil
}
stateObject := NewStateObjectFromBytes(addr, []byte(data))
// Check if there's a cached state for this contract
cachedStateObject := s.states[string(addr)]
if cachedStateObject != nil {
//fmt.Printf("get cached #%d %x addr: %x\n", cachedStateObject.trie.Cache().Len(), cachedStateObject.Root(), addr[0:4])
stateObject.state = cachedStateObject
}
return stateObject
}
// Updates any given state object
func (s *State) UpdateStateObject(object *StateObject) {
addr := object.Address()
if object.state != nil && s.states[string(addr)] == nil {
s.states[string(addr)] = object.state
}
ethutil.Config.Db.Put(ethutil.Sha3Bin(object.Script()), object.Script())
s.trie.Update(string(addr), string(object.RlpEncode()))
s.manifest.AddObjectChange(object)
}
func (s *State) GetAccount(addr []byte) (account *StateObject) {
data := s.trie.Get(string(addr))
if data == "" {
account = NewAccount(addr, big.NewInt(0))
} else {
account = NewStateObjectFromBytes(addr, []byte(data))
}
// Check if there's a cached state for this contract
cachedStateObject := s.states[string(addr)]
if cachedStateObject != nil {
account.state = cachedStateObject
}
return
}
func (s *State) Copy() *State {
state := NewState(s.trie.Copy())
for k, subState := range s.states {
state.states[k] = subState.Copy()
}
return state
}
*/
ethchain/state_manager.go
浏览文件 @
ed276cd7
...
...
@@ -123,7 +123,8 @@ done:
break
done
default
:
statelogger
.
Infoln
(
err
)
//statelogger.Infoln(err)
return
nil
,
nil
,
nil
,
err
}
}
...
...
@@ -236,7 +237,10 @@ func (sm *StateManager) ApplyDiff(state *State, parent, block *Block) (receipts
coinbase
.
SetGasPool
(
block
.
CalcGasLimit
(
parent
))
// Process the transactions on to current block
receipts
,
_
,
_
,
_
=
sm
.
ProcessTransactions
(
coinbase
,
state
,
block
,
parent
,
block
.
Transactions
())
receipts
,
_
,
_
,
err
=
sm
.
ProcessTransactions
(
coinbase
,
state
,
block
,
parent
,
block
.
Transactions
())
if
err
!=
nil
{
return
nil
,
err
}
return
receipts
,
nil
}
...
...
ethchain/state_test.go
浏览文件 @
ed276cd7
...
...
@@ -16,12 +16,12 @@ func TestSnapshot(t *testing.T) {
state
.
UpdateStateObject
(
stateObject
)
stateObject
.
SetStorage
(
ethutil
.
Big
(
"0"
),
ethutil
.
NewValue
(
42
))
snapshot
:=
state
.
Snapshot
()
snapshot
:=
state
.
Copy
()
stateObject
=
state
.
GetStateObject
([]
byte
(
"aa"
))
stateObject
.
SetStorage
(
ethutil
.
Big
(
"0"
),
ethutil
.
NewValue
(
43
))
state
.
Rever
t
(
snapshot
)
state
.
Se
t
(
snapshot
)
stateObject
=
state
.
GetStateObject
([]
byte
(
"aa"
))
if
!
stateObject
.
GetStorage
(
ethutil
.
Big
(
"0"
))
.
Cmp
(
ethutil
.
NewValue
(
42
))
{
...
...
ethchain/state_transition.go
浏览文件 @
ed276cd7
...
...
@@ -226,20 +226,14 @@ func (self *StateTransition) transferValue(sender, receiver *StateObject) error
return
fmt
.
Errorf
(
"Insufficient funds to transfer value. Req %v, has %v"
,
self
.
value
,
sender
.
Amount
)
}
//if self.value.Cmp(ethutil.Big0) > 0 {
// Subtract the amount from the senders account
sender
.
SubAmount
(
self
.
value
)
// Add the amount to receivers account which should conclude this transaction
receiver
.
AddAmount
(
self
.
value
)
//statelogger.Debugf("%x => %x (%v)\n", sender.Address()[:4], receiver.Address()[:4], self.value)
//}
return
nil
}
var
testAddr
=
ethutil
.
FromHex
(
"ec4f34c97e43fbb2816cfd95e388353c7181dab1"
)
func
(
self
*
StateTransition
)
Eval
(
script
[]
byte
,
context
*
StateObject
)
(
ret
[]
byte
,
err
error
,
deepErr
bool
)
{
var
(
block
=
self
.
block
...
...
@@ -263,6 +257,7 @@ func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []by
deepErr
=
vm
.
err
!=
nil
/*
var testAddr = ethutil.FromHex("ec4f34c97e43fbb2816cfd95e388353c7181dab1")
if bytes.Compare(testAddr, context.Address()) == 0 {
trie := context.state.trie
trie.NewIterator().Each(func(key string, v *ethutil.Value) {
...
...
@@ -273,7 +268,7 @@ func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []by
}
*/
Paranoia
:=
true
Paranoia
:=
true
// TODO Create a flag for this
if
Paranoia
{
var
(
trie
=
context
.
state
.
trie
...
...
@@ -287,17 +282,19 @@ func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []by
a
:=
ethutil
.
NewValue
(
trie2
.
Root
)
.
Bytes
()
b
:=
ethutil
.
NewValue
(
context
.
state
.
trie
.
Root
)
.
Bytes
()
if
bytes
.
Compare
(
a
,
b
)
!=
0
{
fmt
.
Printf
(
"original: %x
\n
"
,
trie
.
Root
)
/*
statelogger.Debugf("(o): %x\n", trie.Root)
trie.NewIterator().Each(func(key string, v *ethutil.Value) {
v.Decode()
fmt
.
Print
f
(
"%x : %x
\n
"
,
key
,
v
.
Str
())
statelogger.Debug
f("%x : %x\n", key, v.Str())
})
fmt
.
Printf
(
"new
: %x
\n
"
,
trie2
.
Root
)
statelogger.Debugf("(c)
: %x\n", trie2.Root)
trie2.NewIterator().Each(func(key string, v *ethutil.Value) {
v.Decode()
fmt
.
Print
f
(
"%x : %x
\n
"
,
key
,
v
.
Str
())
statelogger.Debug
f("%x : %x\n", key, v.Str())
})
*/
return
nil
,
fmt
.
Errorf
(
"PARANOIA: Different state object roots during copy"
),
false
}
...
...
ethchain/vm_test.go
浏览文件 @
ed276cd7
...
...
@@ -5,9 +5,7 @@ import (
"fmt"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethutil"
"github.com/obscuren/mutan"
"math/big"
"strings"
"testing"
)
...
...
@@ -17,7 +15,7 @@ func TestRun4(t *testing.T) {
db
,
_
:=
ethdb
.
NewMemDatabase
()
state
:=
NewState
(
ethutil
.
NewTrie
(
db
,
""
))
callerScript
,
err
:=
mutan
.
Compile
(
strings
.
NewReader
(
`
callerScript
,
err
:=
ethutil
.
Compile
(
`
this.store[this.origin()] = 10**20
hello := "world"
...
...
@@ -31,7 +29,7 @@ func TestRun4(t *testing.T) {
this.store[to] = this.store[to] + value
}
}
`
)
,
false
)
`
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
...
...
@@ -55,7 +53,7 @@ func TestRun4(t *testing.T) {
vm
:=
NewVm
(
state
,
nil
,
RuntimeVars
{
Origin
:
account
.
Address
(),
BlockNumber
:
1
,
BlockNumber
:
big
.
NewInt
(
1
)
,
PrevHash
:
ethutil
.
FromHex
(
"5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
),
Coinbase
:
ethutil
.
FromHex
(
"2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
),
Time
:
1
,
...
...
ethutil/trie.go
浏览文件 @
ed276cd7
...
...
@@ -173,10 +173,13 @@ func (t *Trie) Update(key string, value string) {
k
:=
CompactHexDecode
(
key
)
root
:=
t
.
UpdateState
(
t
.
Root
,
k
,
value
)
if
_
,
ok
:=
root
.
([]
byte
);
!
ok
{
t
.
Root
=
t
.
cache
.
PutValue
(
root
,
true
)
}
else
{
switch
root
.
(
type
)
{
case
string
:
t
.
Root
=
root
case
[]
byte
:
t
.
Root
=
root
default
:
t
.
Root
=
t
.
cache
.
PutValue
(
root
,
true
)
}
}
...
...
@@ -197,10 +200,13 @@ func (t *Trie) Delete(key string) {
k
:=
CompactHexDecode
(
key
)
root
:=
t
.
DeleteState
(
t
.
Root
,
k
)
if
_
,
ok
:=
root
.
([]
byte
);
!
ok
{
t
.
Root
=
t
.
cache
.
PutValue
(
root
,
true
)
}
else
{
switch
root
.
(
type
)
{
case
string
:
t
.
Root
=
root
case
[]
byte
:
t
.
Root
=
root
default
:
t
.
Root
=
t
.
cache
.
PutValue
(
root
,
true
)
}
}
...
...
ethutil/trie_test.go
浏览文件 @
ed276cd7
...
...
@@ -242,7 +242,6 @@ func TestRemote(t *testing.T) {
for
key
,
value
:=
range
test
.
In
{
trie
.
Update
(
get
(
key
),
get
(
value
))
}
fmt
.
Printf
(
"%-15s: %x
\n
"
,
test
.
Name
,
trie
.
Root
)
a
:=
NewValue
(
h
(
test
.
Root
))
.
Bytes
()
b
:=
NewValue
(
trie
.
Root
)
.
Bytes
()
...
...
@@ -271,3 +270,23 @@ func TestTrieReplay(t *testing.T) {
}
})
}
func
TestIt
(
t
*
testing
.
T
)
{
_
,
trie
:=
New
()
test
:=
map
[
string
]
string
{
"0x000000000000000000000000ec4f34c97e43fbb2816cfd95e388353c7181dab1"
:
"0x4e616d6552656700000000000000000000000000000000000000000000000000"
,
"0x0000000000000000000000000000000000000000000000000000000000000045"
:
"0x22b224a1420a802ab51d326e29fa98e34c4f24ea"
,
"0x0000000000000000000000000000000000000000000000000000000000000046"
:
"0x67706c2076330000000000000000000000000000000000000000000000000000"
,
"0x000000000000000000000000697c7b8c961b56f675d570498424ac8de1a918f6"
:
"0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000"
,
"0x0000000000000000000000007ef9e639e2733cb34e4dfc576d4b23f72db776b2"
:
"0x4655474156000000000000000000000000000000000000000000000000000000"
,
"0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000"
:
"0x697c7b8c961b56f675d570498424ac8de1a918f6"
,
"0x4655474156000000000000000000000000000000000000000000000000000000"
:
"0x7ef9e639e2733cb34e4dfc576d4b23f72db776b2"
,
"0x4e616d6552656700000000000000000000000000000000000000000000000000"
:
"0xec4f34c97e43fbb2816cfd95e388353c7181dab1"
,
}
for
k
,
v
:=
range
test
{
trie
.
Update
(
k
,
v
)
}
fmt
.
Printf
(
"root : %x
\n
"
,
trie
.
Root
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录