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
b69942be
Commit
b69942be
authored
Sep 29, 2018
by
Ryan Schneider
Committed by
Felix Lange
Sep 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core, internal/ethapi: add and use LRU cache for receipts (#17610)
parent
86ec2130
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
16 deletions
+20
-16
blockchain.go
core/blockchain.go
+18
-6
api_backend.go
eth/api_backend.go
+2
-10
No files found.
core/blockchain.go
View file @
b69942be
...
@@ -55,6 +55,7 @@ var (
...
@@ -55,6 +55,7 @@ var (
const
(
const
(
bodyCacheLimit
=
256
bodyCacheLimit
=
256
blockCacheLimit
=
256
blockCacheLimit
=
256
receiptsCacheLimit
=
32
maxFutureBlocks
=
256
maxFutureBlocks
=
256
maxTimeFutureBlocks
=
30
maxTimeFutureBlocks
=
30
badBlockLimit
=
10
badBlockLimit
=
10
...
@@ -111,11 +112,12 @@ type BlockChain struct {
...
@@ -111,11 +112,12 @@ type BlockChain struct {
currentBlock
atomic
.
Value
// Current head of the block chain
currentBlock
atomic
.
Value
// Current head of the block chain
currentFastBlock
atomic
.
Value
// Current head of the fast-sync chain (may be above the block chain!)
currentFastBlock
atomic
.
Value
// Current head of the fast-sync chain (may be above the block chain!)
stateCache
state
.
Database
// State database to reuse between imports (contains state cache)
stateCache
state
.
Database
// State database to reuse between imports (contains state cache)
bodyCache
*
lru
.
Cache
// Cache for the most recent block bodies
bodyCache
*
lru
.
Cache
// Cache for the most recent block bodies
bodyRLPCache
*
lru
.
Cache
// Cache for the most recent block bodies in RLP encoded format
bodyRLPCache
*
lru
.
Cache
// Cache for the most recent block bodies in RLP encoded format
blockCache
*
lru
.
Cache
// Cache for the most recent entire blocks
receiptsCache
*
lru
.
Cache
// Cache for the most recent receipts per block
futureBlocks
*
lru
.
Cache
// future blocks are blocks added for later processing
blockCache
*
lru
.
Cache
// Cache for the most recent entire blocks
futureBlocks
*
lru
.
Cache
// future blocks are blocks added for later processing
quit
chan
struct
{}
// blockchain quit channel
quit
chan
struct
{}
// blockchain quit channel
running
int32
// running must be called atomically
running
int32
// running must be called atomically
...
@@ -144,6 +146,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
...
@@ -144,6 +146,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
}
}
bodyCache
,
_
:=
lru
.
New
(
bodyCacheLimit
)
bodyCache
,
_
:=
lru
.
New
(
bodyCacheLimit
)
bodyRLPCache
,
_
:=
lru
.
New
(
bodyCacheLimit
)
bodyRLPCache
,
_
:=
lru
.
New
(
bodyCacheLimit
)
receiptsCache
,
_
:=
lru
.
New
(
receiptsCacheLimit
)
blockCache
,
_
:=
lru
.
New
(
blockCacheLimit
)
blockCache
,
_
:=
lru
.
New
(
blockCacheLimit
)
futureBlocks
,
_
:=
lru
.
New
(
maxFutureBlocks
)
futureBlocks
,
_
:=
lru
.
New
(
maxFutureBlocks
)
badBlocks
,
_
:=
lru
.
New
(
badBlockLimit
)
badBlocks
,
_
:=
lru
.
New
(
badBlockLimit
)
...
@@ -158,6 +161,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
...
@@ -158,6 +161,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
shouldPreserve
:
shouldPreserve
,
shouldPreserve
:
shouldPreserve
,
bodyCache
:
bodyCache
,
bodyCache
:
bodyCache
,
bodyRLPCache
:
bodyRLPCache
,
bodyRLPCache
:
bodyRLPCache
,
receiptsCache
:
receiptsCache
,
blockCache
:
blockCache
,
blockCache
:
blockCache
,
futureBlocks
:
futureBlocks
,
futureBlocks
:
futureBlocks
,
engine
:
engine
,
engine
:
engine
,
...
@@ -280,6 +284,7 @@ func (bc *BlockChain) SetHead(head uint64) error {
...
@@ -280,6 +284,7 @@ func (bc *BlockChain) SetHead(head uint64) error {
// Clear out any stale content from the caches
// Clear out any stale content from the caches
bc
.
bodyCache
.
Purge
()
bc
.
bodyCache
.
Purge
()
bc
.
bodyRLPCache
.
Purge
()
bc
.
bodyRLPCache
.
Purge
()
bc
.
receiptsCache
.
Purge
()
bc
.
blockCache
.
Purge
()
bc
.
blockCache
.
Purge
()
bc
.
futureBlocks
.
Purge
()
bc
.
futureBlocks
.
Purge
()
...
@@ -603,11 +608,18 @@ func (bc *BlockChain) GetBlockByNumber(number uint64) *types.Block {
...
@@ -603,11 +608,18 @@ func (bc *BlockChain) GetBlockByNumber(number uint64) *types.Block {
// GetReceiptsByHash retrieves the receipts for all transactions in a given block.
// GetReceiptsByHash retrieves the receipts for all transactions in a given block.
func
(
bc
*
BlockChain
)
GetReceiptsByHash
(
hash
common
.
Hash
)
types
.
Receipts
{
func
(
bc
*
BlockChain
)
GetReceiptsByHash
(
hash
common
.
Hash
)
types
.
Receipts
{
if
receipts
,
ok
:=
bc
.
receiptsCache
.
Get
(
hash
);
ok
{
return
receipts
.
(
types
.
Receipts
)
}
number
:=
rawdb
.
ReadHeaderNumber
(
bc
.
db
,
hash
)
number
:=
rawdb
.
ReadHeaderNumber
(
bc
.
db
,
hash
)
if
number
==
nil
{
if
number
==
nil
{
return
nil
return
nil
}
}
return
rawdb
.
ReadReceipts
(
bc
.
db
,
hash
,
*
number
)
receipts
:=
rawdb
.
ReadReceipts
(
bc
.
db
,
hash
,
*
number
)
bc
.
receiptsCache
.
Add
(
hash
,
receipts
)
return
receipts
}
}
// GetBlocksFromHash returns the block corresponding to hash and up to n-1 ancestors.
// GetBlocksFromHash returns the block corresponding to hash and up to n-1 ancestors.
...
...
eth/api_backend.go
View file @
b69942be
...
@@ -25,7 +25,6 @@ import (
...
@@ -25,7 +25,6 @@ import (
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/bloombits"
"github.com/ethereum/go-ethereum/core/bloombits"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/core/vm"
...
@@ -107,18 +106,11 @@ func (b *EthAPIBackend) GetBlock(ctx context.Context, hash common.Hash) (*types.
...
@@ -107,18 +106,11 @@ func (b *EthAPIBackend) GetBlock(ctx context.Context, hash common.Hash) (*types.
}
}
func
(
b
*
EthAPIBackend
)
GetReceipts
(
ctx
context
.
Context
,
hash
common
.
Hash
)
(
types
.
Receipts
,
error
)
{
func
(
b
*
EthAPIBackend
)
GetReceipts
(
ctx
context
.
Context
,
hash
common
.
Hash
)
(
types
.
Receipts
,
error
)
{
if
number
:=
rawdb
.
ReadHeaderNumber
(
b
.
eth
.
chainDb
,
hash
);
number
!=
nil
{
return
b
.
eth
.
blockchain
.
GetReceiptsByHash
(
hash
),
nil
return
rawdb
.
ReadReceipts
(
b
.
eth
.
chainDb
,
hash
,
*
number
),
nil
}
return
nil
,
nil
}
}
func
(
b
*
EthAPIBackend
)
GetLogs
(
ctx
context
.
Context
,
hash
common
.
Hash
)
([][]
*
types
.
Log
,
error
)
{
func
(
b
*
EthAPIBackend
)
GetLogs
(
ctx
context
.
Context
,
hash
common
.
Hash
)
([][]
*
types
.
Log
,
error
)
{
number
:=
rawdb
.
ReadHeaderNumber
(
b
.
eth
.
chainDb
,
hash
)
receipts
:=
b
.
eth
.
blockchain
.
GetReceiptsByHash
(
hash
)
if
number
==
nil
{
return
nil
,
nil
}
receipts
:=
rawdb
.
ReadReceipts
(
b
.
eth
.
chainDb
,
hash
,
*
number
)
if
receipts
==
nil
{
if
receipts
==
nil
{
return
nil
,
nil
return
nil
,
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