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
23f0ea39
Commit
23f0ea39
authored
Oct 19, 2023
by
Felipe Andrade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(proxyd): avoid caching debug_getRawReceipts responses with 0 receipts
parent
04f5105c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
8 deletions
+30
-8
cache.go
proxyd/cache.go
+9
-1
methods.go
proxyd/methods.go
+11
-5
handler.go
proxyd/tools/mockserver/handler/handler.go
+1
-1
node1.yml
proxyd/tools/mockserver/node1.yml
+9
-1
No files found.
proxyd/cache.go
View file @
23f0ea39
...
@@ -128,7 +128,7 @@ type rpcCache struct {
...
@@ -128,7 +128,7 @@ 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
,
debugGetRawReceiptsHandler
:=
&
StaticMethodHandler
{
cache
:
cache
,
filter
:
func
(
req
*
RPCReq
)
bool
{
filter
Get
:
func
(
req
*
RPCReq
)
bool
{
// cache only if the request is for a block hash
// cache only if the request is for a block hash
var
p
[]
rpc
.
BlockNumberOrHash
var
p
[]
rpc
.
BlockNumberOrHash
...
@@ -141,6 +141,14 @@ func newRPCCache(cache Cache) RPCCache {
...
@@ -141,6 +141,14 @@ func newRPCCache(cache Cache) RPCCache {
}
}
return
p
[
0
]
.
BlockHash
!=
nil
return
p
[
0
]
.
BlockHash
!=
nil
},
},
filterPut
:
func
(
req
*
RPCReq
,
res
*
RPCRes
)
bool
{
// don't cache if response contains 0 receipts
rawReceipts
,
ok
:=
res
.
Result
.
([]
interface
{})
if
!
ok
{
return
false
}
return
len
(
rawReceipts
)
>
0
},
}
}
handlers
:=
map
[
string
]
RPCMethodHandler
{
handlers
:=
map
[
string
]
RPCMethodHandler
{
"eth_chainId"
:
staticHandler
,
"eth_chainId"
:
staticHandler
,
...
...
proxyd/methods.go
View file @
23f0ea39
...
@@ -17,9 +17,10 @@ type RPCMethodHandler interface {
...
@@ -17,9 +17,10 @@ type RPCMethodHandler interface {
}
}
type
StaticMethodHandler
struct
{
type
StaticMethodHandler
struct
{
cache
Cache
cache
Cache
m
sync
.
RWMutex
m
sync
.
RWMutex
filter
func
(
*
RPCReq
)
bool
filterGet
func
(
*
RPCReq
)
bool
filterPut
func
(
*
RPCReq
,
*
RPCRes
)
bool
}
}
func
(
e
*
StaticMethodHandler
)
key
(
req
*
RPCReq
)
string
{
func
(
e
*
StaticMethodHandler
)
key
(
req
*
RPCReq
)
string
{
...
@@ -34,7 +35,7 @@ func (e *StaticMethodHandler) GetRPCMethod(ctx context.Context, req *RPCReq) (*R
...
@@ -34,7 +35,7 @@ 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
)
{
if
e
.
filter
Get
!=
nil
&&
!
e
.
filterGet
(
req
)
{
return
nil
,
nil
return
nil
,
nil
}
}
...
@@ -67,7 +68,12 @@ func (e *StaticMethodHandler) PutRPCMethod(ctx context.Context, req *RPCReq, res
...
@@ -67,7 +68,12 @@ 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
)
{
// if there is a filter on get, we don't want to cache it because its irretrievable
if
e
.
filterGet
!=
nil
&&
!
e
.
filterGet
(
req
)
{
return
nil
}
// response filter
if
e
.
filterPut
!=
nil
&&
!
e
.
filterPut
(
req
,
res
)
{
return
nil
return
nil
}
}
...
...
proxyd/tools/mockserver/handler/handler.go
View file @
23f0ea39
...
@@ -77,7 +77,7 @@ func (mh *MockedHandler) Handler(w http.ResponseWriter, req *http.Request) {
...
@@ -77,7 +77,7 @@ func (mh *MockedHandler) Handler(w http.ResponseWriter, req *http.Request) {
for
_
,
r
:=
range
requests
{
for
_
,
r
:=
range
requests
{
method
:=
r
[
"method"
]
method
:=
r
[
"method"
]
block
:=
""
block
:=
""
if
method
==
"eth_getBlockByNumber"
{
if
method
==
"eth_getBlockByNumber"
||
method
==
"debug_getRawReceipts"
{
block
=
(
r
[
"params"
]
.
([]
interface
{})[
0
])
.
(
string
)
block
=
(
r
[
"params"
]
.
([]
interface
{})[
0
])
.
(
string
)
}
}
...
...
proxyd/tools/mockserver/node1.yml
View file @
23f0ea39
This source diff could not be displayed because it is too large. You can
view the blob
instead.
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