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
5cf1d354
Unverified
Commit
5cf1d354
authored
Feb 22, 2018
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth, les, light: filter on logs only, derive receipts on demand
parent
45352477
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
123 additions
and
17 deletions
+123
-17
simulated.go
accounts/abi/bind/backends/simulated.go
+13
-0
api_backend.go
eth/api_backend.go
+12
-0
filter.go
eth/filters/filter.go
+16
-3
filter_system.go
eth/filters/filter_system.go
+19
-3
filter_system_test.go
eth/filters/filter_system_test.go
+13
-2
api.go
internal/ethapi/api.go
+7
-3
api_backend.go
les/api_backend.go
+4
-0
odr_util.go
light/odr_util.go
+39
-6
No files found.
accounts/abi/bind/backends/simulated.go
View file @
5cf1d354
...
...
@@ -428,10 +428,23 @@ func (fb *filterBackend) HeaderByNumber(ctx context.Context, block rpc.BlockNumb
}
return
fb
.
bc
.
GetHeaderByNumber
(
uint64
(
block
.
Int64
())),
nil
}
func
(
fb
*
filterBackend
)
GetReceipts
(
ctx
context
.
Context
,
hash
common
.
Hash
)
(
types
.
Receipts
,
error
)
{
return
core
.
GetBlockReceipts
(
fb
.
db
,
hash
,
core
.
GetBlockNumber
(
fb
.
db
,
hash
)),
nil
}
func
(
fb
*
filterBackend
)
GetLogs
(
ctx
context
.
Context
,
hash
common
.
Hash
)
([][]
*
types
.
Log
,
error
)
{
receipts
:=
core
.
GetBlockReceipts
(
fb
.
db
,
hash
,
core
.
GetBlockNumber
(
fb
.
db
,
hash
))
if
receipts
==
nil
{
return
nil
,
nil
}
logs
:=
make
([][]
*
types
.
Log
,
len
(
receipts
))
for
i
,
receipt
:=
range
receipts
{
logs
[
i
]
=
receipt
.
Logs
}
return
logs
,
nil
}
func
(
fb
*
filterBackend
)
SubscribeTxPreEvent
(
ch
chan
<-
core
.
TxPreEvent
)
event
.
Subscription
{
return
event
.
NewSubscription
(
func
(
quit
<-
chan
struct
{})
error
{
<-
quit
...
...
eth/api_backend.go
View file @
5cf1d354
...
...
@@ -104,6 +104,18 @@ func (b *EthApiBackend) GetReceipts(ctx context.Context, blockHash common.Hash)
return
core
.
GetBlockReceipts
(
b
.
eth
.
chainDb
,
blockHash
,
core
.
GetBlockNumber
(
b
.
eth
.
chainDb
,
blockHash
)),
nil
}
func
(
b
*
EthApiBackend
)
GetLogs
(
ctx
context
.
Context
,
blockHash
common
.
Hash
)
([][]
*
types
.
Log
,
error
)
{
receipts
:=
core
.
GetBlockReceipts
(
b
.
eth
.
chainDb
,
blockHash
,
core
.
GetBlockNumber
(
b
.
eth
.
chainDb
,
blockHash
))
if
receipts
==
nil
{
return
nil
,
nil
}
logs
:=
make
([][]
*
types
.
Log
,
len
(
receipts
))
for
i
,
receipt
:=
range
receipts
{
logs
[
i
]
=
receipt
.
Logs
}
return
logs
,
nil
}
func
(
b
*
EthApiBackend
)
GetTd
(
blockHash
common
.
Hash
)
*
big
.
Int
{
return
b
.
eth
.
blockchain
.
GetTdByHash
(
blockHash
)
}
...
...
eth/filters/filter.go
View file @
5cf1d354
...
...
@@ -34,6 +34,7 @@ type Backend interface {
EventMux
()
*
event
.
TypeMux
HeaderByNumber
(
ctx
context
.
Context
,
blockNr
rpc
.
BlockNumber
)
(
*
types
.
Header
,
error
)
GetReceipts
(
ctx
context
.
Context
,
blockHash
common
.
Hash
)
(
types
.
Receipts
,
error
)
GetLogs
(
ctx
context
.
Context
,
blockHash
common
.
Hash
)
([][]
*
types
.
Log
,
error
)
SubscribeTxPreEvent
(
chan
<-
core
.
TxPreEvent
)
event
.
Subscription
SubscribeChainEvent
(
ch
chan
<-
core
.
ChainEvent
)
event
.
Subscription
...
...
@@ -201,16 +202,28 @@ func (f *Filter) unindexedLogs(ctx context.Context, end uint64) ([]*types.Log, e
// match the filter criteria. This function is called when the bloom filter signals a potential match.
func
(
f
*
Filter
)
checkMatches
(
ctx
context
.
Context
,
header
*
types
.
Header
)
(
logs
[]
*
types
.
Log
,
err
error
)
{
// Get the logs of the block
receipts
,
err
:=
f
.
backend
.
GetReceipt
s
(
ctx
,
header
.
Hash
())
logsList
,
err
:=
f
.
backend
.
GetLog
s
(
ctx
,
header
.
Hash
())
if
err
!=
nil
{
return
nil
,
err
}
var
unfiltered
[]
*
types
.
Log
for
_
,
receipt
:=
range
receipts
{
unfiltered
=
append
(
unfiltered
,
receipt
.
L
ogs
...
)
for
_
,
logs
:=
range
logsList
{
unfiltered
=
append
(
unfiltered
,
l
ogs
...
)
}
logs
=
filterLogs
(
unfiltered
,
nil
,
nil
,
f
.
addresses
,
f
.
topics
)
if
len
(
logs
)
>
0
{
// We have matching logs, check if we need to resolve full logs via the light client
if
logs
[
0
]
.
TxHash
==
(
common
.
Hash
{})
{
receipts
,
err
:=
f
.
backend
.
GetReceipts
(
ctx
,
header
.
Hash
())
if
err
!=
nil
{
return
nil
,
err
}
unfiltered
=
unfiltered
[
:
0
]
for
_
,
receipt
:=
range
receipts
{
unfiltered
=
append
(
unfiltered
,
receipt
.
Logs
...
)
}
logs
=
filterLogs
(
unfiltered
,
nil
,
nil
,
f
.
addresses
,
f
.
topics
)
}
return
logs
,
nil
}
return
nil
,
nil
...
...
eth/filters/filter_system.go
View file @
5cf1d354
...
...
@@ -375,19 +375,35 @@ func (es *EventSystem) lightFilterLogs(header *types.Header, addresses []common.
// Get the logs of the block
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
5
)
defer
cancel
()
receipts
,
err
:=
es
.
backend
.
GetReceipt
s
(
ctx
,
header
.
Hash
())
logsList
,
err
:=
es
.
backend
.
GetLog
s
(
ctx
,
header
.
Hash
())
if
err
!=
nil
{
return
nil
}
var
unfiltered
[]
*
types
.
Log
for
_
,
receipt
:=
range
receipts
{
for
_
,
log
:=
range
receipt
.
L
ogs
{
for
_
,
logs
:=
range
logsList
{
for
_
,
log
:=
range
l
ogs
{
logcopy
:=
*
log
logcopy
.
Removed
=
remove
unfiltered
=
append
(
unfiltered
,
&
logcopy
)
}
}
logs
:=
filterLogs
(
unfiltered
,
nil
,
nil
,
addresses
,
topics
)
if
len
(
logs
)
>
0
&&
logs
[
0
]
.
TxHash
==
(
common
.
Hash
{})
{
// We have matching but non-derived logs
receipts
,
err
:=
es
.
backend
.
GetReceipts
(
ctx
,
header
.
Hash
())
if
err
!=
nil
{
return
nil
}
unfiltered
=
unfiltered
[
:
0
]
for
_
,
receipt
:=
range
receipts
{
for
_
,
log
:=
range
receipt
.
Logs
{
logcopy
:=
*
log
logcopy
.
Removed
=
remove
unfiltered
=
append
(
unfiltered
,
&
logcopy
)
}
}
logs
=
filterLogs
(
unfiltered
,
nil
,
nil
,
addresses
,
topics
)
}
return
logs
}
return
nil
...
...
eth/filters/filter_system_test.go
View file @
5cf1d354
...
...
@@ -69,8 +69,19 @@ func (b *testBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumbe
}
func
(
b
*
testBackend
)
GetReceipts
(
ctx
context
.
Context
,
blockHash
common
.
Hash
)
(
types
.
Receipts
,
error
)
{
num
:=
core
.
GetBlockNumber
(
b
.
db
,
blockHash
)
return
core
.
GetBlockReceipts
(
b
.
db
,
blockHash
,
num
),
nil
number
:=
core
.
GetBlockNumber
(
b
.
db
,
blockHash
)
return
core
.
GetBlockReceipts
(
b
.
db
,
blockHash
,
number
),
nil
}
func
(
b
*
testBackend
)
GetLogs
(
ctx
context
.
Context
,
blockHash
common
.
Hash
)
([][]
*
types
.
Log
,
error
)
{
number
:=
core
.
GetBlockNumber
(
b
.
db
,
blockHash
)
receipts
:=
core
.
GetBlockReceipts
(
b
.
db
,
blockHash
,
number
)
logs
:=
make
([][]
*
types
.
Log
,
len
(
receipts
))
for
i
,
receipt
:=
range
receipts
{
logs
[
i
]
=
receipt
.
Logs
}
return
logs
,
nil
}
func
(
b
*
testBackend
)
SubscribeTxPreEvent
(
ch
chan
<-
core
.
TxPreEvent
)
event
.
Subscription
{
...
...
internal/ethapi/api.go
View file @
5cf1d354
...
...
@@ -1032,15 +1032,19 @@ func (s *PublicTransactionPoolAPI) GetRawTransactionByHash(ctx context.Context,
}
// GetTransactionReceipt returns the transaction receipt for the given transaction hash.
func
(
s
*
PublicTransactionPoolAPI
)
GetTransactionReceipt
(
hash
common
.
Hash
)
(
map
[
string
]
interface
{},
error
)
{
func
(
s
*
PublicTransactionPoolAPI
)
GetTransactionReceipt
(
ctx
context
.
Context
,
hash
common
.
Hash
)
(
map
[
string
]
interface
{},
error
)
{
tx
,
blockHash
,
blockNumber
,
index
:=
core
.
GetTransaction
(
s
.
b
.
ChainDb
(),
hash
)
if
tx
==
nil
{
return
nil
,
errors
.
New
(
"unknown transaction"
)
}
receipt
,
_
,
_
,
_
:=
core
.
GetReceipt
(
s
.
b
.
ChainDb
(),
hash
)
// Old receipts don't have the lookup data available
if
receipt
==
nil
{
receipts
,
err
:=
s
.
b
.
GetReceipts
(
ctx
,
blockHash
)
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
receipts
)
<=
int
(
index
)
{
return
nil
,
errors
.
New
(
"unknown receipt"
)
}
receipt
:=
receipts
[
index
]
var
signer
types
.
Signer
=
types
.
FrontierSigner
{}
if
tx
.
Protected
()
{
...
...
les/api_backend.go
View file @
5cf1d354
...
...
@@ -87,6 +87,10 @@ func (b *LesApiBackend) GetReceipts(ctx context.Context, blockHash common.Hash)
return
light
.
GetBlockReceipts
(
ctx
,
b
.
eth
.
odr
,
blockHash
,
core
.
GetBlockNumber
(
b
.
eth
.
chainDb
,
blockHash
))
}
func
(
b
*
LesApiBackend
)
GetLogs
(
ctx
context
.
Context
,
blockHash
common
.
Hash
)
([][]
*
types
.
Log
,
error
)
{
return
light
.
GetBlockLogs
(
ctx
,
b
.
eth
.
odr
,
blockHash
,
core
.
GetBlockNumber
(
b
.
eth
.
chainDb
,
blockHash
))
}
func
(
b
*
LesApiBackend
)
GetTd
(
blockHash
common
.
Hash
)
*
big
.
Int
{
return
b
.
eth
.
blockchain
.
GetTdByHash
(
blockHash
)
}
...
...
light/odr_util.go
View file @
5cf1d354
...
...
@@ -126,15 +126,48 @@ func GetBlock(ctx context.Context, odr OdrBackend, hash common.Hash, number uint
// GetBlockReceipts retrieves the receipts generated by the transactions included
// in a block given by its hash.
func
GetBlockReceipts
(
ctx
context
.
Context
,
odr
OdrBackend
,
hash
common
.
Hash
,
number
uint64
)
(
types
.
Receipts
,
error
)
{
// Retrieve the potentially incomplete receipts from disk or network
receipts
:=
core
.
GetBlockReceipts
(
odr
.
Database
(),
hash
,
number
)
if
receipts
!=
nil
{
return
receipts
,
nil
if
receipts
==
nil
{
r
:=
&
ReceiptsRequest
{
Hash
:
hash
,
Number
:
number
}
if
err
:=
odr
.
Retrieve
(
ctx
,
r
);
err
!=
nil
{
return
nil
,
err
}
receipts
=
r
.
Receipts
}
r
:=
&
ReceiptsRequest
{
Hash
:
hash
,
Number
:
number
}
if
err
:=
odr
.
Retrieve
(
ctx
,
r
);
err
!=
nil
{
return
nil
,
err
// If the receipts are incomplete, fill the derived fields
if
len
(
receipts
)
>
0
&&
receipts
[
0
]
.
TxHash
==
(
common
.
Hash
{})
{
block
,
err
:=
GetBlock
(
ctx
,
odr
,
hash
,
number
)
if
err
!=
nil
{
return
nil
,
err
}
genesis
:=
core
.
GetCanonicalHash
(
odr
.
Database
(),
0
)
config
,
_
:=
core
.
GetChainConfig
(
odr
.
Database
(),
genesis
)
core
.
SetReceiptsData
(
config
,
block
,
receipts
)
core
.
WriteBlockReceipts
(
odr
.
Database
(),
hash
,
number
,
receipts
)
}
return
receipts
,
nil
}
// GetBlockLogs retrieves the logs generated by the transactions included in a
// block given by its hash.
func
GetBlockLogs
(
ctx
context
.
Context
,
odr
OdrBackend
,
hash
common
.
Hash
,
number
uint64
)
([][]
*
types
.
Log
,
error
)
{
// Retrieve the potentially incomplete receipts from disk or network
receipts
:=
core
.
GetBlockReceipts
(
odr
.
Database
(),
hash
,
number
)
if
receipts
==
nil
{
r
:=
&
ReceiptsRequest
{
Hash
:
hash
,
Number
:
number
}
if
err
:=
odr
.
Retrieve
(
ctx
,
r
);
err
!=
nil
{
return
nil
,
err
}
receipts
=
r
.
Receipts
}
// Return the logs without deriving any computed fields on the receipts
logs
:=
make
([][]
*
types
.
Log
,
len
(
receipts
))
for
i
,
receipt
:=
range
receipts
{
logs
[
i
]
=
receipt
.
Logs
}
return
r
.
Receipt
s
,
nil
return
log
s
,
nil
}
// GetBloomBits retrieves a batch of compressed bloomBits vectors belonging to the given bit index and section indexes
...
...
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