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
cd856cb2
Commit
cd856cb2
authored
Mar 06, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separated block db from state db. Partial fix for #416
parent
ed84b58a
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
56 additions
and
40 deletions
+56
-40
js.go
cmd/ethereum/js.go
+1
-1
main.go
cmd/ethereum/main.go
+3
-3
bindings.go
cmd/mist/bindings.go
+1
-1
cmd.go
cmd/utils/cmd.go
+1
-1
flags.go
cmd/utils/flags.go
+8
-3
chain_makers.go
core/chain_makers.go
+1
-1
chain_manager.go
core/chain_manager.go
+16
-15
manager.go
core/manager.go
+2
-1
backend.go
eth/backend.go
+18
-10
worker.go
miner/worker.go
+1
-1
api.go
rpc/api.go
+1
-1
state.go
xeth/state.go
+1
-1
xeth.go
xeth/xeth.go
+2
-1
No files found.
cmd/ethereum/js.go
View file @
cd856cb2
...
@@ -229,7 +229,7 @@ func (self *repl) dump(call otto.FunctionCall) otto.Value {
...
@@ -229,7 +229,7 @@ func (self *repl) dump(call otto.FunctionCall) otto.Value {
block
=
self
.
ethereum
.
ChainManager
()
.
CurrentBlock
()
block
=
self
.
ethereum
.
ChainManager
()
.
CurrentBlock
()
}
}
statedb
:=
state
.
New
(
block
.
Root
(),
self
.
ethereum
.
Db
())
statedb
:=
state
.
New
(
block
.
Root
(),
self
.
ethereum
.
State
Db
())
v
,
_
:=
self
.
re
.
Vm
.
ToValue
(
statedb
.
RawDump
())
v
,
_
:=
self
.
re
.
Vm
.
ToValue
(
statedb
.
RawDump
())
...
...
cmd/ethereum/main.go
View file @
cd856cb2
...
@@ -171,7 +171,7 @@ func importchain(ctx *cli.Context) {
...
@@ -171,7 +171,7 @@ func importchain(ctx *cli.Context) {
if
len
(
ctx
.
Args
())
!=
1
{
if
len
(
ctx
.
Args
())
!=
1
{
utils
.
Fatalf
(
"This command requires an argument."
)
utils
.
Fatalf
(
"This command requires an argument."
)
}
}
chain
,
_
:=
utils
.
GetChain
(
ctx
)
chain
,
_
,
_
:=
utils
.
GetChain
(
ctx
)
start
:=
time
.
Now
()
start
:=
time
.
Now
()
err
:=
utils
.
ImportChain
(
chain
,
ctx
.
Args
()
.
First
())
err
:=
utils
.
ImportChain
(
chain
,
ctx
.
Args
()
.
First
())
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -182,7 +182,7 @@ func importchain(ctx *cli.Context) {
...
@@ -182,7 +182,7 @@ func importchain(ctx *cli.Context) {
}
}
func
dump
(
ctx
*
cli
.
Context
)
{
func
dump
(
ctx
*
cli
.
Context
)
{
chain
,
d
b
:=
utils
.
GetChain
(
ctx
)
chain
,
_
,
stateD
b
:=
utils
.
GetChain
(
ctx
)
for
_
,
arg
:=
range
ctx
.
Args
()
{
for
_
,
arg
:=
range
ctx
.
Args
()
{
var
block
*
types
.
Block
var
block
*
types
.
Block
if
hashish
(
arg
)
{
if
hashish
(
arg
)
{
...
@@ -195,7 +195,7 @@ func dump(ctx *cli.Context) {
...
@@ -195,7 +195,7 @@ func dump(ctx *cli.Context) {
fmt
.
Println
(
"{}"
)
fmt
.
Println
(
"{}"
)
utils
.
Fatalf
(
"block not found"
)
utils
.
Fatalf
(
"block not found"
)
}
else
{
}
else
{
statedb
:=
state
.
New
(
block
.
Root
(),
d
b
)
statedb
:=
state
.
New
(
block
.
Root
(),
stateD
b
)
fmt
.
Printf
(
"%s
\n
"
,
statedb
.
Dump
())
fmt
.
Printf
(
"%s
\n
"
,
statedb
.
Dump
())
// fmt.Println(block)
// fmt.Println(block)
}
}
...
...
cmd/mist/bindings.go
View file @
cd856cb2
...
@@ -113,7 +113,7 @@ func (self *Gui) DumpState(hash, path string) {
...
@@ -113,7 +113,7 @@ func (self *Gui) DumpState(hash, path string) {
return
return
}
}
stateDump
=
state
.
New
(
block
.
Root
(),
self
.
eth
.
Db
())
.
Dump
()
stateDump
=
state
.
New
(
block
.
Root
(),
self
.
eth
.
State
Db
())
.
Dump
()
}
}
file
,
err
:=
os
.
OpenFile
(
path
[
7
:
],
os
.
O_CREATE
|
os
.
O_RDWR
,
os
.
ModePerm
)
file
,
err
:=
os
.
OpenFile
(
path
[
7
:
],
os
.
O_CREATE
|
os
.
O_RDWR
,
os
.
ModePerm
)
...
...
cmd/utils/cmd.go
View file @
cd856cb2
...
@@ -197,7 +197,7 @@ func BlockDo(ethereum *eth.Ethereum, hash []byte) error {
...
@@ -197,7 +197,7 @@ func BlockDo(ethereum *eth.Ethereum, hash []byte) error {
parent
:=
ethereum
.
ChainManager
()
.
GetBlock
(
block
.
ParentHash
())
parent
:=
ethereum
.
ChainManager
()
.
GetBlock
(
block
.
ParentHash
())
statedb
:=
state
.
New
(
parent
.
Root
(),
ethereum
.
Db
())
statedb
:=
state
.
New
(
parent
.
Root
(),
ethereum
.
State
Db
())
_
,
err
:=
ethereum
.
BlockProcessor
()
.
TransitionState
(
statedb
,
parent
,
block
,
true
)
_
,
err
:=
ethereum
.
BlockProcessor
()
.
TransitionState
(
statedb
,
parent
,
block
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
cmd/utils/flags.go
View file @
cd856cb2
...
@@ -175,11 +175,16 @@ func GetEthereum(clientID, version string, ctx *cli.Context) *eth.Ethereum {
...
@@ -175,11 +175,16 @@ func GetEthereum(clientID, version string, ctx *cli.Context) *eth.Ethereum {
return
ethereum
return
ethereum
}
}
func
GetChain
(
ctx
*
cli
.
Context
)
(
*
core
.
ChainManager
,
ethutil
.
Database
)
{
func
GetChain
(
ctx
*
cli
.
Context
)
(
*
core
.
ChainManager
,
ethutil
.
Database
,
ethutil
.
Database
)
{
dataDir
:=
ctx
.
GlobalString
(
DataDirFlag
.
Name
)
dataDir
:=
ctx
.
GlobalString
(
DataDirFlag
.
Name
)
d
b
,
err
:=
ethdb
.
NewLDBDatabase
(
path
.
Join
(
dataDir
,
"blockchain"
))
blockD
b
,
err
:=
ethdb
.
NewLDBDatabase
(
path
.
Join
(
dataDir
,
"blockchain"
))
if
err
!=
nil
{
if
err
!=
nil
{
Fatalf
(
"Could not open database: %v"
,
err
)
Fatalf
(
"Could not open database: %v"
,
err
)
}
}
return
core
.
NewChainManager
(
db
,
new
(
event
.
TypeMux
)),
db
stateDb
,
err
:=
ethdb
.
NewLDBDatabase
(
path
.
Join
(
dataDir
,
"state"
))
if
err
!=
nil
{
Fatalf
(
"Could not open database: %v"
,
err
)
}
return
core
.
NewChainManager
(
blockDb
,
stateDb
,
new
(
event
.
TypeMux
)),
blockDb
,
stateDb
}
}
core/chain_makers.go
View file @
cd856cb2
...
@@ -108,7 +108,7 @@ func makeChain(bman *BlockProcessor, parent *types.Block, max int, db ethutil.Da
...
@@ -108,7 +108,7 @@ func makeChain(bman *BlockProcessor, parent *types.Block, max int, db ethutil.Da
// Create a new chain manager starting from given block
// Create a new chain manager starting from given block
// Effectively a fork factory
// Effectively a fork factory
func
newChainManager
(
block
*
types
.
Block
,
eventMux
*
event
.
TypeMux
,
db
ethutil
.
Database
)
*
ChainManager
{
func
newChainManager
(
block
*
types
.
Block
,
eventMux
*
event
.
TypeMux
,
db
ethutil
.
Database
)
*
ChainManager
{
bc
:=
&
ChainManager
{
d
b
:
db
,
genesisBlock
:
GenesisBlock
(
db
),
eventMux
:
eventMux
}
bc
:=
&
ChainManager
{
blockDb
:
db
,
stateD
b
:
db
,
genesisBlock
:
GenesisBlock
(
db
),
eventMux
:
eventMux
}
if
block
==
nil
{
if
block
==
nil
{
bc
.
Reset
()
bc
.
Reset
()
}
else
{
}
else
{
...
...
core/chain_manager.go
View file @
cd856cb2
...
@@ -75,7 +75,8 @@ func CalcGasLimit(parent, block *types.Block) *big.Int {
...
@@ -75,7 +75,8 @@ func CalcGasLimit(parent, block *types.Block) *big.Int {
type
ChainManager
struct
{
type
ChainManager
struct
{
//eth EthManager
//eth EthManager
db
ethutil
.
Database
blockDb
ethutil
.
Database
stateDb
ethutil
.
Database
processor
types
.
BlockProcessor
processor
types
.
BlockProcessor
eventMux
*
event
.
TypeMux
eventMux
*
event
.
TypeMux
genesisBlock
*
types
.
Block
genesisBlock
*
types
.
Block
...
@@ -92,8 +93,8 @@ type ChainManager struct {
...
@@ -92,8 +93,8 @@ type ChainManager struct {
quit
chan
struct
{}
quit
chan
struct
{}
}
}
func
NewChainManager
(
d
b
ethutil
.
Database
,
mux
*
event
.
TypeMux
)
*
ChainManager
{
func
NewChainManager
(
blockDb
,
stateD
b
ethutil
.
Database
,
mux
*
event
.
TypeMux
)
*
ChainManager
{
bc
:=
&
ChainManager
{
db
:
db
,
genesisBlock
:
GenesisBlock
(
d
b
),
eventMux
:
mux
,
quit
:
make
(
chan
struct
{})}
bc
:=
&
ChainManager
{
blockDb
:
blockDb
,
stateDb
:
stateDb
,
genesisBlock
:
GenesisBlock
(
stateD
b
),
eventMux
:
mux
,
quit
:
make
(
chan
struct
{})}
bc
.
setLastBlock
()
bc
.
setLastBlock
()
bc
.
transState
=
bc
.
State
()
.
Copy
()
bc
.
transState
=
bc
.
State
()
.
Copy
()
bc
.
txState
=
bc
.
State
()
.
Copy
()
bc
.
txState
=
bc
.
State
()
.
Copy
()
...
@@ -135,7 +136,7 @@ func (self *ChainManager) SetProcessor(proc types.BlockProcessor) {
...
@@ -135,7 +136,7 @@ func (self *ChainManager) SetProcessor(proc types.BlockProcessor) {
}
}
func
(
self
*
ChainManager
)
State
()
*
state
.
StateDB
{
func
(
self
*
ChainManager
)
State
()
*
state
.
StateDB
{
return
state
.
New
(
self
.
CurrentBlock
()
.
Root
(),
self
.
d
b
)
return
state
.
New
(
self
.
CurrentBlock
()
.
Root
(),
self
.
stateD
b
)
}
}
func
(
self
*
ChainManager
)
TransState
()
*
state
.
StateDB
{
func
(
self
*
ChainManager
)
TransState
()
*
state
.
StateDB
{
...
@@ -163,7 +164,7 @@ func (self *ChainManager) setTransState(statedb *state.StateDB) {
...
@@ -163,7 +164,7 @@ func (self *ChainManager) setTransState(statedb *state.StateDB) {
}
}
func
(
bc
*
ChainManager
)
setLastBlock
()
{
func
(
bc
*
ChainManager
)
setLastBlock
()
{
data
,
_
:=
bc
.
d
b
.
Get
([]
byte
(
"LastBlock"
))
data
,
_
:=
bc
.
blockD
b
.
Get
([]
byte
(
"LastBlock"
))
if
len
(
data
)
!=
0
{
if
len
(
data
)
!=
0
{
var
block
types
.
Block
var
block
types
.
Block
rlp
.
Decode
(
bytes
.
NewReader
(
data
),
&
block
)
rlp
.
Decode
(
bytes
.
NewReader
(
data
),
&
block
)
...
@@ -171,7 +172,7 @@ func (bc *ChainManager) setLastBlock() {
...
@@ -171,7 +172,7 @@ func (bc *ChainManager) setLastBlock() {
bc
.
lastBlockHash
=
block
.
Hash
()
bc
.
lastBlockHash
=
block
.
Hash
()
// Set the last know difficulty (might be 0x0 as initial value, Genesis)
// Set the last know difficulty (might be 0x0 as initial value, Genesis)
bc
.
td
=
ethutil
.
BigD
(
bc
.
d
b
.
LastKnownTD
())
bc
.
td
=
ethutil
.
BigD
(
bc
.
blockD
b
.
LastKnownTD
())
}
else
{
}
else
{
bc
.
Reset
()
bc
.
Reset
()
}
}
...
@@ -220,7 +221,7 @@ func (bc *ChainManager) Reset() {
...
@@ -220,7 +221,7 @@ func (bc *ChainManager) Reset() {
defer
bc
.
mu
.
Unlock
()
defer
bc
.
mu
.
Unlock
()
for
block
:=
bc
.
currentBlock
;
block
!=
nil
;
block
=
bc
.
GetBlock
(
block
.
Header
()
.
ParentHash
)
{
for
block
:=
bc
.
currentBlock
;
block
!=
nil
;
block
=
bc
.
GetBlock
(
block
.
Header
()
.
ParentHash
)
{
bc
.
d
b
.
Delete
(
block
.
Hash
())
bc
.
blockD
b
.
Delete
(
block
.
Hash
())
}
}
// Prepare the genesis block
// Prepare the genesis block
...
@@ -236,7 +237,7 @@ func (bc *ChainManager) ResetWithGenesisBlock(gb *types.Block) {
...
@@ -236,7 +237,7 @@ func (bc *ChainManager) ResetWithGenesisBlock(gb *types.Block) {
defer
bc
.
mu
.
Unlock
()
defer
bc
.
mu
.
Unlock
()
for
block
:=
bc
.
currentBlock
;
block
!=
nil
;
block
=
bc
.
GetBlock
(
block
.
Header
()
.
ParentHash
)
{
for
block
:=
bc
.
currentBlock
;
block
!=
nil
;
block
=
bc
.
GetBlock
(
block
.
Header
()
.
ParentHash
)
{
bc
.
d
b
.
Delete
(
block
.
Hash
())
bc
.
blockD
b
.
Delete
(
block
.
Hash
())
}
}
// Prepare the genesis block
// Prepare the genesis block
...
@@ -262,14 +263,14 @@ func (self *ChainManager) Export() []byte {
...
@@ -262,14 +263,14 @@ func (self *ChainManager) Export() []byte {
func
(
bc
*
ChainManager
)
insert
(
block
*
types
.
Block
)
{
func
(
bc
*
ChainManager
)
insert
(
block
*
types
.
Block
)
{
encodedBlock
:=
ethutil
.
Encode
(
block
)
encodedBlock
:=
ethutil
.
Encode
(
block
)
bc
.
d
b
.
Put
([]
byte
(
"LastBlock"
),
encodedBlock
)
bc
.
blockD
b
.
Put
([]
byte
(
"LastBlock"
),
encodedBlock
)
bc
.
currentBlock
=
block
bc
.
currentBlock
=
block
bc
.
lastBlockHash
=
block
.
Hash
()
bc
.
lastBlockHash
=
block
.
Hash
()
}
}
func
(
bc
*
ChainManager
)
write
(
block
*
types
.
Block
)
{
func
(
bc
*
ChainManager
)
write
(
block
*
types
.
Block
)
{
encodedBlock
:=
ethutil
.
Encode
(
block
.
RlpDataForStorage
())
encodedBlock
:=
ethutil
.
Encode
(
block
.
RlpDataForStorage
())
bc
.
d
b
.
Put
(
block
.
Hash
(),
encodedBlock
)
bc
.
blockD
b
.
Put
(
block
.
Hash
(),
encodedBlock
)
}
}
// Accessors
// Accessors
...
@@ -279,7 +280,7 @@ func (bc *ChainManager) Genesis() *types.Block {
...
@@ -279,7 +280,7 @@ func (bc *ChainManager) Genesis() *types.Block {
// Block fetching methods
// Block fetching methods
func
(
bc
*
ChainManager
)
HasBlock
(
hash
[]
byte
)
bool
{
func
(
bc
*
ChainManager
)
HasBlock
(
hash
[]
byte
)
bool
{
data
,
_
:=
bc
.
d
b
.
Get
(
hash
)
data
,
_
:=
bc
.
blockD
b
.
Get
(
hash
)
return
len
(
data
)
!=
0
return
len
(
data
)
!=
0
}
}
...
@@ -307,7 +308,7 @@ func (self *ChainManager) GetBlockHashesFromHash(hash []byte, max uint64) (chain
...
@@ -307,7 +308,7 @@ func (self *ChainManager) GetBlockHashesFromHash(hash []byte, max uint64) (chain
}
}
func
(
self
*
ChainManager
)
GetBlock
(
hash
[]
byte
)
*
types
.
Block
{
func
(
self
*
ChainManager
)
GetBlock
(
hash
[]
byte
)
*
types
.
Block
{
data
,
_
:=
self
.
d
b
.
Get
(
hash
)
data
,
_
:=
self
.
blockD
b
.
Get
(
hash
)
if
len
(
data
)
==
0
{
if
len
(
data
)
==
0
{
return
nil
return
nil
}
}
...
@@ -361,7 +362,7 @@ func (self *ChainManager) GetBlockByNumber(num uint64) *types.Block {
...
@@ -361,7 +362,7 @@ func (self *ChainManager) GetBlockByNumber(num uint64) *types.Block {
}
}
func
(
bc
*
ChainManager
)
setTotalDifficulty
(
td
*
big
.
Int
)
{
func
(
bc
*
ChainManager
)
setTotalDifficulty
(
td
*
big
.
Int
)
{
bc
.
d
b
.
Put
([]
byte
(
"LTD"
),
td
.
Bytes
())
bc
.
blockD
b
.
Put
([]
byte
(
"LTD"
),
td
.
Bytes
())
bc
.
td
=
td
bc
.
td
=
td
}
}
...
@@ -448,7 +449,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
...
@@ -448,7 +449,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
})
})
*/
*/
self
.
setTransState
(
state
.
New
(
block
.
Root
(),
self
.
d
b
))
self
.
setTransState
(
state
.
New
(
block
.
Root
(),
self
.
stateD
b
))
queue
[
i
]
=
ChainEvent
{
block
}
queue
[
i
]
=
ChainEvent
{
block
}
queueEvent
.
canonicalCount
++
queueEvent
.
canonicalCount
++
}
else
{
}
else
{
...
@@ -487,7 +488,7 @@ out:
...
@@ -487,7 +488,7 @@ out:
// On chain splits we need to reset the transaction state. We can't be sure whether the actual
// On chain splits we need to reset the transaction state. We can't be sure whether the actual
// state of the accounts are still valid.
// state of the accounts are still valid.
if
i
==
ev
.
splitCount
{
if
i
==
ev
.
splitCount
{
self
.
setTxState
(
state
.
New
(
event
.
Block
.
Root
(),
self
.
d
b
))
self
.
setTxState
(
state
.
New
(
event
.
Block
.
Root
(),
self
.
stateD
b
))
}
}
}
}
...
...
core/manager.go
View file @
cd856cb2
...
@@ -15,6 +15,7 @@ type Backend interface {
...
@@ -15,6 +15,7 @@ type Backend interface {
IsListening
()
bool
IsListening
()
bool
Peers
()
[]
*
p2p
.
Peer
Peers
()
[]
*
p2p
.
Peer
KeyManager
()
*
crypto
.
KeyManager
KeyManager
()
*
crypto
.
KeyManager
Db
()
ethutil
.
Database
BlockDb
()
ethutil
.
Database
StateDb
()
ethutil
.
Database
EventMux
()
*
event
.
TypeMux
EventMux
()
*
event
.
TypeMux
}
}
eth/backend.go
View file @
cd856cb2
...
@@ -111,7 +111,8 @@ type Ethereum struct {
...
@@ -111,7 +111,8 @@ type Ethereum struct {
shutdownChan
chan
bool
shutdownChan
chan
bool
// DB interface
// DB interface
db
ethutil
.
Database
blockDb
ethutil
.
Database
stateDb
ethutil
.
Database
//*** SERVICES ***
//*** SERVICES ***
// State manager for processing new blocks and managing the over all states
// State manager for processing new blocks and managing the over all states
...
@@ -140,13 +141,17 @@ func New(config *Config) (*Ethereum, error) {
...
@@ -140,13 +141,17 @@ func New(config *Config) (*Ethereum, error) {
// Boostrap database
// Boostrap database
ethlogger
:=
logger
.
New
(
config
.
DataDir
,
config
.
LogFile
,
config
.
LogLevel
,
config
.
LogFormat
)
ethlogger
:=
logger
.
New
(
config
.
DataDir
,
config
.
LogFile
,
config
.
LogLevel
,
config
.
LogFormat
)
db
,
err
:=
ethdb
.
NewLDBDatabase
(
path
.
Join
(
config
.
DataDir
,
"blockchain"
))
blockDb
,
err
:=
ethdb
.
NewLDBDatabase
(
path
.
Join
(
config
.
DataDir
,
"blockchain"
))
if
err
!=
nil
{
return
nil
,
err
}
stateDb
,
err
:=
ethdb
.
NewLDBDatabase
(
path
.
Join
(
config
.
DataDir
,
"state"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
// Perform database sanity checks
// Perform database sanity checks
d
,
_
:=
d
b
.
Get
([]
byte
(
"ProtocolVersion"
))
d
,
_
:=
blockD
b
.
Get
([]
byte
(
"ProtocolVersion"
))
protov
:=
ethutil
.
NewValue
(
d
)
.
Uint
()
protov
:=
ethutil
.
NewValue
(
d
)
.
Uint
()
if
protov
!=
ProtocolVersion
&&
protov
!=
0
{
if
protov
!=
ProtocolVersion
&&
protov
!=
0
{
path
:=
path
.
Join
(
config
.
DataDir
,
"blockchain"
)
path
:=
path
.
Join
(
config
.
DataDir
,
"blockchain"
)
...
@@ -157,7 +162,7 @@ func New(config *Config) (*Ethereum, error) {
...
@@ -157,7 +162,7 @@ func New(config *Config) (*Ethereum, error) {
var
keyManager
*
crypto
.
KeyManager
var
keyManager
*
crypto
.
KeyManager
switch
config
.
KeyStore
{
switch
config
.
KeyStore
{
case
"db"
:
case
"db"
:
keyManager
=
crypto
.
NewDBKeyManager
(
d
b
)
keyManager
=
crypto
.
NewDBKeyManager
(
blockD
b
)
case
"file"
:
case
"file"
:
keyManager
=
crypto
.
NewFileKeyManager
(
config
.
DataDir
)
keyManager
=
crypto
.
NewFileKeyManager
(
config
.
DataDir
)
default
:
default
:
...
@@ -166,23 +171,24 @@ func New(config *Config) (*Ethereum, error) {
...
@@ -166,23 +171,24 @@ func New(config *Config) (*Ethereum, error) {
// Initialise the keyring
// Initialise the keyring
keyManager
.
Init
(
config
.
KeyRing
,
0
,
false
)
keyManager
.
Init
(
config
.
KeyRing
,
0
,
false
)
saveProtocolVersion
(
d
b
)
saveProtocolVersion
(
blockD
b
)
//ethutil.Config.Db = db
//ethutil.Config.Db = db
eth
:=
&
Ethereum
{
eth
:=
&
Ethereum
{
shutdownChan
:
make
(
chan
bool
),
shutdownChan
:
make
(
chan
bool
),
db
:
db
,
blockDb
:
blockDb
,
stateDb
:
stateDb
,
keyManager
:
keyManager
,
keyManager
:
keyManager
,
eventMux
:
&
event
.
TypeMux
{},
eventMux
:
&
event
.
TypeMux
{},
logger
:
ethlogger
,
logger
:
ethlogger
,
DataDir
:
config
.
DataDir
,
DataDir
:
config
.
DataDir
,
}
}
eth
.
chainManager
=
core
.
NewChainManager
(
d
b
,
eth
.
EventMux
())
eth
.
chainManager
=
core
.
NewChainManager
(
blockDb
,
stateD
b
,
eth
.
EventMux
())
pow
:=
ethash
.
New
(
eth
.
chainManager
)
pow
:=
ethash
.
New
(
eth
.
chainManager
)
eth
.
txPool
=
core
.
NewTxPool
(
eth
.
EventMux
())
eth
.
txPool
=
core
.
NewTxPool
(
eth
.
EventMux
())
eth
.
blockProcessor
=
core
.
NewBlockProcessor
(
d
b
,
pow
,
eth
.
txPool
,
eth
.
chainManager
,
eth
.
EventMux
())
eth
.
blockProcessor
=
core
.
NewBlockProcessor
(
stateD
b
,
pow
,
eth
.
txPool
,
eth
.
chainManager
,
eth
.
EventMux
())
eth
.
chainManager
.
SetProcessor
(
eth
.
blockProcessor
)
eth
.
chainManager
.
SetProcessor
(
eth
.
blockProcessor
)
eth
.
whisper
=
whisper
.
New
()
eth
.
whisper
=
whisper
.
New
()
eth
.
miner
=
miner
.
New
(
keyManager
.
Address
(),
eth
,
pow
,
config
.
MinerThreads
)
eth
.
miner
=
miner
.
New
(
keyManager
.
Address
(),
eth
,
pow
,
config
.
MinerThreads
)
...
@@ -228,7 +234,8 @@ func (s *Ethereum) TxPool() *core.TxPool { return s.txPool }
...
@@ -228,7 +234,8 @@ func (s *Ethereum) TxPool() *core.TxPool { return s.txPool }
func
(
s
*
Ethereum
)
BlockPool
()
*
blockpool
.
BlockPool
{
return
s
.
blockPool
}
func
(
s
*
Ethereum
)
BlockPool
()
*
blockpool
.
BlockPool
{
return
s
.
blockPool
}
func
(
s
*
Ethereum
)
Whisper
()
*
whisper
.
Whisper
{
return
s
.
whisper
}
func
(
s
*
Ethereum
)
Whisper
()
*
whisper
.
Whisper
{
return
s
.
whisper
}
func
(
s
*
Ethereum
)
EventMux
()
*
event
.
TypeMux
{
return
s
.
eventMux
}
func
(
s
*
Ethereum
)
EventMux
()
*
event
.
TypeMux
{
return
s
.
eventMux
}
func
(
s
*
Ethereum
)
Db
()
ethutil
.
Database
{
return
s
.
db
}
func
(
s
*
Ethereum
)
BlockDb
()
ethutil
.
Database
{
return
s
.
blockDb
}
func
(
s
*
Ethereum
)
StateDb
()
ethutil
.
Database
{
return
s
.
stateDb
}
func
(
s
*
Ethereum
)
Miner
()
*
miner
.
Miner
{
return
s
.
miner
}
func
(
s
*
Ethereum
)
Miner
()
*
miner
.
Miner
{
return
s
.
miner
}
func
(
s
*
Ethereum
)
IsListening
()
bool
{
return
true
}
// Always listening
func
(
s
*
Ethereum
)
IsListening
()
bool
{
return
true
}
// Always listening
func
(
s
*
Ethereum
)
PeerCount
()
int
{
return
s
.
net
.
PeerCount
()
}
func
(
s
*
Ethereum
)
PeerCount
()
int
{
return
s
.
net
.
PeerCount
()
}
...
@@ -279,7 +286,8 @@ func (self *Ethereum) SuggestPeer(nodeURL string) error {
...
@@ -279,7 +286,8 @@ func (self *Ethereum) SuggestPeer(nodeURL string) error {
func
(
s
*
Ethereum
)
Stop
()
{
func
(
s
*
Ethereum
)
Stop
()
{
// Close the database
// Close the database
defer
s
.
db
.
Close
()
defer
s
.
blockDb
.
Close
()
defer
s
.
stateDb
.
Close
()
s
.
txSub
.
Unsubscribe
()
// quits txBroadcastLoop
s
.
txSub
.
Unsubscribe
()
// quits txBroadcastLoop
s
.
blockSub
.
Unsubscribe
()
// quits blockBroadcastLoop
s
.
blockSub
.
Unsubscribe
()
// quits blockBroadcastLoop
...
...
miner/worker.go
View file @
cd856cb2
...
@@ -30,7 +30,7 @@ type environment struct {
...
@@ -30,7 +30,7 @@ type environment struct {
}
}
func
env
(
block
*
types
.
Block
,
eth
core
.
Backend
)
*
environment
{
func
env
(
block
*
types
.
Block
,
eth
core
.
Backend
)
*
environment
{
state
:=
state
.
New
(
block
.
Root
(),
eth
.
Db
())
state
:=
state
.
New
(
block
.
Root
(),
eth
.
State
Db
())
env
:=
&
environment
{
env
:=
&
environment
{
totalUsedGas
:
new
(
big
.
Int
),
totalUsedGas
:
new
(
big
.
Int
),
state
:
state
,
state
:
state
,
...
...
rpc/api.go
View file @
cd856cb2
...
@@ -83,7 +83,7 @@ func (self *EthereumApi) setStateByBlockNumber(num int64) {
...
@@ -83,7 +83,7 @@ func (self *EthereumApi) setStateByBlockNumber(num int64) {
block
=
chain
.
GetBlockByNumber
(
uint64
(
num
))
block
=
chain
.
GetBlockByNumber
(
uint64
(
num
))
if
block
!=
nil
{
if
block
!=
nil
{
self
.
useState
(
state
.
New
(
block
.
Root
(),
self
.
xeth
()
.
Backend
()
.
Db
()))
self
.
useState
(
state
.
New
(
block
.
Root
(),
self
.
xeth
()
.
Backend
()
.
State
Db
()))
}
else
{
}
else
{
self
.
useState
(
chain
.
State
())
self
.
useState
(
chain
.
State
())
}
}
...
...
xeth/state.go
View file @
cd856cb2
...
@@ -26,7 +26,7 @@ func (self *State) SafeGet(addr string) *Object {
...
@@ -26,7 +26,7 @@ func (self *State) SafeGet(addr string) *Object {
func
(
self
*
State
)
safeGet
(
addr
string
)
*
state
.
StateObject
{
func
(
self
*
State
)
safeGet
(
addr
string
)
*
state
.
StateObject
{
object
:=
self
.
state
.
GetStateObject
(
fromHex
(
addr
))
object
:=
self
.
state
.
GetStateObject
(
fromHex
(
addr
))
if
object
==
nil
{
if
object
==
nil
{
object
=
state
.
NewStateObject
(
fromHex
(
addr
),
self
.
xeth
.
eth
.
Db
())
object
=
state
.
NewStateObject
(
fromHex
(
addr
),
self
.
xeth
.
eth
.
State
Db
())
}
}
return
object
return
object
...
...
xeth/xeth.go
View file @
cd856cb2
...
@@ -32,7 +32,8 @@ type Backend interface {
...
@@ -32,7 +32,8 @@ type Backend interface {
IsListening
()
bool
IsListening
()
bool
Peers
()
[]
*
p2p
.
Peer
Peers
()
[]
*
p2p
.
Peer
KeyManager
()
*
crypto
.
KeyManager
KeyManager
()
*
crypto
.
KeyManager
Db
()
ethutil
.
Database
BlockDb
()
ethutil
.
Database
StateDb
()
ethutil
.
Database
EventMux
()
*
event
.
TypeMux
EventMux
()
*
event
.
TypeMux
Whisper
()
*
whisper
.
Whisper
Whisper
()
*
whisper
.
Whisper
Miner
()
*
miner
.
Miner
Miner
()
*
miner
.
Miner
...
...
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