Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
exchain
nebula
Commits
6da869ce
Commit
6da869ce
authored
May 31, 2023
by
Felipe Andrade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add cache support for debug_getRawReceipts when request is for block hash
parent
2b000cc4
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
3 deletions
+52
-3
README.md
proxyd/README.md
+1
-1
cache.go
proxyd/cache.go
+18
-0
cache_test.go
proxyd/cache_test.go
+23
-0
methods.go
proxyd/methods.go
+10
-2
No files found.
proxyd/README.md
View file @
6da869ce
...
@@ -87,7 +87,7 @@ Cache use Redis and can be enabled for the following immutable methods:
...
@@ -87,7 +87,7 @@ Cache use Redis and can be enabled for the following immutable methods:
*
`eth_getBlockByHash`
*
`eth_getBlockByHash`
*
`eth_getTransactionByBlockHashAndIndex`
*
`eth_getTransactionByBlockHashAndIndex`
*
`eth_getUncleByBlockHashAndIndex`
*
`eth_getUncleByBlockHashAndIndex`
*
`debug_getRawReceipts`
(block hash only)
## Metrics
## Metrics
...
...
proxyd/cache.go
View file @
6da869ce
...
@@ -2,6 +2,8 @@ package proxyd
...
@@ -2,6 +2,8 @@ package proxyd
import
(
import
(
"context"
"context"
"encoding/json"
"github.com/ethereum/go-ethereum/rpc"
"strings"
"strings"
"time"
"time"
...
@@ -124,6 +126,21 @@ type rpcCache struct {
...
@@ -124,6 +126,21 @@ type rpcCache struct {
func
newRPCCache
(
cache
Cache
)
RPCCache
{
func
newRPCCache
(
cache
Cache
)
RPCCache
{
staticHandler
:=
&
StaticMethodHandler
{
cache
:
cache
}
staticHandler
:=
&
StaticMethodHandler
{
cache
:
cache
}
debugGetRawReceiptsHandler
:=
&
StaticMethodHandler
{
cache
:
cache
,
filter
:
func
(
req
*
RPCReq
)
bool
{
// cache only if the request is for a block hash
var
p
[]
rpc
.
BlockNumberOrHash
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
p
)
if
err
!=
nil
{
return
false
}
if
len
(
p
)
!=
1
{
return
false
}
return
p
[
0
]
.
BlockHash
!=
nil
},
}
handlers
:=
map
[
string
]
RPCMethodHandler
{
handlers
:=
map
[
string
]
RPCMethodHandler
{
"eth_chainId"
:
staticHandler
,
"eth_chainId"
:
staticHandler
,
"net_version"
:
staticHandler
,
"net_version"
:
staticHandler
,
...
@@ -132,6 +149,7 @@ func newRPCCache(cache Cache) RPCCache {
...
@@ -132,6 +149,7 @@ func newRPCCache(cache Cache) RPCCache {
"eth_getBlockByHash"
:
staticHandler
,
"eth_getBlockByHash"
:
staticHandler
,
"eth_getTransactionByBlockHashAndIndex"
:
staticHandler
,
"eth_getTransactionByBlockHashAndIndex"
:
staticHandler
,
"eth_getUncleByBlockHashAndIndex"
:
staticHandler
,
"eth_getUncleByBlockHashAndIndex"
:
staticHandler
,
"debug_getRawReceipts"
:
debugGetRawReceiptsHandler
,
}
}
return
&
rpcCache
{
return
&
rpcCache
{
cache
:
cache
,
cache
:
cache
,
...
...
proxyd/cache_test.go
View file @
6da869ce
...
@@ -101,6 +101,20 @@ func TestRPCCacheImmutableRPCs(t *testing.T) {
...
@@ -101,6 +101,20 @@ func TestRPCCacheImmutableRPCs(t *testing.T) {
},
},
name
:
"eth_getUncleByBlockHashAndIndex"
,
name
:
"eth_getUncleByBlockHashAndIndex"
,
},
},
{
req
:
&
RPCReq
{
JSONRPC
:
"2.0"
,
Method
:
"debug_getRawReceipts"
,
Params
:
mustMarshalJSON
([]
string
{
"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b"
}),
ID
:
ID
,
},
res
:
&
RPCRes
{
JSONRPC
:
"2.0"
,
Result
:
`{"debug_getRawReceipts":"!"}`
,
ID
:
ID
,
},
name
:
"debug_getRawReceipts"
,
},
}
}
for
_
,
rpc
:=
range
rpcs
{
for
_
,
rpc
:=
range
rpcs
{
...
@@ -173,6 +187,15 @@ func TestRPCCacheUnsupportedMethod(t *testing.T) {
...
@@ -173,6 +187,15 @@ func TestRPCCacheUnsupportedMethod(t *testing.T) {
ID
:
ID
,
ID
:
ID
,
},
},
},
},
{
req
:
&
RPCReq
{
JSONRPC
:
"2.0"
,
Method
:
"debug_getRawReceipts"
,
Params
:
mustMarshalJSON
([]
string
{
"0x100"
}),
ID
:
ID
,
},
name
:
"debug_getRawReceipts"
,
},
}
}
for
_
,
rpc
:=
range
rpcs
{
for
_
,
rpc
:=
range
rpcs
{
...
...
proxyd/methods.go
View file @
6da869ce
...
@@ -19,6 +19,7 @@ type RPCMethodHandler interface {
...
@@ -19,6 +19,7 @@ type RPCMethodHandler interface {
type
StaticMethodHandler
struct
{
type
StaticMethodHandler
struct
{
cache
Cache
cache
Cache
m
sync
.
RWMutex
m
sync
.
RWMutex
filter
func
(
*
RPCReq
)
bool
}
}
func
(
e
*
StaticMethodHandler
)
key
(
req
*
RPCReq
)
string
{
func
(
e
*
StaticMethodHandler
)
key
(
req
*
RPCReq
)
string
{
...
@@ -33,6 +34,10 @@ func (e *StaticMethodHandler) GetRPCMethod(ctx context.Context, req *RPCReq) (*R
...
@@ -33,6 +34,10 @@ func (e *StaticMethodHandler) GetRPCMethod(ctx context.Context, req *RPCReq) (*R
if
e
.
cache
==
nil
{
if
e
.
cache
==
nil
{
return
nil
,
nil
return
nil
,
nil
}
}
if
e
.
filter
!=
nil
&&
!
e
.
filter
(
req
)
{
return
nil
,
nil
}
e
.
m
.
RLock
()
e
.
m
.
RLock
()
defer
e
.
m
.
RUnlock
()
defer
e
.
m
.
RUnlock
()
...
@@ -62,6 +67,9 @@ func (e *StaticMethodHandler) PutRPCMethod(ctx context.Context, req *RPCReq, res
...
@@ -62,6 +67,9 @@ func (e *StaticMethodHandler) PutRPCMethod(ctx context.Context, req *RPCReq, res
if
e
.
cache
==
nil
{
if
e
.
cache
==
nil
{
return
nil
return
nil
}
}
if
e
.
filter
!=
nil
&&
!
e
.
filter
(
req
)
{
return
nil
}
e
.
m
.
Lock
()
e
.
m
.
Lock
()
defer
e
.
m
.
Unlock
()
defer
e
.
m
.
Unlock
()
...
...
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