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
76447959
Unverified
Commit
76447959
authored
Mar 29, 2021
by
Martin Holst Swende
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth/protocols/snap: try to prevent requests timing out
parent
76700ac8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
5 deletions
+10
-5
handler.go
eth/protocols/snap/handler.go
+9
-4
sync.go
eth/protocols/snap/sync.go
+1
-1
No files found.
eth/protocols/snap/handler.go
View file @
76447959
...
...
@@ -50,6 +50,11 @@ const (
// maxTrieNodeLookups is the maximum number of state trie nodes to serve. This
// number is there to limit the number of disk lookups.
maxTrieNodeLookups
=
1024
// maxTrieNodeTimeSpent is the maximum time we should spend on looking up trie nodes.
// If we spend too much time, then it's a fairly high chance of timing out
// at the remote side, which means all the work is in vain.
maxTrieNodeTimeSpent
=
5
*
time
.
Second
)
// Handler is a callback to invoke from an outside runner after the boilerplate
...
...
@@ -129,7 +134,7 @@ func handleMessage(backend Backend, peer *Peer) error {
return
fmt
.
Errorf
(
"%w: %v > %v"
,
errMsgTooLarge
,
msg
.
Size
,
maxMessageSize
)
}
defer
msg
.
Discard
()
start
:=
time
.
Now
()
// Track the emount of time it takes to serve the request and run the handler
if
metrics
.
Enabled
{
h
:=
fmt
.
Sprintf
(
"%s/%s/%d/%#02x"
,
p2p
.
HandleHistName
,
ProtocolName
,
peer
.
Version
(),
msg
.
Code
)
...
...
@@ -140,7 +145,7 @@ func handleMessage(backend Backend, peer *Peer) error {
)
}
metrics
.
GetOrRegisterHistogramLazy
(
h
,
nil
,
sampler
)
.
Update
(
time
.
Since
(
start
)
.
Microseconds
())
}(
time
.
Now
()
)
}(
start
)
}
// Handle the message depending on its contents
switch
{
...
...
@@ -470,13 +475,13 @@ func handleMessage(backend Backend, peer *Peer) error {
bytes
+=
uint64
(
len
(
blob
))
// Sanity check limits to avoid DoS on the store trie loads
if
bytes
>
req
.
Bytes
||
loads
>
maxTrieNodeLookups
{
if
bytes
>
req
.
Bytes
||
loads
>
maxTrieNodeLookups
||
time
.
Since
(
start
)
>
maxTrieNodeTimeSpent
{
break
}
}
}
// Abort request processing if we've exceeded our limits
if
bytes
>
req
.
Bytes
||
loads
>
maxTrieNodeLookups
{
if
bytes
>
req
.
Bytes
||
loads
>
maxTrieNodeLookups
||
time
.
Since
(
start
)
>
maxTrieNodeTimeSpent
{
break
}
}
...
...
eth/protocols/snap/sync.go
View file @
76447959
...
...
@@ -85,7 +85,7 @@ const (
var
(
// requestTimeout is the maximum time a peer is allowed to spend on serving
// a single network request.
requestTimeout
=
1
0
*
time
.
Second
// TODO(karalabe): Make it dynamic ala fast-sync?
requestTimeout
=
1
5
*
time
.
Second
// TODO(karalabe): Make it dynamic ala fast-sync?
)
// ErrCancelled is returned from snap syncing if the operation was prematurely
...
...
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