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
7a18a393
Commit
7a18a393
authored
Apr 04, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prevent deadlock
parent
f9488cb7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
17 deletions
+12
-17
blockpool.go
blockpool/blockpool.go
+2
-0
block_processor.go
core/block_processor.go
+4
-4
chain_manager.go
core/chain_manager.go
+6
-13
No files found.
blockpool/blockpool.go
View file @
7a18a393
...
@@ -622,6 +622,8 @@ func (self *BlockPool) AddBlock(block *types.Block, peerId string) {
...
@@ -622,6 +622,8 @@ func (self *BlockPool) AddBlock(block *types.Block, peerId string) {
entry
:=
self
.
get
(
hash
)
entry
:=
self
.
get
(
hash
)
fmt
.
Println
(
"block number"
,
block
.
Number
())
defer
fmt
.
Println
(
"AddBlock done"
)
// a peer's current head block is appearing the first time
// a peer's current head block is appearing the first time
if
hash
==
sender
.
currentBlockHash
{
if
hash
==
sender
.
currentBlockHash
{
if
sender
.
currentBlock
==
nil
{
if
sender
.
currentBlock
==
nil
{
...
...
core/block_processor.go
View file @
7a18a393
...
@@ -268,15 +268,15 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error {
...
@@ -268,15 +268,15 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error {
return
BlockNumberErr
return
BlockNumberErr
}
}
if
block
.
Time
<=
parent
.
Time
{
return
BlockEqualTSErr
//ValidationError("Block timestamp equal or less than previous block (%v - %v)", block.Time, parent.Time)
}
// Verify the nonce of the block. Return an error if it's not valid
// Verify the nonce of the block. Return an error if it's not valid
if
!
sm
.
Pow
.
Verify
(
types
.
NewBlockWithHeader
(
block
))
{
if
!
sm
.
Pow
.
Verify
(
types
.
NewBlockWithHeader
(
block
))
{
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
}
}
...
...
core/chain_manager.go
View file @
7a18a393
...
@@ -437,21 +437,20 @@ type queueEvent struct {
...
@@ -437,21 +437,20 @@ type queueEvent struct {
}
}
func
(
self
*
ChainManager
)
procFutureBlocks
()
{
func
(
self
*
ChainManager
)
procFutureBlocks
()
{
self
.
futureBlocks
.
mu
.
Lock
()
blocks
:=
make
([]
*
types
.
Block
,
len
(
self
.
futureBlocks
.
blocks
))
blocks
:=
make
([]
*
types
.
Block
,
len
(
self
.
futureBlocks
.
blocks
))
for
i
,
hash
:=
range
self
.
futureBlocks
.
hashes
{
for
i
,
hash
:=
range
self
.
futureBlocks
.
hashes
{
blocks
[
i
]
=
self
.
futureBlocks
.
Get
(
hash
)
blocks
[
i
]
=
self
.
futureBlocks
.
Get
(
hash
)
}
}
self
.
futureBlocks
.
mu
.
Unlock
()
types
.
BlockBy
(
types
.
Number
)
.
Sort
(
blocks
)
types
.
BlockBy
(
types
.
Number
)
.
Sort
(
blocks
)
self
.
InsertChain
(
blocks
)
self
.
InsertChain
(
blocks
)
}
}
func
(
self
*
ChainManager
)
InsertChain
(
chain
types
.
Blocks
)
error
{
func
(
self
*
ChainManager
)
InsertChain
(
chain
types
.
Blocks
)
error
{
//self.tsmu.Lock()
if
len
(
chain
)
>
0
{
//defer self.tsmu.Unlock()
fmt
.
Println
(
"insert chain"
,
len
(
chain
))
defer
fmt
.
Println
(
"insert chain done"
)
}
// A queued approach to delivering events. This is generally faster than direct delivery and requires much less mutex acquiring.
// A queued approach to delivering events. This is generally faster than direct delivery and requires much less mutex acquiring.
var
queue
=
make
([]
interface
{},
len
(
chain
))
var
queue
=
make
([]
interface
{},
len
(
chain
))
...
@@ -472,23 +471,17 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
...
@@ -472,23 +471,17 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
// Do not penelise on future block. We'll need a block queue eventually that will queue
// Do not penelise on future block. We'll need a block queue eventually that will queue
// future block for future use
// future block for future use
if
err
==
BlockFutureErr
{
if
err
==
BlockFutureErr
{
fmt
.
Println
(
"added future block"
,
block
.
Number
())
self
.
futureBlocks
.
Push
(
block
)
self
.
futureBlocks
.
Push
(
block
)
continue
continue
}
}
if
IsParentErr
(
err
)
&&
self
.
futureBlocks
.
Has
(
block
.
ParentHash
())
{
if
IsParentErr
(
err
)
&&
self
.
futureBlocks
.
Has
(
block
.
ParentHash
())
{
fmt
.
Println
(
"added future block 2"
,
block
.
Number
())
self
.
futureBlocks
.
Push
(
block
)
self
.
futureBlocks
.
Push
(
block
)
continue
continue
}
}
/*
if err == BlockEqualTSErr {
//queue[i] = ChainSideEvent{block, logs}
// XXX silently discard it?
continue
}
*/
h
:=
block
.
Header
()
h
:=
block
.
Header
()
chainlogger
.
Errorf
(
"INVALID block #%v (%x)
\n
"
,
h
.
Number
,
h
.
Hash
()
.
Bytes
()[
:
4
])
chainlogger
.
Errorf
(
"INVALID block #%v (%x)
\n
"
,
h
.
Number
,
h
.
Hash
()
.
Bytes
()[
:
4
])
chainlogger
.
Errorln
(
err
)
chainlogger
.
Errorln
(
err
)
...
...
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