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
6ca3a446
Commit
6ca3a446
authored
Jun 19, 2015
by
obscuren
Committed by
Jeffrey Wilcke
Jun 29, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: switched to proper LRU
parent
4460dc9d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
9 deletions
+6
-9
chain_manager.go
core/chain_manager.go
+6
-9
No files found.
core/chain_manager.go
View file @
6ca3a446
...
@@ -21,7 +21,7 @@ import (
...
@@ -21,7 +21,7 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/pow"
"github.com/ethereum/go-ethereum/pow"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rlp"
"github.com/
golang/groupcache/
lru"
"github.com/
hashicorp/golang-
lru"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb"
)
)
...
@@ -121,13 +121,14 @@ type ChainManager struct {
...
@@ -121,13 +121,14 @@ type ChainManager struct {
}
}
func
NewChainManager
(
genesis
*
types
.
Block
,
blockDb
,
stateDb
common
.
Database
,
pow
pow
.
PoW
,
mux
*
event
.
TypeMux
)
(
*
ChainManager
,
error
)
{
func
NewChainManager
(
genesis
*
types
.
Block
,
blockDb
,
stateDb
common
.
Database
,
pow
pow
.
PoW
,
mux
*
event
.
TypeMux
)
(
*
ChainManager
,
error
)
{
cache
,
_
:=
lru
.
New
(
blockCacheLimit
)
bc
:=
&
ChainManager
{
bc
:=
&
ChainManager
{
blockDb
:
blockDb
,
blockDb
:
blockDb
,
stateDb
:
stateDb
,
stateDb
:
stateDb
,
genesisBlock
:
GenesisBlock
(
42
,
stateDb
),
genesisBlock
:
GenesisBlock
(
42
,
stateDb
),
eventMux
:
mux
,
eventMux
:
mux
,
quit
:
make
(
chan
struct
{}),
quit
:
make
(
chan
struct
{}),
cache
:
lru
.
New
(
blockCacheLimit
)
,
cache
:
cache
,
pow
:
pow
,
pow
:
pow
,
}
}
// Check the genesis block given to the chain manager. If the genesis block mismatches block number 0
// Check the genesis block given to the chain manager. If the genesis block mismatches block number 0
...
@@ -172,7 +173,7 @@ func (bc *ChainManager) SetHead(head *types.Block) {
...
@@ -172,7 +173,7 @@ func (bc *ChainManager) SetHead(head *types.Block) {
bc
.
removeBlock
(
block
)
bc
.
removeBlock
(
block
)
}
}
bc
.
cache
=
lru
.
New
(
blockCacheLimit
)
bc
.
cache
,
_
=
lru
.
New
(
blockCacheLimit
)
bc
.
currentBlock
=
head
bc
.
currentBlock
=
head
bc
.
makeCache
()
bc
.
makeCache
()
...
@@ -260,9 +261,7 @@ func (bc *ChainManager) setLastState() {
...
@@ -260,9 +261,7 @@ func (bc *ChainManager) setLastState() {
}
}
func
(
bc
*
ChainManager
)
makeCache
()
{
func
(
bc
*
ChainManager
)
makeCache
()
{
if
bc
.
cache
==
nil
{
bc
.
cache
,
_
=
lru
.
New
(
blockCacheLimit
)
bc
.
cache
=
lru
.
New
(
blockCacheLimit
)
}
// load in last `blockCacheLimit` - 1 blocks. Last block is the current.
// load in last `blockCacheLimit` - 1 blocks. Last block is the current.
ancestors
:=
bc
.
GetAncestors
(
bc
.
currentBlock
,
blockCacheLimit
-
1
)
ancestors
:=
bc
.
GetAncestors
(
bc
.
currentBlock
,
blockCacheLimit
-
1
)
ancestors
=
append
(
ancestors
,
bc
.
currentBlock
)
ancestors
=
append
(
ancestors
,
bc
.
currentBlock
)
...
@@ -279,9 +278,7 @@ func (bc *ChainManager) Reset() {
...
@@ -279,9 +278,7 @@ func (bc *ChainManager) Reset() {
bc
.
removeBlock
(
block
)
bc
.
removeBlock
(
block
)
}
}
if
bc
.
cache
==
nil
{
bc
.
cache
,
_
=
lru
.
New
(
blockCacheLimit
)
bc
.
cache
=
lru
.
New
(
blockCacheLimit
)
}
// Prepare the genesis block
// Prepare the genesis block
bc
.
write
(
bc
.
genesisBlock
)
bc
.
write
(
bc
.
genesisBlock
)
...
...
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