Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
57dc435f
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,发现更多精彩内容 >>
提交
57dc435f
编写于
9月 24, 2014
作者:
O
obscuren
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added TD for each block
上级
615d2059
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
44 addition
and
2 deletion
+44
-2
ethchain/block.go
ethchain/block.go
+3
-1
ethchain/block_chain.go
ethchain/block_chain.go
+22
-1
ethereum.go
ethereum.go
+14
-0
ethutil/list.go
ethutil/list.go
+5
-0
未找到文件。
ethchain/block.go
浏览文件 @
57dc435f
...
...
@@ -18,6 +18,7 @@ type BlockInfo struct {
Number
uint64
Hash
[]
byte
Parent
[]
byte
TD
*
big
.
Int
}
func
(
bi
*
BlockInfo
)
RlpDecode
(
data
[]
byte
)
{
...
...
@@ -26,10 +27,11 @@ func (bi *BlockInfo) RlpDecode(data []byte) {
bi
.
Number
=
decoder
.
Get
(
0
)
.
Uint
()
bi
.
Hash
=
decoder
.
Get
(
1
)
.
Bytes
()
bi
.
Parent
=
decoder
.
Get
(
2
)
.
Bytes
()
bi
.
TD
=
decoder
.
Get
(
3
)
.
BigInt
()
}
func
(
bi
*
BlockInfo
)
RlpEncode
()
[]
byte
{
return
ethutil
.
Encode
([]
interface
{}{
bi
.
Number
,
bi
.
Hash
,
bi
.
Parent
})
return
ethutil
.
Encode
([]
interface
{}{
bi
.
Number
,
bi
.
Hash
,
bi
.
Parent
,
bi
.
TD
})
}
type
Blocks
[]
*
Block
...
...
ethchain/block_chain.go
浏览文件 @
57dc435f
...
...
@@ -2,6 +2,7 @@ package ethchain
import
(
"bytes"
"fmt"
"math/big"
"github.com/ethereum/eth-go/ethlog"
...
...
@@ -191,6 +192,26 @@ func (bc *BlockChain) Add(block *Block) {
ethutil
.
Config
.
Db
.
Put
([]
byte
(
"LastBlock"
),
encodedBlock
)
}
func
(
self
*
BlockChain
)
CalcTotalDiff
(
block
*
Block
)
(
*
big
.
Int
,
error
)
{
parent
:=
self
.
GetBlock
(
block
.
PrevHash
)
if
parent
==
nil
{
return
nil
,
fmt
.
Errorf
(
"Unable to calculate total diff without known parent %x"
,
block
.
PrevHash
)
}
parentTd
:=
parent
.
BlockInfo
()
.
TD
uncleDiff
:=
new
(
big
.
Int
)
for
_
,
uncle
:=
range
block
.
Uncles
{
uncleDiff
=
uncleDiff
.
Add
(
uncleDiff
,
uncle
.
Difficulty
)
}
td
:=
new
(
big
.
Int
)
td
=
td
.
Add
(
parentTd
,
uncleDiff
)
td
=
td
.
Add
(
td
,
block
.
Difficulty
)
return
td
,
nil
}
func
(
bc
*
BlockChain
)
GetBlock
(
hash
[]
byte
)
*
Block
{
data
,
_
:=
ethutil
.
Config
.
Db
.
Get
(
hash
)
if
len
(
data
)
==
0
{
...
...
@@ -234,7 +255,7 @@ func (bc *BlockChain) BlockInfo(block *Block) BlockInfo {
// Unexported method for writing extra non-essential block info to the db
func
(
bc
*
BlockChain
)
writeBlockInfo
(
block
*
Block
)
{
bc
.
LastBlockNumber
++
bi
:=
BlockInfo
{
Number
:
bc
.
LastBlockNumber
,
Hash
:
block
.
Hash
(),
Parent
:
block
.
PrevHash
}
bi
:=
BlockInfo
{
Number
:
bc
.
LastBlockNumber
,
Hash
:
block
.
Hash
(),
Parent
:
block
.
PrevHash
,
TD
:
bc
.
TD
}
// For now we use the block hash with the words "info" appended as key
ethutil
.
Config
.
Db
.
Put
(
append
(
block
.
Hash
(),
[]
byte
(
"Info"
)
...
),
bi
.
RlpEncode
())
...
...
ethereum.go
浏览文件 @
57dc435f
...
...
@@ -4,6 +4,7 @@ import (
"container/list"
"encoding/json"
"fmt"
"math/big"
"math/rand"
"net"
"path"
...
...
@@ -188,6 +189,18 @@ func (s *Ethereum) IsListening() bool {
return
s
.
listening
}
func
(
s
*
Ethereum
)
HighestTDPeer
()
(
td
*
big
.
Int
)
{
td
=
big
.
NewInt
(
0
)
eachPeer
(
s
.
peers
,
func
(
p
*
Peer
,
v
*
list
.
Element
)
{
if
p
.
td
.
Cmp
(
td
)
>
0
{
td
=
p
.
td
}
})
return
}
func
(
s
*
Ethereum
)
AddPeer
(
conn
net
.
Conn
)
{
peer
:=
NewPeer
(
conn
,
s
,
true
)
...
...
@@ -370,6 +383,7 @@ func (s *Ethereum) ReapDeadPeerHandler() {
// Start the ethereum
func
(
s
*
Ethereum
)
Start
(
seed
bool
)
{
s
.
reactor
.
Start
()
s
.
blockPool
.
Start
()
// Bind to addr and port
ln
,
err
:=
net
.
Listen
(
"tcp"
,
":"
+
s
.
Port
)
if
err
!=
nil
{
...
...
ethutil/list.go
浏览文件 @
57dc435f
...
...
@@ -2,6 +2,7 @@ package ethutil
import
(
"encoding/json"
"fmt"
"reflect"
)
...
...
@@ -29,6 +30,10 @@ func EmptyList() *List {
// Get N element from the embedded slice. Returns nil if OOB.
func
(
self
*
List
)
Get
(
i
int
)
interface
{}
{
if
self
.
list
.
Len
()
==
3
{
fmt
.
Println
(
"get"
,
i
,
self
.
list
.
Index
(
i
)
.
Interface
())
}
if
self
.
list
.
Len
()
>
i
{
return
self
.
list
.
Index
(
i
)
.
Interface
()
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录