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
07e85d8e
Commit
07e85d8e
authored
Apr 22, 2015
by
Bas van Kervel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved leveldb update loop to eth/backend
parent
4ddbf81e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
42 deletions
+56
-42
db.go
common/db.go
+1
-0
backend.go
eth/backend.go
+48
-17
database.go
ethdb/database.go
+3
-25
memory_database.go
ethdb/memory_database.go
+4
-0
No files found.
common/db.go
View file @
07e85d8e
...
...
@@ -7,4 +7,5 @@ type Database interface {
Delete
(
key
[]
byte
)
error
LastKnownTD
()
[]
byte
Close
()
Flush
()
error
}
eth/backend.go
View file @
07e85d8e
...
...
@@ -6,6 +6,7 @@ import (
"math"
"path"
"strings"
"time"
"github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/accounts"
...
...
@@ -124,6 +125,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
...
...
@@ -199,18 +202,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
())
...
...
@@ -378,6 +382,9 @@ func (s *Ethereum) Start() error {
}
}
// periodically flush databases
go
s
.
syncDatabases
()
// Start services
s
.
txPool
.
Start
()
...
...
@@ -397,6 +404,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
,
...
...
@@ -417,11 +452,6 @@ 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
.
minedBlockSub
.
Unsubscribe
()
// quits blockBroadcastLoop
...
...
@@ -437,6 +467,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
View file @
07e85d8e
...
...
@@ -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
View file @
07e85d8e
...
...
@@ -65,3 +65,7 @@ func (db *MemDatabase) LastKnownTD() []byte {
return
data
}
func
(
db
*
MemDatabase
)
Flush
()
error
{
return
nil
}
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