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
07db098c
Commit
07db098c
authored
Jun 20, 2015
by
obscuren
Committed by
Jeffrey Wilcke
Jun 29, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: renamed next to pending & fixed tests
parent
855e76fd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
17 deletions
+14
-17
chain_manager.go
core/chain_manager.go
+10
-15
chain_manager_test.go
core/chain_manager_test.go
+4
-2
No files found.
core/chain_manager.go
View file @
07db098c
...
...
@@ -108,9 +108,9 @@ type ChainManager struct {
transState
*
state
.
StateDB
txState
*
state
.
ManagedState
cache
*
lru
.
Cache
// cache is the LRU caching
futureBlocks
*
BlockCache
// future blocks are blocks added for later processing
nextBlocks
*
BlockCache
// next blocks is used during large inserts
cache
*
lru
.
Cache
// cache is the LRU caching
futureBlocks
*
BlockCache
// future blocks are blocks added for later processing
pendingBlocks
*
BlockCache
// pending blocks contain blocks not yet written to the db
quit
chan
struct
{}
// procInterrupt must be atomically called
...
...
@@ -389,8 +389,8 @@ func (bc *ChainManager) HasBlock(hash common.Hash) bool {
return
true
}
if
bc
.
next
Blocks
!=
nil
{
if
block
:=
bc
.
next
Blocks
.
Get
(
hash
);
block
!=
nil
{
if
bc
.
pending
Blocks
!=
nil
{
if
block
:=
bc
.
pending
Blocks
.
Get
(
hash
);
block
!=
nil
{
return
true
}
}
...
...
@@ -425,8 +425,8 @@ func (self *ChainManager) GetBlock(hash common.Hash) *types.Block {
return
block
.
(
*
types
.
Block
)
}
if
self
.
next
Blocks
!=
nil
{
if
block
:=
self
.
next
Blocks
.
Get
(
hash
);
block
!=
nil
{
if
self
.
pending
Blocks
!=
nil
{
if
block
:=
self
.
pending
Blocks
.
Get
(
hash
);
block
!=
nil
{
return
block
}
}
...
...
@@ -521,13 +521,13 @@ func (self *ChainManager) procFutureBlocks() {
}
func
(
self
*
ChainManager
)
enqueueForWrite
(
block
*
types
.
Block
)
{
self
.
next
Blocks
.
Push
(
block
)
self
.
pending
Blocks
.
Push
(
block
)
}
func
(
self
*
ChainManager
)
flushQueuedBlocks
()
{
db
,
batchWrite
:=
self
.
blockDb
.
(
*
ethdb
.
LDBDatabase
)
batch
:=
new
(
leveldb
.
Batch
)
self
.
next
Blocks
.
Each
(
func
(
i
int
,
block
*
types
.
Block
)
{
self
.
pending
Blocks
.
Each
(
func
(
i
int
,
block
*
types
.
Block
)
{
enc
,
_
:=
rlp
.
EncodeToBytes
((
*
types
.
StorageBlock
)(
block
))
key
:=
append
(
blockHashPre
,
block
.
Hash
()
.
Bytes
()
...
)
if
batchWrite
{
...
...
@@ -539,10 +539,6 @@ func (self *ChainManager) flushQueuedBlocks() {
if
batchWrite
{
db
.
LDB
()
.
Write
(
batch
,
nil
)
}
// reset the next blocks cache
self
.
nextBlocks
=
nil
}
// InsertChain will attempt to insert the given chain in to the canonical chain or, otherwise, create a fork. It an error is returned
...
...
@@ -554,7 +550,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
self
.
chainmu
.
Lock
()
defer
self
.
chainmu
.
Unlock
()
self
.
next
Blocks
=
NewBlockCache
(
len
(
chain
))
self
.
pending
Blocks
=
NewBlockCache
(
len
(
chain
))
// A queued approach to delivering events. This is generally
// faster than direct delivery and requires much less mutex
...
...
@@ -687,7 +683,6 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
queue
[
i
]
=
ChainSideEvent
{
block
,
logs
}
queueEvent
.
sideCount
++
}
// Write block to database. Eventually we'll have to improve on this and throw away blocks that are
// not in the canonical chain.
self
.
enqueueForWrite
(
block
)
// Delete from future blocks
...
...
core/chain_manager_test.go
View file @
07db098c
...
...
@@ -18,6 +18,7 @@ import (
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/pow"
"github.com/ethereum/go-ethereum/rlp"
"github.com/hashicorp/golang-lru"
)
func
init
()
{
...
...
@@ -109,7 +110,8 @@ func testChain(chainB types.Blocks, bman *BlockProcessor) (*big.Int, error) {
bman
.
bc
.
mu
.
Lock
()
{
bman
.
bc
.
write
(
block
)
bman
.
bc
.
enqueueForWrite
(
block
)
//bman.bc.write(block)
}
bman
.
bc
.
mu
.
Unlock
()
}
...
...
@@ -391,7 +393,7 @@ func makeChainWithDiff(genesis *types.Block, d []int, seed byte) []*types.Block
func
chm
(
genesis
*
types
.
Block
,
db
common
.
Database
)
*
ChainManager
{
var
eventMux
event
.
TypeMux
bc
:=
&
ChainManager
{
blockDb
:
db
,
stateDb
:
db
,
genesisBlock
:
genesis
,
eventMux
:
&
eventMux
,
pow
:
FakePow
{}}
bc
.
cache
=
NewBlockCache
(
100
)
bc
.
cache
,
_
=
lru
.
New
(
100
)
bc
.
futureBlocks
=
NewBlockCache
(
100
)
bc
.
processor
=
bproc
{}
bc
.
ResetWithGenesisBlock
(
genesis
)
...
...
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