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
d116b959
Commit
d116b959
authored
May 15, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #989 from obscuren/develop
core, miner: fork resolving and restart miner after sync op
parents
82c0780f
55d85d60
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
9 deletions
+20
-9
admin.go
cmd/geth/admin.go
+1
-1
chain_manager.go
core/chain_manager.go
+15
-7
backend.go
eth/backend.go
+2
-0
miner.go
miner/miner.go
+2
-1
No files found.
cmd/geth/admin.go
View file @
d116b959
...
...
@@ -288,7 +288,7 @@ func (js *jsre) startMining(call otto.FunctionCall) otto.Value {
return
otto
.
FalseValue
()
}
}
else
{
threads
=
4
threads
=
int64
(
js
.
ethereum
.
MinerThreads
)
}
err
=
js
.
ethereum
.
StartMining
(
int
(
threads
))
...
...
core/chain_manager.go
View file @
d116b959
...
...
@@ -577,10 +577,10 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
// Compare the TD of the last known block in the canonical chain to make sure it's greater.
// At this point it's possible that a different chain (fork) becomes the new canonical chain.
if
block
.
Td
.
Cmp
(
self
.
td
)
>
0
{
//
Check for chain forks. If H(block.num - 1) != block.parent, we're on a fork and need to do some merging
if
previous
:=
self
.
getBlockByNumber
(
block
.
NumberU64
()
-
1
);
previous
.
Hash
()
!=
block
.
Parent
Hash
()
{
//
chain fork
if
block
.
ParentHash
()
!=
cblock
.
Hash
()
{
// during split we merge two different chains and create the new canonical chain
self
.
merge
(
previous
,
block
)
self
.
merge
(
cblock
,
block
)
queue
[
i
]
=
ChainSplitEvent
{
block
,
logs
}
queueEvent
.
splitCount
++
...
...
@@ -641,9 +641,17 @@ func (self *ChainManager) diff(oldBlock, newBlock *types.Block) types.Blocks {
oldStart
=
oldBlock
newStart
=
newBlock
)
// first find common number
for
newBlock
=
newBlock
;
newBlock
.
NumberU64
()
!=
oldBlock
.
NumberU64
();
newBlock
=
self
.
GetBlock
(
newBlock
.
ParentHash
())
{
newChain
=
append
(
newChain
,
newBlock
)
// first reduce whoever is higher bound
if
oldBlock
.
NumberU64
()
>
newBlock
.
NumberU64
()
{
// reduce old chain
for
oldBlock
=
oldBlock
;
oldBlock
.
NumberU64
()
!=
newBlock
.
NumberU64
();
oldBlock
=
self
.
GetBlock
(
oldBlock
.
ParentHash
())
{
}
}
else
{
// reduce new chain and append new chain blocks for inserting later on
for
newBlock
=
newBlock
;
newBlock
.
NumberU64
()
!=
oldBlock
.
NumberU64
();
newBlock
=
self
.
GetBlock
(
newBlock
.
ParentHash
())
{
newChain
=
append
(
newChain
,
newBlock
)
}
}
numSplit
:=
newBlock
.
Number
()
...
...
@@ -669,7 +677,7 @@ func (self *ChainManager) diff(oldBlock, newBlock *types.Block) types.Blocks {
func
(
self
*
ChainManager
)
merge
(
oldBlock
,
newBlock
*
types
.
Block
)
{
newChain
:=
self
.
diff
(
oldBlock
,
newBlock
)
// insert blocks
// insert blocks
. Order does not matter. Last block will be written in ImportChain itself which creates the new head properly
for
_
,
block
:=
range
newChain
{
self
.
insert
(
block
)
}
...
...
eth/backend.go
View file @
d116b959
...
...
@@ -190,6 +190,7 @@ type Ethereum struct {
// logger logger.LogSystem
Mining
bool
MinerThreads
int
NatSpec
bool
DataDir
string
etherbase
common
.
Address
...
...
@@ -262,6 +263,7 @@ func New(config *Config) (*Ethereum, error) {
ethVersionId
:
config
.
ProtocolVersion
,
netVersionId
:
config
.
NetworkId
,
NatSpec
:
config
.
NatSpec
,
MinerThreads
:
config
.
MinerThreads
,
}
eth
.
chainManager
=
core
.
NewChainManager
(
blockDb
,
stateDb
,
eth
.
EventMux
())
...
...
miner/miner.go
View file @
d116b959
...
...
@@ -47,6 +47,7 @@ func (self *Miner) update() {
atomic
.
StoreInt32
(
&
self
.
canStart
,
0
)
if
self
.
Mining
()
{
self
.
Stop
()
atomic
.
StoreInt32
(
&
self
.
shouldStart
,
1
)
glog
.
V
(
logger
.
Info
)
.
Infoln
(
"Mining operation aborted due to sync operation"
)
}
case
downloader
.
DoneEvent
,
downloader
.
FailedEvent
:
...
...
@@ -100,7 +101,7 @@ func (self *Miner) Stop() {
}
func
(
self
*
Miner
)
Register
(
agent
Agent
)
{
if
atomic
.
LoadInt32
(
&
self
.
mining
)
==
0
{
if
self
.
Mining
()
{
agent
.
Start
()
}
...
...
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