Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
3c7181d2
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,体验更适合开发者的 AI 搜索 >>
提交
3c7181d2
编写于
2月 02, 2015
作者:
O
obscuren
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed a copy issue in the trie which could cause a consensus failure
上级
6fecb150
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
53 addition
and
19 deletion
+53
-19
trie/cache.go
trie/cache.go
+9
-1
trie/fullnode.go
trie/fullnode.go
+3
-3
trie/hashnode.go
trie/hashnode.go
+9
-6
trie/node.go
trie/node.go
+6
-2
trie/shortnode.go
trie/shortnode.go
+7
-1
trie/trie.go
trie/trie.go
+16
-5
trie/valuenode.go
trie/valuenode.go
+3
-1
未找到文件。
trie/cache.go
浏览文件 @
3c7181d2
...
...
@@ -37,6 +37,14 @@ func (self *Cache) Flush() {
//self.Reset()
}
func
(
self
*
Cache
)
Copy
()
*
Cache
{
cache
:=
NewCache
(
self
.
backend
)
for
k
,
v
:=
range
self
.
store
{
cache
.
store
[
k
]
=
v
}
return
cache
}
func
(
self
*
Cache
)
Reset
()
{
self
.
store
=
make
(
map
[
string
][]
byte
)
//
self.store = make(map[string][]byte)
}
trie/fullnode.go
浏览文件 @
3c7181d2
...
...
@@ -20,11 +20,11 @@ func (self *FullNode) Branches() []Node {
return
self
.
nodes
[
:
16
]
}
func
(
self
*
FullNode
)
Copy
()
Node
{
nnode
:=
NewFullNode
(
self
.
trie
)
func
(
self
*
FullNode
)
Copy
(
t
*
Trie
)
Node
{
nnode
:=
NewFullNode
(
t
)
for
i
,
node
:=
range
self
.
nodes
{
if
node
!=
nil
{
nnode
.
nodes
[
i
]
=
node
nnode
.
nodes
[
i
]
=
node
.
Copy
(
t
)
}
}
...
...
trie/hashnode.go
浏览文件 @
3c7181d2
package
trie
import
"github.com/ethereum/go-ethereum/ethutil"
type
HashNode
struct
{
key
[]
byte
key
[]
byte
trie
*
Trie
}
func
NewHash
(
key
[]
byte
)
*
HashNode
{
return
&
HashNode
{
key
}
func
NewHash
(
key
[]
byte
,
trie
*
Trie
)
*
HashNode
{
return
&
HashNode
{
key
,
trie
}
}
func
(
self
*
HashNode
)
RlpData
()
interface
{}
{
...
...
@@ -17,6 +20,6 @@ func (self *HashNode) Hash() interface{} {
}
// These methods will never be called but we have to satisfy Node interface
func
(
self
*
HashNode
)
Value
()
Node
{
return
nil
}
func
(
self
*
HashNode
)
Dirty
()
bool
{
return
true
}
func
(
self
*
HashNode
)
Copy
(
)
Node
{
return
self
}
func
(
self
*
HashNode
)
Value
()
Node
{
return
nil
}
func
(
self
*
HashNode
)
Dirty
()
bool
{
return
true
}
func
(
self
*
HashNode
)
Copy
(
t
*
Trie
)
Node
{
return
NewHash
(
ethutil
.
CopyBytes
(
self
.
key
),
t
)
}
trie/node.go
浏览文件 @
3c7181d2
...
...
@@ -6,7 +6,7 @@ var indices = []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b
type
Node
interface
{
Value
()
Node
Copy
()
Node
// All nodes, for now, return them self
Copy
(
*
Trie
)
Node
// All nodes, for now, return them self
Dirty
()
bool
fstring
(
string
)
string
Hash
()
interface
{}
...
...
@@ -18,7 +18,11 @@ func (self *ValueNode) String() string { return self.fstring("") }
func
(
self
*
FullNode
)
String
()
string
{
return
self
.
fstring
(
""
)
}
func
(
self
*
ShortNode
)
String
()
string
{
return
self
.
fstring
(
""
)
}
func
(
self
*
ValueNode
)
fstring
(
ind
string
)
string
{
return
fmt
.
Sprintf
(
"%x "
,
self
.
data
)
}
func
(
self
*
HashNode
)
fstring
(
ind
string
)
string
{
return
fmt
.
Sprintf
(
"< %x > "
,
self
.
key
)
}
//func (self *HashNode) fstring(ind string) string { return fmt.Sprintf("< %x > ", self.key) }
func
(
self
*
HashNode
)
fstring
(
ind
string
)
string
{
return
fmt
.
Sprintf
(
"%v"
,
self
.
trie
.
trans
(
self
))
}
// Full node
func
(
self
*
FullNode
)
fstring
(
ind
string
)
string
{
...
...
trie/shortnode.go
浏览文件 @
3c7181d2
package
trie
import
"github.com/ethereum/go-ethereum/ethutil"
type
ShortNode
struct
{
trie
*
Trie
key
[]
byte
...
...
@@ -15,7 +17,11 @@ func (self *ShortNode) Value() Node {
return
self
.
value
}
func
(
self
*
ShortNode
)
Dirty
()
bool
{
return
true
}
func
(
self
*
ShortNode
)
Copy
()
Node
{
return
NewShortNode
(
self
.
trie
,
self
.
key
,
self
.
value
)
}
func
(
self
*
ShortNode
)
Copy
(
t
*
Trie
)
Node
{
node
:=
&
ShortNode
{
t
,
nil
,
self
.
value
.
Copy
(
t
)}
node
.
key
=
ethutil
.
CopyBytes
(
self
.
key
)
return
node
}
func
(
self
*
ShortNode
)
RlpData
()
interface
{}
{
return
[]
interface
{}{
self
.
key
,
self
.
value
.
Hash
()}
...
...
trie/trie.go
浏览文件 @
3c7181d2
...
...
@@ -34,7 +34,9 @@ func New(root []byte, backend Backend) *Trie {
trie
:=
&
Trie
{}
trie
.
revisions
=
list
.
New
()
trie
.
roothash
=
root
trie
.
cache
=
NewCache
(
backend
)
if
backend
!=
nil
{
trie
.
cache
=
NewCache
(
backend
)
}
if
root
!=
nil
{
value
:=
ethutil
.
NewValueFromBytes
(
trie
.
cache
.
Get
(
root
))
...
...
@@ -49,7 +51,15 @@ func (self *Trie) Iterator() *Iterator {
}
func
(
self
*
Trie
)
Copy
()
*
Trie
{
return
New
(
self
.
roothash
,
self
.
cache
.
backend
)
cpy
:=
make
([]
byte
,
32
)
copy
(
cpy
,
self
.
roothash
)
trie
:=
New
(
nil
,
nil
)
trie
.
cache
=
self
.
cache
.
Copy
()
if
self
.
root
!=
nil
{
trie
.
root
=
self
.
root
.
Copy
(
trie
)
}
return
trie
}
// Legacy support
...
...
@@ -177,7 +187,7 @@ func (self *Trie) insert(node Node, key []byte, value Node) Node {
return
NewShortNode
(
self
,
key
[
:
matchlength
],
n
)
case
*
FullNode
:
cpy
:=
node
.
Copy
()
.
(
*
FullNode
)
cpy
:=
node
.
Copy
(
self
)
.
(
*
FullNode
)
cpy
.
set
(
key
[
0
],
self
.
insert
(
node
.
branch
(
key
[
0
]),
key
[
1
:
],
value
))
return
cpy
...
...
@@ -244,7 +254,7 @@ func (self *Trie) delete(node Node, key []byte) Node {
}
case
*
FullNode
:
n
:=
node
.
Copy
()
.
(
*
FullNode
)
n
:=
node
.
Copy
(
self
)
.
(
*
FullNode
)
n
.
set
(
key
[
0
],
self
.
delete
(
n
.
branch
(
key
[
0
]),
key
[
1
:
]))
pos
:=
-
1
...
...
@@ -301,7 +311,7 @@ func (self *Trie) mknode(value *ethutil.Value) Node {
}
return
fnode
case
32
:
return
&
HashNode
{
value
.
Bytes
()}
return
&
HashNode
{
value
.
Bytes
()
,
self
}
}
return
&
ValueNode
{
self
,
value
.
Bytes
()}
...
...
@@ -331,4 +341,5 @@ func (self *Trie) store(node Node) interface{} {
func
(
self
*
Trie
)
PrintRoot
()
{
fmt
.
Println
(
self
.
root
)
fmt
.
Printf
(
"root=%x
\n
"
,
self
.
Root
())
}
trie/valuenode.go
浏览文件 @
3c7181d2
package
trie
import
"github.com/ethereum/go-ethereum/ethutil"
type
ValueNode
struct
{
trie
*
Trie
data
[]
byte
...
...
@@ -8,6 +10,6 @@ type ValueNode struct {
func
(
self
*
ValueNode
)
Value
()
Node
{
return
self
}
// Best not to call :-)
func
(
self
*
ValueNode
)
Val
()
[]
byte
{
return
self
.
data
}
func
(
self
*
ValueNode
)
Dirty
()
bool
{
return
true
}
func
(
self
*
ValueNode
)
Copy
(
)
Node
{
return
&
ValueNode
{
self
.
trie
,
self
.
data
}
}
func
(
self
*
ValueNode
)
Copy
(
t
*
Trie
)
Node
{
return
&
ValueNode
{
t
,
ethutil
.
CopyBytes
(
self
.
data
)
}
}
func
(
self
*
ValueNode
)
RlpData
()
interface
{}
{
return
self
.
data
}
func
(
self
*
ValueNode
)
Hash
()
interface
{}
{
return
self
.
data
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录