Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
f5e0388f
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,发现更多精彩内容 >>
提交
f5e0388f
编写于
4月 23, 2015
作者:
J
Jeffrey Wilcke
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #778 from bas-vk/issue764
Moved database update loop to eth/backend
上级
abe08d7b
c12180d0
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
62 addition
and
48 deletion
+62
-48
common/db.go
common/db.go
+1
-0
core/chain_manager.go
core/chain_manager.go
+5
-5
eth/backend.go
eth/backend.go
+49
-18
ethdb/database.go
ethdb/database.go
+3
-25
ethdb/memory_database.go
ethdb/memory_database.go
+4
-0
未找到文件。
common/db.go
浏览文件 @
f5e0388f
...
...
@@ -7,4 +7,5 @@ type Database interface {
Delete
(
key
[]
byte
)
error
LastKnownTD
()
[]
byte
Close
()
Flush
()
error
}
core/chain_manager.go
浏览文件 @
f5e0388f
...
...
@@ -342,14 +342,14 @@ func (self *ChainManager) Export(w io.Writer) error {
}
func
(
bc
*
ChainManager
)
insert
(
block
*
types
.
Block
)
{
bc
.
blockDb
.
Put
([]
byte
(
"LastBlock"
),
block
.
Hash
()
.
Bytes
())
bc
.
currentBlock
=
block
bc
.
lastBlockHash
=
block
.
Hash
()
key
:=
append
(
blockNumPre
,
block
.
Number
()
.
Bytes
()
...
)
bc
.
blockDb
.
Put
(
key
,
b
c
.
lastBlockHash
.
Bytes
())
bc
.
blockDb
.
Put
(
key
,
b
lock
.
Hash
()
.
Bytes
())
// Push block to cache
bc
.
cache
.
Push
(
block
)
bc
.
blockDb
.
Put
([]
byte
(
"LastBlock"
),
block
.
Hash
()
.
Bytes
())
bc
.
currentBlock
=
block
bc
.
lastBlockHash
=
block
.
Hash
()
}
func
(
bc
*
ChainManager
)
write
(
block
*
types
.
Block
)
{
...
...
eth/backend.go
浏览文件 @
f5e0388f
...
...
@@ -5,6 +5,7 @@ import (
"fmt"
"path"
"strings"
"time"
"github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/accounts"
...
...
@@ -123,6 +124,8 @@ type Ethereum struct {
blockDb
common
.
Database
// Block chain database
stateDb
common
.
Database
// State changes database
extraDb
common
.
Database
// Extra database (txs, etc)
// Closed when databases are flushed and closed
databasesClosed
chan
bool
//*** SERVICES ***
// State manager for processing new blocks and managing the over all states
...
...
@@ -197,18 +200,19 @@ func New(config *Config) (*Ethereum, error) {
glog
.
V
(
logger
.
Info
)
.
Infof
(
"Blockchain DB Version: %d"
,
config
.
BlockChainVersion
)
eth
:=
&
Ethereum
{
shutdownChan
:
make
(
chan
bool
),
blockDb
:
blockDb
,
stateDb
:
stateDb
,
extraDb
:
extraDb
,
eventMux
:
&
event
.
TypeMux
{},
accountManager
:
config
.
AccountManager
,
DataDir
:
config
.
DataDir
,
etherbase
:
common
.
HexToAddress
(
config
.
Etherbase
),
clientVersion
:
config
.
Name
,
// TODO should separate from Name
ethVersionId
:
config
.
ProtocolVersion
,
netVersionId
:
config
.
NetworkId
,
NatSpec
:
config
.
NatSpec
,
shutdownChan
:
make
(
chan
bool
),
databasesClosed
:
make
(
chan
bool
),
blockDb
:
blockDb
,
stateDb
:
stateDb
,
extraDb
:
extraDb
,
eventMux
:
&
event
.
TypeMux
{},
accountManager
:
config
.
AccountManager
,
DataDir
:
config
.
DataDir
,
etherbase
:
common
.
HexToAddress
(
config
.
Etherbase
),
clientVersion
:
config
.
Name
,
// TODO should separate from Name
ethVersionId
:
config
.
ProtocolVersion
,
netVersionId
:
config
.
NetworkId
,
NatSpec
:
config
.
NatSpec
,
}
eth
.
chainManager
=
core
.
NewChainManager
(
blockDb
,
stateDb
,
eth
.
EventMux
())
...
...
@@ -376,6 +380,9 @@ func (s *Ethereum) Start() error {
}
}
// periodically flush databases
go
s
.
syncDatabases
()
// Start services
go
s
.
txPool
.
Start
()
s
.
protocolManager
.
Start
()
...
...
@@ -392,6 +399,34 @@ func (s *Ethereum) Start() error {
return
nil
}
func
(
s
*
Ethereum
)
syncDatabases
()
{
ticker
:=
time
.
NewTicker
(
1
*
time
.
Minute
)
done
:
for
{
select
{
case
<-
ticker
.
C
:
// don't change the order of database flushes
if
err
:=
s
.
extraDb
.
Flush
();
err
!=
nil
{
glog
.
V
(
logger
.
Error
)
.
Infof
(
"error: flush extraDb: %v
\n
"
,
err
)
}
if
err
:=
s
.
stateDb
.
Flush
();
err
!=
nil
{
glog
.
V
(
logger
.
Error
)
.
Infof
(
"error: flush stateDb: %v
\n
"
,
err
)
}
if
err
:=
s
.
blockDb
.
Flush
();
err
!=
nil
{
glog
.
V
(
logger
.
Error
)
.
Infof
(
"error: flush blockDb: %v
\n
"
,
err
)
}
case
<-
s
.
shutdownChan
:
break
done
}
}
s
.
blockDb
.
Close
()
s
.
stateDb
.
Close
()
s
.
extraDb
.
Close
()
close
(
s
.
databasesClosed
)
}
func
(
s
*
Ethereum
)
StartForTest
()
{
jsonlogger
.
LogJson
(
&
logger
.
LogStarting
{
ClientString
:
s
.
net
.
Name
,
...
...
@@ -412,12 +447,7 @@ func (self *Ethereum) SuggestPeer(nodeURL string) error {
}
func
(
s
*
Ethereum
)
Stop
()
{
// Close the database
defer
s
.
blockDb
.
Close
()
defer
s
.
stateDb
.
Close
()
defer
s
.
extraDb
.
Close
()
s
.
txSub
.
Unsubscribe
()
// quits txBroadcastLoop
s
.
txSub
.
Unsubscribe
()
// quits txBroadcastLoop
s
.
protocolManager
.
Stop
()
s
.
txPool
.
Stop
()
...
...
@@ -432,6 +462,7 @@ func (s *Ethereum) Stop() {
// This function will wait for a shutdown and resumes main thread execution
func
(
s
*
Ethereum
)
WaitForShutdown
()
{
<-
s
.
databasesClosed
<-
s
.
shutdownChan
}
...
...
ethdb/database.go
浏览文件 @
f5e0388f
...
...
@@ -2,7 +2,6 @@ package ethdb
import
(
"sync"
"time"
"github.com/ethereum/go-ethereum/compression/rle"
"github.com/ethereum/go-ethereum/logger"
...
...
@@ -35,8 +34,6 @@ func NewLDBDatabase(file string) (*LDBDatabase, error) {
}
database
.
makeQueue
()
go
database
.
update
()
return
database
,
nil
}
...
...
@@ -111,35 +108,16 @@ func (self *LDBDatabase) Flush() error {
}
self
.
makeQueue
()
// reset the queue
glog
.
V
(
logger
.
Detail
)
.
Infoln
(
"Flush database: "
,
self
.
fn
)
return
self
.
db
.
Write
(
batch
,
nil
)
}
func
(
self
*
LDBDatabase
)
Close
()
{
self
.
quit
<-
struct
{}{}
<-
self
.
quit
glog
.
V
(
logger
.
Info
)
.
Infoln
(
"flushed and closed db:"
,
self
.
fn
)
}
func
(
self
*
LDBDatabase
)
update
()
{
ticker
:=
time
.
NewTicker
(
1
*
time
.
Minute
)
done
:
for
{
select
{
case
<-
ticker
.
C
:
if
err
:=
self
.
Flush
();
err
!=
nil
{
glog
.
V
(
logger
.
Error
)
.
Infof
(
"error: flush '%s': %v
\n
"
,
self
.
fn
,
err
)
}
case
<-
self
.
quit
:
break
done
}
}
if
err
:=
self
.
Flush
();
err
!=
nil
{
glog
.
V
(
logger
.
Error
)
.
Infof
(
"error: flush '%s': %v
\n
"
,
self
.
fn
,
err
)
}
// Close the leveldb database
self
.
db
.
Close
()
self
.
quit
<-
struct
{}{}
glog
.
V
(
logger
.
Error
)
.
Infoln
(
"flushed and closed db:"
,
self
.
fn
)
}
ethdb/memory_database.go
浏览文件 @
f5e0388f
...
...
@@ -65,3 +65,7 @@ func (db *MemDatabase) LastKnownTD() []byte {
return
data
}
func
(
db
*
MemDatabase
)
Flush
()
error
{
return
nil
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录