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
dc3a9379
Commit
dc3a9379
authored
Mar 23, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
logging for possible uncles
parent
524f8199
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
25 deletions
+44
-25
block_processor.go
core/block_processor.go
+23
-13
chain_manager.go
core/chain_manager.go
+5
-0
error.go
core/error.go
+3
-2
worker.go
miner/worker.go
+13
-10
No files found.
core/block_processor.go
View file @
dc3a9379
...
@@ -166,9 +166,15 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big
...
@@ -166,9 +166,15 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big
// Create a new state based on the parent's root (e.g., create copy)
// Create a new state based on the parent's root (e.g., create copy)
state
:=
state
.
New
(
parent
.
Root
(),
sm
.
db
)
state
:=
state
.
New
(
parent
.
Root
(),
sm
.
db
)
// track (possible) uncle block
var
uncle
bool
// Block validation
// Block validation
if
err
=
sm
.
ValidateHeader
(
block
.
Header
(),
parent
.
Header
());
err
!=
nil
{
if
err
=
sm
.
ValidateHeader
(
block
.
Header
(),
parent
.
Header
());
err
!=
nil
{
return
if
err
!=
BlockEqualTSErr
{
return
}
err
=
nil
uncle
=
true
}
}
// There can be at most two uncles
// There can be at most two uncles
...
@@ -223,14 +229,22 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big
...
@@ -223,14 +229,22 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big
td
=
CalculateTD
(
block
,
parent
)
td
=
CalculateTD
(
block
,
parent
)
// Sync the current block's state to the database
// Sync the current block's state to the database
state
.
Sync
()
state
.
Sync
()
// Remove transactions from the pool
sm
.
txpool
.
RemoveSet
(
block
.
Transactions
())
if
!
uncle
{
// Remove transactions from the pool
sm
.
txpool
.
RemoveSet
(
block
.
Transactions
())
}
for
_
,
tx
:=
range
block
.
Transactions
()
{
for
_
,
tx
:=
range
block
.
Transactions
()
{
putTx
(
sm
.
extraDb
,
tx
)
putTx
(
sm
.
extraDb
,
tx
)
}
}
chainlogger
.
Infof
(
"processed block #%d (%x...)
\n
"
,
header
.
Number
,
block
.
Hash
()
.
Bytes
()[
0
:
4
])
if
uncle
{
chainlogger
.
Infof
(
"found possible uncle block #%d (%x...)
\n
"
,
header
.
Number
,
block
.
Hash
()
.
Bytes
()[
0
:
4
])
return
td
,
nil
,
BlockEqualTSErr
}
else
{
chainlogger
.
Infof
(
"processed block #%d (%x...)
\n
"
,
header
.
Number
,
block
.
Hash
()
.
Bytes
()[
0
:
4
])
}
return
td
,
state
.
Logs
(),
nil
return
td
,
state
.
Logs
(),
nil
}
}
...
@@ -255,10 +269,6 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error {
...
@@ -255,10 +269,6 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error {
return
fmt
.
Errorf
(
"GasLimit check failed for block %v (%v > %v)"
,
block
.
GasLimit
,
a
,
b
)
return
fmt
.
Errorf
(
"GasLimit check failed for block %v (%v > %v)"
,
block
.
GasLimit
,
a
,
b
)
}
}
if
block
.
Time
<=
parent
.
Time
{
return
ValidationError
(
"Block timestamp equal or less than previous block (%v - %v)"
,
block
.
Time
,
parent
.
Time
)
}
if
int64
(
block
.
Time
)
>
time
.
Now
()
.
Unix
()
{
if
int64
(
block
.
Time
)
>
time
.
Now
()
.
Unix
()
{
return
BlockFutureErr
return
BlockFutureErr
}
}
...
@@ -272,6 +282,10 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error {
...
@@ -272,6 +282,10 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error {
return
ValidationError
(
"Block's nonce is invalid (= %x)"
,
block
.
Nonce
)
return
ValidationError
(
"Block's nonce is invalid (= %x)"
,
block
.
Nonce
)
}
}
if
block
.
Time
<=
parent
.
Time
{
return
BlockEqualTSErr
//ValidationError("Block timestamp equal or less than previous block (%v - %v)", block.Time, parent.Time)
}
return
nil
return
nil
}
}
...
@@ -307,14 +321,10 @@ func (sm *BlockProcessor) AccumulateRewards(statedb *state.StateDB, block, paren
...
@@ -307,14 +321,10 @@ func (sm *BlockProcessor) AccumulateRewards(statedb *state.StateDB, block, paren
return
UncleError
(
fmt
.
Sprintf
(
"Uncle's parent unknown (%x)"
,
uncle
.
ParentHash
[
0
:
4
]))
return
UncleError
(
fmt
.
Sprintf
(
"Uncle's parent unknown (%x)"
,
uncle
.
ParentHash
[
0
:
4
]))
}
}
if
err
:=
sm
.
ValidateHeader
(
uncle
,
ancestorHeaders
[
uncle
.
ParentHash
]);
err
!=
nil
{
if
err
:=
sm
.
ValidateHeader
(
uncle
,
ancestorHeaders
[
uncle
.
ParentHash
]);
err
!=
nil
&&
err
!=
BlockEqualTSErr
{
return
ValidationError
(
fmt
.
Sprintf
(
"%v"
,
err
))
return
ValidationError
(
fmt
.
Sprintf
(
"%v"
,
err
))
}
}
if
!
sm
.
Pow
.
Verify
(
types
.
NewBlockWithHeader
(
uncle
))
{
return
ValidationError
(
"Uncle's nonce is invalid (= %x)"
,
uncle
.
Nonce
)
}
r
:=
new
(
big
.
Int
)
r
:=
new
(
big
.
Int
)
r
.
Mul
(
BlockReward
,
big
.
NewInt
(
15
))
.
Div
(
r
,
big
.
NewInt
(
16
))
r
.
Mul
(
BlockReward
,
big
.
NewInt
(
15
))
.
Div
(
r
,
big
.
NewInt
(
16
))
...
...
core/chain_manager.go
View file @
dc3a9379
...
@@ -447,6 +447,11 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
...
@@ -447,6 +447,11 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
continue
continue
}
}
if
err
==
BlockEqualTSErr
{
queue
[
i
]
=
ChainSideEvent
{
block
,
logs
}
continue
}
h
:=
block
.
Header
()
h
:=
block
.
Header
()
chainlogger
.
Infof
(
"INVALID block #%v (%x)
\n
"
,
h
.
Number
,
h
.
Hash
()
.
Bytes
()[
:
4
])
chainlogger
.
Infof
(
"INVALID block #%v (%x)
\n
"
,
h
.
Number
,
h
.
Hash
()
.
Bytes
()[
:
4
])
chainlogger
.
Infoln
(
err
)
chainlogger
.
Infoln
(
err
)
...
...
core/error.go
View file @
dc3a9379
...
@@ -9,8 +9,9 @@ import (
...
@@ -9,8 +9,9 @@ import (
)
)
var
(
var
(
BlockNumberErr
=
errors
.
New
(
"block number invalid"
)
BlockNumberErr
=
errors
.
New
(
"block number invalid"
)
BlockFutureErr
=
errors
.
New
(
"block time is in the future"
)
BlockFutureErr
=
errors
.
New
(
"block time is in the future"
)
BlockEqualTSErr
=
errors
.
New
(
"block time stamp equal to previous"
)
)
)
// Parent error. In case a parent is unknown this error will be thrown
// Parent error. In case a parent is unknown this error will be thrown
...
...
miner/worker.go
View file @
dc3a9379
...
@@ -131,7 +131,7 @@ out:
...
@@ -131,7 +131,7 @@ out:
}
}
case
core
.
NewMinedBlockEvent
:
case
core
.
NewMinedBlockEvent
:
self
.
commitNewWork
()
self
.
commitNewWork
()
case
core
.
ChainS
plit
Event
:
case
core
.
ChainS
ide
Event
:
self
.
uncleMu
.
Lock
()
self
.
uncleMu
.
Lock
()
self
.
possibleUncles
[
ev
.
Block
.
Hash
()]
=
ev
.
Block
self
.
possibleUncles
[
ev
.
Block
.
Hash
()]
=
ev
.
Block
self
.
uncleMu
.
Unlock
()
self
.
uncleMu
.
Unlock
()
...
@@ -170,6 +170,10 @@ func (self *worker) wait() {
...
@@ -170,6 +170,10 @@ func (self *worker) wait() {
})
})
if
err
:=
self
.
chain
.
InsertChain
(
types
.
Blocks
{
self
.
current
.
block
});
err
==
nil
{
if
err
:=
self
.
chain
.
InsertChain
(
types
.
Blocks
{
self
.
current
.
block
});
err
==
nil
{
for
_
,
uncle
:=
range
self
.
current
.
block
.
Uncles
()
{
delete
(
self
.
possibleUncles
,
uncle
.
Hash
())
}
self
.
mux
.
Post
(
core
.
NewMinedBlockEvent
{
self
.
current
.
block
})
self
.
mux
.
Post
(
core
.
NewMinedBlockEvent
{
self
.
current
.
block
})
}
else
{
}
else
{
self
.
commitNewWork
()
self
.
commitNewWork
()
...
@@ -233,9 +237,9 @@ gasLimit:
...
@@ -233,9 +237,9 @@ gasLimit:
}
}
self
.
eth
.
TxPool
()
.
RemoveSet
(
remove
)
self
.
eth
.
TxPool
()
.
RemoveSet
(
remove
)
ucount
:=
0
var
uncles
[]
*
types
.
Header
for
hash
,
uncle
:=
range
self
.
possibleUncles
{
for
hash
,
uncle
:=
range
self
.
possibleUncles
{
if
ucount
==
2
{
if
len
(
uncles
)
==
2
{
break
break
}
}
...
@@ -243,11 +247,12 @@ gasLimit:
...
@@ -243,11 +247,12 @@ gasLimit:
minerlogger
.
Infof
(
"Bad uncle found and will be removed (%x)
\n
"
,
hash
[
:
4
])
minerlogger
.
Infof
(
"Bad uncle found and will be removed (%x)
\n
"
,
hash
[
:
4
])
minerlogger
.
Debugln
(
uncle
)
minerlogger
.
Debugln
(
uncle
)
}
else
{
}
else
{
minerlogger
.
Infof
(
"
C
ommiting %x as uncle
\n
"
,
hash
[
:
4
])
minerlogger
.
Infof
(
"
c
ommiting %x as uncle
\n
"
,
hash
[
:
4
])
u
count
++
u
ncles
=
append
(
uncles
,
uncle
.
Header
())
}
}
}
}
minerlogger
.
Infoln
(
"Included %d uncle(s)"
)
minerlogger
.
Infoln
(
"Included"
,
len
(
uncles
),
"uncle(s)"
)
self
.
current
.
block
.
SetUncles
(
uncles
)
self
.
current
.
state
.
AddBalance
(
self
.
coinbase
,
core
.
BlockReward
)
self
.
current
.
state
.
AddBalance
(
self
.
coinbase
,
core
.
BlockReward
)
...
@@ -276,10 +281,8 @@ func (self *worker) commitUncle(uncle *types.Header) error {
...
@@ -276,10 +281,8 @@ func (self *worker) commitUncle(uncle *types.Header) error {
return
core
.
UncleError
(
fmt
.
Sprintf
(
"Uncle already in family (%x)"
,
uncle
.
Hash
()))
return
core
.
UncleError
(
fmt
.
Sprintf
(
"Uncle already in family (%x)"
,
uncle
.
Hash
()))
}
}
uncleAccount
:=
self
.
current
.
state
.
GetAccount
(
uncle
.
Coinbase
)
self
.
current
.
state
.
AddBalance
(
uncle
.
Coinbase
,
uncleReward
)
uncleAccount
.
AddBalance
(
uncleReward
)
self
.
current
.
state
.
AddBalance
(
self
.
coinbase
,
inclusionReward
)
self
.
current
.
coinbase
.
AddBalance
(
uncleReward
)
return
nil
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