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
524f8199
Commit
524f8199
authored
Mar 23, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added some nil checks for cache (testing specific)
parent
6657d544
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
6 deletions
+19
-6
chain_manager.go
core/chain_manager.go
+19
-6
No files found.
core/chain_manager.go
View file @
524f8199
...
...
@@ -106,12 +106,7 @@ func NewChainManager(blockDb, stateDb common.Database, mux *event.TypeMux) *Chai
// Take ownership of this particular state
bc
.
txState
=
state
.
ManageState
(
bc
.
State
()
.
Copy
())
// load in last `blockCacheLimit` - 1 blocks. Last block is the current.
ancestors
:=
bc
.
GetAncestors
(
bc
.
currentBlock
,
blockCacheLimit
-
1
)
ancestors
=
append
(
ancestors
,
bc
.
currentBlock
)
for
_
,
block
:=
range
ancestors
{
bc
.
cache
.
Push
(
block
)
}
bc
.
makeCache
()
go
bc
.
update
()
...
...
@@ -194,6 +189,18 @@ func (bc *ChainManager) setLastBlock() {
chainlogger
.
Infof
(
"Last block (#%v) %x TD=%v
\n
"
,
bc
.
currentBlock
.
Number
(),
bc
.
currentBlock
.
Hash
(),
bc
.
td
)
}
func
(
bc
*
ChainManager
)
makeCache
()
{
if
bc
.
cache
==
nil
{
bc
.
cache
=
NewBlockCache
(
blockCacheLimit
)
}
// load in last `blockCacheLimit` - 1 blocks. Last block is the current.
ancestors
:=
bc
.
GetAncestors
(
bc
.
currentBlock
,
blockCacheLimit
-
1
)
ancestors
=
append
(
ancestors
,
bc
.
currentBlock
)
for
_
,
block
:=
range
ancestors
{
bc
.
cache
.
Push
(
block
)
}
}
// Block creation & chain handling
func
(
bc
*
ChainManager
)
NewBlock
(
coinbase
common
.
Address
)
*
types
.
Block
{
bc
.
mu
.
RLock
()
...
...
@@ -240,10 +247,15 @@ func (bc *ChainManager) Reset() {
bc
.
removeBlock
(
block
)
}
if
bc
.
cache
==
nil
{
bc
.
cache
=
NewBlockCache
(
blockCacheLimit
)
}
// Prepare the genesis block
bc
.
write
(
bc
.
genesisBlock
)
bc
.
insert
(
bc
.
genesisBlock
)
bc
.
currentBlock
=
bc
.
genesisBlock
bc
.
makeCache
()
bc
.
setTotalDifficulty
(
common
.
Big
(
"0"
))
}
...
...
@@ -265,6 +277,7 @@ func (bc *ChainManager) ResetWithGenesisBlock(gb *types.Block) {
bc
.
write
(
bc
.
genesisBlock
)
bc
.
insert
(
bc
.
genesisBlock
)
bc
.
currentBlock
=
bc
.
genesisBlock
bc
.
makeCache
()
}
// Export writes the active chain to the given writer.
...
...
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